Henri Verbeet : ddraw: Validate the primary surface format in ddraw_surface7_Restore().
Alexandre Julliard
julliard at winehq.org
Wed Feb 1 15:26:07 CST 2017
Module: wine
Branch: master
Commit: 312cb81138a3bd947a3e9ec8cf94774e852ad0df
URL: http://source.winehq.org/git/wine.git/?a=commit;h=312cb81138a3bd947a3e9ec8cf94774e852ad0df
Author: Henri Verbeet <hverbeet at codeweavers.com>
Date: Wed Feb 1 12:02:57 2017 +0100
ddraw: Validate the primary surface format in ddraw_surface7_Restore().
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/ddraw/surface.c | 20 +++++++++++++++++---
dlls/ddraw/tests/ddraw1.c | 13 +++++++++++++
dlls/ddraw/tests/ddraw2.c | 13 +++++++++++++
dlls/ddraw/tests/ddraw4.c | 13 +++++++++++++
dlls/ddraw/tests/ddraw7.c | 13 +++++++++++++
5 files changed, 69 insertions(+), 3 deletions(-)
diff --git a/dlls/ddraw/surface.c b/dlls/ddraw/surface.c
index c46472c..710f6cd 100644
--- a/dlls/ddraw/surface.c
+++ b/dlls/ddraw/surface.c
@@ -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;
}
}
diff --git a/dlls/ddraw/tests/ddraw1.c b/dlls/ddraw/tests/ddraw1.c
index 28b67fd..c57fa67 100644
--- a/dlls/ddraw/tests/ddraw1.c
+++ b/dlls/ddraw/tests/ddraw1.c
@@ -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);
diff --git a/dlls/ddraw/tests/ddraw2.c b/dlls/ddraw/tests/ddraw2.c
index f27889f..853a0d4 100644
--- a/dlls/ddraw/tests/ddraw2.c
+++ b/dlls/ddraw/tests/ddraw2.c
@@ -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);
diff --git a/dlls/ddraw/tests/ddraw4.c b/dlls/ddraw/tests/ddraw4.c
index bcbc2f3..93987e9 100644
--- a/dlls/ddraw/tests/ddraw4.c
+++ b/dlls/ddraw/tests/ddraw4.c
@@ -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);
diff --git a/dlls/ddraw/tests/ddraw7.c b/dlls/ddraw/tests/ddraw7.c
index 3774afb..c29a50d 100644
--- a/dlls/ddraw/tests/ddraw7.c
+++ b/dlls/ddraw/tests/ddraw7.c
@@ -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);
More information about the wine-cvs
mailing list