1 | /*
|
---|
2 | *IDirect3DSwapChain9 implementation
|
---|
3 | *
|
---|
4 | *Copyright 2002-2003 Jason Edmeades
|
---|
5 | *Copyright 2002-2003 Raphael Junqueira
|
---|
6 | *Copyright 2005 Oliver Stieber
|
---|
7 | *Copyright 2007-2008 Stefan Dösinger for CodeWeavers
|
---|
8 | *
|
---|
9 | *This library is free software; you can redistribute it and/or
|
---|
10 | *modify it under the terms of the GNU Lesser General Public
|
---|
11 | *License as published by the Free Software Foundation; either
|
---|
12 | *version 2.1 of the License, or (at your option) any later version.
|
---|
13 | *
|
---|
14 | *This library is distributed in the hope that it will be useful,
|
---|
15 | *but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
17 | *Lesser General Public License for more details.
|
---|
18 | *
|
---|
19 | *You should have received a copy of the GNU Lesser General Public
|
---|
20 | *License along with this library; if not, write to the Free Software
|
---|
21 | *Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
---|
22 | */
|
---|
23 |
|
---|
24 | /*
|
---|
25 | * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
|
---|
26 | * other than GPL or LGPL is available it will apply instead, Sun elects to use only
|
---|
27 | * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
|
---|
28 | * a choice of LGPL license versions is made available with the language indicating
|
---|
29 | * that LGPLv2 or any later version may be used, or where a choice of which version
|
---|
30 | * of the LGPL is applied is otherwise unspecified.
|
---|
31 | */
|
---|
32 |
|
---|
33 | #include "config.h"
|
---|
34 | #include "wined3d_private.h"
|
---|
35 |
|
---|
36 | WINE_DEFAULT_DEBUG_CHANNEL(d3d);
|
---|
37 | WINE_DECLARE_DEBUG_CHANNEL(fps);
|
---|
38 |
|
---|
39 | static void WINAPI IWineGDISwapChainImpl_Destroy(IWineD3DSwapChain *iface, D3DCB_DESTROYSURFACEFN D3DCB_DestroyRenderback) {
|
---|
40 | IWineD3DSwapChainImpl *This = (IWineD3DSwapChainImpl *)iface;
|
---|
41 | WINED3DDISPLAYMODE mode;
|
---|
42 |
|
---|
43 | TRACE("Destroying swapchain %p\n", iface);
|
---|
44 |
|
---|
45 | IWineD3DSwapChain_SetGammaRamp(iface, 0, &This->orig_gamma);
|
---|
46 |
|
---|
47 | /* release the ref to the front and back buffer parents */
|
---|
48 | if(This->frontBuffer) {
|
---|
49 | IWineD3DSurface_SetContainer(This->frontBuffer, 0);
|
---|
50 | if(D3DCB_DestroyRenderback(This->frontBuffer) > 0) {
|
---|
51 | FIXME("(%p) Something's still holding the front buffer\n",This);
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 | if(This->backBuffer) {
|
---|
56 | UINT i;
|
---|
57 | for(i = 0; i < This->presentParms.BackBufferCount; i++) {
|
---|
58 | IWineD3DSurface_SetContainer(This->backBuffer[i], 0);
|
---|
59 | if(D3DCB_DestroyRenderback(This->backBuffer[i]) > 0) {
|
---|
60 | FIXME("(%p) Something's still holding the back buffer\n",This);
|
---|
61 | }
|
---|
62 | }
|
---|
63 | HeapFree(GetProcessHeap(), 0, This->backBuffer);
|
---|
64 | }
|
---|
65 |
|
---|
66 | /* Restore the screen resolution if we rendered in fullscreen
|
---|
67 | * This will restore the screen resolution to what it was before creating the swapchain. In case of d3d8 and d3d9
|
---|
68 | * this will be the original desktop resolution. In case of d3d7 this will be a NOP because ddraw sets the resolution
|
---|
69 | * before starting up Direct3D, thus orig_width and orig_height will be equal to the modes in the presentation params
|
---|
70 | */
|
---|
71 | if(This->presentParms.Windowed == FALSE && This->presentParms.AutoRestoreDisplayMode) {
|
---|
72 | mode.Width = This->orig_width;
|
---|
73 | mode.Height = This->orig_height;
|
---|
74 | mode.RefreshRate = 0;
|
---|
75 | mode.Format = This->orig_fmt;
|
---|
76 | IWineD3DDevice_SetDisplayMode((IWineD3DDevice *) This->wineD3DDevice, 0, &mode);
|
---|
77 | }
|
---|
78 |
|
---|
79 | HeapFree(GetProcessHeap(), 0, This);
|
---|
80 | }
|
---|
81 |
|
---|
82 | /*****************************************************************************
|
---|
83 | * x11_copy_to_screen
|
---|
84 | *
|
---|
85 | * Helper function that blts the front buffer contents to the target window
|
---|
86 | *
|
---|
87 | * Params:
|
---|
88 | * This: Surface to copy from
|
---|
89 | * rc: Rectangle to copy
|
---|
90 | *
|
---|
91 | *****************************************************************************/
|
---|
92 | void x11_copy_to_screen(IWineD3DSwapChainImpl *This, const RECT *rc)
|
---|
93 | {
|
---|
94 | IWineD3DSurfaceImpl *front = (IWineD3DSurfaceImpl *) This->frontBuffer;
|
---|
95 |
|
---|
96 | if(front->resource.usage & WINED3DUSAGE_RENDERTARGET) {
|
---|
97 | POINT offset = {0,0};
|
---|
98 | HWND hDisplayWnd;
|
---|
99 | HDC hDisplayDC;
|
---|
100 | HDC hSurfaceDC = 0;
|
---|
101 | RECT drawrect;
|
---|
102 | TRACE("(%p)->(%p): Copying to screen\n", front, rc);
|
---|
103 |
|
---|
104 | hSurfaceDC = front->hDC;
|
---|
105 |
|
---|
106 | hDisplayWnd = This->win_handle;
|
---|
107 | hDisplayDC = GetDCEx(hDisplayWnd, 0, DCX_CLIPSIBLINGS|DCX_CACHE);
|
---|
108 | if(rc) {
|
---|
109 | TRACE(" copying rect (%d,%d)->(%d,%d), offset (%d,%d)\n",
|
---|
110 | rc->left, rc->top, rc->right, rc->bottom, offset.x, offset.y);
|
---|
111 | }
|
---|
112 |
|
---|
113 | /* Front buffer coordinates are screen coordinates. Map them to the destination
|
---|
114 | * window if not fullscreened
|
---|
115 | */
|
---|
116 | if(This->presentParms.Windowed) {
|
---|
117 | ClientToScreen(hDisplayWnd, &offset);
|
---|
118 | }
|
---|
119 | #if 0
|
---|
120 | /* FIXME: This doesn't work... if users really want to run
|
---|
121 | * X in 8bpp, then we need to call directly into display.drv
|
---|
122 | * (or Wine's equivalent), and force a private colormap
|
---|
123 | * without default entries. */
|
---|
124 | if (front->palette) {
|
---|
125 | SelectPalette(hDisplayDC, front->palette->hpal, FALSE);
|
---|
126 | RealizePalette(hDisplayDC); /* sends messages => deadlocks */
|
---|
127 | }
|
---|
128 | #endif
|
---|
129 | drawrect.left = 0;
|
---|
130 | drawrect.right = front->currentDesc.Width;
|
---|
131 | drawrect.top = 0;
|
---|
132 | drawrect.bottom = front->currentDesc.Height;
|
---|
133 |
|
---|
134 | #if 0
|
---|
135 | /* TODO: Support clippers */
|
---|
136 | if (front->clipper)
|
---|
137 | {
|
---|
138 | RECT xrc;
|
---|
139 | HWND hwnd = ((IWineD3DClipperImpl *) front->clipper)->hWnd;
|
---|
140 | if (hwnd && GetClientRect(hwnd,&xrc))
|
---|
141 | {
|
---|
142 | OffsetRect(&xrc,offset.x,offset.y);
|
---|
143 | IntersectRect(&drawrect,&drawrect,&xrc);
|
---|
144 | }
|
---|
145 | }
|
---|
146 | #endif
|
---|
147 | if (rc) {
|
---|
148 | IntersectRect(&drawrect,&drawrect,rc);
|
---|
149 | }
|
---|
150 | else {
|
---|
151 | /* Only use this if the caller did not pass a rectangle, since
|
---|
152 | * due to double locking this could be the wrong one ...
|
---|
153 | */
|
---|
154 | if (front->lockedRect.left != front->lockedRect.right) {
|
---|
155 | IntersectRect(&drawrect,&drawrect,&front->lockedRect);
|
---|
156 | }
|
---|
157 | }
|
---|
158 |
|
---|
159 | BitBlt(hDisplayDC,
|
---|
160 | drawrect.left-offset.x, drawrect.top-offset.y,
|
---|
161 | drawrect.right-drawrect.left, drawrect.bottom-drawrect.top,
|
---|
162 | hSurfaceDC,
|
---|
163 | drawrect.left, drawrect.top,
|
---|
164 | SRCCOPY);
|
---|
165 | ReleaseDC(hDisplayWnd, hDisplayDC);
|
---|
166 | }
|
---|
167 | }
|
---|
168 |
|
---|
169 | static HRESULT WINAPI IWineGDISwapChainImpl_SetDestWindowOverride(IWineD3DSwapChain *iface, HWND window) {
|
---|
170 | IWineD3DSwapChainImpl *This = (IWineD3DSwapChainImpl *)iface;
|
---|
171 |
|
---|
172 | This->win_handle = window;
|
---|
173 | return WINED3D_OK;
|
---|
174 | }
|
---|
175 |
|
---|
176 | static HRESULT WINAPI IWineGDISwapChainImpl_Present(IWineD3DSwapChain *iface, CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion, DWORD dwFlags) {
|
---|
177 | IWineD3DSwapChainImpl *This = (IWineD3DSwapChainImpl *) iface;
|
---|
178 | IWineD3DSurfaceImpl *front, *back;
|
---|
179 |
|
---|
180 | if(!This->backBuffer) {
|
---|
181 | WARN("Swapchain doesn't have a backbuffer, returning WINED3DERR_INVALIDCALL\n");
|
---|
182 | return WINED3DERR_INVALIDCALL;
|
---|
183 | }
|
---|
184 | front = (IWineD3DSurfaceImpl *) This->frontBuffer;
|
---|
185 | back = (IWineD3DSurfaceImpl *) This->backBuffer[0];
|
---|
186 |
|
---|
187 | /* Flip the DC */
|
---|
188 | {
|
---|
189 | HDC tmp;
|
---|
190 | tmp = front->hDC;
|
---|
191 | front->hDC = back->hDC;
|
---|
192 | back->hDC = tmp;
|
---|
193 | }
|
---|
194 |
|
---|
195 | /* Flip the DIBsection */
|
---|
196 | {
|
---|
197 | HBITMAP tmp;
|
---|
198 | tmp = front->dib.DIBsection;
|
---|
199 | front->dib.DIBsection = back->dib.DIBsection;
|
---|
200 | back->dib.DIBsection = tmp;
|
---|
201 | }
|
---|
202 |
|
---|
203 | /* Flip the surface data */
|
---|
204 | {
|
---|
205 | void* tmp;
|
---|
206 |
|
---|
207 | tmp = front->dib.bitmap_data;
|
---|
208 | front->dib.bitmap_data = back->dib.bitmap_data;
|
---|
209 | back->dib.bitmap_data = tmp;
|
---|
210 |
|
---|
211 | tmp = front->resource.allocatedMemory;
|
---|
212 | front->resource.allocatedMemory = back->resource.allocatedMemory;
|
---|
213 | back->resource.allocatedMemory = tmp;
|
---|
214 |
|
---|
215 | if(front->resource.heapMemory) {
|
---|
216 | ERR("GDI Surface %p has heap memory allocated\n", front);
|
---|
217 | }
|
---|
218 | if(back->resource.heapMemory) {
|
---|
219 | ERR("GDI Surface %p has heap memory allocated\n", back);
|
---|
220 | }
|
---|
221 | }
|
---|
222 |
|
---|
223 | /* client_memory should not be different, but just in case */
|
---|
224 | {
|
---|
225 | BOOL tmp;
|
---|
226 | tmp = front->dib.client_memory;
|
---|
227 | front->dib.client_memory = back->dib.client_memory;
|
---|
228 | back->dib.client_memory = tmp;
|
---|
229 | }
|
---|
230 |
|
---|
231 | /* FPS support */
|
---|
232 | if (TRACE_ON(fps))
|
---|
233 | {
|
---|
234 | static long prev_time, frames;
|
---|
235 |
|
---|
236 | DWORD time = GetTickCount();
|
---|
237 | frames++;
|
---|
238 | /* every 1.5 seconds */
|
---|
239 | if (time - prev_time > 1500) {
|
---|
240 | TRACE_(fps)("@ approx %.2ffps\n", 1000.0*frames/(time - prev_time));
|
---|
241 | prev_time = time;
|
---|
242 | frames = 0;
|
---|
243 | }
|
---|
244 | }
|
---|
245 |
|
---|
246 | x11_copy_to_screen(This, NULL);
|
---|
247 |
|
---|
248 | return WINED3D_OK;
|
---|
249 | }
|
---|
250 |
|
---|
251 | const IWineD3DSwapChainVtbl IWineGDISwapChain_Vtbl =
|
---|
252 | {
|
---|
253 | /* IUnknown */
|
---|
254 | IWineD3DBaseSwapChainImpl_QueryInterface,
|
---|
255 | IWineD3DBaseSwapChainImpl_AddRef,
|
---|
256 | IWineD3DBaseSwapChainImpl_Release,
|
---|
257 | /* IWineD3DSwapChain */
|
---|
258 | IWineD3DBaseSwapChainImpl_GetParent,
|
---|
259 | IWineGDISwapChainImpl_Destroy,
|
---|
260 | IWineD3DBaseSwapChainImpl_GetDevice,
|
---|
261 | IWineGDISwapChainImpl_Present,
|
---|
262 | IWineGDISwapChainImpl_SetDestWindowOverride,
|
---|
263 | IWineD3DBaseSwapChainImpl_GetFrontBufferData,
|
---|
264 | IWineD3DBaseSwapChainImpl_GetBackBuffer,
|
---|
265 | IWineD3DBaseSwapChainImpl_GetRasterStatus,
|
---|
266 | IWineD3DBaseSwapChainImpl_GetDisplayMode,
|
---|
267 | IWineD3DBaseSwapChainImpl_GetPresentParameters,
|
---|
268 | IWineD3DBaseSwapChainImpl_SetGammaRamp,
|
---|
269 | IWineD3DBaseSwapChainImpl_GetGammaRamp
|
---|
270 | };
|
---|