[PATCH 4/4] wined3d: Merge wined3d_surface_set_mem into wined3d_surface_update_desc (try 2) .

Stefan Dösinger stefan at codeweavers.com
Tue Jan 7 09:58:23 CST 2014


Try 2: Keep the mapped and dc in use checks.

Note that the call to surface_release_client_storage is not needed even
without the assumption that user memory and client storage are mutually
exclusive because wined3d_surface_update_desc unloads the surface before
doing anything.
---
 dlls/d3d8/device.c        |  2 +-
 dlls/d3d9/device.c        |  7 ++++--
 dlls/ddraw/surface.c      | 25 +++++----------------
 dlls/wined3d/device.c     |  6 ++---
 dlls/wined3d/surface.c    | 57 +++++++++++++----------------------------------
 dlls/wined3d/wined3d.spec |  3 +--
 include/wine/wined3d.h    |  4 ++--
 7 files changed, 33 insertions(+), 71 deletions(-)

diff --git a/dlls/d3d8/device.c b/dlls/d3d8/device.c
index 59ddfcc..d28ada5 100644
--- a/dlls/d3d8/device.c
+++ b/dlls/d3d8/device.c
@@ -1028,7 +1028,7 @@ static HRESULT WINAPI d3d8_device_CopyRects(IDirect3DDevice8 *iface,
     {
         TRACE("Converting destination surface from WINED3DFMT_UNKNOWN to the source format.\n");
         if (FAILED(hr = wined3d_surface_update_desc(dst->wined3d_surface, wined3d_desc.width, wined3d_desc.height,
-                src_format, wined3d_desc.multisample_type, wined3d_desc.multisample_quality)))
+                src_format, wined3d_desc.multisample_type, wined3d_desc.multisample_quality, NULL, 0)))
         {
             WARN("Failed to update surface desc, hr %#x.\n", hr);
             wined3d_mutex_unlock();
diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c
index ea49b0a..159f74b 100644
--- a/dlls/d3d9/device.c
+++ b/dlls/d3d9/device.c
@@ -782,7 +782,9 @@ static HRESULT WINAPI d3d9_device_CreateTexture(IDirect3DDevice9Ex *iface,
 
         resource = wined3d_texture_get_sub_resource(object->wined3d_texture, 0);
         surface = wined3d_resource_get_parent(resource);
-        wined3d_surface_set_mem(surface->wined3d_surface, *shared_handle, 0);
+        wined3d_surface_update_desc(surface->wined3d_surface, width, height,
+                wined3dformat_from_d3dformat(format), WINED3D_MULTISAMPLE_NONE, 0,
+                *shared_handle, 0);
     }
 
     TRACE("Created texture %p.\n", object);
@@ -1020,7 +1022,8 @@ static HRESULT d3d9_device_create_surface(struct d3d9_device *device, UINT width
     wined3d_texture_decref(texture);
 
     if (user_mem)
-        wined3d_surface_set_mem(surface_impl->wined3d_surface, user_mem, 0);
+        wined3d_surface_update_desc(surface_impl->wined3d_surface, width, height,
+                desc.format, multisample_type, multisample_quality, user_mem, 0);
 
     wined3d_mutex_unlock();
 
diff --git a/dlls/ddraw/surface.c b/dlls/ddraw/surface.c
index 4abe3bf..bab396a 100644
--- a/dlls/ddraw/surface.c
+++ b/dlls/ddraw/surface.c
@@ -4386,11 +4386,11 @@ static HRESULT WINAPI ddraw_surface7_SetSurfaceDesc(IDirectDrawSurface7 *iface,
     }
 
     if (FAILED(hr = wined3d_surface_update_desc(This->wined3d_surface, width, height,
-            format_id, WINED3D_MULTISAMPLE_NONE, 0)))
+            format_id, WINED3D_MULTISAMPLE_NONE, 0, DDSD->lpSurface, pitch)))
     {
         WARN("Failed to update surface desc, hr %#x.\n", hr);
         wined3d_mutex_unlock();
-        return hr;
+        return hr_ddraw_from_wined3d(hr);
     }
 
     if (DDSD->dwFlags & DDSD_WIDTH)
