From: Mohamad Al-Jaf mohamadaljaf@gmail.com
--- dlls/dxcore/dxcore.c | 180 ++++++++++++++++++++++++++++++++++++- dlls/dxcore/tests/dxcore.c | 9 -- 2 files changed, 176 insertions(+), 13 deletions(-)
diff --git a/dlls/dxcore/dxcore.c b/dlls/dxcore/dxcore.c index f63f1c9f3b9..38598f99a89 100644 --- a/dlls/dxcore/dxcore.c +++ b/dlls/dxcore/dxcore.c @@ -27,11 +27,144 @@
WINE_DEFAULT_DEBUG_CHANNEL(dxcore);
+struct dxcore_adapter +{ + IDXCoreAdapter IDXCoreAdapter_iface; + LONG ref; +}; + +static inline struct dxcore_adapter *impl_from_IDXCoreAdapter( IDXCoreAdapter *iface ) +{ + return CONTAINING_RECORD( iface, struct dxcore_adapter, IDXCoreAdapter_iface ); +} + +static HRESULT WINAPI dxcore_adapter_QueryInterface( IDXCoreAdapter *iface, REFIID iid, void **out ) +{ + struct dxcore_adapter *impl = impl_from_IDXCoreAdapter( iface ); + + TRACE( "iface %p, iid %s, out %p.\n", iface, debugstr_guid( iid ), out ); + + if (IsEqualGUID( iid, &IID_IUnknown ) || + IsEqualGUID( iid, &IID_IDXCoreAdapter )) + { + *out = &impl->IDXCoreAdapter_iface; + IUnknown_AddRef( (IUnknown *)*out ); + return S_OK; + } + + FIXME( "%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid( iid ) ); + *out = NULL; + return E_NOINTERFACE; +} + +static ULONG WINAPI dxcore_adapter_AddRef( IDXCoreAdapter *iface ) +{ + struct dxcore_adapter *impl = impl_from_IDXCoreAdapter( iface ); + ULONG ref = InterlockedIncrement( &impl->ref ); + TRACE( "iface %p, ref %lu.\n", iface, ref ); + return ref; +} + +static ULONG WINAPI dxcore_adapter_Release( IDXCoreAdapter *iface ) +{ + struct dxcore_adapter *impl = impl_from_IDXCoreAdapter( iface ); + ULONG ref = InterlockedDecrement( &impl->ref ); + + TRACE( "iface %p, ref %lu.\n", iface, ref ); + + if (!ref) free( impl ); + return ref; +} + +static BOOL WINAPI dxcore_adapter_IsValid( IDXCoreAdapter *iface ) +{ + FIXME( "iface %p stub!\n", iface ); + return FALSE; +} + +static BOOL WINAPI dxcore_adapter_IsAttributeSupported( IDXCoreAdapter *iface, REFGUID attribute ) +{ + FIXME( "iface %p, attribute %s stub!\n", iface, debugstr_guid( attribute ) ); + return FALSE; +} + +static BOOL WINAPI dxcore_adapter_IsPropertySupported( IDXCoreAdapter *iface, DXCoreAdapterProperty property ) +{ + FIXME( "iface %p, property %u stub!\n", iface, property ); + return FALSE; +} + +static HRESULT WINAPI dxcore_adapter_GetProperty( IDXCoreAdapter *iface, DXCoreAdapterProperty property, size_t buffer_size, void *buffer ) +{ + FIXME( "iface %p, property %u, buffer_size %Iu, buffer stub!%p\n", iface, property, buffer_size, buffer ); + return E_NOTIMPL; +} + +static HRESULT WINAPI dxcore_adapter_GetPropertySize( IDXCoreAdapter *iface, DXCoreAdapterProperty property, size_t *buffer_size ) +{ + FIXME( "iface %p, property %u, buffer_size %p stub!\n", iface, property, buffer_size ); + return E_NOTIMPL; +} + +static BOOL WINAPI dxcore_adapter_IsQueryStateSupported( IDXCoreAdapter *iface, DXCoreAdapterState property ) +{ + FIXME( "iface %p, property %u stub!\n", iface, property ); + return FALSE; +} + +static HRESULT WINAPI dxcore_adapter_QueryState( IDXCoreAdapter *iface, DXCoreAdapterState state, size_t state_details_size, + const void *state_details, size_t buffer_size, void *buffer ) +{ + FIXME( "iface %p, state %u, state_details_size %Iu, state_details %p, buffer_size %Iu, buffer %p stub!\n", + iface, state, state_details_size, state_details, buffer_size, buffer ); + return E_NOTIMPL; +} + +static BOOL WINAPI dxcore_adapter_IsSetStateSupported( IDXCoreAdapter *iface, DXCoreAdapterState property ) +{ + FIXME( "iface %p, property %u stub!\n", iface, property ); + return FALSE; +} + +static HRESULT WINAPI dxcore_adapter_SetState( IDXCoreAdapter *iface, DXCoreAdapterState state, size_t state_details_size, + const void *state_details, size_t buffer_size, const void *buffer ) +{ + FIXME( "iface %p, state %u, state_details_size %Iu, state_details %p, buffer_size %Iu, buffer %p stub!\n", + iface, state, state_details_size, state_details, buffer_size, buffer ); + return E_NOTIMPL; +} + +static HRESULT WINAPI dxcore_adapter_GetFactory( IDXCoreAdapter *iface, REFIID riid, void **ppv ) +{ + FIXME( "iface %p, riid %s, ppv %p stub!\n", iface, debugstr_guid( riid ), ppv ); + return E_NOTIMPL; +} + +static const struct IDXCoreAdapterVtbl dxcore_adapter_vtbl = +{ + /* IUnknown methods */ + dxcore_adapter_QueryInterface, + dxcore_adapter_AddRef, + dxcore_adapter_Release, + /* IDXCoreAdapter methods */ + dxcore_adapter_IsValid, + dxcore_adapter_IsAttributeSupported, + dxcore_adapter_IsPropertySupported, + dxcore_adapter_GetProperty, + dxcore_adapter_GetPropertySize, + dxcore_adapter_IsQueryStateSupported, + dxcore_adapter_QueryState, + dxcore_adapter_IsSetStateSupported, + dxcore_adapter_SetState, + dxcore_adapter_GetFactory, +}; + struct dxcore_adapter_list { IDXCoreAdapterList IDXCoreAdapterList_iface; LONG ref;
+ struct dxcore_adapter **adapters; uint32_t adapter_count; };
@@ -74,14 +207,33 @@ static ULONG WINAPI dxcore_adapter_list_Release( IDXCoreAdapterList *iface )
TRACE( "iface %p, ref %lu.\n", iface, ref );
- if (!ref) free( impl ); + if (!ref) + { + for (UINT i = 0; i < impl->adapter_count; i++) + if (impl->adapters[i]) IDXCoreAdapter_Release( &impl->adapters[i]->IDXCoreAdapter_iface ); + free( impl->adapters ); + free( impl ); + } return ref; }
static HRESULT WINAPI dxcore_adapter_list_GetAdapter( IDXCoreAdapterList *iface, uint32_t index, REFIID riid, void **ppv ) { - FIXME( "iface %p, index %u, riid %s, ppv %p stub!\n", iface, index, debugstr_guid( riid ), ppv ); - return E_NOTIMPL; + struct dxcore_adapter_list *impl = impl_from_IDXCoreAdapterList( iface ); + IDXCoreAdapter *adapter; + + TRACE( "iface %p, index %u, riid %s, ppv %p\n", iface, index, debugstr_guid( riid ), ppv ); + + if (!ppv) return E_POINTER; + if (index >= impl->adapter_count) + { + *ppv = NULL; + return E_INVALIDARG; + } + + adapter = &impl->adapters[index]->IDXCoreAdapter_iface; + TRACE( "returning IDXCoreAdapter %p for index %u.\n", adapter, index ); + return IDXCoreAdapter_QueryInterface( adapter, riid, ppv ); }
static uint32_t WINAPI dxcore_adapter_list_GetAdapterCount( IDXCoreAdapterList *iface ) @@ -185,9 +337,29 @@ static HRESULT get_adapters( struct dxcore_adapter_list *impl ) HRESULT hr = S_OK;
if (!wined3d) return E_FAIL; + if (!(impl->adapter_count = wined3d_get_adapter_count( wined3d ) )) goto done; + if (!(impl->adapters = calloc( impl->adapter_count, sizeof( *impl->adapters ) ))) + { + hr = E_OUTOFMEMORY; + goto done; + }
- impl->adapter_count = wined3d_get_adapter_count( wined3d ); + for (UINT i = 0; i < impl->adapter_count; i++) + { + struct dxcore_adapter *dxcore_adapter = calloc( 1, sizeof( *dxcore_adapter )); + + if (!dxcore_adapter) + { + hr = E_OUTOFMEMORY; + goto done; + } + + dxcore_adapter->IDXCoreAdapter_iface.lpVtbl = &dxcore_adapter_vtbl; + dxcore_adapter->ref = 1;
+ impl->adapters[i] = dxcore_adapter; + } +done: wined3d_decref( wined3d ); return hr; } diff --git a/dlls/dxcore/tests/dxcore.c b/dlls/dxcore/tests/dxcore.c index 00c441732f0..5c845f05cb4 100644 --- a/dlls/dxcore/tests/dxcore.c +++ b/dlls/dxcore/tests/dxcore.c @@ -103,24 +103,16 @@ static void test_DXCoreCreateAdapterFactory(void) ok( adapter_count != 0, "IDXCoreAdapterList_GetAdapterCount returned 0.\n" );
hr = IDXCoreAdapterList_GetAdapter( adapter_list, 0xdeadbeef, &IID_IDXCoreAdapter, NULL ); - todo_wine ok( hr == E_POINTER, "got hr %#lx.\n", hr ); hr = IDXCoreAdapterList_GetAdapter( adapter_list, adapter_count, &IID_IDXCoreAdapter, (void **)&adapter ); - todo_wine ok( hr == E_INVALIDARG, "got hr %#lx.\n", hr ); - todo_wine ok( adapter == NULL, "got adapter %p.\n", adapter ); hr = IDXCoreAdapterList_GetAdapter( adapter_list, 0, &IID_IDXCoreAdapterList, (void **)&adapter ); - todo_wine ok( hr == E_NOINTERFACE, "got hr %#lx.\n", hr );
hr = IDXCoreAdapterList_GetAdapter( adapter_list, 0, &IID_IDXCoreAdapter, (void **)&adapter ); - todo_wine ok( hr == S_OK, "got hr %#lx.\n", hr ); - if (SUCCEEDED(hr)) - { hr = IDXCoreAdapterList_GetAdapter( adapter_list, 0, &IID_IDXCoreAdapter, (void **)&adapter2 ); - todo_wine ok( hr == S_OK, "got hr %#lx.\n", hr ); ok( adapter == adapter2, "got adapter %p, adapter2 %p.\n", adapter, adapter2 ); ref = IDXCoreAdapter_Release( adapter2 ); @@ -134,7 +126,6 @@ static void test_DXCoreCreateAdapterFactory(void) ref = IDXCoreAdapter_Release( adapter ); todo_wine ok( ref == 2, "got ref %ld.\n", ref ); - } ref = IDXCoreAdapterList_Release( adapter_list ); ok( ref == 0, "got ref %ld.\n", ref ); ref = IDXCoreAdapterFactory_Release( adapter_factory );