diff --git a/dlls/ddraw/tests/Makefile.in b/dlls/ddraw/tests/Makefile.in index 60eeef80d25..a3d0ce5cf12 100644 --- a/dlls/ddraw/tests/Makefile.in +++ b/dlls/ddraw/tests/Makefile.in @@ -9,6 +9,5 @@ C_SRCS = \ ddraw7.c \ ddrawmodes.c \ dsurface.c \ - overlay.c \ refcount.c \ visual.c diff --git a/dlls/ddraw/tests/ddraw1.c b/dlls/ddraw/tests/ddraw1.c index 67410935f79..4090b264a52 100644 --- a/dlls/ddraw/tests/ddraw1.c +++ b/dlls/ddraw/tests/ddraw1.c @@ -8410,6 +8410,99 @@ done: DestroyWindow(window); } +static void test_overlay_rect(void) +{ + IDirectDrawSurface *overlay, *primary; + DDSURFACEDESC surface_desc; + RECT rect = {0, 0, 64, 64}; + IDirectDraw *ddraw; + LONG pos_x, pos_y; + HRESULT hr, hr2; + HWND window; + HDC dc; + + window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW, + 0, 0, 640, 480, 0, 0, 0, 0); + ddraw = create_ddraw(); + ok(!!ddraw, "Failed to create a ddraw object.\n"); + hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL); + ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr); + + if (!(overlay = create_overlay(ddraw, 64, 64, MAKEFOURCC('U','Y','V','Y')))) + { + skip("Failed to create a UYVY overlay, skipping test.\n"); + goto done; + } + + memset(&surface_desc, 0, sizeof(surface_desc)); + surface_desc.dwSize = sizeof(surface_desc); + surface_desc.dwFlags = DDSD_CAPS; + surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; + hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &primary, NULL); + ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr); + + /* On Windows 7, and probably Vista, UpdateOverlay() will return + * DDERR_OUTOFCAPS if the dwm is active. Calling GetDC() on the primary + * surface prevents this by disabling the dwm. */ + hr = IDirectDrawSurface_GetDC(primary, &dc); + ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr); + hr = IDirectDrawSurface_ReleaseDC(primary, dc); + ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr); + + /* The dx sdk sort of implies that rect must be set when DDOVER_SHOW is + * used. This is not true in Windows Vista and earlier, but changed in + * Windows 7. */ + hr = IDirectDrawSurface_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_SHOW, NULL); + ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr); + hr = IDirectDrawSurface_UpdateOverlay(overlay, NULL, primary, NULL, DDOVER_HIDE, NULL); + ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr); + hr = IDirectDrawSurface_UpdateOverlay(overlay, NULL, primary, NULL, DDOVER_SHOW, NULL); + ok(hr == DD_OK || hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr); + + /* Show that the overlay position is the (top, left) coordinate of the + * destination rectangle. */ + OffsetRect(&rect, 32, 16); + hr = IDirectDrawSurface_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_SHOW, NULL); + ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr); + pos_x = -1; pos_y = -1; + hr = IDirectDrawSurface_GetOverlayPosition(overlay, &pos_x, &pos_y); + ok(SUCCEEDED(hr), "Failed to get overlay position, hr %#x.\n", hr); + ok(pos_x == rect.left, "Got unexpected pos_x %d, expected %d.\n", pos_x, rect.left); + ok(pos_y == rect.top, "Got unexpected pos_y %d, expected %d.\n", pos_y, rect.top); + + /* Passing a NULL dest rect sets the position to 0/0. Visually it can be + * seen that the overlay overlays the whole primary(==screen). */ + hr2 = IDirectDrawSurface_UpdateOverlay(overlay, NULL, primary, NULL, 0, NULL); + ok(hr2 == DD_OK || hr2 == DDERR_INVALIDPARAMS || hr2 == DDERR_OUTOFCAPS, "Got unexpected hr %#x.\n", hr2); + hr = IDirectDrawSurface_GetOverlayPosition(overlay, &pos_x, &pos_y); + ok(SUCCEEDED(hr), "Failed to get overlay position, hr %#x.\n", hr); + if (SUCCEEDED(hr2)) + { + ok(!pos_x, "Got unexpected pos_x %d.\n", pos_x); + ok(!pos_y, "Got unexpected pos_y %d.\n", pos_y); + } + else + { + ok(pos_x == 32, "Got unexpected pos_x %d.\n", pos_x); + ok(pos_y == 16, "Got unexpected pos_y %d.\n", pos_y); + } + + /* The position cannot be retrieved when the overlay is not shown. */ + hr = IDirectDrawSurface_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_HIDE, NULL); + ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr); + pos_x = -1; pos_y = -1; + hr = IDirectDrawSurface_GetOverlayPosition(overlay, &pos_x, &pos_y); + ok(hr == DDERR_OVERLAYNOTVISIBLE, "Got unexpected hr %#x.\n", hr); + ok(!pos_x, "Got unexpected pos_x %d.\n", pos_x); + ok(!pos_y, "Got unexpected pos_y %d.\n", pos_y); + + IDirectDrawSurface_Release(primary); + IDirectDrawSurface_Release(overlay); +done: + IDirectDraw_Release(ddraw); + DestroyWindow(window); +} + START_TEST(ddraw1) { IDirectDraw *ddraw; @@ -8485,4 +8578,5 @@ START_TEST(ddraw1) test_lockrect_invalid(); test_yv12_overlay(); test_offscreen_overlay(); + test_overlay_rect(); } diff --git a/dlls/ddraw/tests/ddraw2.c b/dlls/ddraw/tests/ddraw2.c index fb9f816641a..5c0bb5208f5 100644 --- a/dlls/ddraw/tests/ddraw2.c +++ b/dlls/ddraw/tests/ddraw2.c @@ -9517,6 +9517,99 @@ done: DestroyWindow(window); } +static void test_overlay_rect(void) +{ + IDirectDrawSurface *overlay, *primary; + DDSURFACEDESC surface_desc; + RECT rect = {0, 0, 64, 64}; + IDirectDraw2 *ddraw; + LONG pos_x, pos_y; + HRESULT hr, hr2; + HWND window; + HDC dc; + + window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW, + 0, 0, 640, 480, 0, 0, 0, 0); + ddraw = create_ddraw(); + ok(!!ddraw, "Failed to create a ddraw object.\n"); + hr = IDirectDraw2_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL); + ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr); + + if (!(overlay = create_overlay(ddraw, 64, 64, MAKEFOURCC('U','Y','V','Y')))) + { + skip("Failed to create a UYVY overlay, skipping test.\n"); + goto done; + } + + memset(&surface_desc, 0, sizeof(surface_desc)); + surface_desc.dwSize = sizeof(surface_desc); + surface_desc.dwFlags = DDSD_CAPS; + surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; + hr = IDirectDraw2_CreateSurface(ddraw, &surface_desc, &primary, NULL); + ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr); + + /* On Windows 7, and probably Vista, UpdateOverlay() will return + * DDERR_OUTOFCAPS if the dwm is active. Calling GetDC() on the primary + * surface prevents this by disabling the dwm. */ + hr = IDirectDrawSurface_GetDC(primary, &dc); + ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr); + hr = IDirectDrawSurface_ReleaseDC(primary, dc); + ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr); + + /* The dx sdk sort of implies that rect must be set when DDOVER_SHOW is + * used. This is not true in Windows Vista and earlier, but changed in + * Windows 7. */ + hr = IDirectDrawSurface_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_SHOW, NULL); + ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr); + hr = IDirectDrawSurface_UpdateOverlay(overlay, NULL, primary, NULL, DDOVER_HIDE, NULL); + ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr); + hr = IDirectDrawSurface_UpdateOverlay(overlay, NULL, primary, NULL, DDOVER_SHOW, NULL); + ok(hr == DD_OK || hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr); + + /* Show that the overlay position is the (top, left) coordinate of the + * destination rectangle. */ + OffsetRect(&rect, 32, 16); + hr = IDirectDrawSurface_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_SHOW, NULL); + ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr); + pos_x = -1; pos_y = -1; + hr = IDirectDrawSurface_GetOverlayPosition(overlay, &pos_x, &pos_y); + ok(SUCCEEDED(hr), "Failed to get overlay position, hr %#x.\n", hr); + ok(pos_x == rect.left, "Got unexpected pos_x %d, expected %d.\n", pos_x, rect.left); + ok(pos_y == rect.top, "Got unexpected pos_y %d, expected %d.\n", pos_y, rect.top); + + /* Passing a NULL dest rect sets the position to 0/0. Visually it can be + * seen that the overlay overlays the whole primary(==screen). */ + hr2 = IDirectDrawSurface_UpdateOverlay(overlay, NULL, primary, NULL, 0, NULL); + ok(hr2 == DD_OK || hr2 == DDERR_INVALIDPARAMS || hr2 == DDERR_OUTOFCAPS, "Got unexpected hr %#x.\n", hr2); + hr = IDirectDrawSurface_GetOverlayPosition(overlay, &pos_x, &pos_y); + ok(SUCCEEDED(hr), "Failed to get overlay position, hr %#x.\n", hr); + if (SUCCEEDED(hr2)) + { + ok(!pos_x, "Got unexpected pos_x %d.\n", pos_x); + ok(!pos_y, "Got unexpected pos_y %d.\n", pos_y); + } + else + { + ok(pos_x == 32, "Got unexpected pos_x %d.\n", pos_x); + ok(pos_y == 16, "Got unexpected pos_y %d.\n", pos_y); + } + + /* The position cannot be retrieved when the overlay is not shown. */ + hr = IDirectDrawSurface_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_HIDE, NULL); + ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr); + pos_x = -1; pos_y = -1; + hr = IDirectDrawSurface_GetOverlayPosition(overlay, &pos_x, &pos_y); + ok(hr == DDERR_OVERLAYNOTVISIBLE, "Got unexpected hr %#x.\n", hr); + ok(!pos_x, "Got unexpected pos_x %d.\n", pos_x); + ok(!pos_y, "Got unexpected pos_y %d.\n", pos_y); + + IDirectDrawSurface_Release(primary); + IDirectDrawSurface_Release(overlay); +done: + IDirectDraw2_Release(ddraw); + DestroyWindow(window); +} + START_TEST(ddraw2) { IDirectDraw2 *ddraw; @@ -9599,4 +9692,5 @@ START_TEST(ddraw2) test_lockrect_invalid(); test_yv12_overlay(); test_offscreen_overlay(); + test_overlay_rect(); } diff --git a/dlls/ddraw/tests/ddraw4.c b/dlls/ddraw/tests/ddraw4.c index 1be75c29a0d..950d4582afc 100644 --- a/dlls/ddraw/tests/ddraw4.c +++ b/dlls/ddraw/tests/ddraw4.c @@ -10692,6 +10692,99 @@ done: DestroyWindow(window); } +static void test_overlay_rect(void) +{ + IDirectDrawSurface4 *overlay, *primary; + DDSURFACEDESC2 surface_desc; + RECT rect = {0, 0, 64, 64}; + IDirectDraw4 *ddraw; + LONG pos_x, pos_y; + HRESULT hr, hr2; + HWND window; + HDC dc; + + window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW, + 0, 0, 640, 480, 0, 0, 0, 0); + ddraw = create_ddraw(); + ok(!!ddraw, "Failed to create a ddraw object.\n"); + hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL); + ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr); + + if (!(overlay = create_overlay(ddraw, 64, 64, MAKEFOURCC('U','Y','V','Y')))) + { + skip("Failed to create a UYVY overlay, skipping test.\n"); + goto done; + } + + memset(&surface_desc, 0, sizeof(surface_desc)); + surface_desc.dwSize = sizeof(surface_desc); + surface_desc.dwFlags = DDSD_CAPS; + surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; + hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &primary, NULL); + ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr); + + /* On Windows 7, and probably Vista, UpdateOverlay() will return + * DDERR_OUTOFCAPS if the dwm is active. Calling GetDC() on the primary + * surface prevents this by disabling the dwm. */ + hr = IDirectDrawSurface4_GetDC(primary, &dc); + ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr); + hr = IDirectDrawSurface4_ReleaseDC(primary, dc); + ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr); + + /* The dx sdk sort of implies that rect must be set when DDOVER_SHOW is + * used. This is not true in Windows Vista and earlier, but changed in + * Windows 7. */ + hr = IDirectDrawSurface4_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_SHOW, NULL); + ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr); + hr = IDirectDrawSurface4_UpdateOverlay(overlay, NULL, primary, NULL, DDOVER_HIDE, NULL); + ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr); + hr = IDirectDrawSurface4_UpdateOverlay(overlay, NULL, primary, NULL, DDOVER_SHOW, NULL); + ok(hr == DD_OK || hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr); + + /* Show that the overlay position is the (top, left) coordinate of the + * destination rectangle. */ + OffsetRect(&rect, 32, 16); + hr = IDirectDrawSurface4_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_SHOW, NULL); + ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr); + pos_x = -1; pos_y = -1; + hr = IDirectDrawSurface4_GetOverlayPosition(overlay, &pos_x, &pos_y); + ok(SUCCEEDED(hr), "Failed to get overlay position, hr %#x.\n", hr); + ok(pos_x == rect.left, "Got unexpected pos_x %d, expected %d.\n", pos_x, rect.left); + ok(pos_y == rect.top, "Got unexpected pos_y %d, expected %d.\n", pos_y, rect.top); + + /* Passing a NULL dest rect sets the position to 0/0. Visually it can be + * seen that the overlay overlays the whole primary(==screen). */ + hr2 = IDirectDrawSurface4_UpdateOverlay(overlay, NULL, primary, NULL, 0, NULL); + ok(hr2 == DD_OK || hr2 == DDERR_INVALIDPARAMS || hr2 == DDERR_OUTOFCAPS, "Got unexpected hr %#x.\n", hr2); + hr = IDirectDrawSurface4_GetOverlayPosition(overlay, &pos_x, &pos_y); + ok(SUCCEEDED(hr), "Failed to get overlay position, hr %#x.\n", hr); + if (SUCCEEDED(hr2)) + { + ok(!pos_x, "Got unexpected pos_x %d.\n", pos_x); + ok(!pos_y, "Got unexpected pos_y %d.\n", pos_y); + } + else + { + ok(pos_x == 32, "Got unexpected pos_x %d.\n", pos_x); + ok(pos_y == 16, "Got unexpected pos_y %d.\n", pos_y); + } + + /* The position cannot be retrieved when the overlay is not shown. */ + hr = IDirectDrawSurface4_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_HIDE, NULL); + ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr); + pos_x = -1; pos_y = -1; + hr = IDirectDrawSurface4_GetOverlayPosition(overlay, &pos_x, &pos_y); + ok(hr == DDERR_OVERLAYNOTVISIBLE, "Got unexpected hr %#x.\n", hr); + ok(!pos_x, "Got unexpected pos_x %d.\n", pos_x); + ok(!pos_y, "Got unexpected pos_y %d.\n", pos_y); + + IDirectDrawSurface4_Release(primary); + IDirectDrawSurface4_Release(overlay); +done: + IDirectDraw4_Release(ddraw); + DestroyWindow(window); +} + START_TEST(ddraw4) { IDirectDraw4 *ddraw; @@ -10781,4 +10874,5 @@ START_TEST(ddraw4) test_lockrect_invalid(); test_yv12_overlay(); test_offscreen_overlay(); + test_overlay_rect(); } diff --git a/dlls/ddraw/tests/ddraw7.c b/dlls/ddraw/tests/ddraw7.c index d6598fe6922..216ce38a6ea 100644 --- a/dlls/ddraw/tests/ddraw7.c +++ b/dlls/ddraw/tests/ddraw7.c @@ -10971,6 +10971,99 @@ done: DestroyWindow(window); } +static void test_overlay_rect(void) +{ + IDirectDrawSurface7 *overlay, *primary; + DDSURFACEDESC2 surface_desc; + RECT rect = {0, 0, 64, 64}; + IDirectDraw7 *ddraw; + LONG pos_x, pos_y; + HRESULT hr, hr2; + HWND window; + HDC dc; + + window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW, + 0, 0, 640, 480, 0, 0, 0, 0); + ddraw = create_ddraw(); + ok(!!ddraw, "Failed to create a ddraw object.\n"); + hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL); + ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr); + + if (!(overlay = create_overlay(ddraw, 64, 64, MAKEFOURCC('U','Y','V','Y')))) + { + skip("Failed to create a UYVY overlay, skipping test.\n"); + goto done; + } + + memset(&surface_desc, 0, sizeof(surface_desc)); + surface_desc.dwSize = sizeof(surface_desc); + surface_desc.dwFlags = DDSD_CAPS; + surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; + hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &primary, NULL); + ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr); + + /* On Windows 7, and probably Vista, UpdateOverlay() will return + * DDERR_OUTOFCAPS if the dwm is active. Calling GetDC() on the primary + * surface prevents this by disabling the dwm. */ + hr = IDirectDrawSurface7_GetDC(primary, &dc); + ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr); + hr = IDirectDrawSurface7_ReleaseDC(primary, dc); + ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr); + + /* The dx sdk sort of implies that rect must be set when DDOVER_SHOW is + * used. This is not true in Windows Vista and earlier, but changed in + * Windows 7. */ + hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_SHOW, NULL); + ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr); + hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, NULL, DDOVER_HIDE, NULL); + ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr); + hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, NULL, DDOVER_SHOW, NULL); + ok(hr == DD_OK || hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr); + + /* Show that the overlay position is the (top, left) coordinate of the + * destination rectangle. */ + OffsetRect(&rect, 32, 16); + hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_SHOW, NULL); + ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr); + pos_x = -1; pos_y = -1; + hr = IDirectDrawSurface7_GetOverlayPosition(overlay, &pos_x, &pos_y); + ok(SUCCEEDED(hr), "Failed to get overlay position, hr %#x.\n", hr); + ok(pos_x == rect.left, "Got unexpected pos_x %d, expected %d.\n", pos_x, rect.left); + ok(pos_y == rect.top, "Got unexpected pos_y %d, expected %d.\n", pos_y, rect.top); + + /* Passing a NULL dest rect sets the position to 0/0. Visually it can be + * seen that the overlay overlays the whole primary(==screen). */ + hr2 = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, NULL, 0, NULL); + ok(hr2 == DD_OK || hr2 == DDERR_INVALIDPARAMS || hr2 == DDERR_OUTOFCAPS, "Got unexpected hr %#x.\n", hr2); + hr = IDirectDrawSurface7_GetOverlayPosition(overlay, &pos_x, &pos_y); + ok(SUCCEEDED(hr), "Failed to get overlay position, hr %#x.\n", hr); + if (SUCCEEDED(hr2)) + { + ok(!pos_x, "Got unexpected pos_x %d.\n", pos_x); + ok(!pos_y, "Got unexpected pos_y %d.\n", pos_y); + } + else + { + ok(pos_x == 32, "Got unexpected pos_x %d.\n", pos_x); + ok(pos_y == 16, "Got unexpected pos_y %d.\n", pos_y); + } + + /* The position cannot be retrieved when the overlay is not shown. */ + hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_HIDE, NULL); + ok(SUCCEEDED(hr), "Failed to update overlay, hr %#x.\n", hr); + pos_x = -1; pos_y = -1; + hr = IDirectDrawSurface7_GetOverlayPosition(overlay, &pos_x, &pos_y); + ok(hr == DDERR_OVERLAYNOTVISIBLE, "Got unexpected hr %#x.\n", hr); + ok(!pos_x, "Got unexpected pos_x %d.\n", pos_x); + ok(!pos_y, "Got unexpected pos_y %d.\n", pos_y); + + IDirectDrawSurface7_Release(primary); + IDirectDrawSurface7_Release(overlay); +done: + IDirectDraw7_Release(ddraw); + DestroyWindow(window); +} + START_TEST(ddraw7) { HMODULE module = GetModuleHandleA("ddraw.dll"); @@ -11071,4 +11164,5 @@ START_TEST(ddraw7) test_lockrect_invalid(); test_yv12_overlay(); test_offscreen_overlay(); + test_overlay_rect(); } diff --git a/dlls/ddraw/tests/overlay.c b/dlls/ddraw/tests/overlay.c deleted file mode 100644 index 3e7b807f713..00000000000 --- a/dlls/ddraw/tests/overlay.c +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Unit tests for DirectDraw overlay functions - * - * Copyright (C) 2008,2011 Stefan Dösinger for CodeWeavers - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA - */ -#define COBJMACROS - -#include "wine/test.h" -#include "ddraw.h" -#include "unknwn.h" - -static HRESULT (WINAPI *pDirectDrawCreateEx)(GUID *driver_guid, - void **ddraw, REFIID interface_iid, IUnknown *outer); - -static IDirectDraw7 *ddraw = NULL; -static IDirectDrawSurface7 *primary = NULL; - -static IDirectDrawSurface7 *create_overlay(DWORD width, DWORD height, DWORD format) { - DDSURFACEDESC2 ddsd; - HRESULT hr; - IDirectDrawSurface7 *ret; - - memset(&ddsd, 0, sizeof(ddsd)); - ddsd.dwSize = sizeof(ddsd); - ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT; - ddsd.dwWidth = width; - ddsd.dwHeight = height; - ddsd.ddsCaps.dwCaps = DDSCAPS_OVERLAY; - U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat); - U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_FOURCC; - U4(ddsd).ddpfPixelFormat.dwFourCC = format; - hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &ret, NULL); - if(FAILED(hr)) return NULL; - else return ret; -} - -static BOOL CreateDirectDraw(void) -{ - HRESULT hr; - DDSURFACEDESC2 ddsd; - IDirectDrawSurface7 *overlay = NULL; - HMODULE hmod = GetModuleHandleA("ddraw.dll"); - - pDirectDrawCreateEx = (void*)GetProcAddress(hmod, "DirectDrawCreateEx"); - if (!pDirectDrawCreateEx) { - win_skip("DirectDrawCreateEx is not available\n"); - return FALSE; - } - - hr = pDirectDrawCreateEx(NULL, (void**)&ddraw, &IID_IDirectDraw7, NULL); - ok(hr == DD_OK || hr == DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreateEx returned: %x\n", hr); - if (!ddraw) { - trace("DirectDrawCreateEx() failed with an error %x\n", hr); - return FALSE; - } - - hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL); - ok(hr == DD_OK, "SetCooperativeLevel returned: %x\n", hr ); - - memset(&ddsd, 0, sizeof(ddsd)); - ddsd.dwSize = sizeof(ddsd); - ddsd.dwFlags = DDSD_CAPS; - ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; - hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL); - if (FAILED(hr)) { - IDirectDraw7_Release(ddraw); - trace("IDirectDraw7_CreateSurface() failed with an error %x\n", hr); - return FALSE; - } - - overlay = create_overlay(64, 64, MAKEFOURCC('U','Y','V','Y')); - if (!overlay) { - IDirectDrawSurface7_Release(primary); - IDirectDraw7_Release(ddraw); - skip("Failed to create an overlay - assuming not supported\n"); - return FALSE; - } - IDirectDraw7_Release(overlay); - - return TRUE; -} - -static void rectangle_settings(void) { - IDirectDrawSurface7 *overlay = create_overlay(64, 64, MAKEFOURCC('U','Y','V','Y')); - HRESULT hr, hr2; - RECT rect = {0, 0, 64, 64}; - LONG posx, posy; - - /* The dx sdk sort of implies that rect must be set when DDOVER_SHOW is used. This is not true - * in Windows Vista and earlier, but changed in Win7 */ - hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_SHOW, NULL); - ok(hr == DD_OK, "IDirectDrawSurface7_UpdateOverlay failed with hr=0x%08x\n", hr); - hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, NULL, DDOVER_HIDE, NULL); - ok(hr == DD_OK, "IDirectDrawSurface7_UpdateOverlay failed with hr=0x%08x\n", hr); - hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, NULL, DDOVER_SHOW, NULL); - ok(hr == DD_OK || hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_UpdateOverlay failed with hr=0x%08x\n", hr); - - /* Show that the overlay position is the (top, left) coordinate of the dest rectangle */ - rect.top += 16; - rect.left += 32; - rect.bottom += 16; - rect.right += 32; - hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_SHOW, NULL); - ok(hr == DD_OK, "IDirectDrawSurface7_UpdateOverlay failed with hr=0x%08x\n", hr); - posx = -1; posy = -1; - hr = IDirectDrawSurface7_GetOverlayPosition(overlay, &posx, &posy); - ok(hr == DD_OK, "IDirectDrawSurface7_GetOverlayPosition failed with hr=0x%08x\n", hr); - ok(posx == rect.left && posy == rect.top, "Overlay position is (%d, %d), expected (%d, %d)\n", - posx, posy, rect.left, rect.top); - - /* Passing a NULL dest rect sets the position to 0/0 . Visually it can be seen that the overlay overlays the whole primary(==screen)*/ - hr2 = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, NULL, 0, NULL); - ok(hr2 == DD_OK || hr2 == DDERR_INVALIDPARAMS - || hr2 == DDERR_OUTOFCAPS, "IDirectDrawSurface7_UpdateOverlay failed with hr=0x%08x\n", hr2); - hr = IDirectDrawSurface7_GetOverlayPosition(overlay, &posx, &posy); - ok(hr == DD_OK, "IDirectDrawSurface7_GetOverlayPosition failed with hr=0x%08x\n", hr); - if (SUCCEEDED(hr2)) - { - ok(posx == 0 && posy == 0, "Overlay position is (%d, %d), expected (%d, %d)\n", - posx, posy, 0, 0); - } - else - { - /* Otherwise the position remains untouched */ - ok(posx == 32 && posy == 16, "Overlay position is (%d, %d), expected (%d, %d)\n", - posx, posy, 32, 16); - } - /* The position cannot be retrieved when the overlay is not shown */ - hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_HIDE, NULL); - ok(hr == DD_OK, "IDirectDrawSurface7_UpdateOverlay failed with hr=0x%08x\n", hr); - posx = -1; posy = -1; - hr = IDirectDrawSurface7_GetOverlayPosition(overlay, &posx, &posy); - ok(hr == DDERR_OVERLAYNOTVISIBLE, "IDirectDrawSurface7_GetOverlayPosition failed with hr=0x%08x\n", hr); - ok(posx == 0 && posy == 0, "Overlay position is (%d, %d), expected (%d, %d)\n", - posx, posy, 0, 0); - - IDirectDrawSurface7_Release(overlay); -} - -START_TEST(overlay) -{ - if(CreateDirectDraw() == FALSE) { - skip("Failed to initialize ddraw\n"); - return; - } - - rectangle_settings(); - - if(primary) IDirectDrawSurface7_Release(primary); - if(ddraw) IDirectDraw7_Release(ddraw); -}