[PATCH 7/8] wined3d: Rotate through backbuffers.

Stefan Dösinger stefan at codeweavers.com
Mon Sep 14 12:17:51 CDT 2015


This doesn't handle front->back flips. We need a shadow frontbuffer for
this. To imlpement this there are two options: One is to manually
exchange the frontbuffer and last backbuffer after rotating if the
swapeffect is flip and we are in fullscreen mode. The other option is to
treat the frontbuffer like a normal buffer and increase the buffer array
size by one in case we have a flip swapeffect. For the second option
though we need to keep the front buffer size equal to the back buffer
size and need to make front buffer accesses work in DDSCL_NORMAL ddraw
somehow.
---
 dlls/wined3d/swapchain.c       | 20 ++++++++++++++------
 dlls/wined3d/wined3d_private.h |  1 +
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/dlls/wined3d/swapchain.c b/dlls/wined3d/swapchain.c
index 0a1373f..ca4f540 100644
--- a/dlls/wined3d/swapchain.c
+++ b/dlls/wined3d/swapchain.c
@@ -195,6 +195,8 @@ struct wined3d_texture * CDECL wined3d_swapchain_get_back_buffer(const struct wi
          * here in wined3d to avoid problems in other libs. */
         return NULL;
     }
+    back_buffer_idx += swapchain->rotate;
+    back_buffer_idx %= swapchain->desc.backbuffer_count;
 
     TRACE("Returning back buffer %p.\n", swapchain->back_buffers[back_buffer_idx]);
 
@@ -283,7 +285,7 @@ static void swapchain_blit(const struct wined3d_swapchain *swapchain,
         struct wined3d_context *context, const RECT *src_rect, const RECT *dst_rect)
 {
     struct wined3d_surface *backbuffer = surface_from_resource(
-            wined3d_texture_get_sub_resource(swapchain->back_buffers[0], 0));
+            wined3d_texture_get_sub_resource(swapchain->back_buffers[swapchain->rotate], 0));
     UINT src_w = src_rect->right - src_rect->left;
     UINT src_h = src_rect->bottom - src_rect->top;
     GLenum gl_filter;
@@ -420,7 +422,7 @@ static void swapchain_gl_present(struct wined3d_swapchain *swapchain, const RECT
         const RECT *dst_rect_in, const RGNDATA *dirty_region, DWORD flags)
 {
     struct wined3d_surface *back_buffer = surface_from_resource(
-            wined3d_texture_get_sub_resource(swapchain->back_buffers[0], 0));
+            wined3d_texture_get_sub_resource(swapchain->back_buffers[swapchain->rotate], 0));
     const struct wined3d_fb_state *fb = &swapchain->device->fb;
     const struct wined3d_gl_info *gl_info;
     struct wined3d_context *context;
@@ -535,7 +537,14 @@ static void swapchain_gl_present(struct wined3d_swapchain *swapchain, const RECT
         gl_info->gl_ops.gl.p_glFinish();
 
     /* call wglSwapBuffers through the gl table to avoid confusing the Steam overlay */
-    gl_info->gl_ops.wgl.p_wglSwapBuffers(context->hdc); /* TODO: cycle through the swapchain buffers */
+    gl_info->gl_ops.wgl.p_wglSwapBuffers(context->hdc);
+
+    if (swapchain->desc.backbuffer_count > 1)
+    {
+        swapchain->rotate++;
+        swapchain->rotate %= swapchain->desc.backbuffer_count;
+        device_invalidate_state(swapchain->device, STATE_FRAMEBUFFER);
+    }
 
     TRACE("SwapBuffers called, Starting new frame\n");
     /* FPS support */
@@ -562,9 +571,8 @@ static void swapchain_gl_present(struct wined3d_swapchain *swapchain, const RECT
      * and INTEXTURE copies can keep their old content if they have any defined content.
      * If the swapeffect is COPY, the content remains the same.
      *
-     * The FLIP swap effect is not implemented yet. We could mark WINED3D_LOCATION_DRAWABLE
-     * up to date and hope WGL flipped front and back buffers and read this data into
-     * the FBO. Don't bother about this for now. */
+     * The FLIP swap effect is not implemented yet. We need a shadow front buffer and
+     * swap it with the last back buffer. */
 
     if (fb->depth_stencil)
     {
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 8dd0a84..0100ae6 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2740,6 +2740,7 @@ struct wined3d_swapchain
 
     struct wined3d_texture **back_buffers;
     struct wined3d_texture *front_buffer;
+    unsigned int rotate;
     struct wined3d_swapchain_desc desc;
     struct wined3d_display_mode original_mode, d3d_mode;
     struct wined3d_gamma_ramp orig_gamma;
-- 
2.4.6




More information about the wine-patches mailing list