@@ -4402,23 +4402,6 @@ static HRESULT WINAPI ddraw_surface7_SetSurfaceDesc(IDirectDrawSurface7 *iface,
     if (DDSD->dwFlags & DDSD_PIXELFORMAT)
         This->surface_desc.u4.ddpfPixelFormat = DDSD->u4.ddpfPixelFormat;
 
-    if (DDSD->dwFlags & DDSD_LPSURFACE && DDSD->lpSurface)
-    {
-        if (FAILED(hr = wined3d_surface_set_mem(This->wined3d_surface, DDSD->lpSurface, pitch)))
-        {
-            /* No need for a trace here, wined3d does that for us */
-            switch(hr)
-            {
-                case WINED3DERR_INVALIDCALL:
-                    wined3d_mutex_unlock();
-                    return DDERR_INVALIDPARAMS;
-                default:
-                    break; /* Go on */
-            }
-        }
-        /* DDSD->lpSurface is set by Lock() */
-    }
-
     wined3d_mutex_unlock();
 
     return DD_OK;
@@ -6117,7 +6100,9 @@ HRESULT ddraw_surface_init(struct ddraw_surface *surface, struct ddraw *ddraw, s
             surface->surface_desc.u1.lPitch = pitch;
         }
 
-        if (FAILED(hr = wined3d_surface_set_mem(wined3d_surface, desc->lpSurface, pitch)))
+        if (FAILED(hr = wined3d_surface_update_desc(wined3d_surface, wined3d_desc.width,
+                wined3d_desc.height, wined3d_desc.format, WINED3D_MULTISAMPLE_NONE, 0,
+                desc->lpSurface, pitch)))
         {
             ERR("Failed to set surface memory, hr %#x.\n", hr);
             return hr;
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index f14aa57..46fdee2 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -4318,21 +4318,21 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device,
 
         if (FAILED(hr = wined3d_surface_update_desc(swapchain->front_buffer, swapchain->desc.backbuffer_width,
                 swapchain->desc.backbuffer_height, swapchain->desc.backbuffer_format,
-                swapchain->desc.multisample_type, swapchain->desc.multisample_quality)))
+                swapchain->desc.multisample_type, swapchain->desc.multisample_quality, NULL, 0)))
             return hr;
 
         for (i = 0; i < swapchain->desc.backbuffer_count; ++i)
         {
             if (FAILED(hr = wined3d_surface_update_desc(swapchain->back_buffers[i], swapchain->desc.backbuffer_width,
                     swapchain->desc.backbuffer_height, swapchain->desc.backbuffer_format,
-                    swapchain->desc.multisample_type, swapchain->desc.multisample_quality)))
+                    swapchain->desc.multisample_type, swapchain->desc.multisample_quality, NULL, 0)))
                 return hr;
         }
         if (device->auto_depth_stencil)
         {
             if (FAILED(hr = wined3d_surface_update_desc(device->auto_depth_stencil, swapchain->desc.backbuffer_width,
                     swapchain->desc.backbuffer_height, device->auto_depth_stencil->resource.format->id,
-                    swapchain->desc.multisample_type, swapchain->desc.multisample_quality)))
+                    swapchain->desc.multisample_type, swapchain->desc.multisample_quality, NULL, 0)))
                 return hr;
         }
     }
diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index 8d6e7b5..73cf28a 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -6,7 +6,7 @@
  * Copyright 2002-2003 Raphael Junqueira
  * Copyright 2004 Christian Costa
  * Copyright 2005 Oliver Stieber
- * Copyright 2006-2011, 2013 Stefan Dösinger for CodeWeavers
+ * Copyright 2006-2011, 2013-2014 Stefan Dösinger for CodeWeavers
  * Copyright 2007-2008 Henri Verbeet
  * Copyright 2006-2008 Roderick Colenbrander
  * Copyright 2009-2011 Henri Verbeet for CodeWeavers
@@ -2609,45 +2609,6 @@ DWORD CDECL wined3d_surface_get_pitch(const struct wined3d_surface *surface)
     return pitch;
 }
 
