1 | /* $Id: d3d9_main.c 40587 2012-03-23 09:08:44Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | * VBox D3D8 dll switcher
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2009 Oracle Corporation
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | */
|
---|
18 |
|
---|
19 | #include "d3d9.h"
|
---|
20 | #include "switcher.h"
|
---|
21 |
|
---|
22 | typedef void (WINAPI *DebugSetMuteProc)(void);
|
---|
23 | typedef IDirect3D9* (WINAPI *Direct3DCreate9Proc)(UINT SDKVersion);
|
---|
24 | typedef HRESULT (WINAPI *Direct3DCreate9ExProc)(UINT SDKVersion, IDirect3D9Ex **direct3d9ex);
|
---|
25 | /* @todo: this does not return a value according to MSDN */
|
---|
26 | typedef void* (WINAPI *Direct3DShaderValidatorCreate9Proc)(void);
|
---|
27 | typedef int (WINAPI *D3DPERF_BeginEventProc)(D3DCOLOR color, LPCWSTR name);
|
---|
28 | typedef int (WINAPI *D3DPERF_EndEventProc)(void);
|
---|
29 | typedef DWORD (WINAPI *D3DPERF_GetStatusProc)(void);
|
---|
30 | typedef void (WINAPI *D3DPERF_SetOptionsProc)(DWORD options);
|
---|
31 | typedef BOOL (WINAPI *D3DPERF_QueryRepeatFrameProc)(void);
|
---|
32 | typedef void (WINAPI *D3DPERF_SetMarkerProc)(D3DCOLOR color, LPCWSTR name);
|
---|
33 | typedef void (WINAPI *D3DPERF_SetRegionProc)(D3DCOLOR color, LPCWSTR name);
|
---|
34 |
|
---|
35 | static void WINAPI vboxDebugSetMuteStub(void)
|
---|
36 | {
|
---|
37 | }
|
---|
38 |
|
---|
39 | static IDirect3D9* WINAPI vboxDirect3DCreate9Stub(UINT SDKVersion)
|
---|
40 | {
|
---|
41 | return NULL;
|
---|
42 | }
|
---|
43 |
|
---|
44 | static HRESULT WINAPI vboxDirect3DCreate9ExStub(UINT SDKVersion, IDirect3D9Ex **direct3d9ex)
|
---|
45 | {
|
---|
46 | if (direct3d9ex)
|
---|
47 | *direct3d9ex = NULL;
|
---|
48 | return E_FAIL;
|
---|
49 | }
|
---|
50 |
|
---|
51 | static void* WINAPI vboxDirect3DShaderValidatorCreate9Stub(void)
|
---|
52 | {
|
---|
53 | return NULL;
|
---|
54 | }
|
---|
55 |
|
---|
56 | static int WINAPI vboxD3DPERF_BeginEventStub(D3DCOLOR color, LPCWSTR name)
|
---|
57 | {
|
---|
58 | return 0;
|
---|
59 | }
|
---|
60 |
|
---|
61 | static int WINAPI vboxD3DPERF_EndEventStub(void)
|
---|
62 | {
|
---|
63 | return 0;
|
---|
64 | }
|
---|
65 |
|
---|
66 | static DWORD WINAPI vboxD3DPERF_GetStatusStub(void)
|
---|
67 | {
|
---|
68 | return 0;
|
---|
69 | }
|
---|
70 |
|
---|
71 | static void WINAPI vboxD3DPERF_SetOptionsStub(DWORD options)
|
---|
72 | {
|
---|
73 |
|
---|
74 | }
|
---|
75 |
|
---|
76 | static BOOL WINAPI vboxD3DPERF_QueryRepeatFrameStub(void)
|
---|
77 | {
|
---|
78 | return 0;
|
---|
79 | }
|
---|
80 |
|
---|
81 | static void WINAPI vboxD3DPERF_SetMarkerStub(D3DCOLOR color, LPCWSTR name)
|
---|
82 | {
|
---|
83 |
|
---|
84 | }
|
---|
85 |
|
---|
86 | static void WINAPI vboxD3DPERF_SetRegionStub(D3DCOLOR color, LPCWSTR name)
|
---|
87 | {
|
---|
88 |
|
---|
89 | }
|
---|
90 |
|
---|
91 |
|
---|
92 | typedef struct _D3D9ExTag
|
---|
93 | {
|
---|
94 | int initialized;
|
---|
95 | const char *vboxName;
|
---|
96 | const char *msName;
|
---|
97 | DebugSetMuteProc pDebugSetMute;
|
---|
98 | Direct3DCreate9Proc pDirect3DCreate9;
|
---|
99 | Direct3DCreate9ExProc pDirect3DCreate9Ex;
|
---|
100 | Direct3DShaderValidatorCreate9Proc pDirect3DShaderValidatorCreate9;
|
---|
101 | D3DPERF_BeginEventProc pD3DPERF_BeginEvent;
|
---|
102 | D3DPERF_EndEventProc pD3DPERF_EndEvent;
|
---|
103 | D3DPERF_GetStatusProc pD3DPERF_GetStatus;
|
---|
104 | D3DPERF_SetOptionsProc pD3DPERF_SetOptions;
|
---|
105 | D3DPERF_QueryRepeatFrameProc pD3DPERF_QueryRepeatFrame;
|
---|
106 | D3DPERF_SetMarkerProc pD3DPERF_SetMarker;
|
---|
107 | D3DPERF_SetRegionProc pD3DPERF_SetRegion;
|
---|
108 | } D3D9Export;
|
---|
109 |
|
---|
110 | #ifdef VBOX_WDDM_WOW64
|
---|
111 | static D3D9Export g_swd3d9 = {0, "VBoxD3D9-x86.dll", "MSD3D9.dll",};
|
---|
112 | #else
|
---|
113 | static D3D9Export g_swd3d9 = {0, "VBoxD3D9.dll", "MSD3D9.dll",};
|
---|
114 | #endif
|
---|
115 |
|
---|
116 | void FillD3DExports(HANDLE hDLL)
|
---|
117 | {
|
---|
118 | SW_FILLPROC(g_swd3d9, hDLL, DebugSetMute);
|
---|
119 | SW_FILLPROC(g_swd3d9, hDLL, Direct3DCreate9);
|
---|
120 | SW_FILLPROC(g_swd3d9, hDLL, Direct3DCreate9Ex);
|
---|
121 | SW_FILLPROC(g_swd3d9, hDLL, Direct3DShaderValidatorCreate9);
|
---|
122 | SW_FILLPROC(g_swd3d9, hDLL, D3DPERF_BeginEvent);
|
---|
123 | SW_FILLPROC(g_swd3d9, hDLL, D3DPERF_EndEvent);
|
---|
124 | SW_FILLPROC(g_swd3d9, hDLL, D3DPERF_GetStatus);
|
---|
125 | SW_FILLPROC(g_swd3d9, hDLL, D3DPERF_SetOptions);
|
---|
126 | SW_FILLPROC(g_swd3d9, hDLL, D3DPERF_QueryRepeatFrame);
|
---|
127 | SW_FILLPROC(g_swd3d9, hDLL, D3DPERF_SetMarker);
|
---|
128 | SW_FILLPROC(g_swd3d9, hDLL, D3DPERF_SetRegion);
|
---|
129 | }
|
---|
130 |
|
---|
131 | void WINAPI DebugSetMute(void)
|
---|
132 | {
|
---|
133 | SW_CHECKCALL(g_swd3d9, DebugSetMute);
|
---|
134 | g_swd3d9.pDebugSetMute();
|
---|
135 | }
|
---|
136 |
|
---|
137 | IDirect3D9* WINAPI Direct3DCreate9(UINT SDKVersion)
|
---|
138 | {
|
---|
139 | SW_CHECKRET(g_swd3d9, Direct3DCreate9, NULL);
|
---|
140 | return g_swd3d9.pDirect3DCreate9(SDKVersion);
|
---|
141 | }
|
---|
142 |
|
---|
143 | HRESULT WINAPI Direct3DCreate9Ex(UINT SDKVersion, IDirect3D9Ex **direct3d9ex)
|
---|
144 | {
|
---|
145 | SW_CHECKRET(g_swd3d9, Direct3DCreate9Ex, E_FAIL);
|
---|
146 | return g_swd3d9.pDirect3DCreate9Ex(SDKVersion, direct3d9ex);
|
---|
147 | }
|
---|
148 |
|
---|
149 | void* WINAPI Direct3DShaderValidatorCreate9(void)
|
---|
150 | {
|
---|
151 | SW_CHECKRET(g_swd3d9, Direct3DShaderValidatorCreate9, NULL);
|
---|
152 | return g_swd3d9.pDirect3DShaderValidatorCreate9();
|
---|
153 | }
|
---|
154 |
|
---|
155 | int WINAPI D3DPERF_BeginEvent(D3DCOLOR color, LPCWSTR name)
|
---|
156 | {
|
---|
157 | SW_CHECKRET(g_swd3d9, D3DPERF_BeginEvent, -1);
|
---|
158 | return g_swd3d9.pD3DPERF_BeginEvent(color, name);
|
---|
159 | }
|
---|
160 |
|
---|
161 | int WINAPI D3DPERF_EndEvent(void)
|
---|
162 | {
|
---|
163 | SW_CHECKRET(g_swd3d9, D3DPERF_EndEvent, -1);
|
---|
164 | return g_swd3d9.pD3DPERF_EndEvent();
|
---|
165 | }
|
---|
166 |
|
---|
167 | DWORD WINAPI D3DPERF_GetStatus(void)
|
---|
168 | {
|
---|
169 | SW_CHECKRET(g_swd3d9, D3DPERF_EndEvent, 0);
|
---|
170 | return g_swd3d9.pD3DPERF_GetStatus();
|
---|
171 | }
|
---|
172 |
|
---|
173 | void WINAPI D3DPERF_SetOptions(DWORD options)
|
---|
174 | {
|
---|
175 | SW_CHECKCALL(g_swd3d9, D3DPERF_SetOptions);
|
---|
176 | g_swd3d9.pD3DPERF_SetOptions(options);
|
---|
177 | }
|
---|
178 |
|
---|
179 | BOOL WINAPI D3DPERF_QueryRepeatFrame(void)
|
---|
180 | {
|
---|
181 | SW_CHECKRET(g_swd3d9, D3DPERF_QueryRepeatFrame, FALSE);
|
---|
182 | return g_swd3d9.pD3DPERF_QueryRepeatFrame();
|
---|
183 | }
|
---|
184 |
|
---|
185 | void WINAPI D3DPERF_SetMarker(D3DCOLOR color, LPCWSTR name)
|
---|
186 | {
|
---|
187 | SW_CHECKCALL(g_swd3d9, D3DPERF_SetMarker);
|
---|
188 | g_swd3d9.pD3DPERF_SetMarker(color, name);
|
---|
189 | }
|
---|
190 |
|
---|
191 | void WINAPI D3DPERF_SetRegion(D3DCOLOR color, LPCWSTR name)
|
---|
192 | {
|
---|
193 | SW_CHECKCALL(g_swd3d9, D3DPERF_SetRegion);
|
---|
194 | g_swd3d9.pD3DPERF_SetRegion(color, name);
|
---|
195 | }
|
---|