]> git.cworth.org Git - apitrace/blobdiff - retrace/d3d9retrace.py
qapitrace: Adjust PATH only once and for all.
[apitrace] / retrace / d3d9retrace.py
index 0564c0040989f0074f31ab8a6377f94cf7dd240c..9bc9628d59e7f398e4c6f791b8756e715fc336d9 100644 (file)
 """D3D retracer generator."""
 
 
+import sys
 from dllretrace import DllRetracer as Retracer
-import specs.stdapi as stdapi
-from specs.d3d9 import *
+from specs.stdapi import API
 
 
 class D3DRetracer(Retracer):
 
     def retraceApi(self, api):
-        print '''
-static IDirect3DDevice9 *
-pLastDirect3DDevice9 = NULL;
-
-image::Image *
-retrace::getSnapshot(void) {
-    if (!pLastDirect3DDevice9) {
-        return NULL;
-    }
-    return d3dstate::getRenderTargetImage(pLastDirect3DDevice9);
-}
-
-
-bool
-retrace::dumpState(std::ostream &os)
-{
-    if (!pLastDirect3DDevice9) {
-        return false;
-    }
-    d3dstate::dumpDevice(os, pLastDirect3DDevice9);
-    return true;
-}
-'''
-
         print '// Swizzling mapping for lock addresses'
         print 'static std::map<void *, void *> _maps;'
         print
 
-        self.table_name = 'd3dretrace::d3d_callbacks'
-
         Retracer.retraceApi(self, api)
 
     def invokeFunction(self, function):
@@ -84,7 +58,10 @@ retrace::dumpState(std::ostream &os)
     def invokeInterfaceMethod(self, interface, method):
         # keep track of the last used device for state dumping
         if interface.name in ('IDirect3DDevice9', 'IDirect3DDevice9Ex'):
-            print r'    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'):
@@ -115,38 +92,63 @@ retrace::dumpState(std::ostream &os)
         if method.name == 'Present':
             print r'    d3dretrace::processEvents();'
 
-        # check errors
-        if str(method.type) == 'HRESULT':
-            print r'    if (FAILED(_result)) {'
-            print r'        retrace::warning(call) << "failed\n";'
-            print r'    }'
-
         if method.name in ('Lock', 'LockRect', 'LockBox'):
             print '    VOID *_pbData = NULL;'
             print '    size_t _MappedSize = 0;'
             print '    _getMapInfo(_this, %s, _pbData, _MappedSize);' % ', '.join(method.argNames()[:-1])
-            print '    _maps[_this] = _pbData;'
+            print '    if (_MappedSize) {'
+            print '        _maps[_this] = _pbData;'
+            print '    } else {'
+            print '        return;'
+            print '    }'
         
         if method.name in ('Unlock', 'UnlockRect', 'UnlockBox'):
             print '    VOID *_pbData = 0;'
             print '    _pbData = _maps[_this];'
             print '    if (_pbData) {'
             print '        retrace::delRegionByPointer(_pbData);'
+            print '        _maps[_this] = 0;'
             print '    }'
 
 
-if __name__ == '__main__':
-    print r'''
-#include <string.h>
-
-#include <iostream>
+def main():
+    print r'#include <string.h>'
+    print
+    print r'#include <iostream>'
+    print
+    print r'#include "d3dretrace.hpp"'
+    print
+
+    moduleName = sys.argv[1]
+    support = int(sys.argv[2])
+
+    api = API()
+    
+    if support:
+        if moduleName == 'd3d9':
+            from specs.d3d9 import d3d9
+            print r'#include "d3d9imports.hpp"'
+            print r'#include "d3d9size.hpp"'
+            api.addModule(d3d9)
+            print
+            print '''static d3dretrace::D3DDumper<IDirect3DDevice9> d3d9Dumper;'''
+            print
+        elif moduleName == 'd3d8':
+            from specs.d3d8 import d3d8
+            print r'#include <windows.h>'
+            print r'#include <d3d8.h>'
+            print r'#include "d3d8size.hpp"'
+            api.addModule(d3d8)
+            print
+            #print '''static d3dretrace::D3DDumper<IDirect3DDevice8> d3d8Dumper;'''
+            print
+        else:
+            assert False
 
-#include "d3d9imports.hpp"
-#include "d3d9size.hpp"
-#include "d3dretrace.hpp"
-#include "d3d9state.hpp"
+    retracer = D3DRetracer()
+    retracer.table_name = 'd3dretrace::%s_callbacks' % moduleName
+    retracer.retraceApi(api)
 
-'''
 
-    retracer = D3DRetracer()
-    retracer.retraceModule(d3d9)
+if __name__ == '__main__':
+    main()