VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/swapchain_gdi.c@ 29452

Last change on this file since 29452 was 25949, checked in by vboxsync, 15 years ago

crOpenGL: update to wine 1.1.36 and disable unnecessary fbo state poll

  • Property svn:eol-style set to native
File size: 9.3 KB
Line 
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
36WINE_DEFAULT_DEBUG_CHANNEL(d3d);
37WINE_DECLARE_DEBUG_CHANNEL(fps);
38
39static void WINAPI IWineGDISwapChainImpl_Destroy(IWineD3DSwapChain *iface)
40{
41 IWineD3DSwapChainImpl *This = (IWineD3DSwapChainImpl *)iface;
42 WINED3DDISPLAYMODE mode;
43
44 TRACE("Destroying swapchain %p\n", iface);
45
46 IWineD3DSwapChain_SetGammaRamp(iface, 0, &This->orig_gamma);
47
48 /* release the ref to the front and back buffer parents */
49 if(This->frontBuffer) {
50 IWineD3DSurface_SetContainer(This->frontBuffer, 0);
51 if (IWineD3DSurface_Release(This->frontBuffer) > 0)
52 {
53 WARN("(%p) Something's still holding the front buffer\n",This);
54 }
55 }
56
57 if(This->backBuffer) {
58 UINT i;
59 for(i = 0; i < This->presentParms.BackBufferCount; i++) {
60 IWineD3DSurface_SetContainer(This->backBuffer[i], 0);
61 if (IWineD3DSurface_Release(This->backBuffer[i]) > 0)
62 {
63 WARN("(%p) Something's still holding the back buffer\n",This);
64 }
65 }
66 HeapFree(GetProcessHeap(), 0, This->backBuffer);
67 }
68
69 /* Restore the screen resolution if we rendered in fullscreen
70 * This will restore the screen resolution to what it was before creating the swapchain. In case of d3d8 and d3d9
71 * this will be the original desktop resolution. In case of d3d7 this will be a NOP because ddraw sets the resolution
72 * before starting up Direct3D, thus orig_width and orig_height will be equal to the modes in the presentation params
73 */
74 if(This->presentParms.Windowed == FALSE && This->presentParms.AutoRestoreDisplayMode) {
75 mode.Width = This->orig_width;
76 mode.Height = This->orig_height;
77 mode.RefreshRate = 0;
78 mode.Format = This->orig_fmt;
79 IWineD3DDevice_SetDisplayMode((IWineD3DDevice *)This->device, 0, &mode);
80 }
81
82 HeapFree(GetProcessHeap(), 0, This->context);
83 HeapFree(GetProcessHeap(), 0, This);
84}
85
86/*****************************************************************************
87 * x11_copy_to_screen
88 *
89 * Helper function that blts the front buffer contents to the target window
90 *
91 * Params:
92 * This: Surface to copy from
93 * rc: Rectangle to copy
94 *
95 *****************************************************************************/
96void x11_copy_to_screen(IWineD3DSwapChainImpl *This, const RECT *rc)
97{
98 IWineD3DSurfaceImpl *front = (IWineD3DSurfaceImpl *) This->frontBuffer;
99
100 if(front->resource.usage & WINED3DUSAGE_RENDERTARGET) {
101 POINT offset = {0,0};
102 HWND hDisplayWnd;
103 HDC hDisplayDC;
104 HDC hSurfaceDC = 0;
105 RECT drawrect;
106 TRACE("(%p)->(%p): Copying to screen\n", front, rc);
107
108 hSurfaceDC = front->hDC;
109
110 hDisplayWnd = This->win_handle;
111 hDisplayDC = GetDCEx(hDisplayWnd, 0, DCX_CLIPSIBLINGS|DCX_CACHE);
112 if(rc) {
113 TRACE(" copying rect (%d,%d)->(%d,%d), offset (%d,%d)\n",
114 rc->left, rc->top, rc->right, rc->bottom, offset.x, offset.y);
115 }
116
117 /* Front buffer coordinates are screen coordinates. Map them to the destination
118 * window if not fullscreened
119 */
120 if(This->presentParms.Windowed) {
121 ClientToScreen(hDisplayWnd, &offset);
122 }
123#if 0
124 /* FIXME: This doesn't work... if users really want to run
125 * X in 8bpp, then we need to call directly into display.drv
126 * (or Wine's equivalent), and force a private colormap
127 * without default entries. */
128 if (front->palette) {
129 SelectPalette(hDisplayDC, front->palette->hpal, FALSE);
130 RealizePalette(hDisplayDC); /* sends messages => deadlocks */
131 }
132#endif
133 drawrect.left = 0;
134 drawrect.right = front->currentDesc.Width;
135 drawrect.top = 0;
136 drawrect.bottom = front->currentDesc.Height;
137
138#if 0
139 /* TODO: Support clippers */
140 if (front->clipper)
141 {
142 RECT xrc;
143 HWND hwnd = ((IWineD3DClipperImpl *) front->clipper)->hWnd;
144 if (hwnd && GetClientRect(hwnd,&xrc))
145 {
146 OffsetRect(&xrc,offset.x,offset.y);
147 IntersectRect(&drawrect,&drawrect,&xrc);
148 }
149 }
150#endif
151 if (rc) {
152 IntersectRect(&drawrect,&drawrect,rc);
153 }
154 else {
155 /* Only use this if the caller did not pass a rectangle, since
156 * due to double locking this could be the wrong one ...
157 */
158 if (front->lockedRect.left != front->lockedRect.right) {
159 IntersectRect(&drawrect,&drawrect,&front->lockedRect);
160 }
161 }
162
163 BitBlt(hDisplayDC,
164 drawrect.left-offset.x, drawrect.top-offset.y,
165 drawrect.right-drawrect.left, drawrect.bottom-drawrect.top,
166 hSurfaceDC,
167 drawrect.left, drawrect.top,
168 SRCCOPY);
169 ReleaseDC(hDisplayWnd, hDisplayDC);
170 }
171}
172
173static HRESULT WINAPI IWineGDISwapChainImpl_SetDestWindowOverride(IWineD3DSwapChain *iface, HWND window) {
174 IWineD3DSwapChainImpl *This = (IWineD3DSwapChainImpl *)iface;
175
176 This->win_handle = window;
177 return WINED3D_OK;
178}
179
180static HRESULT WINAPI IWineGDISwapChainImpl_Present(IWineD3DSwapChain *iface, CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion, DWORD dwFlags) {
181 IWineD3DSwapChainImpl *This = (IWineD3DSwapChainImpl *) iface;
182 IWineD3DSurfaceImpl *front, *back;
183
184 if(!This->backBuffer) {
185 WARN("Swapchain doesn't have a backbuffer, returning WINED3DERR_INVALIDCALL\n");
186 return WINED3DERR_INVALIDCALL;
187 }
188 front = (IWineD3DSurfaceImpl *) This->frontBuffer;
189 back = (IWineD3DSurfaceImpl *) This->backBuffer[0];
190
191 /* Flip the DC */
192 {
193 HDC tmp;
194 tmp = front->hDC;
195 front->hDC = back->hDC;
196 back->hDC = tmp;
197 }
198
199 /* Flip the DIBsection */
200 {
201 HBITMAP tmp;
202 tmp = front->dib.DIBsection;
203 front->dib.DIBsection = back->dib.DIBsection;
204 back->dib.DIBsection = tmp;
205 }
206
207 /* Flip the surface data */
208 {
209 void* tmp;
210
211 tmp = front->dib.bitmap_data;
212 front->dib.bitmap_data = back->dib.bitmap_data;
213 back->dib.bitmap_data = tmp;
214
215 tmp = front->resource.allocatedMemory;
216 front->resource.allocatedMemory = back->resource.allocatedMemory;
217 back->resource.allocatedMemory = tmp;
218
219 if(front->resource.heapMemory) {
220 ERR("GDI Surface %p has heap memory allocated\n", front);
221 }
222 if(back->resource.heapMemory) {
223 ERR("GDI Surface %p has heap memory allocated\n", back);
224 }
225 }
226
227 /* client_memory should not be different, but just in case */
228 {
229 BOOL tmp;
230 tmp = front->dib.client_memory;
231 front->dib.client_memory = back->dib.client_memory;
232 back->dib.client_memory = tmp;
233 }
234
235 /* FPS support */
236 if (TRACE_ON(fps))
237 {
238 static long prev_time, frames;
239
240 DWORD time = GetTickCount();
241 frames++;
242 /* every 1.5 seconds */
243 if (time - prev_time > 1500) {
244 TRACE_(fps)("@ approx %.2ffps\n", 1000.0*frames/(time - prev_time));
245 prev_time = time;
246 frames = 0;
247 }
248 }
249
250 x11_copy_to_screen(This, NULL);
251
252 return WINED3D_OK;
253}
254
255const IWineD3DSwapChainVtbl IWineGDISwapChain_Vtbl =
256{
257 /* IUnknown */
258 IWineD3DBaseSwapChainImpl_QueryInterface,
259 IWineD3DBaseSwapChainImpl_AddRef,
260 IWineD3DBaseSwapChainImpl_Release,
261 /* IWineD3DSwapChain */
262 IWineD3DBaseSwapChainImpl_GetParent,
263 IWineGDISwapChainImpl_Destroy,
264 IWineD3DBaseSwapChainImpl_GetDevice,
265 IWineGDISwapChainImpl_Present,
266 IWineGDISwapChainImpl_SetDestWindowOverride,
267 IWineD3DBaseSwapChainImpl_GetFrontBufferData,
268 IWineD3DBaseSwapChainImpl_GetBackBuffer,
269 IWineD3DBaseSwapChainImpl_GetRasterStatus,
270 IWineD3DBaseSwapChainImpl_GetDisplayMode,
271 IWineD3DBaseSwapChainImpl_GetPresentParameters,
272 IWineD3DBaseSwapChainImpl_SetGammaRamp,
273 IWineD3DBaseSwapChainImpl_GetGammaRamp
274};
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette