diff --git a/dlls/d3d8/device.c b/dlls/d3d8/device.c index 22280cd58dd..751ba0557e5 100644 --- a/dlls/d3d8/device.c +++ b/dlls/d3d8/device.c @@ -1122,19 +1122,14 @@ static HRESULT WINAPI d3d8_device_SetRenderTarget(IDirect3DDevice8 *iface, } } - hr = wined3d_device_get_depth_stencil(device->wined3d_device, &original_ds); - if (hr == WINED3D_OK || hr == WINED3DERR_NOTFOUND) + original_ds = wined3d_device_get_depth_stencil(device->wined3d_device); + hr = wined3d_device_set_depth_stencil(device->wined3d_device, ds_impl ? ds_impl->wined3d_surface : NULL); + if (SUCCEEDED(hr) && render_target) { - hr = wined3d_device_set_depth_stencil(device->wined3d_device, ds_impl ? ds_impl->wined3d_surface : NULL); - if (SUCCEEDED(hr) && render_target) - { - hr = wined3d_device_set_render_target(device->wined3d_device, 0, rt_impl->wined3d_surface, TRUE); - if (FAILED(hr)) - wined3d_device_set_depth_stencil(device->wined3d_device, original_ds); - } + hr = wined3d_device_set_render_target(device->wined3d_device, 0, rt_impl->wined3d_surface, TRUE); + if (FAILED(hr)) + wined3d_device_set_depth_stencil(device->wined3d_device, original_ds); } - if (original_ds) - wined3d_surface_decref(original_ds); wined3d_mutex_unlock(); @@ -1177,7 +1172,7 @@ static HRESULT WINAPI d3d8_device_GetDepthStencilSurface(IDirect3DDevice8 *iface struct d3d8_device *device = impl_from_IDirect3DDevice8(iface); struct wined3d_surface *wined3d_surface; struct d3d8_surface *surface_impl; - HRESULT hr; + HRESULT hr = D3D_OK; TRACE("iface %p, depth_stencil %p.\n", iface, depth_stencil); @@ -1185,18 +1180,15 @@ static HRESULT WINAPI d3d8_device_GetDepthStencilSurface(IDirect3DDevice8 *iface return D3DERR_INVALIDCALL; wined3d_mutex_lock(); - hr = wined3d_device_get_depth_stencil(device->wined3d_device, &wined3d_surface); - if (SUCCEEDED(hr)) + if ((wined3d_surface = wined3d_device_get_depth_stencil(device->wined3d_device))) { surface_impl = wined3d_surface_get_parent(wined3d_surface); *depth_stencil = &surface_impl->IDirect3DSurface8_iface; IDirect3DSurface8_AddRef(*depth_stencil); - wined3d_surface_decref(wined3d_surface); } else { - if (hr != WINED3DERR_NOTFOUND) - ERR("Failed to get wined3d depth stencil, hr %#x.\n", hr); + hr = WINED3DERR_NOTFOUND; *depth_stencil = NULL; } wined3d_mutex_unlock(); diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c index 68ab0a4dc08..af2a92fcae3 100644 --- a/dlls/d3d9/device.c +++ b/dlls/d3d9/device.c @@ -1240,7 +1240,7 @@ static HRESULT WINAPI d3d9_device_GetDepthStencilSurface(IDirect3DDevice9Ex *ifa 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, depth_stencil %p.\n", iface, depth_stencil); @@ -1248,18 +1248,15 @@ static HRESULT WINAPI d3d9_device_GetDepthStencilSurface(IDirect3DDevice9Ex *ifa return D3DERR_INVALIDCALL; wined3d_mutex_lock(); - hr = wined3d_device_get_depth_stencil(device->wined3d_device, &wined3d_surface); - if (SUCCEEDED(hr)) + if ((wined3d_surface = wined3d_device_get_depth_stencil(device->wined3d_device))) { surface_impl = wined3d_surface_get_parent(wined3d_surface); *depth_stencil = &surface_impl->IDirect3DSurface9_iface; IDirect3DSurface9_AddRef(*depth_stencil); - wined3d_surface_decref(wined3d_surface); } else { - if (hr != WINED3DERR_NOTFOUND) - WARN("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr); + hr = WINED3DERR_NOTFOUND; *depth_stencil = NULL; } wined3d_mutex_unlock(); diff --git a/dlls/ddraw/ddraw.c b/dlls/ddraw/ddraw.c index b352705b13d..1530685b431 100644 --- a/dlls/ddraw/ddraw.c +++ b/dlls/ddraw/ddraw.c @@ -754,7 +754,7 @@ 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_surface *rt = NULL, *ds = NULL; struct wined3d_stateblock *stateblock; BOOL restore_state = FALSE; HWND window; @@ -938,7 +938,8 @@ static HRESULT WINAPI ddraw7_SetCooperativeLevel(IDirectDraw7 *iface, HWND hwnd, else if (rt) wined3d_surface_incref(rt); - wined3d_device_get_depth_stencil(This->wined3d_device, &ds); + if ((ds = wined3d_device_get_depth_stencil(This->wined3d_device))) + wined3d_surface_incref(ds); } ddraw_destroy_swapchain(This); diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 29fb12417ad..6927f9fcd80 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -4493,20 +4493,11 @@ struct wined3d_surface * CDECL wined3d_device_get_render_target(const struct win return device->fb.render_targets[render_target_idx]; } -HRESULT CDECL wined3d_device_get_depth_stencil(const struct wined3d_device *device, - struct wined3d_surface **depth_stencil) +struct wined3d_surface * CDECL wined3d_device_get_depth_stencil(const struct wined3d_device *device) { - TRACE("device %p, depth_stencil %p.\n", device, depth_stencil); + TRACE("device %p.\n", device); - *depth_stencil = device->fb.depth_stencil; - TRACE("Returning depth/stencil surface %p.\n", *depth_stencil); - - if (!*depth_stencil) - return WINED3DERR_NOTFOUND; - - wined3d_surface_incref(*depth_stencil); - - return WINED3D_OK; + return device->fb.depth_stencil; } HRESULT CDECL wined3d_device_set_render_target(struct wined3d_device *device, diff --git a/dlls/wined3d/wined3d.spec b/dlls/wined3d/wined3d.spec index 55bd32ae97d..a8857464de8 100644 --- a/dlls/wined3d/wined3d.spec +++ b/dlls/wined3d/wined3d.spec @@ -59,7 +59,7 @@ @ cdecl wined3d_device_get_clip_plane(ptr long ptr) @ cdecl wined3d_device_get_clip_status(ptr ptr) @ cdecl wined3d_device_get_creation_parameters(ptr ptr) -@ cdecl wined3d_device_get_depth_stencil(ptr ptr) +@ cdecl wined3d_device_get_depth_stencil(ptr) @ cdecl wined3d_device_get_device_caps(ptr ptr) @ cdecl wined3d_device_get_display_mode(ptr long ptr ptr) @ cdecl wined3d_device_get_front_buffer_data(ptr long ptr) diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h index a630e49c430..d527949a462 100644 --- a/include/wine/wined3d.h +++ b/include/wine/wined3d.h @@ -2116,8 +2116,7 @@ HRESULT __cdecl wined3d_device_get_clip_status(const struct wined3d_device *devi struct wined3d_clip_status *clip_status); HRESULT __cdecl wined3d_device_get_creation_parameters(const struct wined3d_device *device, struct wined3d_device_creation_parameters *creation_parameters); -HRESULT __cdecl wined3d_device_get_depth_stencil(const struct wined3d_device *device, - struct wined3d_surface **depth_stencil); +struct wined3d_surface * __cdecl wined3d_device_get_depth_stencil(const struct wined3d_device *device); HRESULT __cdecl wined3d_device_get_device_caps(const struct wined3d_device *device, WINED3DCAPS *caps); HRESULT __cdecl wined3d_device_get_display_mode(const struct wined3d_device *device, UINT swapchain_idx, struct wined3d_display_mode *mode, enum wined3d_display_rotation *rotation);