2 * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
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:
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
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. */
24 #include "device9ex.h"
25 #include "nine_pipe.h"
26 #include "swapchain9ex.h"
28 #include "nine_helpers.h"
30 #define DBG_CHANNEL DBG_DEVICE
33 NineDevice9Ex_ctor( struct NineDevice9Ex
*This
,
34 struct NineUnknownParams
*pParams
,
35 struct pipe_screen
*pScreen
,
36 D3DDEVICE_CREATION_PARAMETERS
*pCreationParameters
,
38 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
39 D3DDISPLAYMODEEX
*pFullscreenDisplayMode
,
40 IDirect3D9Ex
*pD3D9Ex
,
41 ID3DPresentGroup
*pPresentationGroup
,
42 struct d3dadapter9_context
*pCTX
,
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
);
52 return NineDevice9_ctor(&This
->base
, pParams
,
53 pScreen
, pCreationParameters
, pCaps
,
54 pPresentationParameters
,
55 (IDirect3D9
*)pD3D9Ex
, pPresentationGroup
, pCTX
,
56 TRUE
, pFullscreenDisplayMode
, minorVersionNum
);
60 NineDevice9Ex_dtor( struct NineDevice9Ex
*This
)
62 NineDevice9_dtor(&This
->base
);
66 NineDevice9Ex_SetConvolutionMonoKernel( struct NineDevice9Ex
*This
,
72 STUB(D3DERR_INVALIDCALL
);
76 NineDevice9Ex_ComposeRects( struct NineDevice9Ex
*This
,
77 IDirect3DSurface9
*pSrc
,
78 IDirect3DSurface9
*pDst
,
79 IDirect3DVertexBuffer9
*pSrcRectDescs
,
81 IDirect3DVertexBuffer9
*pDstRectDescs
,
82 D3DCOMPOSERECTSOP Operation
,
86 STUB(D3DERR_INVALIDCALL
);
90 NineDevice9Ex_PresentEx( struct NineDevice9Ex
*This
,
91 const RECT
*pSourceRect
,
92 const RECT
*pDestRect
,
93 HWND hDestWindowOverride
,
94 const RGNDATA
*pDirtyRegion
,
100 DBG("This=%p pSourceRect=%p pDestRect=%p hDestWindowOverride=%p "
101 "pDirtyRegion=%p dwFlags=%d\n",
102 This
, pSourceRect
, pDestRect
, hDestWindowOverride
,
103 pDirtyRegion
, dwFlags
);
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
; }
115 NineDevice9Ex_GetGPUThreadPriority( struct NineDevice9Ex
*This
,
118 STUB(D3DERR_INVALIDCALL
);
122 NineDevice9Ex_SetGPUThreadPriority( struct NineDevice9Ex
*This
,
125 STUB(D3DERR_INVALIDCALL
);
129 NineDevice9Ex_WaitForVBlank( struct NineDevice9Ex
*This
,
132 STUB(D3DERR_INVALIDCALL
);
136 NineDevice9Ex_CheckResourceResidency( struct NineDevice9Ex
*This
,
137 IDirect3DResource9
**pResourceArray
,
138 UINT32 NumResources
)
140 STUB(D3DERR_INVALIDCALL
);
144 NineDevice9Ex_SetMaximumFrameLatency( struct NineDevice9Ex
*This
,
147 STUB(D3DERR_INVALIDCALL
);
151 NineDevice9Ex_GetMaximumFrameLatency( struct NineDevice9Ex
*This
,
154 STUB(D3DERR_INVALIDCALL
);
158 NineDevice9Ex_CheckDeviceState( struct NineDevice9Ex
*This
,
159 HWND hDestinationWindow
)
161 DBG("This=%p hDestinationWindow=%p\n",
162 This
, hDestinationWindow
);
164 user_assert(!This
->base
.swapchains
[0]->params
.Windowed
, D3D_OK
);
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
;
172 /* TODO: handle the other return values */
177 NineDevice9Ex_CreateRenderTargetEx( struct NineDevice9Ex
*This
,
181 D3DMULTISAMPLE_TYPE MultiSample
,
182 DWORD MultisampleQuality
,
184 IDirect3DSurface9
**ppSurface
,
185 HANDLE
*pSharedHandle
,
188 STUB(D3DERR_INVALIDCALL
);
192 NineDevice9Ex_CreateOffscreenPlainSurfaceEx( struct NineDevice9Ex
*This
,
197 IDirect3DSurface9
**ppSurface
,
198 HANDLE
*pSharedHandle
,
201 STUB(D3DERR_INVALIDCALL
);
205 NineDevice9Ex_CreateDepthStencilSurfaceEx( struct NineDevice9Ex
*This
,
209 D3DMULTISAMPLE_TYPE MultiSample
,
210 DWORD MultisampleQuality
,
212 IDirect3DSurface9
**ppSurface
,
213 HANDLE
*pSharedHandle
,
216 STUB(D3DERR_INVALIDCALL
);
220 NineDevice9Ex_ResetEx( struct NineDevice9Ex
*This
,
221 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
222 D3DDISPLAYMODEEX
*pFullscreenDisplayMode
)
227 DBG("This=%p pPresentationParameters=%p pFullscreenDisplayMode=%p\n", This
, pPresentationParameters
, pFullscreenDisplayMode
);
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
);
238 NineDevice9_SetRenderTarget(
239 (struct NineDevice9
*)This
, 0, (IDirect3DSurface9
*)This
->base
.swapchains
[0]->buffers
[0]);
245 NineDevice9Ex_Reset( struct NineDevice9Ex
*This
,
246 D3DPRESENT_PARAMETERS
*pPresentationParameters
)
251 DBG("This=%p pPresentationParameters=%p\n", This
, pPresentationParameters
);
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
);
260 nine_pipe_context_clear((struct NineDevice9
*)This
);
261 nine_state_clear(&This
->base
.state
, TRUE
);
263 NineDevice9_SetDefaultState((struct NineDevice9
*)This
, TRUE
);
264 NineDevice9_SetRenderTarget(
265 (struct NineDevice9
*)This
, 0, (IDirect3DSurface9
*)This
->base
.swapchains
[0]->buffers
[0]);
271 NineDevice9Ex_GetDisplayModeEx( struct NineDevice9Ex
*This
,
273 D3DDISPLAYMODEEX
*pMode
,
274 D3DDISPLAYROTATION
*pRotation
)
276 struct NineSwapChain9Ex
*swapchain
;
278 DBG("This=%p iSwapChain=%u pMode=%p pRotation=%p\n",
279 This
, iSwapChain
, pMode
, pRotation
);
281 user_assert(iSwapChain
< This
->base
.nswapchains
, D3DERR_INVALIDCALL
);
283 swapchain
= NineSwapChain9Ex(This
->base
.swapchains
[iSwapChain
]);
284 return NineSwapChain9Ex_GetDisplayModeEx(swapchain
, pMode
, pRotation
);
288 NineDevice9Ex_TestCooperativeLevel( struct NineDevice9Ex
*This
)
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
431 static const GUID
*NineDevice9Ex_IIDs
[] = {
432 &IID_IDirect3DDevice9Ex
,
433 &IID_IDirect3DDevice9
,
439 NineDevice9Ex_new( struct pipe_screen
*pScreen
,
440 D3DDEVICE_CREATION_PARAMETERS
*pCreationParameters
,
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
)
451 lock
= !!(pCreationParameters
->BehaviorFlags
& D3DCREATE_MULTITHREADED
);
453 NINE_NEW(Device9Ex
, ppOut
, lock
,
454 pScreen
, pCreationParameters
, pCaps
, pPresentationParameters
,
455 pFullscreenDisplayMode
, pD3D9Ex
, pPresentationGroup
, pCTX
, minorVersionNum
);