wined3d: Be more lenient with wined3d_texture_get_dc() calls from ddraw.

Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Henri Verbeet 2016-04-13 12:18:47 +02:00 committed by Alexandre Julliard
parent 02e5560d99
commit c3d74913b7
10 changed files with 43 additions and 44 deletions

View File

@ -312,11 +312,7 @@ static HRESULT WINAPI d3d9_surface_ReleaseDC(IDirect3DSurface9 *iface, HDC dc)
hr = wined3d_texture_release_dc(surface->wined3d_texture, surface->sub_resource_idx, dc);
wined3d_mutex_unlock();
switch (hr)
{
case WINEDDERR_NODC: return D3DERR_INVALIDCALL;
default: return hr;
}
return hr;
}
static const struct IDirect3DSurface9Vtbl d3d9_surface_vtbl =

View File

@ -7683,7 +7683,7 @@ static void test_getdc(void)
ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", testdata[i].name, hr);
dc2 = (void *)0x1234;
hr = IDirect3DSurface9_GetDC(surface, &dc2);
todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
ok(dc2 == (void *)0x1234, "Got unexpected dc %p for format %s.\n", dc, testdata[i].name);
hr = IDirect3DSurface9_ReleaseDC(surface, dc);
ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", testdata[i].name, hr);

View File

@ -2138,7 +2138,9 @@ static HRESULT WINAPI ddraw_surface7_GetDC(IDirectDrawSurface7 *iface, HDC *dc)
return DDERR_INVALIDPARAMS;
wined3d_mutex_lock();
if (surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
if (surface->dc)
hr = DDERR_DCALREADYCREATED;
else 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, dc);
@ -2234,7 +2236,11 @@ static HRESULT WINAPI ddraw_surface7_ReleaseDC(IDirectDrawSurface7 *iface, HDC h
TRACE("iface %p, dc %p.\n", iface, hdc);
wined3d_mutex_lock();
if (SUCCEEDED(hr = wined3d_texture_release_dc(surface->wined3d_texture, surface->sub_resource_idx, hdc)))
if (!surface->dc)
{
hr = DDERR_NODC;
}
else 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)
@ -6096,10 +6102,11 @@ HRESULT ddraw_surface_create(struct ddraw *ddraw, const DDSURFACEDESC2 *surface_
* address. Some of those also assume that this address is valid even when
* the surface isn't mapped, and that updates done this way will be
* visible on the screen. The game Nox is such an application,
* Commandos: Behind Enemy Lines is another. We set
* WINED3D_TEXTURE_CREATE_PIN_SYSMEM because of this. */
* Commandos: Behind Enemy Lines is another. Setting
* WINED3D_TEXTURE_CREATE_GET_DC_LENIENT will ensure this. */
if (FAILED(hr = wined3d_texture_create(ddraw->wined3d_device, &wined3d_desc, levels,
WINED3D_TEXTURE_CREATE_PIN_SYSMEM, NULL, texture, &ddraw_texture_wined3d_parent_ops, &wined3d_texture)))
WINED3D_TEXTURE_CREATE_GET_DC_LENIENT, NULL, texture,
&ddraw_texture_wined3d_parent_ops, &wined3d_texture)))
{
WARN("Failed to create wined3d texture, hr %#x.\n", hr);
HeapFree(GetProcessHeap(), 0, texture);
@ -6217,7 +6224,7 @@ HRESULT ddraw_surface_create(struct ddraw *ddraw, const DDSURFACEDESC2 *surface_
desc->u5.dwBackBufferCount = 0;
if (FAILED(hr = wined3d_texture_create(ddraw->wined3d_device, &wined3d_desc, 1,
WINED3D_TEXTURE_CREATE_PIN_SYSMEM, NULL, texture,
WINED3D_TEXTURE_CREATE_GET_DC_LENIENT, NULL, texture,
&ddraw_texture_wined3d_parent_ops, &wined3d_texture)))
{
HeapFree(GetProcessHeap(), 0, texture);

View File

@ -8741,9 +8741,9 @@ static void test_getdc(void)
hr = IDirectDrawSurface_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
hr = IDirectDrawSurface_GetDC(surface, &dc);
todo_wine ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
hr = IDirectDrawSurface_ReleaseDC(surface, dc);
todo_wine ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
hr = IDirectDrawSurface_Unlock(surface, NULL);
ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
@ -8777,9 +8777,9 @@ static void test_getdc(void)
hr = IDirectDrawSurface_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
hr = IDirectDrawSurface_GetDC(surface, &dc);
todo_wine ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
hr = IDirectDrawSurface_ReleaseDC(surface, dc);
todo_wine ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
hr = IDirectDrawSurface_Unlock(surface, NULL);
ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);

View File

@ -9848,9 +9848,9 @@ static void test_getdc(void)
hr = IDirectDrawSurface_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
hr = IDirectDrawSurface_GetDC(surface, &dc);
todo_wine ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
hr = IDirectDrawSurface_ReleaseDC(surface, dc);
todo_wine ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
hr = IDirectDrawSurface_Unlock(surface, NULL);
ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
@ -9884,9 +9884,9 @@ static void test_getdc(void)
hr = IDirectDrawSurface_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
hr = IDirectDrawSurface_GetDC(surface, &dc);
todo_wine ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
hr = IDirectDrawSurface_ReleaseDC(surface, dc);
todo_wine ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
hr = IDirectDrawSurface_Unlock(surface, NULL);
ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);

View File

@ -11126,9 +11126,9 @@ static void test_getdc(void)
hr = IDirectDrawSurface4_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
hr = IDirectDrawSurface4_GetDC(surface, &dc);
todo_wine ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
todo_wine ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
hr = IDirectDrawSurface4_Unlock(surface, NULL);
ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
@ -11162,9 +11162,9 @@ static void test_getdc(void)
hr = IDirectDrawSurface4_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
hr = IDirectDrawSurface4_GetDC(surface, &dc);
todo_wine ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
todo_wine ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
hr = IDirectDrawSurface4_Unlock(surface, NULL);
ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);

