[PATCH 3/3] d3drm/tests: Add test for IDirect3DRM*::CreateDeviceFromD3D (try 3).

Aaryaman Vasishta jem456.vasishta at gmail.com
Thu Jun 18 13:41:30 CDT 2015


---
 dlls/d3drm/tests/d3drm.c | 176 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 176 insertions(+)

diff --git a/dlls/d3drm/tests/d3drm.c b/dlls/d3drm/tests/d3drm.c
index 682b0ab..1a504be 100644
--- a/dlls/d3drm/tests/d3drm.c
+++ b/dlls/d3drm/tests/d3drm.c
@@ -2245,6 +2245,181 @@ cleanup:
     DestroyWindow(window);
 }
 
+static IDirect3DDevice2 *create_device(IDirectDraw2 *ddraw, HWND window, DWORD coop_level)
+{
+    static const DWORD z_depths[] = { 32, 24, 16 };
+    IDirectDrawSurface *surface, *ds;
+    IDirect3DDevice2 *device = NULL;
+    DDSURFACEDESC surface_desc;
+    IDirect3D2 *d3d;
+    unsigned int i;
+    HRESULT hr;
+    RECT rc;
+
+    GetClientRect(window, &rc);
+    hr = IDirectDraw2_SetCooperativeLevel(ddraw, window, coop_level);
+    ok(SUCCEEDED(hr), "Failed to set cooperative level, 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_3DDEVICE;
+    surface_desc.dwWidth = rc.right;
+    surface_desc.dwHeight = rc.bottom;
+
+    hr = IDirectDraw2_CreateSurface(ddraw, &surface_desc, &surface, NULL);
+    ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
+
+    if (coop_level & DDSCL_NORMAL)
+    {
+        IDirectDrawClipper *clipper;
+
+        hr = IDirectDraw2_CreateClipper(ddraw, 0, &clipper, NULL);
+        ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
+        hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
+        ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
+        hr = IDirectDrawSurface_SetClipper(surface, clipper);
+        ok(SUCCEEDED(hr), "Failed to set surface clipper, hr %#x.\n", hr);
+        IDirectDrawClipper_Release(clipper);
+    }
+
+    hr = IDirectDraw2_QueryInterface(ddraw, &IID_IDirect3D2, (void **)&d3d);
+    if (FAILED(hr))
+    {
+        IDirectDrawSurface_Release(surface);
+        return NULL;
+    }
+
+    /* We used to use EnumDevices() for this, but it seems
+    * D3DDEVICEDESC.dwDeviceZBufferBitDepth only has a very casual
+    * relationship with reality. */
+    for (i = 0; i < sizeof(z_depths) / sizeof(*z_depths); ++i)
+    {
+        memset(&surface_desc, 0, sizeof(surface_desc));
+        surface_desc.dwSize = sizeof(surface_desc);
+        surface_desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
+        surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
+        U2(surface_desc).dwZBufferBitDepth = z_depths[i];
+        surface_desc.dwWidth = rc.right;
+        surface_desc.dwHeight = rc.bottom;
+        if (FAILED(IDirectDraw2_CreateSurface(ddraw, &surface_desc, &ds, NULL)))
+            continue;
+
+        hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
+        ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
+        IDirectDrawSurface_Release(ds);
+        if (FAILED(hr))
+            continue;
+
+        if (SUCCEEDED(IDirect3D2_CreateDevice(d3d, &IID_IDirect3DRGBDevice, surface, &device)))
+            break;
+
+        IDirectDrawSurface_DeleteAttachedSurface(surface, 0, ds);
+    }
+
+    IDirect3D2_Release(d3d);
+    IDirectDrawSurface_Release(surface);
+    return device;
+}
+
+static void test_create_device_from_d3d(void)
+{
+    IDirectDraw *ddraw1 = NULL;
+    IDirectDraw2 *ddraw2 = NULL;
+    IDirect3D2 *d3d2 = NULL;
+    IDirect3DRM *d3drm1 = NULL;
+    IDirect3DRM2 *d3drm2 = NULL;
+    IDirect3DRMDevice2 *device2 = NULL;
+    IDirect3DDevice2 *d3ddevice2 = NULL, *rdevice = NULL;
+    IDirectDrawSurface *surface = NULL, *ds = NULL;
+    DWORD expected_flags;
+    DDSCAPS caps = { DDSCAPS_ZBUFFER };
+    DDSURFACEDESC desc;
+    RECT rc;
+    HWND window;
+    ULONG ref1, ref2;
+    HRESULT hr;
+
+    hr = DirectDrawCreate(NULL, &ddraw1, NULL);
+    ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
+
+    window = CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW, 0, 0, 300, 200, 0, 0, 0, 0);
+    GetClientRect(window, &rc);
+
+    hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirect3D2, (void**)&d3d2);
+    ok(hr == DD_OK, "Cannot get IDirect3D2 interface (hr = %x).\n", hr);
+    hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirectDraw2, (void**)&ddraw2);
+    ok(hr == DD_OK, "Cannot get IDirectDraw2 interface (hr = %x).\n", hr);
+
+    /* Create the immediate mode device */
+    d3ddevice2 = create_device(ddraw2, window, DDSCL_NORMAL);
+    ref1 = get_refcount((IUnknown *)d3ddevice2);
+
+    hr = Direct3DRMCreate(&d3drm1);
+    ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
+
+    hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
+    ok(hr == D3DRM_OK, "Cannot get IDirect3DRM3 interface (hr = %x).\n", hr);
+
+    hr = IDirect3DRM2_CreateDeviceFromD3D(d3drm2, d3d2, d3ddevice2, &device2);
+    ok(hr == DD_OK, "Failed to create IDirect3DRMDevice2 interface (hr = %x)\n", hr);
+    ref2 = get_refcount((IUnknown *)d3ddevice2);
+    todo_wine ok(ref2 > ref1, "Expected ref2 > ref1, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
+
+    hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &rdevice);
+    todo_wine ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
+    if (FAILED(hr))
+        goto cleanup;
+    ok(d3ddevice2 == rdevice, "Expected Immediate Mode deivce created == %p, got %p.\n", d3ddevice2, rdevice);
+
+    /* Check properties of primary and depth surfaces */
+    hr = IDirect3DDevice2_GetRenderTarget(rdevice, &surface);
+    ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
+
+    memset(&desc, 0, sizeof(desc));
+    desc.dwSize = sizeof(desc);
+    hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc);
+    ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
+
+    ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimentions = %d, %d, got %d, %d.\n",
+            rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
+    ok((desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE),
+            "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, desc.ddsCaps.dwCaps);
+    expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
+    ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
+
+    hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
+    ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
+
+    desc.dwSize = sizeof(desc);
+    hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
+    ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
+
+    ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimentions = %d, %d, got %d, %d.\n",
+            rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
+    ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
+    expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
+    ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
+
+    IDirectDrawSurface_Release(surface);
+    IDirectDrawSurface_Release(ds);
+    IDirect3DDevice2_Release(rdevice);
+cleanup:
+    if (device2)
+    {
+        IDirect3DRMDevice2_Release(device2);
+        ref2 = get_refcount((IUnknown *)d3ddevice2);
+        ok(ref2 == ref1, "Expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
+    }
+    IDirect3DRM2_Release(d3drm2);
+    IDirect3DRM_Release(d3drm1);
+    IDirect3DDevice2_Release(d3ddevice2);
+    IDirect3D2_Release(d3d2);
+    IDirectDraw2_Release(ddraw2);
+    IDirectDraw_Release(ddraw1);
+    DestroyWindow(window);
+}
+
 START_TEST(d3drm)
 {
     test_MeshBuilder();
@@ -2264,4 +2439,5 @@ START_TEST(d3drm)
     test_frame_qi();
     test_create_device_from_clipper();
     test_create_device_from_surface();
+    test_create_device_from_d3d();
 }
-- 
1.9.3 (Apple Git-50)




More information about the wine-patches mailing list