[PATCH 2/3] wined3d: Replace surface_prepare_map memory with wined3d_surface_prepare.

Stefan Dösinger stefan at codeweavers.com
Wed Nov 4 04:28:23 CST 2015


Signed-off-by: Stefan Dösinger <stefan at codeweavers.com>
---
 dlls/wined3d/surface.c         | 74 ++++++++++++------------------------------
 dlls/wined3d/texture.c         |  2 +-
 dlls/wined3d/wined3d_private.h |  1 -
 3 files changed, 21 insertions(+), 56 deletions(-)

diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index 89fefbb..beb0a8e 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -510,18 +510,15 @@ static void surface_get_memory(const struct wined3d_surface *surface, struct win
     data->buffer_object = 0;
 }
 
-static void surface_prepare_buffer(struct wined3d_surface *surface)
+/* Context activation is done by the caller. */
+static void surface_prepare_buffer(struct wined3d_surface *surface, struct wined3d_context *context)
 {
-    struct wined3d_context *context;
     GLenum error;
-    const struct wined3d_gl_info *gl_info;
+    const struct wined3d_gl_info *gl_info = context->gl_info;
 
     if (surface->pbo)
         return;
 
-    context = context_acquire(surface->resource.device, NULL);
-    gl_info = context->gl_info;
-
     GL_EXTCALL(glGenBuffers(1, &surface->pbo));
     error = gl_info->gl_ops.gl.p_glGetError();
     if (!surface->pbo || error != GL_NO_ERROR)
@@ -538,8 +535,6 @@ static void surface_prepare_buffer(struct wined3d_surface *surface)
 
     GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0));
     checkGLcall("glBindBuffer");
-
-    context_release(context);
 }
 
 static void surface_prepare_system_memory(struct wined3d_surface *surface)
@@ -558,33 +553,6 @@ static void surface_prepare_system_memory(struct wined3d_surface *surface)
         ERR("Surface without system memory has WINED3D_LOCATION_SYSMEM set.\n");
 }
 
-void surface_prepare_map_memory(struct wined3d_surface *surface)
-{
-    switch (surface->resource.map_binding)
-    {
-        case WINED3D_LOCATION_SYSMEM:
-            surface_prepare_system_memory(surface);
-            break;
-
-        case WINED3D_LOCATION_USER_MEMORY:
-            if (!surface->user_memory)
-                ERR("Map binding is set to WINED3D_LOCATION_USER_MEMORY but surface->user_memory is NULL.\n");
-            break;
-
-        case WINED3D_LOCATION_DIB:
-            if (!surface->dib.bitmap_data)
-                ERR("Map binding is set to WINED3D_LOCATION_DIB but surface->dib.bitmap_data is NULL.\n");
-            break;
-
-        case WINED3D_LOCATION_BUFFER:
-            surface_prepare_buffer(surface);
-            break;
-
-        default:
-            ERR("Unexpected map binding %s.\n", wined3d_debug_location(surface->resource.map_binding));
-    }
-}
-
 static void surface_evict_sysmem(struct wined3d_surface *surface)
 {
     /* In some conditions the surface memory must not be freed:
@@ -1159,7 +1127,7 @@ static void surface_unload(struct wined3d_resource *resource)
     }
     else
     {
-        surface_prepare_map_memory(surface);
+        wined3d_surface_prepare(surface, context, surface->resource.map_binding);
         surface_load_location(surface, context, surface->resource.map_binding);
         surface_invalidate_location(surface, ~surface->resource.map_binding);
     }
@@ -2477,9 +2445,9 @@ HRESULT CDECL wined3d_surface_map(struct wined3d_surface *surface,
     const struct wined3d_format *format = surface->resource.format;
     unsigned int fmt_flags = surface->container->resource.format_flags;
     struct wined3d_device *device = surface->resource.device;
-    struct wined3d_context *context;
-    const struct wined3d_gl_info *gl_info;
     BYTE *base_memory;
+    struct wined3d_context *context = NULL;
+    const struct wined3d_gl_info *gl_info = NULL;
 
     TRACE("surface %p, map_desc %p, box %p, flags %#x.\n",
             surface, map_desc, box, flags);
@@ -2520,7 +2488,13 @@ HRESULT CDECL wined3d_surface_map(struct wined3d_surface *surface,
         }
     }
 
-    surface_prepare_map_memory(surface);
+    if (surface->resource.device->d3d_initialized)
+    {
+        context = context_acquire(device, NULL);
+        gl_info = context->gl_info;
+    }
+
+    wined3d_surface_prepare(surface, context, surface->resource.map_binding);
     if (flags & WINED3D_MAP_DISCARD)
     {
         TRACE("WINED3D_MAP_DISCARD flag passed, marking %s as up to date.\n",
@@ -2529,16 +2503,10 @@ HRESULT CDECL wined3d_surface_map(struct wined3d_surface *surface,
     }
     else
     {
-        struct wined3d_context *context = NULL;
-
         if (surface->resource.usage & WINED3DUSAGE_DYNAMIC)
             WARN_(d3d_perf)("Mapping a dynamic surface without WINED3D_MAP_DISCARD.\n");
 
-        if (surface->resource.device->d3d_initialized)
-            context = context_acquire(surface->resource.device, NULL);
         surface_load_location(surface, context, surface->resource.map_binding);
-        if (context)
-            context_release(context);
     }
 
     if (!(flags & (WINED3D_MAP_NO_DIRTY_UPDATE | WINED3D_MAP_READONLY)))
@@ -2559,15 +2527,10 @@ HRESULT CDECL wined3d_surface_map(struct wined3d_surface *surface,
             break;
 
         case WINED3D_LOCATION_BUFFER:
-            context = context_acquire(device, NULL);
-            gl_info = context->gl_info;
-
             GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, surface->pbo));
             base_memory = GL_EXTCALL(glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE));
             GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0));
             checkGLcall("map PBO");
-
-            context_release(context);
             break;
 
         default:
@@ -2575,6 +2538,9 @@ HRESULT CDECL wined3d_surface_map(struct wined3d_surface *surface,
             base_memory = NULL;
     }
 
+    if (context)
+        context_release(context);
+
     if (fmt_flags & WINED3DFMT_FLAG_BROKEN_PITCH)
         map_desc->row_pitch = surface->resource.width * format->byte_count;
     else
@@ -3962,7 +3928,7 @@ static HRESULT surface_load_texture(struct wined3d_surface *surface,
         {
             /* Performance warning... */
             FIXME("Downloading RGB surface %p to reload it as sRGB.\n", surface);
-            surface_prepare_map_memory(surface);
+            wined3d_surface_prepare(surface, context, surface->resource.map_binding);
             surface_load_location(surface, context, surface->resource.map_binding);
         }
     }
