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. */
23 #include "device9ex.h"
24 #include "swapchain9ex.h"
26 #include "nine_helpers.h"
28 #define DBG_CHANNEL DBG_DEVICE
31 NineDevice9Ex_ctor( struct NineDevice9Ex
*This
,
32 struct NineUnknownParams
*pParams
,
33 struct pipe_screen
*pScreen
,
34 D3DDEVICE_CREATION_PARAMETERS
*pCreationParameters
,
36 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
37 D3DDISPLAYMODEEX
*pFullscreenDisplayMode
,
38 IDirect3D9Ex
*pD3D9Ex
,
39 ID3DPresentGroup
*pPresentationGroup
,
40 struct d3dadapter9_context
*pCTX
)
42 DBG("This=%p pParams=%p pScreen=%p pCreationParameters=%p pCaps=%p "
43 "pPresentationParameters=%p pFullscreenDisplayMode=%p "
44 "pD3D9Ex=%p pPresentationGroup=%p pCTX=%p\n",
45 This
, pParams
, pScreen
, pCreationParameters
, pCaps
,
46 pPresentationParameters
, pFullscreenDisplayMode
,
47 pD3D9Ex
, pPresentationGroup
, pCTX
);
49 return NineDevice9_ctor(&This
->base
, pParams
,
50 pScreen
, pCreationParameters
, pCaps
,
51 pPresentationParameters
,
52 (IDirect3D9
*)pD3D9Ex
, pPresentationGroup
, pCTX
,
53 TRUE
, pFullscreenDisplayMode
);
57 NineDevice9Ex_dtor( struct NineDevice9Ex
*This
)
59 NineDevice9_dtor(&This
->base
);
63 NineDevice9Ex_SetConvolutionMonoKernel( struct NineDevice9Ex
*This
,
69 STUB(D3DERR_INVALIDCALL
);
73 NineDevice9Ex_ComposeRects( struct NineDevice9Ex
*This
,
74 IDirect3DSurface9
*pSrc
,
75 IDirect3DSurface9
*pDst
,
76 IDirect3DVertexBuffer9
*pSrcRectDescs
,
78 IDirect3DVertexBuffer9
*pDstRectDescs
,
79 D3DCOMPOSERECTSOP Operation
,
83 STUB(D3DERR_INVALIDCALL
);
87 NineDevice9Ex_PresentEx( struct NineDevice9Ex
*This
,
88 const RECT
*pSourceRect
,
89 const RECT
*pDestRect
,
90 HWND hDestWindowOverride
,
91 const RGNDATA
*pDirtyRegion
,
97 DBG("This=%p pSourceRect=%p pDestRect=%p hDestWindowOverride=%p "
98 "pDirtyRegion=%p dwFlags=%d\n",
99 This
, pSourceRect
, pDestRect
, hDestWindowOverride
,
100 pDirtyRegion
, dwFlags
);
102 for (i
= 0; i
< This
->base
.nswapchains
; i
++) {
103 hr
= NineSwapChain9_Present(This
->base
.swapchains
[i
], pSourceRect
, pDestRect
,
104 hDestWindowOverride
, pDirtyRegion
, dwFlags
);
105 if (FAILED(hr
)) { return hr
; }
112 NineDevice9Ex_GetGPUThreadPriority( struct NineDevice9Ex
*This
,
115 STUB(D3DERR_INVALIDCALL
);
119 NineDevice9Ex_SetGPUThreadPriority( struct NineDevice9Ex
*This
,
122 STUB(D3DERR_INVALIDCALL
);
126 NineDevice9Ex_WaitForVBlank( struct NineDevice9Ex
*This
,
129 STUB(D3DERR_INVALIDCALL
);
133 NineDevice9Ex_CheckResourceResidency( struct NineDevice9Ex
*This
,
134 IDirect3DResource9
**pResourceArray
,
135 UINT32 NumResources
)
137 STUB(D3DERR_INVALIDCALL
);
141 NineDevice9Ex_SetMaximumFrameLatency( struct NineDevice9Ex
*This
,
144 STUB(D3DERR_INVALIDCALL
);
148 NineDevice9Ex_GetMaximumFrameLatency( struct NineDevice9Ex
*This
,
151 STUB(D3DERR_INVALIDCALL
);
155 NineDevice9Ex_CheckDeviceState( struct NineDevice9Ex
*This
,
156 HWND hDestinationWindow
)
158 DBG("This=%p hDestinationWindow=%p\n",
159 This
, hDestinationWindow
);
161 /* TODO: handle the other return values */
166 NineDevice9Ex_CreateRenderTargetEx( struct NineDevice9Ex
*This
,
170 D3DMULTISAMPLE_TYPE MultiSample
,
171 DWORD MultisampleQuality
,
173 IDirect3DSurface9
**ppSurface
,
174 HANDLE
*pSharedHandle
,
177 STUB(D3DERR_INVALIDCALL
);
181 NineDevice9Ex_CreateOffscreenPlainSurfaceEx( struct NineDevice9Ex
*This
,
186 IDirect3DSurface9
**ppSurface
,
187 HANDLE
*pSharedHandle
,
190 STUB(D3DERR_INVALIDCALL
);
194 NineDevice9Ex_CreateDepthStencilSurfaceEx( struct NineDevice9Ex
*This
,
198 D3DMULTISAMPLE_TYPE MultiSample
,
199 DWORD MultisampleQuality
,
201 IDirect3DSurface9
**ppSurface
,
202 HANDLE
*pSharedHandle
,
205 STUB(D3DERR_INVALIDCALL
);
209 NineDevice9Ex_ResetEx( struct NineDevice9Ex
*This
,
210 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
211 D3DDISPLAYMODEEX
*pFullscreenDisplayMode
)
216 DBG("This=%p pPresentationParameters=%p pFullscreenDisplayMode=%p\n", This
, pPresentationParameters
, pFullscreenDisplayMode
);
218 for (i
= 0; i
< This
->base
.nswapchains
; ++i
) {
219 D3DDISPLAYMODEEX
*mode
= NULL
;
220 D3DPRESENT_PARAMETERS
*params
= &pPresentationParameters
[i
];
221 if (pFullscreenDisplayMode
) mode
= &(pFullscreenDisplayMode
[i
]);
222 hr
= NineSwapChain9_Resize(This
->base
.swapchains
[i
], params
, mode
);
224 return (hr
== D3DERR_OUTOFVIDEOMEMORY
) ? hr
: D3DERR_DEVICELOST
;
227 NineDevice9_SetRenderTarget(
228 (struct NineDevice9
*)This
, 0, (IDirect3DSurface9
*)This
->base
.swapchains
[0]->buffers
[0]);
235 NineDevice9Ex_GetDisplayModeEx( struct NineDevice9Ex
*This
,
237 D3DDISPLAYMODEEX
*pMode
,
238 D3DDISPLAYROTATION
*pRotation
)
240 struct NineSwapChain9Ex
*swapchain
;
242 DBG("This=%p iSwapChain=%u pMode=%p pRotation=%p\n",
243 This
, iSwapChain
, pMode
, pRotation
);
245 user_assert(iSwapChain
< This
->base
.nswapchains
, D3DERR_INVALIDCALL
);
247 swapchain
= NineSwapChain9Ex(This
->base
.swapchains
[iSwapChain
]);
248 return NineSwapChain9Ex_GetDisplayModeEx(swapchain
, pMode
, pRotation
);
251 IDirect3DDevice9ExVtbl NineDevice9Ex_vtable
= {
252 (void *)NineUnknown_QueryInterface
,
253 (void *)NineUnknown_AddRef
,
254 (void *)NineUnknown_Release
,
255 (void *)NineDevice9_TestCooperativeLevel
,
256 (void *)NineDevice9_GetAvailableTextureMem
,
257 (void *)NineDevice9_EvictManagedResources
,
258 (void *)NineDevice9_GetDirect3D
,
259 (void *)NineDevice9_GetDeviceCaps
,
260 (void *)NineDevice9_GetDisplayMode
,
261 (void *)NineDevice9_GetCreationParameters
,
262 (void *)NineDevice9_SetCursorProperties
,
263 (void *)NineDevice9_SetCursorPosition
,
264 (void *)NineDevice9_ShowCursor
,
265 (void *)NineDevice9_CreateAdditionalSwapChain
,
266 (void *)NineDevice9_GetSwapChain
,
267 (void *)NineDevice9_GetNumberOfSwapChains
,
268 (void *)NineDevice9_Reset
,
269 (void *)NineDevice9_Present
,
270 (void *)NineDevice9_GetBackBuffer
,
271 (void *)NineDevice9_GetRasterStatus
,
272 (void *)NineDevice9_SetDialogBoxMode
,
273 (void *)NineDevice9_SetGammaRamp
,
274 (void *)NineDevice9_GetGammaRamp
,
275 (void *)NineDevice9_CreateTexture
,
276 (void *)NineDevice9_CreateVolumeTexture
,
277 (void *)NineDevice9_CreateCubeTexture
,
278 (void *)NineDevice9_CreateVertexBuffer
,
279 (void *)NineDevice9_CreateIndexBuffer
,
280 (void *)NineDevice9_CreateRenderTarget
,
281 (void *)NineDevice9_CreateDepthStencilSurface
,
282 (void *)NineDevice9_UpdateSurface
,
283 (void *)NineDevice9_UpdateTexture
,
284 (void *)NineDevice9_GetRenderTargetData
,
285 (void *)NineDevice9_GetFrontBufferData
,
286 (void *)NineDevice9_StretchRect
,
287 (void *)NineDevice9_ColorFill
,
288 (void *)NineDevice9_CreateOffscreenPlainSurface
,
289 (void *)NineDevice9_SetRenderTarget
,
290 (void *)NineDevice9_GetRenderTarget
,
291 (void *)NineDevice9_SetDepthStencilSurface
,
292 (void *)NineDevice9_GetDepthStencilSurface
,
293 (void *)NineDevice9_BeginScene
,
294 (void *)NineDevice9_EndScene
,
295 (void *)NineDevice9_Clear
,
296 (void *)NineDevice9_SetTransform
,
297 (void *)NineDevice9_GetTransform
,
298 (void *)NineDevice9_MultiplyTransform
,
299 (void *)NineDevice9_SetViewport
,
300 (void *)NineDevice9_GetViewport
,
301 (void *)NineDevice9_SetMaterial
,
302 (void *)NineDevice9_GetMaterial
,
303 (void *)NineDevice9_SetLight
,
304 (void *)NineDevice9_GetLight
,
305 (void *)NineDevice9_LightEnable
,
306 (void *)NineDevice9_GetLightEnable
,
307 (void *)NineDevice9_SetClipPlane
,
308 (void *)NineDevice9_GetClipPlane
,
309 (void *)NineDevice9_SetRenderState
,
310 (void *)NineDevice9_GetRenderState
,
311 (void *)NineDevice9_CreateStateBlock
,
312 (void *)NineDevice9_BeginStateBlock
,
313 (void *)NineDevice9_EndStateBlock
,
314 (void *)NineDevice9_SetClipStatus
,
315 (void *)NineDevice9_GetClipStatus
,
316 (void *)NineDevice9_GetTexture
,
317 (void *)NineDevice9_SetTexture
,
318 (void *)NineDevice9_GetTextureStageState
,
319 (void *)NineDevice9_SetTextureStageState
,
320 (void *)NineDevice9_GetSamplerState
,
321 (void *)NineDevice9_SetSamplerState
,
322 (void *)NineDevice9_ValidateDevice
,
323 (void *)NineDevice9_SetPaletteEntries
,
324 (void *)NineDevice9_GetPaletteEntries
,
325 (void *)NineDevice9_SetCurrentTexturePalette
,
326 (void *)NineDevice9_GetCurrentTexturePalette
,
327 (void *)NineDevice9_SetScissorRect
,
328 (void *)NineDevice9_GetScissorRect
,
329 (void *)NineDevice9_SetSoftwareVertexProcessing
,
330 (void *)NineDevice9_GetSoftwareVertexProcessing
,
331 (void *)NineDevice9_SetNPatchMode
,
332 (void *)NineDevice9_GetNPatchMode
,
333 (void *)NineDevice9_DrawPrimitive
,
334 (void *)NineDevice9_DrawIndexedPrimitive
,
335 (void *)NineDevice9_DrawPrimitiveUP
,
336 (void *)NineDevice9_DrawIndexedPrimitiveUP
,
337 (void *)NineDevice9_ProcessVertices
,
338 (void *)NineDevice9_CreateVertexDeclaration
,
339 (void *)NineDevice9_SetVertexDeclaration
,
340 (void *)NineDevice9_GetVertexDeclaration
,
341 (void *)NineDevice9_SetFVF
,
342 (void *)NineDevice9_GetFVF
,
343 (void *)NineDevice9_CreateVertexShader
,
344 (void *)NineDevice9_SetVertexShader
,
345 (void *)NineDevice9_GetVertexShader
,
346 (void *)NineDevice9_SetVertexShaderConstantF
,
347 (void *)NineDevice9_GetVertexShaderConstantF
,
348 (void *)NineDevice9_SetVertexShaderConstantI
,
349 (void *)NineDevice9_GetVertexShaderConstantI
,
350 (void *)NineDevice9_SetVertexShaderConstantB
,
351 (void *)NineDevice9_GetVertexShaderConstantB
,
352 (void *)NineDevice9_SetStreamSource
,
353 (void *)NineDevice9_GetStreamSource
,
354 (void *)NineDevice9_SetStreamSourceFreq
,
355 (void *)NineDevice9_GetStreamSourceFreq
,
356 (void *)NineDevice9_SetIndices
,
357 (void *)NineDevice9_GetIndices
,
358 (void *)NineDevice9_CreatePixelShader
,
359 (void *)NineDevice9_SetPixelShader
,
360 (void *)NineDevice9_GetPixelShader
,
361 (void *)NineDevice9_SetPixelShaderConstantF
,
362 (void *)NineDevice9_GetPixelShaderConstantF
,
363 (void *)NineDevice9_SetPixelShaderConstantI
,
364 (void *)NineDevice9_GetPixelShaderConstantI
,
365 (void *)NineDevice9_SetPixelShaderConstantB
,
366 (void *)NineDevice9_GetPixelShaderConstantB
,
367 (void *)NineDevice9_DrawRectPatch
,
368 (void *)NineDevice9_DrawTriPatch
,
369 (void *)NineDevice9_DeletePatch
,
370 (void *)NineDevice9_CreateQuery
,
371 (void *)NineDevice9Ex_SetConvolutionMonoKernel
,
372 (void *)NineDevice9Ex_ComposeRects
,
373 (void *)NineDevice9Ex_PresentEx
,
374 (void *)NineDevice9Ex_GetGPUThreadPriority
,
375 (void *)NineDevice9Ex_SetGPUThreadPriority
,
376 (void *)NineDevice9Ex_WaitForVBlank
,
377 (void *)NineDevice9Ex_CheckResourceResidency
,
378 (void *)NineDevice9Ex_SetMaximumFrameLatency
,
379 (void *)NineDevice9Ex_GetMaximumFrameLatency
,
380 (void *)NineDevice9Ex_CheckDeviceState
,
381 (void *)NineDevice9Ex_CreateRenderTargetEx
,
382 (void *)NineDevice9Ex_CreateOffscreenPlainSurfaceEx
,
383 (void *)NineDevice9Ex_CreateDepthStencilSurfaceEx
,
384 (void *)NineDevice9Ex_ResetEx
,
385 (void *)NineDevice9Ex_GetDisplayModeEx
388 static const GUID
*NineDevice9Ex_IIDs
[] = {
389 &IID_IDirect3DDevice9Ex
,
390 &IID_IDirect3DDevice9
,
396 NineDevice9Ex_new( struct pipe_screen
*pScreen
,
397 D3DDEVICE_CREATION_PARAMETERS
*pCreationParameters
,
399 D3DPRESENT_PARAMETERS
*pPresentationParameters
,
400 D3DDISPLAYMODEEX
*pFullscreenDisplayMode
,
401 IDirect3D9Ex
*pD3D9Ex
,
402 ID3DPresentGroup
*pPresentationGroup
,
403 struct d3dadapter9_context
*pCTX
,
404 struct NineDevice9Ex
**ppOut
)
407 lock
= !!(pCreationParameters
->BehaviorFlags
& D3DCREATE_MULTITHREADED
);
409 NINE_NEW(Device9Ex
, ppOut
, lock
,
410 pScreen
, pCreationParameters
, pCaps
, pPresentationParameters
,
411 pFullscreenDisplayMode
, pD3D9Ex
, pPresentationGroup
, pCTX
);