nine: Add state tracker nine for Direct3D9 (v3)
[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 "device9ex.h"
24 #include "swapchain9ex.h"
25
26 #include "nine_helpers.h"
27
28 #define DBG_CHANNEL DBG_DEVICE
29
30 static HRESULT
31 NineDevice9Ex_ctor( struct NineDevice9Ex *This,
32 struct NineUnknownParams *pParams,
33 struct pipe_screen *pScreen,
34 D3DDEVICE_CREATION_PARAMETERS *pCreationParameters,
35 D3DCAPS9 *pCaps,
36 D3DPRESENT_PARAMETERS *pPresentationParameters,
37 D3DDISPLAYMODEEX *pFullscreenDisplayMode,
38 IDirect3D9Ex *pD3D9Ex,
39 ID3DPresentGroup *pPresentationGroup,
40 struct d3dadapter9_context *pCTX )
41 {
42 This->base.ex = TRUE;
43 This->base.pFullscreenDisplayMode = pFullscreenDisplayMode;
44
45 return NineDevice9_ctor(&This->base, pParams,
46 pScreen, pCreationParameters, pCaps,
47 pPresentationParameters,
48 (IDirect3D9 *)pD3D9Ex, pPresentationGroup, pCTX);
49 }
50
51 static void
52 NineDevice9Ex_dtor( struct NineDevice9Ex *This )
53 {
54 NineDevice9_dtor(&This->base);
55 }
56
57 HRESULT WINAPI
58 NineDevice9Ex_SetConvolutionMonoKernel( struct NineDevice9Ex *This,
59 UINT width,
60 UINT height,
61 float *rows,
62 float *columns )
63 {
64 STUB(D3DERR_INVALIDCALL);
65 }
66
67 HRESULT WINAPI
68 NineDevice9Ex_ComposeRects( struct NineDevice9Ex *This,
69 IDirect3DSurface9 *pSrc,
70 IDirect3DSurface9 *pDst,
71 IDirect3DVertexBuffer9 *pSrcRectDescs,
72 UINT NumRects,
73 IDirect3DVertexBuffer9 *pDstRectDescs,
74 D3DCOMPOSERECTSOP Operation,
75 int Xoffset,
76 int Yoffset )
77 {
78 STUB(D3DERR_INVALIDCALL);
79 }
80
81 HRESULT WINAPI
82 NineDevice9Ex_PresentEx( struct NineDevice9Ex *This,
83 const RECT *pSourceRect,
84 const RECT *pDestRect,
85 HWND hDestWindowOverride,
86 const RGNDATA *pDirtyRegion,
87 DWORD dwFlags )
88 {
89 unsigned i;
90 HRESULT hr;
91
92 for (i = 0; i < This->base.nswapchains; i++) {
93 hr = NineSwapChain9_Present(This->base.swapchains[i], pSourceRect, pDestRect,
94 hDestWindowOverride, pDirtyRegion, dwFlags);
95 if (FAILED(hr)) { return hr; }
96 }
97
98 return D3D_OK;
99 }
100
101 HRESULT WINAPI
102 NineDevice9Ex_GetGPUThreadPriority( struct NineDevice9Ex *This,
103 INT *pPriority )
104 {
105 STUB(D3DERR_INVALIDCALL);
106 }
107
108 HRESULT WINAPI
109 NineDevice9Ex_SetGPUThreadPriority( struct NineDevice9Ex *This,
110 INT Priority )
111 {
112 STUB(D3DERR_INVALIDCALL);
113 }
114
115 HRESULT WINAPI
116 NineDevice9Ex_WaitForVBlank( struct NineDevice9Ex *This,
117 UINT iSwapChain )
118 {
119 STUB(D3DERR_INVALIDCALL);
120 }
121
122 HRESULT WINAPI
123 NineDevice9Ex_CheckResourceResidency( struct NineDevice9Ex *This,
124 IDirect3DResource9 **pResourceArray,
125 UINT32 NumResources )
126 {
127 STUB(D3DERR_INVALIDCALL);
128 }
129
130 HRESULT WINAPI
131 NineDevice9Ex_SetMaximumFrameLatency( struct NineDevice9Ex *This,
132 UINT MaxLatency )
133 {
134 STUB(D3DERR_INVALIDCALL);
135 }
136
137 HRESULT WINAPI
138 NineDevice9Ex_GetMaximumFrameLatency( struct NineDevice9Ex *This,
139 UINT *pMaxLatency )
140 {
141 STUB(D3DERR_INVALIDCALL);
142 }
143
144 HRESULT WINAPI
145 NineDevice9Ex_CheckDeviceState( struct NineDevice9Ex *This,
146 HWND hDestinationWindow )
147 {
148 DBG("This=%p hDestinationWindow=%p\n",
149 This, hDestinationWindow);
150
151 /* TODO: handle the other return values */
152 return D3D_OK;
153 }
154
155 HRESULT WINAPI
156 NineDevice9Ex_CreateRenderTargetEx( struct NineDevice9Ex *This,
157 UINT Width,
158 UINT Height,
159 D3DFORMAT Format,
160 D3DMULTISAMPLE_TYPE MultiSample,
161 DWORD MultisampleQuality,
162 BOOL Lockable,
163 IDirect3DSurface9 **ppSurface,
164 HANDLE *pSharedHandle,
165 DWORD Usage )
166 {
167 STUB(D3DERR_INVALIDCALL);
168 }
169
170 HRESULT WINAPI
171 NineDevice9Ex_CreateOffscreenPlainSurfaceEx( struct NineDevice9Ex *This,
172 UINT Width,
173 UINT Height,
174 D3DFORMAT Format,
175 D3DPOOL Pool,
176 IDirect3DSurface9 **ppSurface,
177 HANDLE *pSharedHandle,
178 DWORD Usage )
179 {
180 STUB(D3DERR_INVALIDCALL);
181 }
182
183 HRESULT WINAPI
184 NineDevice9Ex_CreateDepthStencilSurfaceEx( struct NineDevice9Ex *This,
185 UINT Width,
186 UINT Height,
187 D3DFORMAT Format,
188 D3DMULTISAMPLE_TYPE MultiSample,
189 DWORD MultisampleQuality,
190 BOOL Discard,
191 IDirect3DSurface9 **ppSurface,
192 HANDLE *pSharedHandle,
193 DWORD Usage )
194 {
195 STUB(D3DERR_INVALIDCALL);
196 }
197
198 HRESULT WINAPI
199 NineDevice9Ex_ResetEx( struct NineDevice9Ex *This,
200 D3DPRESENT_PARAMETERS *pPresentationParameters,
201 D3DDISPLAYMODEEX *pFullscreenDisplayMode )
202 {
203 HRESULT hr = D3D_OK;
204 unsigned i;
205
206 DBG("This=%p pPresentationParameters=%p pFullscreenDisplayMode=%p\n", This, pPresentationParameters, pFullscreenDisplayMode);
207
208 for (i = 0; i < This->base.nswapchains; ++i) {
209 D3DDISPLAYMODEEX *mode = NULL;
210 D3DPRESENT_PARAMETERS *params = &pPresentationParameters[i];
211 if (pFullscreenDisplayMode) mode = &(pFullscreenDisplayMode[i]);
212 hr = NineSwapChain9_Resize(This->base.swapchains[i], params, mode);
213 if (FAILED(hr))
214 return (hr == D3DERR_OUTOFVIDEOMEMORY) ? hr : D3DERR_DEVICELOST;
215 }
216
217 NineDevice9_SetRenderTarget(
218 (struct NineDevice9 *)This, 0, (IDirect3DSurface9 *)This->base.swapchains[0]->buffers[0]);
219
220
221 return hr;
222 }
223
224 HRESULT WINAPI
225 NineDevice9Ex_GetDisplayModeEx( struct NineDevice9Ex *This,
226 UINT iSwapChain,
227 D3DDISPLAYMODEEX *pMode,
228 D3DDISPLAYROTATION *pRotation )
229 {
230 struct NineSwapChain9Ex *swapchain;
231
232 user_assert(iSwapChain < This->base.nswapchains, D3DERR_INVALIDCALL);
233
234 swapchain = NineSwapChain9Ex(This->base.swapchains[iSwapChain]);
235 return NineSwapChain9Ex_GetDisplayModeEx(swapchain, pMode, pRotation);
236 }
237
238 IDirect3DDevice9ExVtbl NineDevice9Ex_vtable = {
239 (void *)NineUnknown_QueryInterface,
240 (void *)NineUnknown_AddRef,
241 (void *)NineUnknown_Release,
242 (void *)NineDevice9_TestCooperativeLevel,
243 (void *)NineDevice9_GetAvailableTextureMem,
244 (void *)NineDevice9_EvictManagedResources,
245 (void *)NineDevice9_GetDirect3D,
246 (void *)NineDevice9_GetDeviceCaps,
247 (void *)NineDevice9_GetDisplayMode,
248 (void *)NineDevice9_GetCreationParameters,
249 (void *)NineDevice9_SetCursorProperties,
250 (void *)NineDevice9_SetCursorPosition,
251 (void *)NineDevice9_ShowCursor,
252 (void *)NineDevice9_CreateAdditionalSwapChain,
253 (void *)NineDevice9_GetSwapChain,
254 (void *)NineDevice9_GetNumberOfSwapChains,
255 (void *)NineDevice9_Reset,
256 (void *)NineDevice9_Present,
257 (void *)NineDevice9_GetBackBuffer,
258 (void *)NineDevice9_GetRasterStatus,
259 (void *)NineDevice9_SetDialogBoxMode,
260 (void *)NineDevice9_SetGammaRamp,
261 (void *)NineDevice9_GetGammaRamp,
262 (void *)NineDevice9_CreateTexture,
263 (void *)NineDevice9_CreateVolumeTexture,
264 (void *)NineDevice9_CreateCubeTexture,
265 (void *)NineDevice9_CreateVertexBuffer,
266 (void *)NineDevice9_CreateIndexBuffer,
267 (void *)NineDevice9_CreateRenderTarget,
268 (void *)NineDevice9_CreateDepthStencilSurface,
269 (void *)NineDevice9_UpdateSurface,
270 (void *)NineDevice9_UpdateTexture,
271 (void *)NineDevice9_GetRenderTargetData,
272 (void *)NineDevice9_GetFrontBufferData,
273 (void *)NineDevice9_StretchRect,
274 (void *)NineDevice9_ColorFill,
275 (void *)NineDevice9_CreateOffscreenPlainSurface,
276 (void *)NineDevice9_SetRenderTarget,
277 (void *)NineDevice9_GetRenderTarget,
278 (void *)NineDevice9_SetDepthStencilSurface,
279 (void *)NineDevice9_GetDepthStencilSurface,
280 (void *)NineDevice9_BeginScene,
281 (void *)NineDevice9_EndScene,
282 (void *)NineDevice9_Clear,
283 (void *)NineDevice9_SetTransform,
284 (void *)NineDevice9_GetTransform,
285 (void *)NineDevice9_MultiplyTransform,
286 (void *)NineDevice9_SetViewport,
287 (void *)NineDevice9_GetViewport,
288 (void *)NineDevice9_SetMaterial,
289 (void *)NineDevice9_GetMaterial,
290 (void *)NineDevice9_SetLight,
291 (void *)NineDevice9_GetLight,
292 (void *)NineDevice9_LightEnable,
293 (void *)NineDevice9_GetLightEnable,
294 (void *)NineDevice9_SetClipPlane,
295 (void *)NineDevice9_GetClipPlane,
296 (void *)NineDevice9_SetRenderState,
297 (void *)NineDevice9_GetRenderState,
298 (void *)NineDevice9_CreateStateBlock,
299 (void *)NineDevice9_BeginStateBlock,
300 (void *)NineDevice9_EndStateBlock,
301 (void *)NineDevice9_SetClipStatus,
302 (void *)NineDevice9_GetClipStatus,
303 (void *)NineDevice9_GetTexture,
304 (void *)NineDevice9_SetTexture,
305 (void *)NineDevice9_GetTextureStageState,
306 (void *)NineDevice9_SetTextureStageState,
307 (void *)NineDevice9_GetSamplerState,
308 (void *)NineDevice9_SetSamplerState,
309 (void *)NineDevice9_ValidateDevice,
310 (void *)NineDevice9_SetPaletteEntries,
311 (void *)NineDevice9_GetPaletteEntries,
312 (void *)NineDevice9_SetCurrentTexturePalette,
313 (void *)NineDevice9_GetCurrentTexturePalette,
314 (void *)NineDevice9_SetScissorRect,
315 (void *)NineDevice9_GetScissorRect,
316 (void *)NineDevice9_SetSoftwareVertexProcessing,
317 (void *)NineDevice9_GetSoftwareVertexProcessing,
318 (void *)NineDevice9_SetNPatchMode,
319 (void *)NineDevice9_GetNPatchMode,
320 (void *)NineDevice9_DrawPrimitive,
321 (void *)NineDevice9_DrawIndexedPrimitive,
322 (void *)NineDevice9_DrawPrimitiveUP,
323 (void *)NineDevice9_DrawIndexedPrimitiveUP,
324 (void *)NineDevice9_ProcessVertices,
325 (void *)NineDevice9_CreateVertexDeclaration,
326 (void *)NineDevice9_SetVertexDeclaration,
327 (void *)NineDevice9_GetVertexDeclaration,
328 (void *)NineDevice9_SetFVF,
329 (void *)NineDevice9_GetFVF,
330 (void *)NineDevice9_CreateVertexShader,
331 (void *)NineDevice9_SetVertexShader,
332 (void *)NineDevice9_GetVertexShader,
333 (void *)NineDevice9_SetVertexShaderConstantF,
334 (void *)NineDevice9_GetVertexShaderConstantF,
335 (void *)NineDevice9_SetVertexShaderConstantI,
336 (void *)NineDevice9_GetVertexShaderConstantI,
337 (void *)NineDevice9_SetVertexShaderConstantB,
338 (void *)NineDevice9_GetVertexShaderConstantB,
339 (void *)NineDevice9_SetStreamSource,
340 (void *)NineDevice9_GetStreamSource,
341 (void *)NineDevice9_SetStreamSourceFreq,
342 (void *)NineDevice9_GetStreamSourceFreq,
343 (void *)NineDevice9_SetIndices,
344 (void *)NineDevice9_GetIndices,
345 (void *)NineDevice9_CreatePixelShader,
346 (void *)NineDevice9_SetPixelShader,
347 (void *)NineDevice9_GetPixelShader,
348 (void *)NineDevice9_SetPixelShaderConstantF,
349 (void *)NineDevice9_GetPixelShaderConstantF,
350 (void *)NineDevice9_SetPixelShaderConstantI,
351 (void *)NineDevice9_GetPixelShaderConstantI,
352 (void *)NineDevice9_SetPixelShaderConstantB,
353 (void *)NineDevice9_GetPixelShaderConstantB,
354 (void *)NineDevice9_DrawRectPatch,
355 (void *)NineDevice9_DrawTriPatch,
356 (void *)NineDevice9_DeletePatch,
357 (void *)NineDevice9_CreateQuery,
358 (void *)NineDevice9Ex_SetConvolutionMonoKernel,
359 (void *)NineDevice9Ex_ComposeRects,
360 (void *)NineDevice9Ex_PresentEx,
361 (void *)NineDevice9Ex_GetGPUThreadPriority,
362 (void *)NineDevice9Ex_SetGPUThreadPriority,
363 (void *)NineDevice9Ex_WaitForVBlank,
364 (void *)NineDevice9Ex_CheckResourceResidency,
365 (void *)NineDevice9Ex_SetMaximumFrameLatency,
366 (void *)NineDevice9Ex_GetMaximumFrameLatency,
367 (void *)NineDevice9Ex_CheckDeviceState,
368 (void *)NineDevice9Ex_CreateRenderTargetEx,
369 (void *)NineDevice9Ex_CreateOffscreenPlainSurfaceEx,
370 (void *)NineDevice9Ex_CreateDepthStencilSurfaceEx,
371 (void *)NineDevice9Ex_ResetEx,
372 (void *)NineDevice9Ex_GetDisplayModeEx
373 };
374
375 static const GUID *NineDevice9Ex_IIDs[] = {
376 &IID_IDirect3DDevice9Ex,
377 &IID_IDirect3DDevice9,
378 &IID_IUnknown,
379 NULL
380 };
381
382 HRESULT
383 NineDevice9Ex_new( struct pipe_screen *pScreen,
384 D3DDEVICE_CREATION_PARAMETERS *pCreationParameters,
385 D3DCAPS9 *pCaps,
386 D3DPRESENT_PARAMETERS *pPresentationParameters,
387 D3DDISPLAYMODEEX *pFullscreenDisplayMode,
388 IDirect3D9Ex *pD3D9Ex,
389 ID3DPresentGroup *pPresentationGroup,
390 struct d3dadapter9_context *pCTX,
391 struct NineDevice9Ex **ppOut )
392 {
393 BOOL lock;
394 lock = !!(pCreationParameters->BehaviorFlags & D3DCREATE_MULTITHREADED);
395
396 NINE_NEW(Device9Ex, ppOut, lock,
397 pScreen, pCreationParameters, pCaps, pPresentationParameters,
398 pFullscreenDisplayMode, pD3D9Ex, pPresentationGroup, pCTX);
399 }
400