d3drm: Implement IDirect3DRM{2-3}::CreateDeviceFromClipper

Aaryaman Vasishta jem456.vasishta at gmail.com
Tue Aug 18 08:53:51 CDT 2015


---
 dlls/d3drm/Makefile.in     |  2 +-
 dlls/d3drm/d3drm.c         | 84 +++++++++++++++++++++++++++++++++++++++--
 dlls/d3drm/d3drm_private.h |  5 +++
 dlls/d3drm/device.c        | 94 ++++++++++++++++++++++++++++++++++++++++++++++
 dlls/d3drm/tests/d3drm.c   | 16 ++++----
 5 files changed, 188 insertions(+), 13 deletions(-)

diff --git a/dlls/d3drm/Makefile.in b/dlls/d3drm/Makefile.in
index 35d7af0..5db3494 100644
--- a/dlls/d3drm/Makefile.in
+++ b/dlls/d3drm/Makefile.in
@@ -1,6 +1,6 @@
 MODULE    = d3drm.dll
 IMPORTLIB = d3drm
-IMPORTS   = dxguid uuid d3dxof
+IMPORTS   = dxguid uuid d3dxof ddraw
 
 C_SRCS = \
 	d3drm.c \
diff --git a/dlls/d3drm/d3drm.c b/dlls/d3drm/d3drm.c
index 70c2678..d734c3b 100644
--- a/dlls/d3drm/d3drm.c
+++ b/dlls/d3drm/d3drm.c
@@ -610,10 +610,73 @@ static HRESULT WINAPI d3drm2_CreateDeviceFromClipper(IDirect3DRM2 *iface,
         IDirectDrawClipper *clipper, GUID *guid, int width, int height,
         IDirect3DRMDevice2 **device)
 {
-    FIXME("iface %p, clipper %p, guid %s, width %d, height %d, device %p partial stub.\n",
+    struct d3drm *d3drm = impl_from_IDirect3DRM2(iface);
+    IDirectDraw *ddraw1;
+    IDirectDraw2 *ddraw2;
+    IDirectDrawSurface *surface, *primary_surface;
+    DDSURFACEDESC surface_desc;
+    IDirect3D2 *d3d2;
+    HWND window;
+    HRESULT hr;
+
+    TRACE("iface %p, clipper %p, guid %s, width %d, height %d, device %p.\n",
             iface, clipper, debugstr_guid(guid), width, height, device);
 
-    return Direct3DRMDevice_create(&IID_IDirect3DRMDevice2, (IUnknown **)device);
+    if (!clipper || !width || !height)
+        return D3DRMERR_BADVALUE;
+
+    hr = DirectDrawCreate(NULL, &ddraw1, NULL);
+    if (FAILED(hr))
+        return hr;
+
+    hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirectDraw2, (void**)&ddraw2);
+    if (FAILED(hr))
+        return hr;
+
+    hr = IDirectDrawClipper_GetHWnd(clipper, &window);
+    if (FAILED(hr))
+        return hr;
+
+    hr = IDirectDraw2_SetCooperativeLevel(ddraw2, window, DDSCL_NORMAL);
+    if (FAILED(hr))
+        return hr;
+
+    hr = Direct3DRMDevice_create(&IID_IDirect3DRMDevice2, (IUnknown **)device);
+    if (FAILED(hr))
+        return hr;
+
+    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(ddraw2, &surface_desc, &primary_surface, NULL);
+    if (FAILED(hr))
+        return hr;
+    hr = IDirectDrawSurface_SetClipper(primary_surface, clipper);
+    if (FAILED(hr))
+        return hr;
+    set_primary_surface(device, clipper, primary_surface);
+
+    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 = width;
+    surface_desc.dwHeight = height;
+
+    hr = IDirectDraw2_CreateSurface(ddraw2, &surface_desc, &surface, NULL);
+    if (FAILED(hr))
+        return hr;
+
+    hr = IDirectDraw2_QueryInterface(ddraw2, &IID_IDirect3D2, (void **)&d3d2);
+    if (FAILED(hr))
+    {
+        IDirectDrawSurface_Release(surface);
+        return hr;
+    }
+    IDirectDraw2_Release(ddraw2);
+
+    return init_device(&d3drm->IDirect3DRM_iface, guid, ddraw1, surface, TRUE, d3d2, width, height, device);
 }
 
 static HRESULT WINAPI d3drm2_CreateTextureFromSurface(IDirect3DRM2 *iface,
@@ -984,10 +1047,23 @@ static HRESULT WINAPI d3drm3_CreateDeviceFromClipper(IDirect3DRM3 *iface,
         IDirectDrawClipper *clipper, GUID *guid, int width, int height,
         IDirect3DRMDevice3 **device)
 {
-    FIXME("iface %p, clipper %p, guid %s, width %d, height %d, device %p partial stub.\n",
+    struct d3drm *d3drm = impl_from_IDirect3DRM3(iface);
+    IDirect3DRMDevice2 *device2;
+    HRESULT hr;
+
+    TRACE("iface %p, clipper %p, guid %s, width %d, height %d, device %p.\n",
             iface, clipper, debugstr_guid(guid), width, height, device);
 
-    return Direct3DRMDevice_create(&IID_IDirect3DRMDevice3, (IUnknown **)device);
+    hr = IDirect3DRM2_CreateDeviceFromClipper(&d3drm->IDirect3DRM2_iface, clipper, guid, width, height, &device2);
+    if (FAILED(hr))
+        return hr;
+
+    hr = IDirect3DRMDevice2_QueryInterface(device2, &IID_IDirect3DRMDevice3, (void**)device);
+    if (FAILED(hr))
+        return hr;
+    IDirect3DRMDevice2_Release(device2);
+
+    return D3DRM_OK;
 }
 
 static HRESULT WINAPI d3drm3_CreateShadow(IDirect3DRM3 *iface, IUnknown *object, IDirect3DRMLight *light,
diff --git a/dlls/d3drm/d3drm_private.h b/dlls/d3drm/d3drm_private.h
index 80da952..6744a54 100644
--- a/dlls/d3drm/d3drm_private.h
+++ b/dlls/d3drm/d3drm_private.h
@@ -37,6 +37,11 @@ HRESULT Direct3DRMTexture_create(REFIID riid, IUnknown** ret_iface) DECLSPEC_HID
 HRESULT load_mesh_data(IDirect3DRMMeshBuilder3 *iface, IDirectXFileData *data,
                        D3DRMLOADTEXTURECALLBACK load_texture_proc, void *arg) DECLSPEC_HIDDEN;
 
+void set_primary_surface(IDirect3DRMDevice2 **device, IDirectDrawClipper *clipper, IDirectDrawSurface *primary_surface) DECLSPEC_HIDDEN;
+
+HRESULT init_device(IDirect3DRM *d3drm, GUID *guid, IDirectDraw *ddraw, IDirectDrawSurface *surface, BOOL z_surface, IDirect3D2 *d3d2,
+    int width, int height, IDirect3DRMDevice2 **device) DECLSPEC_HIDDEN;
+
 struct d3drm_file_header
 {
     WORD major;
diff --git a/dlls/d3drm/device.c b/dlls/d3drm/device.c
index 9293854..bc69e29 100644
--- a/dlls/d3drm/device.c
+++ b/dlls/d3drm/device.c
@@ -37,6 +37,11 @@ struct d3drm_device
     IDirect3DRMDevice2 IDirect3DRMDevice2_iface;
     IDirect3DRMDevice3 IDirect3DRMDevice3_iface;
     IDirect3DRMWinDevice IDirect3DRMWinDevice_iface;
+    IDirect3DRM *d3drm;
+    IDirectDraw *ddraw;
+    IDirectDrawSurface *primary_surface;
+    IDirectDrawClipper *clipper;
+    IDirect3DDevice *device;
     LONG ref;
     BOOL dither;
     D3DRMRENDERQUALITY quality;
@@ -65,6 +70,77 @@ static inline struct d3drm_device *impl_from_IDirect3DRMWinDevice(IDirect3DRMWin
     return CONTAINING_RECORD(iface, struct d3drm_device, IDirect3DRMWinDevice_iface);
 }
 
+void set_primary_surface(IDirect3DRMDevice2 **device, IDirectDrawClipper *clipper, IDirectDrawSurface *primary_surface)
+{
+    struct d3drm_device *object = impl_from_IDirect3DRMDevice2(*device);
+
+    object->primary_surface = primary_surface;
+    object->clipper = clipper;
+    IDirectDrawClipper_AddRef(clipper);
+}
+
+HRESULT init_device(IDirect3DRM *d3drm, GUID *guid, IDirectDraw *ddraw, IDirectDrawSurface *surface, BOOL z_surface, IDirect3D2 *d3d2,
+            int width, int height, IDirect3DRMDevice2 **device)
+{
+    struct d3drm_device *object = impl_from_IDirect3DRMDevice2(*device);
+    IDirectDraw2 *ddraw2;
+    IDirectDrawSurface *ds;
+    IDirect3DDevice *device1;
+    IDirect3DDevice2 *device2;
+    DDSURFACEDESC surface_desc;
+    HRESULT hr;
+
+    hr = IDirectDraw2_QueryInterface(ddraw, &IID_IDirectDraw2, (void**)&ddraw2);
+    if (FAILED(hr))
+        return hr;
+
+    if (z_surface)
+    {
+        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;
+        surface_desc.dwZBufferBitDepth = 16;
+        surface_desc.dwWidth = width;
+        surface_desc.dwHeight = height;
+        hr = IDirectDraw2_CreateSurface(ddraw2, &surface_desc, &ds, NULL);
+        if (FAILED(hr))
+            return hr;
+
+        hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
+        IDirectDrawSurface_Release(ds);
+        if (FAILED(hr))
+            return hr;
+
+        hr = IDirect3D2_CreateDevice(d3d2, &IID_IDirect3DRGBDevice, surface, &device2);
+        if (FAILED(hr))
+            return hr;
+    }
+    else
+        hr = IDirect3D2_CreateDevice(d3d2, &IID_IDirect3DRGBDevice, surface, &device2);
+
+    if (FAILED(hr))
+        return hr;
+
+    IDirect3D2_Release(d3d2);
+    IDirectDrawSurface_Release(surface);
+
+    hr = IDirect3DDevice2_QueryInterface(device2, &IID_IDirect3DDevice, (void**)&device1);
+    if (FAILED(hr))
+        return hr;
+
+
+    object->device = device1;
+    object->ddraw = ddraw;
+    object->d3drm = d3drm;
+
+    IDirect3DRM_AddRef(d3drm);
+    IDirect3DDevice2_Release(device2);
+    IDirectDraw2_Release(ddraw2);
+
+    return D3DRM_OK;
+}
+
 static HRESULT WINAPI d3drm_device1_QueryInterface(IDirect3DRMDevice *iface, REFIID riid, void **out)
 {
     struct d3drm_device *device = impl_from_IDirect3DRMDevice(iface);
@@ -420,7 +496,25 @@ static ULONG WINAPI d3drm_device2_Release(IDirect3DRMDevice2 *iface)
     TRACE("%p decreasing refcount to %u.\n", iface, refcount);
 
     if (!refcount)
+    {
+        TRACE("%p\n", device->d3drm);
+        if (device->d3drm)
+            IDirect3DRM_Release(device->d3drm);
+        if (device->primary_surface)
+        {
+            TRACE("Releasing primary surface and attached clipper.\n");
+            IDirectDrawClipper_Release(device->clipper);
+            IDirectDrawSurface_Release(device->primary_surface);
+        }
+        if (device->device)
+        {
+            TRACE("Releasing attached ddraw interfaces.\n");
+            IDirect3DDevice_Release(device->device);
+            IDirectDraw_Release(device->ddraw);
+        }
+
         HeapFree(GetProcessHeap(), 0, device);
+    }
 
     return refcount;
 }
diff --git a/dlls/d3drm/tests/d3drm.c b/dlls/d3drm/tests/d3drm.c
index 0347a6e..12f71dd 100644
--- a/dlls/d3drm/tests/d3drm.c
+++ b/dlls/d3drm/tests/d3drm.c
@@ -2174,20 +2174,20 @@ static void test_create_device_from_clipper2(void)
     ref2 = get_refcount((IUnknown *)d3drm2);
 
     hr = IDirect3DRM2_CreateDeviceFromClipper(d3drm2, clipper, &driver, 0, 0, &device2);
-    todo_wine ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
+    ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
 
     /* If NULL is passed for clipper, CreateDeviceFromClipper returns D3DRMERR_BADVALUE */
     hr = IDirect3DRM2_CreateDeviceFromClipper(d3drm2, NULL, &driver, 0, 0, &device2);
-    todo_wine ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
+    ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
 
     hr = IDirect3DRM2_CreateDeviceFromClipper(d3drm2, clipper, &driver, 300, 200, &device2);
     ok(hr == D3DRM_OK, "Cannot create IDirect3DRMDevice2 interface (hr = %x).\n", hr);
     ref3 = get_refcount((IUnknown *)d3drm1);
-    todo_wine ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
+    ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
     ref3 = get_refcount((IUnknown *)d3drm2);
     ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
     cref2 = get_refcount((IUnknown *)clipper);
-    todo_wine ok(cref2 > cref1, "expected cref2 > cref1, got cref1 = %u , cref2 = %u.\n", cref1, cref2);
+    ok(cref2 > cref1, "expected cref2 > cref1, got cref1 = %u , cref2 = %u.\n", cref1, cref2);
 
     /* Fetch immediate mode device in order to access render target */
     hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3ddevice2);
@@ -2361,20 +2361,20 @@ static void test_create_device_from_clipper3(void)
     ref2 = get_refcount((IUnknown *)d3drm3);
 
     hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, 0, 0, &device3);
-    todo_wine ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
+    ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
 
     /* If NULL is passed for clipper, CreateDeviceFromClipper returns D3DRMERR_BADVALUE */
     hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, NULL, &driver, 0, 0, &device3);
-    todo_wine ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
+    ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
 
     hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, 300, 200, &device3);
     ok(hr == D3DRM_OK, "Cannot create IDirect3DRMDevice3 interface (hr = %x).\n", hr);
     ref3 = get_refcount((IUnknown *)d3drm1);
-    todo_wine ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
+    ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
     ref3 = get_refcount((IUnknown *)d3drm3);
     ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
     cref2 = get_refcount((IUnknown *)clipper);
-    todo_wine ok(cref2 > cref1, "expected cref2 > cref1, got cref1 = %u , cref2 = %u.\n", cref1, cref2);
+    ok(cref2 > cref1, "expected cref2 > cref1, got cref1 = %u , cref2 = %u.\n", cref1, cref2);
 
     /* Fetch immediate mode device in order to access render target */
     hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
-- 
2.3.2 (Apple Git-55)




More information about the wine-patches mailing list