From 37c427f54ad8829e1a135611622d4da51b10624e Mon Sep 17 00:00:00 2001 From: Christian Costa Date: Tue, 15 May 2012 08:08:31 +0200 Subject: [PATCH] d3drm: Implement IDirect3DRMFrame2Impl_GetVisuals and IDirect3DRMVisualArray interface. --- dlls/d3drm/frame.c | 155 ++++++++++++++++++++++++++++++++++++++++++++++- dlls/d3drm/tests/d3drm.c | 2 +- 2 files changed, 154 insertions(+), 3 deletions(-) diff --git a/dlls/d3drm/frame.c b/dlls/d3drm/frame.c index 60e8966c0a0..d02cba882af 100644 --- a/dlls/d3drm/frame.c +++ b/dlls/d3drm/frame.c @@ -2,6 +2,7 @@ * Implementation of IDirect3DRMFrame Interface * * Copyright 2011, 2012 André Hentschel + * Copyright 2012 Christian Costa * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -63,7 +64,15 @@ typedef struct { LPDIRECT3DRMFRAME* frames; } IDirect3DRMFrameArrayImpl; +typedef struct { + IDirect3DRMVisualArray IDirect3DRMVisualArray_iface; + LONG ref; + ULONG size; + LPDIRECT3DRMVISUAL* visuals; +} IDirect3DRMVisualArrayImpl; + HRESULT Direct3DRMFrameArray_create(IDirect3DRMFrameArray** obj); +HRESULT Direct3DRMVisualArray_create(IDirect3DRMVisualArray** ret_iface); static inline IDirect3DRMFrameImpl *impl_from_IDirect3DRMFrame2(IDirect3DRMFrame2 *iface) { @@ -460,10 +469,36 @@ static HRESULT WINAPI IDirect3DRMFrame2Impl_GetVisuals(IDirect3DRMFrame2* iface, LPDIRECT3DRMVISUALARRAY *visuals) { IDirect3DRMFrameImpl *This = impl_from_IDirect3DRMFrame2(iface); + IDirect3DRMVisualArrayImpl* obj; + HRESULT hr; - FIXME("(%p/%p)->(%p): stub\n", iface, This, visuals); + TRACE("(%p/%p)->(%p)\n", iface, This, visuals); - return E_NOTIMPL; + if (!visuals) + return D3DRMERR_BADVALUE; + + hr = Direct3DRMVisualArray_create(visuals); + + if (hr != D3DRM_OK) + return hr; + + obj = (IDirect3DRMVisualArrayImpl*)*visuals; + + obj->size = This->nb_visuals; + if (This->nb_visuals) + { + ULONG i; + obj->visuals = HeapAlloc(GetProcessHeap(), 0, This->nb_visuals * sizeof(LPDIRECT3DRMVISUAL)); + if (!obj->visuals) + return E_OUTOFMEMORY; + for (i = 0; i < This->nb_visuals; i++) + { + obj->visuals[i] = This->visuals[i]; + IDirect3DRMVisual_AddRef(This->visuals[i]); + } + } + + return D3DRM_OK; } static HRESULT WINAPI IDirect3DRMFrame2Impl_GetTextureTopology(IDirect3DRMFrame2* iface, @@ -2360,3 +2395,119 @@ HRESULT Direct3DRMFrameArray_create(IDirect3DRMFrameArray** obj) return S_OK; } + +/*** IUnknown methods ***/ +static HRESULT WINAPI IDirect3DRMVisualArrayImpl_QueryInterface(IDirect3DRMVisualArray* iface, + REFIID riid, void** ret_iface) +{ + TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ret_iface); + + if (IsEqualGUID(riid, &IID_IUnknown) || + IsEqualGUID(riid, &IID_IDirect3DRMFrameArray)) + { + *ret_iface = iface; + IDirect3DRMVisualArray_AddRef(iface); + return S_OK; + } + + *ret_iface = NULL; + + WARN("Interface %s not implemented\n", debugstr_guid(riid)); + + return E_NOINTERFACE; +} + +static ULONG WINAPI IDirect3DRMVisualArrayImpl_AddRef(IDirect3DRMVisualArray* iface) +{ + IDirect3DRMVisualArrayImpl *This = (IDirect3DRMVisualArrayImpl*)iface; + ULONG ref = InterlockedIncrement(&This->ref); + + TRACE("(%p)->(): new ref = %u\n", iface, ref); + + return ref; +} + +static ULONG WINAPI IDirect3DRMVisualArrayImpl_Release(IDirect3DRMVisualArray* iface) +{ + IDirect3DRMVisualArrayImpl *This = (IDirect3DRMVisualArrayImpl*)iface; + ULONG ref = InterlockedDecrement(&This->ref); + ULONG i; + + TRACE("(%p)->(): new ref = %u\n", iface, ref); + + if (!ref) + { + for (i = 0; i < This->size; i++) + IDirect3DRMVisual_Release(This->visuals[i]); + HeapFree(GetProcessHeap(), 0, This->visuals); + HeapFree(GetProcessHeap(), 0, This); + } + + return ref; +} + +/*** IDirect3DRMArray methods ***/ +static DWORD WINAPI IDirect3DRMVisualArrayImpl_GetSize(IDirect3DRMVisualArray* iface) +{ + IDirect3DRMVisualArrayImpl *This = (IDirect3DRMVisualArrayImpl*)iface; + + TRACE("(%p)->() = %d\n", iface, This->size); + + return This->size; +} + +/*** IDirect3DRMVisualArray methods ***/ +static HRESULT WINAPI IDirect3DRMVisualArrayImpl_GetElement(IDirect3DRMVisualArray* iface, DWORD index, LPDIRECT3DRMVISUAL* visual) +{ + IDirect3DRMVisualArrayImpl *This = (IDirect3DRMVisualArrayImpl*)iface; + + TRACE("(%p)->(%u, %p)\n", iface, index, visual); + + if (!visual) + return D3DRMERR_BADVALUE; + + *visual = NULL; + + if (index >= This->size) + return D3DRMERR_BADVALUE; + + IDirect3DRMVisual_AddRef(This->visuals[index]); + *visual = This->visuals[index]; + + return D3DRM_OK; +} + +static const struct IDirect3DRMVisualArrayVtbl Direct3DRMVisualArray_Vtbl = +{ + /*** IUnknown methods ***/ + IDirect3DRMVisualArrayImpl_QueryInterface, + IDirect3DRMVisualArrayImpl_AddRef, + IDirect3DRMVisualArrayImpl_Release, + /*** IDirect3DRMArray methods ***/ + IDirect3DRMVisualArrayImpl_GetSize, + /*** IDirect3DRMVisualArray methods ***/ + IDirect3DRMVisualArrayImpl_GetElement +}; + +HRESULT Direct3DRMVisualArray_create(IDirect3DRMVisualArray** ret_iface) +{ + IDirect3DRMVisualArrayImpl* object; + + TRACE("(%p)\n", ret_iface); + + *ret_iface = NULL; + + object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DRMVisualArrayImpl)); + if (!object) + { + ERR("Out of memory\n"); + return E_OUTOFMEMORY; + } + + object->IDirect3DRMVisualArray_iface.lpVtbl = &Direct3DRMVisualArray_Vtbl; + object->ref = 1; + + *ret_iface = &object->IDirect3DRMVisualArray_iface; + + return S_OK; +} diff --git a/dlls/d3drm/tests/d3drm.c b/dlls/d3drm/tests/d3drm.c index 8a8968ea274..3126fbde211 100644 --- a/dlls/d3drm/tests/d3drm.c +++ b/dlls/d3drm/tests/d3drm.c @@ -662,7 +662,7 @@ static void test_Frame(void) pVisualArray = NULL; hr = IDirect3DRMFrame_GetVisuals(pFrameP1, &pVisualArray); - todo_wine ok(hr == D3DRM_OK, "Cannot get visuals (hr = %x)\n", hr); + ok(hr == D3DRM_OK, "Cannot get visuals (hr = %x)\n", hr); if (pVisualArray) { count = IDirect3DRMVisualArray_GetSize(pVisualArray); -- 2.11.4.GIT