View File

@ -11394,9 +11394,9 @@ static void test_getdc(void)
hr = IDirectDrawSurface7_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
hr = IDirectDrawSurface7_GetDC(surface, &dc);
todo_wine ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
todo_wine ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
hr = IDirectDrawSurface7_Unlock(surface, NULL);
ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);
@ -11430,9 +11430,9 @@ static void test_getdc(void)
hr = IDirectDrawSurface7_Lock(surface, NULL, &map_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
ok(SUCCEEDED(hr), "Failed to map surface for format %s, hr %#x.\n", test_data[i].name, hr);
hr = IDirectDrawSurface7_GetDC(surface, &dc);
todo_wine ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
ok(SUCCEEDED(hr), "Failed to get DC for format %s, hr %#x.\n", test_data[i].name, hr);
hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
todo_wine ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
ok(SUCCEEDED(hr), "Failed to release DC for format %s, hr %#x.\n", test_data[i].name, hr);
hr = IDirectDrawSurface7_Unlock(surface, NULL);
ok(SUCCEEDED(hr), "Failed to unmap surface for format %s, hr %#x.\n", test_data[i].name, hr);

View File

@ -191,8 +191,8 @@ static HRESULT wined3d_texture_init(struct wined3d_texture *texture, const struc
texture->filter_type = (desc->usage & WINED3DUSAGE_AUTOGENMIPMAP) ? WINED3D_TEXF_LINEAR : WINED3D_TEXF_NONE;
texture->lod = 0;
texture->flags |= WINED3D_TEXTURE_POW2_MAT_IDENT | WINED3D_TEXTURE_NORMALIZED_COORDS;
if (flags & WINED3D_TEXTURE_CREATE_PIN_SYSMEM)
texture->flags |= WINED3D_TEXTURE_PIN_SYSMEM;
if (flags & WINED3D_TEXTURE_CREATE_GET_DC_LENIENT)
texture->flags |= WINED3D_TEXTURE_PIN_SYSMEM | WINED3D_TEXTURE_GET_DC_LENIENT;
return WINED3D_OK;
}
@ -2238,12 +2238,7 @@ HRESULT CDECL wined3d_texture_get_dc(struct wined3d_texture *texture, unsigned i
surface = sub_resource->u.surface;
/* Give more detailed info for ddraw. */
if (surface->flags & SFLAG_DCINUSE)
return WINEDDERR_DCALREADYCREATED;
/* Can't GetDC if the surface is locked. */
if (sub_resource->map_count)
if (sub_resource->map_count && !(texture->flags & WINED3D_TEXTURE_GET_DC_LENIENT))
return WINED3DERR_INVALIDCALL;
if (device->d3d_initialized)
@ -2270,7 +2265,8 @@ HRESULT CDECL wined3d_texture_get_dc(struct wined3d_texture *texture, unsigned i
if (context)
context_release(context);
surface->flags |= SFLAG_DCINUSE;
if (!(texture->flags & WINED3D_TEXTURE_GET_DC_LENIENT))
surface->flags |= SFLAG_DCINUSE;
++texture->resource.map_count;
++sub_resource->map_count;
@ -2300,19 +2296,20 @@ HRESULT CDECL wined3d_texture_release_dc(struct wined3d_texture *texture, unsign
surface = sub_resource->u.surface;
if (!(surface->flags & SFLAG_DCINUSE))
return WINEDDERR_NODC;
if (!(texture->flags & WINED3D_TEXTURE_GET_DC_LENIENT) && !(surface->flags & SFLAG_DCINUSE))
return WINED3DERR_INVALIDCALL;
if (surface->hDC != dc)
{
WARN("Application tries to release invalid DC %p, surface DC is %p.\n",
dc, surface->hDC);
return WINEDDERR_NODC;
return WINED3DERR_INVALIDCALL;
}
--sub_resource->map_count;
--texture->resource.map_count;
surface->flags &= ~SFLAG_DCINUSE;
if (!(texture->flags & WINED3D_TEXTURE_GET_DC_LENIENT))
surface->flags &= ~SFLAG_DCINUSE;
if (surface->resource.map_binding == WINED3D_LOCATION_USER_MEMORY
|| (surface->container->flags & WINED3D_TEXTURE_PIN_SYSMEM

View File

@ -2438,6 +2438,7 @@ struct wined3d_texture_ops
#define WINED3D_TEXTURE_CONVERTED 0x00000100
#define WINED3D_TEXTURE_PIN_SYSMEM 0x00000200
#define WINED3D_TEXTURE_NORMALIZED_COORDS 0x00000400
#define WINED3D_TEXTURE_GET_DC_LENIENT 0x00000800
#define WINED3D_TEXTURE_ASYNC_COLOR_KEY 0x00000001

View File

@ -46,8 +46,6 @@
#define WINED3DERR_INVALIDCALL MAKE_WINED3DHRESULT(2156)
#define WINEDDERR_NOTAOVERLAYSURFACE MAKE_WINED3DHRESULT(580)
#define WINEDDERR_NOTLOCKED MAKE_WINED3DHRESULT(584)
#define WINEDDERR_NODC MAKE_WINED3DHRESULT(586)
#define WINEDDERR_DCALREADYCREATED MAKE_WINED3DHRESULT(620)
#define WINEDDERR_SURFACEBUSY MAKE_WINED3DHRESULT(430)
#define WINEDDERR_INVALIDRECT MAKE_WINED3DHRESULT(150)
#define WINEDDERR_OVERLAYNOTVISIBLE MAKE_WINED3DHRESULT(577)
@ -1470,7 +1468,7 @@ enum wined3d_display_rotation
#define WINED3D_TEXTURE_CREATE_MAPPABLE 0x00000001
#define WINED3D_TEXTURE_CREATE_DISCARD 0x00000002
#define WINED3D_TEXTURE_CREATE_PIN_SYSMEM 0x00000004
#define WINED3D_TEXTURE_CREATE_GET_DC_LENIENT 0x00000004
#define WINED3D_APPEND_ALIGNED_ELEMENT 0xffffffff