st/nine: Handle Window Occlusion
[mesa.git] / src / gallium / state_trackers / nine / device9ex.c
1 /*
2 * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
22
23 #include "device9.h"
24 #include "device9ex.h"
25 #include "nine_pipe.h"
26 #include "swapchain9ex.h"
27
28 #include "nine_helpers.h"
29
30 #define DBG_CHANNEL DBG_DEVICE
31
32 static HRESULT
33 NineDevice9Ex_ctor( struct NineDevice9Ex *This,
34 struct NineUnknownParams *pParams,
35 struct pipe_screen *pScreen,
36 D3DDEVICE_CREATION_PARAMETERS *pCreationParameters,
37 D3DCAPS9 *pCaps,
38 D3DPRESENT_PARAMETERS *pPresentationParameters,
39 D3DDISPLAYMODEEX *pFullscreenDisplayMode,
40 IDirect3D9Ex *pD3D9Ex,
41 ID3DPresentGroup *pPresentationGroup,
42 struct d3dadapter9_context *pCTX,
43 int minorVersionNum )
44 {
45 DBG("This=%p pParams=%p pScreen=%p pCreationParameters=%p pCaps=%p "
46 "pPresentationParameters=%p pFullscreenDisplayMode=%p "
47 "pD3D9Ex=%p pPresentationGroup=%p pCTX=%p\n",
48 This, pParams, pScreen, pCreationParameters, pCaps,
49 pPresentationParameters, pFullscreenDisplayMode,
50 pD3D9Ex, pPresentationGroup, pCTX);
51
52 return NineDevice9_ctor(&This->base, pParams,
53 pScreen, pCreationParameters, pCaps,
54 pPresentationParameters,
55 (IDirect3D9 *)pD3D9Ex, pPresentationGroup, pCTX,
56 TRUE, pFullscreenDisplayMode, minorVersionNum);
57 }
58
59 static void
60 NineDevice9Ex_dtor( struct NineDevice9Ex *This )
61 {
62 NineDevice9_dtor(&This->base);
63 }
64
65 HRESULT WINAPI
66 NineDevice9Ex_SetConvolutionMonoKernel( struct NineDevice9Ex *This,
67 UINT width,
68 UINT height,
69 float *rows,
70 float *columns )
71 {
72 STUB(D3DERR_INVALIDCALL);
73 }
74
75 HRESULT WINAPI
76 NineDevice9Ex_ComposeRects( struct NineDevice9Ex *This,
77 IDirect3DSurface9 *pSrc,
78 IDirect3DSurface9 *pDst,
79 IDirect3DVertexBuffer9 *pSrcRectDescs,
80 UINT NumRects,
81 IDirect3DVertexBuffer9 *pDstRectDescs,
82 D3DCOMPOSERECTSOP Operation,
83 int Xoffset,
84 int Yoffset )
85 {
86 STUB(D3DERR_INVALIDCALL);
87 }
88
89 HRESULT WINAPI
90 NineDevice9Ex_PresentEx( struct NineDevice9Ex *This,
91 const RECT *pSourceRect,
92 const RECT *pDestRect,
93 HWND hDestWindowOverride,
94 const RGNDATA *pDirtyRegion,
95 DWORD dwFlags )
96 {
97 unsigned i;
98 HRESULT hr;
99
100 DBG("This=%p pSourceRect=%p pDestRect=%p hDestWindowOverride=%p "
101 "pDirtyRegion=%p dwFlags=%d\n",
102 This, pSourceRect, pDestRect, hDestWindowOverride,
103 pDirtyRegion, dwFlags);
104
105 for (i = 0; i < This->base.nswapchains; i++) {
106 hr = NineSwapChain9_Present(This->base.swapchains[i], pSourceRect, pDestRect,
107 hDestWindowOverride, pDirtyRegion, dwFlags);
108 if (FAILED(hr)) { return hr; }
109 }
110
111 return D3D_OK;
112 }
113
114 HRESULT WINAPI
115 NineDevice9Ex_GetGPUThreadPriority( struct NineDevice9Ex *This,
116 INT *pPriority )
117 {
118 STUB(D3DERR_INVALIDCALL);
119 }
120
121 HRESULT WINAPI
122 NineDevice9Ex_SetGPUThreadPriority( struct NineDevice9Ex *This,
123 INT Priority )
124 {
125 STUB(D3DERR_INVALIDCALL);
126 }
127
128 HRESULT WINAPI
129 NineDevice9Ex_WaitForVBlank( struct NineDevice9Ex *This,
130 UINT iSwapChain )
131 {
132 STUB(D3DERR_INVALIDCALL);
133 }
134
135 HRESULT WINAPI
136 NineDevice9Ex_CheckResourceResidency( struct NineDevice9Ex *This,
137 IDirect3DResource9 **pResourceArray,
138 UINT32 NumResources )
139 {
140 STUB(D3DERR_INVALIDCALL);
141 }
142
143 HRESULT WINAPI
144 NineDevice9Ex_SetMaximumFrameLatency( struct NineDevice9Ex *This,
145 UINT MaxLatency )
146 {
147 STUB(D3DERR_INVALIDCALL);
148 }
149
150 HRESULT WINAPI
151 NineDevice9Ex_GetMaximumFrameLatency( struct NineDevice9Ex *This,
152 UINT *pMaxLatency )
153 {
154 STUB(D3DERR_INVALIDCALL);
155 }
156
157 HRESULT WINAPI
158 NineDevice9Ex_CheckDeviceState( struct NineDevice9Ex *This,
159 HWND hDestinationWindow )
160 {
161 DBG("This=%p hDestinationWindow=%p\n",
162 This, hDestinationWindow);
163
164 user_assert(!This->base.swapchains[0]->params.Windowed, D3D_OK);
165
166 if (This->base.params.hFocusWindow == hDestinationWindow) {
167 if (NineSwapChain9_GetOccluded(This->base.swapchains[0]))
168 return S_PRESENT_OCCLUDED;
169 } else if(!NineSwapChain9_GetOccluded(This->base.swapchains[0])) {
170 return S_PRESENT_OCCLUDED;
171 }
172 /* TODO: handle the other return values */
173 return D3D_OK;
174 }
175
176 HRESULT WINAPI
177 NineDevice9Ex_CreateRenderTargetEx( struct NineDevice9Ex *This,
178 UINT Width,
179 UINT Height,
180 D3DFORMAT Format,
181 D3DMULTISAMPLE_TYPE MultiSample,
182 DWORD MultisampleQuality,
183 BOOL Lockable,
184 IDirect3DSurface9 **ppSurface,
185 HANDLE *pSharedHandle,
186 DWORD Usage )
187 {
188 STUB(D3DERR_INVALIDCALL);
189 }
190
191 HRESULT WINAPI
192 NineDevice9Ex_CreateOffscreenPlainSurfaceEx( struct NineDevice9Ex *This,
193 UINT Width,
194 UINT Height,
195 D3DFORMAT Format,
196 D3DPOOL Pool,
197 IDirect3DSurface9 **ppSurface,
198 HANDLE *pSharedHandle,
199 DWORD Usage )
200 {
201 STUB(D3DERR_INVALIDCALL);
202 }
203
204 HRESULT WINAPI
205 NineDevice9Ex_CreateDepthStencilSurfaceEx( struct NineDevice9Ex *This,
206 UINT Width,
207 UINT Height,
208 D3DFORMAT Format,
209 D3DMULTISAMPLE_TYPE MultiSample,
210 DWORD MultisampleQuality,
211 BOOL Discard,
212 IDirect3DSurface9 **ppSurface,
213 HANDLE *pSharedHandle,
214 DWORD Usage )
215 {
216 STUB(D3DERR_INVALIDCALL);
217 }
218
219 HRESULT WINAPI
220 NineDevice9Ex_ResetEx( struct NineDevice9Ex *This,
221 D3DPRESENT_PARAMETERS *pPresentationParameters,
222 D3DDISPLAYMODEEX *pFullscreenDisplayMode )
223 {
224 HRESULT hr = D3D_OK;
225 unsigned i;
226
227 DBG("This=%p pPresentationParameters=%p pFullscreenDisplayMode=%p\n", This, pPresentationParameters, pFullscreenDisplayMode);
228
229 for (i = 0; i < This->base.nswapchains; ++i) {
230 D3DDISPLAYMODEEX *mode = NULL;
231 D3DPRESENT_PARAMETERS *params = &pPresentationParameters[i];
232 if (pFullscreenDisplayMode) mode = &(pFullscreenDisplayMode[i]);
233 hr = NineSwapChain9_Resize(This->base.swapchains[i], params, mode);
234 if (FAILED(hr))
235 break;
236 }
237
238 NineDevice9_SetRenderTarget(
239 (struct NineDevice9 *)This, 0, (IDirect3DSurface9 *)This->base.swapchains[0]->buffers[0]);
240
241 return hr;
242 }
243
244 HRESULT WINAPI
245 NineDevice9Ex_Reset( struct NineDevice9Ex *This,
246 D3DPRESENT_PARAMETERS *pPresentationParameters )
247 {
248 HRESULT hr = D3D_OK;
249 unsigned i;
250
251 DBG("This=%p pPresentationParameters=%p\n", This, pPresentationParameters);
252
253 for (i = 0; i < This->base.nswapchains; ++i) {
254 D3DPRESENT_PARAMETERS *params = &pPresentationParameters[i];
255 hr = NineSwapChain9_Resize(This->base.swapchains[i], params, NULL);
256 if (FAILED(hr))
257 break;
258 }
259
260 nine_pipe_context_clear((struct NineDevice9 *)This);
261 nine_state_clear(&This->base.state, TRUE);
262
263 NineDevice9_SetDefaultState((struct NineDevice9 *)This, TRUE);
264 NineDevice9_SetRenderTarget(
265 (struct NineDevice9 *)This, 0, (IDirect3DSurface9 *)This->base.swapchains[0]->buffers[0]);
266
267 return hr;
268 }
269
270 HRESULT WINAPI
271 NineDevice9Ex_GetDisplayModeEx( struct NineDevice9Ex *This,
272 UINT iSwapChain,
273 D3DDISPLAYMODEEX *pMode,
274 D3DDISPLAYROTATION *pRotation )
275 {
276 struct NineSwapChain9Ex *swapchain;
277
278 DBG("This=%p iSwapChain=%u pMode=%p pRotation=%p\n",
279 This, iSwapChain, pMode, pRotation);
280
281 user_assert(iSwapChain < This->base.nswapchains, D3DERR_INVALIDCALL);
282
283 swapchain = NineSwapChain9Ex(This->base.swapchains[iSwapChain]);
284 return NineSwapChain9Ex_GetDisplayModeEx(swapchain, pMode, pRotation);
285 }
286
287 HRESULT WINAPI
288 NineDevice9Ex_TestCooperativeLevel( struct NineDevice9Ex *This )
289 {
290 return D3D_OK;
291 }
292
293
294 IDirect3DDevice9ExVtbl NineDevice9Ex_vtable = {
295 (void *)NineUnknown_QueryInterface,
296 (void *)NineUnknown_AddRef,
297 (void *)NineUnknown_Release,
298 (void *)NineDevice9Ex_TestCooperativeLevel,
299 (void *)NineDevice9_GetAvailableTextureMem,
300 (void *)NineDevice9_EvictManagedResources,
301 (void *)NineDevice9_GetDirect3D,
302 (void *)NineDevice9_GetDeviceCaps,
303 (void *)NineDevice9_GetDisplayMode,
304 (void *)NineDevice9_GetCreationParameters,
305 (void *)NineDevice9_SetCursorProperties,
306 (void *)NineDevice9_SetCursorPosition,
307 (void *)NineDevice9_ShowCursor,
308 (void *)NineDevice9_CreateAdditionalSwapChain,
309 (void *)NineDevice9_GetSwapChain,
310 (void *)NineDevice9_GetNumberOfSwapChains,
311 (void *)NineDevice9Ex_Reset,
312 (void *)NineDevice9_Present,
313 (void *)NineDevice9_GetBackBuffer,
314 (void *)NineDevice9_GetRasterStatus,
315 (void *)NineDevice9_SetDialogBoxMode,
316 (void *)NineDevice9_SetGammaRamp,
317 (void *)NineDevice9_GetGammaRamp,
318 (void *)NineDevice9_CreateTexture,
319 (void *)NineDevice9_CreateVolumeTexture,
320 (void *)NineDevice9_CreateCubeTexture,
321 (void *)NineDevice9_CreateVertexBuffer,
322 (void *)NineDevice9_CreateIndexBuffer,
323 (void *)NineDevice9_CreateRenderTarget,
324 (void *)NineDevice9_CreateDepthStencilSurface,
325 (void *)NineDevice9_UpdateSurface,
326 (void *)NineDevice9_UpdateTexture,
327 (void *)NineDevice9_GetRenderTargetData,
328 (void *)NineDevice9_GetFrontBufferData,
329 (void *)NineDevice9_StretchRect,
330 (void *)NineDevice9_ColorFill,
331 (void *)NineDevice9_CreateOffscreenPlainSurface,
332 (void *)NineDevice9_SetRenderTarget,
333 (void *)NineDevice9_GetRenderTarget,
334 (void *)NineDevice9_SetDepthStencilSurface,
335 (void *)NineDevice9_GetDepthStencilSurface,
336 (void *)NineDevice9_BeginScene,
337 (void *)NineDevice9_EndScene,
338 (void *)NineDevice9_Clear,
339 (void *)NineDevice9_SetTransform,
340 (void *)NineDevice9_GetTransform,
341 (void *)NineDevice9_MultiplyTransform,
342 (void *)NineDevice9_SetViewport,
343 (void *)NineDevice9_GetViewport,
344 (void *)NineDevice9_SetMaterial,
345 (void *)NineDevice9_GetMaterial,
346 (void *)NineDevice9_SetLight,
347 (void *)NineDevice9_GetLight,
348 (void *)NineDevice9_LightEnable,
349 (void *)NineDevice9_GetLightEnable,
350 (void *)NineDevice9_SetClipPlane,
351 (void *)NineDevice9_GetClipPlane,
352 (void *)NineDevice9_SetRenderState,
353 (void *)NineDevice9_GetRenderState,
354 (void *)NineDevice9_CreateStateBlock,
355 (void *)NineDevice9_BeginStateBlock,
356 (void *)NineDevice9_EndStateBlock,
357 (void *)NineDevice9_SetClipStatus,
358 (void *)NineDevice9_GetClipStatus,
359 (void *)NineDevice9_GetTexture,
360 (void *)NineDevice9_SetTexture,
361 (void *)NineDevice9_GetTextureStageState,
362 (void *)NineDevice9_SetTextureStageState,
363 (void *)NineDevice9_GetSamplerState,
364 (void *)NineDevice9_SetSamplerState,
365 (void *)NineDevice9_ValidateDevice,
366 (void *)NineDevice9_SetPaletteEntries,
367 (void *)NineDevice9_GetPaletteEntries,
368 (void *)NineDevice9_SetCurrentTexturePalette,
369 (void *)NineDevice9_GetCurrentTexturePalette,
370 (void *)NineDevice9_SetScissorRect,
371 (void *)NineDevice9_GetScissorRect,
372 (void *)NineDevice9_SetSoftwareVertexProcessing,
373 (void *)NineDevice9_GetSoftwareVertexProcessing,
374 (void *)NineDevice9_SetNPatchMode,
375 (void *)NineDevice9_GetNPatchMode,
376 (void *)NineDevice9_DrawPrimitive,
377 (void *)NineDevice9_DrawIndexedPrimitive,
378 (void *)NineDevice9_DrawPrimitiveUP,
379 (void *)NineDevice9_DrawIndexedPrimitiveUP,
380 (void *)NineDevice9_ProcessVertices,
381 (void *)NineDevice9_CreateVertexDeclaration,
382 (void *)NineDevice9_SetVertexDeclaration,
383 (void *)NineDevice9_GetVertexDeclaration,
384 (void *)NineDevice9_SetFVF,
385 (void *)NineDevice9_GetFVF,
386 (void *)NineDevice9_CreateVertexShader,
387 (void *)NineDevice9_SetVertexShader,
388 (void *)NineDevice9_GetVertexShader,
389 (void *)NineDevice9_SetVertexShaderConstantF,
390 (void *)NineDevice9_GetVertexShaderConstantF,
391 (void *)NineDevice9_SetVertexShaderConstantI,
392 (void *)NineDevice9_GetVertexShaderConstantI,
393 (void *)NineDevice9_SetVertexShaderConstantB,
394 (void *)NineDevice9_GetVertexShaderConstantB,
395 (void *)NineDevice9_SetStreamSource,
396 (void *)NineDevice9_GetStreamSource,
397 (void *)NineDevice9_SetStreamSourceFreq,
398 (void *)NineDevice9_GetStreamSourceFreq,
399 (void *)NineDevice9_SetIndices,
400 (void *)NineDevice9_GetIndices,
401 (void *)NineDevice9_CreatePixelShader,
402 (void *)NineDevice9_SetPixelShader,
403 (void *)NineDevice9_GetPixelShader,
404 (void *)NineDevice9_SetPixelShaderConstantF,
405 (void *)NineDevice9_GetPixelShaderConstantF,
406 (void *)NineDevice9_SetPixelShaderConstantI,
407 (void *)NineDevice9_GetPixelShaderConstantI,
408 (void *)NineDevice9_SetPixelShaderConstantB,
409 (void *)NineDevice9_GetPixelShaderConstantB,
410 (void *)NineDevice9_DrawRectPatch,
411 (void *)NineDevice9_DrawTriPatch,
412 (void *)NineDevice9_DeletePatch,
413 (void *)NineDevice9_CreateQuery,
414 (void *)NineDevice9Ex_SetConvolutionMonoKernel,
415 (void *)NineDevice9Ex_ComposeRects,
416 (void *)NineDevice9Ex_PresentEx,
417 (void *)NineDevice9Ex_GetGPUThreadPriority,
418 (void *)NineDevice9Ex_SetGPUThreadPriority,
419 (void *)NineDevice9Ex_WaitForVBlank,
420 (void *)NineDevice9Ex_CheckResourceResidency,
421 (void *)NineDevice9Ex_SetMaximumFrameLatency,
422 (void *)NineDevice9Ex_GetMaximumFrameLatency,
423 (void *)NineDevice9Ex_CheckDeviceState,
424 (void *)NineDevice9Ex_CreateRenderTargetEx,
425 (void *)NineDevice9Ex_CreateOffscreenPlainSurfaceEx,
426 (void *)NineDevice9Ex_CreateDepthStencilSurfaceEx,
427 (void *)NineDevice9Ex_ResetEx,
428 (void *)NineDevice9Ex_GetDisplayModeEx
429 };
430
431 static const GUID *NineDevice9Ex_IIDs[] = {
432 &IID_IDirect3DDevice9Ex,
433 &IID_IDirect3DDevice9,
434 &IID_IUnknown,
435 NULL
436 };
437
438 HRESULT
439 NineDevice9Ex_new( struct pipe_screen *pScreen,
440 D3DDEVICE_CREATION_PARAMETERS *pCreationParameters,
441 D3DCAPS9 *pCaps,
442 D3DPRESENT_PARAMETERS *pPresentationParameters,
443 D3DDISPLAYMODEEX *pFullscreenDisplayMode,
444 IDirect3D9Ex *pD3D9Ex,
445 ID3DPresentGroup *pPresentationGroup,
446 struct d3dadapter9_context *pCTX,
447 struct NineDevice9Ex **ppOut,
448 int minorVersionNum )
449 {
450 BOOL lock;
451 lock = !!(pCreationParameters->BehaviorFlags & D3DCREATE_MULTITHREADED);
452
453 NINE_NEW(Device9Ex, ppOut, lock,
454 pScreen, pCreationParameters, pCaps, pPresentationParameters,
455 pFullscreenDisplayMode, pD3D9Ex, pPresentationGroup, pCTX, minorVersionNum );
456 }
457