diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c index dff1ed00414..8f8f17789c8 100644 --- a/dlls/d3d9/device.c +++ b/dlls/d3d9/device.c @@ -506,24 +506,24 @@ static HRESULT WINAPI DECLSPEC_HOTPATCH d3d9_device_GetSwapChain(IDirect3DDevice UINT swapchain_idx, IDirect3DSwapChain9 **swapchain) { struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface); - struct wined3d_swapchain *wined3d_swapchain = NULL; + struct wined3d_swapchain *wined3d_swapchain; struct d3d9_swapchain *swapchain_impl; HRESULT hr; TRACE("iface %p, swapchain_idx %u, swapchain %p.\n", iface, swapchain_idx, swapchain); wined3d_mutex_lock(); - hr = wined3d_device_get_swapchain(device->wined3d_device, swapchain_idx, &wined3d_swapchain); - if (SUCCEEDED(hr) && wined3d_swapchain) + if ((wined3d_swapchain = wined3d_device_get_swapchain(device->wined3d_device, swapchain_idx))) { swapchain_impl = wined3d_swapchain_get_parent(wined3d_swapchain); *swapchain = &swapchain_impl->IDirect3DSwapChain9_iface; IDirect3DSwapChain9_AddRef(*swapchain); - wined3d_swapchain_decref(wined3d_swapchain); + hr = D3D_OK; } else { *swapchain = NULL; + hr = D3DERR_INVALIDCALL; } wined3d_mutex_unlock(); diff --git a/dlls/ddraw/ddraw.c b/dlls/ddraw/ddraw.c index 6a63d8a540c..0230b5d74b1 100644 --- a/dlls/ddraw/ddraw.c +++ b/dlls/ddraw/ddraw.c @@ -695,13 +695,13 @@ static HRESULT ddraw_create_swapchain(struct ddraw *ddraw, HWND window, BOOL win 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); - ddraw->wined3d_swapchain = NULL; - return hr; + ERR("Failed to get swapchain.\n"); + return DDERR_INVALIDPARAMS; } + wined3d_swapchain_incref(ddraw->wined3d_swapchain); ddraw_set_swapchain_window(ddraw, window); return DD_OK; diff --git a/dlls/dxgi/factory.c b/dlls/dxgi/factory.c index 045baf8ce21..b339d0f886f 100644 --- a/dlls/dxgi/factory.c +++ b/dlls/dxgi/factory.c @@ -229,16 +229,15 @@ static HRESULT STDMETHODCALLTYPE dxgi_factory_CreateSwapChain(IWineDXGIFactory * 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); - if (FAILED(hr)) + if (!wined3d_swapchain) { - WARN("Failed to get swapchain, returning %#x\n", hr); - return hr; + WARN("Failed to get swapchain.\n"); + return E_FAIL; } *swapchain = wined3d_swapchain_get_parent(wined3d_swapchain); - wined3d_swapchain_decref(wined3d_swapchain); /* FIXME? The swapchain is created with refcount 1 by the wined3d device, * but the wined3d device can't hold a real reference. */ diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index ba8c4be03b9..386fd25262a 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -897,26 +897,18 @@ UINT CDECL wined3d_device_get_swapchain_count(const struct wined3d_device *devic return device->swapchain_count; } -HRESULT CDECL wined3d_device_get_swapchain(const struct wined3d_device *device, - UINT swapchain_idx, struct wined3d_swapchain **swapchain) +struct wined3d_swapchain * CDECL wined3d_device_get_swapchain(const struct wined3d_device *device, UINT swapchain_idx) { - TRACE("device %p, swapchain_idx %u, swapchain %p.\n", - device, swapchain_idx, swapchain); + TRACE("device %p, swapchain_idx %u.\n", device, swapchain_idx); if (swapchain_idx >= device->swapchain_count) { WARN("swapchain_idx %u >= swapchain_count %u.\n", swapchain_idx, device->swapchain_count); - *swapchain = NULL; - - return WINED3DERR_INVALIDCALL; + return NULL; } - *swapchain = device->swapchains[swapchain_idx]; - wined3d_swapchain_incref(*swapchain); - TRACE("Returning %p.\n", *swapchain); - - return WINED3D_OK; + return device->swapchains[swapchain_idx]; } 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) { struct wined3d_swapchain *swapchain; - HRESULT hr; TRACE("device %p, swapchain_idx %u, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n", device, swapchain_idx, backbuffer_idx, backbuffer_type, backbuffer); - hr = wined3d_device_get_swapchain(device, swapchain_idx, &swapchain); - if (FAILED(hr)) - { - WARN("Failed to get swapchain %u, hr %#x.\n", swapchain_idx, hr); - return hr; - } + if (!(swapchain = wined3d_device_get_swapchain(device, swapchain_idx))) + return WINED3DERR_INVALIDCALL; - hr = 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; + return wined3d_swapchain_get_back_buffer(swapchain, backbuffer_idx, backbuffer_type, backbuffer); } 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_swapchain *swapchain; - HRESULT hr; TRACE("device %p, swapchain_idx %u, mode %p, rotation %p.\n", device, swapchain_idx, mode, rotation); - if (SUCCEEDED(hr = wined3d_device_get_swapchain(device, swapchain_idx, &swapchain))) - { - hr = wined3d_swapchain_get_display_mode(swapchain, mode, rotation); - wined3d_swapchain_decref(swapchain); - } + if (!(swapchain = wined3d_device_get_swapchain(device, swapchain_idx))) + return WINED3DERR_INVALIDCALL; - return hr; + return wined3d_swapchain_get_display_mode(swapchain, mode, rotation); } 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) { struct wined3d_swapchain *swapchain; - HRESULT hr; 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 (FAILED(hr)) return hr; + if (!(swapchain = wined3d_device_get_swapchain(device, swapchain_idx))) + return WINED3DERR_INVALIDCALL; - hr = wined3d_swapchain_get_front_buffer_data(swapchain, dst_surface); - wined3d_swapchain_decref(swapchain); - - return hr; + return wined3d_swapchain_get_front_buffer_data(swapchain, dst_surface); } 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) { struct wined3d_swapchain *swapchain; - HRESULT hr; TRACE("device %p, swapchain_idx %u, raster_status %p.\n", device, swapchain_idx, raster_status); - hr = wined3d_device_get_swapchain(device, swapchain_idx, &swapchain); - if (FAILED(hr)) - { - WARN("Failed to get swapchain %u, hr %#x.\n", swapchain_idx, hr); - return hr; - } + if (!(swapchain = wined3d_device_get_swapchain(device, swapchain_idx))) + return WINED3DERR_INVALIDCALL; - hr = 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; + return wined3d_swapchain_get_raster_status(swapchain, raster_status); } 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); - 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"); - return hr; + return WINED3DERR_INVALIDCALL; } stateblock_unbind_resources(device->stateBlock); @@ -5172,10 +5130,7 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device, { TRACE("Enumerating resource %p.\n", resource); if (FAILED(hr = callback(resource))) - { - wined3d_swapchain_decref(swapchain); return hr; - } } /* 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))) { ERR("Failed to create the depth stencil buffer, hr %#x.\n", hr); - wined3d_swapchain_decref(swapchain); return WINED3DERR_INVALIDCALL; } } @@ -5300,36 +5254,24 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device, { 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.multisample_type, swapchain->desc.multisample_quality); - if (FAILED(hr)) - { - wined3d_swapchain_decref(swapchain); + swapchain->desc.multisample_type, swapchain->desc.multisample_quality))) return hr; - } 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.multisample_type, swapchain->desc.multisample_quality); - if (FAILED(hr)) - { - wined3d_swapchain_decref(swapchain); + swapchain->desc.multisample_type, swapchain->desc.multisample_quality))) return hr; - } } 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.multisample_type, swapchain->desc.multisample_quality); - if (FAILED(hr)) - { - wined3d_swapchain_decref(swapchain); + swapchain->desc.multisample_type, swapchain->desc.multisample_quality))) 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))) { WARN("Failed to set display mode, hr %#x.\n", hr); - wined3d_swapchain_decref(swapchain); 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))) { ERR("Failed to acquire focus window, hr %#x.\n", hr); - wined3d_swapchain_decref(swapchain); return hr; } @@ -5419,7 +5359,6 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device, if (device->d3d_initialized) 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 * 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", 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_decref(swapchain); - } } 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", 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_decref(swapchain); - } } void device_resource_add(struct wined3d_device *device, struct wined3d_resource *resource) diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c index 9660f2ed62e..3e1ecb26e74 100644 --- a/dlls/wined3d/stateblock.c +++ b/dlls/wined3d/stateblock.c @@ -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 */ - hr = wined3d_device_get_swapchain(device, 0, &swapchain); - if (SUCCEEDED(hr) && swapchain) + 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) @@ -1321,8 +1320,6 @@ void stateblock_init_default_state(struct wined3d_stateblock *stateblock) state->viewport.height = swapchain->desc.backbuffer_height; state->viewport.min_z = 0.0f; state->viewport.max_z = 1.0f; - - wined3d_swapchain_decref(swapchain); } TRACE("Done.\n"); diff --git a/dlls/wined3d/wined3d.spec b/dlls/wined3d/wined3d.spec index 6555ae86b6e..aa0c186405d 100644 --- a/dlls/wined3d/wined3d.spec +++ b/dlls/wined3d/wined3d.spec @@ -83,7 +83,7 @@ @ 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_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_texture(ptr long ptr) @ cdecl wined3d_device_get_texture_stage_state(ptr long long ptr) diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h index 941bd8e9648..82a1c803644 100644 --- a/include/wine/wined3d.h +++ b/include/wine/wined3d.h @@ -2157,8 +2157,8 @@ HRESULT __cdecl wined3d_device_get_stream_source_freq(const struct wined3d_devic UINT stream_idx, UINT *divider); HRESULT __cdecl wined3d_device_get_surface_from_dc(const struct wined3d_device *device, HDC dc, struct wined3d_surface **surface); -HRESULT __cdecl wined3d_device_get_swapchain(const struct wined3d_device *device, - UINT swapchain_idx, struct wined3d_swapchain **swapchain); +struct wined3d_swapchain * __cdecl wined3d_device_get_swapchain(const struct wined3d_device *device, + UINT swapchain_idx); UINT __cdecl wined3d_device_get_swapchain_count(const struct wined3d_device *device); HRESULT __cdecl wined3d_device_get_texture(const struct wined3d_device *device, UINT stage, struct wined3d_texture **texture);