]> git.cworth.org Git - apitrace/commitdiff
Move d3d window creation to a separate source file.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Sun, 13 May 2012 08:45:04 +0000 (09:45 +0100)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Sun, 13 May 2012 08:45:04 +0000 (09:45 +0100)
retrace/CMakeLists.txt
retrace/d3dretrace.hpp
retrace/d3dretrace.py
retrace/d3dretrace_ws.cpp [new file with mode: 0644]

index 8d638d017b677cec50df93927bf2d68e1bc7f643..00cef67af628155df305c34a5882dc89717d61ac 100644 (file)
@@ -149,6 +149,7 @@ if (WIN32 AND DirectX_D3DX9_INCLUDE_DIR)
         retrace_stdc.cpp
         d3dretrace_main.cpp
         d3dretrace_d3d9.cpp
+        d3dretrace_ws.cpp
         d3dstate.cpp
         d3dstate_images.cpp
     )
index ebfa10a3c8d70e2b71e0581f7fffb307585fd939..91f235766284474c0cf412ba7fcf2d8099cc714a 100644 (file)
@@ -26,6 +26,9 @@
 #ifndef _D3DRETRACE_HPP_
 #define _D3DRETRACE_HPP_
 
+
+#include <windows.h>
+
 #include "retrace.hpp"
 
 
@@ -44,6 +47,10 @@ extern IDirect3DDevice9 *pLastDirect3DDevice9;
 extern const retrace::Entry d3d9_callbacks[];
 
 
+HWND
+createWindow(int width, int height);
+
+
 } /* namespace d3dretrace */
 
 
index cbf57d4aab981fe8f1bfa5b59a57bb73efd59661..3270161197f049bb8474cdf07dd914524dd2c2f0 100644 (file)
@@ -34,12 +34,13 @@ from specs.d3d9 import *
 
 class D3DRetracer(Retracer):
 
-    table_name = 'd3dretrace::d3d9_callbacks'
+    def retraceApi(self, api):
+        print 'static const GUID GUID_D3DRETRACE = {0x7D71CAC9,0x7F58,0x432C,{0xA9,0x75,0xA1,0x9F,0xCF,0xCE,0xFD,0x14}};'
+        print
 
-    bufferInterfaceNames = [
-        'IDirect3DVertexBuffer9',
-        'IDirect3DIndexBuffer9',
-    ]
+        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
@@ -48,7 +49,7 @@ class D3DRetracer(Retracer):
 
         # create windows as neccessary
         if method.name in ('CreateDevice', 'CreateDeviceEx'):
-            print r'    HWND hWnd = createWindow(pPresentationParameters->BackBufferWidth, pPresentationParameters->BackBufferHeight);'
+            print r'    HWND hWnd = d3dretrace::createWindow(pPresentationParameters->BackBufferWidth, pPresentationParameters->BackBufferHeight);'
             print r'    hFocusWindow = hWnd;'
             print r'    pPresentationParameters->hDeviceWindow = hWnd;'
 
@@ -74,12 +75,12 @@ class D3DRetracer(Retracer):
             print '    VOID *_pbData = NULL;'
             print '    size_t _LockedSize = 0;'
             print '    _getLockInfo(_this, %s, _pbData, _LockedSize);' % ', '.join(method.argNames()[:-1])
-            print '    _this->SetPrivateData(GUID_APITRACE, &_pbData, sizeof _pbData, 0);'
+            print '    _this->SetPrivateData(GUID_D3DRETRACE, &_pbData, sizeof _pbData, 0);'
         
         if method.name in ('Unlock', 'UnlockRect', 'UnlockBox'):
             print '    VOID *_pbData = 0;'
             print '    DWORD dwSizeOfData = sizeof _pbData;'
-            print '    _this->GetPrivateData(GUID_APITRACE, &_pbData, &dwSizeOfData);'
+            print '    _this->GetPrivateData(GUID_D3DRETRACE, &_pbData, &dwSizeOfData);'
             print '    if (_pbData) {'
             print '        retrace::delRegionByPointer(_pbData);'
             print '    }'