@@ -3973,7 +3939,7 @@ static HRESULT surface_load_texture(struct wined3d_surface *surface,
         {
             /* Performance warning... */
             FIXME("Downloading sRGB surface %p to reload it as RGB.\n", surface);
-            surface_prepare_map_memory(surface);
+            wined3d_surface_prepare(surface, context, surface->resource.map_binding);
             surface_load_location(surface, context, surface->resource.map_binding);
         }
     }
@@ -4007,7 +3973,7 @@ static HRESULT surface_load_texture(struct wined3d_surface *surface,
         else
             surface->resource.map_binding = WINED3D_LOCATION_SYSMEM;
 
-        surface_prepare_map_memory(surface);
+        wined3d_surface_prepare(surface, context, surface->resource.map_binding);
         surface_load_location(surface, context, surface->resource.map_binding);
         surface_remove_pbo(surface, gl_info);
     }
@@ -5507,7 +5473,7 @@ void wined3d_surface_prepare(struct wined3d_surface *surface, struct wined3d_con
             break;
 
         case WINED3D_LOCATION_BUFFER:
-            /* Intentionally not yet handled in this patch. */
+            surface_prepare_buffer(surface, context);
             break;
 
         case WINED3D_LOCATION_TEXTURE_RGB:
diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c
index f8ebfff..867dd92 100644
--- a/dlls/wined3d/texture.c
+++ b/dlls/wined3d/texture.c
@@ -772,8 +772,8 @@ static void texture2d_sub_resource_add_dirty_region(struct wined3d_resource *sub
     struct wined3d_surface *surface = surface_from_resource(sub_resource);
     struct wined3d_context *context;
 
-    surface_prepare_map_memory(surface);
     context = context_acquire(surface->resource.device, NULL);
+    wined3d_surface_prepare(surface, context, surface->resource.map_binding);
     surface_load_location(surface, context, surface->resource.map_binding);
     context_release(context);
     surface_invalidate_location(surface, ~surface->resource.map_binding);
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index fd7bbc8..f835a81 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2476,7 +2476,6 @@ HRESULT wined3d_surface_create(struct wined3d_texture *container, const struct w
         GLenum target, unsigned int level, unsigned int layer, DWORD flags,
         struct wined3d_surface **surface) DECLSPEC_HIDDEN;
 void wined3d_surface_destroy(struct wined3d_surface *surface) DECLSPEC_HIDDEN;
-void surface_prepare_map_memory(struct wined3d_surface *surface) DECLSPEC_HIDDEN;
 void wined3d_surface_upload_data(struct wined3d_surface *surface, const struct wined3d_gl_info *gl_info,
         const struct wined3d_format *format, const RECT *src_rect, UINT src_pitch, const POINT *dst_point,
         BOOL srgb, const struct wined3d_const_bo_address *data) DECLSPEC_HIDDEN;
-- 
2.4.10




More information about the wine-patches mailing list