1 | /* $Id: d3d9_main.c 20227 2009-06-03 10:25:25Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | * VBox D3D8 dll switcher
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2009 Sun Microsystems, Inc.
|
---|
9 | *
|
---|
10 | * Sun Microsystems, Inc. confidential
|
---|
11 | * All rights reserved
|
---|
12 | */
|
---|
13 |
|
---|
14 | #include "d3d9.h"
|
---|
15 | #include "switcher.h"
|
---|
16 |
|
---|
17 | typedef void (WINAPI *DebugSetMuteProc)(void);
|
---|
18 | typedef IDirect3D9* (WINAPI *Direct3DCreate9Proc)(UINT SDKVersion);
|
---|
19 | typedef HRESULT (WINAPI *Direct3DCreate9ExProc)(UINT SDKVersion, IDirect3D9Ex **direct3d9ex);
|
---|
20 | typedef void* (WINAPI *Direct3DShaderValidatorCreate9Proc)(void);
|
---|
21 | typedef int (WINAPI *D3DPERF_BeginEventProc)(D3DCOLOR color, LPCWSTR name);
|
---|
22 | typedef int (WINAPI *D3DPERF_EndEventProc)(void);
|
---|
23 | typedef DWORD (WINAPI *D3DPERF_GetStatusProc)(void);
|
---|
24 | typedef void (WINAPI *D3DPERF_SetOptionsProc)(DWORD options);
|
---|
25 | typedef BOOL (WINAPI *D3DPERF_QueryRepeatFrameProc)(void);
|
---|
26 | typedef void (WINAPI *D3DPERF_SetMarkerProc)(D3DCOLOR color, LPCWSTR name);
|
---|
27 | typedef void (WINAPI *D3DPERF_SetRegionProc)(D3DCOLOR color, LPCWSTR name);
|
---|
28 |
|
---|
29 | typedef struct _D3D9ExTag
|
---|
30 | {
|
---|
31 | int initialized;
|
---|
32 | const char *vboxName;
|
---|
33 | const char *msName;
|
---|
34 | DebugSetMuteProc pDebugSetMute;
|
---|
35 | Direct3DCreate9Proc pDirect3DCreate9;
|
---|
36 | Direct3DCreate9ExProc pDirect3DCreate9Ex;
|
---|
37 | Direct3DShaderValidatorCreate9Proc pDirect3DShaderValidatorCreate9;
|
---|
38 | D3DPERF_BeginEventProc pD3DPERF_BeginEvent;
|
---|
39 | D3DPERF_EndEventProc pD3DPERF_EndEvent;
|
---|
40 | D3DPERF_GetStatusProc pD3DPERF_GetStatus;
|
---|
41 | D3DPERF_SetOptionsProc pD3DPERF_SetOptions;
|
---|
42 | D3DPERF_QueryRepeatFrameProc pD3DPERF_QueryRepeatFrame;
|
---|
43 | D3DPERF_SetMarkerProc pD3DPERF_SetMarker;
|
---|
44 | D3DPERF_SetRegionProc pD3DPERF_SetRegion;
|
---|
45 | } D3D9Export;
|
---|
46 |
|
---|
47 | static D3D9Export g_swd3d9 = {0, "VBoxD3D9.dll", "MSD3D9.dll",};
|
---|
48 |
|
---|
49 | void FillD3DExports(HANDLE hDLL)
|
---|
50 | {
|
---|
51 | SW_FILLPROC(g_swd3d9, hDLL, DebugSetMute);
|
---|
52 | SW_FILLPROC(g_swd3d9, hDLL, Direct3DCreate9);
|
---|
53 | SW_FILLPROC(g_swd3d9, hDLL, Direct3DCreate9Ex);
|
---|
54 | SW_FILLPROC(g_swd3d9, hDLL, Direct3DShaderValidatorCreate9);
|
---|
55 | SW_FILLPROC(g_swd3d9, hDLL, D3DPERF_BeginEvent);
|
---|
56 | SW_FILLPROC(g_swd3d9, hDLL, D3DPERF_EndEvent);
|
---|
57 | SW_FILLPROC(g_swd3d9, hDLL, D3DPERF_GetStatus);
|
---|
58 | SW_FILLPROC(g_swd3d9, hDLL, D3DPERF_SetOptions);
|
---|
59 | SW_FILLPROC(g_swd3d9, hDLL, D3DPERF_QueryRepeatFrame);
|
---|
60 | SW_FILLPROC(g_swd3d9, hDLL, D3DPERF_SetMarker);
|
---|
61 | SW_FILLPROC(g_swd3d9, hDLL, D3DPERF_SetRegion);
|
---|
62 | }
|
---|
63 |
|
---|
64 | void WINAPI DebugSetMute(void)
|
---|
65 | {
|
---|
66 | SW_CHECKCALL(g_swd3d9, DebugSetMute);
|
---|
67 | g_swd3d9.pDebugSetMute();
|
---|
68 | }
|
---|
69 |
|
---|
70 | IDirect3D9* WINAPI Direct3DCreate9(UINT SDKVersion)
|
---|
71 | {
|
---|
72 | SW_CHECKRET(g_swd3d9, Direct3DCreate9, NULL);
|
---|
73 | return g_swd3d9.pDirect3DCreate9(SDKVersion);
|
---|
74 | }
|
---|
75 |
|
---|
76 | HRESULT WINAPI Direct3DCreate9Ex(UINT SDKVersion, IDirect3D9Ex **direct3d9ex)
|
---|
77 | {
|
---|
78 | SW_CHECKRET(g_swd3d9, Direct3DCreate9Ex, E_FAIL);
|
---|
79 | return g_swd3d9.pDirect3DCreate9Ex(SDKVersion, direct3d9ex);
|
---|
80 | }
|
---|
81 |
|
---|
82 | void* WINAPI Direct3DShaderValidatorCreate9(void)
|
---|
83 | {
|
---|
84 | SW_CHECKRET(g_swd3d9, Direct3DShaderValidatorCreate9, NULL);
|
---|
85 | return g_swd3d9.pDirect3DShaderValidatorCreate9();
|
---|
86 | }
|
---|
87 |
|
---|
88 | int WINAPI D3DPERF_BeginEvent(D3DCOLOR color, LPCWSTR name)
|
---|
89 | {
|
---|
90 | SW_CHECKRET(g_swd3d9, D3DPERF_BeginEvent, -1);
|
---|
91 | return g_swd3d9.pD3DPERF_BeginEvent(color, name);
|
---|
92 | }
|
---|
93 |
|
---|
94 | int WINAPI D3DPERF_EndEvent(void)
|
---|
95 | {
|
---|
96 | SW_CHECKRET(g_swd3d9, D3DPERF_EndEvent, -1);
|
---|
97 | return g_swd3d9.pD3DPERF_EndEvent();
|
---|
98 | }
|
---|
99 |
|
---|
100 | DWORD WINAPI D3DPERF_GetStatus(void)
|
---|
101 | {
|
---|
102 | SW_CHECKRET(g_swd3d9, D3DPERF_EndEvent, 0);
|
---|
103 | return g_swd3d9.pD3DPERF_GetStatus();
|
---|
104 | }
|
---|
105 |
|
---|
106 | void WINAPI D3DPERF_SetOptions(DWORD options)
|
---|
107 | {
|
---|
108 | SW_CHECKCALL(g_swd3d9, D3DPERF_SetOptions);
|
---|
109 | g_swd3d9.pD3DPERF_SetOptions(options);
|
---|
110 | }
|
---|
111 |
|
---|
112 | BOOL WINAPI D3DPERF_QueryRepeatFrame(void)
|
---|
113 | {
|
---|
114 | SW_CHECKRET(g_swd3d9, D3DPERF_QueryRepeatFrame, FALSE);
|
---|
115 | return g_swd3d9.pD3DPERF_QueryRepeatFrame();
|
---|
116 | }
|
---|
117 |
|
---|
118 | void WINAPI D3DPERF_SetMarker(D3DCOLOR color, LPCWSTR name)
|
---|
119 | {
|
---|
120 | SW_CHECKCALL(g_swd3d9, D3DPERF_SetMarker);
|
---|
121 | g_swd3d9.pD3DPERF_SetMarker(color, name);
|
---|
122 | }
|
---|
123 |
|
---|
124 | void WINAPI D3DPERF_SetRegion(D3DCOLOR color, LPCWSTR name)
|
---|
125 | {
|
---|
126 | SW_CHECKCALL(g_swd3d9, D3DPERF_SetRegion);
|
---|
127 | g_swd3d9.pD3DPERF_SetRegion(color, name);
|
---|
128 | }
|
---|