@@ -87,8 +88,6 @@ class D3DRetracer(Retracer):
 
 if __name__ == '__main__':
     print r'''
-#define INITGUID
-
 #include <string.h>
 
 #include <iostream>
@@ -97,145 +96,6 @@ if __name__ == '__main__':
 #include "d3dsize.hpp"
 #include "d3dretrace.hpp"
 
-
-// XXX: Don't duplicate this code.
-
-static LRESULT CALLBACK
-WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
-{
-    MINMAXINFO *pMMI;
-    switch (uMsg) {
-    case WM_GETMINMAXINFO:
-        // Allow to create a window bigger than the desktop
-        pMMI = (MINMAXINFO *)lParam;
-        pMMI->ptMaxSize.x = 60000;
-        pMMI->ptMaxSize.y = 60000;
-        pMMI->ptMaxTrackSize.x = 60000;
-        pMMI->ptMaxTrackSize.y = 60000;
-        break;
-    default:
-        break;
-    }
-
-    return DefWindowProc(hWnd, uMsg, wParam, lParam);
-}
-
-
-DEFINE_GUID(GUID_APITRACE,0X7D71CAC9,0X7F58,0X432C,0XA9,0X75,0XA1,0X9F,0XCF,0XCE,0XFD,0X14);
-
-
-static HWND
-createWindow(int width, int height) {
-    static bool first = TRUE;
-    RECT rect;
-
-    if (first) {
-        WNDCLASS wc;
-        memset(&wc, 0, sizeof wc);
-        wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
-        wc.hCursor = LoadCursor(NULL, IDC_ARROW);
-        wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
-        wc.lpfnWndProc = WndProc;
-        wc.lpszClassName = "d3dretrace";
-        wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
-        RegisterClass(&wc);
-        first = FALSE;
-    }
-
-    DWORD dwExStyle;
-    DWORD dwStyle;
-    HWND hWnd;
-
-    dwExStyle = 0;
-    dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW;
-
-    int x = 0, y = 0;
-
-    rect.left = x;
-    rect.top = y;
-    rect.right = rect.left + width;
-    rect.bottom = rect.top + height;
-
-    AdjustWindowRectEx(&rect, dwStyle, FALSE, dwExStyle);
-
-    hWnd = CreateWindowEx(dwExStyle,
-                          "d3dretrace", /* wc.lpszClassName */
-                          NULL,
-                          dwStyle,
-                          0, /* x */
-                          0, /* y */
-                          rect.right - rect.left, /* width */
-                          rect.bottom - rect.top, /* height */
-                          NULL,
-                          NULL,
-                          NULL,
-                          NULL);
-    ShowWindow(hWnd, SW_SHOW);
-    return hWnd;
-}
-
-
-
-typedef HRESULT
-(WINAPI *PD3DXASSEMBLESHADER)(
-    LPCSTR pSrcData,
-    UINT SrcDataLen,
-    const D3DXMACRO *pDefines,
-    LPD3DXINCLUDE pInclude,
-    DWORD Flags,
-    LPD3DXBUFFER *ppShader,
-    LPD3DXBUFFER *ppErrorMsgs
-);
-
-DWORD *
-extractShader(LPCSTR pSrcData)
-{
-    static BOOL firsttime = TRUE;
-    static HMODULE hD3DXModule = NULL;
-    static PD3DXASSEMBLESHADER pfnD3DXAssembleShader = NULL;
-
-    if (firsttime) {
-        if (!hD3DXModule) {
-            unsigned release;
-            int version;
-            for (release = 0; release <= 1; ++release) {
-                /* Version 41 corresponds to Mar 2009 version of DirectX Runtime / SDK */
-                for (version = 41; version >= 0; --version) {
-                    char filename[256];
-                    _snprintf(filename, sizeof(filename),
-                              "d3dx9%s%s%u.dll", release ? "" : "d", version ? "_" : "", version);
-                    hD3DXModule = LoadLibraryA(filename);
-                    if (hD3DXModule)
-                        goto found;
-                }
-            }
-found:
-            ;
-        }
-
-        if (hD3DXModule) {
-            if (!pfnD3DXAssembleShader) {
-                pfnD3DXAssembleShader = (PD3DXASSEMBLESHADER)GetProcAddress(hD3DXModule, "D3DXAssembleShader");
-            }
-        }
-
-        firsttime = FALSE;
-    }
-
-    if (pfnD3DXAssembleShader) {
-        LPD3DXBUFFER pTokens = NULL;
-        HRESULT hr;
-
-        hr = pfnD3DXAssembleShader(pSrcData, strlen(pSrcData), NULL, NULL, 0, &pTokens, NULL);
-        if (SUCCEEDED(hr)) {
-            return (DWORD *)pTokens->GetBufferPointer();
-        }
-
-        // FIXME: Don't leak pTokens
-    }
-
-    return NULL;
-}
 '''
 
     retracer = D3DRetracer()
diff --git a/retrace/d3dretrace_ws.cpp b/retrace/d3dretrace_ws.cpp
new file mode 100644 (file)
index 0000000..8626a76
--- /dev/null
@@ -0,0 +1,110 @@
+/**************************************************************************
+ *
+ * Copyright 2012 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.
+ *
+ **************************************************************************/
+
+
+#include "d3dretrace.hpp"
+
+
+namespace d3dretrace {
+
+
+// XXX: Don't duplicate this code.
+
+static LRESULT CALLBACK
+WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+    MINMAXINFO *pMMI;
+    switch (uMsg) {
+    case WM_GETMINMAXINFO:
+        // Allow to create a window bigger than the desktop
+        pMMI = (MINMAXINFO *)lParam;
+        pMMI->ptMaxSize.x = 60000;
+        pMMI->ptMaxSize.y = 60000;
+        pMMI->ptMaxTrackSize.x = 60000;
+        pMMI->ptMaxTrackSize.y = 60000;
+        break;
+    default:
+        break;
+    }
+
+    return DefWindowProc(hWnd, uMsg, wParam, lParam);
+}
+
+
+HWND
+createWindow(int width, int height) {
+    static bool first = TRUE;
+    RECT rect;
+
+    if (first) {
+        WNDCLASS wc;
+        memset(&wc, 0, sizeof wc);
+        wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
+        wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+        wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
+        wc.lpfnWndProc = WndProc;
+        wc.lpszClassName = "d3dretrace";
+        wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
+        RegisterClass(&wc);
+        first = FALSE;
+    }
+
+    DWORD dwExStyle;
+    DWORD dwStyle;
+    HWND hWnd;
+
+    dwExStyle = 0;
+    dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW;
+
+    int x = 0, y = 0;
+
+    rect.left = x;
+    rect.top = y;
+    rect.right = rect.left + width;
+    rect.bottom = rect.top + height;
+
+    AdjustWindowRectEx(&rect, dwStyle, FALSE, dwExStyle);
+
+    hWnd = CreateWindowEx(dwExStyle,
+                          "d3dretrace", /* wc.lpszClassName */
+                          NULL,
+                          dwStyle,
+                          0, /* x */
+                          0, /* y */
+                          rect.right - rect.left, /* width */
+                          rect.bottom - rect.top, /* height */
+                          NULL,
+                          NULL,
+                          NULL,
+                          NULL);
+    ShowWindow(hWnd, SW_SHOW);
+    return hWnd;
+}
+
+
+
+
+
+} /* namespace d3dretrace */