wined3d: Just return the swapchain from wined3d_device_get_swapchain().

This commit is contained in:
Henri Verbeet 2012-09-04 20:15:10 +02:00 committed by Alexandre Julliard
parent ac5c420c91
commit 8fd7d3a2b3
7 changed files with 42 additions and 113 deletions

View File

@ -506,24 +506,24 @@ static HRESULT WINAPI DECLSPEC_HOTPATCH d3d9_device_GetSwapChain(IDirect3DDevice
UINT swapchain_idx, IDirect3DSwapChain9 **swapchain) UINT swapchain_idx, IDirect3DSwapChain9 **swapchain)
{ {
struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface); struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
struct wined3d_swapchain *wined3d_swapchain = NULL; struct wined3d_swapchain *wined3d_swapchain;
struct d3d9_swapchain *swapchain_impl; struct d3d9_swapchain *swapchain_impl;
HRESULT hr; HRESULT hr;
TRACE("iface %p, swapchain_idx %u, swapchain %p.\n", iface, swapchain_idx, swapchain); TRACE("iface %p, swapchain_idx %u, swapchain %p.\n", iface, swapchain_idx, swapchain);
wined3d_mutex_lock(); wined3d_mutex_lock();
hr = wined3d_device_get_swapchain(device->wined3d_device, swapchain_idx, &wined3d_swapchain); if ((wined3d_swapchain = wined3d_device_get_swapchain(device->wined3d_device, swapchain_idx)))
if (SUCCEEDED(hr) && wined3d_swapchain)
{ {
swapchain_impl = wined3d_swapchain_get_parent(wined3d_swapchain); swapchain_impl = wined3d_swapchain_get_parent(wined3d_swapchain);
*swapchain = &swapchain_impl->IDirect3DSwapChain9_iface; *swapchain = &swapchain_impl->IDirect3DSwapChain9_iface;
IDirect3DSwapChain9_AddRef(*swapchain); IDirect3DSwapChain9_AddRef(*swapchain);
wined3d_swapchain_decref(wined3d_swapchain); hr = D3D_OK;
} }
else else
{ {
*swapchain = NULL; *swapchain = NULL;
hr = D3DERR_INVALIDCALL;
} }
wined3d_mutex_unlock(); wined3d_mutex_unlock();

View File

@ -695,13 +695,13 @@ static HRESULT ddraw_create_swapchain(struct ddraw *ddraw, HWND window, BOOL win
return hr; return hr;
} }
if (FAILED(hr = wined3d_device_get_swapchain(ddraw->wined3d_device, 0, &ddraw->wined3d_swapchain))) if (!(ddraw->wined3d_swapchain = wined3d_device_get_swapchain(ddraw->wined3d_device, 0)))
{ {
ERR("Failed to get swapchain, hr %#x.\n", hr); ERR("Failed to get swapchain.\n");
ddraw->wined3d_swapchain = NULL; return DDERR_INVALIDPARAMS;
return hr;
} }
wined3d_swapchain_incref(ddraw->wined3d_swapchain);
ddraw_set_swapchain_window(ddraw, window); ddraw_set_swapchain_window(ddraw, window);
return DD_OK; return DD_OK;

View File

@ -229,16 +229,15 @@ static HRESULT STDMETHODCALLTYPE dxgi_factory_CreateSwapChain(IWineDXGIFactory *
return hr; return hr;
} }
hr = wined3d_device_get_swapchain(wined3d_device, 0, &wined3d_swapchain); wined3d_swapchain = wined3d_device_get_swapchain(wined3d_device, 0);
wined3d_device_decref(wined3d_device); wined3d_device_decref(wined3d_device);
if (FAILED(hr)) if (!wined3d_swapchain)
{ {
WARN("Failed to get swapchain, returning %#x\n", hr); WARN("Failed to get swapchain.\n");
return hr; return E_FAIL;
} }
*swapchain = wined3d_swapchain_get_parent(wined3d_swapchain); *swapchain = wined3d_swapchain_get_parent(wined3d_swapchain);
wined3d_swapchain_decref(wined3d_swapchain);
/* FIXME? The swapchain is created with refcount 1 by the wined3d device, /* FIXME? The swapchain is created with refcount 1 by the wined3d device,
* but the wined3d device can't hold a real reference. */ * but the wined3d device can't hold a real reference. */

View File

