[PATCH 4/5] ddraw: Store IDirectDrawClipper instead of ddraw_clipper.

Stefan Dösinger stefan at codeweavers.com
Mon Mar 4 13:59:03 CST 2019


Signed-off-by: Stefan Dösinger <stefan at codeweavers.com>

---

This gets rid of unsafe_impl_from_IDirectDrawClipper, which feels
slightly out of place because impl_from_IDirectDrawClipper does plenty
of checks. However, we can't use any random clipper implementation
because we're not calling the external API through the vtable, so we may
want to keep unsafe_impl_from_IDirectDrawClipper for the WARN it writes.
Please ignore this patch in this case.
---
 dlls/ddraw/clipper.c       | 15 ---------------
 dlls/ddraw/ddraw_private.h |  3 +--
 dlls/ddraw/surface.c       | 26 +++++++++++---------------
 3 files changed, 12 insertions(+), 32 deletions(-)

diff --git a/dlls/ddraw/clipper.c b/dlls/ddraw/clipper.c
index e7e96eb643d..aa76ac3d162 100644
--- a/dlls/ddraw/clipper.c
+++ b/dlls/ddraw/clipper.c
@@ -383,18 +383,3 @@ HRESULT ddraw_clipper_init(struct ddraw_clipper *clipper)
 
     return DD_OK;
 }
-
-struct ddraw_clipper *unsafe_impl_from_IDirectDrawClipper(IDirectDrawClipper *iface)
-{
-    struct ddraw_clipper *clipper;
-
-    if (!iface)
-        return NULL;
-
-    clipper = impl_from_IDirectDrawClipper(iface);
-
-    if (!clipper || iface->lpVtbl != &ddraw_clipper_vtbl)
-        WARN("The application passed us a bad clipper object.\n");
-
-    return clipper;
-}
diff --git a/dlls/ddraw/ddraw_private.h b/dlls/ddraw/ddraw_private.h
index 4a3d3027249..7fb41d50e99 100644
--- a/dlls/ddraw/ddraw_private.h
+++ b/dlls/ddraw/ddraw_private.h
@@ -193,7 +193,7 @@ struct ddraw_surface
     DDSURFACEDESC2          surface_desc;
 
     /* Clipper objects */
-    struct ddraw_clipper *clipper;
+    IDirectDrawClipper   *clipper;
     struct ddraw_palette *palette;
 
     /* For the ddraw surface list */
@@ -391,7 +391,6 @@ struct ddraw_clipper
 };
 
 HRESULT ddraw_clipper_init(struct ddraw_clipper *clipper) DECLSPEC_HIDDEN;
-struct ddraw_clipper *unsafe_impl_from_IDirectDrawClipper(IDirectDrawClipper *iface) DECLSPEC_HIDDEN;
 
 /* Invoke clipper methods directly instead of going through the vtable. Clipper methods have
  * protections against invalid clipper objects, but that won't work if we crash when reading
diff --git a/dlls/ddraw/surface.c b/dlls/ddraw/surface.c
index 2a5404f03fd..e0214778bfe 100644
--- a/dlls/ddraw/surface.c
+++ b/dlls/ddraw/surface.c
@@ -1552,8 +1552,7 @@ static HRESULT ddraw_surface_blt_clipped(struct ddraw_surface *dst_surface, cons
     scale_x = (float)(src_rect.right - src_rect.left) / (float)(dst_rect.right - dst_rect.left);
     scale_y = (float)(src_rect.bottom - src_rect.top) / (float)(dst_rect.bottom - dst_rect.top);
 
-    if (FAILED(hr = ddraw_clipper_GetClipList(&dst_surface->clipper->IDirectDrawClipper_iface,
-            &dst_rect, NULL, &clip_list_size)))
+    if (FAILED(hr = ddraw_clipper_GetClipList(dst_surface->clipper, &dst_rect, NULL, &clip_list_size)))
     {
         WARN("Failed to get clip list size, hr %#x.\n", hr);
         return hr;
@@ -1565,8 +1564,7 @@ static HRESULT ddraw_surface_blt_clipped(struct ddraw_surface *dst_surface, cons
         return E_OUTOFMEMORY;
     }
 
-    if (FAILED(hr = ddraw_clipper_GetClipList(&dst_surface->clipper->IDirectDrawClipper_iface,
-            &dst_rect, clip_list, &clip_list_size)))
+    if (FAILED(hr = ddraw_clipper_GetClipList(dst_surface->clipper, &dst_rect, clip_list, &clip_list_size)))
     {
         WARN("Failed to get clip list, hr %#x.\n", hr);
         heap_free(clip_list);
@@ -4440,7 +4438,7 @@ static HRESULT WINAPI ddraw_surface7_GetClipper(IDirectDrawSurface7 *iface, IDir
         return DDERR_NOCLIPPERATTACHED;
     }
 
-    *Clipper = &surface->clipper->IDirectDrawClipper_iface;
+    *Clipper = surface->clipper;
     ddraw_clipper_AddRef(*Clipper);
     wined3d_mutex_unlock();
 
@@ -4496,14 +4494,13 @@ static HRESULT WINAPI ddraw_surface1_GetClipper(IDirectDrawSurface *iface, IDire
  *
  *****************************************************************************/
 static HRESULT WINAPI ddraw_surface7_SetClipper(IDirectDrawSurface7 *iface,
-        IDirectDrawClipper *iclipper)
+        IDirectDrawClipper *clipper)
 {
     struct ddraw_surface *This = impl_from_IDirectDrawSurface7(iface);
-    struct ddraw_clipper *clipper = unsafe_impl_from_IDirectDrawClipper(iclipper);
-    struct ddraw_clipper *old_clipper = This->clipper;
+    IDirectDrawClipper *old_clipper = This->clipper;
     HWND clipWindow;
 
-    TRACE("iface %p, clipper %p.\n", iface, iclipper);
+    TRACE("iface %p, clipper %p.\n", iface, clipper);
 
     wined3d_mutex_lock();
     if (clipper == This->clipper)
@@ -4514,16 +4511,15 @@ static HRESULT WINAPI ddraw_surface7_SetClipper(IDirectDrawSurface7 *iface,
 
     This->clipper = clipper;
 
-    if (clipper != NULL)
-        ddraw_clipper_AddRef(iclipper);
+    if (clipper)
+        ddraw_clipper_AddRef(clipper);
     if (old_clipper)
-        ddraw_clipper_Release(&old_clipper->IDirectDrawClipper_iface);
+        ddraw_clipper_Release(old_clipper);
 
     if ((This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) && This->ddraw->wined3d_swapchain)
     {
         clipWindow = NULL;
-        if (clipper)
-            ddraw_clipper_GetHWnd(iclipper, &clipWindow);
+        ddraw_clipper_GetHWnd(clipper, &clipWindow);
 
         if (clipWindow)
         {
@@ -5797,7 +5793,7 @@ static void STDMETHODCALLTYPE ddraw_surface_wined3d_object_destroyed(void *paren
     list_remove(&surface->surface_list_entry);
 
     if (surface->clipper)
-        ddraw_clipper_Release(&surface->clipper->IDirectDrawClipper_iface);
+        ddraw_clipper_Release(surface->clipper);
 
     if (surface == surface->ddraw->primary)
     {
-- 
2.19.2




More information about the wine-devel mailing list