1 | /* $Id: VBoxDispD3DIf.cpp 44528 2013-02-04 14:27:54Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | * VBoxVideo Display D3D User mode dll
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2012 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 "VBoxDispD3DIf.h"
|
---|
20 | #include "VBoxDispD3DCmn.h"
|
---|
21 |
|
---|
22 | #include <iprt/assert.h>
|
---|
23 |
|
---|
24 | void VBoxDispD3DClose(VBOXDISPD3D *pD3D)
|
---|
25 | {
|
---|
26 | FreeLibrary(pD3D->hD3DLib);
|
---|
27 | pD3D->hD3DLib = NULL;
|
---|
28 | }
|
---|
29 |
|
---|
30 |
|
---|
31 | HRESULT VBoxDispD3DOpen(VBOXDISPD3D *pD3D)
|
---|
32 | {
|
---|
33 | #ifdef VBOX_WDDM_WOW64
|
---|
34 | pD3D->hD3DLib = LoadLibraryW(L"VBoxD3D9wddm-x86.dll");
|
---|
35 | #else
|
---|
36 | pD3D->hD3DLib = LoadLibraryW(L"VBoxD3D9wddm.dll");
|
---|
37 | #endif
|
---|
38 | if (!pD3D->hD3DLib)
|
---|
39 | {
|
---|
40 | DWORD winErr = GetLastError();
|
---|
41 | WARN((__FUNCTION__": LoadLibraryW failed, winErr = (%d)", winErr));
|
---|
42 | return E_FAIL;
|
---|
43 | }
|
---|
44 |
|
---|
45 | do
|
---|
46 | {
|
---|
47 | pD3D->pfnDirect3DCreate9Ex = (PFNVBOXDISPD3DCREATE9EX)GetProcAddress(pD3D->hD3DLib, "Direct3DCreate9Ex");
|
---|
48 | if (!pD3D->pfnDirect3DCreate9Ex)
|
---|
49 | {
|
---|
50 | WARN(("no Direct3DCreate9Ex"));
|
---|
51 | break;
|
---|
52 | }
|
---|
53 |
|
---|
54 | pD3D->pfnVBoxWineExD3DDev9CreateTexture = (PFNVBOXWINEEXD3DDEV9_CREATETEXTURE)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DDev9CreateTexture");
|
---|
55 | if (!pD3D->pfnVBoxWineExD3DDev9CreateTexture)
|
---|
56 | {
|
---|
57 | WARN(("no VBoxWineExD3DDev9CreateTexture"));
|
---|
58 | break;
|
---|
59 | }
|
---|
60 |
|
---|
61 | pD3D->pfnVBoxWineExD3DDev9CreateCubeTexture = (PFNVBOXWINEEXD3DDEV9_CREATECUBETEXTURE)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DDev9CreateCubeTexture");
|
---|
62 | if (!pD3D->pfnVBoxWineExD3DDev9CreateCubeTexture)
|
---|
63 | {
|
---|
64 | WARN(("no VBoxWineExD3DDev9CreateCubeTexture"));
|
---|
65 | break;
|
---|
66 | }
|
---|
67 |
|
---|
68 | pD3D->pfnVBoxWineExD3DDev9CreateVolumeTexture = (PFNVBOXWINEEXD3DDEV9_CREATEVOLUMETEXTURE)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DDev9CreateVolumeTexture");
|
---|
69 | if (!pD3D->pfnVBoxWineExD3DDev9CreateVolumeTexture)
|
---|
70 | {
|
---|
71 | WARN(("no VBoxWineExD3DDev9CreateVolumeTexture"));
|
---|
72 | break;
|
---|
73 | }
|
---|
74 |
|
---|
75 | pD3D->pfnVBoxWineExD3DDev9Flush = (PFNVBOXWINEEXD3DDEV9_FLUSH)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DDev9Flush");
|
---|
76 | if (!pD3D->pfnVBoxWineExD3DDev9Flush)
|
---|
77 | {
|
---|
78 | WARN(("no VBoxWineExD3DDev9Flush"));
|
---|
79 | break;
|
---|
80 | }
|
---|
81 |
|
---|
82 | pD3D->pfnVBoxWineExD3DDev9FlushToHost = (PFNVBOXWINEEXD3DDEV9_FLUSHTOHOST)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DDev9FlushToHost");
|
---|
83 | if (!pD3D->pfnVBoxWineExD3DDev9FlushToHost)
|
---|
84 | {
|
---|
85 | WARN(("no VBoxWineExD3DDev9FlushToHost"));
|
---|
86 | break;
|
---|
87 | }
|
---|
88 |
|
---|
89 | pD3D->pfnVBoxWineExD3DDev9Finish = (PFNVBOXWINEEXD3DDEV9_FINISH)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DDev9Finish");
|
---|
90 | if (!pD3D->pfnVBoxWineExD3DDev9Finish)
|
---|
91 | {
|
---|
92 | WARN(("no VBoxWineExD3DDev9Finish"));
|
---|
93 | break;
|
---|
94 | }
|
---|
95 |
|
---|
96 | pD3D->pfnVBoxWineExD3DDev9VolBlt = (PFNVBOXWINEEXD3DDEV9_VOLBLT)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DDev9VolBlt");
|
---|
97 | if (!pD3D->pfnVBoxWineExD3DDev9VolBlt)
|
---|
98 | {
|
---|
99 | WARN(("no VBoxWineExD3DDev9VolBlt"));
|
---|
100 | break;
|
---|
101 | }
|
---|
102 |
|
---|
103 | pD3D->pfnVBoxWineExD3DDev9VolTexBlt = (PFNVBOXWINEEXD3DDEV9_VOLTEXBLT)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DDev9VolTexBlt");
|
---|
104 | if (!pD3D->pfnVBoxWineExD3DDev9VolTexBlt)
|
---|
105 | {
|
---|
106 | WARN(("no VBoxWineExD3DDev9VolTexBlt"));
|
---|
107 | break;
|
---|
108 | }
|
---|
109 |
|
---|
110 | pD3D->pfnVBoxWineExD3DDev9Term = (PFNVBOXWINEEXD3DDEV9_TERM)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DDev9Term");
|
---|
111 | if (!pD3D->pfnVBoxWineExD3DDev9Term)
|
---|
112 | {
|
---|
113 | WARN(("no VBoxWineExD3DDev9Term"));
|
---|
114 | break;
|
---|
115 | }
|
---|
116 |
|
---|
117 | pD3D->pfnVBoxWineExD3DSwapchain9Present = (PFNVBOXWINEEXD3DSWAPCHAIN9_PRESENT)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DSwapchain9Present");
|
---|
118 | if (!pD3D->pfnVBoxWineExD3DSwapchain9Present)
|
---|
119 | {
|
---|
120 | WARN(("no VBoxWineExD3DSwapchain9Present"));
|
---|
121 | break;
|
---|
122 | }
|
---|
123 |
|
---|
124 | return S_OK;
|
---|
125 |
|
---|
126 | } while (0);
|
---|
127 |
|
---|
128 | VBoxDispD3DClose(pD3D);
|
---|
129 |
|
---|
130 | return E_FAIL;
|
---|
131 | }
|
---|
132 |
|
---|
133 |
|
---|
134 |
|
---|
135 | static FORMATOP gVBoxFormatOps3D[] = {
|
---|
136 | {D3DDDIFMT_A8R8G8B8,
|
---|
137 | FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
|
---|
138 | FORMATOP_SAME_FORMAT_RENDERTARGET|
|
---|
139 | FORMATOP_SAME_FORMAT_UP_TO_ALPHA_RENDERTARGET|
|
---|
140 | FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|FORMATOP_SRGBREAD|
|
---|
141 | FORMATOP_MEMBEROFGROUP_ARGB|
|
---|
142 | FORMATOP_SRGBWRITE|FORMATOP_VERTEXTEXTURE, 0, 0, 0},
|
---|
143 |
|
---|
144 | {D3DDDIFMT_X8R8G8B8,
|
---|
145 | FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
|
---|
146 | FORMATOP_SAME_FORMAT_RENDERTARGET|
|
---|
147 | FORMATOP_DISPLAYMODE|FORMATOP_3DACCELERATION|
|
---|
148 | FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|FORMATOP_SRGBREAD|
|
---|
149 | FORMATOP_MEMBEROFGROUP_ARGB|
|
---|
150 | FORMATOP_SRGBWRITE|FORMATOP_VERTEXTEXTURE, 0, 0, 0},
|
---|
151 |
|
---|
152 | {D3DDDIFMT_A2R10G10B10,
|
---|
153 | FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
|
---|
154 | FORMATOP_SAME_FORMAT_RENDERTARGET|
|
---|
155 | 0|
|
---|
156 | FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|
|
---|
157 | FORMATOP_MEMBEROFGROUP_ARGB|
|
---|
158 | FORMATOP_VERTEXTEXTURE, 0, 0, 0},
|
---|
159 |
|
---|
160 | {D3DDDIFMT_X1R5G5B5,
|
---|
161 | FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
|
---|
162 | FORMATOP_SAME_FORMAT_RENDERTARGET|
|
---|
163 | 0|
|
---|
164 | FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|
|
---|
165 | FORMATOP_MEMBEROFGROUP_ARGB|
|
---|
166 | FORMATOP_VERTEXTEXTURE, 0, 0, 0},
|
---|
167 |
|
---|
168 | {D3DDDIFMT_A1R5G5B5,
|
---|
169 | FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
|
---|
170 | FORMATOP_SAME_FORMAT_RENDERTARGET|
|
---|
171 | FORMATOP_SAME_FORMAT_UP_TO_ALPHA_RENDERTARGET|
|
---|
172 | FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|
|
---|
173 | FORMATOP_MEMBEROFGROUP_ARGB|
|
---|
174 | FORMATOP_VERTEXTEXTURE, 0, 0, 0},
|
---|
175 |
|
---|
176 | {D3DDDIFMT_A4R4G4B4,
|
---|
177 | FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
|
---|
178 | FORMATOP_SAME_FORMAT_RENDERTARGET|
|
---|
179 | FORMATOP_SAME_FORMAT_UP_TO_ALPHA_RENDERTARGET|
|
---|
180 | FORMATOP_OFFSCREENPLAIN|
|
---|
181 | 0|
|
---|
182 | FORMATOP_VERTEXTEXTURE, 0, 0, 0},
|
---|
183 |
|
---|
184 | {D3DDDIFMT_R5G6B5,
|
---|
185 | FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
|
---|
186 | FORMATOP_SAME_FORMAT_RENDERTARGET|
|
---|
187 | FORMATOP_DISPLAYMODE|FORMATOP_3DACCELERATION|
|
---|
188 | FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|
|
---|
189 | FORMATOP_MEMBEROFGROUP_ARGB|
|
---|
190 | FORMATOP_VERTEXTEXTURE, 0, 0, 0},
|
---|
191 |
|
---|
192 | {D3DDDIFMT_L16,
|
---|
193 | FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|
|
---|
194 | 0|
|
---|
195 | 0|
|
---|
196 | FORMATOP_OFFSCREENPLAIN|
|
---|
197 | 0|
|
---|
198 | FORMATOP_VERTEXTEXTURE, 0, 0, 0},
|
---|
199 |
|
---|
200 | {D3DDDIFMT_A8L8,
|
---|
201 | FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|
|
---|
202 | 0|
|
---|
203 | 0|
|
---|
204 | FORMATOP_OFFSCREENPLAIN|
|
---|
205 | 0|
|
---|
206 | FORMATOP_VERTEXTEXTURE, 0, 0, 0},
|
---|
207 |
|
---|
208 | {D3DDDIFMT_A8,
|
---|
209 | FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|
|
---|
210 | 0|
|
---|
211 | 0|
|
---|
212 | FORMATOP_OFFSCREENPLAIN|
|
---|
213 | 0|
|
---|
214 | FORMATOP_VERTEXTEXTURE, 0, 0, 0},
|
---|
215 |
|
---|
216 | {D3DDDIFMT_L8,
|
---|
217 | FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|
|
---|
218 | 0|
|
---|
219 | 0|
|
---|
220 | FORMATOP_OFFSCREENPLAIN|
|
---|
221 | 0|
|
---|
222 | FORMATOP_VERTEXTEXTURE, 0, 0, 0},
|
---|
223 |
|
---|
224 | {D3DDDIFMT_D16, FORMATOP_TEXTURE|FORMATOP_ZSTENCIL|FORMATOP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH, 0, 0, 0},
|
---|
225 | {D3DDDIFMT_D24S8, FORMATOP_TEXTURE|FORMATOP_ZSTENCIL|FORMATOP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH, 0, 0, 0},
|
---|
226 | {D3DDDIFMT_D24X8, FORMATOP_TEXTURE|FORMATOP_ZSTENCIL|FORMATOP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH, 0, 0, 0},
|
---|
227 | {D3DDDIFMT_D16_LOCKABLE, FORMATOP_ZSTENCIL|FORMATOP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH, 0, 0, 0},
|
---|
228 | {D3DDDIFMT_X8D24, FORMATOP_TEXTURE|FORMATOP_ZSTENCIL|FORMATOP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH, 0, 0, 0},
|
---|
229 | {D3DDDIFMT_D32F_LOCKABLE, FORMATOP_TEXTURE|FORMATOP_ZSTENCIL|FORMATOP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH, 0, 0, 0},
|
---|
230 | {D3DDDIFMT_S8D24, FORMATOP_TEXTURE|FORMATOP_ZSTENCIL|FORMATOP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH, 0, 0, 0},
|
---|
231 |
|
---|
232 | {D3DDDIFMT_DXT1,
|
---|
233 | FORMATOP_TEXTURE|FORMATOP_CUBETEXTURE|
|
---|
234 | 0|
|
---|
235 | 0|
|
---|
236 | FORMATOP_OFFSCREENPLAIN|FORMATOP_SRGBREAD|
|
---|
237 | 0|
|
---|
238 | FORMATOP_VERTEXTEXTURE, 0, 0, 0},
|
---|
239 |
|
---|
240 | {D3DDDIFMT_DXT2,
|
---|
241 | FORMATOP_TEXTURE|FORMATOP_CUBETEXTURE|
|
---|
242 | 0|
|
---|
243 | 0|
|
---|
244 | FORMATOP_OFFSCREENPLAIN|FORMATOP_SRGBREAD|
|
---|
245 | 0|
|
---|
246 | FORMATOP_VERTEXTEXTURE, 0, 0, 0},
|
---|
247 |
|
---|
248 | {D3DDDIFMT_DXT3,
|
---|
249 | FORMATOP_TEXTURE|FORMATOP_CUBETEXTURE|
|
---|
250 | 0|
|
---|
251 | 0|
|
---|
252 | FORMATOP_OFFSCREENPLAIN|FORMATOP_SRGBREAD|
|
---|
253 | 0|
|
---|
254 | FORMATOP_VERTEXTEXTURE, 0, 0, 0},
|
---|
255 |
|
---|
256 | {D3DDDIFMT_DXT4,
|
---|
257 | FORMATOP_TEXTURE|FORMATOP_CUBETEXTURE|
|
---|
258 | 0|
|
---|
259 | 0|
|
---|
260 | FORMATOP_OFFSCREENPLAIN|FORMATOP_SRGBREAD|
|
---|
261 | 0|
|
---|
262 | FORMATOP_VERTEXTEXTURE, 0, 0, 0},
|
---|
263 |
|
---|
264 | {D3DDDIFMT_DXT5,
|
---|
265 | FORMATOP_TEXTURE|FORMATOP_CUBETEXTURE|
|
---|
266 | 0|
|
---|
267 | 0|
|
---|
268 | FORMATOP_OFFSCREENPLAIN|FORMATOP_SRGBREAD|
|
---|
269 | 0|
|
---|
270 | FORMATOP_VERTEXTEXTURE, 0, 0, 0},
|
---|
271 |
|
---|
272 | {D3DDDIFMT_X8L8V8U8,
|
---|
273 | FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|
|
---|
274 | 0|
|
---|
275 | 0|
|
---|
276 | 0|
|
---|
277 | FORMATOP_BUMPMAP|
|
---|
278 | FORMATOP_VERTEXTEXTURE, 0, 0, 0},
|
---|
279 |
|
---|
280 | {D3DDDIFMT_A2W10V10U10,
|
---|
281 | FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|
|
---|
282 | 0|
|
---|
283 | 0|
|
---|
284 | 0|
|
---|
285 | FORMATOP_BUMPMAP|
|
---|
286 | FORMATOP_VERTEXTEXTURE, 0, 0, 0},
|
---|
287 |
|
---|
288 | {D3DDDIFMT_V8U8,
|
---|
289 | FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|
|
---|
290 | 0|
|
---|
291 | 0|
|
---|
292 | 0|
|
---|
293 | FORMATOP_BUMPMAP|
|
---|
294 | FORMATOP_VERTEXTEXTURE, 0, 0, 0},
|
---|
295 |
|
---|
296 | {D3DDDIFMT_Q8W8V8U8,
|
---|
297 | FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
|
---|
298 | 0|
|
---|
299 | 0|
|
---|
300 | FORMATOP_OFFSCREENPLAIN|
|
---|
301 | FORMATOP_BUMPMAP|
|
---|
302 | FORMATOP_VERTEXTEXTURE, 0, 0, 0},
|
---|
303 |
|
---|
304 | {D3DDDIFMT_CxV8U8, FORMATOP_NOFILTER|FORMATOP_NOALPHABLEND|FORMATOP_NOTEXCOORDWRAPNORMIP, 0, 0, 0},
|
---|
305 |
|
---|
306 | {D3DDDIFMT_R16F,
|
---|
307 | FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
|
---|
308 | FORMATOP_SAME_FORMAT_RENDERTARGET|
|
---|
309 | 0|
|
---|
310 | FORMATOP_OFFSCREENPLAIN|
|
---|
311 | 0|
|
---|
312 | FORMATOP_VERTEXTEXTURE, 0, 0, 0},
|
---|
313 |
|
---|
314 | {D3DDDIFMT_R32F,
|
---|
315 | FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
|
---|
316 | FORMATOP_SAME_FORMAT_RENDERTARGET|
|
---|
317 | 0|
|
---|
318 | FORMATOP_OFFSCREENPLAIN|
|
---|
319 | 0|
|
---|
320 | FORMATOP_VERTEXTEXTURE, 0, 0, 0},
|
---|
321 |
|
---|
322 | {D3DDDIFMT_G16R16F,
|
---|
323 | FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
|
---|
324 | FORMATOP_SAME_FORMAT_RENDERTARGET|
|
---|
325 | 0|
|
---|
326 | FORMATOP_OFFSCREENPLAIN|
|
---|
327 | 0|
|
---|
328 | FORMATOP_VERTEXTEXTURE, 0, 0, 0},
|
---|
329 |
|
---|
330 | {D3DDDIFMT_G32R32F,
|
---|
331 | FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
|
---|
332 | FORMATOP_SAME_FORMAT_RENDERTARGET|
|
---|
333 | 0|
|
---|
334 | FORMATOP_OFFSCREENPLAIN|
|
---|
335 | 0|
|
---|
336 | FORMATOP_VERTEXTEXTURE, 0, 0, 0},
|
---|
337 |
|
---|
338 | {D3DDDIFMT_A16B16G16R16F,
|
---|
339 | FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
|
---|
340 | FORMATOP_SAME_FORMAT_RENDERTARGET|
|
---|
341 | 0|
|
---|
342 | FORMATOP_OFFSCREENPLAIN|
|
---|
343 | 0|
|
---|
344 | FORMATOP_VERTEXTEXTURE, 0, 0, 0},
|
---|
345 |
|
---|
346 | {D3DDDIFMT_A32B32G32R32F,
|
---|
347 | FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
|
---|
348 | FORMATOP_SAME_FORMAT_RENDERTARGET|
|
---|
349 | 0|
|
---|
350 | FORMATOP_OFFSCREENPLAIN|
|
---|
351 | 0|
|
---|
352 | FORMATOP_VERTEXTEXTURE, 0, 0, 0},
|
---|
353 |
|
---|
354 | {D3DDDIFMT_G16R16,
|
---|
355 | FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
|
---|
356 | FORMATOP_SAME_FORMAT_RENDERTARGET|
|
---|
357 | 0|
|
---|
358 | FORMATOP_OFFSCREENPLAIN|
|
---|
359 | 0|
|
---|
360 | FORMATOP_VERTEXTEXTURE, 0, 0, 0},
|
---|
361 |
|
---|
362 | {D3DDDIFMT_A16B16G16R16,
|
---|
363 | FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
|
---|
364 | FORMATOP_SAME_FORMAT_RENDERTARGET|
|
---|
365 | 0|
|
---|
366 | FORMATOP_OFFSCREENPLAIN|
|
---|
367 | 0|
|
---|
368 | FORMATOP_VERTEXTEXTURE, 0, 0, 0},
|
---|
369 |
|
---|
370 | {D3DDDIFMT_V16U16,
|
---|
371 | FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|
|
---|
372 | 0|
|
---|
373 | 0|
|
---|
374 | 0|
|
---|
375 | FORMATOP_BUMPMAP|
|
---|
376 | FORMATOP_VERTEXTEXTURE, 0, 0, 0},
|
---|
377 |
|
---|
378 | {D3DDDIFMT_P8, FORMATOP_DISPLAYMODE|FORMATOP_3DACCELERATION|FORMATOP_OFFSCREENPLAIN, 0, 0, 0},
|
---|
379 |
|
---|
380 | {D3DDDIFMT_UYVY,
|
---|
381 | 0|
|
---|
382 | 0|
|
---|
383 | 0|
|
---|
384 | FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|
|
---|
385 | FORMATOP_NOFILTER|
|
---|
386 | FORMATOP_NOALPHABLEND|
|
---|
387 | FORMATOP_NOTEXCOORDWRAPNORMIP, 0, 0, 0},
|
---|
388 |
|
---|
389 | {D3DDDIFMT_YUY2,
|
---|
390 | 0|
|
---|
391 | 0|
|
---|
392 | 0|
|
---|
393 | FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|
|
---|
394 | FORMATOP_NOFILTER|
|
---|
395 | FORMATOP_NOALPHABLEND|
|
---|
396 | FORMATOP_NOTEXCOORDWRAPNORMIP, 0, 0, 0},
|
---|
397 |
|
---|
398 | {D3DDDIFMT_Q16W16V16U16,
|
---|
399 | FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
|
---|
400 | FORMATOP_SAME_FORMAT_RENDERTARGET|
|
---|
401 | 0|
|
---|
402 | FORMATOP_OFFSCREENPLAIN|
|
---|
403 | FORMATOP_BUMPMAP|FORMATOP_DMAP|
|
---|
404 | FORMATOP_VERTEXTEXTURE, 0, 0, 0},
|
---|
405 |
|
---|
406 | {D3DDDIFMT_X8B8G8R8,
|
---|
407 | FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
|
---|
408 | FORMATOP_SAME_FORMAT_RENDERTARGET|
|
---|
409 | FORMATOP_SAME_FORMAT_UP_TO_ALPHA_RENDERTARGET|
|
---|
410 | FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|FORMATOP_SRGBREAD|
|
---|
411 | FORMATOP_DMAP|FORMATOP_MEMBEROFGROUP_ARGB|
|
---|
412 | FORMATOP_SRGBWRITE|FORMATOP_AUTOGENMIPMAP|FORMATOP_VERTEXTEXTURE|
|
---|
413 | FORMATOP_OVERLAY, 0, 0, 0},
|
---|
414 |
|
---|
415 | {D3DDDIFMT_BINARYBUFFER, FORMATOP_OFFSCREENPLAIN, 0, 0, 0},
|
---|
416 |
|
---|
417 | {D3DDDIFMT_A4L4,
|
---|
418 | FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|
|
---|
419 | 0|
|
---|
420 | 0|
|
---|
421 | FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|
|
---|
422 | FORMATOP_DMAP|
|
---|
423 | FORMATOP_VERTEXTEXTURE, 0, 0, 0},
|
---|
424 |
|
---|
425 | {D3DDDIFMT_A2B10G10R10,
|
---|
426 | FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
|
---|
427 | FORMATOP_SAME_FORMAT_RENDERTARGET|
|
---|
428 | 0|
|
---|
429 | FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|
|
---|
430 | FORMATOP_DMAP|FORMATOP_MEMBEROFGROUP_ARGB|
|
---|
431 | FORMATOP_AUTOGENMIPMAP|FORMATOP_VERTEXTEXTURE, 0, 0, 0},
|
---|
432 | };
|
---|
433 |
|
---|
434 | static FORMATOP gVBoxFormatOpsBase[] = {
|
---|
435 | {D3DDDIFMT_X8R8G8B8, FORMATOP_DISPLAYMODE, 0, 0, 0},
|
---|
436 |
|
---|
437 | {D3DDDIFMT_R8G8B8, FORMATOP_DISPLAYMODE, 0, 0, 0},
|
---|
438 |
|
---|
439 | {D3DDDIFMT_R5G6B5, FORMATOP_DISPLAYMODE, 0, 0, 0},
|
---|
440 |
|
---|
441 | {D3DDDIFMT_P8, FORMATOP_DISPLAYMODE, 0, 0, 0},
|
---|
442 | };
|
---|
443 |
|
---|
444 | static DDSURFACEDESC gVBoxSurfDescsBase[] = {
|
---|
445 | {
|
---|
446 | sizeof (DDSURFACEDESC), /* DWORD dwSize; */
|
---|
447 | DDSD_CAPS | DDSD_PIXELFORMAT, /* DWORD dwFlags; */
|
---|
448 | 0, /* DWORD dwHeight; */
|
---|
449 | 0, /* DWORD dwWidth; */
|
---|
450 | {
|
---|
451 | 0, /* Union */
|
---|
452 | /* LONG lPitch; */
|
---|
453 | /* DWORD dwLinearSize; */
|
---|
454 | },
|
---|
455 | 0, /* DWORD dwBackBufferCount; */
|
---|
456 | {
|
---|
457 | 0, /* Union */
|
---|
458 | /* DWORD dwMipMapCount; */
|
---|
459 | /* DWORD dwZBufferBitDepth; */
|
---|
460 | /* DWORD dwRefreshRate; */
|
---|
461 | },
|
---|
462 | 0, /* DWORD dwAlphaBitDepth; */
|
---|
463 | 0, /* DWORD dwReserved; */
|
---|
464 | NULL, /* LPVOID lpSurface; */
|
---|
465 | {
|
---|
466 | 0, /* DWORD dwColorSpaceLowValue; */
|
---|
467 | 0, /* DWORD dwColorSpaceHighValue; */
|
---|
468 | }, /* DDCOLORKEY ddckCKDestOverlay; */
|
---|
469 | {
|
---|
470 | 0, /* DWORD dwColorSpaceLowValue; */
|
---|
471 | 0, /* DWORD dwColorSpaceHighValue; */
|
---|
472 | }, /* DDCOLORKEY ddckCKDestBlt; */
|
---|
473 | {
|
---|
474 | 0, /* DWORD dwColorSpaceLowValue; */
|
---|
475 | 0, /* DWORD dwColorSpaceHighValue; */
|
---|
476 | }, /* DDCOLORKEY ddckCKSrcOverlay; */
|
---|
477 | {
|
---|
478 | 0, /* DWORD dwColorSpaceLowValue; */
|
---|
479 | 0, /* DWORD dwColorSpaceHighValue; */
|
---|
480 | }, /* DDCOLORKEY ddckCKSrcBlt; */
|
---|
481 | {
|
---|
482 | sizeof (DDPIXELFORMAT), /* DWORD dwSize; */
|
---|
483 | DDPF_RGB, /* DWORD dwFlags; */
|
---|
484 | 0, /* DWORD dwFourCC; */
|
---|
485 | {
|
---|
486 | 32, /* union */
|
---|
487 | /* DWORD dwRGBBitCount; */
|
---|
488 | /* DWORD dwYUVBitCount; */
|
---|
489 | /* DWORD dwZBufferBitDepth; */
|
---|
490 | /* DWORD dwAlphaBitDepth; */
|
---|
491 | /* DWORD dwLuminanceBitCount; */
|
---|
492 | /* DWORD dwBumpBitCount; */
|
---|
493 | },
|
---|
494 | {
|
---|
495 | 0xff0000, /* union */
|
---|
496 | /* DWORD dwRBitMask; */
|
---|
497 | /* DWORD dwYBitMask; */
|
---|
498 | /* DWORD dwStencilBitDepth; */
|
---|
499 | /* DWORD dwLuminanceBitMask; */
|
---|
500 | /* DWORD dwBumpDuBitMask; */
|
---|
501 | },
|
---|
502 | {
|
---|
503 | 0xff00,
|
---|
504 | /* DWORD dwGBitMask; */
|
---|
505 | /* DWORD dwUBitMask; */
|
---|
506 | /* DWORD dwZBitMask; */
|
---|
507 | /* DWORD dwBumpDvBitMask; */
|
---|
508 | },
|
---|
509 | {
|
---|
510 | 0xff,
|
---|
511 | /* DWORD dwBBitMask; */
|
---|
512 | /* DWORD dwVBitMask; */
|
---|
513 | /* DWORD dwStencilBitMask; */
|
---|
514 | /* DWORD dwBumpLuminanceBitMask; */
|
---|
515 | },
|
---|
516 | {
|
---|
517 | 0,
|
---|
518 | /* DWORD dwRGBAlphaBitMask; */
|
---|
519 | /* DWORD dwYUVAlphaBitMask; */
|
---|
520 | /* DWORD dwLuminanceAlphaBitMask; */
|
---|
521 | /* DWORD dwRGBZBitMask; */
|
---|
522 | /* DWORD dwYUVZBitMask; */
|
---|
523 | },
|
---|
524 | }, /* DDPIXELFORMAT ddpfPixelFormat; */
|
---|
525 | {
|
---|
526 | DDSCAPS_BACKBUFFER
|
---|
527 | | DDSCAPS_COMPLEX
|
---|
528 | | DDSCAPS_FLIP
|
---|
529 | | DDSCAPS_FRONTBUFFER
|
---|
530 | | DDSCAPS_LOCALVIDMEM
|
---|
531 | | DDSCAPS_PRIMARYSURFACE
|
---|
532 | | DDSCAPS_VIDEOMEMORY
|
---|
533 | | DDSCAPS_VISIBLE /* DWORD dwCaps; */
|
---|
534 | } /* DDSCAPS ddsCaps; */
|
---|
535 | },
|
---|
536 | {
|
---|
537 | sizeof (DDSURFACEDESC), /* DWORD dwSize; */
|
---|
538 | DDSD_CAPS | DDSD_PIXELFORMAT, /* DWORD dwFlags; */
|
---|
539 | 0, /* DWORD dwHeight; */
|
---|
540 | 0, /* DWORD dwWidth; */
|
---|
541 | {
|
---|
542 | 0, /* Union */
|
---|
543 | /* LONG lPitch; */
|
---|
544 | /* DWORD dwLinearSize; */
|
---|
545 | },
|
---|
546 | 0, /* DWORD dwBackBufferCount; */
|
---|
547 | {
|
---|
548 | 0, /* Union */
|
---|
549 | /* DWORD dwMipMapCount; */
|
---|
550 | /* DWORD dwZBufferBitDepth; */
|
---|
551 | /* DWORD dwRefreshRate; */
|
---|
552 | },
|
---|
553 | 0, /* DWORD dwAlphaBitDepth; */
|
---|
554 | 0, /* DWORD dwReserved; */
|
---|
555 | NULL, /* LPVOID lpSurface; */
|
---|
556 | {
|
---|
557 | 0, /* DWORD dwColorSpaceLowValue; */
|
---|
558 | 0, /* DWORD dwColorSpaceHighValue; */
|
---|
559 | }, /* DDCOLORKEY ddckCKDestOverlay; */
|
---|
560 | {
|
---|
561 | 0, /* DWORD dwColorSpaceLowValue; */
|
---|
562 | 0, /* DWORD dwColorSpaceHighValue; */
|
---|
563 | }, /* DDCOLORKEY ddckCKDestBlt; */
|
---|
564 | {
|
---|
565 | 0, /* DWORD dwColorSpaceLowValue; */
|
---|
566 | 0, /* DWORD dwColorSpaceHighValue; */
|
---|
567 | }, /* DDCOLORKEY ddckCKSrcOverlay; */
|
---|
568 | {
|
---|
569 | 0, /* DWORD dwColorSpaceLowValue; */
|
---|
570 | 0, /* DWORD dwColorSpaceHighValue; */
|
---|
571 | }, /* DDCOLORKEY ddckCKSrcBlt; */
|
---|
572 | {
|
---|
573 | sizeof (DDPIXELFORMAT), /* DWORD dwSize; */
|
---|
574 | DDPF_RGB, /* DWORD dwFlags; */
|
---|
575 | 0, /* DWORD dwFourCC; */
|
---|
576 | {
|
---|
577 | 24, /* union */
|
---|
578 | /* DWORD dwRGBBitCount; */
|
---|
579 | /* DWORD dwYUVBitCount; */
|
---|
580 | /* DWORD dwZBufferBitDepth; */
|
---|
581 | /* DWORD dwAlphaBitDepth; */
|
---|
582 | /* DWORD dwLuminanceBitCount; */
|
---|
583 | /* DWORD dwBumpBitCount; */
|
---|
584 | },
|
---|
585 | {
|
---|
586 | 0xff0000, /* union */
|
---|
587 | /* DWORD dwRBitMask; */
|
---|
588 | /* DWORD dwYBitMask; */
|
---|
589 | /* DWORD dwStencilBitDepth; */
|
---|
590 | /* DWORD dwLuminanceBitMask; */
|
---|
591 | /* DWORD dwBumpDuBitMask; */
|
---|
592 | },
|
---|
593 | {
|
---|
594 | 0xff00,
|
---|
595 | /* DWORD dwGBitMask; */
|
---|
596 | /* DWORD dwUBitMask; */
|
---|
597 | /* DWORD dwZBitMask; */
|
---|
598 | /* DWORD dwBumpDvBitMask; */
|
---|
599 | },
|
---|
600 | {
|
---|
601 | 0xff,
|
---|
602 | /* DWORD dwBBitMask; */
|
---|
603 | /* DWORD dwVBitMask; */
|
---|
604 | /* DWORD dwStencilBitMask; */
|
---|
605 | /* DWORD dwBumpLuminanceBitMask; */
|
---|
606 | },
|
---|
607 | {
|
---|
608 | 0,
|
---|
609 | /* DWORD dwRGBAlphaBitMask; */
|
---|
610 | /* DWORD dwYUVAlphaBitMask; */
|
---|
611 | /* DWORD dwLuminanceAlphaBitMask; */
|
---|
612 | /* DWORD dwRGBZBitMask; */
|
---|
613 | /* DWORD dwYUVZBitMask; */
|
---|
614 | },
|
---|
615 | }, /* DDPIXELFORMAT ddpfPixelFormat; */
|
---|
616 | {
|
---|
617 | DDSCAPS_BACKBUFFER
|
---|
618 | | DDSCAPS_COMPLEX
|
---|
619 | | DDSCAPS_FLIP
|
---|
620 | | DDSCAPS_FRONTBUFFER
|
---|
621 | | DDSCAPS_LOCALVIDMEM
|
---|
622 | | DDSCAPS_PRIMARYSURFACE
|
---|
623 | | DDSCAPS_VIDEOMEMORY
|
---|
624 | | DDSCAPS_VISIBLE /* DWORD dwCaps; */
|
---|
625 | } /* DDSCAPS ddsCaps; */
|
---|
626 | },
|
---|
627 | {
|
---|
628 | sizeof (DDSURFACEDESC), /* DWORD dwSize; */
|
---|
629 | DDSD_CAPS | DDSD_PIXELFORMAT, /* DWORD dwFlags; */
|
---|
630 | 0, /* DWORD dwHeight; */
|
---|
631 | 0, /* DWORD dwWidth; */
|
---|
632 | {
|
---|
633 | 0, /* Union */
|
---|
634 | /* LONG lPitch; */
|
---|
635 | /* DWORD dwLinearSize; */
|
---|
636 | },
|
---|
637 | 0, /* DWORD dwBackBufferCount; */
|
---|
638 | {
|
---|
639 | 0, /* Union */
|
---|
640 | /* DWORD dwMipMapCount; */
|
---|
641 | /* DWORD dwZBufferBitDepth; */
|
---|
642 | /* DWORD dwRefreshRate; */
|
---|
643 | },
|
---|
644 | 0, /* DWORD dwAlphaBitDepth; */
|
---|
645 | 0, /* DWORD dwReserved; */
|
---|
646 | NULL, /* LPVOID lpSurface; */
|
---|
647 | {
|
---|
648 | 0, /* DWORD dwColorSpaceLowValue; */
|
---|
649 | 0, /* DWORD dwColorSpaceHighValue; */
|
---|
650 | }, /* DDCOLORKEY ddckCKDestOverlay; */
|
---|
651 | {
|
---|
652 | 0, /* DWORD dwColorSpaceLowValue; */
|
---|
653 | 0, /* DWORD dwColorSpaceHighValue; */
|
---|
654 | }, /* DDCOLORKEY ddckCKDestBlt; */
|
---|
655 | {
|
---|
656 | 0, /* DWORD dwColorSpaceLowValue; */
|
---|
657 | 0, /* DWORD dwColorSpaceHighValue; */
|
---|
658 | }, /* DDCOLORKEY ddckCKSrcOverlay; */
|
---|
659 | {
|
---|
660 | 0, /* DWORD dwColorSpaceLowValue; */
|
---|
661 | 0, /* DWORD dwColorSpaceHighValue; */
|
---|
662 | }, /* DDCOLORKEY ddckCKSrcBlt; */
|
---|
663 | {
|
---|
664 | sizeof (DDPIXELFORMAT), /* DWORD dwSize; */
|
---|
665 | DDPF_RGB, /* DWORD dwFlags; */
|
---|
666 | 0, /* DWORD dwFourCC; */
|
---|
667 | {
|
---|
668 | 16, /* union */
|
---|
669 | /* DWORD dwRGBBitCount; */
|
---|
670 | /* DWORD dwYUVBitCount; */
|
---|
671 | /* DWORD dwZBufferBitDepth; */
|
---|
672 | /* DWORD dwAlphaBitDepth; */
|
---|
673 | /* DWORD dwLuminanceBitCount; */
|
---|
674 | /* DWORD dwBumpBitCount; */
|
---|
675 | },
|
---|
676 | {
|
---|
677 | 0xf800, /* union */
|
---|
678 | /* DWORD dwRBitMask; */
|
---|
679 | /* DWORD dwYBitMask; */
|
---|
680 | /* DWORD dwStencilBitDepth; */
|
---|
681 | /* DWORD dwLuminanceBitMask; */
|
---|
682 | /* DWORD dwBumpDuBitMask; */
|
---|
683 | },
|
---|
684 | {
|
---|
685 | 0x7e0,
|
---|
686 | /* DWORD dwGBitMask; */
|
---|
687 | /* DWORD dwUBitMask; */
|
---|
688 | /* DWORD dwZBitMask; */
|
---|
689 | /* DWORD dwBumpDvBitMask; */
|
---|
690 | },
|
---|
691 | {
|
---|
692 | 0x1f,
|
---|
693 | /* DWORD dwBBitMask; */
|
---|
694 | /* DWORD dwVBitMask; */
|
---|
695 | /* DWORD dwStencilBitMask; */
|
---|
696 | /* DWORD dwBumpLuminanceBitMask; */
|
---|
697 | },
|
---|
698 | {
|
---|
699 | 0,
|
---|
700 | /* DWORD dwRGBAlphaBitMask; */
|
---|
701 | /* DWORD dwYUVAlphaBitMask; */
|
---|
702 | /* DWORD dwLuminanceAlphaBitMask; */
|
---|
703 | /* DWORD dwRGBZBitMask; */
|
---|
704 | /* DWORD dwYUVZBitMask; */
|
---|
705 | },
|
---|
706 | }, /* DDPIXELFORMAT ddpfPixelFormat; */
|
---|
707 | {
|
---|
708 | DDSCAPS_BACKBUFFER
|
---|
709 | | DDSCAPS_COMPLEX
|
---|
710 | | DDSCAPS_FLIP
|
---|
711 | | DDSCAPS_FRONTBUFFER
|
---|
712 | | DDSCAPS_LOCALVIDMEM
|
---|
713 | | DDSCAPS_PRIMARYSURFACE
|
---|
714 | | DDSCAPS_VIDEOMEMORY
|
---|
715 | | DDSCAPS_VISIBLE /* DWORD dwCaps; */
|
---|
716 | } /* DDSCAPS ddsCaps; */
|
---|
717 | },
|
---|
718 | };
|
---|
719 |
|
---|
720 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
721 |
|
---|
722 | static void vboxVhwaPopulateOverlayFourccSurfDesc(DDSURFACEDESC *pDesc, uint32_t fourcc)
|
---|
723 | {
|
---|
724 | memset(pDesc, 0, sizeof (DDSURFACEDESC));
|
---|
725 |
|
---|
726 | pDesc->dwSize = sizeof (DDSURFACEDESC);
|
---|
727 | pDesc->dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT;
|
---|
728 | pDesc->ddpfPixelFormat.dwSize = sizeof (DDPIXELFORMAT);
|
---|
729 | pDesc->ddpfPixelFormat.dwFlags = DDPF_FOURCC;
|
---|
730 | pDesc->ddpfPixelFormat.dwFourCC = fourcc;
|
---|
731 | pDesc->ddsCaps.dwCaps = DDSCAPS_BACKBUFFER
|
---|
732 | | DDSCAPS_COMPLEX
|
---|
733 | | DDSCAPS_FLIP
|
---|
734 | | DDSCAPS_FRONTBUFFER
|
---|
735 | | DDSCAPS_LOCALVIDMEM
|
---|
736 | | DDSCAPS_OVERLAY
|
---|
737 | | DDSCAPS_VIDEOMEMORY
|
---|
738 | | DDSCAPS_VISIBLE;
|
---|
739 | }
|
---|
740 |
|
---|
741 | static bool vboxPixFormatMatch(DDPIXELFORMAT *pFormat1, DDPIXELFORMAT *pFormat2)
|
---|
742 | {
|
---|
743 | return !memcmp(pFormat1, pFormat2, sizeof (DDPIXELFORMAT));
|
---|
744 | }
|
---|
745 |
|
---|
746 | HRESULT vboxSurfDescMerge(DDSURFACEDESC *paDescs, uint32_t *pcDescs, uint32_t cMaxDescs, DDSURFACEDESC *pDesc)
|
---|
747 | {
|
---|
748 | uint32_t cDescs = *pcDescs;
|
---|
749 |
|
---|
750 | Assert(cMaxDescs >= cDescs);
|
---|
751 | Assert(pDesc->dwFlags == (DDSD_CAPS | DDSD_PIXELFORMAT));
|
---|
752 | if (pDesc->dwFlags != (DDSD_CAPS | DDSD_PIXELFORMAT))
|
---|
753 | return E_INVALIDARG;
|
---|
754 |
|
---|
755 | for (uint32_t i = 0; i < cDescs; ++i)
|
---|
756 | {
|
---|
757 | DDSURFACEDESC *pCur = &paDescs[i];
|
---|
758 | if (vboxPixFormatMatch(&pCur->ddpfPixelFormat, &pDesc->ddpfPixelFormat))
|
---|
759 | {
|
---|
760 | if (pDesc->dwFlags & DDSD_CAPS)
|
---|
761 | {
|
---|
762 | pCur->dwFlags |= DDSD_CAPS;
|
---|
763 | pCur->ddsCaps.dwCaps |= pDesc->ddsCaps.dwCaps;
|
---|
764 | }
|
---|
765 | return S_OK;
|
---|
766 | }
|
---|
767 | }
|
---|
768 |
|
---|
769 | if (cMaxDescs > cDescs)
|
---|
770 | {
|
---|
771 | paDescs[cDescs] = *pDesc;
|
---|
772 | ++cDescs;
|
---|
773 | *pcDescs = cDescs;
|
---|
774 | return VINF_SUCCESS;
|
---|
775 | }
|
---|
776 | return E_FAIL;
|
---|
777 | }
|
---|
778 |
|
---|
779 | HRESULT vboxFormatOpsMerge(FORMATOP *paOps, uint32_t *pcOps, uint32_t cMaxOps, FORMATOP *pOp)
|
---|
780 | {
|
---|
781 | uint32_t cOps = *pcOps;
|
---|
782 |
|
---|
783 | Assert(cMaxOps >= cOps);
|
---|
784 |
|
---|
785 | for (uint32_t i = 0; i < cOps; ++i)
|
---|
786 | {
|
---|
787 | FORMATOP *pCur = &paOps[i];
|
---|
788 | if (pCur->Format == pOp->Format)
|
---|
789 | {
|
---|
790 | pCur->Operations |= pOp->Operations;
|
---|
791 | Assert(pCur->FlipMsTypes == pOp->FlipMsTypes);
|
---|
792 | Assert(pCur->BltMsTypes == pOp->BltMsTypes);
|
---|
793 | Assert(pCur->PrivateFormatBitCount == pOp->PrivateFormatBitCount);
|
---|
794 | return S_OK;
|
---|
795 | }
|
---|
796 | }
|
---|
797 |
|
---|
798 | if (cMaxOps > cOps)
|
---|
799 | {
|
---|
800 | paOps[cOps] = *pOp;
|
---|
801 | ++cOps;
|
---|
802 | *pcOps = cOps;
|
---|
803 | return VINF_SUCCESS;
|
---|
804 | }
|
---|
805 | return E_FAIL;
|
---|
806 | }
|
---|
807 |
|
---|
808 | HRESULT VBoxDispD3DGlobal2DFormatsInit(PVBOXWDDMDISP_ADAPTER pAdapter)
|
---|
809 | {
|
---|
810 | HRESULT hr = S_OK;
|
---|
811 | memset(&pAdapter->D3D, 0, sizeof (pAdapter->D3D));
|
---|
812 | memset(&pAdapter->Formats, 0, sizeof (pAdapter->Formats));
|
---|
813 |
|
---|
814 | /* just calc the max number of formats */
|
---|
815 | uint32_t cFormats = RT_ELEMENTS(gVBoxFormatOpsBase);
|
---|
816 | uint32_t cSurfDescs = RT_ELEMENTS(gVBoxSurfDescsBase);
|
---|
817 | uint32_t cOverlayFormats = 0;
|
---|
818 | for (uint32_t i = 0; i < pAdapter->cHeads; ++i)
|
---|
819 | {
|
---|
820 | VBOXDISPVHWA_INFO *pVhwa = &pAdapter->aHeads[i].Vhwa;
|
---|
821 | if (pVhwa->Settings.fFlags & VBOXVHWA_F_ENABLED)
|
---|
822 | {
|
---|
823 | cOverlayFormats += pVhwa->Settings.cFormats;
|
---|
824 | }
|
---|
825 | }
|
---|
826 |
|
---|
827 | cFormats += cOverlayFormats;
|
---|
828 | cSurfDescs += cOverlayFormats;
|
---|
829 |
|
---|
830 | uint32_t cbFormatOps = cFormats * sizeof (FORMATOP);
|
---|
831 | cbFormatOps = (cbFormatOps + 7) & ~3;
|
---|
832 | /* ensure the surf descs are 8 byte aligned */
|
---|
833 | uint32_t offSurfDescs = (cbFormatOps + 7) & ~3;
|
---|
834 | uint32_t cbSurfDescs = cSurfDescs * sizeof (DDSURFACEDESC);
|
---|
835 | uint32_t cbBuf = offSurfDescs + cbSurfDescs;
|
---|
836 | uint8_t* pvBuf = (uint8_t*)RTMemAllocZ(cbBuf);
|
---|
837 | if (pvBuf)
|
---|
838 | {
|
---|
839 | pAdapter->Formats.paFormstOps = (FORMATOP*)pvBuf;
|
---|
840 | memcpy ((void*)pAdapter->Formats.paFormstOps , gVBoxFormatOpsBase, sizeof (gVBoxFormatOpsBase));
|
---|
841 | pAdapter->Formats.cFormstOps = RT_ELEMENTS(gVBoxFormatOpsBase);
|
---|
842 |
|
---|
843 | FORMATOP fo = {D3DDDIFMT_UNKNOWN, 0, 0, 0, 0};
|
---|
844 | for (uint32_t i = 0; i < pAdapter->cHeads; ++i)
|
---|
845 | {
|
---|
846 | VBOXDISPVHWA_INFO *pVhwa = &pAdapter->aHeads[i].Vhwa;
|
---|
847 | if (pVhwa->Settings.fFlags & VBOXVHWA_F_ENABLED)
|
---|
848 | {
|
---|
849 | for (uint32_t j = 0; j < pVhwa->Settings.cFormats; ++j)
|
---|
850 | {
|
---|
851 | fo.Format = pVhwa->Settings.aFormats[j];
|
---|
852 | fo.Operations = FORMATOP_OVERLAY;
|
---|
853 | hr = vboxFormatOpsMerge((FORMATOP *)pAdapter->Formats.paFormstOps, &pAdapter->Formats.cFormstOps, cFormats, &fo);
|
---|
854 | if (FAILED(hr))
|
---|
855 | {
|
---|
856 | WARN(("vboxFormatOpsMerge failed, hr 0x%x", hr));
|
---|
857 | }
|
---|
858 | }
|
---|
859 | }
|
---|
860 | }
|
---|
861 |
|
---|
862 | pAdapter->Formats.paSurfDescs = (DDSURFACEDESC*)(pvBuf + offSurfDescs);
|
---|
863 | memcpy ((void*)pAdapter->Formats.paSurfDescs , gVBoxSurfDescsBase, sizeof (gVBoxSurfDescsBase));
|
---|
864 | pAdapter->Formats.cSurfDescs = RT_ELEMENTS(gVBoxSurfDescsBase);
|
---|
865 |
|
---|
866 | DDSURFACEDESC sd;
|
---|
867 | for (uint32_t i = 0; i < pAdapter->cHeads; ++i)
|
---|
868 | {
|
---|
869 | VBOXDISPVHWA_INFO *pVhwa = &pAdapter->aHeads[i].Vhwa;
|
---|
870 | if (pVhwa->Settings.fFlags & VBOXVHWA_F_ENABLED)
|
---|
871 | {
|
---|
872 | for (uint32_t j = 0; j < pVhwa->Settings.cFormats; ++j)
|
---|
873 | {
|
---|
874 | uint32_t fourcc = vboxWddmFormatToFourcc(pVhwa->Settings.aFormats[j]);
|
---|
875 | if (fourcc)
|
---|
876 | {
|
---|
877 | vboxVhwaPopulateOverlayFourccSurfDesc(&sd, fourcc);
|
---|
878 | hr = vboxSurfDescMerge((DDSURFACEDESC *)pAdapter->Formats.paSurfDescs, &pAdapter->Formats.cSurfDescs, cSurfDescs, &sd);
|
---|
879 | if (FAILED(hr))
|
---|
880 | {
|
---|
881 | WARN(("vboxFormatOpsMerge failed, hr 0x%x", hr));
|
---|
882 | }
|
---|
883 | }
|
---|
884 | }
|
---|
885 | }
|
---|
886 | }
|
---|
887 | }
|
---|
888 | else
|
---|
889 | {
|
---|
890 | WARN(("RTMemAllocZ failed"));
|
---|
891 | return E_FAIL;
|
---|
892 | }
|
---|
893 | return S_OK;
|
---|
894 | }
|
---|
895 |
|
---|
896 | void VBoxDispD3DGlobal2DFormatsTerm(PVBOXWDDMDISP_ADAPTER pAdapter)
|
---|
897 | {
|
---|
898 | if (pAdapter->Formats.paFormstOps)
|
---|
899 | RTMemFree((void *)pAdapter->Formats.paFormstOps);
|
---|
900 | }
|
---|
901 |
|
---|
902 | #endif
|
---|
903 |
|
---|
904 | static CRITICAL_SECTION g_VBoxDispD3DGlobalCritSect;
|
---|
905 | static VBOXWDDMDISP_D3D g_VBoxDispD3DGlobalD3D;
|
---|
906 | static VBOXWDDMDISP_FORMATS g_VBoxDispD3DGlobalD3DFormats;
|
---|
907 | static uint32_t g_cVBoxDispD3DGlobalOpens;
|
---|
908 |
|
---|
909 | void vboxDispD3DGlobalLock()
|
---|
910 | {
|
---|
911 | EnterCriticalSection(&g_VBoxDispD3DGlobalCritSect);
|
---|
912 | }
|
---|
913 |
|
---|
914 | void vboxDispD3DGlobalUnlock()
|
---|
915 | {
|
---|
916 | LeaveCriticalSection(&g_VBoxDispD3DGlobalCritSect);
|
---|
917 | }
|
---|
918 |
|
---|
919 | void VBoxDispD3DGlobalInit()
|
---|
920 | {
|
---|
921 | g_cVBoxDispD3DGlobalOpens = 0;
|
---|
922 | InitializeCriticalSection(&g_VBoxDispD3DGlobalCritSect);
|
---|
923 | }
|
---|
924 |
|
---|
925 | void VBoxDispD3DGlobalTerm()
|
---|
926 | {
|
---|
927 | DeleteCriticalSection(&g_VBoxDispD3DGlobalCritSect);
|
---|
928 | }
|
---|
929 |
|
---|
930 | static void vboxDispD3DGlobalD3DFormatsInit(PVBOXWDDMDISP_FORMATS pFormats)
|
---|
931 | {
|
---|
932 | memset(pFormats, 0, sizeof (pFormats));
|
---|
933 | pFormats->paFormstOps = gVBoxFormatOps3D;
|
---|
934 | pFormats->cFormstOps = RT_ELEMENTS(gVBoxFormatOps3D);
|
---|
935 | }
|
---|
936 |
|
---|
937 |
|
---|
938 | //#define D3DDEVCAPS_FLOATTLVERTEX 0x00000001
|
---|
939 | //#define D3DPMISCCAPS_FOGINFVF 0x00002000
|
---|
940 | //#define D3DPRASTERCAPS_SUBPIXEL 0x00000020
|
---|
941 | //#define D3DPRASTERCAPS_STIPPLE 0x00000200
|
---|
942 | //#define D3DPTEXTURECAPS_TRANSPARENCY 0x00000008
|
---|
943 |
|
---|
944 | static HRESULT vboxWddmGetD3D9Caps(PVBOXWDDMDISP_D3D pD3D, D3DCAPS9 *pCaps)
|
---|
945 | {
|
---|
946 | HRESULT hr = pD3D->pD3D9If->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, pCaps);
|
---|
947 | if (FAILED(hr))
|
---|
948 | {
|
---|
949 | WARN(("GetDeviceCaps failed hr(0x%x)",hr));
|
---|
950 | return hr;
|
---|
951 | }
|
---|
952 |
|
---|
953 | /* needed for Windows Media Player to work properly */
|
---|
954 | pCaps->Caps |= D3DCAPS_READ_SCANLINE;
|
---|
955 | pCaps->Caps2 |= 0x00080000 /*D3DCAPS2_CANRENDERWINDOWED*/;
|
---|
956 | pCaps->Caps2 |= D3DCAPS2_CANSHARERESOURCE;
|
---|
957 | pCaps->DevCaps |= D3DDEVCAPS_FLOATTLVERTEX /* <- must be set according to the docs */
|
---|
958 | /*| D3DDEVCAPS_HWVERTEXBUFFER | D3DDEVCAPS_HWINDEXBUFFER | D3DDEVCAPS_SUBVOLUMELOCK */;
|
---|
959 | pCaps->PrimitiveMiscCaps |= D3DPMISCCAPS_INDEPENDENTWRITEMASKS
|
---|
960 | | D3DPMISCCAPS_FOGINFVF
|
---|
961 | | D3DPMISCCAPS_SEPARATEALPHABLEND | D3DPMISCCAPS_MRTINDEPENDENTBITDEPTHS;
|
---|
962 | pCaps->RasterCaps |= D3DPRASTERCAPS_SUBPIXEL | D3DPRASTERCAPS_STIPPLE | D3DPRASTERCAPS_ZBIAS | D3DPRASTERCAPS_COLORPERSPECTIVE /* keep */;
|
---|
963 | pCaps->TextureCaps |= D3DPTEXTURECAPS_TRANSPARENCY | D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE;
|
---|
964 | pCaps->TextureAddressCaps |= D3DPTADDRESSCAPS_MIRRORONCE;
|
---|
965 | pCaps->VolumeTextureAddressCaps |= D3DPTADDRESSCAPS_MIRRORONCE;
|
---|
966 | pCaps->StencilCaps |= D3DSTENCILCAPS_TWOSIDED;
|
---|
967 | pCaps->DeclTypes |= D3DDTCAPS_FLOAT16_2 | D3DDTCAPS_FLOAT16_4;
|
---|
968 | pCaps->VertexTextureFilterCaps |= D3DPTFILTERCAPS_MINFPOINT | D3DPTFILTERCAPS_MAGFPOINT;
|
---|
969 | pCaps->GuardBandLeft = -8192.;
|
---|
970 | pCaps->GuardBandTop = -8192.;
|
---|
971 | pCaps->GuardBandRight = 8192.;
|
---|
972 | pCaps->GuardBandBottom = 8192.;
|
---|
973 | pCaps->VS20Caps.DynamicFlowControlDepth = 24;
|
---|
974 | pCaps->VS20Caps.NumTemps = D3DVS20_MAX_NUMTEMPS;
|
---|
975 | pCaps->PS20Caps.DynamicFlowControlDepth = 24;
|
---|
976 | pCaps->PS20Caps.NumTemps = D3DVS20_MAX_NUMTEMPS;
|
---|
977 |
|
---|
978 | /* workaround for wine not returning InstructionSlots correctly for shaders v3.0 */
|
---|
979 | if ((pCaps->VertexShaderVersion & 0xff00) == 0x0300)
|
---|
980 | {
|
---|
981 | pCaps->MaxVertexShader30InstructionSlots = RT_MIN(32768, pCaps->MaxVertexShader30InstructionSlots);
|
---|
982 | pCaps->MaxPixelShader30InstructionSlots = RT_MIN(32768, pCaps->MaxPixelShader30InstructionSlots);
|
---|
983 | }
|
---|
984 | #if defined(DEBUG)
|
---|
985 | if ((pCaps->VertexShaderVersion & 0xff00) == 0x0300)
|
---|
986 | {
|
---|
987 | Assert(pCaps->MaxVertexShader30InstructionSlots >= 512);
|
---|
988 | Assert(pCaps->MaxVertexShader30InstructionSlots <= 32768);
|
---|
989 | Assert(pCaps->MaxPixelShader30InstructionSlots >= 512);
|
---|
990 | Assert(pCaps->MaxPixelShader30InstructionSlots <= 32768);
|
---|
991 | }
|
---|
992 | else if ((pCaps->VertexShaderVersion & 0xff00) == 0x0200)
|
---|
993 | {
|
---|
994 | Assert(pCaps->MaxVertexShader30InstructionSlots == 0);
|
---|
995 | Assert(pCaps->MaxPixelShader30InstructionSlots == 0);
|
---|
996 | }
|
---|
997 | else
|
---|
998 | {
|
---|
999 | WARN(("incorect shader caps!"));
|
---|
1000 | }
|
---|
1001 | #endif
|
---|
1002 |
|
---|
1003 | vboxDispDumpD3DCAPS9(pCaps);
|
---|
1004 |
|
---|
1005 | return S_OK;
|
---|
1006 | }
|
---|
1007 |
|
---|
1008 | static void vboxDispD3DGlobalDoClose(PVBOXWDDMDISP_D3D pD3D)
|
---|
1009 | {
|
---|
1010 | pD3D->pD3D9If->Release();
|
---|
1011 | VBoxDispD3DClose(&pD3D->D3D);
|
---|
1012 | }
|
---|
1013 |
|
---|
1014 | static HRESULT vboxDispD3DGlobalDoOpen(PVBOXWDDMDISP_D3D pD3D)
|
---|
1015 | {
|
---|
1016 | memset(pD3D, 0, sizeof (*pD3D));
|
---|
1017 | HRESULT hr = VBoxDispD3DOpen(&pD3D->D3D);
|
---|
1018 | if (SUCCEEDED(hr))
|
---|
1019 | {
|
---|
1020 | hr = pD3D->D3D.pfnDirect3DCreate9Ex(D3D_SDK_VERSION, &pD3D->pD3D9If);
|
---|
1021 | if (SUCCEEDED(hr))
|
---|
1022 | {
|
---|
1023 | hr = vboxWddmGetD3D9Caps(pD3D, &pD3D->Caps);
|
---|
1024 | if (SUCCEEDED(hr))
|
---|
1025 | {
|
---|
1026 | pD3D->cMaxSimRTs = pD3D->Caps.NumSimultaneousRTs;
|
---|
1027 | Assert(pD3D->cMaxSimRTs);
|
---|
1028 | Assert(pD3D->cMaxSimRTs < UINT32_MAX/2);
|
---|
1029 | LOG(("SUCCESS 3D Enabled, pD3D (0x%p)", pD3D));
|
---|
1030 | return S_OK;
|
---|
1031 | }
|
---|
1032 | else
|
---|
1033 | {
|
---|
1034 | WARN(("vboxWddmGetD3D9Caps failed hr = 0x%x", hr));
|
---|
1035 | }
|
---|
1036 | pD3D->pD3D9If->Release();
|
---|
1037 | }
|
---|
1038 | else
|
---|
1039 | {
|
---|
1040 | WARN(("pfnDirect3DCreate9Ex failed hr = 0x%x", hr));
|
---|
1041 | }
|
---|
1042 | VBoxDispD3DClose(&pD3D->D3D);
|
---|
1043 | }
|
---|
1044 | else
|
---|
1045 | {
|
---|
1046 | WARN(("VBoxDispD3DOpen failed hr = 0x%x", hr));
|
---|
1047 | }
|
---|
1048 | return hr;
|
---|
1049 | }
|
---|
1050 |
|
---|
1051 | HRESULT VBoxDispD3DGlobalOpen(PVBOXWDDMDISP_D3D pD3D, PVBOXWDDMDISP_FORMATS pFormats)
|
---|
1052 | {
|
---|
1053 | vboxDispD3DGlobalLock();
|
---|
1054 | if (!g_cVBoxDispD3DGlobalOpens)
|
---|
1055 | {
|
---|
1056 | HRESULT hr = vboxDispD3DGlobalDoOpen(&g_VBoxDispD3DGlobalD3D);
|
---|
1057 | if (!SUCCEEDED(hr))
|
---|
1058 | {
|
---|
1059 | WARN(("vboxDispD3DGlobalDoOpen failed hr = 0x%x", hr));
|
---|
1060 | return hr;
|
---|
1061 | }
|
---|
1062 |
|
---|
1063 | vboxDispD3DGlobalD3DFormatsInit(&g_VBoxDispD3DGlobalD3DFormats);
|
---|
1064 | }
|
---|
1065 | ++g_cVBoxDispD3DGlobalOpens;
|
---|
1066 | vboxDispD3DGlobalUnlock();
|
---|
1067 |
|
---|
1068 | *pD3D = g_VBoxDispD3DGlobalD3D;
|
---|
1069 | *pFormats = g_VBoxDispD3DGlobalD3DFormats;
|
---|
1070 | return S_OK;
|
---|
1071 | }
|
---|
1072 |
|
---|
1073 | void VBoxDispD3DGlobalClose(PVBOXWDDMDISP_D3D pD3D, PVBOXWDDMDISP_FORMATS pFormats)
|
---|
1074 | {
|
---|
1075 | vboxDispD3DGlobalLock();
|
---|
1076 | --g_cVBoxDispD3DGlobalOpens;
|
---|
1077 | if (!g_cVBoxDispD3DGlobalOpens)
|
---|
1078 | {
|
---|
1079 | vboxDispD3DGlobalDoClose(&g_VBoxDispD3DGlobalD3D);
|
---|
1080 | }
|
---|
1081 | vboxDispD3DGlobalUnlock();
|
---|
1082 | }
|
---|