[PATCH 1/4] d3drm: Implement IDirect3DRMFrameX_AddChild.

Christian Costa titan.costa at gmail.com
Mon Apr 2 01:54:12 CDT 2012


---
 dlls/d3drm/frame.c       |   43 +++++++++++++++++++++++++++++++++++++++----
 dlls/d3drm/tests/d3drm.c |   18 +++++++++---------
 2 files changed, 48 insertions(+), 13 deletions(-)

diff --git a/dlls/d3drm/frame.c b/dlls/d3drm/frame.c
index 5d5427f..d29c450 100644
--- a/dlls/d3drm/frame.c
+++ b/dlls/d3drm/frame.c
@@ -33,6 +33,8 @@ typedef struct {
     IDirect3DRMFrame2 IDirect3DRMFrame2_iface;
     IDirect3DRMFrame3 IDirect3DRMFrame3_iface;
     LONG ref;
+    ULONG nb_children;
+    IDirect3DRMFrame3** children;
 } IDirect3DRMFrameImpl;
 
 static inline IDirect3DRMFrameImpl *impl_from_IDirect3DRMFrame2(IDirect3DRMFrame2 *iface)
@@ -89,11 +91,17 @@ static ULONG WINAPI IDirect3DRMFrame2Impl_Release(IDirect3DRMFrame2* iface)
 {
     IDirect3DRMFrameImpl *This = impl_from_IDirect3DRMFrame2(iface);
     ULONG ref = InterlockedDecrement(&This->ref);
+    ULONG i;
 
     TRACE("(%p)->(): new ref = %d\n", This, ref);
 
     if (!ref)
+    {
+        for (i = 0; i < This->nb_children; i++)
+            IDirect3DRMFrame3_Release(This->children[i]);
+        HeapFree(GetProcessHeap(), 0, This->children);
         HeapFree(GetProcessHeap(), 0, This);
+    }
 
     return ref;
 }
@@ -185,10 +193,16 @@ static HRESULT WINAPI IDirect3DRMFrame2Impl_AddChild(IDirect3DRMFrame2* iface,
                                                      LPDIRECT3DRMFRAME child)
 {
     IDirect3DRMFrameImpl *This = impl_from_IDirect3DRMFrame2(iface);
+    LPDIRECT3DRMFRAME3 frame;
 
-    FIXME("(%p/%p)->(%p): stub\n", iface, This, child);
+    TRACE("(%p/%p)->(%p)\n", iface, This, child);
 
-    return E_NOTIMPL;
+    if (!child)
+        return D3DRMERR_BADOBJECT;
+
+    frame = &impl_from_IDirect3DRMFrame2((LPDIRECT3DRMFRAME2)child)->IDirect3DRMFrame3_iface;
+
+    return IDirect3DRMFrame3_AddChild(&This->IDirect3DRMFrame3_iface, frame);
 }
 
 static HRESULT WINAPI IDirect3DRMFrame2Impl_AddLight(IDirect3DRMFrame2* iface,
@@ -1036,10 +1050,31 @@ static HRESULT WINAPI IDirect3DRMFrame3Impl_AddChild(IDirect3DRMFrame3* iface,
                                                      LPDIRECT3DRMFRAME3 child)
 {
     IDirect3DRMFrameImpl *This = impl_from_IDirect3DRMFrame3(iface);
+    ULONG i;
+    IDirect3DRMFrame3** children;
 
-    FIXME("(%p/%p)->(%p): stub\n", iface, This, child);
+    TRACE("(%p/%p)->(%p)\n", iface, This, child);
 
-    return E_NOTIMPL;
+    if (!child)
+        return D3DRMERR_BADOBJECT;
+
+    /* Check if already existing and return gracefully without increasing ref count */
+    for (i = 0; i < This->nb_children; i++)
+        if (This->children[i] == child)
+            return D3DRM_OK;
+
+
+    children = (IDirect3DRMFrame3**)HeapAlloc(GetProcessHeap(), 0, (This->nb_children + 1) * sizeof(IDirect3DRMFrame3*));
+    if (!children)
+        return E_OUTOFMEMORY;
+
+    CopyMemory(children, This->children, This->nb_children * sizeof(IDirect3DRMFrame3*));
+    HeapFree(GetProcessHeap(), 0, This->children);
+    This->children = children;
+    This->children[This->nb_children++] = child;
+    IDirect3DRMFrame3_AddRef(child);
+
+    return D3DRM_OK;
 }
 
 static HRESULT WINAPI IDirect3DRMFrame3Impl_AddLight(IDirect3DRMFrame3* iface,
diff --git a/dlls/d3drm/tests/d3drm.c b/dlls/d3drm/tests/d3drm.c
index 0a05dcd..caa9dc5 100644
--- a/dlls/d3drm/tests/d3drm.c
+++ b/dlls/d3drm/tests/d3drm.c
@@ -446,7 +446,7 @@ static void test_Frame(void)
 
     /* [Add/Delete]Child with NULL pointer */
     hr = IDirect3DRMFrame_AddChild(pFrameP1, NULL);
-    todo_wine ok(hr == D3DRMERR_BADOBJECT, "Should have returned D3DRMERR_BADOBJECT (hr = %x)\n", hr);
+    ok(hr == D3DRMERR_BADOBJECT, "Should have returned D3DRMERR_BADOBJECT (hr = %x)\n", hr);
     CHECK_REFCOUNT(pFrameP1, 1);
 
     hr = IDirect3DRMFrame_DeleteChild(pFrameP1, NULL);
@@ -460,9 +460,9 @@ static void test_Frame(void)
     todo_wine ok(pFrameTmp == NULL, "pFrameTmp = %p\n", pFrameTmp);
 
     hr = IDirect3DRMFrame_AddChild(pFrameP1, pFrameC);
-    todo_wine ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr);
+    ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr);
     CHECK_REFCOUNT(pFrameP1, 1);
