VirtualBox

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

Last change on this file since 32891 was 32622, checked in by vboxsync, 14 years ago

wddm: VBOXWDDM->VBOX_WITH_WDDM

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

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