[PATCH 3/5] wined3d: Just return the surface from wined3d_device_get_render_target().

Henri Verbeet hverbeet at codeweavers.com
Mon Oct 1 04:05:21 CDT 2012


---
 dlls/d3d8/device.c        |   14 ++++++--------
 dlls/d3d9/device.c        |    9 +++------
 dlls/ddraw/ddraw.c        |    9 ++++-----
 dlls/wined3d/device.c     |   19 +++++--------------
 dlls/wined3d/wined3d.spec |    2 +-
 include/wine/wined3d.h    |    4 ++--
 6 files changed, 21 insertions(+), 36 deletions(-)

diff --git a/dlls/d3d8/device.c b/dlls/d3d8/device.c
index f892138..22280cd 100644
--- a/dlls/d3d8/device.c
+++ b/dlls/d3d8/device.c
@@ -1100,14 +1100,12 @@ static HRESULT WINAPI d3d8_device_SetRenderTarget(IDirect3DDevice8 *iface,
         /* If no render target is passed in check the size against the current RT */
         if (!render_target)
         {
-            hr = wined3d_device_get_render_target(device->wined3d_device, 0, &original_rt);
-            if (FAILED(hr) || !original_rt)
+            if (!(original_rt = wined3d_device_get_render_target(device->wined3d_device, 0)))
             {
                 wined3d_mutex_unlock();
-                return hr;
+                return D3DERR_NOTFOUND;
             }
             wined3d_resource = wined3d_surface_get_resource(original_rt);
-            wined3d_surface_decref(original_rt);
         }
         else
             wined3d_resource = wined3d_surface_get_resource(rt_impl->wined3d_surface);
@@ -1156,18 +1154,18 @@ static HRESULT WINAPI d3d8_device_GetRenderTarget(IDirect3DDevice8 *iface, IDire
         return D3DERR_INVALIDCALL;
 
     wined3d_mutex_lock();
-    hr = wined3d_device_get_render_target(device->wined3d_device, 0, &wined3d_surface);
-    if (SUCCEEDED(hr) && wined3d_surface)
+    if ((wined3d_surface = wined3d_device_get_render_target(device->wined3d_device, 0)))
     {
         surface_impl = wined3d_surface_get_parent(wined3d_surface);
         *render_target = &surface_impl->IDirect3DSurface8_iface;
         IDirect3DSurface8_AddRef(*render_target);
-        wined3d_surface_decref(wined3d_surface);
+        hr = D3D_OK;
     }
     else
     {
-        ERR("Failed to get wined3d render target, hr %#x.\n", hr);
+        ERR("Failed to get wined3d render target.\n");
         *render_target = NULL;
+        hr = D3DERR_NOTFOUND;
     }
     wined3d_mutex_unlock();
 
diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c
index cd7e001..68ab0a4 100644
--- a/dlls/d3d9/device.c
+++ b/dlls/d3d9/device.c
@@ -1190,7 +1190,7 @@ static HRESULT WINAPI d3d9_device_GetRenderTarget(IDirect3DDevice9Ex *iface, DWO
     struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
     struct wined3d_surface *wined3d_surface;
     struct d3d9_surface *surface_impl;
-    HRESULT hr;
+    HRESULT hr = D3D_OK;
 
     TRACE("iface %p, idx %u, surface %p.\n", iface, idx, surface);
 
@@ -1204,18 +1204,15 @@ static HRESULT WINAPI d3d9_device_GetRenderTarget(IDirect3DDevice9Ex *iface, DWO
     }
 
     wined3d_mutex_lock();
-    hr = wined3d_device_get_render_target(device->wined3d_device, idx, &wined3d_surface);
-    if (SUCCEEDED(hr))
+    if ((wined3d_surface = wined3d_device_get_render_target(device->wined3d_device, idx)))
     {
         surface_impl = wined3d_surface_get_parent(wined3d_surface);
         *surface = &surface_impl->IDirect3DSurface9_iface;
         IDirect3DSurface9_AddRef(*surface);
-        wined3d_surface_decref(wined3d_surface);
     }
     else
     {
-        if (hr != WINED3DERR_NOTFOUND)
-            WARN("Failed to get render target %u, hr %#x.\n", idx, hr);
+        hr = WINED3DERR_NOTFOUND;
         *surface = NULL;
     }
     wined3d_mutex_unlock();
diff --git a/dlls/ddraw/ddraw.c b/dlls/ddraw/ddraw.c
index 0230b5d..b352705 100644
--- a/dlls/ddraw/ddraw.c
+++ b/dlls/ddraw/ddraw.c
@@ -754,8 +754,8 @@ static HRESULT ddraw_create_swapchain(struct ddraw *ddraw, HWND window, BOOL win
 static HRESULT WINAPI ddraw7_SetCooperativeLevel(IDirectDraw7 *iface, HWND hwnd, DWORD cooplevel)
 {
     struct ddraw *This = impl_from_IDirectDraw7(iface);
+    struct wined3d_surface *rt = NULL, *ds;
     struct wined3d_stateblock *stateblock;
-    struct wined3d_surface *rt, *ds;
     BOOL restore_state = FALSE;
     HWND window;
     HRESULT hr;
@@ -932,12 +932,11 @@ static HRESULT WINAPI ddraw7_SetCooperativeLevel(IDirectDraw7 *iface, HWND hwnd,
                 return hr;
             }
 
-            wined3d_device_get_render_target(This->wined3d_device, 0, &rt);
+            rt = wined3d_device_get_render_target(This->wined3d_device, 0);
             if (rt == This->wined3d_frontbuffer)
-            {
-                wined3d_surface_decref(rt);
                 rt = NULL;
-            }
+            else if (rt)
+                wined3d_surface_incref(rt);
 
             wined3d_device_get_depth_stencil(This->wined3d_device, &ds);
         }
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index 916a648..29fb124 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -4479,27 +4479,18 @@ void CDECL wined3d_device_clear_rendertarget_view(struct wined3d_device *device,
     if (FAILED(hr)) ERR("Color fill failed, hr %#x.\n", hr);
 }
 
-HRESULT CDECL wined3d_device_get_render_target(const struct wined3d_device *device,
-        UINT render_target_idx, struct wined3d_surface **render_target)
+struct wined3d_surface * CDECL wined3d_device_get_render_target(const struct wined3d_device *device,
+        UINT render_target_idx)
 {
-    TRACE("device %p, render_target_idx %u, render_target %p.\n",
-            device, render_target_idx, render_target);
+    TRACE("device %p, render_target_idx %u.\n", device, render_target_idx);
 
     if (render_target_idx >= device->adapter->gl_info.limits.buffers)
     {
         WARN("Only %u render targets are supported.\n", device->adapter->gl_info.limits.buffers);
-        return WINED3DERR_INVALIDCALL;
+        return NULL;
     }
 
-    *render_target = device->fb.render_targets[render_target_idx];
-    TRACE("Returning render target %p.\n", *render_target);
-
-    if (!*render_target)
-        return WINED3DERR_NOTFOUND;
-
-    wined3d_surface_incref(*render_target);
-
-    return WINED3D_OK;
+    return device->fb.render_targets[render_target_idx];
 }
 
 HRESULT CDECL wined3d_device_get_depth_stencil(const struct wined3d_device *device,
diff --git a/dlls/wined3d/wined3d.spec b/dlls/wined3d/wined3d.spec
index 7971552..55bd32a 100644
--- a/dlls/wined3d/wined3d.spec
+++ b/dlls/wined3d/wined3d.spec
@@ -76,7 +76,7 @@
 @ cdecl wined3d_device_get_ps_consts_i(ptr long ptr long)
 @ cdecl wined3d_device_get_raster_status(ptr long ptr)
 @ cdecl wined3d_device_get_render_state(ptr long)
-@ cdecl wined3d_device_get_render_target(ptr long ptr)
+@ cdecl wined3d_device_get_render_target(ptr long)
 @ cdecl wined3d_device_get_sampler_state(ptr long long)
 @ cdecl wined3d_device_get_scissor_rect(ptr ptr)
 @ cdecl wined3d_device_get_software_vertex_processing(ptr)
diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h
index 40dfda8..a630e49 100644
--- a/include/wine/wined3d.h
+++ b/include/wine/wined3d.h
@@ -2143,8 +2143,8 @@ HRESULT __cdecl wined3d_device_get_ps_consts_i(const struct wined3d_device *devi
 HRESULT __cdecl wined3d_device_get_raster_status(const struct wined3d_device *device,
         UINT swapchain_idx, struct wined3d_raster_status *raster_status);
 DWORD __cdecl wined3d_device_get_render_state(const struct wined3d_device *device, enum wined3d_render_state state);
-HRESULT __cdecl wined3d_device_get_render_target(const struct wined3d_device *device,
-        UINT render_target_idx, struct wined3d_surface **render_target);
+struct wined3d_surface * __cdecl wined3d_device_get_render_target(const struct wined3d_device *device,
+        UINT render_target_idx);
 DWORD __cdecl wined3d_device_get_sampler_state(const struct wined3d_device *device,
         UINT sampler_idx, enum wined3d_sampler_state state);
 void __cdecl wined3d_device_get_scissor_rect(const struct wined3d_device *device, RECT *rect);
-- 
1.7.8.6




More information about the wine-patches mailing list