-    todo_wine CHECK_REFCOUNT(pFrameC, 2);
+    CHECK_REFCOUNT(pFrameC, 2);
 
     pArray = NULL;
     hr = IDirect3DRMFrame_GetChildren(pFrameP1, &pArray);
@@ -489,7 +489,7 @@ static void test_Frame(void)
     ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFrame interface (hr = %x)\n", hr);
 
     hr = IDirect3DRMFrame_AddChild(pFrameP2, pFrameC);
-    todo_wine ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr);
+    ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr);
     todo_wine CHECK_REFCOUNT(pFrameC, 2);
 
     pArray = NULL;
@@ -528,7 +528,7 @@ static void test_Frame(void)
 
     /* Add child again */
     hr = IDirect3DRMFrame_AddChild(pFrameP2, pFrameC);
-    todo_wine ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr);
+    ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr);
     todo_wine CHECK_REFCOUNT(pFrameC, 2);
 
     pArray = NULL;
@@ -548,7 +548,7 @@ static void test_Frame(void)
     /* Delete child */
     hr = IDirect3DRMFrame_DeleteChild(pFrameP2, pFrameC);
     todo_wine ok(hr == D3DRM_OK, "Cannot delete child frame (hr = %x)\n", hr);
-    CHECK_REFCOUNT(pFrameC, 1);
+    todo_wine CHECK_REFCOUNT(pFrameC, 1);
 
     pArray = NULL;
     hr = IDirect3DRMFrame_GetChildren(pFrameP2, &pArray);
@@ -570,11 +570,11 @@ static void test_Frame(void)
 
     /* Add two children */
     hr = IDirect3DRMFrame_AddChild(pFrameP2, pFrameC);
-    todo_wine ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr);
+    ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr);
     todo_wine CHECK_REFCOUNT(pFrameC, 2);
 
     hr = IDirect3DRMFrame_AddChild(pFrameP2, pFrameP1);
-    todo_wine ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr);
+    ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr);
     todo_wine CHECK_REFCOUNT(pFrameP1, 3);
 
     pArray = NULL;
@@ -596,7 +596,7 @@ static void test_Frame(void)
     }
 
     IDirect3DRMMeshBuilder_Release(pFrameP2);
-    todo_wine CHECK_REFCOUNT(pFrameC, 2);
+    CHECK_REFCOUNT(pFrameC, 2);
     todo_wine CHECK_REFCOUNT(pFrameP1, 3);
 
     IDirect3DRMMeshBuilder_Release(pFrameC);




More information about the wine-patches mailing list