2 *IDirect3DSwapChain9 implementation
4 *Copyright 2002-2003 Jason Edmeades
5 *Copyright 2002-2003 Raphael Junqueira
6 *Copyright 2005 Oliver Stieber
8 *This library is free software; you can redistribute it and/or
9 *modify it under the terms of the GNU Lesser General Public
10 *License as published by the Free Software Foundation; either
11 *version 2.1 of the License, or (at your option) any later version.
13 *This library is distributed in the hope that it will be useful,
14 *but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 *Lesser General Public License for more details.
18 *You should have received a copy of the GNU Lesser General Public
19 *License along with this library; if not, write to the Free Software
20 *Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wined3d_private.h"
27 /*TODO: some of the additional parameters may be required to
28 set the gamma ramp (for some weird reason microsoft have left swap gammaramp in device
29 but it operates on a swapchain, it may be a good idea to move it to IWineD3DSwapChain for IWineD3D)*/
32 WINE_DEFAULT_DEBUG_CHANNEL(d3d
);
33 WINE_DECLARE_DEBUG_CHANNEL(fps
);
35 #define GLINFO_LOCATION This->wineD3DDevice->adapter->gl_info
37 /* IDirect3DSwapChain IUnknown parts follow: */
38 static ULONG WINAPI
IWineD3DSwapChainImpl_AddRef(IWineD3DSwapChain
*iface
) {
39 IWineD3DSwapChainImpl
*This
= (IWineD3DSwapChainImpl
*)iface
;
40 DWORD refCount
= InterlockedIncrement(&This
->ref
);
41 TRACE("(%p) : AddRef increasing from %d\n", This
, refCount
- 1);
45 static HRESULT WINAPI
IWineD3DSwapChainImpl_QueryInterface(IWineD3DSwapChain
*iface
, REFIID riid
, LPVOID
*ppobj
)
47 IWineD3DSwapChainImpl
*This
= (IWineD3DSwapChainImpl
*)iface
;
48 TRACE("(%p)->(%s,%p)\n", This
, debugstr_guid(riid
), ppobj
);
49 if (IsEqualGUID(riid
, &IID_IUnknown
)
50 || IsEqualGUID(riid
, &IID_IWineD3DBase
)
51 || IsEqualGUID(riid
, &IID_IWineD3DSwapChain
)){
52 IWineD3DSwapChainImpl_AddRef(iface
);
54 ERR("Query interface called but now data allocated\n");
65 static ULONG WINAPI
IWineD3DSwapChainImpl_Release(IWineD3DSwapChain
*iface
) {
66 IWineD3DSwapChainImpl
*This
= (IWineD3DSwapChainImpl
*)iface
;
68 refCount
= InterlockedDecrement(&This
->ref
);
69 TRACE("(%p) : ReleaseRef to %d\n", This
, refCount
);
71 IWineD3DSwapChain_Destroy(iface
, D3DCB_DefaultDestroySurface
);
76 static HRESULT WINAPI
IWineD3DSwapChainImpl_GetParent(IWineD3DSwapChain
*iface
, IUnknown
** ppParent
){
77 IWineD3DSwapChainImpl
*This
= (IWineD3DSwapChainImpl
*)iface
;
78 *ppParent
= This
->parent
;
79 IUnknown_AddRef(*ppParent
);
80 TRACE("(%p) returning %p\n", This
, *ppParent
);
84 /*IWineD3DSwapChain parts follow: */
85 static void WINAPI
IWineD3DSwapChainImpl_Destroy(IWineD3DSwapChain
*iface
, D3DCB_DESTROYSURFACEFN D3DCB_DestroyRenderTarget
) {
86 IWineD3DSwapChainImpl
*This
= (IWineD3DSwapChainImpl
*)iface
;
87 WINED3DDISPLAYMODE mode
;
90 /* release the ref to the front and back buffer parents */
91 if(This
->frontBuffer
) {
92 IWineD3DSurface_SetContainer(This
->frontBuffer
, 0);
93 if(D3DCB_DestroyRenderTarget(This
->frontBuffer
) > 0) {
94 FIXME("(%p) Something's still holding the front buffer\n",This
);
98 if(This
->backBuffer
) {
100 for(i
= 0; i
< This
->presentParms
.BackBufferCount
; i
++) {
101 IWineD3DSurface_SetContainer(This
->backBuffer
[i
], 0);
102 if(D3DCB_DestroyRenderTarget(This
->backBuffer
[i
]) > 0) {
103 FIXME("(%p) Something's still holding the back buffer\n",This
);
106 HeapFree(GetProcessHeap(), 0, This
->backBuffer
);
109 for(i
= 0; i
< This
->num_contexts
; i
++) {
110 DestroyContext(This
->wineD3DDevice
, This
->context
[i
]);
112 /* Restore the screen resolution if we rendered in fullscreen
113 * This will restore the screen resolution to what it was before creating the swapchain. In case of d3d8 and d3d9
114 * this will be the original desktop resolution. In case of d3d7 this will be a NOP because ddraw sets the resolution
115 * before starting up Direct3D, thus orig_width and orig_height will be equal to the modes in the presentation params
117 if(This
->presentParms
.Windowed
== FALSE
) {
118 mode
.Width
= This
->orig_width
;
119 mode
.Height
= This
->orig_height
;
120 mode
.RefreshRate
= 0;
121 mode
.Format
= This
->orig_fmt
;
122 IWineD3DDevice_SetDisplayMode((IWineD3DDevice
*) This
->wineD3DDevice
, 0, &mode
);
124 HeapFree(GetProcessHeap(), 0, This
->context
);
126 HeapFree(GetProcessHeap(), 0, This
);
129 static HRESULT WINAPI
IWineD3DSwapChainImpl_Present(IWineD3DSwapChain
*iface
, CONST RECT
*pSourceRect
, CONST RECT
*pDestRect
, HWND hDestWindowOverride
, CONST RGNDATA
*pDirtyRegion
, DWORD dwFlags
) {
130 IWineD3DSwapChainImpl
*This
= (IWineD3DSwapChainImpl
*)iface
;
135 ActivateContext(This
->wineD3DDevice
, This
->backBuffer
[0], CTXUSAGE_RESOURCELOAD
);
137 /* Render the cursor onto the back buffer, using our nifty directdraw blitting code :-) */
138 if(This
->wineD3DDevice
->bCursorVisible
&& This
->wineD3DDevice
->cursorTexture
) {
139 IWineD3DSurfaceImpl cursor
;
140 RECT destRect
= {This
->wineD3DDevice
->xScreenSpace
- This
->wineD3DDevice
->xHotSpot
,
141 This
->wineD3DDevice
->yScreenSpace
- This
->wineD3DDevice
->yHotSpot
,
142 This
->wineD3DDevice
->xScreenSpace
+ This
->wineD3DDevice
->cursorWidth
- This
->wineD3DDevice
->xHotSpot
,
143 This
->wineD3DDevice
->yScreenSpace
+ This
->wineD3DDevice
->cursorHeight
- This
->wineD3DDevice
->yHotSpot
};
144 TRACE("Rendering the cursor. Creating fake surface at %p\n", &cursor
);
145 /* Build a fake surface to call the Blitting code. It is not possible to use the interface passed by
146 * the application because we are only supposed to copy the information out. Using a fake surface
147 * allows to use the Blitting engine and avoid copying the whole texture -> render target blitting code.
149 memset(&cursor
, 0, sizeof(cursor
));
150 cursor
.lpVtbl
= &IWineD3DSurface_Vtbl
;
151 cursor
.resource
.ref
= 1;
152 cursor
.resource
.wineD3DDevice
= This
->wineD3DDevice
;
153 cursor
.resource
.pool
= WINED3DPOOL_SCRATCH
;
154 cursor
.resource
.format
= WINED3DFMT_A8R8G8B8
;
155 cursor
.resource
.resourceType
= WINED3DRTYPE_SURFACE
;
156 cursor
.glDescription
.textureName
= This
->wineD3DDevice
->cursorTexture
;
157 cursor
.glDescription
.target
= GL_TEXTURE_2D
;
158 cursor
.glDescription
.level
= 0;
159 cursor
.currentDesc
.Width
= This
->wineD3DDevice
->cursorWidth
;
160 cursor
.currentDesc
.Height
= This
->wineD3DDevice
->cursorHeight
;
161 cursor
.glRect
.left
= 0;
162 cursor
.glRect
.top
= 0;
163 cursor
.glRect
.right
= cursor
.currentDesc
.Width
;
164 cursor
.glRect
.bottom
= cursor
.currentDesc
.Height
;
165 /* The cursor must have pow2 sizes */
166 cursor
.pow2Width
= cursor
.currentDesc
.Width
;
167 cursor
.pow2Height
= cursor
.currentDesc
.Height
;
168 /* The surface is in the texture */
169 cursor
.Flags
|= SFLAG_INTEXTURE
;
170 /* DDBLT_KEYSRC will cause BltOverride to enable the alpha test with GL_NOTEQUAL, 0.0,
171 * which is exactly what we want :-)
173 if (This
->presentParms
.Windowed
) {
174 MapWindowPoints(NULL
, This
->win_handle
, (LPPOINT
)&destRect
, 2);
176 IWineD3DSurface_Blt(This
->backBuffer
[0], &destRect
, (IWineD3DSurface
*) &cursor
, NULL
, WINEDDBLT_KEYSRC
, NULL
, WINED3DTEXF_NONE
);
178 if(This
->wineD3DDevice
->logo_surface
) {
179 /* Blit the logo into the upper left corner of the drawable */
180 IWineD3DSurface_BltFast(This
->backBuffer
[0], 0, 0, This
->wineD3DDevice
->logo_surface
, NULL
, WINEDDBLTFAST_SRCCOLORKEY
);
183 if (pSourceRect
|| pDestRect
) FIXME("Unhandled present options %p/%p\n", pSourceRect
, pDestRect
);
184 /* TODO: If only source rect or dest rect are supplied then clip the window to match */
185 TRACE("preseting HDC %p\n", This
->context
[0]->hdc
);
187 /* Don't call checkGLcall, as glGetError is not applicable here */
188 if (hDestWindowOverride
&& This
->win_handle
!= hDestWindowOverride
) {
189 WINED3DLOCKED_RECT r
;
192 TRACE("Performing dest override of swapchain %p from window %p to %p\n", This
, This
->win_handle
, hDestWindowOverride
);
193 if(This
->context
[0] == This
->wineD3DDevice
->contexts
[0]) {
194 /* The primary context 'owns' all the opengl resources. Destroying and recreating that context would require downloading
195 * all opengl resources, deleting the gl resources, destroying all other contexts, then recreating all other contexts
196 * and reload the resources
198 ERR("Cannot change the destination window of the owner of the primary context\n");
200 This
->win_handle
= hDestWindowOverride
;
202 /* The old back buffer has to be copied over to the new back buffer. A lockrect - switchcontext - unlockrect
203 * would suffice in theory, but it is rather nasty and may cause troubles with future changes of the locking code
204 * So lock read only, copy the surface out, then lock with the discard flag and write back
206 IWineD3DSurface_LockRect(This
->backBuffer
[0], &r
, NULL
, WINED3DLOCK_READONLY
);
207 mem
= HeapAlloc(GetProcessHeap(), 0, r
.Pitch
* ((IWineD3DSurfaceImpl
*) This
->backBuffer
[0])->currentDesc
.Height
);
208 memcpy(mem
, r
.pBits
, r
.Pitch
* ((IWineD3DSurfaceImpl
*) This
->backBuffer
[0])->currentDesc
.Height
);
209 IWineD3DSurface_UnlockRect(This
->backBuffer
[0]);
211 DestroyContext(This
->wineD3DDevice
, This
->context
[0]);
212 This
->context
[0] = CreateContext(This
->wineD3DDevice
, (IWineD3DSurfaceImpl
*) This
->frontBuffer
, This
->win_handle
, FALSE
/* pbuffer */, &This
->presentParms
);
214 IWineD3DSurface_LockRect(This
->backBuffer
[0], &r
, NULL
, WINED3DLOCK_DISCARD
);
215 memcpy(r
.pBits
, mem
, r
.Pitch
* ((IWineD3DSurfaceImpl
*) This
->backBuffer
[0])->currentDesc
.Height
);
216 HeapFree(GetProcessHeap(), 0, mem
);
217 IWineD3DSurface_UnlockRect(This
->backBuffer
[0]);
221 SwapBuffers(This
->context
[0]->hdc
); /* TODO: cycle through the swapchain buffers */
223 TRACE("SwapBuffers called, Starting new frame\n");
227 DWORD time
= GetTickCount();
229 /* every 1.5 seconds */
230 if (time
- This
->prev_time
> 1500) {
231 TRACE_(fps
)("%p @ approx %.2ffps\n", This
, 1000.0*This
->frames
/(time
- This
->prev_time
));
232 This
->prev_time
= time
;
237 #if defined(FRAME_DEBUGGING)
239 if (GetFileAttributesA("C:\\D3DTRACE") != INVALID_FILE_ATTRIBUTES
) {
242 FIXME("Enabling D3D Trace\n");
243 __WINE_SET_DEBUGGING(__WINE_DBCL_TRACE
, __wine_dbch_d3d
, 1);
244 #if defined(SHOW_FRAME_MAKEUP)
245 FIXME("Singe Frame snapshots Starting\n");
246 isDumpingFrames
= TRUE
;
248 glClear(GL_COLOR_BUFFER_BIT
);
252 #if defined(SINGLE_FRAME_DEBUGGING)
254 #if defined(SHOW_FRAME_MAKEUP)
255 FIXME("Singe Frame snapshots Finishing\n");
256 isDumpingFrames
= FALSE
;
258 FIXME("Singe Frame trace complete\n");
259 DeleteFileA("C:\\D3DTRACE");
260 __WINE_SET_DEBUGGING(__WINE_DBCL_TRACE
, __wine_dbch_d3d
, 0);
266 #if defined(SHOW_FRAME_MAKEUP)
267 FIXME("Single Frame snapshots Finishing\n");
268 isDumpingFrames
= FALSE
;
270 FIXME("Disabling D3D Trace\n");
271 __WINE_SET_DEBUGGING(__WINE_DBCL_TRACE
, __wine_dbch_d3d
, 0);
277 /* This is disabled, but the code left in for debug purposes.
279 * Since we're allowed to modify the new back buffer on a D3DSWAPEFFECT_DISCARD flip,
280 * we can clear it with some ugly color to make bad drawing visible and ease debugging.
281 * The Debug runtime does the same on Windows. However, a few games do not redraw the
282 * screen properly, like Max Payne 2, which leaves a few pixels undefined.
284 * Tests show that the content of the back buffer after a discard flip is indeed not
285 * reliable, so no game can depend on the exact content. However, it resembles the
286 * old contents in some way, for example by showing fragments at other locations. In
287 * general, the color theme is still intact. So Max payne, which draws rather dark scenes
288 * gets a dark background image. If we clear it with a bright ugly color, the game's
289 * bug shows up much more than it does on Windows, and the players see single pixels
291 * (The Max Payne bug has been confirmed on Windows with the debug runtime)
293 if (FALSE
&& This
->presentParms
.SwapEffect
== WINED3DSWAPEFFECT_DISCARD
) {
294 TRACE("Clearing the color buffer with cyan color\n");
296 IWineD3DDevice_Clear((IWineD3DDevice
*)This
->wineD3DDevice
, 0, NULL
,
297 WINED3DCLEAR_TARGET
, 0xff00ffff, 1.0, 0);
300 if(((IWineD3DSurfaceImpl
*) This
->frontBuffer
)->Flags
& SFLAG_INSYSMEM
||
301 ((IWineD3DSurfaceImpl
*) This
->backBuffer
[0])->Flags
& SFLAG_INSYSMEM
) {
302 /* Both memory copies of the surfaces are ok, flip them around too instead of dirtifying */
303 IWineD3DSurfaceImpl
*front
= (IWineD3DSurfaceImpl
*) This
->frontBuffer
;
304 IWineD3DSurfaceImpl
*back
= (IWineD3DSurfaceImpl
*) This
->backBuffer
[0];
305 BOOL frontuptodate
= front
->Flags
& SFLAG_INSYSMEM
;
306 BOOL backuptodate
= back
->Flags
& SFLAG_INSYSMEM
;
308 if(front
->resource
.size
== back
->resource
.size
) {
313 front
->hDC
= back
->hDC
;
317 /* Flip the DIBsection */
320 BOOL hasDib
= front
->Flags
& SFLAG_DIBSECTION
;
321 tmp
= front
->dib
.DIBsection
;
322 front
->dib
.DIBsection
= back
->dib
.DIBsection
;
323 back
->dib
.DIBsection
= tmp
;
325 if(back
->Flags
& SFLAG_DIBSECTION
) front
->Flags
|= SFLAG_DIBSECTION
;
326 else front
->Flags
&= ~SFLAG_DIBSECTION
;
327 if(hasDib
) back
->Flags
|= SFLAG_DIBSECTION
;
328 else back
->Flags
&= ~SFLAG_DIBSECTION
;
331 /* Flip the surface data */
335 tmp
= front
->dib
.bitmap_data
;
336 front
->dib
.bitmap_data
= back
->dib
.bitmap_data
;
337 back
->dib
.bitmap_data
= tmp
;
339 tmp
= front
->resource
.allocatedMemory
;
340 front
->resource
.allocatedMemory
= back
->resource
.allocatedMemory
;
341 back
->resource
.allocatedMemory
= tmp
;
343 tmp
= front
->resource
.heapMemory
;
344 front
->resource
.heapMemory
= back
->resource
.heapMemory
;
345 back
->resource
.heapMemory
= tmp
;
350 DWORD tmp_flags
= front
->Flags
;
352 GLuint tmp_pbo
= front
->pbo
;
353 front
->pbo
= back
->pbo
;
356 if(back
->Flags
& SFLAG_PBO
)
357 front
->Flags
|= SFLAG_PBO
;
359 front
->Flags
&= ~SFLAG_PBO
;
361 if(tmp_flags
& SFLAG_PBO
)
362 back
->Flags
|= SFLAG_PBO
;
364 back
->Flags
&= ~SFLAG_PBO
;
367 /* client_memory should not be different, but just in case */
370 tmp
= front
->dib
.client_memory
;
371 front
->dib
.client_memory
= back
->dib
.client_memory
;
372 back
->dib
.client_memory
= tmp
;
374 if(frontuptodate
) back
->Flags
|= SFLAG_INSYSMEM
;
375 else back
->Flags
&= ~SFLAG_INSYSMEM
;
376 if(backuptodate
) front
->Flags
|= SFLAG_INSYSMEM
;
377 else front
->Flags
&= ~SFLAG_INSYSMEM
;
379 IWineD3DSurface_ModifyLocation((IWineD3DSurface
*) front
, SFLAG_INDRAWABLE
, TRUE
);
380 IWineD3DSurface_ModifyLocation((IWineD3DSurface
*) back
, SFLAG_INDRAWABLE
, TRUE
);
384 if(This
->presentParms
.PresentationInterval
!= WINED3DPRESENT_INTERVAL_IMMEDIATE
&& GL_SUPPORT(SGI_VIDEO_SYNC
)) {
385 retval
= GL_EXTCALL(glXGetVideoSyncSGI(&sync
));
387 ERR("glXGetVideoSyncSGI failed(retval = %d\n", retval
);
390 switch(This
->presentParms
.PresentationInterval
) {
391 case WINED3DPRESENT_INTERVAL_DEFAULT
:
392 case WINED3DPRESENT_INTERVAL_ONE
:
393 if(sync
<= This
->vSyncCounter
) {
394 retval
= GL_EXTCALL(glXWaitVideoSyncSGI(1, 0, &This
->vSyncCounter
));
396 This
->vSyncCounter
= sync
;
399 case WINED3DPRESENT_INTERVAL_TWO
:
400 if(sync
<= This
->vSyncCounter
+ 1) {
401 retval
= GL_EXTCALL(glXWaitVideoSyncSGI(2, This
->vSyncCounter
& 0x1, &This
->vSyncCounter
));
403 This
->vSyncCounter
= sync
;
406 case WINED3DPRESENT_INTERVAL_THREE
:
407 if(sync
<= This
->vSyncCounter
+ 2) {
408 retval
= GL_EXTCALL(glXWaitVideoSyncSGI(3, This
->vSyncCounter
% 0x3, &This
->vSyncCounter
));
410 This
->vSyncCounter
= sync
;
413 case WINED3DPRESENT_INTERVAL_FOUR
:
414 if(sync
<= This
->vSyncCounter
+ 3) {
415 retval
= GL_EXTCALL(glXWaitVideoSyncSGI(4, This
->vSyncCounter
& 0x3, &This
->vSyncCounter
));
417 This
->vSyncCounter
= sync
;
421 FIXME("Unknown presentation interval %08x\n", This
->presentParms
.PresentationInterval
);
425 TRACE("returning\n");
429 static HRESULT WINAPI
IWineD3DSwapChainImpl_GetFrontBufferData(IWineD3DSwapChain
*iface
, IWineD3DSurface
*pDestSurface
) {
430 IWineD3DSwapChainImpl
*This
= (IWineD3DSwapChainImpl
*)iface
;
433 TRACE("(%p) : iface(%p) pDestSurface(%p)\n", This
, iface
, pDestSurface
);
438 if (This
->presentParms
.Windowed
) {
439 MapWindowPoints(This
->win_handle
, NULL
, &start
, 1);
442 IWineD3DSurface_BltFast(pDestSurface
, start
.x
, start
.y
, This
->frontBuffer
, NULL
, 0);
446 static HRESULT WINAPI
IWineD3DSwapChainImpl_GetBackBuffer(IWineD3DSwapChain
*iface
, UINT iBackBuffer
, WINED3DBACKBUFFER_TYPE Type
, IWineD3DSurface
**ppBackBuffer
) {
448 IWineD3DSwapChainImpl
*This
= (IWineD3DSwapChainImpl
*)iface
;
450 if (iBackBuffer
> This
->presentParms
.BackBufferCount
- 1) {
451 TRACE("Back buffer count out of range\n");
452 /* Native d3d9 doesn't set NULL here, just as wine's d3d9. But set it here
453 * in wined3d to avoid problems in other libs
455 *ppBackBuffer
= NULL
;
456 return WINED3DERR_INVALIDCALL
;
459 *ppBackBuffer
= This
->backBuffer
[iBackBuffer
];
460 TRACE("(%p) : BackBuf %d Type %d returning %p\n", This
, iBackBuffer
, Type
, *ppBackBuffer
);
462 /* Note inc ref on returned surface */
463 if(*ppBackBuffer
) IWineD3DSurface_AddRef(*ppBackBuffer
);
468 static HRESULT WINAPI
IWineD3DSwapChainImpl_GetRasterStatus(IWineD3DSwapChain
*iface
, WINED3DRASTER_STATUS
*pRasterStatus
) {
469 IWineD3DSwapChainImpl
*This
= (IWineD3DSwapChainImpl
*)iface
;
470 static BOOL showFixmes
= TRUE
;
471 pRasterStatus
->InVBlank
= TRUE
;
472 pRasterStatus
->ScanLine
= 0;
473 /* No openGL equivalent */
475 FIXME("(%p) : stub (once)\n", This
);
481 static HRESULT WINAPI
IWineD3DSwapChainImpl_GetDisplayMode(IWineD3DSwapChain
*iface
, WINED3DDISPLAYMODE
*pMode
) {
482 IWineD3DSwapChainImpl
*This
= (IWineD3DSwapChainImpl
*)iface
;
485 TRACE("(%p)->(%p): Calling GetAdapterDisplayMode\n", This
, pMode
);
486 hr
= IWineD3D_GetAdapterDisplayMode(This
->wineD3DDevice
->wineD3D
, This
->wineD3DDevice
->adapter
->num
, pMode
);
488 TRACE("(%p) : returning w(%d) h(%d) rr(%d) fmt(%u,%s)\n", This
, pMode
->Width
, pMode
->Height
, pMode
->RefreshRate
,
489 pMode
->Format
, debug_d3dformat(pMode
->Format
));
493 static HRESULT WINAPI
IWineD3DSwapChainImpl_GetDevice(IWineD3DSwapChain
*iface
, IWineD3DDevice
**ppDevice
) {
494 IWineD3DSwapChainImpl
*This
= (IWineD3DSwapChainImpl
*)iface
;
496 *ppDevice
= (IWineD3DDevice
*) This
->wineD3DDevice
;
498 /* Note Calling this method will increase the internal reference count
499 on the IDirect3DDevice9 interface. */
500 IWineD3DDevice_AddRef(*ppDevice
);
501 TRACE("(%p) : returning %p\n", This
, *ppDevice
);
505 static HRESULT WINAPI
IWineD3DSwapChainImpl_GetPresentParameters(IWineD3DSwapChain
*iface
, WINED3DPRESENT_PARAMETERS
*pPresentationParameters
) {
506 IWineD3DSwapChainImpl
*This
= (IWineD3DSwapChainImpl
*)iface
;
507 TRACE("(%p)\n", This
);
509 *pPresentationParameters
= This
->presentParms
;
514 static HRESULT WINAPI
IWineD3DSwapChainImpl_SetGammaRamp(IWineD3DSwapChain
*iface
, DWORD Flags
, CONST WINED3DGAMMARAMP
*pRamp
){
516 IWineD3DSwapChainImpl
*This
= (IWineD3DSwapChainImpl
*)iface
;
518 TRACE("(%p) : pRamp@%p flags(%d)\n", This
, pRamp
, Flags
);
519 hDC
= GetDC(This
->win_handle
);
520 SetDeviceGammaRamp(hDC
, (LPVOID
)pRamp
);
521 ReleaseDC(This
->win_handle
, hDC
);
526 static HRESULT WINAPI
IWineD3DSwapChainImpl_GetGammaRamp(IWineD3DSwapChain
*iface
, WINED3DGAMMARAMP
*pRamp
){
528 IWineD3DSwapChainImpl
*This
= (IWineD3DSwapChainImpl
*)iface
;
530 TRACE("(%p) : pRamp@%p\n", This
, pRamp
);
531 hDC
= GetDC(This
->win_handle
);
532 GetDeviceGammaRamp(hDC
, pRamp
);
533 ReleaseDC(This
->win_handle
, hDC
);
539 const IWineD3DSwapChainVtbl IWineD3DSwapChain_Vtbl
=
542 IWineD3DSwapChainImpl_QueryInterface
,
543 IWineD3DSwapChainImpl_AddRef
,
544 IWineD3DSwapChainImpl_Release
,
545 /* IWineD3DSwapChain */
546 IWineD3DSwapChainImpl_GetParent
,
547 IWineD3DSwapChainImpl_Destroy
,
548 IWineD3DSwapChainImpl_GetDevice
,
549 IWineD3DSwapChainImpl_Present
,
550 IWineD3DSwapChainImpl_GetFrontBufferData
,
551 IWineD3DSwapChainImpl_GetBackBuffer
,
552 IWineD3DSwapChainImpl_GetRasterStatus
,
553 IWineD3DSwapChainImpl_GetDisplayMode
,
554 IWineD3DSwapChainImpl_GetPresentParameters
,
555 IWineD3DSwapChainImpl_SetGammaRamp
,
556 IWineD3DSwapChainImpl_GetGammaRamp
559 WineD3DContext
*IWineD3DSwapChainImpl_CreateContextForThread(IWineD3DSwapChain
*iface
) {
561 IWineD3DSwapChainImpl
*This
= (IWineD3DSwapChainImpl
*) iface
;
562 WineD3DContext
**newArray
;
564 TRACE("Creating a new context for swapchain %p, thread %d\n", This
, GetCurrentThreadId());
566 ctx
= CreateContext(This
->wineD3DDevice
, (IWineD3DSurfaceImpl
*) This
->frontBuffer
,
567 This
->context
[0]->win_handle
, FALSE
/* pbuffer */, &This
->presentParms
);
569 ERR("Failed to create a new context for the swapchain\n");
573 newArray
= HeapAlloc(GetProcessHeap(), 0, sizeof(*newArray
) * This
->num_contexts
+ 1);
575 ERR("Out of memory when trying to allocate a new context array\n");
576 DestroyContext(This
->wineD3DDevice
, ctx
);
579 memcpy(newArray
, This
->context
, sizeof(*newArray
) * This
->num_contexts
);
580 HeapFree(GetProcessHeap(), 0, This
->context
);
581 newArray
[This
->num_contexts
] = ctx
;
582 This
->context
= newArray
;
583 This
->num_contexts
++;
585 TRACE("Returning context %p\n", ctx
);
589 void get_drawable_size_swapchain(IWineD3DSurfaceImpl
*This
, UINT
*width
, UINT
*height
) {
590 /* The drawable size of an onscreen drawable is the surface size.
591 * (Actually: The window size, but the surface is created in window size)
593 *width
= This
->currentDesc
.Width
;
594 *height
= This
->currentDesc
.Height
;