@ -897,26 +897,18 @@ UINT CDECL wined3d_device_get_swapchain_count(const struct wined3d_device *devic
return device->swapchain_count; return device->swapchain_count;
} }
HRESULT CDECL wined3d_device_get_swapchain(const struct wined3d_device *device, struct wined3d_swapchain * CDECL wined3d_device_get_swapchain(const struct wined3d_device *device, UINT swapchain_idx)
UINT swapchain_idx, struct wined3d_swapchain **swapchain)
{ {
TRACE("device %p, swapchain_idx %u, swapchain %p.\n", TRACE("device %p, swapchain_idx %u.\n", device, swapchain_idx);
device, swapchain_idx, swapchain);
if (swapchain_idx >= device->swapchain_count) if (swapchain_idx >= device->swapchain_count)
{ {
WARN("swapchain_idx %u >= swapchain_count %u.\n", WARN("swapchain_idx %u >= swapchain_count %u.\n",
swapchain_idx, device->swapchain_count); swapchain_idx, device->swapchain_count);
*swapchain = NULL; return NULL;
return WINED3DERR_INVALIDCALL;
} }
*swapchain = device->swapchains[swapchain_idx]; return device->swapchains[swapchain_idx];
wined3d_swapchain_incref(*swapchain);
TRACE("Returning %p.\n", *swapchain);
return WINED3D_OK;
} }
static void device_load_logo(struct wined3d_device *device, const char *filename) static void device_load_logo(struct wined3d_device *device, const char *filename)
@ -3677,27 +3669,14 @@ HRESULT CDECL wined3d_device_get_back_buffer(const struct wined3d_device *device
UINT backbuffer_idx, enum wined3d_backbuffer_type backbuffer_type, struct wined3d_surface **backbuffer) UINT backbuffer_idx, enum wined3d_backbuffer_type backbuffer_type, struct wined3d_surface **backbuffer)
{ {
struct wined3d_swapchain *swapchain; struct wined3d_swapchain *swapchain;
HRESULT hr;
TRACE("device %p, swapchain_idx %u, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n", TRACE("device %p, swapchain_idx %u, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
device, swapchain_idx, backbuffer_idx, backbuffer_type, backbuffer); device, swapchain_idx, backbuffer_idx, backbuffer_type, backbuffer);
hr = wined3d_device_get_swapchain(device, swapchain_idx, &swapchain); if (!(swapchain = wined3d_device_get_swapchain(device, swapchain_idx)))
if (FAILED(hr)) return WINED3DERR_INVALIDCALL;
{
WARN("Failed to get swapchain %u, hr %#x.\n", swapchain_idx, hr);
return hr;
}
hr = wined3d_swapchain_get_back_buffer(swapchain, backbuffer_idx, backbuffer_type, backbuffer); return wined3d_swapchain_get_back_buffer(swapchain, backbuffer_idx, backbuffer_type, backbuffer);
wined3d_swapchain_decref(swapchain);
if (FAILED(hr))
{
WARN("Failed to get backbuffer %u, hr %#x.\n", backbuffer_idx, hr);
return hr;
}
return WINED3D_OK;
} }
HRESULT CDECL wined3d_device_get_device_caps(const struct wined3d_device *device, WINED3DCAPS *caps) HRESULT CDECL wined3d_device_get_device_caps(const struct wined3d_device *device, WINED3DCAPS *caps)
@ -3712,18 +3691,14 @@ HRESULT CDECL wined3d_device_get_display_mode(const struct wined3d_device *devic
struct wined3d_display_mode *mode, enum wined3d_display_rotation *rotation) struct wined3d_display_mode *mode, enum wined3d_display_rotation *rotation)
{ {
struct wined3d_swapchain *swapchain; struct wined3d_swapchain *swapchain;
HRESULT hr;
TRACE("device %p, swapchain_idx %u, mode %p, rotation %p.\n", TRACE("device %p, swapchain_idx %u, mode %p, rotation %p.\n",
device, swapchain_idx, mode, rotation); device, swapchain_idx, mode, rotation);
if (SUCCEEDED(hr = wined3d_device_get_swapchain(device, swapchain_idx, &swapchain))) if (!(swapchain = wined3d_device_get_swapchain(device, swapchain_idx)))
{ return WINED3DERR_INVALIDCALL;
hr = wined3d_swapchain_get_display_mode(swapchain, mode, rotation);
wined3d_swapchain_decref(swapchain);
}
return hr; return wined3d_swapchain_get_display_mode(swapchain, mode, rotation);
} }
HRESULT CDECL wined3d_device_begin_stateblock(struct wined3d_device *device) HRESULT CDECL wined3d_device_begin_stateblock(struct wined3d_device *device)
@ -4251,17 +4226,13 @@ HRESULT CDECL wined3d_device_get_front_buffer_data(const struct wined3d_device *
UINT swapchain_idx, struct wined3d_surface *dst_surface) UINT swapchain_idx, struct wined3d_surface *dst_surface)
{ {
struct wined3d_swapchain *swapchain; struct wined3d_swapchain *swapchain;
HRESULT hr;
TRACE("device %p, swapchain_idx %u, dst_surface %p.\n", device, swapchain_idx, dst_surface); TRACE("device %p, swapchain_idx %u, dst_surface %p.\n", device, swapchain_idx, dst_surface);
hr = wined3d_device_get_swapchain(device, swapchain_idx, &swapchain); if (!(swapchain = wined3d_device_get_swapchain(device, swapchain_idx)))
if (FAILED(hr)) return hr; return WINED3DERR_INVALIDCALL;
hr = wined3d_swapchain_get_front_buffer_data(swapchain, dst_surface); return wined3d_swapchain_get_front_buffer_data(swapchain, dst_surface);
wined3d_swapchain_decref(swapchain);
return hr;
} }
HRESULT CDECL wined3d_device_validate_device(const struct wined3d_device *device, DWORD *num_passes) HRESULT CDECL wined3d_device_validate_device(const struct wined3d_device *device, DWORD *num_passes)
@ -4363,27 +4334,14 @@ HRESULT CDECL wined3d_device_get_raster_status(const struct wined3d_device *devi
UINT swapchain_idx, struct wined3d_raster_status *raster_status) UINT swapchain_idx, struct wined3d_raster_status *raster_status)
{ {
struct wined3d_swapchain *swapchain; struct wined3d_swapchain *swapchain;
HRESULT hr;
TRACE("device %p, swapchain_idx %u, raster_status %p.\n", TRACE("device %p, swapchain_idx %u, raster_status %p.\n",
device, swapchain_idx, raster_status); device, swapchain_idx, raster_status);
hr = wined3d_device_get_swapchain(device, swapchain_idx, &swapchain); if (!(swapchain = wined3d_device_get_swapchain(device, swapchain_idx)))
if (FAILED(hr)) return WINED3DERR_INVALIDCALL;
{
WARN("Failed to get swapchain %u, hr %#x.\n", swapchain_idx, hr);
return hr;
}
hr = wined3d_swapchain_get_raster_status(swapchain, raster_status); return wined3d_swapchain_get_raster_status(swapchain, raster_status);
wined3d_swapchain_decref(swapchain);
if (FAILED(hr))
{
WARN("Failed to get raster status, hr %#x.\n", hr);
return hr;
}
return WINED3D_OK;
} }
HRESULT CDECL wined3d_device_set_npatch_mode(struct wined3d_device *device, float segments) HRESULT CDECL wined3d_device_set_npatch_mode(struct wined3d_device *device, float segments)
@ -5142,10 +5100,10 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device,
TRACE("device %p, swapchain_desc %p, mode %p, callback %p.\n", device, swapchain_desc, mode, callback); TRACE("device %p, swapchain_desc %p, mode %p, callback %p.\n", device, swapchain_desc, mode, callback);
if (FAILED(hr = wined3d_device_get_swapchain(device, 0, &swapchain))) if (!(swapchain = wined3d_device_get_swapchain(device, 0)))
{ {
ERR("Failed to get the first implicit swapchain.\n"); ERR("Failed to get the first implicit swapchain.\n");
return hr; return WINED3DERR_INVALIDCALL;
} }
stateblock_unbind_resources(device->stateBlock); stateblock_unbind_resources(device->stateBlock);
@ -5172,10 +5130,7 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device,
{ {
TRACE("Enumerating resource %p.\n", resource); TRACE("Enumerating resource %p.\n", resource);
if (FAILED(hr = callback(resource))) if (FAILED(hr = callback(resource)))
{
wined3d_swapchain_decref(swapchain);
return hr; return hr;
}
} }
/* Is it necessary to recreate the gl context? Actually every setting can be changed /* Is it necessary to recreate the gl context? Actually every setting can be changed
@ -5237,7 +5192,6 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device,
&device->auto_depth_stencil))) &device->auto_depth_stencil)))
{ {
ERR("Failed to create the depth stencil buffer, hr %#x.\n", hr); ERR("Failed to create the depth stencil buffer, hr %#x.\n", hr);
wined3d_swapchain_decref(swapchain);
return WINED3DERR_INVALIDCALL; return WINED3DERR_INVALIDCALL;
} }
} }
@ -5300,36 +5254,24 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device,
{ {
UINT i; UINT i;
hr = wined3d_surface_update_desc(swapchain->front_buffer, swapchain->desc.backbuffer_width, if (FAILED(hr = wined3d_surface_update_desc(swapchain->front_buffer, swapchain->desc.backbuffer_width,
swapchain->desc.backbuffer_height, swapchain->desc.backbuffer_format, swapchain->desc.backbuffer_height, swapchain->desc.backbuffer_format,
swapchain->desc.multisample_type, swapchain->desc.multisample_quality); swapchain->desc.multisample_type, swapchain->desc.multisample_quality)))
if (FAILED(hr))
{
wined3d_swapchain_decref(swapchain);
return hr; return hr;
}
for (i = 0; i < swapchain->desc.backbuffer_count; ++i) for (i = 0; i < swapchain->desc.backbuffer_count; ++i)
{ {
hr = wined3d_surface_update_desc(swapchain->back_buffers[i], swapchain->desc.backbuffer_width, if (FAILED(hr = wined3d_surface_update_desc(swapchain->back_buffers[i], swapchain->desc.backbuffer_width,
swapchain->desc.backbuffer_height, swapchain->desc.backbuffer_format, swapchain->desc.backbuffer_height, swapchain->desc.backbuffer_format,
swapchain->desc.multisample_type, swapchain->desc.multisample_quality); swapchain->desc.multisample_type, swapchain->desc.multisample_quality)))
if (FAILED(hr))
{
wined3d_swapchain_decref(swapchain);
return hr; return hr;
}
} }
if (device->auto_depth_stencil) if (device->auto_depth_stencil)
{ {
hr = wined3d_surface_update_desc(device->auto_depth_stencil, swapchain->desc.backbuffer_width, if (FAILED(hr = wined3d_surface_update_desc(device->auto_depth_stencil, swapchain->desc.backbuffer_width,
swapchain->desc.backbuffer_height, device->auto_depth_stencil->resource.format->id, swapchain->desc.backbuffer_height, device->auto_depth_stencil->resource.format->id,
swapchain->desc.multisample_type, swapchain->desc.multisample_quality); swapchain->desc.multisample_type, swapchain->desc.multisample_quality)))
if (FAILED(hr))
{
wined3d_swapchain_decref(swapchain);
return hr; return hr;
}
} }
} }
@ -5339,7 +5281,6 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device,
if (FAILED(hr = wined3d_set_adapter_display_mode(device->wined3d, device->adapter->ordinal, &m))) if (FAILED(hr = wined3d_set_adapter_display_mode(device->wined3d, device->adapter->ordinal, &m)))
{ {
WARN("Failed to set display mode, hr %#x.\n", hr); WARN("Failed to set display mode, hr %#x.\n", hr);
wined3d_swapchain_decref(swapchain);
return WINED3DERR_INVALIDCALL; return WINED3DERR_INVALIDCALL;
} }
@ -5353,7 +5294,6 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device,
if (FAILED(hr = wined3d_device_acquire_focus_window(device, focus_window))) if (FAILED(hr = wined3d_device_acquire_focus_window(device, focus_window)))
{ {
ERR("Failed to acquire focus window, hr %#x.\n", hr); ERR("Failed to acquire focus window, hr %#x.\n", hr);
wined3d_swapchain_decref(swapchain);
return hr; return hr;
} }
@ -5419,7 +5359,6 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device,
if (device->d3d_initialized) if (device->d3d_initialized)
hr = create_primary_opengl_context(device, swapchain); hr = create_primary_opengl_context(device, swapchain);
wined3d_swapchain_decref(swapchain);
/* All done. There is no need to reload resources or shaders, this will happen automatically on the /* All done. There is no need to reload resources or shaders, this will happen automatically on the
* first use * first use
@ -5454,11 +5393,8 @@ void CDECL wined3d_device_set_gamma_ramp(const struct wined3d_device *device,
TRACE("device %p, swapchain_idx %u, flags %#x, ramp %p.\n", TRACE("device %p, swapchain_idx %u, flags %#x, ramp %p.\n",
device, swapchain_idx, flags, ramp); device, swapchain_idx, flags, ramp);
if (SUCCEEDED(wined3d_device_get_swapchain(device, swapchain_idx, &swapchain))) if ((swapchain = wined3d_device_get_swapchain(device, swapchain_idx)))
{
wined3d_swapchain_set_gamma_ramp(swapchain, flags, ramp); wined3d_swapchain_set_gamma_ramp(swapchain, flags, ramp);
wined3d_swapchain_decref(swapchain);
}
} }
void CDECL wined3d_device_get_gamma_ramp(const struct wined3d_device *device, void CDECL wined3d_device_get_gamma_ramp(const struct wined3d_device *device,
@ -5469,11 +5405,8 @@ void CDECL wined3d_device_get_gamma_ramp(const struct wined3d_device *device,
TRACE("device %p, swapchain_idx %u, ramp %p.\n", TRACE("device %p, swapchain_idx %u, ramp %p.\n",
device, swapchain_idx, ramp); device, swapchain_idx, ramp);
if (SUCCEEDED(wined3d_device_get_swapchain(device, swapchain_idx, &swapchain))) if ((swapchain = wined3d_device_get_swapchain(device, swapchain_idx)))
{
wined3d_swapchain_get_gamma_ramp(swapchain, ramp); wined3d_swapchain_get_gamma_ramp(swapchain, ramp);
wined3d_swapchain_decref(swapchain);
}
} }
void device_resource_add(struct wined3d_device *device, struct wined3d_resource *resource) void device_resource_add(struct wined3d_device *device, struct wined3d_resource *resource)

View File

@ -1296,8 +1296,7 @@ void stateblock_init_default_state(struct wined3d_stateblock *stateblock)
} }
/* check the return values, because the GetBackBuffer call isn't valid for ddraw */ /* check the return values, because the GetBackBuffer call isn't valid for ddraw */
hr = wined3d_device_get_swapchain(device, 0, &swapchain); if ((swapchain = wined3d_device_get_swapchain(device, 0)))
if (SUCCEEDED(hr) && swapchain)
{ {
hr = wined3d_swapchain_get_back_buffer(swapchain, 0, WINED3D_BACKBUFFER_TYPE_MONO, &backbuffer); hr = wined3d_swapchain_get_back_buffer(swapchain, 0, WINED3D_BACKBUFFER_TYPE_MONO, &backbuffer);
if (SUCCEEDED(hr) && backbuffer) if (SUCCEEDED(hr) && backbuffer)
@ -1321,8 +1320,6 @@ void stateblock_init_default_state(struct wined3d_stateblock *stateblock)
state->viewport.height = swapchain->desc.backbuffer_height; state->viewport.height = swapchain->desc.backbuffer_height;
state->viewport.min_z = 0.0f; state->viewport.min_z = 0.0f;
state->viewport.max_z = 1.0f; state->viewport.max_z = 1.0f;
wined3d_swapchain_decref(swapchain);
} }
TRACE("Done.\n"); TRACE("Done.\n");

