ddraw: Validate the primary surface format in ddraw_surface7_Restore().

Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Henri Verbeet 2017-02-01 12:02:57 +01:00 committed by Alexandre Julliard
parent ca6b29983b
commit 312cb81138
5 changed files with 69 additions and 3 deletions

View File

@ -3625,6 +3625,7 @@ static HRESULT WINAPI ddraw_surface7_Restore(IDirectDrawSurface7 *iface)
if (surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
{
struct wined3d_swapchain *swapchain = surface->ddraw->wined3d_swapchain;
struct wined3d_sub_resource_desc wined3d_desc;
struct wined3d_display_mode mode;
HRESULT hr;
@ -3634,10 +3635,23 @@ static HRESULT WINAPI ddraw_surface7_Restore(IDirectDrawSurface7 *iface)
return hr;
}
if (mode.width != surface->surface_desc.dwWidth || mode.height != surface->surface_desc.dwHeight)
if (FAILED(hr = wined3d_texture_get_sub_resource_desc(surface->wined3d_texture, 0, &wined3d_desc)))
{
WARN("Display mode %ux%u doesn't match surface dimensions %ux%u.\n",
mode.width, mode.height, surface->surface_desc.dwWidth, surface->surface_desc.dwHeight);
WARN("Failed to get resource desc, hr %#x.\n", hr);
return hr;
}
if (mode.width != wined3d_desc.width || mode.height != wined3d_desc.height)
{
WARN("Display mode dimensions %ux%u don't match surface dimensions %ux%u.\n",
mode.width, mode.height, wined3d_desc.width, wined3d_desc.height);
return DDERR_WRONGMODE;
}
if (mode.format_id != wined3d_desc.format)
{
WARN("Display mode format %#x doesn't match surface format %#x.\n",
mode.format_id, wined3d_desc.format);
return DDERR_WRONGMODE;
}
}

View File

@ -4626,6 +4626,19 @@ static void test_primary_palette(void)
hr = IDirectDrawSurface_GetPalette(primary, &tmp);
ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface_IsLost(primary);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
hr = set_display_mode(ddraw, 640, 480);
ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
hr = IDirectDrawSurface_IsLost(primary);
ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface_Restore(primary);
ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface_IsLost(primary);
ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
done:
refcount = IDirectDrawSurface_Release(backbuffer);
ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);

View File

@ -5673,6 +5673,19 @@ static void test_primary_palette(void)
hr = IDirectDrawSurface_GetPalette(primary, &tmp);
ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface_IsLost(primary);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
hr = set_display_mode(ddraw, 640, 480);
ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
hr = IDirectDrawSurface_IsLost(primary);
ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface_Restore(primary);
ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface_IsLost(primary);
ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
done:
refcount = IDirectDrawSurface_Release(backbuffer);
ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);

View File

@ -6944,6 +6944,19 @@ static void test_primary_palette(void)
hr = IDirectDrawSurface4_GetPalette(primary, &tmp);
ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface4_IsLost(primary);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
hr = set_display_mode(ddraw, 640, 480);
ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
hr = IDirectDrawSurface4_IsLost(primary);
ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface4_Restore(primary);
ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface4_IsLost(primary);
ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
done:
refcount = IDirectDrawSurface4_Release(backbuffer);
ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);

View File

@ -6867,6 +6867,19 @@ static void test_primary_palette(void)
hr = IDirectDrawSurface7_GetPalette(primary, &tmp);
ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface7_IsLost(primary);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
hr = set_display_mode(ddraw, 640, 480);
ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
hr = IDirectDrawSurface7_IsLost(primary);
ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface7_Restore(primary);
ok(hr == DDERR_WRONGMODE, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface7_IsLost(primary);
ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
done:
refcount = IDirectDrawSurface7_Release(backbuffer);
ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);