gdiplus: Comment out a test that crashes some gdiplus implementations.
[wine/multimedia.git] / dlls / wined3d / swapchain.c
blob6dbd2d761b3fe1c58b75855eaee4e07e7c10fa72
1 /*
2 * Copyright 2002-2003 Jason Edmeades
3 * Copyright 2002-2003 Raphael Junqueira
4 * Copyright 2005 Oliver Stieber
5 * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
6 * Copyright 2011 Henri Verbeet for CodeWeavers
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
23 #include "config.h"
24 #include "wine/port.h"
25 #include "wined3d_private.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
28 WINE_DECLARE_DEBUG_CHANNEL(fps);
30 /* Do not call while under the GL lock. */
31 static void swapchain_cleanup(struct wined3d_swapchain *swapchain)
33 struct wined3d_display_mode mode;
34 HRESULT hr;
35 UINT i;
37 TRACE("Destroying swapchain %p.\n", swapchain);
39 wined3d_swapchain_set_gamma_ramp(swapchain, 0, &swapchain->orig_gamma);
41 /* Release the swapchain's draw buffers. Make sure swapchain->back_buffers[0]
42 * is the last buffer to be destroyed, FindContext() depends on that. */
43 if (swapchain->front_buffer)
45 surface_set_container(swapchain->front_buffer, WINED3D_CONTAINER_NONE, NULL);
46 if (wined3d_surface_decref(swapchain->front_buffer))
47 WARN("Something's still holding the front buffer (%p).\n", swapchain->front_buffer);
48 swapchain->front_buffer = NULL;
51 if (swapchain->back_buffers)
53 i = swapchain->desc.backbuffer_count;
55 while (i--)
57 surface_set_container(swapchain->back_buffers[i], WINED3D_CONTAINER_NONE, NULL);
58 if (wined3d_surface_decref(swapchain->back_buffers[i]))
59 WARN("Something's still holding back buffer %u (%p).\n", i, swapchain->back_buffers[i]);
61 HeapFree(GetProcessHeap(), 0, swapchain->back_buffers);
62 swapchain->back_buffers = NULL;
65 for (i = 0; i < swapchain->num_contexts; ++i)
67 context_destroy(swapchain->device, swapchain->context[i]);
69 HeapFree(GetProcessHeap(), 0, swapchain->context);
71 /* Restore the screen resolution if we rendered in fullscreen.
72 * This will restore the screen resolution to what it was before creating
73 * the swapchain. In case of d3d8 and d3d9 this will be the original
74 * desktop resolution. In case of d3d7 this will be a NOP because ddraw
75 * sets the resolution before starting up Direct3D, thus orig_width and
76 * orig_height will be equal to the modes in the presentation params. */
77 if (!swapchain->desc.windowed && swapchain->desc.auto_restore_display_mode)
79 mode.width = swapchain->orig_width;
80 mode.height = swapchain->orig_height;
81 mode.refresh_rate = 0;
82 mode.format_id = swapchain->orig_fmt;
83 mode.scanline_ordering = WINED3D_SCANLINE_ORDERING_UNKNOWN;
84 if (FAILED(hr = wined3d_set_adapter_display_mode(swapchain->device->wined3d,
85 swapchain->device->adapter->ordinal, &mode)))
86 ERR("Failed to restore display mode, hr %#x.\n", hr);
89 if (swapchain->backup_dc)
91 TRACE("Destroying backup wined3d window %p, dc %p.\n", swapchain->backup_wnd, swapchain->backup_dc);
93 ReleaseDC(swapchain->backup_wnd, swapchain->backup_dc);
94 DestroyWindow(swapchain->backup_wnd);
98 ULONG CDECL wined3d_swapchain_incref(struct wined3d_swapchain *swapchain)
100 ULONG refcount = InterlockedIncrement(&swapchain->ref);
102 TRACE("%p increasing refcount to %u.\n", swapchain, refcount);
104 return refcount;
107 /* Do not call while under the GL lock. */
108 ULONG CDECL wined3d_swapchain_decref(struct wined3d_swapchain *swapchain)
110 ULONG refcount = InterlockedDecrement(&swapchain->ref);
112 TRACE("%p decreasing refcount to %u.\n", swapchain, refcount);
114 if (!refcount)
116 swapchain_cleanup(swapchain);
117 swapchain->parent_ops->wined3d_object_destroyed(swapchain->parent);
118 HeapFree(GetProcessHeap(), 0, swapchain);
121 return refcount;
124 void * CDECL wined3d_swapchain_get_parent(const struct wined3d_swapchain *swapchain)
126 TRACE("swapchain %p.\n", swapchain);
128 return swapchain->parent;
131 HRESULT CDECL wined3d_swapchain_set_window(struct wined3d_swapchain *swapchain, HWND window)
133 if (!window)
134 window = swapchain->device_window;
135 if (window == swapchain->win_handle)
136 return WINED3D_OK;
138 TRACE("Setting swapchain %p window from %p to %p.\n",
139 swapchain, swapchain->win_handle, window);
140 swapchain->win_handle = window;
142 return WINED3D_OK;
145 HRESULT CDECL wined3d_swapchain_present(struct wined3d_swapchain *swapchain,
146 const RECT *src_rect, const RECT *dst_rect, HWND dst_window_override,
147 const RGNDATA *dirty_region, DWORD flags)
149 TRACE("swapchain %p, src_rect %s, dst_rect %s, dst_window_override %p, dirty_region %p, flags %#x.\n",
150 swapchain, wine_dbgstr_rect(src_rect), wine_dbgstr_rect(dst_rect),
151 dst_window_override, dirty_region, flags);
153 if (!swapchain->back_buffers)
155 WARN("Swapchain doesn't have a backbuffer, returning WINED3DERR_INVALIDCALL\n");
156 return WINED3DERR_INVALIDCALL;
159 wined3d_swapchain_set_window(swapchain, dst_window_override);
161 swapchain->swapchain_ops->swapchain_present(swapchain, src_rect, dst_rect, dirty_region, flags);
163 return WINED3D_OK;
166 HRESULT CDECL wined3d_swapchain_get_front_buffer_data(const struct wined3d_swapchain *swapchain,
167 struct wined3d_surface *dst_surface)
169 struct wined3d_surface *src_surface;
170 RECT src_rect, dst_rect;
172 TRACE("swapchain %p, dst_surface %p.\n", swapchain, dst_surface);
174 src_surface = swapchain->front_buffer;
175 SetRect(&src_rect, 0, 0, src_surface->resource.width, src_surface->resource.height);
176 dst_rect = src_rect;
178 if (swapchain->desc.windowed)
180 MapWindowPoints(swapchain->win_handle, NULL, (POINT *)&dst_rect, 2);
181 FIXME("Using destination rect %s in windowed mode, this is likely wrong.\n",
182 wine_dbgstr_rect(&dst_rect));
185 return wined3d_surface_blt(dst_surface, &dst_rect, src_surface, &src_rect, 0, NULL, WINED3D_TEXF_POINT);
188 HRESULT CDECL wined3d_swapchain_get_back_buffer(const struct wined3d_swapchain *swapchain,
189 UINT back_buffer_idx, enum wined3d_backbuffer_type type, struct wined3d_surface **back_buffer)
191 TRACE("swapchain %p, back_buffer_idx %u, type %#x, back_buffer %p.\n",
192 swapchain, back_buffer_idx, type, back_buffer);
194 /* Return invalid if there is no backbuffer array, otherwise it will
195 * crash when ddraw is used (there swapchain->back_buffers is always
196 * NULL). We need this because this function is called from
197 * stateblock_init_default_state() to get the default scissorrect
198 * dimensions. */
199 if (!swapchain->back_buffers || back_buffer_idx >= swapchain->desc.backbuffer_count)
201 WARN("Invalid back buffer index.\n");
202 /* Native d3d9 doesn't set NULL here, just as wine's d3d9. But set it
203 * here in wined3d to avoid problems in other libs. */
204 *back_buffer = NULL;
205 return WINED3DERR_INVALIDCALL;
208 *back_buffer = swapchain->back_buffers[back_buffer_idx];
209 if (*back_buffer)
210 wined3d_surface_incref(*back_buffer);
212 TRACE("Returning back buffer %p.\n", *back_buffer);
214 return WINED3D_OK;
217 HRESULT CDECL wined3d_swapchain_get_raster_status(const struct wined3d_swapchain *swapchain,
218 struct wined3d_raster_status *raster_status)
220 static BOOL warned;
221 LARGE_INTEGER counter, freq_per_sec;
222 LONGLONG freq_per_frame, freq_per_line;
223 struct wined3d_display_mode mode;
225 /* No OpenGL equivalent */
226 if (!warned)
228 FIXME("swapchain %p, raster_status %p semi-stub!\n", swapchain, raster_status);
229 warned = TRUE;
232 /* Obtaining the raster status is a widely implemented but optional
233 * feature. When this method returns OK StarCraft 2 expects the
234 * raster_status->InVBlank value to actually change over time.
235 * And Endless Alice Crysis doesn't care even if this method fails.
236 * Thus this method returns OK and fakes raster_status by
237 * QueryPerformanceCounter. */
239 if (!QueryPerformanceCounter(&counter) || !QueryPerformanceFrequency(&freq_per_sec))
240 return WINED3DERR_INVALIDCALL;
242 if (FAILED(wined3d_swapchain_get_display_mode(swapchain, &mode, NULL)))
243 return WINED3DERR_INVALIDCALL;
244 if (mode.refresh_rate == DEFAULT_REFRESH_RATE)
245 mode.refresh_rate = 60;
247 freq_per_frame = freq_per_sec.QuadPart / mode.refresh_rate;
248 /* Assume 20 scan lines in the vertical blank */
249 freq_per_line = freq_per_frame / (mode.height + 20);
250 raster_status->scan_line = (counter.QuadPart % freq_per_frame) / freq_per_line;
251 if (raster_status->scan_line < mode.height)
252 raster_status->in_vblank = FALSE;
253 else
255 raster_status->scan_line = 0;
256 raster_status->in_vblank = TRUE;
258 TRACE("Returning fake value, in_vblank %u, scan_line %u.\n",
259 raster_status->in_vblank, raster_status->scan_line);
260 return WINED3D_OK;
263 HRESULT CDECL wined3d_swapchain_get_display_mode(const struct wined3d_swapchain *swapchain,
264 struct wined3d_display_mode *mode, enum wined3d_display_rotation *rotation)
266 HRESULT hr;
268 TRACE("swapchain %p, mode %p, rotation %p.\n", swapchain, mode, rotation);
270 hr = wined3d_get_adapter_display_mode(swapchain->device->wined3d,
271 swapchain->device->adapter->ordinal, mode, rotation);
273 TRACE("Returning w %u, h %u, refresh rate %u, format %s.\n",
274 mode->width, mode->height, mode->refresh_rate, debug_d3dformat(mode->format_id));
276 return hr;
279 struct wined3d_device * CDECL wined3d_swapchain_get_device(const struct wined3d_swapchain *swapchain)
281 TRACE("swapchain %p.\n", swapchain);
283 return swapchain->device;
286 HRESULT CDECL wined3d_swapchain_get_desc(const struct wined3d_swapchain *swapchain,
287 struct wined3d_swapchain_desc *desc)
289 TRACE("swapchain %p, desc %p.\n", swapchain, desc);
291 *desc = swapchain->desc;
293 return WINED3D_OK;
296 HRESULT CDECL wined3d_swapchain_set_gamma_ramp(const struct wined3d_swapchain *swapchain,
297 DWORD flags, const struct wined3d_gamma_ramp *ramp)
299 HDC dc;
301 TRACE("swapchain %p, flags %#x, ramp %p.\n", swapchain, flags, ramp);
303 if (flags)
304 FIXME("Ignoring flags %#x.\n", flags);
306 dc = GetDC(swapchain->device_window);
307 SetDeviceGammaRamp(dc, (void *)ramp);
308 ReleaseDC(swapchain->device_window, dc);
310 return WINED3D_OK;
313 HRESULT CDECL wined3d_swapchain_get_gamma_ramp(const struct wined3d_swapchain *swapchain,
314 struct wined3d_gamma_ramp *ramp)
316 HDC dc;
318 TRACE("swapchain %p, ramp %p.\n", swapchain, ramp);
320 dc = GetDC(swapchain->device_window);
321 GetDeviceGammaRamp(dc, ramp);
322 ReleaseDC(swapchain->device_window, dc);
324 return WINED3D_OK;
327 /* A GL context is provided by the caller */
328 static void swapchain_blit(const struct wined3d_swapchain *swapchain,
329 struct wined3d_context *context, const RECT *src_rect, const RECT *dst_rect)
331 struct wined3d_surface *backbuffer = swapchain->back_buffers[0];
332 UINT src_w = src_rect->right - src_rect->left;
333 UINT src_h = src_rect->bottom - src_rect->top;
334 GLenum gl_filter;
335 const struct wined3d_gl_info *gl_info = context->gl_info;
336 RECT win_rect;
337 UINT win_h;
339 TRACE("swapchain %p, context %p, src_rect %s, dst_rect %s.\n",
340 swapchain, context, wine_dbgstr_rect(src_rect), wine_dbgstr_rect(dst_rect));
342 if (src_w == dst_rect->right - dst_rect->left && src_h == dst_rect->bottom - dst_rect->top)
343 gl_filter = GL_NEAREST;
344 else
345 gl_filter = GL_LINEAR;
347 GetClientRect(swapchain->win_handle, &win_rect);
348 win_h = win_rect.bottom - win_rect.top;
350 if (gl_info->fbo_ops.glBlitFramebuffer && is_identity_fixup(backbuffer->resource.format->color_fixup))
352 DWORD location = SFLAG_INTEXTURE;
354 if (backbuffer->resource.multisample_type)
356 location = SFLAG_INRB_RESOLVED;
357 surface_load_location(backbuffer, location, NULL);
360 ENTER_GL();
361 context_apply_fbo_state_blit(context, GL_READ_FRAMEBUFFER, backbuffer, NULL, location);
362 glReadBuffer(GL_COLOR_ATTACHMENT0);
363 context_check_fbo_status(context, GL_READ_FRAMEBUFFER);
365 context_apply_fbo_state_blit(context, GL_DRAW_FRAMEBUFFER, swapchain->front_buffer, NULL, SFLAG_INDRAWABLE);
366 context_set_draw_buffer(context, GL_BACK);
367 context_invalidate_state(context, STATE_FRAMEBUFFER);
369 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
370 context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE));
371 context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE1));
372 context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE2));
373 context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE3));
375 glDisable(GL_SCISSOR_TEST);
376 context_invalidate_state(context, STATE_RENDER(WINED3D_RS_SCISSORTESTENABLE));
378 /* Note that the texture is upside down */
379 gl_info->fbo_ops.glBlitFramebuffer(src_rect->left, src_rect->top, src_rect->right, src_rect->bottom,
380 dst_rect->left, win_h - dst_rect->top, dst_rect->right, win_h - dst_rect->bottom,
381 GL_COLOR_BUFFER_BIT, gl_filter);
382 checkGLcall("Swapchain present blit(EXT_framebuffer_blit)\n");
383 LEAVE_GL();
385 else
387 struct wined3d_device *device = swapchain->device;
388 struct wined3d_context *context2;
389 float tex_left = src_rect->left;
390 float tex_top = src_rect->top;
391 float tex_right = src_rect->right;
392 float tex_bottom = src_rect->bottom;
394 context2 = context_acquire(device, swapchain->back_buffers[0]);
395 context_apply_blit_state(context2, device);
397 if (backbuffer->flags & SFLAG_NORMCOORD)
399 tex_left /= src_w;
400 tex_right /= src_w;
401 tex_top /= src_h;
402 tex_bottom /= src_h;
405 if (is_complex_fixup(backbuffer->resource.format->color_fixup))
406 gl_filter = GL_NEAREST;
408 ENTER_GL();
409 context_apply_fbo_state_blit(context2, GL_FRAMEBUFFER, swapchain->front_buffer, NULL, SFLAG_INDRAWABLE);
411 /* Set up the texture. The surface is not in a wined3d_texture
412 * container, so there are no D3D texture settings to dirtify. */
413 device->blitter->set_shader(device->blit_priv, context2, backbuffer);
414 glTexParameteri(backbuffer->texture_target, GL_TEXTURE_MIN_FILTER, gl_filter);
415 glTexParameteri(backbuffer->texture_target, GL_TEXTURE_MAG_FILTER, gl_filter);
417 context_set_draw_buffer(context, GL_BACK);
419 /* Set the viewport to the destination rectandle, disable any projection
420 * transformation set up by context_apply_blit_state(), and draw a
421 * (-1,-1)-(1,1) quad.
423 * Back up viewport and matrix to avoid breaking last_was_blit
425 * Note that context_apply_blit_state() set up viewport and ortho to
426 * match the surface size - we want the GL drawable(=window) size. */
427 glPushAttrib(GL_VIEWPORT_BIT);
428 glViewport(dst_rect->left, win_h - dst_rect->bottom, dst_rect->right, win_h - dst_rect->top);
429 glMatrixMode(GL_PROJECTION);
430 glPushMatrix();
431 glLoadIdentity();
433 glBegin(GL_QUADS);
434 /* bottom left */
435 glTexCoord2f(tex_left, tex_bottom);
436 glVertex2i(-1, -1);
438 /* top left */
439 glTexCoord2f(tex_left, tex_top);
440 glVertex2i(-1, 1);
442 /* top right */
443 glTexCoord2f(tex_right, tex_top);
444 glVertex2i(1, 1);
446 /* bottom right */
447 glTexCoord2f(tex_right, tex_bottom);
448 glVertex2i(1, -1);
449 glEnd();
451 glPopMatrix();
452 glPopAttrib();
454 device->blitter->unset_shader(context->gl_info);
455 checkGLcall("Swapchain present blit(manual)\n");
456 LEAVE_GL();
458 context_release(context2);
462 static void swapchain_gl_present(struct wined3d_swapchain *swapchain, const RECT *src_rect_in,
463 const RECT *dst_rect_in, const RGNDATA *dirty_region, DWORD flags)
465 struct wined3d_surface *back_buffer = swapchain->back_buffers[0];
466 const struct wined3d_fb_state *fb = &swapchain->device->fb;
467 const struct wined3d_gl_info *gl_info;
468 struct wined3d_context *context;
469 RECT src_rect, dst_rect;
470 BOOL render_to_fbo;
472 context = context_acquire(swapchain->device, back_buffer);
473 if (!context->valid)
475 context_release(context);
476 WARN("Invalid context, skipping present.\n");
477 return;
480 gl_info = context->gl_info;
482 /* Render the cursor onto the back buffer, using our nifty directdraw blitting code :-) */
483 if (swapchain->device->bCursorVisible &&
484 swapchain->device->cursorTexture &&
485 !swapchain->device->hardwareCursor)
487 struct wined3d_surface cursor;
488 RECT destRect =
490 swapchain->device->xScreenSpace - swapchain->device->xHotSpot,
491 swapchain->device->yScreenSpace - swapchain->device->yHotSpot,
492 swapchain->device->xScreenSpace + swapchain->device->cursorWidth - swapchain->device->xHotSpot,
493 swapchain->device->yScreenSpace + swapchain->device->cursorHeight - swapchain->device->yHotSpot,
495 TRACE("Rendering the cursor. Creating fake surface at %p\n", &cursor);
496 /* Build a fake surface to call the Blitting code. It is not possible to use the interface passed by
497 * the application because we are only supposed to copy the information out. Using a fake surface
498 * allows us to use the Blitting engine and avoid copying the whole texture -> render target blitting code.
500 memset(&cursor, 0, sizeof(cursor));
501 cursor.resource.ref = 1;
502 cursor.resource.device = swapchain->device;
503 cursor.resource.pool = WINED3D_POOL_SCRATCH;
504 cursor.resource.format = wined3d_get_format(gl_info, WINED3DFMT_B8G8R8A8_UNORM);
505 cursor.resource.type = WINED3D_RTYPE_SURFACE;
506 cursor.texture_name = swapchain->device->cursorTexture;
507 cursor.texture_target = GL_TEXTURE_2D;
508 cursor.texture_level = 0;
509 cursor.resource.width = swapchain->device->cursorWidth;
510 cursor.resource.height = swapchain->device->cursorHeight;
511 /* The cursor must have pow2 sizes */
512 cursor.pow2Width = cursor.resource.width;
513 cursor.pow2Height = cursor.resource.height;
514 /* The surface is in the texture */
515 cursor.flags |= SFLAG_INTEXTURE;
516 /* DDBLT_KEYSRC will cause BltOverride to enable the alpha test with GL_NOTEQUAL, 0.0,
517 * which is exactly what we want :-)
519 if (swapchain->desc.windowed)
520 MapWindowPoints(NULL, swapchain->win_handle, (POINT *)&destRect, 2);
521 wined3d_surface_blt(back_buffer, &destRect, &cursor, NULL, WINEDDBLT_KEYSRC,
522 NULL, WINED3D_TEXF_POINT);
525 if (swapchain->device->logo_surface)
527 struct wined3d_surface *src_surface = swapchain->device->logo_surface;
528 RECT rect = {0, 0, src_surface->resource.width, src_surface->resource.height};
530 /* Blit the logo into the upper left corner of the drawable. */
531 wined3d_surface_blt(back_buffer, &rect, src_surface, &rect, WINEDDBLT_KEYSRC,
532 NULL, WINED3D_TEXF_POINT);
535 TRACE("Presenting HDC %p.\n", context->hdc);
537 render_to_fbo = swapchain->render_to_fbo;
539 if (src_rect_in)
541 src_rect = *src_rect_in;
542 if (!render_to_fbo && (src_rect.left || src_rect.top
543 || src_rect.right != swapchain->desc.backbuffer_width
544 || src_rect.bottom != swapchain->desc.backbuffer_height))
546 render_to_fbo = TRUE;
549 else
551 src_rect.left = 0;
552 src_rect.top = 0;
553 src_rect.right = swapchain->desc.backbuffer_width;
554 src_rect.bottom = swapchain->desc.backbuffer_height;
557 if (dst_rect_in)
558 dst_rect = *dst_rect_in;
559 else
560 GetClientRect(swapchain->win_handle, &dst_rect);
562 if (!render_to_fbo && (dst_rect.left || dst_rect.top
563 || dst_rect.right != swapchain->desc.backbuffer_width
564 || dst_rect.bottom != swapchain->desc.backbuffer_height))
565 render_to_fbo = TRUE;
567 /* Rendering to a window of different size, presenting partial rectangles,
568 * or rendering to a different window needs help from FBO_blit or a textured
569 * draw. Render the swapchain to a FBO in the future.
571 * Note that FBO_blit from the backbuffer to the frontbuffer cannot solve
572 * all these issues - this fails if the window is smaller than the backbuffer.
574 if (!swapchain->render_to_fbo && render_to_fbo && wined3d_settings.offscreen_rendering_mode == ORM_FBO)
576 surface_load_location(back_buffer, SFLAG_INTEXTURE, NULL);
577 surface_modify_location(back_buffer, SFLAG_INDRAWABLE, FALSE);
578 swapchain->render_to_fbo = TRUE;
579 swapchain_update_draw_bindings(swapchain);
581 else
583 surface_load_location(back_buffer, back_buffer->draw_binding, NULL);
586 if (swapchain->render_to_fbo)
588 /* This codepath should only be hit with the COPY swapeffect. Otherwise a backbuffer-
589 * window size mismatch is impossible(fullscreen) and src and dst rectangles are
590 * not allowed(they need the COPY swapeffect)
592 * The DISCARD swap effect is ok as well since any backbuffer content is allowed after
593 * the swap. */
594 if (swapchain->desc.swap_effect == WINED3D_SWAP_EFFECT_FLIP)
595 FIXME("Render-to-fbo with WINED3D_SWAP_EFFECT_FLIP\n");
597 swapchain_blit(swapchain, context, &src_rect, &dst_rect);
600 if (swapchain->num_contexts > 1)
601 wglFinish();
602 SwapBuffers(context->hdc); /* TODO: cycle through the swapchain buffers */
604 TRACE("SwapBuffers called, Starting new frame\n");
605 /* FPS support */
606 if (TRACE_ON(fps))
608 DWORD time = GetTickCount();
609 ++swapchain->frames;
611 /* every 1.5 seconds */
612 if (time - swapchain->prev_time > 1500)
614 TRACE_(fps)("%p @ approx %.2ffps\n",
615 swapchain, 1000.0 * swapchain->frames / (time - swapchain->prev_time));
616 swapchain->prev_time = time;
617 swapchain->frames = 0;
621 /* This is disabled, but the code left in for debug purposes.
623 * Since we're allowed to modify the new back buffer on a D3DSWAPEFFECT_DISCARD flip,
624 * we can clear it with some ugly color to make bad drawing visible and ease debugging.
625 * The Debug runtime does the same on Windows. However, a few games do not redraw the
626 * screen properly, like Max Payne 2, which leaves a few pixels undefined.
628 * Tests show that the content of the back buffer after a discard flip is indeed not
629 * reliable, so no game can depend on the exact content. However, it resembles the
630 * old contents in some way, for example by showing fragments at other locations. In
631 * general, the color theme is still intact. So Max payne, which draws rather dark scenes
632 * gets a dark background image. If we clear it with a bright ugly color, the game's
633 * bug shows up much more than it does on Windows, and the players see single pixels
634 * with wrong colors.
635 * (The Max Payne bug has been confirmed on Windows with the debug runtime) */
636 if (FALSE && swapchain->desc.swap_effect == WINED3D_SWAP_EFFECT_DISCARD)
638 static const struct wined3d_color cyan = {0.0f, 1.0f, 1.0f, 1.0f};
640 TRACE("Clearing the color buffer with cyan color\n");
642 wined3d_device_clear(swapchain->device, 0, NULL,
643 WINED3DCLEAR_TARGET, &cyan, 1.0f, 0);
646 if (!swapchain->render_to_fbo && ((swapchain->front_buffer->flags & SFLAG_INSYSMEM)
647 || (back_buffer->flags & SFLAG_INSYSMEM)))
649 /* Both memory copies of the surfaces are ok, flip them around too instead of dirtifying
650 * Doesn't work with render_to_fbo because we're not flipping
652 struct wined3d_surface *front = swapchain->front_buffer;
654 if (front->resource.size == back_buffer->resource.size)
656 DWORD fbflags;
657 flip_surface(front, back_buffer);
659 /* Tell the front buffer surface that is has been modified. However,
660 * the other locations were preserved during that, so keep the flags.
661 * This serves to update the emulated overlay, if any. */
662 fbflags = front->flags;
663 surface_modify_location(front, SFLAG_INDRAWABLE, TRUE);
664 front->flags = fbflags;
666 else
668 surface_modify_location(front, SFLAG_INDRAWABLE, TRUE);
669 surface_modify_location(back_buffer, SFLAG_INDRAWABLE, TRUE);
672 else
674 surface_modify_location(swapchain->front_buffer, SFLAG_INDRAWABLE, TRUE);
675 /* If the swapeffect is DISCARD, the back buffer is undefined. That means the SYSMEM
676 * and INTEXTURE copies can keep their old content if they have any defined content.
677 * If the swapeffect is COPY, the content remains the same. If it is FLIP however,
678 * the texture / sysmem copy needs to be reloaded from the drawable
680 if (swapchain->desc.swap_effect == WINED3D_SWAP_EFFECT_FLIP)
681 surface_modify_location(back_buffer, back_buffer->draw_binding, TRUE);
684 if (fb->depth_stencil)
686 if (swapchain->desc.flags & WINED3DPRESENTFLAG_DISCARD_DEPTHSTENCIL
687 || fb->depth_stencil->flags & SFLAG_DISCARD)
689 surface_modify_ds_location(fb->depth_stencil, SFLAG_DISCARDED,
690 fb->depth_stencil->resource.width,
691 fb->depth_stencil->resource.height);
692 if (fb->depth_stencil == swapchain->device->onscreen_depth_stencil)
694 wined3d_surface_decref(swapchain->device->onscreen_depth_stencil);
695 swapchain->device->onscreen_depth_stencil = NULL;
700 context_release(context);
703 static const struct wined3d_swapchain_ops swapchain_gl_ops =
705 swapchain_gl_present,
708 /* Helper function that blits the front buffer contents to the target window. */
709 void x11_copy_to_screen(const struct wined3d_swapchain *swapchain, const RECT *rect)
711 const struct wined3d_surface *front;
712 POINT offset = {0, 0};
713 HDC src_dc, dst_dc;
714 RECT draw_rect;
715 HWND window;
717 TRACE("swapchain %p, rect %s.\n", swapchain, wine_dbgstr_rect(rect));
719 front = swapchain->front_buffer;
720 if (!(front->resource.usage & WINED3DUSAGE_RENDERTARGET))
721 return;
723 if (front->resource.map_count)
724 ERR("Trying to blit a mapped surface.\n");
726 TRACE("Copying surface %p to screen.\n", front);
728 src_dc = front->hDC;
729 window = swapchain->win_handle;
730 dst_dc = GetDCEx(window, 0, DCX_CLIPSIBLINGS | DCX_CACHE);
732 /* Front buffer coordinates are screen coordinates. Map them to the
733 * destination window if not fullscreened. */
734 if (swapchain->desc.windowed)
735 ClientToScreen(window, &offset);
737 TRACE("offset %s.\n", wine_dbgstr_point(&offset));
739 draw_rect.left = 0;
740 draw_rect.right = front->resource.width;
741 draw_rect.top = 0;
742 draw_rect.bottom = front->resource.height;
744 if (rect)
745 IntersectRect(&draw_rect, &draw_rect, rect);
747 BitBlt(dst_dc, draw_rect.left - offset.x, draw_rect.top - offset.y,
748 draw_rect.right - draw_rect.left, draw_rect.bottom - draw_rect.top,
749 src_dc, draw_rect.left, draw_rect.top, SRCCOPY);
750 ReleaseDC(window, dst_dc);
753 static void swapchain_gdi_present(struct wined3d_swapchain *swapchain, const RECT *src_rect_in,
754 const RECT *dst_rect_in, const RGNDATA *dirty_region, DWORD flags)
756 struct wined3d_surface *front, *back;
758 front = swapchain->front_buffer;
759 back = swapchain->back_buffers[0];
761 /* Flip the DC. */
763 HDC tmp;
764 tmp = front->hDC;
765 front->hDC = back->hDC;
766 back->hDC = tmp;
769 /* Flip the DIBsection. */
771 HBITMAP tmp;
772 tmp = front->dib.DIBsection;
773 front->dib.DIBsection = back->dib.DIBsection;
774 back->dib.DIBsection = tmp;
777 /* Flip the surface data. */
779 void *tmp;
781 tmp = front->dib.bitmap_data;
782 front->dib.bitmap_data = back->dib.bitmap_data;
783 back->dib.bitmap_data = tmp;
785 tmp = front->resource.allocatedMemory;
786 front->resource.allocatedMemory = back->resource.allocatedMemory;
787 back->resource.allocatedMemory = tmp;
789 if (front->resource.heapMemory)
790 ERR("GDI Surface %p has heap memory allocated.\n", front);
792 if (back->resource.heapMemory)
793 ERR("GDI Surface %p has heap memory allocated.\n", back);
796 /* FPS support */
797 if (TRACE_ON(fps))
799 static LONG prev_time, frames;
800 DWORD time = GetTickCount();
802 ++frames;
804 /* every 1.5 seconds */
805 if (time - prev_time > 1500)
807 TRACE_(fps)("@ approx %.2ffps\n", 1000.0 * frames / (time - prev_time));
808 prev_time = time;
809 frames = 0;
813 x11_copy_to_screen(swapchain, NULL);
816 static const struct wined3d_swapchain_ops swapchain_gdi_ops =
818 swapchain_gdi_present,
821 void swapchain_update_render_to_fbo(struct wined3d_swapchain *swapchain)
823 RECT client_rect;
825 if (wined3d_settings.offscreen_rendering_mode != ORM_FBO)
826 return;
828 if (!swapchain->desc.backbuffer_count)
830 TRACE("Single buffered rendering.\n");
831 swapchain->render_to_fbo = FALSE;
832 return;
835 GetClientRect(swapchain->win_handle, &client_rect);
837 TRACE("Backbuffer %ux%u, window %ux%u.\n",
838 swapchain->desc.backbuffer_width,
839 swapchain->desc.backbuffer_height,
840 client_rect.right, client_rect.bottom);
841 TRACE("Multisample type %#x, quality %#x.\n",
842 swapchain->desc.multisample_type,
843 swapchain->desc.multisample_quality);
845 if (!wined3d_settings.always_offscreen && !swapchain->desc.multisample_type
846 && swapchain->desc.backbuffer_width == client_rect.right
847 && swapchain->desc.backbuffer_height == client_rect.bottom)
849 TRACE("Backbuffer dimensions match window dimensions, rendering onscreen.\n");
850 swapchain->render_to_fbo = FALSE;
851 return;
854 TRACE("Rendering to FBO.\n");
855 swapchain->render_to_fbo = TRUE;
858 /* Do not call while under the GL lock. */
859 static HRESULT swapchain_init(struct wined3d_swapchain *swapchain, enum wined3d_surface_type surface_type,
860 struct wined3d_device *device, struct wined3d_swapchain_desc *desc,
861 void *parent, const struct wined3d_parent_ops *parent_ops)
863 const struct wined3d_adapter *adapter = device->adapter;
864 const struct wined3d_format *format;
865 struct wined3d_display_mode mode;
866 BOOL displaymode_set = FALSE;
867 RECT client_rect;
868 HWND window;
869 HRESULT hr;
870 UINT i;
872 if (desc->backbuffer_count > WINED3DPRESENT_BACK_BUFFER_MAX)
874 FIXME("The application requested %u back buffers, this is not supported.\n",
875 desc->backbuffer_count);
876 return WINED3DERR_INVALIDCALL;
879 if (desc->backbuffer_count > 1)
881 FIXME("The application requested more than one back buffer, this is not properly supported.\n"
882 "Please configure the application to use double buffering (1 back buffer) if possible.\n");
885 switch (surface_type)
887 case WINED3D_SURFACE_TYPE_GDI:
888 swapchain->swapchain_ops = &swapchain_gdi_ops;
889 break;
891 case WINED3D_SURFACE_TYPE_OPENGL:
892 swapchain->swapchain_ops = &swapchain_gl_ops;
893 break;
895 default:
896 ERR("Invalid surface type %#x.\n", surface_type);
897 return WINED3DERR_INVALIDCALL;
900 window = desc->device_window ? desc->device_window : device->create_parms.focus_window;
902 swapchain->device = device;
903 swapchain->parent = parent;
904 swapchain->parent_ops = parent_ops;
905 swapchain->ref = 1;
906 swapchain->win_handle = window;
907 swapchain->device_window = window;
909 wined3d_get_adapter_display_mode(device->wined3d, adapter->ordinal, &mode, NULL);
910 swapchain->orig_width = mode.width;
911 swapchain->orig_height = mode.height;
912 swapchain->orig_fmt = mode.format_id;
913 format = wined3d_get_format(&adapter->gl_info, mode.format_id);
915 GetClientRect(window, &client_rect);
916 if (desc->windowed
917 && (!desc->backbuffer_width || !desc->backbuffer_height
918 || desc->backbuffer_format == WINED3DFMT_UNKNOWN))
921 if (!desc->backbuffer_width)
923 desc->backbuffer_width = client_rect.right;
924 TRACE("Updating width to %u.\n", desc->backbuffer_width);
927 if (!desc->backbuffer_height)
929 desc->backbuffer_height = client_rect.bottom;
930 TRACE("Updating height to %u.\n", desc->backbuffer_height);
933 if (desc->backbuffer_format == WINED3DFMT_UNKNOWN)
935 desc->backbuffer_format = swapchain->orig_fmt;
936 TRACE("Updating format to %s.\n", debug_d3dformat(swapchain->orig_fmt));
939 swapchain->desc = *desc;
940 swapchain_update_render_to_fbo(swapchain);
942 TRACE("Creating front buffer.\n");
943 hr = device->device_parent->ops->create_rendertarget(device->device_parent, parent,
944 swapchain->desc.backbuffer_width, swapchain->desc.backbuffer_height,
945 swapchain->desc.backbuffer_format, swapchain->desc.multisample_type,
946 swapchain->desc.multisample_quality, TRUE /* Lockable */,
947 &swapchain->front_buffer);
948 if (FAILED(hr))
950 WARN("Failed to create front buffer, hr %#x.\n", hr);
951 goto err;
954 surface_set_container(swapchain->front_buffer, WINED3D_CONTAINER_SWAPCHAIN, swapchain);
955 if (surface_type == WINED3D_SURFACE_TYPE_OPENGL)
956 surface_modify_location(swapchain->front_buffer, SFLAG_INDRAWABLE, TRUE);
958 /* MSDN says we're only allowed a single fullscreen swapchain per device,
959 * so we should really check to see if there is a fullscreen swapchain
960 * already. Does a single head count as full screen? */
962 if (!desc->windowed)
964 struct wined3d_display_mode mode;
966 /* Change the display settings */
967 mode.width = desc->backbuffer_width;
968 mode.height = desc->backbuffer_height;
969 mode.format_id = desc->backbuffer_format;
970 mode.refresh_rate = desc->refresh_rate;
971 mode.scanline_ordering = WINED3D_SCANLINE_ORDERING_UNKNOWN;
973 if (FAILED(hr = wined3d_set_adapter_display_mode(device->wined3d, device->adapter->ordinal, &mode)))
975 WARN("Failed to set display mode, hr %#x.\n", hr);
976 goto err;
978 displaymode_set = TRUE;
981 if (surface_type == WINED3D_SURFACE_TYPE_OPENGL)
983 static const enum wined3d_format_id formats[] =
985 WINED3DFMT_D24_UNORM_S8_UINT,
986 WINED3DFMT_D32_UNORM,
987 WINED3DFMT_R24_UNORM_X8_TYPELESS,
988 WINED3DFMT_D16_UNORM,
989 WINED3DFMT_S1_UINT_D15_UNORM
992 const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
994 swapchain->context = HeapAlloc(GetProcessHeap(), 0, sizeof(*swapchain->context));
995 if (!swapchain->context)
997 ERR("Failed to create the context array.\n");
998 hr = E_OUTOFMEMORY;
999 goto err;
1001 swapchain->num_contexts = 1;
1003 /* In WGL both color, depth and stencil are features of a pixel format. In case of D3D they are separate.
1004 * You are able to add a depth + stencil surface at a later stage when you need it.
1005 * In order to support this properly in WineD3D we need the ability to recreate the opengl context and
1006 * drawable when this is required. This is very tricky as we need to reapply ALL opengl states for the new
1007 * context, need torecreate shaders, textures and other resources.
1009 * The context manager already takes care of the state problem and for the other tasks code from Reset
1010 * can be used. These changes are way to risky during the 1.0 code freeze which is taking place right now.
1011 * Likely a lot of other new bugs will be exposed. For that reason request a depth stencil surface all the
1012 * time. It can cause a slight performance hit but fixes a lot of regressions. A fixme reminds of that this
1013 * issue needs to be fixed. */
1014 for (i = 0; i < (sizeof(formats) / sizeof(*formats)); i++)
1016 swapchain->ds_format = wined3d_get_format(gl_info, formats[i]);
1017 swapchain->context[0] = context_create(swapchain, swapchain->front_buffer, swapchain->ds_format);
1018 if (swapchain->context[0]) break;
1019 TRACE("Depth stencil format %s is not supported, trying next format\n",
1020 debug_d3dformat(formats[i]));
1023 if (!swapchain->context[0])
1025 WARN("Failed to create context.\n");
1026 hr = WINED3DERR_NOTAVAILABLE;
1027 goto err;
1030 if (wined3d_settings.offscreen_rendering_mode != ORM_FBO
1031 && (!desc->enable_auto_depth_stencil
1032 || swapchain->desc.auto_depth_stencil_format != swapchain->ds_format->id))
1034 FIXME("Add OpenGL context recreation support to context_validate_onscreen_formats\n");
1036 context_release(swapchain->context[0]);
1039 if (swapchain->desc.backbuffer_count > 0)
1041 swapchain->back_buffers = HeapAlloc(GetProcessHeap(), 0,
1042 sizeof(*swapchain->back_buffers) * swapchain->desc.backbuffer_count);
1043 if (!swapchain->back_buffers)
1045 ERR("Failed to allocate backbuffer array memory.\n");
1046 hr = E_OUTOFMEMORY;
1047 goto err;
1050 for (i = 0; i < swapchain->desc.backbuffer_count; ++i)
1052 TRACE("Creating back buffer %u.\n", i);
1053 hr = device->device_parent->ops->create_rendertarget(device->device_parent, parent,
1054 swapchain->desc.backbuffer_width, swapchain->desc.backbuffer_height,
1055 swapchain->desc.backbuffer_format, swapchain->desc.multisample_type,
1056 swapchain->desc.multisample_quality, TRUE /* Lockable */,
1057 &swapchain->back_buffers[i]);
1058 if (FAILED(hr))
1060 WARN("Failed to create back buffer %u, hr %#x.\n", i, hr);
1061 goto err;
1064 surface_set_container(swapchain->back_buffers[i], WINED3D_CONTAINER_SWAPCHAIN, swapchain);
1068 /* Swapchains share the depth/stencil buffer, so only create a single depthstencil surface. */
1069 if (desc->enable_auto_depth_stencil && surface_type == WINED3D_SURFACE_TYPE_OPENGL)
1071 TRACE("Creating depth/stencil buffer.\n");
1072 if (!device->auto_depth_stencil)
1074 hr = device->device_parent->ops->create_depth_stencil(device->device_parent,
1075 swapchain->desc.backbuffer_width, swapchain->desc.backbuffer_height,
1076 swapchain->desc.auto_depth_stencil_format, swapchain->desc.multisample_type,
1077 swapchain->desc.multisample_quality, FALSE /* FIXME: Discard */,
1078 &device->auto_depth_stencil);
1079 if (FAILED(hr))
1081 WARN("Failed to create the auto depth stencil, hr %#x.\n", hr);
1082 goto err;
1085 surface_set_container(device->auto_depth_stencil, WINED3D_CONTAINER_NONE, NULL);
1089 wined3d_swapchain_get_gamma_ramp(swapchain, &swapchain->orig_gamma);
1091 return WINED3D_OK;
1093 err:
1094 if (displaymode_set)
1096 DEVMODEW devmode;
1098 ClipCursor(NULL);
1100 /* Change the display settings */
1101 memset(&devmode, 0, sizeof(devmode));
1102 devmode.dmSize = sizeof(devmode);
1103 devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
1104 devmode.dmBitsPerPel = format->byte_count * CHAR_BIT;
1105 devmode.dmPelsWidth = swapchain->orig_width;
1106 devmode.dmPelsHeight = swapchain->orig_height;
1107 ChangeDisplaySettingsExW(adapter->DeviceName, &devmode, NULL, CDS_FULLSCREEN, NULL);
1110 if (swapchain->back_buffers)
1112 for (i = 0; i < swapchain->desc.backbuffer_count; ++i)
1114 if (swapchain->back_buffers[i])
1116 surface_set_container(swapchain->back_buffers[i], WINED3D_CONTAINER_NONE, NULL);
1117 wined3d_surface_decref(swapchain->back_buffers[i]);
1120 HeapFree(GetProcessHeap(), 0, swapchain->back_buffers);
1123 if (swapchain->context)
1125 if (swapchain->context[0])
1127 context_release(swapchain->context[0]);
1128 context_destroy(device, swapchain->context[0]);
1129 swapchain->num_contexts = 0;
1131 HeapFree(GetProcessHeap(), 0, swapchain->context);
1134 if (swapchain->front_buffer)
1136 surface_set_container(swapchain->front_buffer, WINED3D_CONTAINER_NONE, NULL);
1137 wined3d_surface_decref(swapchain->front_buffer);
1140 return hr;
1143 /* Do not call while under the GL lock. */
1144 HRESULT CDECL wined3d_swapchain_create(struct wined3d_device *device,
1145 struct wined3d_swapchain_desc *desc, enum wined3d_surface_type surface_type,
1146 void *parent, const struct wined3d_parent_ops *parent_ops,
1147 struct wined3d_swapchain **swapchain)
1149 struct wined3d_swapchain *object;
1150 HRESULT hr;
1152 TRACE("device %p, desc %p, swapchain %p, parent %p, surface_type %#x.\n",
1153 device, desc, swapchain, parent, surface_type);
1155 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1156 if (!object)
1158 ERR("Failed to allocate swapchain memory.\n");
1159 return E_OUTOFMEMORY;
1162 hr = swapchain_init(object, surface_type, device, desc, parent, parent_ops);
1163 if (FAILED(hr))
1165 WARN("Failed to initialize swapchain, hr %#x.\n", hr);
1166 HeapFree(GetProcessHeap(), 0, object);
1167 return hr;
1170 TRACE("Created swapchain %p.\n", object);
1171 *swapchain = object;
1173 return WINED3D_OK;
1176 /* Do not call while under the GL lock. */
1177 static struct wined3d_context *swapchain_create_context(struct wined3d_swapchain *swapchain)
1179 struct wined3d_context **newArray;
1180 struct wined3d_context *ctx;
1182 TRACE("Creating a new context for swapchain %p, thread %u.\n", swapchain, GetCurrentThreadId());
1184 if (!(ctx = context_create(swapchain, swapchain->front_buffer, swapchain->ds_format)))
1186 ERR("Failed to create a new context for the swapchain\n");
1187 return NULL;
1189 context_release(ctx);
1191 newArray = HeapAlloc(GetProcessHeap(), 0, sizeof(*newArray) * (swapchain->num_contexts + 1));
1192 if(!newArray) {
1193 ERR("Out of memory when trying to allocate a new context array\n");
1194 context_destroy(swapchain->device, ctx);
1195 return NULL;
1197 memcpy(newArray, swapchain->context, sizeof(*newArray) * swapchain->num_contexts);
1198 HeapFree(GetProcessHeap(), 0, swapchain->context);
1199 newArray[swapchain->num_contexts] = ctx;
1200 swapchain->context = newArray;
1201 swapchain->num_contexts++;
1203 TRACE("Returning context %p\n", ctx);
1204 return ctx;
1207 void swapchain_destroy_contexts(struct wined3d_swapchain *swapchain)
1209 unsigned int i;
1211 for (i = 0; i < swapchain->num_contexts; ++i)
1213 context_destroy(swapchain->device, swapchain->context[i]);
1215 swapchain->num_contexts = 0;
1218 struct wined3d_context *swapchain_get_context(struct wined3d_swapchain *swapchain)
1220 DWORD tid = GetCurrentThreadId();
1221 unsigned int i;
1223 for (i = 0; i < swapchain->num_contexts; ++i)
1225 if (swapchain->context[i]->tid == tid)
1226 return swapchain->context[i];
1229 /* Create a new context for the thread */
1230 return swapchain_create_context(swapchain);
1233 void get_drawable_size_swapchain(const struct wined3d_context *context, UINT *width, UINT *height)
1235 /* The drawable size of an onscreen drawable is the surface size.
1236 * (Actually: The window size, but the surface is created in window size) */
1237 *width = context->current_rt->resource.width;
1238 *height = context->current_rt->resource.height;
1241 HDC swapchain_get_backup_dc(struct wined3d_swapchain *swapchain)
1243 if (!swapchain->backup_dc)
1245 TRACE("Creating the backup window for swapchain %p.\n", swapchain);
1247 if (!(swapchain->backup_wnd = CreateWindowA(WINED3D_OPENGL_WINDOW_CLASS_NAME, "WineD3D fake window",
1248 WS_OVERLAPPEDWINDOW, 10, 10, 10, 10, NULL, NULL, NULL, NULL)))
1250 ERR("Failed to create a window.\n");
1251 return NULL;
1254 if (!(swapchain->backup_dc = GetDC(swapchain->backup_wnd)))
1256 ERR("Failed to get a DC.\n");
1257 DestroyWindow(swapchain->backup_wnd);
1258 swapchain->backup_wnd = NULL;
1259 return NULL;
1263 return swapchain->backup_dc;
1266 void swapchain_update_draw_bindings(struct wined3d_swapchain *swapchain)
1268 UINT i;
1270 surface_update_draw_binding(swapchain->front_buffer);
1272 for (i = 0; i < swapchain->desc.backbuffer_count; ++i)
1274 surface_update_draw_binding(swapchain->back_buffers[i]);