]> git.cworth.org Git - apitrace/blobdiff - retrace/d3d9retrace.py
d3dretrace: Add d3d9 prefix to d3d9 specific files.
[apitrace] / retrace / d3d9retrace.py
diff --git a/retrace/d3d9retrace.py b/retrace/d3d9retrace.py
new file mode 100644 (file)
index 0000000..14b92ab
--- /dev/null
@@ -0,0 +1,113 @@
+##########################################################################
+#
+# Copyright 2011 Jose Fonseca
+# All Rights Reserved.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+#
+##########################################################################/
+
+
+"""D3D retracer generator."""
+
+
+from dllretrace import DllRetracer as Retracer
+import specs.stdapi as stdapi
+from specs.d3d9 import *
+
+
+class D3DRetracer(Retracer):
+
+    def retraceApi(self, api):
+        print '// Swizzling mapping for lock addresses'
+        print 'static std::map<void *, void *> _locks;'
+        print
+
+        self.table_name = 'd3dretrace::%s_callbacks' % api.name.lower()
+
+        Retracer.retraceApi(self, api)
+
+    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;'
+
+        # create windows as neccessary
+        if method.name in ('CreateDevice', 'CreateDeviceEx', 'CreateAdditionalSwapChain'):
+            print r'    HWND hWnd = d3dretrace::createWindow(pPresentationParameters->BackBufferWidth, pPresentationParameters->BackBufferHeight);'
+            print r'    pPresentationParameters->hDeviceWindow = hWnd;'
+            if 'hFocusWindow' in method.argNames():
+                print r'    hFocusWindow = hWnd;'
+
+        if method.name in ('Reset', 'ResetEx'):
+            print r'    if (pPresentationParameters->Windowed) {'
+            print r'        d3dretrace::resizeWindow(pPresentationParameters->hDeviceWindow, pPresentationParameters->BackBufferWidth, pPresentationParameters->BackBufferHeight);'
+            print r'    }'
+
+        # notify frame has been completed
+        if method.name == 'Present':
+            print r'    retrace::frameComplete(call);'
+            print r'    hDestWindowOverride = NULL;'
+
+        if 'pSharedHandle' in method.argNames():
+            print r'    if (pSharedHandle) {'
+            print r'        retrace::warning(call) << "shared surfaces unsupported\n";'
+            print r'        pSharedHandle = NULL;'
+            print r'    }'
+
+        Retracer.invokeInterfaceMethod(self, interface, method)
+
+        # process events after presents
+        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 _LockedSize = 0;'
+            print '    _getLockInfo(_this, %s, _pbData, _LockedSize);' % ', '.join(method.argNames()[:-1])
+            print '    _locks[_this] = _pbData;'
+        
+        if method.name in ('Unlock', 'UnlockRect', 'UnlockBox'):
+            print '    VOID *_pbData = 0;'
+            print '    _pbData = _locks[_this];'
+            print '    if (_pbData) {'
+            print '        retrace::delRegionByPointer(_pbData);'
+            print '    }'
+
+
+if __name__ == '__main__':
+    print r'''
+#include <string.h>
+
+#include <iostream>
+
+#include "d3d9imports.hpp"
+#include "d3d9size.hpp"
+#include "d3dretrace.hpp"
+
+'''
+
+    retracer = D3DRetracer()
+    retracer.retraceApi(d3d9)