Henri Verbeet : ddraw: Make the DDSURFACEDESC2 parameter to ddraw_surface_create_texture() const.

Alexandre Julliard julliard at winehq.org
Fri Nov 29 13:24:27 CST 2013


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

Author: Henri Verbeet <hverbeet at codeweavers.com>
Date:   Thu Nov 28 09:55:41 2013 +0100

ddraw: Make the DDSURFACEDESC2 parameter to ddraw_surface_create_texture() const.

---

 dlls/ddraw/ddraw.c         |   19 ++++---------------
 dlls/ddraw/ddraw_private.h |    4 ++--
 dlls/ddraw/surface.c       |   36 +++++++++++++++++++++++++++---------
 3 files changed, 33 insertions(+), 26 deletions(-)

diff --git a/dlls/ddraw/ddraw.c b/dlls/ddraw/ddraw.c
index 389038c..9645c2d 100644
--- a/dlls/ddraw/ddraw.c
+++ b/dlls/ddraw/ddraw.c
@@ -2808,21 +2808,13 @@ static HRESULT WINAPI ddraw7_StartModeTest(IDirectDraw7 *iface, SIZE *Modes, DWO
  *  DDERR_* if an error occurs
  *
  *****************************************************************************/
-static HRESULT CreateSurface(struct ddraw *ddraw, DDSURFACEDESC2 *DDSD,
+static HRESULT CreateSurface(struct ddraw *ddraw, const DDSURFACEDESC2 *surface_desc,
         struct ddraw_surface **surface, IUnknown *UnkOuter, UINT version)
 {
     struct ddraw_surface *object = NULL;
     HRESULT hr;
-    DDSURFACEDESC2 desc2;
 
-    TRACE("ddraw %p, surface_desc %p, surface %p, outer_unknown %p.\n", ddraw, DDSD, surface, UnkOuter);
-
-    /* Some checks before we start */
-    if (TRACE_ON(ddraw))
-    {
-        TRACE(" (%p) Requesting surface desc :\n", ddraw);
-        DDRAW_dump_surface_desc(DDSD);
-    }
+    TRACE("ddraw %p, surface_desc %p, surface %p, outer_unknown %p.\n", ddraw, surface_desc, surface, UnkOuter);
 
     if (UnkOuter != NULL)
     {
@@ -2836,10 +2828,7 @@ static HRESULT CreateSurface(struct ddraw *ddraw, DDSURFACEDESC2 *DDSD,
         return E_POINTER; /* unchecked */
     }
 
-    /* Modify some flags */
-    copy_to_surfacedesc2(&desc2, DDSD);
-
-    if (FAILED(hr = ddraw_surface_create_texture(ddraw, &desc2, version, &object)))
+    if (FAILED(hr = ddraw_surface_create_texture(ddraw, surface_desc, version, &object)))
     {
         WARN("Failed to create texture, hr %#x.\n", hr);
         return hr;
@@ -2848,7 +2837,7 @@ static HRESULT CreateSurface(struct ddraw *ddraw, DDSURFACEDESC2 *DDSD,
 
     *surface = object;
 
-    if (desc2.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
+    if (surface_desc->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
         ddraw->primary = object;
 
     return hr;
diff --git a/dlls/ddraw/ddraw_private.h b/dlls/ddraw/ddraw_private.h
index 782c136..94f5453 100644
--- a/dlls/ddraw/ddraw_private.h
+++ b/dlls/ddraw/ddraw_private.h
@@ -193,7 +193,7 @@ struct ddraw_texture
     struct ddraw_surface *root;
 };
 
-HRESULT ddraw_surface_create_texture(struct ddraw *ddraw, DDSURFACEDESC2 *desc,
+HRESULT ddraw_surface_create_texture(struct ddraw *ddraw, const DDSURFACEDESC2 *desc,
         unsigned int version, struct ddraw_surface **surface) DECLSPEC_HIDDEN;
 HRESULT ddraw_surface_init(struct ddraw_surface *surface, struct ddraw *ddraw, struct ddraw_texture *texture,
         struct wined3d_surface *wined3d_surface, const struct wined3d_parent_ops **parent_ops) DECLSPEC_HIDDEN;
@@ -611,7 +611,7 @@ struct member_info
 #define SIZEOF_END_PADDING(type, last_field) \
     (sizeof(type) - offsetof(type, last_field) - sizeof(((type *)0)->last_field))
 
-static inline void copy_to_surfacedesc2(DDSURFACEDESC2 *to, DDSURFACEDESC2 *from)
+static inline void copy_to_surfacedesc2(DDSURFACEDESC2 *to, const DDSURFACEDESC2 *from)
 {
     DWORD from_size = from->dwSize;
     if (from_size == sizeof(DDSURFACEDESC))
diff --git a/dlls/ddraw/surface.c b/dlls/ddraw/surface.c
index a13a5e4..ee5f2eb 100644
--- a/dlls/ddraw/surface.c
+++ b/dlls/ddraw/surface.c
@@ -5589,7 +5589,7 @@ static HRESULT CDECL ddraw_reset_enum_callback(struct wined3d_resource *resource
     return DD_OK;
 }
 
-HRESULT ddraw_surface_create_texture(struct ddraw *ddraw, DDSURFACEDESC2 *desc,
+HRESULT ddraw_surface_create_texture(struct ddraw *ddraw, const DDSURFACEDESC2 *surface_desc,
         unsigned int version, struct ddraw_surface **surface)
 {
     struct ddraw_surface *root, *mip, **attach;
@@ -5597,17 +5597,24 @@ HRESULT ddraw_surface_create_texture(struct ddraw *ddraw, DDSURFACEDESC2 *desc,
     struct wined3d_texture *wined3d_texture;
     struct wined3d_resource *resource;
     struct wined3d_display_mode mode;
+    DDSURFACEDESC2 *desc, *mip_desc;
     struct ddraw_texture *texture;
     UINT layers, levels, i, j;
-    DDSURFACEDESC2 *mip_desc;
     HRESULT hr;
 
     if (TRACE_ON(ddraw))
     {
         TRACE("Requesting surface desc:\n");
-        DDRAW_dump_surface_desc(desc);
+        DDRAW_dump_surface_desc(surface_desc);
     }
 
+    if (!(texture = HeapAlloc(GetProcessHeap(), 0, sizeof(*texture))))
+        return E_OUTOFMEMORY;
+
+    texture->version = version;
+    copy_to_surfacedesc2(&texture->surface_desc, surface_desc);
+    desc = &texture->surface_desc;
+
     /* Ensure DDSD_CAPS is always set. */
     desc->dwFlags |= DDSD_CAPS;
 
@@ -5621,6 +5628,7 @@ HRESULT ddraw_surface_create_texture(struct ddraw *ddraw, DDSURFACEDESC2 *desc,
             && !(ddraw->cooperative_level & DDSCL_EXCLUSIVE))
     {
         WARN("Tried to create a flippable primary surface without DDSCL_EXCLUSIVE.\n");
+        HeapFree(GetProcessHeap(), 0, texture);
         return DDERR_NOEXCLUSIVEMODE;
     }
 
@@ -5628,6 +5636,7 @@ HRESULT ddraw_surface_create_texture(struct ddraw *ddraw, DDSURFACEDESC2 *desc,
             == (DDSCAPS_BACKBUFFER | DDSCAPS_PRIMARYSURFACE))
     {
         WARN("Tried to create a back buffer surface.\n");
+        HeapFree(GetProcessHeap(), 0, texture);
         return DDERR_INVALIDCAPS;
     }
 
@@ -5636,6 +5645,7 @@ HRESULT ddraw_surface_create_texture(struct ddraw *ddraw, DDSURFACEDESC2 *desc,
             == (DDSCAPS_VIDEOMEMORY | DDSCAPS_SYSTEMMEMORY))
     {
         WARN("Tried to create a surface in both system and video memory.\n");
+        HeapFree(GetProcessHeap(), 0, texture);
         return DDERR_INVALIDCAPS;
     }
 
@@ -5643,6 +5653,7 @@ HRESULT ddraw_surface_create_texture(struct ddraw *ddraw, DDSURFACEDESC2 *desc,
             && !(desc->ddsCaps.dwCaps2 & DDSCAPS2_CUBEMAP))
     {
         WARN("Cube map faces requested without cube map flag.\n");
+        HeapFree(GetProcessHeap(), 0, texture);
         return DDERR_INVALIDCAPS;
     }
 
@@ -5650,6 +5661,7 @@ HRESULT ddraw_surface_create_texture(struct ddraw *ddraw, DDSURFACEDESC2 *desc,
             && !(desc->ddsCaps.dwCaps2 & DDSCAPS2_CUBEMAP_ALLFACES))
     {
         WARN("Cube map without faces requested.\n");
+        HeapFree(GetProcessHeap(), 0, texture);
         return DDERR_INVALIDPARAMS;
     }
 
@@ -5662,12 +5674,14 @@ HRESULT ddraw_surface_create_texture(struct ddraw *ddraw, DDSURFACEDESC2 *desc,
         if (!(desc->ddsCaps.dwCaps & DDSCAPS_TEXTURE))
         {
             WARN("DDSCAPS2_TEXTUREMANAGE used without DDSCAPS_TEXTURE, returning DDERR_INVALIDCAPS.\n");
+            HeapFree(GetProcessHeap(), 0, texture);
             return DDERR_INVALIDCAPS;
         }
         if (desc->ddsCaps.dwCaps & (DDSCAPS_VIDEOMEMORY | DDSCAPS_SYSTEMMEMORY))
         {
             WARN("DDSCAPS2_TEXTUREMANAGE used width DDSCAPS_VIDEOMEMORY "
                     "or DDSCAPS_SYSTEMMEMORY, returning DDERR_INVALIDCAPS.\n");
+            HeapFree(GetProcessHeap(), 0, texture);
             return DDERR_INVALIDCAPS;
         }
     }
@@ -5675,6 +5689,7 @@ HRESULT ddraw_surface_create_texture(struct ddraw *ddraw, DDSURFACEDESC2 *desc,
     if (FAILED(hr = wined3d_get_adapter_display_mode(ddraw->wined3d, WINED3DADAPTER_DEFAULT, &mode, NULL)))
     {
         ERR("Failed to get display mode, hr %#x.\n", hr);
+        HeapFree(GetProcessHeap(), 0, texture);
         return hr;
     }
 
@@ -5690,6 +5705,7 @@ HRESULT ddraw_surface_create_texture(struct ddraw *ddraw, DDSURFACEDESC2 *desc,
     if (wined3d_desc.format == WINED3DFMT_UNKNOWN)
     {
         WARN("Unsupported / unknown pixelformat.\n");
+        HeapFree(GetProcessHeap(), 0, texture);
         return DDERR_INVALIDPIXELFORMAT;
     }
 
@@ -5699,6 +5715,7 @@ HRESULT ddraw_surface_create_texture(struct ddraw *ddraw, DDSURFACEDESC2 *desc,
         if (!(desc->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE))
         {
             WARN("No width / height specified.\n");
+            HeapFree(GetProcessHeap(), 0, texture);
             return DDERR_INVALIDPARAMS;
         }
 
@@ -5708,7 +5725,10 @@ HRESULT ddraw_surface_create_texture(struct ddraw *ddraw, DDSURFACEDESC2 *desc,
     }
 
     if (!desc->dwWidth || !desc->dwHeight)
+    {
+        HeapFree(GetProcessHeap(), 0, texture);
         return DDERR_INVALIDPARAMS;
+    }
 
     if (desc->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
     {
@@ -5728,6 +5748,7 @@ HRESULT ddraw_surface_create_texture(struct ddraw *ddraw, DDSURFACEDESC2 *desc,
                     &swapchain_desc, NULL, ddraw_reset_enum_callback, TRUE)))
             {
                 ERR("Failed to reset device.\n");
+                HeapFree(GetProcessHeap(), 0, texture);
                 return hr;
             }
         }
@@ -5757,7 +5778,10 @@ HRESULT ddraw_surface_create_texture(struct ddraw *ddraw, DDSURFACEDESC2 *desc,
             {
                 /* Mipmap count is given, should not be 0. */
                 if (!desc->u2.dwMipMapCount)
+                {
+                    HeapFree(GetProcessHeap(), 0, texture);
                     return DDERR_INVALIDPARAMS;
+                }
             }
             else
             {
@@ -5853,12 +5877,6 @@ HRESULT ddraw_surface_create_texture(struct ddraw *ddraw, DDSURFACEDESC2 *desc,
     if (desc->ddsCaps.dwCaps & DDSCAPS_OWNDC)
         wined3d_desc.usage |= WINED3DUSAGE_OWNDC;
 
-    if (!(texture = HeapAlloc(GetProcessHeap(), 0, sizeof(*texture))))
-        return E_OUTOFMEMORY;
-
-    texture->version = version;
-    copy_to_surfacedesc2(&texture->surface_desc, desc);
-
     if (desc->ddsCaps.dwCaps2 & DDSCAPS2_CUBEMAP)
     {
         wined3d_desc.resource_type = WINED3D_RTYPE_CUBE_TEXTURE;




More information about the wine-cvs mailing list