wined3d: Get rid of wined3d_device_get_surface_from_dc().

Signed-off-by: Riccardo Bortolato <rikyz619@gmail.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Riccardo Bortolato 2016-02-08 18:32:06 +01:00 committed by Alexandre Julliard
parent 195d16c826
commit b278bb8f56
7 changed files with 57 additions and 75 deletions

View File

@ -2621,29 +2621,38 @@ static HRESULT WINAPI ddraw4_GetDeviceIdentifier(IDirectDraw4 *iface,
* Always returns DD_OK because it's a stub
*
*****************************************************************************/
static HRESULT WINAPI ddraw7_GetSurfaceFromDC(IDirectDraw7 *iface, HDC hdc,
IDirectDrawSurface7 **Surface)
static HRESULT WINAPI ddraw7_GetSurfaceFromDC(IDirectDraw7 *iface,
HDC dc, IDirectDrawSurface7 **surface)
{
struct ddraw *ddraw = impl_from_IDirectDraw7(iface);
struct wined3d_surface *wined3d_surface;
struct ddraw_surface *surface_impl;
TRACE("iface %p, dc %p, surface %p.\n", iface, hdc, Surface);
TRACE("iface %p, dc %p, surface %p.\n", iface, dc, surface);
if (!Surface) return E_INVALIDARG;
if (!surface)
return E_INVALIDARG;
if (!(wined3d_surface = wined3d_device_get_surface_from_dc(ddraw->wined3d_device, hdc)))
if (!dc)
goto done;
wined3d_mutex_lock();
LIST_FOR_EACH_ENTRY(surface_impl, &ddraw->surface_list, struct ddraw_surface, surface_list_entry)
{
TRACE("No surface found for dc %p.\n", hdc);
*Surface = NULL;
return DDERR_NOTFOUND;
}
if (surface_impl->dc != dc)
continue;
surface_impl = wined3d_surface_get_parent(wined3d_surface);
*Surface = &surface_impl->IDirectDrawSurface7_iface;
IDirectDrawSurface7_AddRef(*Surface);
TRACE("Returning surface %p.\n", Surface);
return DD_OK;
TRACE("Found surface %p for dc %p.\n", surface_impl, dc);
*surface = &surface_impl->IDirectDrawSurface7_iface;
IDirectDrawSurface7_AddRef(*surface);
wined3d_mutex_unlock();
return DD_OK;
}
wined3d_mutex_unlock();
done:
TRACE("No surface found for dc %p.\n", dc);
*surface = NULL;
return DDERR_NOTFOUND;
}
static HRESULT WINAPI ddraw4_GetSurfaceFromDC(IDirectDraw4 *iface, HDC dc,

View File

@ -197,6 +197,7 @@ struct ddraw_surface
struct list surface_list_entry;
DWORD Handle;
HDC dc;
};
struct ddraw_texture

View File

