[PATCH 05/12] d3drm: Implement IDirect3DRMDevice*::InitFromD3D.

Aaryaman Vasishta jem456.vasishta at gmail.com
Thu Jul 7 08:52:49 CDT 2016


Also fix some minor test issues.

Signed-off-by: Aaryaman Vasishta <jem456.vasishta at gmail.com>
---
 dlls/d3drm/d3drm.c         |  18 ++++-
 dlls/d3drm/d3drm_private.h |   1 +
 dlls/d3drm/device.c        |  57 +++++++++------
 dlls/d3drm/tests/d3drm.c   | 175 ++++++++++++++++++++++++++++++++++++++++++---
 4 files changed, 216 insertions(+), 35 deletions(-)

diff --git a/dlls/d3drm/d3drm.c b/dlls/d3drm/d3drm.c
index 87fffc9..e98a4b1 100644
--- a/dlls/d3drm/d3drm.c
+++ b/dlls/d3drm/d3drm.c
@@ -64,6 +64,19 @@ static HRESULT d3drm_create_texture_object(void **object, IDirect3DRM *d3drm)
     return hr;
 }
 
+static HRESULT d3drm_create_device_object(void **object, IDirect3DRM *d3drm)
+{
+    struct d3drm_device *device;
+    HRESULT hr;
+
+    if (FAILED(hr = d3drm_device_create(&device, d3drm)))
+        return hr;
+
+    *object = &device->IDirect3DRMDevice_iface;
+
+    return hr;
+}
+
 struct d3drm
 {
     IDirect3DRM IDirect3DRM_iface;
@@ -322,13 +335,11 @@ static HRESULT WINAPI d3drm1_CreateDeviceFromD3D(IDirect3DRM *iface,
     if (!device)
         return D3DRMERR_BADVALUE;
     *device = NULL;
-    if (!d3d || !d3d_device)
-        return D3DRMERR_BADVALUE;
 
     if (FAILED(hr = d3drm_device_create(&object, iface)))
         return hr;
 
-    if (FAILED(hr = d3drm_device_set_ddraw_device_d3d(object, d3d, d3d_device)))
+    if (FAILED(hr = IDirect3DRMDevice_InitFromD3D(&object->IDirect3DRMDevice_iface, d3d, d3d_device)))
     {
         d3drm_device_destroy(object);
         return hr;
@@ -1125,6 +1136,7 @@ static HRESULT WINAPI d3drm3_CreateObject(IDirect3DRM3 *iface,
     object_table[] =
     {
         {&CLSID_CDirect3DRMTexture, d3drm_create_texture_object},
+        {&CLSID_CDirect3DRMDevice, d3drm_create_device_object},
     };
 
     TRACE("iface %p, clsid %s, outer %p, iid %s, out %p.\n",
diff --git a/dlls/d3drm/d3drm_private.h b/dlls/d3drm/d3drm_private.h
index 54580e0..fbaeaeb 100644
--- a/dlls/d3drm/d3drm_private.h
+++ b/dlls/d3drm/d3drm_private.h
@@ -51,6 +51,7 @@ struct d3drm_texture
 
 struct d3drm_frame
 {
+    struct d3drm_object obj;
     IDirect3DRMFrame IDirect3DRMFrame_iface;
     IDirect3DRMFrame2 IDirect3DRMFrame2_iface;
     IDirect3DRMFrame3 IDirect3DRMFrame3_iface;
diff --git a/dlls/d3drm/device.c b/dlls/d3drm/device.c
index 0bc03f5..058386d 100644
--- a/dlls/d3drm/device.c
+++ b/dlls/d3drm/device.c
@@ -213,28 +213,32 @@ HRESULT d3drm_device_set_ddraw_device_d3d(struct d3drm_device *device, IDirect3D
     IDirectDrawSurface *surface;
     IDirect3DDevice2 *d3d_device2;
     DDSURFACEDESC desc;
-    HRESULT hr;
+    HRESULT hr, qi_hr;
 
-    /* Fetch render target and get width/height from there */
-    if (FAILED(hr = IDirect3DDevice_QueryInterface(d3d_device, &IID_IDirectDrawSurface, (void **)&surface)))
+    if (device->ddraw)
+        hr = D3DRMERR_BADOBJECT;
+    else
     {
-        if (FAILED(hr = IDirect3DDevice_QueryInterface(d3d_device, &IID_IDirect3DDevice2, (void **)&d3d_device2)))
-            return hr;
-        hr = IDirect3DDevice2_GetRenderTarget(d3d_device2, &surface);
-        IDirect3DDevice2_Release(d3d_device2);
+        /* Fetch render target and get width/height from there */
+        if (FAILED(hr = IDirect3DDevice_QueryInterface(d3d_device, &IID_IDirectDrawSurface, (void **)&surface)))
+        {
+            if (FAILED(hr = IDirect3DDevice_QueryInterface(d3d_device, &IID_IDirect3DDevice2, (void **)&d3d_device2)))
+                return hr;
+            hr = IDirect3DDevice2_GetRenderTarget(d3d_device2, &surface);
+            IDirect3DDevice2_Release(d3d_device2);
+            if (FAILED(hr))
+                return hr;
+        }
+
+        desc.dwSize = sizeof(desc);
+        hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc);
+        IDirectDrawSurface_Release(surface);
         if (FAILED(hr))
             return hr;
     }
 
-    desc.dwSize = sizeof(desc);
-    hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc);
-    IDirectDrawSurface_Release(surface);
-    if (FAILED(hr))
-        return hr;
-
-    if (FAILED(hr = IDirect3D_QueryInterface(d3d, &IID_IDirectDraw, (void **)&device->ddraw)))
-        return hr;
-
+    if (FAILED(qi_hr = IDirect3D_QueryInterface(d3d, &IID_IDirectDraw, (void **)&device->ddraw)))
+        return qi_hr;
     device->width = desc.dwWidth;
     device->height = desc.dwHeight;
     IDirect3DRM_AddRef(device->d3drm);
@@ -610,7 +614,10 @@ static HRESULT WINAPI d3drm_device3_InitFromD3D(IDirect3DRMDevice3 *iface,
 {
     FIXME("iface %p, d3d %p, d3d_device %p stub!\n", iface, d3d, d3d_device);
 
-    return E_NOTIMPL;
+    if (!d3d || !d3d_device)
+        return D3DRMERR_BADVALUE;
+
+    return E_NOINTERFACE;
 }
 
 static HRESULT WINAPI d3drm_device2_InitFromD3D(IDirect3DRMDevice2 *iface,
@@ -630,7 +637,10 @@ static HRESULT WINAPI d3drm_device1_InitFromD3D(IDirect3DRMDevice *iface,
 
     TRACE("iface %p, d3d %p, d3d_device %p.\n", iface, d3d, d3d_device);
 
-    return d3drm_device3_InitFromD3D(&device->IDirect3DRMDevice3_iface, d3d, d3d_device);
+    if (!d3d || !d3d_device)
+        return D3DRMERR_BADVALUE;
+
+    return d3drm_device_set_ddraw_device_d3d(device, d3d, d3d_device);
 }
 
 static HRESULT WINAPI d3drm_device3_InitFromClipper(IDirect3DRMDevice3 *iface,
@@ -1264,12 +1274,14 @@ static DWORD WINAPI d3drm_device2_GetRenderMode(IDirect3DRMDevice2 *iface)
 static HRESULT WINAPI d3drm_device3_GetDirect3DDevice2(IDirect3DRMDevice3 *iface, IDirect3DDevice2 **d3d_device)
 {
     struct d3drm_device *device = impl_from_IDirect3DRMDevice3(iface);
+    HRESULT hr;
 
     TRACE("iface %p, d3d_device %p.\n", iface, d3d_device);
 
-    IDirect3DDevice_QueryInterface(device->device, &IID_IDirect3DDevice2, (void**)d3d_device);
+    if (FAILED(hr = IDirect3DDevice_QueryInterface(device->device, &IID_IDirect3DDevice2, (void**)d3d_device)))
+        hr = D3DRMERR_BADOBJECT;
 
-    return D3DRM_OK;
+    return hr;
 }
 
 static HRESULT WINAPI d3drm_device2_GetDirect3DDevice2(IDirect3DRMDevice2 *iface, IDirect3DDevice2 **d3d_device)
@@ -1278,7 +1290,10 @@ static HRESULT WINAPI d3drm_device2_GetDirect3DDevice2(IDirect3DRMDevice2 *iface
 
     TRACE("iface %p, d3d_device %p.\n", iface, d3d_device);
 
-    return d3drm_device3_GetDirect3DDevice2(&device->IDirect3DRMDevice3_iface, d3d_device);
+    IDirect3DDevice_QueryInterface(device->device, &IID_IDirect3DDevice2, (void**)d3d_device);
+
+    /* d3drm returns D3DRM_OK even if the above QI fails. */
+    return D3DRM_OK;
 }
 
 static HRESULT WINAPI d3drm_device3_FindPreferredTextureFormat(IDirect3DRMDevice3 *iface,
diff --git a/dlls/d3drm/tests/d3drm.c b/dlls/d3drm/tests/d3drm.c
index e23f13f..1875065 100644
--- a/dlls/d3drm/tests/d3drm.c
+++ b/dlls/d3drm/tests/d3drm.c
@@ -1357,10 +1357,10 @@ static void test_object(void)
     }
     tests[] =
     {
-        { &CLSID_CDirect3DRMDevice,        &IID_IDirect3DRMDevice,       TRUE  },
-        { &CLSID_CDirect3DRMDevice,        &IID_IDirect3DRMDevice2,      TRUE  },
-        { &CLSID_CDirect3DRMDevice,        &IID_IDirect3DRMDevice3,      TRUE  },
-        { &CLSID_CDirect3DRMDevice,        &IID_IDirect3DRMWinDevice,    TRUE  },
+        { &CLSID_CDirect3DRMDevice,        &IID_IDirect3DRMDevice,       FALSE },
+        { &CLSID_CDirect3DRMDevice,        &IID_IDirect3DRMDevice2,      FALSE },
+        { &CLSID_CDirect3DRMDevice,        &IID_IDirect3DRMDevice3,      FALSE },
+        { &CLSID_CDirect3DRMDevice,        &IID_IDirect3DRMWinDevice,    FALSE },
         { &CLSID_CDirect3DRMTexture,       &IID_IDirect3DRMTexture,      FALSE },
         { &CLSID_CDirect3DRMTexture,       &IID_IDirect3DRMTexture2,     FALSE },
         { &CLSID_CDirect3DRMTexture,       &IID_IDirect3DRMTexture3,     FALSE },
@@ -3943,7 +3943,7 @@ static void test_create_device_from_d3d1(void)
     DDSURFACEDESC desc;
     RECT rc;
     HWND window;
-    ULONG ref1, ref2, device_ref1, device_ref2;
+    ULONG ref1, ref2, ref3, device_ref1, device_ref2, d3d_ref1, d3d_ref2;
     HRESULT hr;
 
     hr = DirectDrawCreate(NULL, &ddraw1, NULL);
@@ -3954,6 +3954,7 @@ static void test_create_device_from_d3d1(void)
 
     hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirect3D, (void **)&d3d1);
     ok(hr == DD_OK, "Cannot get IDirect3D2 interface (hr = %x).\n", hr);
+    d3d_ref1 = get_refcount((IUnknown *)d3d1);
 
     /* Create the immediate mode device */
     d3ddevice1 = create_device1(ddraw1, window, &ds);
@@ -3984,6 +3985,8 @@ static void test_create_device_from_d3d1(void)
     ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
     device_ref2 = get_refcount((IUnknown *)d3ddevice1);
     ok(device_ref2 > device_ref1, "Expected device_ref2 > device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1, device_ref2);
+    d3d_ref2 = get_refcount((IUnknown *)d3d1);
+    ok(d3d_ref2 > d3d_ref1, "Expected d3d_ref2 > d3d_ref1, got d3d_ref1 = %u, d3d_ref2 = %u.\n", d3d_ref1, d3d_ref2);
     ret_val = IDirect3DRMDevice_GetWidth(device1);
     ok(ret_val == rc.right, "Expected device width = 300, got %u.\n", ret_val);
     ret_val = IDirect3DRMDevice_GetHeight(device1);
@@ -3992,15 +3995,15 @@ static void test_create_device_from_d3d1(void)
     hr = IDirect3DRMDevice_QueryInterface(device1, &IID_IDirect3DRMDevice2, (void **)&device2);
     ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice2 Interface (hr = %x).\n", hr);
     hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3ddevice2);
-    ok(SUCCEEDED(hr), "Expected hr == DD_OK, got %x).\n", hr);
+    ok(SUCCEEDED(hr), "Expected hr == D3DRM_OK, got %#x.\n", hr);
     ok(d3ddevice2 == NULL, "Expected d3ddevice2 == NULL, got %p.\n", d3ddevice2);
     IDirect3DRMDevice2_Release(device2);
 
     d3ddevice2 = (IDirect3DDevice2 *)0xdeadbeef;
-    hr = IDirect3DRMDevice_QueryInterface(device1, &IID_IDirect3DRMDevice2, (void **)&device3);
-    ok(hr == DD_OK, "Cannot get IDirect3DRMDevice2 Interface (hr = %x).\n", hr);
+    hr = IDirect3DRMDevice_QueryInterface(device1, &IID_IDirect3DRMDevice3, (void **)&device3);
+    ok(hr == DD_OK, "Cannot get IDirect3DRMDevice3 Interface (hr = %x).\n", hr);
     hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
-    ok(hr == DD_OK, "Expected hr == DD_OK, got %x).\n", hr);
+    ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
     ok(d3ddevice2 == NULL, "Expected d3ddevice2 == NULL, got %p.\n", d3ddevice2);
     IDirect3DRMDevice3_Release(device3);
 
@@ -4053,6 +4056,108 @@ static void test_create_device_from_d3d1(void)
     device_ref2 = get_refcount((IUnknown *)d3ddevice1);
     ok(device_ref2 == device_ref1, "Expected device_ref2 == device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1, device_ref2);
 
+    /* InitFromD3D tests */
+    hr = IDirect3DRM_CreateObject(d3drm1, &CLSID_CDirect3DRMDevice, NULL, &IID_IDirect3DRMDevice, (void **)&device1);
+    ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice interface (hr = %#x).\n", hr);
+
+    hr = IDirect3DRMDevice_InitFromD3D(device1, NULL, d3ddevice1);
+    ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
+    hr = IDirect3DRMDevice_InitFromD3D(device1, d3d1, NULL);
+    ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
+
+    hr = IDirect3DRMDevice_InitFromD3D(device1, d3d1, d3ddevice1);
+    ok(SUCCEEDED(hr), "Failed to initialise IDirect3DRMDevice interface (hr = %#x)\n", hr);
+    ref2 = get_refcount((IUnknown *)d3drm1);
+    ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
+    device_ref2 = get_refcount((IUnknown *)d3ddevice1);
+    ok(device_ref2 > device_ref1, "Expected device_ref2 > device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1, device_ref2);
+    d3d_ref2 = get_refcount((IUnknown *)d3d1);
+    ok(d3d_ref2 > d3d_ref1, "Expected d3d_ref2 > d3d_ref1, got d3d_ref1 = %u, d3d_ref2 = %u.\n", d3d_ref1, d3d_ref2);
+    ret_val = IDirect3DRMDevice_GetWidth(device1);
+    ok(ret_val == rc.right, "Expected device width = 300, got %u.\n", ret_val);
+    ret_val = IDirect3DRMDevice_GetHeight(device1);
+    ok(ret_val == rc.bottom, "Expected device height == 200, got %u.\n", ret_val);
+
+    hr = IDirect3DRMDevice_InitFromD3D(device1, d3d1, d3ddevice1);
+    ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
+    ref3 = get_refcount((IUnknown *)d3ddevice1);
+    ok(ref3 > device_ref2, "Expected ref3 > device_ref2, got ref3 = %u, device_ref2 = %u.\n", ref3, device_ref2);
+    ref3 = get_refcount((IUnknown *)d3d1);
+    ok(ref3 > d3d_ref2, "Expected ref3 > d3d_ref2, got ref3 = %u, d3d_ref2 = %u.\n", ref3, d3d_ref2);
+    /* Release leaked references */
+    while (IDirect3DRM_Release(d3drm1) > ref2);
+    while (IDirect3DDevice_Release(d3ddevice1) > device_ref2);
+    while (IDirect3D_Release(d3d1) > d3d_ref2);
+
+    hr = IDirect3DRMDevice_QueryInterface(device1, &IID_IDirect3DRMDevice2, (void **)&device2);
+    ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice2 Interface (hr = %x).\n", hr);
+    hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3ddevice2);
+    ok(SUCCEEDED(hr), "Expected hr == D3DRM_OK, got %#x.\n", hr);
+    ok(d3ddevice2 == NULL, "Expected d3ddevice2 == NULL, got %p.\n", d3ddevice2);
+    IDirect3DRMDevice2_Release(device2);
+
+    d3ddevice2 = (IDirect3DDevice2 *)0xdeadbeef;
+    hr = IDirect3DRMDevice_QueryInterface(device1, &IID_IDirect3DRMDevice3, (void **)&device3);
+    ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice3 Interface (hr = %#x).\n", hr);
+    hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
+    ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
+    ok(d3ddevice2 == NULL, "Expected d3ddevice2 == NULL, got %p.\n", d3ddevice2);
+    IDirect3DRMDevice3_Release(device3);
+
+    surface = NULL;
+    hr = IDirectDraw_EnumSurfaces(ddraw1, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
+            NULL, &surface, surface_callback);
+    ok(SUCCEEDED(hr), "Failed to enumerate surfaces (hr = %#x).\n", hr);
+    ok(surface == NULL, "No primary surface should have enumerated (%p).\n", surface);
+
+    hr = IDirect3DRMDevice_GetDirect3DDevice(device1, &d3drm_d3ddevice1);
+    ok(SUCCEEDED(hr), "Cannot get IDirect3DDevice interface (hr = %#x).\n", hr);
+    ok(d3ddevice1 == d3drm_d3ddevice1, "Expected Immediate Mode device created == %p, got %p.\n", d3ddevice1, d3drm_d3ddevice1);
+
+    /* Check properties of render target and depth surfaces */
+    hr = IDirect3DDevice_QueryInterface(d3drm_d3ddevice1, &IID_IDirectDrawSurface, (void **)&surface);
+    ok(SUCCEEDED(hr), "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(SUCCEEDED(hr), "Cannot get surface desc structure (hr = %#x).\n", hr);
+
+    ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\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, &d3drm_ds);
+    ok(SUCCEEDED(hr), "Cannot get attached depth surface (hr = %x).\n", hr);
+    ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
+
+    desc.dwSize = sizeof(desc);
+    hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
+    ok(SUCCEEDED(hr), "Cannot get z surface desc structure (hr = %#x).\n", hr);
+
+    ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\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(d3drm_ds);
+    IDirectDrawSurface_Release(ds);
+    IDirectDrawSurface_Release(surface);
+    IDirect3DDevice_Release(d3drm_d3ddevice1);
+    IDirect3DRMDevice_Release(device1);
+    ref2 = get_refcount((IUnknown *)d3drm1);
+    ok(ref1 == ref2, "expected ref1 == ref2, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
+    device_ref2 = get_refcount((IUnknown *)d3ddevice1);
+    ok(device_ref2 == device_ref1, "Expected device_ref2 == device_ref1, got device_ref1 = %u, device_ref2 = %u.\n",
+            device_ref1, device_ref2);
+    d3d_ref2 = get_refcount((IUnknown *)d3d1);
+    todo_wine ok(d3d_ref2 > d3d_ref1, "Expected d3d_ref2 > d3d_ref1, got d3d_ref1 = %u, d3d_ref2 = %u.\n", d3d_ref1, d3d_ref2);
+
     IDirect3DRM_Release(d3drm1);
     IDirect3DDevice_Release(d3ddevice1);
     IDirect3D_Release(d3d1);
@@ -4133,10 +4238,12 @@ static void test_create_device_from_d3d2(void)
 {
     IDirectDraw *ddraw1 = NULL;
     IDirectDraw2 *ddraw2 = NULL;
+    IDirect3D* d3d1;
     IDirect3D2 *d3d2 = NULL;
     IDirect3DRM *d3drm1 = NULL;
     IDirect3DRM2 *d3drm2 = NULL;
     IDirect3DRMDevice2 *device2 = (IDirect3DRMDevice2 *)0xdeadbeef;
+    IDirect3DDevice *d3ddevice1;
     IDirect3DDevice2 *d3ddevice2 = NULL, *d3drm_d3ddevice2 = NULL;
     IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_ds = NULL;
     DWORD expected_flags, ret_val;
@@ -4144,7 +4251,7 @@ static void test_create_device_from_d3d2(void)
     DDSURFACEDESC desc;
     RECT rc;
     HWND window;
-    ULONG ref1, ref2, ref3, device_ref1, device_ref2;
+    ULONG ref1, ref2, ref3, device_ref1, device_ref2, d3d_ref1, d3d_ref2;
     HRESULT hr;
 
     hr = DirectDrawCreate(NULL, &ddraw1, NULL);
@@ -4157,6 +4264,7 @@ static void test_create_device_from_d3d2(void)
     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);
+    d3d_ref1 = get_refcount((IUnknown *)d3d2);
 
     /* Create the immediate mode device */
     d3ddevice2 = create_device2(ddraw2, window, &ds);
@@ -4194,6 +4302,8 @@ static void test_create_device_from_d3d2(void)
     ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
     device_ref2 = get_refcount((IUnknown *)d3ddevice2);
     ok(device_ref2 > device_ref1, "Expected device_ref2 > device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1, device_ref2);
+    d3d_ref2 = get_refcount((IUnknown *)d3d2);
+    ok(d3d_ref2 > d3d_ref1, "Expected d3d_ref2 > d3d_ref1, got d3d_ref1 = %u, d3d_ref2 = %u.\n", d3d_ref1, d3d_ref2);
     ret_val = IDirect3DRMDevice2_GetWidth(device2);
     ok(ret_val == rc.right, "Expected device width = 300, got %u.\n", ret_val);
     ret_val = IDirect3DRMDevice2_GetHeight(device2);
@@ -4249,6 +4359,26 @@ static void test_create_device_from_d3d2(void)
     ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
     device_ref2 = get_refcount((IUnknown *)d3ddevice2);
     ok(device_ref2 == device_ref1, "Expected device_ref2 == device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1, device_ref2);
+    d3d_ref2 = get_refcount((IUnknown *)d3d2);
+    ok(d3d_ref2 == d3d_ref1, "Expected d3d_ref2 == d3d_ref1, got d3d_ref1 = %u, d3d_ref2 = %u.\n", d3d_ref1, d3d_ref2);
+
+    /* InitFromD3D tests */
+    hr = IDirect3DRM2_CreateObject(d3drm2, &CLSID_CDirect3DRMDevice, NULL, &IID_IDirect3DRMDevice2, (void **)&device2);
+    ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice2 interface (hr = %#x).\n", hr);
+
+    hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirect3D, (void **)&d3d1);
+    ok(SUCCEEDED(hr), "Cannot get IDirect3D interface (hr = %x).\n", hr);
+    if (SUCCEEDED(hr = IDirect3DDevice2_QueryInterface(d3ddevice2, &IID_IDirect3DDevice, (void **)&d3ddevice1)))
+    {
+        hr = IDirect3DRMDevice2_InitFromD3D(device2, d3d1, d3ddevice1);
+        ok(hr == E_NOINTERFACE, "Expected hr == E_NOINTERFACE, got %#x.\n", hr);
+        hr = IDirect3DRMDevice2_InitFromD3D(device2, NULL, d3ddevice1);
+        ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
+        hr = IDirect3DRMDevice2_InitFromD3D(device2, d3d1, NULL);
+        ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
+    }
+    IDirect3D_Release(d3d1);
+    IDirect3DDevice_Release(d3ddevice1);
 
     IDirect3DRM2_Release(d3drm2);
     IDirect3DRM_Release(d3drm1);
@@ -4263,10 +4393,12 @@ static void test_create_device_from_d3d3(void)
 {
     IDirectDraw *ddraw1 = NULL;
     IDirectDraw2 *ddraw2 = NULL;
+    IDirect3D *d3d1;
     IDirect3D2 *d3d2 = NULL;
     IDirect3DRM *d3drm1 = NULL;
     IDirect3DRM3 *d3drm3 = NULL;
     IDirect3DRMDevice3 *device3 = (IDirect3DRMDevice3 *)0xdeadbeef;
+    IDirect3DDevice *d3ddevice1;
     IDirect3DDevice2 *d3ddevice2 = NULL, *d3drm_d3ddevice2 = NULL;
     IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_ds = NULL;
     DWORD expected_flags, ret_val;
@@ -4274,7 +4406,7 @@ static void test_create_device_from_d3d3(void)
     DDSURFACEDESC desc;
     RECT rc;
     HWND window;
-    ULONG ref1, ref2, ref3, device_ref1, device_ref2;
+    ULONG ref1, ref2, ref3, device_ref1, device_ref2, d3d_ref1, d3d_ref2;
     HRESULT hr;
 
     hr = DirectDrawCreate(NULL, &ddraw1, NULL);
@@ -4287,6 +4419,7 @@ static void test_create_device_from_d3d3(void)
     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);
+    d3d_ref1 = get_refcount((IUnknown *)d3d2);
 
     /* Create the immediate mode device */
     d3ddevice2 = create_device2(ddraw2, window, &ds);
@@ -4379,6 +4512,26 @@ static void test_create_device_from_d3d3(void)
     ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
     device_ref2 = get_refcount((IUnknown *)d3ddevice2);
     ok(device_ref2 == device_ref1, "Expected device_ref2 == device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1, device_ref2);
+    d3d_ref2 = get_refcount((IUnknown *)d3d2);
+    ok(d3d_ref2 == d3d_ref1, "Expected d3d_ref2 == d3d_ref1, got d3d_ref1 = %u, d3d_ref2 = %u.\n", d3d_ref1, d3d_ref2);
+
+    /* InitFromD3D tests */
+    hr = IDirect3DRM3_CreateObject(d3drm3, &CLSID_CDirect3DRMDevice, NULL, &IID_IDirect3DRMDevice3, (void **)&device3);
+    ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice3 interface (hr = %#x).\n", hr);
+
+    hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirect3D, (void **)&d3d1);
+    ok(SUCCEEDED(hr), "Cannot get IDirect3D interface (hr = %#x).\n", hr);
+    if (SUCCEEDED(hr = IDirect3DDevice2_QueryInterface(d3ddevice2, &IID_IDirect3DDevice, (void **)&d3ddevice1)))
+    {
+        hr = IDirect3DRMDevice3_InitFromD3D(device3, d3d1, d3ddevice1);
+        ok(hr == E_NOINTERFACE, "Expected hr == E_NOINTERFACE, got %#x.\n", hr);
+        hr = IDirect3DRMDevice3_InitFromD3D(device3, NULL, d3ddevice1);
+        ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
+        hr = IDirect3DRMDevice3_InitFromD3D(device3, d3d1, NULL);
+        ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
+    }
+    IDirect3D_Release(d3d1);
+    IDirect3DDevice_Release(d3ddevice1);
 
     IDirect3DRM3_Release(d3drm3);
     IDirect3DRM_Release(d3drm1);
-- 
2.3.2 (Apple Git-55)




More information about the wine-patches mailing list