From: Christian Costa Subject: [PATCH 3/4] d3drm: Implement IDirect3DRMFrameX_GetParent and update tests. (resend) Message-Id: <20120413115531.31642.34195.stgit@titanhost> Date: Fri, 13 Apr 2012 13:55:31 +0200 --- dlls/d3drm/frame.c | 55 +++++++++++++++++++++++++++++++++++++++------- dlls/d3drm/tests/d3drm.c | 42 ++++++++++++++++++----------------- 2 files changed, 69 insertions(+), 28 deletions(-) diff --git a/dlls/d3drm/frame.c b/dlls/d3drm/frame.c index 91e27e2..021bb71 100644 --- a/dlls/d3drm/frame.c +++ b/dlls/d3drm/frame.c @@ -34,6 +34,7 @@ typedef struct { IDirect3DRMFrame2 IDirect3DRMFrame2_iface; IDirect3DRMFrame3 IDirect3DRMFrame3_iface; LONG ref; + LPDIRECT3DRMFRAME3 parent; ULONG nb_children; ULONG children_capacity; IDirect3DRMFrame3** children; @@ -327,9 +328,22 @@ static HRESULT WINAPI IDirect3DRMFrame2Impl_GetParent(IDirect3DRMFrame2* iface, { IDirect3DRMFrameImpl *This = impl_from_IDirect3DRMFrame2(iface); - FIXME("(%p/%p)->(%p): stub\n", iface, This, frame); + TRACE("(%p/%p)->(%p)\n", iface, This, frame); - return E_NOTIMPL; + if (!frame) + return D3DRMERR_BADVALUE; + + if (This->parent) + { + *frame = (LPDIRECT3DRMFRAME)(&impl_from_IDirect3DRMFrame3(This->parent)->IDirect3DRMFrame2_iface); + IDirect3DRMFrame_AddRef(*frame); + } + else + { + *frame = NULL; + } + + return D3DRM_OK; } static HRESULT WINAPI IDirect3DRMFrame2Impl_GetPosition(IDirect3DRMFrame2* iface, @@ -1059,18 +1073,28 @@ static HRESULT WINAPI IDirect3DRMFrame3Impl_AddChild(IDirect3DRMFrame3* iface, LPDIRECT3DRMFRAME3 child) { IDirect3DRMFrameImpl *This = impl_from_IDirect3DRMFrame3(iface); - ULONG i; IDirect3DRMFrame3** children; + IDirect3DRMFrame3* parent; TRACE("(%p/%p)->(%p)\n", iface, This, child); 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) + parent = impl_from_IDirect3DRMFrame3(child)->parent; + if (parent) + { + if (parent == iface) + { + /* Passed frame is already a child so return success */ return D3DRM_OK; + } + else + { + /* Remove parent and continue */ + IDirect3DRMFrame3_DeleteChild(parent, child); + } + } if ((This->nb_children + 1) > This->children_capacity) { @@ -1096,6 +1120,7 @@ static HRESULT WINAPI IDirect3DRMFrame3Impl_AddChild(IDirect3DRMFrame3* iface, This->children[This->nb_children++] = child; IDirect3DRMFrame3_AddRef(child); + impl_from_IDirect3DRMFrame3(child)->parent = iface; return D3DRM_OK; } @@ -1218,9 +1243,22 @@ static HRESULT WINAPI IDirect3DRMFrame3Impl_GetParent(IDirect3DRMFrame3* iface, { IDirect3DRMFrameImpl *This = impl_from_IDirect3DRMFrame3(iface); - FIXME("(%p/%p)->(%p): stub\n", iface, This, frame); + TRACE("(%p/%p)->(%p)\n", iface, This, frame); - return E_NOTIMPL; + if (!frame) + return D3DRMERR_BADVALUE; + + if (This->parent) + { + *frame = This->parent; + IDirect3DRMFrame_AddRef(*frame); + } + else + { + *frame = NULL; + } + + return D3DRM_OK; } static HRESULT WINAPI IDirect3DRMFrame3Impl_GetPosition(IDirect3DRMFrame3* iface, @@ -1381,6 +1419,7 @@ static HRESULT WINAPI IDirect3DRMFrame3Impl_DeleteChild(IDirect3DRMFrame3* iface memmove(This->children + i, This->children + i + 1, sizeof(IDirect3DRMFrame3*) * (This->nb_children - 1 - i)); IDirect3DRMFrame3_Release(frame); + impl_from_IDirect3DRMFrame3(frame)->parent = NULL; This->nb_children--; return D3DRM_OK; diff --git a/dlls/d3drm/tests/d3drm.c b/dlls/d3drm/tests/d3drm.c index 91e1c76..ddd152a 100644 --- a/dlls/d3drm/tests/d3drm.c +++ b/dlls/d3drm/tests/d3drm.c @@ -416,10 +416,12 @@ static void test_Frame(void) ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFrame interface (hr = %x)\n", hr); CHECK_REFCOUNT(pFrameC, 1); + hr = IDirect3DRMFrame_GetParent(pFrameC, NULL); + ok(hr == D3DRMERR_BADVALUE, "Should fail and return D3DRM_BADVALUE (hr = %x)\n", hr); pFrameTmp = (void*)0xdeadbeef; hr = IDirect3DRMFrame_GetParent(pFrameC, &pFrameTmp); - todo_wine ok(hr == D3DRM_OK, "Cannot get parent frame (hr = %x)\n", hr); - todo_wine ok(pFrameTmp == NULL, "pFrameTmp = %p\n", pFrameTmp); + ok(hr == D3DRM_OK, "Cannot get parent frame (hr = %x)\n", hr); + ok(pFrameTmp == NULL, "pFrameTmp = %p\n", pFrameTmp); CHECK_REFCOUNT(pFrameC, 1); pArray = NULL; @@ -441,7 +443,7 @@ static void test_Frame(void) /* GetParent with NULL pointer */ hr = IDirect3DRMFrame_GetParent(pFrameP1, NULL); - todo_wine ok(hr == D3DRMERR_BADVALUE, "Should have returned D3DRMERR_BADVALUE (hr = %x)\n", hr); + ok(hr == D3DRMERR_BADVALUE, "Should have returned D3DRMERR_BADVALUE (hr = %x)\n", hr); CHECK_REFCOUNT(pFrameP1, 1); /* [Add/Delete]Child with NULL pointer */ @@ -456,8 +458,8 @@ static void test_Frame(void) /* Add child to first parent */ pFrameTmp = (void*)0xdeadbeef; hr = IDirect3DRMFrame_GetParent(pFrameP1, &pFrameTmp); - todo_wine ok(hr == D3DRM_OK, "Cannot get parent frame (hr = %x)\n", hr); - todo_wine ok(pFrameTmp == NULL, "pFrameTmp = %p\n", pFrameTmp); + ok(hr == D3DRM_OK, "Cannot get parent frame (hr = %x)\n", hr); + ok(pFrameTmp == NULL, "pFrameTmp = %p\n", pFrameTmp); hr = IDirect3DRMFrame_AddChild(pFrameP1, pFrameC); ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr); @@ -480,9 +482,9 @@ static void test_Frame(void) pFrameTmp = (void*)0xdeadbeef; hr = IDirect3DRMFrame_GetParent(pFrameC, &pFrameTmp); - todo_wine ok(hr == D3DRM_OK, "Cannot get parent frame (hr = %x)\n", hr); - todo_wine ok(pFrameTmp == pFrameP1, "pFrameTmp = %p\n", pFrameTmp); - todo_wine CHECK_REFCOUNT(pFrameP1, 2); + ok(hr == D3DRM_OK, "Cannot get parent frame (hr = %x)\n", hr); + ok(pFrameTmp == pFrameP1, "pFrameTmp = %p\n", pFrameTmp); + CHECK_REFCOUNT(pFrameP1, 2); /* Add child to second parent */ hr = IDirect3DRM_CreateFrame(pD3DRM, NULL, &pFrameP2); @@ -490,7 +492,7 @@ static void test_Frame(void) hr = IDirect3DRMFrame_AddChild(pFrameP2, pFrameC); ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr); - todo_wine CHECK_REFCOUNT(pFrameC, 2); + CHECK_REFCOUNT(pFrameC, 2); pArray = NULL; hr = IDirect3DRMFrame_GetChildren(pFrameP2, &pArray); @@ -521,15 +523,15 @@ static void test_Frame(void) pFrameTmp = (void*)0xdeadbeef; hr = IDirect3DRMFrame_GetParent(pFrameC, &pFrameTmp); - todo_wine ok(hr == D3DRM_OK, "Cannot get parent frame (hr = %x)\n", hr); - todo_wine ok(pFrameTmp == pFrameP2, "pFrameTmp = %p\n", pFrameTmp); - todo_wine CHECK_REFCOUNT(pFrameP2, 2); - todo_wine CHECK_REFCOUNT(pFrameC, 2); + ok(hr == D3DRM_OK, "Cannot get parent frame (hr = %x)\n", hr); + ok(pFrameTmp == pFrameP2, "pFrameTmp = %p\n", pFrameTmp); + CHECK_REFCOUNT(pFrameP2, 2); + CHECK_REFCOUNT(pFrameC, 2); /* Add child again */ hr = IDirect3DRMFrame_AddChild(pFrameP2, pFrameC); ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr); - todo_wine CHECK_REFCOUNT(pFrameC, 2); + CHECK_REFCOUNT(pFrameC, 2); pArray = NULL; hr = IDirect3DRMFrame_GetChildren(pFrameP2, &pArray); @@ -548,7 +550,7 @@ static void test_Frame(void) /* Delete child */ hr = IDirect3DRMFrame_DeleteChild(pFrameP2, pFrameC); ok(hr == D3DRM_OK, "Cannot delete child frame (hr = %x)\n", hr); - todo_wine CHECK_REFCOUNT(pFrameC, 1); + CHECK_REFCOUNT(pFrameC, 1); pArray = NULL; hr = IDirect3DRMFrame_GetChildren(pFrameP2, &pArray); @@ -565,17 +567,17 @@ static void test_Frame(void) pFrameTmp = (void*)0xdeadbeef; hr = IDirect3DRMFrame_GetParent(pFrameC, &pFrameTmp); - todo_wine ok(hr == D3DRM_OK, "Cannot get parent frame (hr = %x)\n", hr); - todo_wine ok(pFrameTmp == NULL, "pFrameTmp = %p\n", pFrameTmp); + ok(hr == D3DRM_OK, "Cannot get parent frame (hr = %x)\n", hr); + ok(pFrameTmp == NULL, "pFrameTmp = %p\n", pFrameTmp); /* Add two children */ hr = IDirect3DRMFrame_AddChild(pFrameP2, pFrameC); ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr); - todo_wine CHECK_REFCOUNT(pFrameC, 2); + CHECK_REFCOUNT(pFrameC, 2); hr = IDirect3DRMFrame_AddChild(pFrameP2, pFrameP1); ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr); - todo_wine CHECK_REFCOUNT(pFrameP1, 3); + CHECK_REFCOUNT(pFrameP1, 3); pArray = NULL; hr = IDirect3DRMFrame_GetChildren(pFrameP2, &pArray); @@ -597,7 +599,7 @@ static void test_Frame(void) IDirect3DRMMeshBuilder_Release(pFrameP2); CHECK_REFCOUNT(pFrameC, 2); - todo_wine CHECK_REFCOUNT(pFrameP1, 3); + CHECK_REFCOUNT(pFrameP1, 3); IDirect3DRMMeshBuilder_Release(pFrameC); IDirect3DRMMeshBuilder_Release(pFrameP1);