diff --git a/dlls/d3d8/device.c b/dlls/d3d8/device.c index 82001194313..336a07cecfd 100644 --- a/dlls/d3d8/device.c +++ b/dlls/d3d8/device.c @@ -724,25 +724,38 @@ static HRESULT WINAPI d3d8_device_GetBackBuffer(IDirect3DDevice8 *iface, UINT backbuffer_idx, D3DBACKBUFFER_TYPE backbuffer_type, IDirect3DSurface8 **backbuffer) { struct d3d8_device *device = impl_from_IDirect3DDevice8(iface); - struct wined3d_surface *wined3d_surface = NULL; + struct wined3d_swapchain *swapchain; + struct wined3d_resource *wined3d_resource; + struct wined3d_texture *wined3d_texture; struct d3d8_surface *surface_impl; - HRESULT hr; TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n", iface, backbuffer_idx, backbuffer_type, backbuffer); + /* No need to check for backbuffer == NULL, Windows crashes in that case. */ wined3d_mutex_lock(); - hr = wined3d_device_get_back_buffer(device->wined3d_device, 0, backbuffer_idx, - (enum wined3d_backbuffer_type)backbuffer_type, &wined3d_surface); - if (SUCCEEDED(hr) && wined3d_surface && backbuffer) + if (!(swapchain = wined3d_device_get_swapchain(device->wined3d_device, 0))) { - surface_impl = wined3d_surface_get_parent(wined3d_surface); - *backbuffer = &surface_impl->IDirect3DSurface8_iface; - IDirect3DSurface8_AddRef(*backbuffer); + wined3d_mutex_unlock(); + *backbuffer = NULL; + return D3DERR_INVALIDCALL; } - wined3d_mutex_unlock(); - return hr; + if (!(wined3d_texture = wined3d_swapchain_get_back_buffer(swapchain, + backbuffer_idx, (enum wined3d_backbuffer_type)backbuffer_type))) + { + wined3d_mutex_unlock(); + *backbuffer = NULL; + return D3DERR_INVALIDCALL; + } + + wined3d_resource = wined3d_texture_get_sub_resource(wined3d_texture, 0); + surface_impl = wined3d_resource_get_parent(wined3d_resource); + *backbuffer = &surface_impl->IDirect3DSurface8_iface; + IDirect3DSurface8_AddRef(*backbuffer); + + wined3d_mutex_unlock(); + return D3D_OK; } static HRESULT WINAPI d3d8_device_GetRasterStatus(IDirect3DDevice8 *iface, D3DRASTER_STATUS *raster_status) diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c index 95d1e02910a..5640bdd3ff6 100644 --- a/dlls/d3d9/device.c +++ b/dlls/d3d9/device.c @@ -746,26 +746,41 @@ static HRESULT WINAPI d3d9_device_GetBackBuffer(IDirect3DDevice9Ex *iface, UINT UINT backbuffer_idx, D3DBACKBUFFER_TYPE backbuffer_type, IDirect3DSurface9 **backbuffer) { struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface); - struct wined3d_surface *wined3d_surface = NULL; + struct wined3d_swapchain *wined3d_swapchain; + struct wined3d_resource *wined3d_resource; + struct wined3d_texture *wined3d_texture; struct d3d9_surface *surface_impl; - HRESULT hr; TRACE("iface %p, swapchain %u, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n", iface, swapchain, backbuffer_idx, backbuffer_type, backbuffer); + /* No need to check for backbuffer == NULL, Windows crashes in that case. */ wined3d_mutex_lock(); - hr = wined3d_device_get_back_buffer(device->wined3d_device, swapchain, - backbuffer_idx, (enum wined3d_backbuffer_type)backbuffer_type, &wined3d_surface); - if (SUCCEEDED(hr) && wined3d_surface && backbuffer) - { - surface_impl = wined3d_surface_get_parent(wined3d_surface); - *backbuffer = &surface_impl->IDirect3DSurface9_iface; - IDirect3DSurface9_AddRef(*backbuffer); - } - wined3d_mutex_unlock(); - return hr; + if (!(wined3d_swapchain = wined3d_device_get_swapchain(device->wined3d_device, swapchain))) + { + wined3d_mutex_unlock(); + *backbuffer = NULL; + return D3DERR_INVALIDCALL; + } + + if (!(wined3d_texture = wined3d_swapchain_get_back_buffer(wined3d_swapchain, + backbuffer_idx, (enum wined3d_backbuffer_type)backbuffer_type))) + { + wined3d_mutex_unlock(); + *backbuffer = NULL; + return D3DERR_INVALIDCALL; + } + + wined3d_resource = wined3d_texture_get_sub_resource(wined3d_texture, 0); + surface_impl = wined3d_resource_get_parent(wined3d_resource); + *backbuffer = &surface_impl->IDirect3DSurface9_iface; + IDirect3DSurface9_AddRef(*backbuffer); + + wined3d_mutex_unlock(); + return D3D_OK; } + static HRESULT WINAPI d3d9_device_GetRasterStatus(IDirect3DDevice9Ex *iface, UINT swapchain, D3DRASTER_STATUS *raster_status) { diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index dcc5d378a9d..765af0d93e2 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -3183,26 +3183,6 @@ struct wined3d_texture * CDECL wined3d_device_get_texture(const struct wined3d_d return device->state.textures[stage]; } -HRESULT CDECL wined3d_device_get_back_buffer(const struct wined3d_device *device, UINT swapchain_idx, - UINT backbuffer_idx, enum wined3d_backbuffer_type backbuffer_type, struct wined3d_surface **backbuffer) -{ - struct wined3d_texture *texture; - struct wined3d_resource *resource; - struct wined3d_swapchain *swapchain; - - TRACE("device %p, swapchain_idx %u, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n", - device, swapchain_idx, backbuffer_idx, backbuffer_type, backbuffer); - - if (!(swapchain = wined3d_device_get_swapchain(device, swapchain_idx))) - return WINED3DERR_INVALIDCALL; - - if (!(texture = wined3d_swapchain_get_back_buffer(swapchain, backbuffer_idx, backbuffer_type))) - return WINED3DERR_INVALIDCALL; - resource = wined3d_texture_get_sub_resource(texture, 0); - *backbuffer = wined3d_surface_from_resource(resource); - return WINED3D_OK; -} - HRESULT CDECL wined3d_device_get_device_caps(const struct wined3d_device *device, WINED3DCAPS *caps) { TRACE("device %p, caps %p.\n", device, caps); diff --git a/dlls/wined3d/wined3d.spec b/dlls/wined3d/wined3d.spec index 4710f51d1fa..9f714ef4d0c 100644 --- a/dlls/wined3d/wined3d.spec +++ b/dlls/wined3d/wined3d.spec @@ -49,7 +49,6 @@ @ cdecl wined3d_device_end_stateblock(ptr ptr) @ cdecl wined3d_device_evict_managed_resources(ptr) @ cdecl wined3d_device_get_available_texture_mem(ptr) -@ cdecl wined3d_device_get_back_buffer(ptr long long long ptr) @ cdecl wined3d_device_get_base_vertex_index(ptr) @ cdecl wined3d_device_get_clip_plane(ptr long ptr) @ cdecl wined3d_device_get_clip_status(ptr ptr) diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h index 41384b57353..72a41b2896f 100644 --- a/include/wine/wined3d.h +++ b/include/wine/wined3d.h @@ -2154,8 +2154,6 @@ HRESULT __cdecl wined3d_device_end_scene(struct wined3d_device *device); HRESULT __cdecl wined3d_device_end_stateblock(struct wined3d_device *device, struct wined3d_stateblock **stateblock); void __cdecl wined3d_device_evict_managed_resources(struct wined3d_device *device); UINT __cdecl wined3d_device_get_available_texture_mem(const struct wined3d_device *device); -HRESULT __cdecl wined3d_device_get_back_buffer(const struct wined3d_device *device, UINT swapchain_idx, - UINT backbuffer_idx, enum wined3d_backbuffer_type backbuffer_type, struct wined3d_surface **backbuffer); INT __cdecl wined3d_device_get_base_vertex_index(const struct wined3d_device *device); HRESULT __cdecl wined3d_device_get_clip_plane(const struct wined3d_device *device, UINT plane_idx, struct wined3d_vec4 *plane);