View File

@ -83,7 +83,7 @@
@ cdecl wined3d_device_get_stream_source(ptr long ptr ptr ptr) @ cdecl wined3d_device_get_stream_source(ptr long ptr ptr ptr)
@ cdecl wined3d_device_get_stream_source_freq(ptr long ptr) @ cdecl wined3d_device_get_stream_source_freq(ptr long ptr)
@ cdecl wined3d_device_get_surface_from_dc(ptr ptr ptr) @ cdecl wined3d_device_get_surface_from_dc(ptr ptr ptr)
@ cdecl wined3d_device_get_swapchain(ptr long ptr) @ cdecl wined3d_device_get_swapchain(ptr long)
@ cdecl wined3d_device_get_swapchain_count(ptr) @ cdecl wined3d_device_get_swapchain_count(ptr)
@ cdecl wined3d_device_get_texture(ptr long ptr) @ cdecl wined3d_device_get_texture(ptr long ptr)
@ cdecl wined3d_device_get_texture_stage_state(ptr long long ptr) @ cdecl wined3d_device_get_texture_stage_state(ptr long long ptr)

View File

@ -2157,8 +2157,8 @@ HRESULT __cdecl wined3d_device_get_stream_source_freq(const struct wined3d_devic
UINT stream_idx, UINT *divider); UINT stream_idx, UINT *divider);
HRESULT __cdecl wined3d_device_get_surface_from_dc(const struct wined3d_device *device, HRESULT __cdecl wined3d_device_get_surface_from_dc(const struct wined3d_device *device,
HDC dc, struct wined3d_surface **surface); HDC dc, struct wined3d_surface **surface);
HRESULT __cdecl wined3d_device_get_swapchain(const struct wined3d_device *device, struct wined3d_swapchain * __cdecl wined3d_device_get_swapchain(const struct wined3d_device *device,
UINT swapchain_idx, struct wined3d_swapchain **swapchain); UINT swapchain_idx);
UINT __cdecl wined3d_device_get_swapchain_count(const struct wined3d_device *device); UINT __cdecl wined3d_device_get_swapchain_count(const struct wined3d_device *device);
HRESULT __cdecl wined3d_device_get_texture(const struct wined3d_device *device, HRESULT __cdecl wined3d_device_get_texture(const struct wined3d_device *device,
UINT stage, struct wined3d_texture **texture); UINT stage, struct wined3d_texture **texture);