Commit 5fcc1f8f authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Just return the surface from wined3d_swapchain_get_back_buffer().

parent 272f6326
......@@ -647,7 +647,6 @@ static HRESULT WINAPI d3d8_device_GetBackBuffer(IDirect3DDevice8 *iface,
surface_impl = wined3d_surface_get_parent(wined3d_surface);
*backbuffer = &surface_impl->IDirect3DSurface8_iface;
IDirect3DSurface8_AddRef(*backbuffer);
wined3d_surface_decref(wined3d_surface);
}
wined3d_mutex_unlock();
......
......@@ -110,20 +110,22 @@ static HRESULT WINAPI d3d8_swapchain_GetBackBuffer(IDirect3DSwapChain8 *iface,
struct d3d8_swapchain *swapchain = impl_from_IDirect3DSwapChain8(iface);
struct wined3d_surface *wined3d_surface = NULL;
struct d3d8_surface *surface_impl;
HRESULT hr;
HRESULT hr = D3D_OK;
TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
iface, backbuffer_idx, backbuffer_type, backbuffer);
wined3d_mutex_lock();
hr = wined3d_swapchain_get_back_buffer(swapchain->wined3d_swapchain,
backbuffer_idx, (enum wined3d_backbuffer_type)backbuffer_type, &wined3d_surface);
if (SUCCEEDED(hr) && wined3d_surface)
if ((wined3d_surface = wined3d_swapchain_get_back_buffer(swapchain->wined3d_swapchain,
backbuffer_idx, (enum wined3d_backbuffer_type)backbuffer_type)))
{
surface_impl = wined3d_surface_get_parent(wined3d_surface);
*backbuffer = &surface_impl->IDirect3DSurface8_iface;
IDirect3DSurface8_AddRef(*backbuffer);
wined3d_surface_decref(wined3d_surface);
}
else
{
hr = D3DERR_INVALIDCALL;
}
wined3d_mutex_unlock();
......
......@@ -628,7 +628,6 @@ static HRESULT WINAPI d3d9_device_GetBackBuffer(IDirect3DDevice9Ex *iface, UINT
surface_impl = wined3d_surface_get_parent(wined3d_surface);
*backbuffer = &surface_impl->IDirect3DSurface9_iface;
IDirect3DSurface9_AddRef(*backbuffer);
wined3d_surface_decref(wined3d_surface);
}
wined3d_mutex_unlock();
......
......@@ -131,20 +131,22 @@ static HRESULT WINAPI d3d9_swapchain_GetBackBuffer(IDirect3DSwapChain9 *iface,
struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9(iface);
struct wined3d_surface *wined3d_surface = NULL;
struct d3d9_surface *surface_impl;
HRESULT hr;
HRESULT hr = D3D_OK;
TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
iface, backbuffer_idx, backbuffer_type, backbuffer);
wined3d_mutex_lock();
hr = wined3d_swapchain_get_back_buffer(swapchain->wined3d_swapchain,
backbuffer_idx, (enum wined3d_backbuffer_type)backbuffer_type, &wined3d_surface);
if (SUCCEEDED(hr) && wined3d_surface)
if ((wined3d_surface = wined3d_swapchain_get_back_buffer(swapchain->wined3d_swapchain,
backbuffer_idx, (enum wined3d_backbuffer_type)backbuffer_type)))
{
surface_impl = wined3d_surface_get_parent(wined3d_surface);
*backbuffer = &surface_impl->IDirect3DSurface9_iface;
IDirect3DSurface9_AddRef(*backbuffer);
wined3d_surface_decref(wined3d_surface);
}
else
{
hr = D3DERR_INVALIDCALL;
}
wined3d_mutex_unlock();
......
......@@ -158,17 +158,15 @@ static HRESULT STDMETHODCALLTYPE dxgi_swapchain_GetBuffer(IDXGISwapChain *iface,
EnterCriticalSection(&dxgi_cs);
hr = wined3d_swapchain_get_back_buffer(This->wined3d_swapchain,
buffer_idx, WINED3D_BACKBUFFER_TYPE_MONO, &backbuffer);
if (FAILED(hr))
if (!(backbuffer = wined3d_swapchain_get_back_buffer(This->wined3d_swapchain,
buffer_idx, WINED3D_BACKBUFFER_TYPE_MONO)))
{
LeaveCriticalSection(&dxgi_cs);
return hr;
return DXGI_ERROR_INVALID_CALL;
}
parent = wined3d_surface_get_parent(backbuffer);
hr = IUnknown_QueryInterface(parent, riid, surface);
wined3d_surface_decref(backbuffer);
LeaveCriticalSection(&dxgi_cs);
return hr;
......
......@@ -3583,7 +3583,9 @@ HRESULT CDECL wined3d_device_get_back_buffer(const struct wined3d_device *device
if (!(swapchain = wined3d_device_get_swapchain(device, swapchain_idx)))
return WINED3DERR_INVALIDCALL;
return wined3d_swapchain_get_back_buffer(swapchain, backbuffer_idx, backbuffer_type, backbuffer);
if (!(*backbuffer = wined3d_swapchain_get_back_buffer(swapchain, backbuffer_idx, backbuffer_type)))
return WINED3DERR_INVALIDCALL;
return WINED3D_OK;
}
HRESULT CDECL wined3d_device_get_device_caps(const struct wined3d_device *device, WINED3DCAPS *caps)
......
......@@ -1095,7 +1095,6 @@ void stateblock_init_default_state(struct wined3d_stateblock *stateblock)
unsigned int i;
struct wined3d_swapchain *swapchain;
struct wined3d_surface *backbuffer;
HRESULT hr;
TRACE("stateblock %p.\n", stateblock);
......@@ -1298,13 +1297,11 @@ void stateblock_init_default_state(struct wined3d_stateblock *stateblock)
/* check the return values, because the GetBackBuffer call isn't valid for ddraw */
if ((swapchain = wined3d_device_get_swapchain(device, 0)))
{
hr = wined3d_swapchain_get_back_buffer(swapchain, 0, WINED3D_BACKBUFFER_TYPE_MONO, &backbuffer);
if (SUCCEEDED(hr) && backbuffer)
if ((backbuffer = wined3d_swapchain_get_back_buffer(swapchain, 0, WINED3D_BACKBUFFER_TYPE_MONO)))
{
struct wined3d_resource_desc desc;
wined3d_resource_get_desc(&backbuffer->resource, &desc);
wined3d_surface_decref(backbuffer);
/* Set the default scissor rect values */
state->scissor_rect.left = 0;
......
......@@ -188,11 +188,11 @@ HRESULT CDECL wined3d_swapchain_get_front_buffer_data(const struct wined3d_swapc
return wined3d_surface_blt(dst_surface, &dst_rect, src_surface, &src_rect, 0, NULL, WINED3D_TEXF_POINT);
}
HRESULT CDECL wined3d_swapchain_get_back_buffer(const struct wined3d_swapchain *swapchain,
UINT back_buffer_idx, enum wined3d_backbuffer_type type, struct wined3d_surface **back_buffer)
struct wined3d_surface * CDECL wined3d_swapchain_get_back_buffer(const struct wined3d_swapchain *swapchain,
UINT back_buffer_idx, enum wined3d_backbuffer_type type)
{
TRACE("swapchain %p, back_buffer_idx %u, type %#x, back_buffer %p.\n",
swapchain, back_buffer_idx, type, back_buffer);
TRACE("swapchain %p, back_buffer_idx %u, type %#x.\n",
swapchain, back_buffer_idx, type);
/* Return invalid if there is no backbuffer array, otherwise it will
* crash when ddraw is used (there swapchain->back_buffers is always
......@@ -204,17 +204,12 @@ HRESULT CDECL wined3d_swapchain_get_back_buffer(const struct wined3d_swapchain *
WARN("Invalid back buffer index.\n");
/* Native d3d9 doesn't set NULL here, just as wine's d3d9. But set it
* here in wined3d to avoid problems in other libs. */
*back_buffer = NULL;
return WINED3DERR_INVALIDCALL;
return NULL;
}
*back_buffer = swapchain->back_buffers[back_buffer_idx];
if (*back_buffer)
wined3d_surface_incref(*back_buffer);
TRACE("Returning back buffer %p.\n", swapchain->back_buffers[back_buffer_idx]);
TRACE("Returning back buffer %p.\n", *back_buffer);
return WINED3D_OK;
return swapchain->back_buffers[back_buffer_idx];
}
HRESULT CDECL wined3d_swapchain_get_raster_status(const struct wined3d_swapchain *swapchain,
......
......@@ -222,7 +222,7 @@
@ cdecl wined3d_swapchain_create(ptr ptr long ptr ptr ptr)
@ cdecl wined3d_swapchain_decref(ptr)
@ cdecl wined3d_swapchain_get_back_buffer(ptr long long ptr)
@ cdecl wined3d_swapchain_get_back_buffer(ptr long long)
@ cdecl wined3d_swapchain_get_device(ptr)
@ cdecl wined3d_swapchain_get_display_mode(ptr ptr ptr)
@ cdecl wined3d_swapchain_get_front_buffer_data(ptr ptr)
......
......@@ -2359,8 +2359,8 @@ HRESULT __cdecl wined3d_swapchain_create(struct wined3d_device *device,
struct wined3d_swapchain_desc *desc, enum wined3d_surface_type surface_type, void *parent,
const struct wined3d_parent_ops *parent_ops, struct wined3d_swapchain **swapchain);
ULONG __cdecl wined3d_swapchain_decref(struct wined3d_swapchain *swapchain);
HRESULT __cdecl wined3d_swapchain_get_back_buffer(const struct wined3d_swapchain *swapchain,
UINT backbuffer_idx, enum wined3d_backbuffer_type backbuffer_type, struct wined3d_surface **backbuffer);
struct wined3d_surface * __cdecl wined3d_swapchain_get_back_buffer(const struct wined3d_swapchain *swapchain,
UINT backbuffer_idx, enum wined3d_backbuffer_type backbuffer_type);
struct wined3d_device * __cdecl wined3d_swapchain_get_device(const struct wined3d_swapchain *swapchain);
HRESULT __cdecl wined3d_swapchain_get_display_mode(const struct wined3d_swapchain *swapchain,
struct wined3d_display_mode *mode, enum wined3d_display_rotation *rotation);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment