[PATCH v3 1/5] ddraw: Convert BOOL flags to bitmask in ddraw_surface.

Paul Gofman pgofman at codeweavers.com
Thu Apr 16 08:57:30 CDT 2020


Signed-off-by: Paul Gofman <pgofman at codeweavers.com>
---
v3:
    - add patch.

 dlls/ddraw/ddraw.c         |  2 +-
 dlls/ddraw/ddraw_private.h |  7 +++++--
 dlls/ddraw/surface.c       | 34 +++++++++++++++++-----------------
 3 files changed, 23 insertions(+), 20 deletions(-)

diff --git a/dlls/ddraw/ddraw.c b/dlls/ddraw/ddraw.c
index 95e9fba901..0a916048bc 100644
--- a/dlls/ddraw/ddraw.c
+++ b/dlls/ddraw/ddraw.c
@@ -4899,7 +4899,7 @@ void ddraw_update_lost_surfaces(struct ddraw *ddraw)
 
     LIST_FOR_EACH_ENTRY(surface, &ddraw->surface_list, struct ddraw_surface, surface_list_entry)
     {
-        surface->is_lost = TRUE;
+        surface->flags |= DDRAW_SURFACE_LOST;
     }
     ddraw->device_state = DDRAW_DEVICE_STATE_OK;
 }
diff --git a/dlls/ddraw/ddraw_private.h b/dlls/ddraw/ddraw_private.h
index 83e3ee10c0..b99ad1f805 100644
--- a/dlls/ddraw/ddraw_private.h
+++ b/dlls/ddraw/ddraw_private.h
@@ -154,6 +154,9 @@ void DDRAW_Convert_DDSCAPS_1_To_2(const DDSCAPS *pIn, DDSCAPS2 *pOut) DECLSPEC_H
 void DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(const DDDEVICEIDENTIFIER2 *pIn, DDDEVICEIDENTIFIER *pOut) DECLSPEC_HIDDEN;
 struct wined3d_vertex_declaration *ddraw_find_decl(struct ddraw *ddraw, DWORD fvf) DECLSPEC_HIDDEN;
 