@ -2103,48 +2103,53 @@ static HRESULT WINAPI ddraw_surface1_AddOverlayDirtyRect(IDirectDrawSurface *ifa
* For details, see IWineD3DSurface::GetDC
*
*****************************************************************************/
static HRESULT WINAPI ddraw_surface7_GetDC(IDirectDrawSurface7 *iface, HDC *hdc)
static HRESULT WINAPI ddraw_surface7_GetDC(IDirectDrawSurface7 *iface, HDC *dc)
{
struct ddraw_surface *surface = impl_from_IDirectDrawSurface7(iface);
HRESULT hr = DD_OK;
TRACE("iface %p, dc %p.\n", iface, hdc);
TRACE("iface %p, dc %p.\n", iface, dc);
if(!hdc)
if (!dc)
return DDERR_INVALIDPARAMS;
wined3d_mutex_lock();
if (surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
hr = ddraw_surface_update_frontbuffer(surface, NULL, TRUE);
if (SUCCEEDED(hr))
hr = wined3d_texture_get_dc(surface->wined3d_texture, surface->sub_resource_idx, hdc);
hr = wined3d_texture_get_dc(surface->wined3d_texture, surface->sub_resource_idx, dc);
if (SUCCEEDED(hr) && format_is_paletteindexed(&surface->surface_desc.u4.ddpfPixelFormat))
if (SUCCEEDED(hr))
{
const struct ddraw_palette *palette;
surface->dc = *dc;
if (surface->palette)
palette = surface->palette;
else if (surface->ddraw->primary)
palette = surface->ddraw->primary->palette;
else
palette = NULL;
if (format_is_paletteindexed(&surface->surface_desc.u4.ddpfPixelFormat))
{
const struct ddraw_palette *palette;
if (palette)
wined3d_palette_apply_to_dc(palette->wineD3DPalette, *hdc);
if (surface->palette)
palette = surface->palette;
else if (surface->ddraw->primary)
palette = surface->ddraw->primary->palette;
else
palette = NULL;
if (palette)
wined3d_palette_apply_to_dc(palette->wineD3DPalette, *dc);
}
}
wined3d_mutex_unlock();
switch(hr)
switch (hr)
{
/* Some, but not all errors set *hdc to NULL. E.g. DCALREADYCREATED does not
* touch *hdc
*/
/* Some, but not all errors set *dc to NULL. E.g. DCALREADYCREATED
* does not touch *dc. */
case WINED3DERR_INVALIDCALL:
if(hdc) *hdc = NULL;
*dc = NULL;
return DDERR_INVALIDPARAMS;
default: return hr;
default:
return hr;
}
}
@ -2205,11 +2210,15 @@ static HRESULT WINAPI ddraw_surface7_ReleaseDC(IDirectDrawSurface7 *iface, HDC h
TRACE("iface %p, dc %p.\n", iface, hdc);
wined3d_mutex_lock();
hr = wined3d_texture_release_dc(surface->wined3d_texture, surface->sub_resource_idx, hdc);
if (SUCCEEDED(hr) && (surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE))
hr = ddraw_surface_update_frontbuffer(surface, NULL, FALSE);
if (SUCCEEDED(hr = wined3d_texture_release_dc(surface->wined3d_texture, surface->sub_resource_idx, hdc)))
{
surface->dc = NULL;
if (surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
hr = ddraw_surface_update_frontbuffer(surface, NULL, FALSE);
}
wined3d_mutex_unlock();
return hr;
}

View File

@ -5040,32 +5040,6 @@ void device_resource_released(struct wined3d_device *device, struct wined3d_reso
TRACE("Resource released.\n");
}
struct wined3d_surface * CDECL wined3d_device_get_surface_from_dc(const struct wined3d_device *device, HDC dc)
{
struct wined3d_resource *resource;
TRACE("device %p, dc %p.\n", device, dc);
if (!dc)
return NULL;
LIST_FOR_EACH_ENTRY(resource, &device->resources, struct wined3d_resource, resource_list_entry)
{
if (resource->type == WINED3D_RTYPE_SURFACE)
{
struct wined3d_surface *s = surface_from_resource(resource);
if (s->hDC == dc)
{
TRACE("Found surface %p for dc %p.\n", s, dc);
return s;
}
}
}
return NULL;
}
static int wined3d_sampler_compare(const void *key, const struct wine_rb_entry *entry)
{
const struct wined3d_sampler *sampler = WINE_RB_ENTRY_VALUE(entry, struct wined3d_sampler, entry);

View File

@ -1883,13 +1883,6 @@ static inline unsigned short float_32_to_16(const float *in)
return ret;
}
void * CDECL wined3d_surface_get_parent(const struct wined3d_surface *surface)
{
TRACE("surface %p.\n", surface);
return surface->resource.parent;
}
DWORD CDECL wined3d_surface_get_pitch(const struct wined3d_surface *surface)
{
unsigned int alignment;

View File

@ -84,7 +84,6 @@
@ cdecl wined3d_device_get_stream_output(ptr long 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_surface_from_dc(ptr ptr)
@ cdecl wined3d_device_get_swapchain(ptr long)
@ cdecl wined3d_device_get_swapchain_count(ptr)
@ cdecl wined3d_device_get_texture(ptr long)
@ -221,7 +220,6 @@
@ cdecl wined3d_stateblock_decref(ptr)
@ cdecl wined3d_stateblock_incref(ptr)
@ cdecl wined3d_surface_get_parent(ptr)
@ cdecl wined3d_surface_get_pitch(ptr)
@ cdecl wined3d_swapchain_create(ptr ptr ptr ptr ptr)

View File

@ -2202,7 +2202,6 @@ HRESULT __cdecl wined3d_device_get_stream_source(const struct wined3d_device *de
UINT stream_idx, struct wined3d_buffer **buffer, UINT *offset, UINT *stride);
HRESULT __cdecl wined3d_device_get_stream_source_freq(const struct wined3d_device *device,
UINT stream_idx, UINT *divider);
struct wined3d_surface * __cdecl wined3d_device_get_surface_from_dc(const struct wined3d_device *device, HDC dc);
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);
@ -2473,7 +2472,6 @@ HRESULT __cdecl wined3d_stateblock_create(struct wined3d_device *device,
ULONG __cdecl wined3d_stateblock_decref(struct wined3d_stateblock *stateblock);
ULONG __cdecl wined3d_stateblock_incref(struct wined3d_stateblock *stateblock);
void * __cdecl wined3d_surface_get_parent(const struct wined3d_surface *surface);
DWORD __cdecl wined3d_surface_get_pitch(const struct wined3d_surface *surface);
HRESULT __cdecl wined3d_swapchain_create(struct wined3d_device *device, struct wined3d_swapchain_desc *desc,