[PATCH] DDraw: Add some overlay tests=0A=

Stefan Doesinger stefan at codeweavers.com
Thu Aug 28 09:38:32 CDT 2008


=0A=
---=0A=
 dlls/ddraw/tests/Makefile.in |    1 +=0A=
 dlls/ddraw/tests/overlay.c   |  219 =
++++++++++++++++++++++++++++++++++++++++++=0A=
 2 files changed, 220 insertions(+), 0 deletions(-)=0A=
 create mode 100644 dlls/ddraw/tests/overlay.c=0A=
=0A=
diff --git a/dlls/ddraw/tests/Makefile.in b/dlls/ddraw/tests/Makefile.in=0A=
index a0930a7..74e20d7 100644=0A=
--- a/dlls/ddraw/tests/Makefile.in=0A=
+++ b/dlls/ddraw/tests/Makefile.in=0A=
@@ -9,6 +9,7 @@ CTESTS =3D \=0A=
 	d3d.c \=0A=
 	ddrawmodes.c \=0A=
 	dsurface.c \=0A=
+	overlay.c \=0A=
 	refcount.c \=0A=
 	visual.c=0A=
 =0A=
diff --git a/dlls/ddraw/tests/overlay.c b/dlls/ddraw/tests/overlay.c=0A=
new file mode 100644=0A=
index 0000000..238b8f5=0A=
--- /dev/null=0A=
+++ b/dlls/ddraw/tests/overlay.c=0A=
@@ -0,0 +1,219 @@=0A=
+/*=0A=
+ * Unit tests for DirectDraw overlay functions=0A=
+ *=0A=
+ * Copyright (C) 2008 Stefan D=F6singer for CodeWeavers=0A=
+ *=0A=
+ * This library is free software; you can redistribute it and/or=0A=
+ * modify it under the terms of the GNU Lesser General Public=0A=
+ * License as published by the Free Software Foundation; either=0A=
+ * version 2.1 of the License, or (at your option) any later version.=0A=
+ *=0A=
+ * This library is distributed in the hope that it will be useful,=0A=
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of=0A=
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU=0A=
+ * Lesser General Public License for more details.=0A=
+ *=0A=
+ * You should have received a copy of the GNU Lesser General Public=0A=
+ * License along with this library; if not, write to the Free Software=0A=
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA =
02110-1301, USA=0A=
+ */=0A=
+#define COBJMACROS=0A=
+=0A=
+#include <assert.h>=0A=
+#include "wine/test.h"=0A=
+#include "ddraw.h"=0A=
+#include "unknwn.h"=0A=
+=0A=
+IDirectDraw7 *ddraw =3D NULL;=0A=
+IDirectDrawSurface7 *primary =3D NULL;=0A=
+=0A=
+static IDirectDrawSurface7 *create_overlay(DWORD width, DWORD height, =
DWORD format) {=0A=
+    DDSURFACEDESC2 ddsd;=0A=
+    HRESULT hr;=0A=
+    IDirectDrawSurface7 *ret;=0A=
+=0A=
+    memset(&ddsd, 0, sizeof(ddsd));=0A=
+    ddsd.dwSize =3D sizeof(ddsd);=0A=
+    ddsd.dwFlags =3D DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | =
DDSD_PIXELFORMAT;=0A=
+    ddsd.dwWidth =3D width;=0A=
+    ddsd.dwHeight =3D height;=0A=
+    ddsd.ddsCaps.dwCaps =3D DDSCAPS_OVERLAY;=0A=
+    ddsd.ddpfPixelFormat.dwSize =3D sizeof(ddsd.ddpfPixelFormat);=0A=
+    ddsd.ddpfPixelFormat.dwFlags =3D DDPF_FOURCC;=0A=
+    ddsd.ddpfPixelFormat.dwFourCC =3D format;=0A=
+    hr =3D IDirectDraw7_CreateSurface(ddraw, &ddsd, &ret, NULL);=0A=
+    if(FAILED(hr)) return NULL;=0A=
+    else return ret;=0A=
+}=0A=
+=0A=
+static BOOL CreateDirectDraw(void)=0A=
+{=0A=
+    HRESULT hr;=0A=
+    DDSURFACEDESC2 ddsd;=0A=
+    IDirectDrawSurface7 *overlay =3D NULL;=0A=
+=0A=
+    hr =3D DirectDrawCreateEx(NULL, (void**)&ddraw, &IID_IDirectDraw7, =
NULL);=0A=
+    ok(hr =3D=3D DD_OK || hr =3D=3D DDERR_NODIRECTDRAWSUPPORT, =
"DirectDrawCreateEx returned: %x\n", hr);=0A=
+    if (!ddraw) {=0A=
+        trace("DirectDrawCreateEx() failed with an error %x\n", hr);=0A=
+        return FALSE;=0A=
+    }=0A=
+=0A=
+    hr =3D IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);=0A=
+    ok(hr =3D=3D DD_OK, "SetCooperativeLevel returned: %x\n", hr );=0A=
+=0A=
+    memset(&ddsd, 0, sizeof(ddsd));=0A=
+    ddsd.dwSize =3D sizeof(ddsd);=0A=
+    ddsd.dwFlags =3D DDSD_CAPS;=0A=
+    ddsd.ddsCaps.dwCaps =3D DDSCAPS_PRIMARYSURFACE;=0A=
+    hr =3D IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);=0A=
+    if (!SUCCEEDED(hr)) {=0A=
+        IDirectDraw7_Release(ddraw);=0A=
+        trace("IDirectDraw7_CreateSurface() failed with an error %x\n", =
hr);=0A=
+        return FALSE;=0A=
+    }=0A=
+=0A=
+    overlay =3D create_overlay(64, 64, MAKEFOURCC('U','Y','V','Y'));=0A=
+    if (!overlay) {=0A=
+        IDirectDrawSurface7_Release(primary);=0A=
+        IDirectDraw7_Release(ddraw);=0A=
+        skip("Failed to create an overlay - assuming not supported\n");=0A=
+        return FALSE;=0A=
+    }=0A=
+    IDirectDraw7_Release(overlay);=0A=
+=0A=
+    return TRUE;=0A=
+}=0A=
+=0A=
+void rectangle_settings() {=0A=
+    IDirectDrawSurface7 *overlay =3D create_overlay(64, 64, =
MAKEFOURCC('U','Y','V','Y'));=0A=
+    HRESULT hr;=0A=
+    RECT rect =3D {0, 0, 64, 64};=0A=
+    LONG posx, posy;=0A=
+=0A=
+    /* The dx sdk sort of implies that rect must be set when =
DDOVER_SHOW is used. Show that this is wrong */=0A=
+    hr =3D IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, =
&rect, DDOVER_SHOW, NULL);=0A=
+    ok(hr =3D=3D DD_OK, "IDirectDrawSurface7_UpdateOverlay failed with =
hr=3D0x%08x\n", hr);=0A=
+    hr =3D IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, =
NULL, DDOVER_HIDE, NULL);=0A=
+    ok(hr =3D=3D DD_OK, "IDirectDrawSurface7_UpdateOverlay failed with =
hr=3D0x%08x\n", hr);=0A=
+    hr =3D IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, =
NULL, DDOVER_SHOW, NULL);=0A=
+    ok(hr =3D=3D DD_OK, "IDirectDrawSurface7_UpdateOverlay failed with =
hr=3D0x%08x\n", hr);=0A=
+=0A=
+    /* Show that the overlay position is the (top, left) coordinate of =
the dest rectangle */=0A=
+    rect.top +=3D 16;=0A=
+    rect.left +=3D 32;=0A=
+    rect.bottom +=3D 16;=0A=
+    rect.right +=3D 32;=0A=
+    hr =3D IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, =
&rect, DDOVER_SHOW, NULL);=0A=
+    ok(hr =3D=3D DD_OK, "IDirectDrawSurface7_UpdateOverlay failed with =
hr=3D0x%08x\n", hr);=0A=
+    posx =3D -1; posy =3D -1;=0A=
+    hr =3D IDirectDrawSurface7_GetOverlayPosition(overlay, &posx, =
&posy);=0A=
+    ok(hr =3D=3D DD_OK, "IDirectDrawSurface7_GetOverlayPosition failed =
with hr=3D0x%08x\n", hr);=0A=
+    ok(posx =3D=3D rect.left && posy =3D=3D rect.top, "Overlay position =
is (%d, %d), expected (%d, %d)\n",=0A=
+       posx, posy, rect.left, rect.top);=0A=
+=0A=
+    /* Passing a NULL dest rect sets the position to 0/0 . Visually it =
can be seen that the overlay overlays the whole primary(=3D=3Dscreen)*/=0A=
+    hr =3D IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, =
NULL, 0, NULL);=0A=
+    ok(hr =3D=3D DD_OK, "IDirectDrawSurface7_UpdateOverlay failed with =
hr=3D0x%08x\n", hr);=0A=
+    hr =3D IDirectDrawSurface7_GetOverlayPosition(overlay, &posx, =
&posy);=0A=
+    ok(hr =3D=3D DD_OK, "IDirectDrawSurface7_GetOverlayPosition failed =
with hr=3D0x%08x\n", hr);=0A=
+    ok(posx =3D=3D 0 && posy =3D=3D 0, "Overlay position is (%d, %d), =
expected (%d, %d)\n",=0A=
+       posx, posy, 0, 0);=0A=
+=0A=
+    /* The position cannot be retrieved when the overlay is not shown */=0A=
+    hr =3D IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, =
&rect, DDOVER_HIDE, NULL);=0A=
+    ok(hr =3D=3D DD_OK, "IDirectDrawSurface7_UpdateOverlay failed with =
hr=3D0x%08x\n", hr);=0A=
+    posx =3D -1; posy =3D -1;=0A=
+    hr =3D IDirectDrawSurface7_GetOverlayPosition(overlay, &posx, =
&posy);=0A=
+    ok(hr =3D=3D DDERR_OVERLAYNOTVISIBLE, =
"IDirectDrawSurface7_GetOverlayPosition failed with hr=3D0x%08x\n", hr);=0A=
+    ok(posx =3D=3D 0 && posy =3D=3D 0, "Overlay position is (%d, %d), =
expected (%d, %d)\n",=0A=
+       posx, posy, 0, 0);=0A=
+=0A=
+    IDirectDrawSurface7_Release(overlay);=0A=
+}=0A=
+=0A=
+void offscreen_test() {=0A=
+    IDirectDrawSurface7 *overlay =3D create_overlay(64, 64, =
MAKEFOURCC('U','Y','V','Y')), *offscreen =3D NULL;=0A=
+    HRESULT hr;=0A=
+    DDSURFACEDESC2 ddsd;=0A=
+=0A=
+    /* Try to overlay a NULL surface */=0A=
+    hr =3D IDirectDrawSurface7_UpdateOverlay(overlay, NULL, NULL, NULL, =
DDOVER_SHOW, NULL);=0A=
+    ok(hr =3D=3D DDERR_INVALIDPARAMS, =
"IDirectDrawSurface7_UpdateOverlay failed with hr=3D0x%08x\n", hr);=0A=
+    hr =3D IDirectDrawSurface7_UpdateOverlay(overlay, NULL, NULL, NULL, =
DDOVER_HIDE, NULL);=0A=
+    ok(hr =3D=3D DDERR_INVALIDPARAMS, =
"IDirectDrawSurface7_UpdateOverlay failed with hr=3D0x%08x\n", hr);=0A=
+=0A=
+    /* Try to overlay an offscreen surface */=0A=
+    memset(&ddsd, 0, sizeof(ddsd));=0A=
+    ddsd.dwSize =3D sizeof(ddsd);=0A=
+    ddsd.dwFlags =3D DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | =
DDSD_PIXELFORMAT;=0A=
+    ddsd.dwWidth =3D 64;=0A=
+    ddsd.dwHeight =3D 64;=0A=
+    ddsd.ddpfPixelFormat.dwSize =3D sizeof(ddsd.ddpfPixelFormat);=0A=
+    ddsd.ddpfPixelFormat.dwFlags =3D DDPF_RGB;=0A=
+    ddsd.ddpfPixelFormat.dwFourCC =3D 0;=0A=
+    ddsd.ddpfPixelFormat.dwRGBBitCount =3D 16;=0A=
+    ddsd.ddpfPixelFormat.dwRBitMask =3D 0xF800;=0A=
+    ddsd.ddpfPixelFormat.dwGBitMask =3D 0x07e0;=0A=
+    ddsd.ddpfPixelFormat.dwBBitMask =3D 0x001F;=0A=
+    ddsd.ddsCaps.dwCaps =3D DDSCAPS_OFFSCREENPLAIN;=0A=
+    hr =3D IDirectDraw7_CreateSurface(ddraw, &ddsd, &offscreen, NULL);=0A=
+    ok(hr =3D=3D DD_OK, "IDirectDraw7_CreateSurface failed with =
hr=3D0x%08x\n", hr);=0A=
+=0A=
+    hr =3D IDirectDrawSurface7_UpdateOverlay(overlay, NULL, offscreen, =
NULL, DDOVER_SHOW, NULL);=0A=
+    ok(hr =3D=3D DD_OK, "IDirectDrawSurface7_UpdateOverlay failed with =
hr=3D0x%08x\n", hr);=0A=
+=0A=
+    /* Try to overlay the primary with a non-overlay surface */=0A=
+    hr =3D IDirectDrawSurface7_UpdateOverlay(offscreen, NULL, primary, =
NULL, DDOVER_SHOW, NULL);=0A=
+    ok(hr =3D=3D DDERR_NOTAOVERLAYSURFACE, =
"IDirectDrawSurface7_UpdateOverlay failed with hr=3D0x%08x\n", hr);=0A=
+=0A=
+    IDirectDrawSurface7_Release(offscreen);=0A=
+    IDirectDrawSurface7_Release(overlay);=0A=
+}=0A=
+=0A=
+static void yv12_test(void)=0A=
+{=0A=
+    HRESULT hr;=0A=
+    DDSURFACEDESC2 desc;=0A=
+    IDirectDrawSurface7 *surface;=0A=
+=0A=
+    surface =3D create_overlay(256, 256, MAKEFOURCC('Y','V','1','2'));=0A=
+    if(!surface) {=0A=
+        skip("YV12 surfaces not available\n");=0A=
+        return;=0A=
+    }=0A=
+=0A=
+    memset(&desc, 0, sizeof(desc));=0A=
+    desc.dwSize =3D sizeof(desc);=0A=
+    hr =3D IDirectDrawSurface7_Lock(surface, NULL, &desc, 0, NULL);=0A=
+    ok(hr =3D=3D DD_OK, "IDirectDrawSurface7_Lock returned 0x%08x, =
expected DD_OK\n", hr);=0A=
+=0A=
+    ok(desc.dwFlags =3D=3D (DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT =
| DDSD_CAPS | DDSD_PITCH),=0A=
+       "Unexpected desc.dwFlags 0x%08x\n", desc.dwFlags);=0A=
+    ok(desc.ddsCaps.dwCaps =3D=3D (DDSCAPS_OVERLAY | =
DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM),=0A=
+       "Unexpected desc.ddsCaps.dwCaps 0x%08x\n", desc.ddsCaps.dwCaps);=0A=
+    ok(desc.dwWidth =3D=3D 256 && desc.dwHeight =3D=3D 256, "Expected =
size 64x64, got %ux%u\n",=0A=
+       desc.dwWidth, desc.dwHeight);=0A=
+    /* The overlay pitch seems to have 256 byte alignment */=0A=
+    ok(desc.lPitch =3D=3D 256, "Unexpected pitch %u, expected 256\n", =
desc.lPitch);=0A=
+=0A=
+    hr =3D IDirectDrawSurface7_Unlock(surface, NULL);=0A=
+    ok(hr =3D=3D DD_OK, "IDirectDrawSurface7_Unlock returned 0x%08x, =
expected DD_OK\n", hr);=0A=
+=0A=
+    IDirectDrawSurface7_Release(surface);=0A=
+}=0A=
+=0A=
+START_TEST(overlay)=0A=
+{=0A=
+    if(CreateDirectDraw() =3D=3D FALSE) {=0A=
+        skip("Failed to initialize ddraw\n");=0A=
+        return;=0A=
+    }=0A=
+=0A=
+    rectangle_settings();=0A=
+    offscreen_test();=0A=
+    yv12_test();=0A=
+=0A=
+    if(primary) IDirectDrawSurface7_Release(primary);=0A=
+    if(ddraw) IDirectDraw7_Release(ddraw);=0A=
+}=0A=
-- =0A=
1.5.6.4=0A=
=0A=

------=_NextPart_000_0011_01C909E1.7889D400--




More information about the wine-patches mailing list