From: José Fonseca Date: Sun, 13 May 2012 08:45:04 +0000 (+0100) Subject: Move d3d window creation to a separate source file. X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=5b130ba1590e5a9853771da249360072baaf71f8;p=apitrace Move d3d window creation to a separate source file. --- diff --git a/retrace/CMakeLists.txt b/retrace/CMakeLists.txt index 8d638d0..00cef67 100644 --- a/retrace/CMakeLists.txt +++ b/retrace/CMakeLists.txt @@ -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 ) diff --git a/retrace/d3dretrace.hpp b/retrace/d3dretrace.hpp index ebfa10a..91f2357 100644 --- a/retrace/d3dretrace.hpp +++ b/retrace/d3dretrace.hpp @@ -26,6 +26,9 @@ #ifndef _D3DRETRACE_HPP_ #define _D3DRETRACE_HPP_ + +#include + #include "retrace.hpp" @@ -44,6 +47,10 @@ extern IDirect3DDevice9 *pLastDirect3DDevice9; extern const retrace::Entry d3d9_callbacks[]; +HWND +createWindow(int width, int height); + + } /* namespace d3dretrace */ diff --git a/retrace/d3dretrace.py b/retrace/d3dretrace.py index cbf57d4..3270161 100644 --- a/retrace/d3dretrace.py +++ b/retrace/d3dretrace.py @@ -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 #include @@ -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 index 0000000..8626a76 --- /dev/null +++ b/retrace/d3dretrace_ws.cpp @@ -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 */