]> git.cworth.org Git - apitrace/blobdiff - retrace/d3d9retrace.py
retrace: Allow multiple dumpers to co-exist.
[apitrace] / retrace / d3d9retrace.py
index 7030f868f17b3a98a27d0e3048f7077f412f640c..9884d92d4f8fe602f31e662e802a6e8f2fc21da5 100644 (file)
 
 
 from dllretrace import DllRetracer as Retracer
-import specs.stdapi as stdapi
+from specs.stdapi import API
 from specs.d3d9 import *
 
 
 class D3DRetracer(Retracer):
 
     def retraceApi(self, api):
+        print '''
+
+class D3D9Dumper : public retrace::Dumper {
+public:
+    IDirect3DDevice9 *pLastDirect3DDevice9;
+
+    D3D9Dumper() :
+        pLastDirect3DDevice9(NULL)
+    {}
+
+    image::Image *
+    getSnapshot(void) {
+        if (!pLastDirect3DDevice9) {
+            return NULL;
+        }
+        return d3dstate::getRenderTargetImage(pLastDirect3DDevice9);
+    }
+
+    bool
+    dumpState(std::ostream &os) {
+        if (!pLastDirect3DDevice9) {
+            return false;
+        }
+        d3dstate::dumpDevice(os, pLastDirect3DDevice9);
+        return true;
+    }
+
+    inline void
+    bindDevice(IDirect3DDevice9 *pDevice) {
+        pLastDirect3DDevice9 = pDevice;
+        retrace::dumper = this;
+    }
+    
+    inline void
+    unbindDevice(IDirect3DDevice9 *pDevice) {
+        if (pLastDirect3DDevice9 == pDevice) {
+            pLastDirect3DDevice9 = NULL;
+        }
+    }
+};
+
+static D3D9Dumper d3d9Dumper;
+'''
+
         print '// Swizzling mapping for lock addresses'
-        print 'static std::map<void *, void *> _locks;'
+        print 'static std::map<void *, void *> _maps;'
         print
 
-        self.table_name = 'd3dretrace::d3d_callbacks'
+        self.table_name = 'd3dretrace::d3d9_callbacks'
 
         Retracer.retraceApi(self, api)
 
@@ -60,7 +104,10 @@ class D3DRetracer(Retracer):
     def invokeInterfaceMethod(self, interface, method):
         # keep track of the last used device for state dumping
         if interface.name in ('IDirect3DDevice9', 'IDirect3DDevice9Ex'):
-            print r'    d3dretrace::pLastDirect3DDevice9 = _this;'
+            if method.name == 'Release':
+                print r'    d3d9Dumper.unbindDevice(_this);'
+            else:
+                print r'    d3d9Dumper.bindDevice(_this);'
 
         # create windows as neccessary
         if method.name in ('CreateDevice', 'CreateDeviceEx', 'CreateAdditionalSwapChain'):
@@ -99,13 +146,13 @@ class D3DRetracer(Retracer):
 
         if method.name in ('Lock', 'LockRect', 'LockBox'):
             print '    VOID *_pbData = NULL;'
-            print '    size_t _LockedSize = 0;'
-            print '    _getLockInfo(_this, %s, _pbData, _LockedSize);' % ', '.join(method.argNames()[:-1])
-            print '    _locks[_this] = _pbData;'
+            print '    size_t _MappedSize = 0;'
+            print '    _getMapInfo(_this, %s, _pbData, _MappedSize);' % ', '.join(method.argNames()[:-1])
+            print '    _maps[_this] = _pbData;'
         
         if method.name in ('Unlock', 'UnlockRect', 'UnlockBox'):
             print '    VOID *_pbData = 0;'
-            print '    _pbData = _locks[_this];'
+            print '    _pbData = _maps[_this];'
             print '    if (_pbData) {'
             print '        retrace::delRegionByPointer(_pbData);'
             print '    }'
@@ -120,8 +167,11 @@ if __name__ == '__main__':
 #include "d3d9imports.hpp"
 #include "d3d9size.hpp"
 #include "d3dretrace.hpp"
+#include "d3d9state.hpp"
 
 '''
 
+    api = API()
+    api.addModule(d3d9)
     retracer = D3DRetracer()
-    retracer.retraceApi(d3d9)
+    retracer.retraceApi(api)