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 | * Oracle 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, Oracle 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 |
|
---|
37 | /*TODO: some of the additional parameters may be required to
|
---|
38 | set the gamma ramp (for some weird reason microsoft have left swap gammaramp in device
|
---|
39 | but it operates on a swapchain, it may be a good idea to move it to IWineD3DSwapChain for IWineD3D)*/
|
---|
40 |
|
---|
41 |
|
---|
42 | WINE_DEFAULT_DEBUG_CHANNEL(d3d);
|
---|
43 | WINE_DECLARE_DEBUG_CHANNEL(fps);
|
---|
44 |
|
---|
45 | #define GLINFO_LOCATION This->device->adapter->gl_info
|
---|
46 |
|
---|
47 | /*IWineD3DSwapChain parts follow: */
|
---|
48 | static void WINAPI IWineD3DSwapChainImpl_Destroy(IWineD3DSwapChain *iface)
|
---|
49 | {
|
---|
50 | IWineD3DSwapChainImpl *This = (IWineD3DSwapChainImpl *)iface;
|
---|
51 | WINED3DDISPLAYMODE mode;
|
---|
52 | unsigned int i;
|
---|
53 |
|
---|
54 | TRACE("Destroying swapchain %p\n", iface);
|
---|
55 |
|
---|
56 | IWineD3DSwapChain_SetGammaRamp(iface, 0, &This->orig_gamma);
|
---|
57 |
|
---|
58 | /* Release the swapchain's draw buffers. Make sure This->backBuffer[0] is
|
---|
59 | * the last buffer to be destroyed, FindContext() depends on that. */
|
---|
60 | if (This->frontBuffer)
|
---|
61 | {
|
---|
62 | IWineD3DSurface_SetContainer(This->frontBuffer, 0);
|
---|
63 | if (IWineD3DSurface_Release(This->frontBuffer))
|
---|
64 | {
|
---|
65 | WARN("(%p) Something's still holding the front buffer (%p).\n",
|
---|
66 | This, This->frontBuffer);
|
---|
67 | }
|
---|
68 | This->frontBuffer = NULL;
|
---|
69 | }
|
---|
70 |
|
---|
71 | if (This->backBuffer)
|
---|
72 | {
|
---|
73 | UINT i = This->presentParms.BackBufferCount;
|
---|
74 |
|
---|
75 | while (i--)
|
---|
76 | {
|
---|
77 | IWineD3DSurface_SetContainer(This->backBuffer[i], 0);
|
---|
78 | if (IWineD3DSurface_Release(This->backBuffer[i]))
|
---|
79 | WARN("(%p) Something's still holding back buffer %u (%p).\n",
|
---|
80 | This, i, This->backBuffer[i]);
|
---|
81 | }
|
---|
82 | HeapFree(GetProcessHeap(), 0, This->backBuffer);
|
---|
83 | This->backBuffer = NULL;
|
---|
84 | }
|
---|
85 | #ifndef VBOX_WITH_WDDM
|
---|
86 | for (i = 0; i < This->num_contexts; ++i)
|
---|
87 | {
|
---|
88 | context_destroy(This->device, This->context[i]);
|
---|
89 | }
|
---|
90 | #else
|
---|
91 | IWineD3DDevice_RemoveSwapChain(This->device, This);
|
---|
92 | if (!This->device->NumberOfSwapChains)
|
---|
93 | #endif
|
---|
94 | {
|
---|
95 | /* Restore the screen resolution if we rendered in fullscreen
|
---|
96 | * This will restore the screen resolution to what it was before creating the swapchain. In case of d3d8 and d3d9
|
---|
97 | * this will be the original desktop resolution. In case of d3d7 this will be a NOP because ddraw sets the resolution
|
---|
98 | * before starting up Direct3D, thus orig_width and orig_height will be equal to the modes in the presentation params
|
---|
99 | */
|
---|
100 | if(This->presentParms.Windowed == FALSE && This->presentParms.AutoRestoreDisplayMode) {
|
---|
101 | mode.Width = This->orig_width;
|
---|
102 | mode.Height = This->orig_height;
|
---|
103 | mode.RefreshRate = 0;
|
---|
104 | mode.Format = This->orig_fmt;
|
---|
105 | IWineD3DDevice_SetDisplayMode((IWineD3DDevice *)This->device, 0, &mode);
|
---|
106 | }
|
---|
107 | }
|
---|
108 | #ifdef VBOX_WITH_WDDM
|
---|
109 | if(This->device_window) {
|
---|
110 | /* see VBoxExtGet/ReleaseDC for comments */
|
---|
111 | VBoxExtReleaseDC(This->device_window, This->hDC);
|
---|
112 | }
|
---|
113 | #else
|
---|
114 | HeapFree(GetProcessHeap(), 0, This->context);
|
---|
115 | #endif
|
---|
116 | HeapFree(GetProcessHeap(), 0, This);
|
---|
117 | }
|
---|
118 |
|
---|
119 | /* A GL context is provided by the caller */
|
---|
120 | static void swapchain_blit(IWineD3DSwapChainImpl *This, struct wined3d_context *context,
|
---|
121 | const RECT *src_rect, const RECT *dst_rect)
|
---|
122 | {
|
---|
123 | IWineD3DDeviceImpl *device = This->device;
|
---|
124 | IWineD3DSurfaceImpl *backbuffer = ((IWineD3DSurfaceImpl *) This->backBuffer[0]);
|
---|
125 | UINT src_w = src_rect->right - src_rect->left;
|
---|
126 | UINT src_h = src_rect->bottom - src_rect->top;
|
---|
127 | GLenum gl_filter;
|
---|
128 | const struct wined3d_gl_info *gl_info = context->gl_info;
|
---|
129 |
|
---|
130 | TRACE("swapchain %p, context %p, src_rect %s, dst_rect %s.\n",
|
---|
131 | This, context, wine_dbgstr_rect(src_rect), wine_dbgstr_rect(dst_rect));
|
---|
132 |
|
---|
133 | if (src_w == dst_rect->right - dst_rect->left && src_h == dst_rect->bottom - dst_rect->top)
|
---|
134 | gl_filter = GL_NEAREST;
|
---|
135 | else
|
---|
136 | gl_filter = GL_LINEAR;
|
---|
137 |
|
---|
138 | if (0 && gl_info->fbo_ops.glBlitFramebuffer && is_identity_fixup(backbuffer->resource.format_desc->color_fixup))
|
---|
139 | {
|
---|
140 | ENTER_GL();
|
---|
141 | context_bind_fbo(context, GL_READ_FRAMEBUFFER, &context->src_fbo);
|
---|
142 | context_attach_surface_fbo(context, GL_READ_FRAMEBUFFER, 0, backbuffer);
|
---|
143 | context_attach_depth_stencil_fbo(context, GL_READ_FRAMEBUFFER, NULL, FALSE);
|
---|
144 |
|
---|
145 | context_bind_fbo(context, GL_DRAW_FRAMEBUFFER, NULL);
|
---|
146 | context_set_draw_buffer(context, GL_BACK);
|
---|
147 |
|
---|
148 | glDisable(GL_SCISSOR_TEST);
|
---|
149 | IWineD3DDeviceImpl_MarkStateDirty(This->device, STATE_RENDER(WINED3DRS_SCISSORTESTENABLE));
|
---|
150 |
|
---|
151 | /* Note that the texture is upside down */
|
---|
152 | gl_info->fbo_ops.glBlitFramebuffer(src_rect->left, src_rect->top, src_rect->right, src_rect->bottom,
|
---|
153 | dst_rect->left, dst_rect->bottom, dst_rect->right, dst_rect->top,
|
---|
154 | GL_COLOR_BUFFER_BIT, gl_filter);
|
---|
155 | checkGLcall("Swapchain present blit(EXT_framebuffer_blit)\n");
|
---|
156 | LEAVE_GL();
|
---|
157 | }
|
---|
158 | else
|
---|
159 | {
|
---|
160 | struct wined3d_context *context2;
|
---|
161 | float tex_left = src_rect->left;
|
---|
162 | float tex_top = src_rect->top;
|
---|
163 | float tex_right = src_rect->right;
|
---|
164 | float tex_bottom = src_rect->bottom;
|
---|
165 |
|
---|
166 | context2 = context_acquire(This->device, This->backBuffer[0], CTXUSAGE_BLIT);
|
---|
167 |
|
---|
168 | if(backbuffer->Flags & SFLAG_NORMCOORD)
|
---|
169 | {
|
---|
170 | tex_left /= src_w;
|
---|
171 | tex_right /= src_w;
|
---|
172 | tex_top /= src_h;
|
---|
173 | tex_bottom /= src_h;
|
---|
174 | }
|
---|
175 |
|
---|
176 | if (is_complex_fixup(backbuffer->resource.format_desc->color_fixup))
|
---|
177 | gl_filter = GL_NEAREST;
|
---|
178 |
|
---|
179 | ENTER_GL();
|
---|
180 | context_bind_fbo(context2, GL_DRAW_FRAMEBUFFER, NULL);
|
---|
181 |
|
---|
182 | /* Set up the texture. The surface is not in a IWineD3D*Texture container,
|
---|
183 | * so there are no d3d texture settings to dirtify
|
---|
184 | */
|
---|
185 | device->blitter->set_shader((IWineD3DDevice *) device, backbuffer);
|
---|
186 | glTexParameteri(backbuffer->texture_target, GL_TEXTURE_MIN_FILTER, gl_filter);
|
---|
187 | glTexParameteri(backbuffer->texture_target, GL_TEXTURE_MAG_FILTER, gl_filter);
|
---|
188 |
|
---|
189 | context_set_draw_buffer(context, GL_BACK);
|
---|
190 |
|
---|
191 | /* Set the viewport to the destination rectandle, disable any projection
|
---|
192 | * transformation set up by CTXUSAGE_BLIT, and draw a (-1,-1)-(1,1) quad.
|
---|
193 | *
|
---|
194 | * Back up viewport and matrix to avoid breaking last_was_blit
|
---|
195 | *
|
---|
196 | * Note that CTXUSAGE_BLIT set up viewport and ortho to match the surface
|
---|
197 | * size - we want the GL drawable(=window) size.
|
---|
198 | */
|
---|
199 | glPushAttrib(GL_VIEWPORT_BIT);
|
---|
200 | glViewport(dst_rect->left, dst_rect->top, dst_rect->right, dst_rect->bottom);
|
---|
201 | glMatrixMode(GL_PROJECTION);
|
---|
202 | glPushMatrix();
|
---|
203 | glLoadIdentity();
|
---|
204 |
|
---|
205 | glBegin(GL_QUADS);
|
---|
206 | /* bottom left */
|
---|
207 | glTexCoord2f(tex_left, tex_bottom);
|
---|
208 | glVertex2i(-1, -1);
|
---|
209 |
|
---|
210 | /* top left */
|
---|
211 | glTexCoord2f(tex_left, tex_top);
|
---|
212 | glVertex2i(-1, 1);
|
---|
213 |
|
---|
214 | /* top right */
|
---|
215 | glTexCoord2f(tex_right, tex_top);
|
---|
216 | glVertex2i(1, 1);
|
---|
217 |
|
---|
218 | /* bottom right */
|
---|
219 | glTexCoord2f(tex_right, tex_bottom);
|
---|
220 | glVertex2i(1, -1);
|
---|
221 | glEnd();
|
---|
222 |
|
---|
223 | glPopMatrix();
|
---|
224 | glPopAttrib();
|
---|
225 |
|
---|
226 | device->blitter->unset_shader((IWineD3DDevice *) device);
|
---|
227 | checkGLcall("Swapchain present blit(manual)\n");
|
---|
228 | LEAVE_GL();
|
---|
229 |
|
---|
230 | context_release(context2);
|
---|
231 | }
|
---|
232 | }
|
---|
233 |
|
---|
234 | static HRESULT WINAPI IWineD3DSwapChainImpl_Present(IWineD3DSwapChain *iface, CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion, DWORD dwFlags) {
|
---|
235 | IWineD3DSwapChainImpl *This = (IWineD3DSwapChainImpl *)iface;
|
---|
236 | struct wined3d_context *context;
|
---|
237 | RECT src_rect, dst_rect;
|
---|
238 | BOOL render_to_fbo;
|
---|
239 | unsigned int sync;
|
---|
240 | int retval;
|
---|
241 |
|
---|
242 | IWineD3DSwapChain_SetDestWindowOverride(iface, hDestWindowOverride);
|
---|
243 |
|
---|
244 | context = context_acquire(This->device, This->backBuffer[0], CTXUSAGE_RESOURCELOAD);
|
---|
245 | if (!context->valid)
|
---|
246 | {
|
---|
247 | context_release(context);
|
---|
248 | WARN("Invalid context, skipping present.\n");
|
---|
249 | return WINED3D_OK;
|
---|
250 | }
|
---|
251 |
|
---|
252 | /* Render the cursor onto the back buffer, using our nifty directdraw blitting code :-) */
|
---|
253 | if (This->device->bCursorVisible && This->device->cursorTexture)
|
---|
254 | {
|
---|
255 | IWineD3DSurfaceImpl cursor;
|
---|
256 | RECT destRect =
|
---|
257 | {
|
---|
258 | This->device->xScreenSpace - This->device->xHotSpot,
|
---|
259 | This->device->yScreenSpace - This->device->yHotSpot,
|
---|
260 | This->device->xScreenSpace + This->device->cursorWidth - This->device->xHotSpot,
|
---|
261 | This->device->yScreenSpace + This->device->cursorHeight - This->device->yHotSpot,
|
---|
262 | };
|
---|
263 | TRACE("Rendering the cursor. Creating fake surface at %p\n", &cursor);
|
---|
264 | /* Build a fake surface to call the Blitting code. It is not possible to use the interface passed by
|
---|
265 | * the application because we are only supposed to copy the information out. Using a fake surface
|
---|
266 | * allows to use the Blitting engine and avoid copying the whole texture -> render target blitting code.
|
---|
267 | */
|
---|
268 | memset(&cursor, 0, sizeof(cursor));
|
---|
269 | cursor.lpVtbl = &IWineD3DSurface_Vtbl;
|
---|
270 | cursor.resource.ref = 1;
|
---|
271 | cursor.resource.device = This->device;
|
---|
272 | cursor.resource.pool = WINED3DPOOL_SCRATCH;
|
---|
273 | cursor.resource.format_desc = getFormatDescEntry(WINED3DFMT_B8G8R8A8_UNORM, context->gl_info);
|
---|
274 | cursor.resource.resourceType = WINED3DRTYPE_SURFACE;
|
---|
275 | cursor.texture_name = This->device->cursorTexture;
|
---|
276 | cursor.texture_target = GL_TEXTURE_2D;
|
---|
277 | cursor.texture_level = 0;
|
---|
278 | cursor.currentDesc.Width = This->device->cursorWidth;
|
---|
279 | cursor.currentDesc.Height = This->device->cursorHeight;
|
---|
280 | /* The cursor must have pow2 sizes */
|
---|
281 | cursor.pow2Width = cursor.currentDesc.Width;
|
---|
282 | cursor.pow2Height = cursor.currentDesc.Height;
|
---|
283 | /* The surface is in the texture */
|
---|
284 | cursor.Flags |= SFLAG_INTEXTURE;
|
---|
285 | /* DDBLT_KEYSRC will cause BltOverride to enable the alpha test with GL_NOTEQUAL, 0.0,
|
---|
286 | * which is exactly what we want :-)
|
---|
287 | */
|
---|
288 | if (This->presentParms.Windowed) {
|
---|
289 | MapWindowPoints(NULL, This->win_handle, (LPPOINT)&destRect, 2);
|
---|
290 | }
|
---|
291 | IWineD3DSurface_Blt(This->backBuffer[0], &destRect, (IWineD3DSurface *)&cursor,
|
---|
292 | NULL, WINEDDBLT_KEYSRC, NULL, WINED3DTEXF_POINT);
|
---|
293 | }
|
---|
294 |
|
---|
295 | if (This->device->logo_surface)
|
---|
296 | {
|
---|
297 | /* Blit the logo into the upper left corner of the drawable. */
|
---|
298 | IWineD3DSurface_BltFast(This->backBuffer[0], 0, 0, This->device->logo_surface, NULL, WINEDDBLTFAST_SRCCOLORKEY);
|
---|
299 | }
|
---|
300 |
|
---|
301 | TRACE("Presenting HDC %p.\n", context->hdc);
|
---|
302 |
|
---|
303 | render_to_fbo = This->render_to_fbo;
|
---|
304 |
|
---|
305 | if (pSourceRect)
|
---|
306 | {
|
---|
307 | src_rect = *pSourceRect;
|
---|
308 | if (!render_to_fbo && (src_rect.left || src_rect.top
|
---|
309 | || src_rect.right != This->presentParms.BackBufferWidth
|
---|
310 | || src_rect.bottom != This->presentParms.BackBufferHeight))
|
---|
311 | {
|
---|
312 | render_to_fbo = TRUE;
|
---|
313 | }
|
---|
314 | }
|
---|
315 | else
|
---|
316 | {
|
---|
317 | src_rect.left = 0;
|
---|
318 | src_rect.top = 0;
|
---|
319 | src_rect.right = This->presentParms.BackBufferWidth;
|
---|
320 | src_rect.bottom = This->presentParms.BackBufferHeight;
|
---|
321 | }
|
---|
322 |
|
---|
323 | if (pDestRect) dst_rect = *pDestRect;
|
---|
324 | else GetClientRect(This->win_handle, &dst_rect);
|
---|
325 |
|
---|
326 | if (!render_to_fbo && (dst_rect.left || dst_rect.top
|
---|
327 | || dst_rect.right != This->presentParms.BackBufferWidth
|
---|
328 | || dst_rect.bottom != This->presentParms.BackBufferHeight))
|
---|
329 | {
|
---|
330 | render_to_fbo = TRUE;
|
---|
331 | }
|
---|
332 |
|
---|
333 | /* Rendering to a window of different size, presenting partial rectangles,
|
---|
334 | * or rendering to a different window needs help from FBO_blit or a textured
|
---|
335 | * draw. Render the swapchain to a FBO in the future.
|
---|
336 | *
|
---|
337 | * Note that FBO_blit from the backbuffer to the frontbuffer cannot solve
|
---|
338 | * all these issues - this fails if the window is smaller than the backbuffer.
|
---|
339 | */
|
---|
340 | if (!This->render_to_fbo && render_to_fbo && wined3d_settings.offscreen_rendering_mode == ORM_FBO)
|
---|
341 | {
|
---|
342 | IWineD3DSurface_LoadLocation(This->backBuffer[0], SFLAG_INTEXTURE, NULL);
|
---|
343 | IWineD3DSurface_ModifyLocation(This->backBuffer[0], SFLAG_INDRAWABLE, FALSE);
|
---|
344 | This->render_to_fbo = TRUE;
|
---|
345 |
|
---|
346 | /* Force the context manager to update the render target configuration next draw. */
|
---|
347 | context->current_rt = NULL;
|
---|
348 | }
|
---|
349 |
|
---|
350 | if(This->render_to_fbo)
|
---|
351 | {
|
---|
352 | /* This codepath should only be hit with the COPY swapeffect. Otherwise a backbuffer-
|
---|
353 | * window size mismatch is impossible(fullscreen) and src and dst rectangles are
|
---|
354 | * not allowed(they need the COPY swapeffect)
|
---|
355 | *
|
---|
356 | * The DISCARD swap effect is ok as well since any backbuffer content is allowed after
|
---|
357 | * the swap
|
---|
358 | */
|
---|
359 | if(This->presentParms.SwapEffect == WINED3DSWAPEFFECT_FLIP )
|
---|
360 | {
|
---|
361 | FIXME("Render-to-fbo with WINED3DSWAPEFFECT_FLIP\n");
|
---|
362 | }
|
---|
363 |
|
---|
364 | swapchain_blit(This, context, &src_rect, &dst_rect);
|
---|
365 | }
|
---|
366 |
|
---|
367 | #ifdef VBOX_WITH_WDDM
|
---|
368 | if (This->device->numContexts > 1) wglFinish();
|
---|
369 | #else
|
---|
370 | if (This->num_contexts > 1) wglFinish();
|
---|
371 | #endif
|
---|
372 |
|
---|
373 | #if defined(VBOX_WITH_WDDM) && defined(DEBUG)
|
---|
374 | {
|
---|
375 | HWND wnd = WindowFromDC(context->hdc);
|
---|
376 | Assert(context->currentSwapchain && context->win_handle==context->currentSwapchain->win_handle);
|
---|
377 | Assert(wnd==context->win_handle);
|
---|
378 | Assert(IsWindow(context->win_handle));
|
---|
379 | Assert(wnd == context->win_handle);
|
---|
380 | }
|
---|
381 | #endif
|
---|
382 |
|
---|
383 | #ifdef VBOX_WITH_WDDM
|
---|
384 | /* We're directly using wglMakeCurrent calls skipping GDI layer, which causes GDI SwapBuffers to fail trying to
|
---|
385 | * call glFinish, which doesn't have any context set. So we use wglSwapLayerBuffers directly as well.
|
---|
386 | */
|
---|
387 | pwglSwapLayerBuffers(context->hdc, WGL_SWAP_MAIN_PLANE);
|
---|
388 | #else
|
---|
389 | SwapBuffers(context->hdc); /* TODO: cycle through the swapchain buffers */
|
---|
390 | #endif
|
---|
391 |
|
---|
392 | TRACE("SwapBuffers called, Starting new frame\n");
|
---|
393 | /* FPS support */
|
---|
394 | if (TRACE_ON(fps))
|
---|
395 | {
|
---|
396 | DWORD time = GetTickCount();
|
---|
397 | This->frames++;
|
---|
398 | /* every 1.5 seconds */
|
---|
399 | if (time - This->prev_time > 1500) {
|
---|
400 | TRACE_(fps)("%p @ approx %.2ffps\n", This, 1000.0*This->frames/(time - This->prev_time));
|
---|
401 | This->prev_time = time;
|
---|
402 | This->frames = 0;
|
---|
403 | }
|
---|
404 | }
|
---|
405 |
|
---|
406 | #if defined(FRAME_DEBUGGING)
|
---|
407 | {
|
---|
408 | if (GetFileAttributesA("C:\\D3DTRACE") != INVALID_FILE_ATTRIBUTES) {
|
---|
409 | if (!isOn) {
|
---|
410 | isOn = TRUE;
|
---|
411 | FIXME("Enabling D3D Trace\n");
|
---|
412 | __WINE_SET_DEBUGGING(__WINE_DBCL_TRACE, __wine_dbch_d3d, 1);
|
---|
413 | #if defined(SHOW_FRAME_MAKEUP)
|
---|
414 | FIXME("Singe Frame snapshots Starting\n");
|
---|
415 | isDumpingFrames = TRUE;
|
---|
416 | ENTER_GL();
|
---|
417 | glClear(GL_COLOR_BUFFER_BIT);
|
---|
418 | LEAVE_GL();
|
---|
419 | #endif
|
---|
420 |
|
---|
421 | #if defined(SINGLE_FRAME_DEBUGGING)
|
---|
422 | } else {
|
---|
423 | #if defined(SHOW_FRAME_MAKEUP)
|
---|
424 | FIXME("Singe Frame snapshots Finishing\n");
|
---|
425 | isDumpingFrames = FALSE;
|
---|
426 | #endif
|
---|
427 | FIXME("Singe Frame trace complete\n");
|
---|
428 | DeleteFileA("C:\\D3DTRACE");
|
---|
429 | __WINE_SET_DEBUGGING(__WINE_DBCL_TRACE, __wine_dbch_d3d, 0);
|
---|
430 | #endif
|
---|
431 | }
|
---|
432 | } else {
|
---|
433 | if (isOn) {
|
---|
434 | isOn = FALSE;
|
---|
435 | #if defined(SHOW_FRAME_MAKEUP)
|
---|
436 | FIXME("Single Frame snapshots Finishing\n");
|
---|
437 | isDumpingFrames = FALSE;
|
---|
438 | #endif
|
---|
439 | FIXME("Disabling D3D Trace\n");
|
---|
440 | __WINE_SET_DEBUGGING(__WINE_DBCL_TRACE, __wine_dbch_d3d, 0);
|
---|
441 | }
|
---|
442 | }
|
---|
443 | }
|
---|
444 | #endif
|
---|
445 |
|
---|
446 | /* This is disabled, but the code left in for debug purposes.
|
---|
447 | *
|
---|
448 | * Since we're allowed to modify the new back buffer on a D3DSWAPEFFECT_DISCARD flip,
|
---|
449 | * we can clear it with some ugly color to make bad drawing visible and ease debugging.
|
---|
450 | * The Debug runtime does the same on Windows. However, a few games do not redraw the
|
---|
451 | * screen properly, like Max Payne 2, which leaves a few pixels undefined.
|
---|
452 | *
|
---|
453 | * Tests show that the content of the back buffer after a discard flip is indeed not
|
---|
454 | * reliable, so no game can depend on the exact content. However, it resembles the
|
---|
455 | * old contents in some way, for example by showing fragments at other locations. In
|
---|
456 | * general, the color theme is still intact. So Max payne, which draws rather dark scenes
|
---|
457 | * gets a dark background image. If we clear it with a bright ugly color, the game's
|
---|
458 | * bug shows up much more than it does on Windows, and the players see single pixels
|
---|
459 | * with wrong colors.
|
---|
460 | * (The Max Payne bug has been confirmed on Windows with the debug runtime)
|
---|
461 | */
|
---|
462 | if (FALSE && This->presentParms.SwapEffect == WINED3DSWAPEFFECT_DISCARD) {
|
---|
463 | TRACE("Clearing the color buffer with cyan color\n");
|
---|
464 |
|
---|
465 | IWineD3DDevice_Clear((IWineD3DDevice *)This->device, 0, NULL,
|
---|
466 | WINED3DCLEAR_TARGET, 0xff00ffff, 1.0f, 0);
|
---|
467 | }
|
---|
468 |
|
---|
469 | if(!This->render_to_fbo &&
|
---|
470 | ( ((IWineD3DSurfaceImpl *) This->frontBuffer)->Flags & SFLAG_INSYSMEM ||
|
---|
471 | ((IWineD3DSurfaceImpl *) This->backBuffer[0])->Flags & SFLAG_INSYSMEM ) ) {
|
---|
472 | /* Both memory copies of the surfaces are ok, flip them around too instead of dirtifying
|
---|
473 | * Doesn't work with render_to_fbo because we're not flipping
|
---|
474 | */
|
---|
475 | IWineD3DSurfaceImpl *front = (IWineD3DSurfaceImpl *) This->frontBuffer;
|
---|
476 | IWineD3DSurfaceImpl *back = (IWineD3DSurfaceImpl *) This->backBuffer[0];
|
---|
477 |
|
---|
478 | if(front->resource.size == back->resource.size) {
|
---|
479 | DWORD fbflags;
|
---|
480 | flip_surface(front, back);
|
---|
481 |
|
---|
482 | /* Tell the front buffer surface that is has been modified. However,
|
---|
483 | * the other locations were preserved during that, so keep the flags.
|
---|
484 | * This serves to update the emulated overlay, if any
|
---|
485 | */
|
---|
486 | fbflags = front->Flags;
|
---|
487 | IWineD3DSurface_ModifyLocation(This->frontBuffer, SFLAG_INDRAWABLE, TRUE);
|
---|
488 | front->Flags = fbflags;
|
---|
489 | } else {
|
---|
490 | IWineD3DSurface_ModifyLocation((IWineD3DSurface *) front, SFLAG_INDRAWABLE, TRUE);
|
---|
491 | IWineD3DSurface_ModifyLocation((IWineD3DSurface *) back, SFLAG_INDRAWABLE, TRUE);
|
---|
492 | }
|
---|
493 | } else {
|
---|
494 | IWineD3DSurface_ModifyLocation(This->frontBuffer, SFLAG_INDRAWABLE, TRUE);
|
---|
495 | /* If the swapeffect is DISCARD, the back buffer is undefined. That means the SYSMEM
|
---|
496 | * and INTEXTURE copies can keep their old content if they have any defined content.
|
---|
497 | * If the swapeffect is COPY, the content remains the same. If it is FLIP however,
|
---|
498 | * the texture / sysmem copy needs to be reloaded from the drawable
|
---|
499 | */
|
---|
500 | if(This->presentParms.SwapEffect == WINED3DSWAPEFFECT_FLIP) {
|
---|
501 | IWineD3DSurface_ModifyLocation(This->backBuffer[0], SFLAG_INDRAWABLE, TRUE);
|
---|
502 | }
|
---|
503 | }
|
---|
504 |
|
---|
505 | if (This->device->stencilBufferTarget)
|
---|
506 | {
|
---|
507 | if (This->presentParms.Flags & WINED3DPRESENTFLAG_DISCARD_DEPTHSTENCIL
|
---|
508 | || ((IWineD3DSurfaceImpl *)This->device->stencilBufferTarget)->Flags & SFLAG_DISCARD)
|
---|
509 | {
|
---|
510 | surface_modify_ds_location(This->device->stencilBufferTarget, SFLAG_DS_DISCARDED);
|
---|
511 | }
|
---|
512 | }
|
---|
513 |
|
---|
514 | if (This->presentParms.PresentationInterval != WINED3DPRESENT_INTERVAL_IMMEDIATE
|
---|
515 | && context->gl_info->supported[SGI_VIDEO_SYNC])
|
---|
516 | {
|
---|
517 | retval = GL_EXTCALL(glXGetVideoSyncSGI(&sync));
|
---|
518 | if(retval != 0) {
|
---|
519 | ERR("glXGetVideoSyncSGI failed(retval = %d\n", retval);
|
---|
520 | }
|
---|
521 |
|
---|
522 | switch(This->presentParms.PresentationInterval) {
|
---|
523 | case WINED3DPRESENT_INTERVAL_DEFAULT:
|
---|
524 | case WINED3DPRESENT_INTERVAL_ONE:
|
---|
525 | if(sync <= This->vSyncCounter) {
|
---|
526 | retval = GL_EXTCALL(glXWaitVideoSyncSGI(1, 0, &This->vSyncCounter));
|
---|
527 | } else {
|
---|
528 | This->vSyncCounter = sync;
|
---|
529 | }
|
---|
530 | break;
|
---|
531 | case WINED3DPRESENT_INTERVAL_TWO:
|
---|
532 | if(sync <= This->vSyncCounter + 1) {
|
---|
533 | retval = GL_EXTCALL(glXWaitVideoSyncSGI(2, This->vSyncCounter & 0x1, &This->vSyncCounter));
|
---|
534 | } else {
|
---|
535 | This->vSyncCounter = sync;
|
---|
536 | }
|
---|
537 | break;
|
---|
538 | case WINED3DPRESENT_INTERVAL_THREE:
|
---|
539 | if(sync <= This->vSyncCounter + 2) {
|
---|
540 | retval = GL_EXTCALL(glXWaitVideoSyncSGI(3, This->vSyncCounter % 0x3, &This->vSyncCounter));
|
---|
541 | } else {
|
---|
542 | This->vSyncCounter = sync;
|
---|
543 | }
|
---|
544 | break;
|
---|
545 | case WINED3DPRESENT_INTERVAL_FOUR:
|
---|
546 | if(sync <= This->vSyncCounter + 3) {
|
---|
547 | retval = GL_EXTCALL(glXWaitVideoSyncSGI(4, This->vSyncCounter & 0x3, &This->vSyncCounter));
|
---|
548 | } else {
|
---|
549 | This->vSyncCounter = sync;
|
---|
550 | }
|
---|
551 | break;
|
---|
552 | default:
|
---|
553 | FIXME("Unknown presentation interval %08x\n", This->presentParms.PresentationInterval);
|
---|
554 | }
|
---|
555 | }
|
---|
556 |
|
---|
557 | context_release(context);
|
---|
558 |
|
---|
559 | TRACE("returning\n");
|
---|
560 | return WINED3D_OK;
|
---|
561 | }
|
---|
562 |
|
---|
563 | static HRESULT WINAPI IWineD3DSwapChainImpl_SetDestWindowOverride(IWineD3DSwapChain *iface, HWND window)
|
---|
564 | {
|
---|
565 | IWineD3DSwapChainImpl *swapchain = (IWineD3DSwapChainImpl *)iface;
|
---|
566 |
|
---|
567 | if (!window) window = swapchain->device_window;
|
---|
568 | if (window == swapchain->win_handle) return WINED3D_OK;
|
---|
569 |
|
---|
570 | TRACE("Setting swapchain %p window from %p to %p\n", swapchain, swapchain->win_handle, window);
|
---|
571 | swapchain->win_handle = window;
|
---|
572 |
|
---|
573 | return WINED3D_OK;
|
---|
574 | }
|
---|
575 |
|
---|
576 | static const IWineD3DSwapChainVtbl IWineD3DSwapChain_Vtbl =
|
---|
577 | {
|
---|
578 | /* IUnknown */
|
---|
579 | IWineD3DBaseSwapChainImpl_QueryInterface,
|
---|
580 | IWineD3DBaseSwapChainImpl_AddRef,
|
---|
581 | IWineD3DBaseSwapChainImpl_Release,
|
---|
582 | /* IWineD3DSwapChain */
|
---|
583 | IWineD3DBaseSwapChainImpl_GetParent,
|
---|
584 | IWineD3DSwapChainImpl_Destroy,
|
---|
585 | IWineD3DBaseSwapChainImpl_GetDevice,
|
---|
586 | IWineD3DSwapChainImpl_Present,
|
---|
587 | IWineD3DSwapChainImpl_SetDestWindowOverride,
|
---|
588 | IWineD3DBaseSwapChainImpl_GetFrontBufferData,
|
---|
589 | IWineD3DBaseSwapChainImpl_GetBackBuffer,
|
---|
590 | IWineD3DBaseSwapChainImpl_GetRasterStatus,
|
---|
591 | IWineD3DBaseSwapChainImpl_GetDisplayMode,
|
---|
592 | IWineD3DBaseSwapChainImpl_GetPresentParameters,
|
---|
593 | IWineD3DBaseSwapChainImpl_SetGammaRamp,
|
---|
594 | IWineD3DBaseSwapChainImpl_GetGammaRamp,
|
---|
595 | };
|
---|
596 |
|
---|
597 | static LONG fullscreen_style(LONG style)
|
---|
598 | {
|
---|
599 | /* Make sure the window is managed, otherwise we won't get keyboard input. */
|
---|
600 | style |= WS_POPUP | WS_SYSMENU;
|
---|
601 | style &= ~(WS_CAPTION | WS_THICKFRAME);
|
---|
602 |
|
---|
603 | return style;
|
---|
604 | }
|
---|
605 |
|
---|
606 | static LONG fullscreen_exstyle(LONG exstyle)
|
---|
607 | {
|
---|
608 | /* Filter out window decorations. */
|
---|
609 | exstyle &= ~(WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE);
|
---|
610 |
|
---|
611 | return exstyle;
|
---|
612 | }
|
---|
613 |
|
---|
614 | void swapchain_setup_fullscreen_window(IWineD3DSwapChainImpl *swapchain, UINT w, UINT h)
|
---|
615 | {
|
---|
616 | IWineD3DDeviceImpl *device = swapchain->device;
|
---|
617 | HWND window = swapchain->device_window;
|
---|
618 | BOOL filter_messages;
|
---|
619 | LONG style, exstyle;
|
---|
620 |
|
---|
621 | TRACE("Setting up window %p for fullscreen mode.\n", window);
|
---|
622 |
|
---|
623 | if (device->style || device->exStyle)
|
---|
624 | {
|
---|
625 | ERR("Changing the window style for window %p, but another style (%08x, %08x) is already stored.\n",
|
---|
626 | window, device->style, device->exStyle);
|
---|
627 | }
|
---|
628 |
|
---|
629 | device->style = GetWindowLongW(window, GWL_STYLE);
|
---|
630 | device->exStyle = GetWindowLongW(window, GWL_EXSTYLE);
|
---|
631 |
|
---|
632 | style = fullscreen_style(device->style);
|
---|
633 | exstyle = fullscreen_exstyle(device->exStyle);
|
---|
634 |
|
---|
635 | TRACE("Old style was %08x, %08x, setting to %08x, %08x.\n",
|
---|
636 | device->style, device->exStyle, style, exstyle);
|
---|
637 |
|
---|
638 | filter_messages = device->filter_messages;
|
---|
639 | device->filter_messages = TRUE;
|
---|
640 |
|
---|
641 | SetWindowLongW(window, GWL_STYLE, style);
|
---|
642 | SetWindowLongW(window, GWL_EXSTYLE, exstyle);
|
---|
643 | SetWindowPos(window, HWND_TOP, 0, 0, w, h, SWP_FRAMECHANGED | SWP_SHOWWINDOW | SWP_NOACTIVATE);
|
---|
644 |
|
---|
645 | device->filter_messages = filter_messages;
|
---|
646 | }
|
---|
647 |
|
---|
648 | void swapchain_restore_fullscreen_window(IWineD3DSwapChainImpl *swapchain)
|
---|
649 | {
|
---|
650 | IWineD3DDeviceImpl *device = swapchain->device;
|
---|
651 | HWND window = swapchain->device_window;
|
---|
652 | BOOL filter_messages;
|
---|
653 | LONG style, exstyle;
|
---|
654 |
|
---|
655 | if (!device->style && !device->exStyle) return;
|
---|
656 |
|
---|
657 | TRACE("Restoring window style of window %p to %08x, %08x.\n",
|
---|
658 | window, device->style, device->exStyle);
|
---|
659 |
|
---|
660 | style = GetWindowLongW(window, GWL_STYLE);
|
---|
661 | exstyle = GetWindowLongW(window, GWL_EXSTYLE);
|
---|
662 |
|
---|
663 | filter_messages = device->filter_messages;
|
---|
664 | device->filter_messages = TRUE;
|
---|
665 |
|
---|
666 | /* Only restore the style if the application didn't modify it during the
|
---|
667 | * fullscreen phase. Some applications change it before calling Reset()
|
---|
668 | * when switching between windowed and fullscreen modes (HL2), some
|
---|
669 | * depend on the original style (Eve Online). */
|
---|
670 | if (style == fullscreen_style(device->style) && exstyle == fullscreen_exstyle(device->exStyle))
|
---|
671 | {
|
---|
672 | SetWindowLongW(window, GWL_STYLE, device->style);
|
---|
673 | SetWindowLongW(window, GWL_EXSTYLE, device->exStyle);
|
---|
674 | }
|
---|
675 | SetWindowPos(window, 0, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER);
|
---|
676 |
|
---|
677 | device->filter_messages = filter_messages;
|
---|
678 |
|
---|
679 | /* Delete the old values. */
|
---|
680 | device->style = 0;
|
---|
681 | device->exStyle = 0;
|
---|
682 | }
|
---|
683 |
|
---|
684 |
|
---|
685 | HRESULT swapchain_init(IWineD3DSwapChainImpl *swapchain, WINED3DSURFTYPE surface_type,
|
---|
686 | IWineD3DDeviceImpl *device, WINED3DPRESENT_PARAMETERS *present_parameters, IUnknown *parent)
|
---|
687 | {
|
---|
688 | const struct wined3d_adapter *adapter = device->adapter;
|
---|
689 | const struct wined3d_format_desc *format_desc;
|
---|
690 | BOOL displaymode_set = FALSE;
|
---|
691 | WINED3DDISPLAYMODE mode;
|
---|
692 | RECT client_rect;
|
---|
693 | HWND window;
|
---|
694 | HRESULT hr;
|
---|
695 | UINT i;
|
---|
696 |
|
---|
697 | if (present_parameters->BackBufferCount > WINED3DPRESENT_BACK_BUFFER_MAX)
|
---|
698 | {
|
---|
699 | FIXME("The application requested %u back buffers, this is not supported.\n",
|
---|
700 | present_parameters->BackBufferCount);
|
---|
701 | return WINED3DERR_INVALIDCALL;
|
---|
702 | }
|
---|
703 |
|
---|
704 | if (present_parameters->BackBufferCount > 1)
|
---|
705 | {
|
---|
706 | FIXME("The application requested more than one back buffer, this is not properly supported.\n"
|
---|
707 | "Please configure the application to use double buffering (1 back buffer) if possible.\n");
|
---|
708 | }
|
---|
709 |
|
---|
710 | switch (surface_type)
|
---|
711 | {
|
---|
712 | case SURFACE_GDI:
|
---|
713 | swapchain->lpVtbl = &IWineGDISwapChain_Vtbl;
|
---|
714 | break;
|
---|
715 |
|
---|
716 | case SURFACE_OPENGL:
|
---|
717 | swapchain->lpVtbl = &IWineD3DSwapChain_Vtbl;
|
---|
718 | break;
|
---|
719 |
|
---|
720 | case SURFACE_UNKNOWN:
|
---|
721 | FIXME("Caller tried to create a SURFACE_UNKNOWN swapchain.\n");
|
---|
722 | return WINED3DERR_INVALIDCALL;
|
---|
723 | }
|
---|
724 |
|
---|
725 | window = present_parameters->hDeviceWindow ? present_parameters->hDeviceWindow : device->createParms.hFocusWindow;
|
---|
726 |
|
---|
727 | swapchain->device = device;
|
---|
728 | swapchain->parent = parent;
|
---|
729 | swapchain->ref = 1;
|
---|
730 | swapchain->win_handle = window;
|
---|
731 | swapchain->device_window = window;
|
---|
732 | #ifdef VBOX_WITH_WDDM
|
---|
733 | Assert(window);
|
---|
734 | /* see VBoxExtGet/ReleaseDC for comments */
|
---|
735 | swapchain->hDC = VBoxExtGetDC(window);
|
---|
736 | if (!swapchain->hDC)
|
---|
737 | {
|
---|
738 | DWORD winEr = GetLastError();
|
---|
739 | WARN("Failed to get a window DC, winEr %d.\n", winEr);
|
---|
740 | Assert(0);
|
---|
741 | goto err;
|
---|
742 | }
|
---|
743 | #endif
|
---|
744 |
|
---|
745 | if (!present_parameters->Windowed && window)
|
---|
746 | {
|
---|
747 | swapchain_setup_fullscreen_window(swapchain, present_parameters->BackBufferWidth,
|
---|
748 | present_parameters->BackBufferHeight);
|
---|
749 | }
|
---|
750 |
|
---|
751 | IWineD3D_GetAdapterDisplayMode(device->wined3d, adapter->ordinal, &mode);
|
---|
752 | swapchain->orig_width = mode.Width;
|
---|
753 | swapchain->orig_height = mode.Height;
|
---|
754 | swapchain->orig_fmt = mode.Format;
|
---|
755 | format_desc = getFormatDescEntry(mode.Format, &adapter->gl_info);
|
---|
756 |
|
---|
757 | GetClientRect(window, &client_rect);
|
---|
758 | if (present_parameters->Windowed
|
---|
759 | && (!present_parameters->BackBufferWidth || !present_parameters->BackBufferHeight
|
---|
760 | || present_parameters->BackBufferFormat == WINED3DFMT_UNKNOWN))
|
---|
761 | {
|
---|
762 |
|
---|
763 | if (!present_parameters->BackBufferWidth)
|
---|
764 | {
|
---|
765 | present_parameters->BackBufferWidth = client_rect.right;
|
---|
766 | TRACE("Updating width to %u.\n", present_parameters->BackBufferWidth);
|
---|
767 | }
|
---|
768 |
|
---|
769 | if (!present_parameters->BackBufferHeight)
|
---|
770 | {
|
---|
771 | present_parameters->BackBufferHeight = client_rect.bottom;
|
---|
772 | TRACE("Updating height to %u.\n", present_parameters->BackBufferHeight);
|
---|
773 | }
|
---|
774 |
|
---|
775 | if (present_parameters->BackBufferFormat == WINED3DFMT_UNKNOWN)
|
---|
776 | {
|
---|
777 | present_parameters->BackBufferFormat = swapchain->orig_fmt;
|
---|
778 | TRACE("Updating format to %s.\n", debug_d3dformat(swapchain->orig_fmt));
|
---|
779 | }
|
---|
780 | }
|
---|
781 | swapchain->presentParms = *present_parameters;
|
---|
782 |
|
---|
783 | if (wined3d_settings.offscreen_rendering_mode == ORM_FBO
|
---|
784 | && present_parameters->BackBufferCount
|
---|
785 | && (present_parameters->BackBufferWidth != client_rect.right
|
---|
786 | || present_parameters->BackBufferHeight != client_rect.bottom))
|
---|
787 | {
|
---|
788 | TRACE("Rendering to FBO. Backbuffer %ux%u, window %ux%u.\n",
|
---|
789 | present_parameters->BackBufferWidth,
|
---|
790 | present_parameters->BackBufferHeight,
|
---|
791 | client_rect.right, client_rect.bottom);
|
---|
792 | swapchain->render_to_fbo = TRUE;
|
---|
793 | }
|
---|
794 |
|
---|
795 | TRACE("Creating front buffer.\n");
|
---|
796 | hr = IWineD3DDeviceParent_CreateRenderTarget(device->device_parent, parent,
|
---|
797 | swapchain->presentParms.BackBufferWidth, swapchain->presentParms.BackBufferHeight,
|
---|
798 | swapchain->presentParms.BackBufferFormat, swapchain->presentParms.MultiSampleType,
|
---|
799 | swapchain->presentParms.MultiSampleQuality, TRUE /* Lockable */, &swapchain->frontBuffer);
|
---|
800 | if (FAILED(hr))
|
---|
801 | {
|
---|
802 | WARN("Failed to create front buffer, hr %#x.\n", hr);
|
---|
803 | goto err;
|
---|
804 | }
|
---|
805 |
|
---|
806 | IWineD3DSurface_SetContainer(swapchain->frontBuffer, (IWineD3DBase *)swapchain);
|
---|
807 | ((IWineD3DSurfaceImpl *)swapchain->frontBuffer)->Flags |= SFLAG_SWAPCHAIN;
|
---|
808 | if (surface_type == SURFACE_OPENGL)
|
---|
809 | {
|
---|
810 | IWineD3DSurface_ModifyLocation(swapchain->frontBuffer, SFLAG_INDRAWABLE, TRUE);
|
---|
811 | }
|
---|
812 |
|
---|
813 | /* MSDN says we're only allowed a single fullscreen swapchain per device,
|
---|
814 | * so we should really check to see if there is a fullscreen swapchain
|
---|
815 | * already. Does a single head count as full screen? */
|
---|
816 |
|
---|
817 | if (!present_parameters->Windowed)
|
---|
818 | {
|
---|
819 | WINED3DDISPLAYMODE mode;
|
---|
820 |
|
---|
821 | /* Change the display settings */
|
---|
822 | mode.Width = present_parameters->BackBufferWidth;
|
---|
823 | mode.Height = present_parameters->BackBufferHeight;
|
---|
824 | mode.Format = present_parameters->BackBufferFormat;
|
---|
825 | mode.RefreshRate = present_parameters->FullScreen_RefreshRateInHz;
|
---|
826 |
|
---|
827 | hr = IWineD3DDevice_SetDisplayMode((IWineD3DDevice *)device, 0, &mode);
|
---|
828 | if (FAILED(hr))
|
---|
829 | {
|
---|
830 | WARN("Failed to set display mode, hr %#x.\n", hr);
|
---|
831 | goto err;
|
---|
832 | }
|
---|
833 | displaymode_set = TRUE;
|
---|
834 | }
|
---|
835 |
|
---|
836 | #ifndef VBOX_WITH_WDDM
|
---|
837 | swapchain->context = HeapAlloc(GetProcessHeap(), 0, sizeof(swapchain->context));
|
---|
838 | if (!swapchain->context)
|
---|
839 | {
|
---|
840 | ERR("Failed to create the context array.\n");
|
---|
841 | hr = E_OUTOFMEMORY;
|
---|
842 | goto err;
|
---|
843 | }
|
---|
844 | swapchain->num_contexts = 1;
|
---|
845 | #endif
|
---|
846 |
|
---|
847 | if (surface_type == SURFACE_OPENGL)
|
---|
848 | {
|
---|
849 | struct wined3d_context * swapchainContext;
|
---|
850 | const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
---|
851 |
|
---|
852 | /* In WGL both color, depth and stencil are features of a pixel format. In case of D3D they are separate.
|
---|
853 | * You are able to add a depth + stencil surface at a later stage when you need it.
|
---|
854 | * In order to support this properly in WineD3D we need the ability to recreate the opengl context and
|
---|
855 | * drawable when this is required. This is very tricky as we need to reapply ALL opengl states for the new
|
---|
856 | * context, need torecreate shaders, textures and other resources.
|
---|
857 | *
|
---|
858 | * The context manager already takes care of the state problem and for the other tasks code from Reset
|
---|
859 | * can be used. These changes are way to risky during the 1.0 code freeze which is taking place right now.
|
---|
860 | * Likely a lot of other new bugs will be exposed. For that reason request a depth stencil surface all the
|
---|
861 | * time. It can cause a slight performance hit but fixes a lot of regressions. A fixme reminds of that this
|
---|
862 | * issue needs to be fixed. */
|
---|
863 | if (!present_parameters->EnableAutoDepthStencil
|
---|
864 | || swapchain->presentParms.AutoDepthStencilFormat != WINED3DFMT_D24_UNORM_S8_UINT)
|
---|
865 | {
|
---|
866 | FIXME("Add OpenGL context recreation support to context_validate_onscreen_formats\n");
|
---|
867 | }
|
---|
868 | swapchain->ds_format = getFormatDescEntry(WINED3DFMT_D24_UNORM_S8_UINT, gl_info);
|
---|
869 |
|
---|
870 | #ifdef VBOX_WITH_WDDM
|
---|
871 | swapchainContext = context_find_create(device, swapchain, (IWineD3DSurfaceImpl *)swapchain->frontBuffer,
|
---|
872 | swapchain->ds_format);
|
---|
873 | if (!swapchainContext)
|
---|
874 | #else
|
---|
875 | swapchain->context[0] = context_create(swapchain, (IWineD3DSurfaceImpl *)swapchain->frontBuffer,
|
---|
876 | swapchain->ds_format);
|
---|
877 | if (!swapchain->context[0])
|
---|
878 | #endif
|
---|
879 | {
|
---|
880 | WARN("Failed to create context.\n");
|
---|
881 | hr = WINED3DERR_NOTAVAILABLE;
|
---|
882 | goto err;
|
---|
883 | }
|
---|
884 | #ifdef VBOX_WITH_WDDM
|
---|
885 | context_release(swapchainContext);
|
---|
886 | #else
|
---|
887 | context_release(swapchain->context[0]);
|
---|
888 | #endif
|
---|
889 | }
|
---|
890 | else
|
---|
891 | {
|
---|
892 | #ifndef VBOX_WITH_WDDM
|
---|
893 | swapchain->context[0] = NULL;
|
---|
894 | #endif
|
---|
895 | }
|
---|
896 |
|
---|
897 | if (swapchain->presentParms.BackBufferCount > 0)
|
---|
898 | {
|
---|
899 | swapchain->backBuffer = HeapAlloc(GetProcessHeap(), 0,
|
---|
900 | sizeof(*swapchain->backBuffer) * swapchain->presentParms.BackBufferCount);
|
---|
901 | if (!swapchain->backBuffer)
|
---|
902 | {
|
---|
903 | ERR("Failed to allocate backbuffer array memory.\n");
|
---|
904 | hr = E_OUTOFMEMORY;
|
---|
905 | goto err;
|
---|
906 | }
|
---|
907 |
|
---|
908 | for (i = 0; i < swapchain->presentParms.BackBufferCount; ++i)
|
---|
909 | {
|
---|
910 | TRACE("Creating back buffer %u.\n", i);
|
---|
911 | hr = IWineD3DDeviceParent_CreateRenderTarget(device->device_parent, parent,
|
---|
912 | swapchain->presentParms.BackBufferWidth, swapchain->presentParms.BackBufferHeight,
|
---|
913 | swapchain->presentParms.BackBufferFormat, swapchain->presentParms.MultiSampleType,
|
---|
914 | swapchain->presentParms.MultiSampleQuality, TRUE /* Lockable */, &swapchain->backBuffer[i]);
|
---|
915 | if (FAILED(hr))
|
---|
916 | {
|
---|
917 | WARN("Failed to create back buffer %u, hr %#x.\n", i, hr);
|
---|
918 | goto err;
|
---|
919 | }
|
---|
920 |
|
---|
921 | IWineD3DSurface_SetContainer(swapchain->backBuffer[i], (IWineD3DBase *)swapchain);
|
---|
922 | ((IWineD3DSurfaceImpl *)swapchain->backBuffer[i])->Flags |= SFLAG_SWAPCHAIN;
|
---|
923 | }
|
---|
924 | }
|
---|
925 |
|
---|
926 | /* Swapchains share the depth/stencil buffer, so only create a single depthstencil surface. */
|
---|
927 | if (present_parameters->EnableAutoDepthStencil && surface_type == SURFACE_OPENGL)
|
---|
928 | {
|
---|
929 | TRACE("Creating depth/stencil buffer.\n");
|
---|
930 | if (!device->auto_depth_stencil_buffer)
|
---|
931 | {
|
---|
932 | hr = IWineD3DDeviceParent_CreateDepthStencilSurface(device->device_parent, parent,
|
---|
933 | swapchain->presentParms.BackBufferWidth, swapchain->presentParms.BackBufferHeight,
|
---|
934 | swapchain->presentParms.AutoDepthStencilFormat, swapchain->presentParms.MultiSampleType,
|
---|
935 | swapchain->presentParms.MultiSampleQuality, FALSE /* FIXME: Discard */,
|
---|
936 | &device->auto_depth_stencil_buffer);
|
---|
937 | if (FAILED(hr))
|
---|
938 | {
|
---|
939 | WARN("Failed to create the auto depth stencil, hr %#x.\n", hr);
|
---|
940 | goto err;
|
---|
941 | }
|
---|
942 |
|
---|
943 | IWineD3DSurface_SetContainer(device->auto_depth_stencil_buffer, NULL);
|
---|
944 | }
|
---|
945 | }
|
---|
946 |
|
---|
947 | IWineD3DSwapChain_GetGammaRamp((IWineD3DSwapChain *)swapchain, &swapchain->orig_gamma);
|
---|
948 |
|
---|
949 | return WINED3D_OK;
|
---|
950 |
|
---|
951 | err:
|
---|
952 | if (displaymode_set)
|
---|
953 | {
|
---|
954 | DEVMODEW devmode;
|
---|
955 |
|
---|
956 | ClipCursor(NULL);
|
---|
957 |
|
---|
958 | /* Change the display settings */
|
---|
959 | memset(&devmode, 0, sizeof(devmode));
|
---|
960 | devmode.dmSize = sizeof(devmode);
|
---|
961 | devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
|
---|
962 | devmode.dmBitsPerPel = format_desc->byte_count * 8;
|
---|
963 | devmode.dmPelsWidth = swapchain->orig_width;
|
---|
964 | devmode.dmPelsHeight = swapchain->orig_height;
|
---|
965 | ChangeDisplaySettingsExW(adapter->DeviceName, &devmode, NULL, CDS_FULLSCREEN, NULL);
|
---|
966 | }
|
---|
967 |
|
---|
968 | if (swapchain->backBuffer)
|
---|
969 | {
|
---|
970 | for (i = 0; i < swapchain->presentParms.BackBufferCount; ++i)
|
---|
971 | {
|
---|
972 | if (swapchain->backBuffer[i]) IWineD3DSurface_Release(swapchain->backBuffer[i]);
|
---|
973 | }
|
---|
974 | HeapFree(GetProcessHeap(), 0, swapchain->backBuffer);
|
---|
975 | }
|
---|
976 |
|
---|
977 | #ifdef VBOX_WITH_WDDM
|
---|
978 | if (!device->NumberOfSwapChains)
|
---|
979 | {
|
---|
980 | while (device->numContexts)
|
---|
981 | {
|
---|
982 | context_destroy(device, device->contexts[0]);
|
---|
983 | }
|
---|
984 | }
|
---|
985 | #else
|
---|
986 | if (swapchain->context)
|
---|
987 | {
|
---|
988 | if (swapchain->context[0])
|
---|
989 | {
|
---|
990 | context_release(swapchain->context[0]);
|
---|
991 | context_destroy(device, swapchain->context[0]);
|
---|
992 | swapchain->num_contexts = 0;
|
---|
993 | }
|
---|
994 | HeapFree(GetProcessHeap(), 0, swapchain->context);
|
---|
995 | }
|
---|
996 | #endif
|
---|
997 |
|
---|
998 | if (swapchain->frontBuffer) IWineD3DSurface_Release(swapchain->frontBuffer);
|
---|
999 |
|
---|
1000 | return hr;
|
---|
1001 | }
|
---|
1002 |
|
---|
1003 | struct wined3d_context *swapchain_create_context_for_thread(IWineD3DSwapChain *iface)
|
---|
1004 | {
|
---|
1005 | IWineD3DSwapChainImpl *This = (IWineD3DSwapChainImpl *) iface;
|
---|
1006 | struct wined3d_context **newArray;
|
---|
1007 | struct wined3d_context *ctx;
|
---|
1008 |
|
---|
1009 | TRACE("Creating a new context for swapchain %p, thread %d\n", This, GetCurrentThreadId());
|
---|
1010 |
|
---|
1011 | if (!(ctx = context_create(This, (IWineD3DSurfaceImpl *)This->frontBuffer, This->ds_format)))
|
---|
1012 | {
|
---|
1013 | ERR("Failed to create a new context for the swapchain\n");
|
---|
1014 | return NULL;
|
---|
1015 | }
|
---|
1016 | context_release(ctx);
|
---|
1017 | #ifdef VBOX_WITH_WDDM
|
---|
1018 | /* no need to do anything since context gets added to the device context list within the context_create call */
|
---|
1019 | #else
|
---|
1020 | newArray = HeapAlloc(GetProcessHeap(), 0, sizeof(*newArray) * This->num_contexts + 1);
|
---|
1021 | if(!newArray) {
|
---|
1022 | ERR("Out of memory when trying to allocate a new context array\n");
|
---|
1023 | context_destroy(This->device, ctx);
|
---|
1024 | return NULL;
|
---|
1025 | }
|
---|
1026 | memcpy(newArray, This->context, sizeof(*newArray) * This->num_contexts);
|
---|
1027 | HeapFree(GetProcessHeap(), 0, This->context);
|
---|
1028 | newArray[This->num_contexts] = ctx;
|
---|
1029 | This->context = newArray;
|
---|
1030 | This->num_contexts++;
|
---|
1031 | #endif
|
---|
1032 | TRACE("Returning context %p\n", ctx);
|
---|
1033 | return ctx;
|
---|
1034 | }
|
---|
1035 |
|
---|
1036 | void get_drawable_size_swapchain(struct wined3d_context *context, UINT *width, UINT *height)
|
---|
1037 | {
|
---|
1038 | IWineD3DSurfaceImpl *surface = (IWineD3DSurfaceImpl *)context->current_rt;
|
---|
1039 | /* The drawable size of an onscreen drawable is the surface size.
|
---|
1040 | * (Actually: The window size, but the surface is created in window size) */
|
---|
1041 | *width = surface->currentDesc.Width;
|
---|
1042 | *height = surface->currentDesc.Height;
|
---|
1043 | }
|
---|