[PATCH 6/8] wined3d: Store swapchains in views for swapchain buffers.

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


This way we can fetch the correct resource after flipping swapchain
buffers.
---
 dlls/wined3d/view.c            |  30 ++++++++++++
 dlls/wined3d/wined3d_private.h | 108 +++++++++++++++++++++++------------------
 2 files changed, 91 insertions(+), 47 deletions(-)

diff --git a/dlls/wined3d/view.c b/dlls/wined3d/view.c
index 694b65f..61272a6 100644
--- a/dlls/wined3d/view.c
+++ b/dlls/wined3d/view.c
@@ -85,6 +85,14 @@ struct wined3d_resource * CDECL wined3d_rendertarget_view_get_resource(const str
 {
     TRACE("view %p.\n", view);
 
+    if (view->swapchain)
+    {
+        if (view->front_buffer)
+            return &view->swapchain->front_buffer->resource;
+
+        return &wined3d_swapchain_get_back_buffer(view->swapchain, view->backbuffer_idx)->resource;
+    }
+
     return view->resource;
 }
 
@@ -114,6 +122,7 @@ static void wined3d_rendertarget_view_init(struct wined3d_rendertarget_view *vie
     {
         struct wined3d_texture *texture = wined3d_texture_from_resource(resource);
         struct wined3d_resource *sub_resource;
+        struct wined3d_swapchain *swapchain = texture->swapchain;
 
         view->sub_resource_idx = desc->u.texture.layer_idx * texture->level_count + desc->u.texture.level_idx;
         sub_resource = wined3d_texture_get_sub_resource(texture, view->sub_resource_idx);
@@ -122,6 +131,27 @@ static void wined3d_rendertarget_view_init(struct wined3d_rendertarget_view *vie
         view->width = sub_resource->width;
         view->height = sub_resource->height;
         view->depth = desc->u.texture.layer_count;
+
+        if (swapchain)
+        {
+            view->swapchain = swapchain;
+            if (texture == swapchain->front_buffer)
+            {
+                view->front_buffer = TRUE;
+            }
+            else
+            {
+                unsigned int i;
+                for (i = 0; i < swapchain->desc.backbuffer_count; ++i)
+                {
+                    if (texture == wined3d_swapchain_get_back_buffer(view->swapchain, i))
+                    {
+                        view->backbuffer_idx = i;
+                        break;
+                    }
+                }
+            }
+        }
     }
 }
 
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 05de360..8dd0a84 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2724,53 +2724,6 @@ void buffer_internal_preload(struct wined3d_buffer *buffer, struct wined3d_conte
         const struct wined3d_state *state) DECLSPEC_HIDDEN;
 void buffer_mark_used(struct wined3d_buffer *buffer) DECLSPEC_HIDDEN;
 
-struct wined3d_rendertarget_view
-{
-    LONG refcount;
-
-    struct wined3d_resource *resource;
-    void *parent;
-    const struct wined3d_parent_ops *parent_ops;
-
-    const struct wined3d_format *format;
-    unsigned int format_flags;
-    unsigned int sub_resource_idx;
-    unsigned int buffer_offset;
-
-    unsigned int width;
-    unsigned int height;
-    unsigned int depth;
-};
-
-static inline struct wined3d_surface *wined3d_rendertarget_view_get_surface(
-        const struct wined3d_rendertarget_view *view)
-{
-    struct wined3d_resource *resource;
-    struct wined3d_texture *texture;
-
-    if (!view)
-        return NULL;
-
-    resource = view->resource;
-    if (resource->type != WINED3D_RTYPE_TEXTURE && resource->type != WINED3D_RTYPE_CUBE_TEXTURE)
-        return NULL;
-
-    texture = wined3d_texture_from_resource(resource);
-    if (!(resource = wined3d_texture_get_sub_resource(texture, view->sub_resource_idx)))
-        return NULL;
-
-    return surface_from_resource(resource);
-}
-
-struct wined3d_shader_resource_view
-{
-    LONG refcount;
-
-    struct wined3d_resource *resource;
-    void *parent;
-    const struct wined3d_parent_ops *parent_ops;
-};
-
 struct wined3d_swapchain_ops
 {
     void (*swapchain_present)(struct wined3d_swapchain *swapchain, const RECT *src_rect,
@@ -2814,6 +2767,67 @@ void swapchain_destroy_contexts(struct wined3d_swapchain *swapchain) DECLSPEC_HI
 HDC swapchain_get_backup_dc(struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
 void swapchain_update_draw_bindings(struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
 
+struct wined3d_rendertarget_view
+{
+    LONG refcount;
+
+    struct wined3d_resource *resource;
+    void *parent;
+    const struct wined3d_parent_ops *parent_ops;
+
+    struct wined3d_swapchain *swapchain;
+    BOOL front_buffer;
+    unsigned int backbuffer_idx;
+
+    const struct wined3d_format *format;
+    unsigned int format_flags;
+    unsigned int sub_resource_idx;
+    unsigned int buffer_offset;
+
+    unsigned int width;
+    unsigned int height;
+    unsigned int depth;
+};
+
+static inline struct wined3d_surface *wined3d_rendertarget_view_get_surface(
+        const struct wined3d_rendertarget_view *view)
+{
+    struct wined3d_resource *resource;
+    struct wined3d_texture *texture;
+
+    if (!view)
+        return NULL;
+
+    if (view->swapchain)
+    {
+        if (view->front_buffer)
+            texture = view->swapchain->front_buffer;
+        else
+            texture = wined3d_swapchain_get_back_buffer(view->swapchain, view->backbuffer_idx);
+    }
+    else
+    {
+        resource = view->resource;
+        if (resource->type != WINED3D_RTYPE_TEXTURE && resource->type != WINED3D_RTYPE_CUBE_TEXTURE)
+            return NULL;
+        texture = wined3d_texture_from_resource(resource);
+    }
+
+    if (!(resource = wined3d_texture_get_sub_resource(texture, view->sub_resource_idx)))
+        return NULL;
+
+    return surface_from_resource(resource);
+}
+
+struct wined3d_shader_resource_view
+{
+    LONG refcount;
+
+    struct wined3d_resource *resource;
+    void *parent;
+    const struct wined3d_parent_ops *parent_ops;
+};
+
 /*****************************************************************************
  * Utility function prototypes
  */
-- 
2.4.6




More information about the wine-patches mailing list