Henri Verbeet : wined3d: Introduce wined3d_volume_prepare_location().

Alexandre Julliard julliard at wine.codeweavers.com
Wed Mar 9 08:05:55 CST 2016


Module: wine
Branch: master
Commit: 84b9dd383700f562fcc3e0d9722e17325a5e2968
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=84b9dd383700f562fcc3e0d9722e17325a5e2968

Author: Henri Verbeet <hverbeet at codeweavers.com>
Date:   Tue Mar  8 15:51:15 2016 +0100

wined3d: Introduce wined3d_volume_prepare_location().

Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/wined3d/volume.c          | 82 ++++++++++++++++++++++++++----------------
 dlls/wined3d/wined3d_private.h |  1 -
 2 files changed, 51 insertions(+), 32 deletions(-)

diff --git a/dlls/wined3d/volume.c b/dlls/wined3d/volume.c
index 457067d..cfa3cf0 100644
--- a/dlls/wined3d/volume.c
+++ b/dlls/wined3d/volume.c
@@ -27,7 +27,7 @@
 WINE_DEFAULT_DEBUG_CHANNEL(d3d_surface);
 WINE_DECLARE_DEBUG_CHANNEL(d3d_perf);
 
-BOOL volume_prepare_system_memory(struct wined3d_volume *volume)
+static BOOL volume_prepare_system_memory(struct wined3d_volume *volume)
 {
     if (volume->resource.heap_memory)
         return TRUE;
@@ -40,6 +40,36 @@ BOOL volume_prepare_system_memory(struct wined3d_volume *volume)
     return TRUE;
 }
 
+/* Context activation is done by the caller. Context may be NULL in
+ * WINED3D_NO3D mode. */
+static BOOL wined3d_volume_prepare_location(struct wined3d_volume *volume,
+        struct wined3d_context *context, DWORD location)
+{
+    struct wined3d_texture *texture = volume->container;
+
+    switch (location)
+    {
+        case WINED3D_LOCATION_SYSMEM:
+            return volume_prepare_system_memory(volume);
+
+        case WINED3D_LOCATION_BUFFER:
+            wined3d_texture_prepare_buffer_object(texture, volume->texture_level, context->gl_info);
+            return TRUE;
+
+        case WINED3D_LOCATION_TEXTURE_RGB:
+            wined3d_texture_prepare_texture(texture, context, FALSE);
+            return TRUE;
+
+        case WINED3D_LOCATION_TEXTURE_SRGB:
+            wined3d_texture_prepare_texture(texture, context, TRUE);
+            return TRUE;
+
+        default:
+            ERR("Invalid location %s.\n", wined3d_debug_location(location));
+            return FALSE;
+    }
+}
+
 /* This call just uploads data, the caller is responsible for binding the
  * correct texture. */
 /* Context activation is done by the caller. */
@@ -384,11 +414,10 @@ static void volume_unload(struct wined3d_resource *resource)
 
     TRACE("texture %p.\n", resource);
 
-    if (volume_prepare_system_memory(volume))
+    context = context_acquire(device, NULL);
+    if (wined3d_volume_prepare_location(volume, context, WINED3D_LOCATION_SYSMEM))
     {
-        context = context_acquire(device, NULL);
         wined3d_volume_load_location(volume, context, WINED3D_LOCATION_SYSMEM);
-        context_release(context);
         wined3d_volume_invalidate_location(volume, ~WINED3D_LOCATION_SYSMEM);
     }
     else
@@ -397,6 +426,7 @@ static void volume_unload(struct wined3d_resource *resource)
         wined3d_volume_validate_location(volume, WINED3D_LOCATION_DISCARDED);
         wined3d_volume_invalidate_location(volume, ~WINED3D_LOCATION_DISCARDED);
     }
+    context_release(context);
 
     /* The texture name is managed by the container. */
 
@@ -465,17 +495,24 @@ HRESULT wined3d_volume_map(struct wined3d_volume *volume,
 
     flags = wined3d_resource_sanitize_map_flags(&volume->resource, flags);
 
-    if (volume->resource.map_binding == WINED3D_LOCATION_BUFFER)
+    context = context_acquire(device, NULL);
+    gl_info = context->gl_info;
+
+    if (!wined3d_volume_prepare_location(volume, context, volume->resource.map_binding))
     {
-        context = context_acquire(device, NULL);
-        gl_info = context->gl_info;
+        ERR("Failed to prepare location.\n");
+        context_release(context);
+        map_desc->data = NULL;
+        return E_OUTOFMEMORY;
+    }
 
-        wined3d_texture_prepare_buffer_object(texture, volume->texture_level, gl_info);
-        if (flags & WINED3D_MAP_DISCARD)
-            wined3d_volume_validate_location(volume, WINED3D_LOCATION_BUFFER);
-        else
-            wined3d_volume_load_location(volume, context, WINED3D_LOCATION_BUFFER);
+    if (flags & WINED3D_MAP_DISCARD)
+        wined3d_volume_validate_location(volume, volume->resource.map_binding);
+    else
+        wined3d_volume_load_location(volume, context, volume->resource.map_binding);
 
+    if (volume->resource.map_binding == WINED3D_LOCATION_BUFFER)
+    {
         GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, texture->sub_resources[volume->texture_level].buffer_object));
 
         if (gl_info->supported[ARB_MAP_BUFFER_RANGE])
@@ -493,31 +530,14 @@ HRESULT wined3d_volume_map(struct wined3d_volume *volume,
 
         GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0));
         checkGLcall("Map PBO");
-
-        context_release(context);
     }
     else
     {
-        if (!volume_prepare_system_memory(volume))
-        {
-            WARN("Out of memory.\n");
-            map_desc->data = NULL;
-            return E_OUTOFMEMORY;
-        }
-
-        if (flags & WINED3D_MAP_DISCARD)
-        {
-            wined3d_volume_validate_location(volume, WINED3D_LOCATION_SYSMEM);
-        }
-        else if (!(volume->locations & WINED3D_LOCATION_SYSMEM))
-        {
-            context = context_acquire(device, NULL);
-            wined3d_volume_load_location(volume, context, WINED3D_LOCATION_SYSMEM);
-            context_release(context);
-        }
         base_memory = volume->resource.heap_memory;
     }
 
+    context_release(context);
+
     TRACE("Base memory pointer %p.\n", base_memory);
 
     if (fmt_flags & WINED3DFMT_FLAG_BROKEN_PITCH)
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 9eca0e0..2c2dc84 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2454,7 +2454,6 @@ static inline struct wined3d_volume *volume_from_resource(struct wined3d_resourc
     return CONTAINING_RECORD(resource, struct wined3d_volume, resource);
 }
 
-BOOL volume_prepare_system_memory(struct wined3d_volume *volume) DECLSPEC_HIDDEN;
 void wined3d_volume_cleanup(struct wined3d_volume *volume) DECLSPEC_HIDDEN;
 HRESULT wined3d_volume_init(struct wined3d_volume *volume, struct wined3d_texture *container,
         const struct wined3d_resource_desc *desc, UINT level) DECLSPEC_HIDDEN;




More information about the wine-cvs mailing list