+#define DDRAW_SURFACE_COMPLEX_ROOT          0x00000001
+#define DDRAW_SURFACE_LOST                  0x00000002
+
 struct ddraw_surface
 {
     /* IUnknown fields */
@@ -195,8 +198,8 @@ struct ddraw_surface
     /* You can't traverse the tree upwards. Only a flag for Surface::Release because it's needed there,
      * but no pointer to prevent temptations to traverse it in the wrong direction.
      */
-    BOOL                    is_complex_root;
-    BOOL is_lost;
+
+    unsigned int flags;
 
     /* Surface description, for GetAttachedSurface */
     DDSURFACEDESC2          surface_desc;
diff --git a/dlls/ddraw/surface.c b/dlls/ddraw/surface.c
index 20143891d3..0a681caf07 100644
--- a/dlls/ddraw/surface.c
+++ b/dlls/ddraw/surface.c
@@ -35,7 +35,7 @@ static inline struct ddraw_surface *impl_from_IDirectDrawGammaControl(IDirectDra
 
 static BOOL ddraw_surface_is_lost(const struct ddraw_surface *surface)
 {
-    return surface->ddraw->device_state != DDRAW_DEVICE_STATE_OK || surface->is_lost;
+    return surface->ddraw->device_state != DDRAW_DEVICE_STATE_OK || surface->flags & DDRAW_SURFACE_LOST;
 }
 
 /* This is slow, of course. Also, in case of locks, we can't prevent other
@@ -528,7 +528,7 @@ static void ddraw_surface_cleanup(struct ddraw_surface *surface)
 
         surf = surface->complex_array[i];
         surface->complex_array[i] = NULL;
-        if (!surf->is_complex_root)
+        if (!(surf->flags & DDRAW_SURFACE_COMPLEX_ROOT))
         {
             struct ddraw_texture *texture = wined3d_texture_get_parent(surf->wined3d_texture);
             struct wined3d_device *wined3d_device = texture->wined3d_device;
@@ -558,33 +558,33 @@ static void ddraw_surface_cleanup(struct ddraw_surface *surface)
     wined3d_texture_decref(surface->wined3d_texture);
 }
 
-static ULONG ddraw_surface_release_iface(struct ddraw_surface *This)
+static ULONG ddraw_surface_release_iface(struct ddraw_surface *surface)
 {
     ULONG iface_count;
 
     /* Prevent the surface from being destroyed if it's still attached to
      * another surface. It will be destroyed when the root is destroyed. */
-    if (This->iface_count == 1 && This->attached_iface)
-        IUnknown_AddRef(This->attached_iface);
-    iface_count = InterlockedDecrement(&This->iface_count);
+    if (surface->iface_count == 1 && surface->attached_iface)
+        IUnknown_AddRef(surface->attached_iface);
+    iface_count = InterlockedDecrement(&surface->iface_count);
 
-    TRACE("%p decreasing iface count to %u.\n", This, iface_count);
+    TRACE("%p decreasing iface count to %u.\n", surface, iface_count);
 
     if (iface_count == 0)
     {
-        struct ddraw_texture *texture = wined3d_texture_get_parent(This->wined3d_texture);
+        struct ddraw_texture *texture = wined3d_texture_get_parent(surface->wined3d_texture);
         struct wined3d_device *wined3d_device = texture->wined3d_device;
-        IUnknown *release_iface = This->ifaceToRelease;
+        IUnknown *release_iface = surface->ifaceToRelease;
 
         /* Complex attached surfaces are destroyed implicitly when the root is released */
         wined3d_mutex_lock();
-        if(!This->is_complex_root)
+        if(!(surface->flags & DDRAW_SURFACE_COMPLEX_ROOT))
         {
-            WARN("(%p) Attempt to destroy a surface that is not a complex root\n", This);
+            WARN("(%p) Attempt to destroy a surface that is not a complex root\n", surface);
             wined3d_mutex_unlock();
             return iface_count;
         }
-        ddraw_surface_cleanup(This);
+        ddraw_surface_cleanup(surface);
         wined3d_mutex_unlock();
 
         if (release_iface)
@@ -2565,7 +2565,7 @@ static HRESULT WINAPI ddraw_surface7_GetPriority(IDirectDrawSurface7 *iface, DWO
         WARN("Called on offscreenplain surface, returning DDERR_INVALIDOBJECT.\n");
         hr = DDERR_INVALIDOBJECT;
     }
-    else if (!(surface->surface_desc.ddsCaps.dwCaps2 & managed) || !surface->is_complex_root)
+    else if (!(surface->surface_desc.ddsCaps.dwCaps2 & managed) || !(surface->flags & DDRAW_SURFACE_COMPLEX_ROOT))
     {
         WARN("Called on non-managed texture or non-root surface, returning DDERR_INVALIDPARAMS.\n");
         hr = DDERR_INVALIDPARAMS;
@@ -3780,12 +3780,12 @@ static HRESULT WINAPI ddraw_surface7_Restore(IDirectDrawSurface7 *iface)
     }
 
     ddraw_update_lost_surfaces(surface->ddraw);
-    surface->is_lost = FALSE;
+    surface->flags &= ~DDRAW_SURFACE_LOST;
 
     for(i = 0; i < MAX_COMPLEX_ATTACHED; i++)
     {
         if (surface->complex_array[i])
-            surface->complex_array[i]->is_lost = FALSE;
+            surface->complex_array[i]->flags &= ~DDRAW_SURFACE_LOST;
     }
 
     return DD_OK;
@@ -4910,7 +4910,7 @@ static HRESULT ddraw_surface_set_color_key(struct ddraw_surface *surface, DWORD
         }
     }
 
-    if (surface->is_complex_root)
+    if (surface->flags & DDRAW_SURFACE_COMPLEX_ROOT)
         hr = wined3d_texture_set_color_key(surface->wined3d_texture, flags,
                 color_key ? (struct wined3d_color_key *)&fixed_color_key : NULL);
 
@@ -6388,7 +6388,7 @@ HRESULT ddraw_surface_create(struct ddraw *ddraw, const DDSURFACEDESC2 *surface_
 
     root = wined3d_texture_get_sub_resource_parent(wined3d_texture, 0);
     wined3d_texture_decref(wined3d_texture);
-    root->is_complex_root = TRUE;
+    root->flags |= DDRAW_SURFACE_COMPLEX_ROOT;
     texture->root = root;
     wined3d_device_incref(texture->wined3d_device = ddraw->wined3d_device);
 
-- 
2.25.2




More information about the wine-devel mailing list