-HRESULT CDECL wined3d_surface_set_mem(struct wined3d_surface *surface, void *mem, UINT pitch)
-{
-    TRACE("surface %p, mem %p.\n", surface, mem);
-
-    if (surface->resource.map_count || (surface->flags & SFLAG_DCINUSE))
-    {
-        WARN("Surface is mapped or the DC is in use.\n");
-        return WINED3DERR_INVALIDCALL;
-    }
-
-    if (surface->flags & SFLAG_DIBSECTION)
-    {
-        DeleteDC(surface->hDC);
-        DeleteObject(surface->dib.DIBsection);
-        surface->dib.bitmap_data = NULL;
-        surface->resource.allocatedMemory = NULL;
-        surface->hDC = NULL;
-        surface->flags &= ~SFLAG_DIBSECTION;
-    }
-    else if (!(surface->flags & SFLAG_USERPTR))
-    {
-        wined3d_resource_free_sysmem(&surface->resource);
-        surface->resource.allocatedMemory = NULL;
-    }
-
-    surface->user_memory = mem;
-    surface->flags |= SFLAG_USERPTR;
-    surface_validate_location(surface, SFLAG_INSYSMEM);
-    surface_invalidate_location(surface, ~SFLAG_INSYSMEM);
-
-    /* For client textures OpenGL has to be notified. */
-    if (surface->flags & SFLAG_CLIENT)
-        surface_release_client_storage(surface);
-
-    surface->pitch = pitch;
-
-    return WINED3D_OK;
-}
-
 HRESULT CDECL wined3d_surface_set_overlay_position(struct wined3d_surface *surface, LONG x, LONG y)
 {
     LONG w, h;
@@ -2780,7 +2741,8 @@ HRESULT CDECL wined3d_surface_update_overlay(struct wined3d_surface *surface, co
 
 HRESULT CDECL wined3d_surface_update_desc(struct wined3d_surface *surface,
         UINT width, UINT height, enum wined3d_format_id format_id,
-        enum wined3d_multisample_type multisample_type, UINT multisample_quality)
+        enum wined3d_multisample_type multisample_type, UINT multisample_quality,
+        void *mem, UINT pitch)
 {
     struct wined3d_device *device = surface->resource.device;
     const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
@@ -2795,6 +2757,12 @@ HRESULT CDECL wined3d_surface_update_desc(struct wined3d_surface *surface,
     if (!resource_size)
         return WINED3DERR_INVALIDCALL;
 
+    if (surface->resource.map_count || (surface->flags & SFLAG_DCINUSE))
+    {
+        WARN("Surface is mapped or the DC is in use.\n");
+        return WINED3DERR_INVALIDCALL;
+    }
+
     if (device->d3d_initialized)
         surface->resource.resource_ops->resource_unload(&surface->resource);
 
@@ -2833,6 +2801,13 @@ HRESULT CDECL wined3d_surface_update_desc(struct wined3d_surface *surface,
     else
         surface->flags &= ~SFLAG_NONPOW2;
 
+    if (mem)
+    {
+        surface->user_memory = mem;
+        surface->flags |= SFLAG_USERPTR;
+    }
+    surface->pitch = pitch;
+
     surface->resource.format = format;
     surface->resource.multisample_type = multisample_type;
     surface->resource.multisample_quality = multisample_quality;
diff --git a/dlls/wined3d/wined3d.spec b/dlls/wined3d/wined3d.spec
index a1a99d9..33f88b4 100644
--- a/dlls/wined3d/wined3d.spec
+++ b/dlls/wined3d/wined3d.spec
@@ -223,12 +223,11 @@
 @ cdecl wined3d_surface_releasedc(ptr ptr)
 @ cdecl wined3d_surface_restore(ptr)
 @ cdecl wined3d_surface_set_color_key(ptr long ptr)
-@ cdecl wined3d_surface_set_mem(ptr ptr long)
 @ cdecl wined3d_surface_set_overlay_position(ptr long long)
 @ cdecl wined3d_surface_set_palette(ptr ptr)
 @ cdecl wined3d_surface_set_priority(ptr long)
 @ cdecl wined3d_surface_unmap(ptr)
-@ cdecl wined3d_surface_update_desc(ptr long long long long long)
+@ cdecl wined3d_surface_update_desc(ptr long long long long long ptr long)
 @ cdecl wined3d_surface_update_overlay(ptr ptr ptr ptr long ptr)
 @ cdecl wined3d_surface_update_overlay_z_order(ptr long ptr)
 
diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h
index 47dde06..bde05d3 100644
--- a/include/wine/wined3d.h
+++ b/include/wine/wined3d.h
@@ -2313,14 +2313,14 @@ HRESULT __cdecl wined3d_surface_releasedc(struct wined3d_surface *surface, HDC d
 HRESULT __cdecl wined3d_surface_restore(struct wined3d_surface *surface);
 HRESULT __cdecl wined3d_surface_set_color_key(struct wined3d_surface *surface,
         DWORD flags, const struct wined3d_color_key *color_key);
-HRESULT __cdecl wined3d_surface_set_mem(struct wined3d_surface *surface, void *mem, UINT pitch);
 HRESULT __cdecl wined3d_surface_set_overlay_position(struct wined3d_surface *surface, LONG x, LONG y);
 void __cdecl wined3d_surface_set_palette(struct wined3d_surface *surface, struct wined3d_palette *palette);
 DWORD __cdecl wined3d_surface_set_priority(struct wined3d_surface *surface, DWORD new_priority);
 HRESULT __cdecl wined3d_surface_unmap(struct wined3d_surface *surface);
 HRESULT __cdecl wined3d_surface_update_desc(struct wined3d_surface *surface,
         UINT width, UINT height, enum wined3d_format_id format_id,
-        enum wined3d_multisample_type multisample_type, UINT multisample_quality);
+        enum wined3d_multisample_type multisample_type, UINT multisample_quality,
+        void *mem, UINT pitch);
 HRESULT __cdecl wined3d_surface_update_overlay(struct wined3d_surface *surface, const RECT *src_rect,
         struct wined3d_surface *dst_surface, const RECT *dst_rect, DWORD flags, const WINEDDOVERLAYFX *fx);
 HRESULT __cdecl wined3d_surface_update_overlay_z_order(struct wined3d_surface *surface,
-- 
1.8.3.2




More information about the wine-patches mailing list