Commit 312cb811 authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

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

parent ca6b2998
......@@ -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;
}
}
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment