ddraw/tests: Test system memory surface with lost device for ddraw2.

Signed-off-by: Paul Gofman <pgofman@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Paul Gofman 2020-04-16 16:57:33 +03:00 committed by Alexandre Julliard
parent f2ba4d78d3
commit 47e777d6ea
1 changed files with 45 additions and 4 deletions

View File

@ -8150,6 +8150,7 @@ static void test_palette_alpha(void)
static void test_lost_device(void)
{
IDirectDrawSurface *surface, *back_buffer;
IDirectDrawSurface *sysmem_surface;
DDSURFACEDESC surface_desc;
HWND window1, window2;
IDirectDraw2 *ddraw;
@ -8165,7 +8166,7 @@ static void test_lost_device(void)
ddraw = create_ddraw();
ok(!!ddraw, "Failed to create a ddraw object.\n");
hr = IDirectDraw2_SetCooperativeLevel(ddraw, window1, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
memset(&surface_desc, 0, sizeof(surface_desc));
surface_desc.dwSize = sizeof(surface_desc);
@ -8173,12 +8174,23 @@ static void test_lost_device(void)
surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
surface_desc.dwBackBufferCount = 1;
hr = IDirectDraw2_CreateSurface(ddraw, &surface_desc, &surface, NULL);
ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
memset(&surface_desc, 0, sizeof(surface_desc));
surface_desc.dwSize = sizeof(surface_desc);
surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
surface_desc.dwWidth = 100;
surface_desc.dwHeight = 100;
hr = IDirectDraw2_CreateSurface(ddraw, &surface_desc, &sysmem_surface, NULL);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface_IsLost(surface);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface_Flip(surface, NULL, DDFLIP_WAIT);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface_IsLost(sysmem_surface);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
ret = SetForegroundWindow(GetDesktopWindow());
ok(ret, "Failed to set foreground window.\n");
@ -8186,6 +8198,8 @@ static void test_lost_device(void)
ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface_Flip(surface, NULL, DDFLIP_WAIT);
ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface_IsLost(sysmem_surface);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
ret = SetForegroundWindow(window1);
ok(ret, "Failed to set foreground window.\n");
@ -8193,6 +8207,8 @@ static void test_lost_device(void)
ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface_Flip(surface, NULL, DDFLIP_WAIT);
ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface_IsLost(sysmem_surface);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
hr = restore_surfaces(ddraw);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
@ -8200,6 +8216,8 @@ static void test_lost_device(void)
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface_Flip(surface, NULL, DDFLIP_WAIT);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface_IsLost(sysmem_surface);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirectDraw2_SetCooperativeLevel(ddraw, window1, DDSCL_NORMAL);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
@ -8207,6 +8225,8 @@ static void test_lost_device(void)
todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface_Flip(surface, NULL, DDFLIP_WAIT);
todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface_IsLost(sysmem_surface);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
/* Trying to restore the primary will crash, probably because flippable
* surfaces can't exist in DDSCL_NORMAL. */
@ -8216,7 +8236,7 @@ static void test_lost_device(void)
surface_desc.dwFlags = DDSD_CAPS;
surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
hr = IDirectDraw2_CreateSurface(ddraw, &surface_desc, &surface, NULL);
ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface_IsLost(surface);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
@ -8225,21 +8245,29 @@ static void test_lost_device(void)
ok(ret, "Failed to set foreground window.\n");
hr = IDirectDrawSurface_IsLost(surface);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface_IsLost(sysmem_surface);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
ret = SetForegroundWindow(window1);
ok(ret, "Failed to set foreground window.\n");
hr = IDirectDrawSurface_IsLost(surface);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface_IsLost(sysmem_surface);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirectDraw2_SetCooperativeLevel(ddraw, window1, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface_IsLost(surface);
ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface_IsLost(sysmem_surface);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
hr = restore_surfaces(ddraw);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface_IsLost(surface);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface_IsLost(sysmem_surface);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
IDirectDrawSurface_Release(surface);
memset(&surface_desc, 0, sizeof(surface_desc));
@ -8248,7 +8276,7 @@ static void test_lost_device(void)
surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
surface_desc.dwBackBufferCount = 1;
hr = IDirectDraw2_CreateSurface(ddraw, &surface_desc, &surface, NULL);
ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirectDraw2_SetCooperativeLevel(ddraw, window1, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
@ -8256,6 +8284,8 @@ static void test_lost_device(void)
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface_Flip(surface, NULL, DDFLIP_WAIT);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface_IsLost(sysmem_surface);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirectDraw2_SetCooperativeLevel(ddraw, window1, DDSCL_NORMAL | DDSCL_FULLSCREEN);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
@ -8263,6 +8293,8 @@ static void test_lost_device(void)
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface_Flip(surface, NULL, DDFLIP_WAIT);
ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface_IsLost(sysmem_surface);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirectDraw2_SetCooperativeLevel(ddraw, window1, DDSCL_NORMAL);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
@ -8270,6 +8302,8 @@ static void test_lost_device(void)
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface_Flip(surface, NULL, DDFLIP_WAIT);
ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface_IsLost(sysmem_surface);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirectDraw2_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
@ -8277,6 +8311,8 @@ static void test_lost_device(void)
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface_Flip(surface, NULL, DDFLIP_WAIT);
ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface_IsLost(sysmem_surface);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirectDraw2_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL | DDSCL_FULLSCREEN);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
@ -8284,6 +8320,8 @@ static void test_lost_device(void)
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface_Flip(surface, NULL, DDFLIP_WAIT);
ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface_IsLost(sysmem_surface);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirectDraw2_SetCooperativeLevel(ddraw, window2, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
@ -8291,6 +8329,8 @@ static void test_lost_device(void)
ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface_Flip(surface, NULL, DDFLIP_WAIT);
ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface_IsLost(sysmem_surface);
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
memset(&caps, 0, sizeof(caps));
caps.dwCaps = DDSCAPS_FLIP;
@ -8305,6 +8345,7 @@ static void test_lost_device(void)
ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
IDirectDrawSurface_Release(back_buffer);
IDirectDrawSurface_Release(sysmem_surface);
IDirectDrawSurface_Release(surface);
refcount = IDirectDraw2_Release(ddraw);
ok(!refcount, "Got unexpected refcount %u.\n", refcount);