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