ddraw: Always store a pointer to the wined3d texture in the surface.
authorHenri Verbeet <hverbeet@codeweavers.com>
Thu, 28 Jan 2016 17:40:24 +0000 (18:40 +0100)
committerAlexandre Julliard <julliard@winehq.org>
Fri, 29 Jan 2016 12:25:15 +0000 (21:25 +0900)
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
dlls/ddraw/ddraw.c
dlls/ddraw/ddraw_private.h
dlls/ddraw/surface.c

index f17bb64b26ffa78af100b1aa755bec70e43735d2..a3c9465d8440451cd9971ecf1b92e0e8024fc9c5 100644 (file)
@@ -4765,7 +4765,7 @@ static HRESULT CDECL device_parent_surface_created(struct wined3d_device_parent
         return DDERR_OUTOFVIDEOMEMORY;
     }
 
-    ddraw_surface_init(ddraw_surface, ddraw, wined3d_texture_get_parent(wined3d_texture), surface, parent_ops);
+    ddraw_surface_init(ddraw_surface, ddraw, wined3d_texture, surface, parent_ops);
     *parent = ddraw_surface;
 
     ddraw_update_lost_surfaces(ddraw);
index 38139f8b0eee55a11e3908753be276079b1ee394..1966a3e93df06b7b781c91192aa88edada8d9edc 100644 (file)
@@ -209,7 +209,7 @@ struct ddraw_texture
 HRESULT ddraw_surface_create(struct ddraw *ddraw, const DDSURFACEDESC2 *surface_desc,
         struct ddraw_surface **surface, IUnknown *outer_unknown, unsigned int version) DECLSPEC_HIDDEN;
 struct wined3d_rendertarget_view *ddraw_surface_get_rendertarget_view(struct ddraw_surface *surface) DECLSPEC_HIDDEN;
-void ddraw_surface_init(struct ddraw_surface *surface, struct ddraw *ddraw, struct ddraw_texture *texture,
+void ddraw_surface_init(struct ddraw_surface *surface, struct ddraw *ddraw, struct wined3d_texture *wined3d_texture,
         struct wined3d_surface *wined3d_surface, const struct wined3d_parent_ops **parent_ops) DECLSPEC_HIDDEN;
 ULONG ddraw_surface_release_iface(struct ddraw_surface *This) DECLSPEC_HIDDEN;
 HRESULT ddraw_surface_update_frontbuffer(struct ddraw_surface *surface,
index baf6201277ccac36c79d80f8074790f14936076b..4e8f547c67fbebe4118c61dc98d3044a4e13df20 100644 (file)
@@ -323,10 +323,7 @@ static void ddraw_surface_add_iface(struct ddraw_surface *surface)
         wined3d_mutex_lock();
         if (surface->wined3d_rtv)
             wined3d_rendertarget_view_incref(surface->wined3d_rtv);
-        if (surface->wined3d_surface)
-            wined3d_surface_incref(surface->wined3d_surface);
-        if (surface->wined3d_texture)
-            wined3d_texture_incref(surface->wined3d_texture);
+        wined3d_texture_incref(surface->wined3d_texture);
         wined3d_mutex_unlock();
     }
 }
@@ -529,10 +526,7 @@ static void ddraw_surface_cleanup(struct ddraw_surface *surface)
 
     if (surface->wined3d_rtv)
         wined3d_rendertarget_view_decref(surface->wined3d_rtv);
-    if (surface->wined3d_texture)
-        wined3d_texture_decref(surface->wined3d_texture);
-    if (surface->wined3d_surface)
-        wined3d_surface_decref(surface->wined3d_surface);
+    wined3d_texture_decref(surface->wined3d_texture);
 }
 
 ULONG ddraw_surface_release_iface(struct ddraw_surface *This)
@@ -4027,13 +4021,6 @@ static HRESULT WINAPI ddraw_surface7_SetLOD(IDirectDrawSurface7 *iface, DWORD Ma
         return DDERR_INVALIDOBJECT;
     }
 
-    if (!surface->wined3d_texture)
-    {
-        ERR("The ddraw surface has no wined3d texture.\n");
-        wined3d_mutex_unlock();
-        return DDERR_INVALIDOBJECT;
-    }
-
     hr = wined3d_texture_set_lod(surface->wined3d_texture, MaxLOD);
     wined3d_mutex_unlock();
 
@@ -4697,7 +4684,7 @@ static HRESULT ddraw_surface_set_color_key(struct ddraw_surface *surface, DWORD
         }
     }
 
-    if (surface->wined3d_texture)
+    if (surface->is_complex_root)
         hr = wined3d_texture_set_color_key(surface->wined3d_texture, flags,
                 color_key ? (struct wined3d_color_key *)&fixed_color_key : NULL);
 
@@ -6076,7 +6063,7 @@ HRESULT ddraw_surface_create(struct ddraw *ddraw, const DDSURFACEDESC2 *surface_
 
     resource = wined3d_texture_get_sub_resource(wined3d_texture, 0);
     root = wined3d_resource_get_parent(resource);
-    root->wined3d_texture = wined3d_texture;
+    wined3d_texture_decref(wined3d_texture);
     root->is_complex_root = TRUE;
     texture->root = root;
 
@@ -6189,7 +6176,7 @@ HRESULT ddraw_surface_create(struct ddraw *ddraw, const DDSURFACEDESC2 *surface_
 
             resource = wined3d_texture_get_sub_resource(wined3d_texture, 0);
             last = wined3d_resource_get_parent(resource);
-            last->wined3d_texture = wined3d_texture;
+            wined3d_texture_decref(wined3d_texture);
             texture->root = last;
 
             if (desc->dwFlags & DDSD_CKDESTOVERLAY)
@@ -6228,9 +6215,10 @@ fail:
     return hr;
 }
 
-void ddraw_surface_init(struct ddraw_surface *surface, struct ddraw *ddraw, struct ddraw_texture *texture,
+void ddraw_surface_init(struct ddraw_surface *surface, struct ddraw *ddraw, struct wined3d_texture *wined3d_texture,
         struct wined3d_surface *wined3d_surface, const struct wined3d_parent_ops **parent_ops)
 {
+    struct ddraw_texture *texture = wined3d_texture_get_parent(wined3d_texture);
     DDSURFACEDESC2 *desc = &surface->surface_desc;
     struct wined3d_resource_desc wined3d_desc;
     unsigned int version = texture->version;
@@ -6287,8 +6275,8 @@ void ddraw_surface_init(struct ddraw_surface *surface, struct ddraw *ddraw, stru
     }
     desc->lpSurface = NULL;
 
-    wined3d_surface_incref(wined3d_surface);
     surface->wined3d_surface = wined3d_surface;
+    wined3d_texture_incref(surface->wined3d_texture = wined3d_texture);
     *parent_ops = &ddraw_surface_wined3d_parent_ops;
 
     wined3d_private_store_init(&surface->private_store);