static ULONG STDMETHODCALLTYPE dxgi_factory_Release(IWineDXGIFactory *iface) { struct dxgi_factory *This = (struct dxgi_factory *)iface; ULONG refcount = InterlockedDecrement(&This->refcount); TRACE("%p decreasing refcount to %u\n", This, refcount); if (!refcount) { UINT i; for (i = 0; i < This->adapter_count; ++i) { IDXGIAdapter_Release(This->adapters[i]); } HeapFree(GetProcessHeap(), 0, This->adapters); EnterCriticalSection(&dxgi_cs); IWineD3D_Release(This->wined3d); LeaveCriticalSection(&dxgi_cs); HeapFree(GetProcessHeap(), 0, This); } return refcount; }
static ULONG WINAPI IDirect3D8Impl_Release(LPDIRECT3D8 iface) { IDirect3D8Impl *This = (IDirect3D8Impl *)iface; ULONG ref = InterlockedDecrement(&This->ref); TRACE("(%p) : ReleaseRef to %d\n", This, ref); if (ref == 0) { TRACE("Releasing wined3d %p\n", This->WineD3D); IWineD3D_Release(This->WineD3D); HeapFree(GetProcessHeap(), 0, This); } return ref; }
static ULONG WINAPI IDirect3D9Impl_Release(LPDIRECT3D9EX iface) { IDirect3D9Impl *This = (IDirect3D9Impl *)iface; ULONG ref = InterlockedDecrement(&This->ref); TRACE("(%p) : ReleaseRef to %d\n", This, ref); if (ref == 0) { EnterCriticalSection(&d3d9_cs); IWineD3D_Release(This->WineD3D); LeaveCriticalSection(&d3d9_cs); HeapFree(GetProcessHeap(), 0, This); } return ref; }
static ULONG WINAPI IDirect3D9Impl_Release(LPDIRECT3D9EX iface) { IDirect3D9Impl *This = (IDirect3D9Impl *)iface; ULONG ref = InterlockedDecrement(&This->ref); TRACE("%p decreasing refcount to %u.\n", iface, ref); if (ref == 0) { wined3d_mutex_lock(); IWineD3D_Release(This->WineD3D); wined3d_mutex_unlock(); HeapFree(GetProcessHeap(), 0, This); } return ref; }
HRESULT dxgi_factory_init(struct dxgi_factory *factory) { HRESULT hr; UINT i; factory->vtbl = &dxgi_factory_vtbl; factory->refcount = 1; EnterCriticalSection(&dxgi_cs); factory->wined3d = WineDirect3DCreate(10, (IUnknown *)factory); if (!factory->wined3d) { LeaveCriticalSection(&dxgi_cs); return DXGI_ERROR_UNSUPPORTED; } factory->adapter_count = IWineD3D_GetAdapterCount(factory->wined3d); LeaveCriticalSection(&dxgi_cs); factory->adapters = HeapAlloc(GetProcessHeap(), 0, factory->adapter_count * sizeof(*factory->adapters)); if (!factory->adapters) { ERR("Failed to allocate DXGI adapter array memory.\n"); hr = E_OUTOFMEMORY; goto fail; } for (i = 0; i < factory->adapter_count; ++i) { struct dxgi_adapter *adapter = HeapAlloc(GetProcessHeap(), 0, sizeof(*adapter)); if (!adapter) { UINT j; ERR("Failed to allocate DXGI adapter memory.\n"); for (j = 0; j < i; ++j) { IDXGIAdapter_Release(factory->adapters[j]); } hr = E_OUTOFMEMORY; goto fail; } hr = dxgi_adapter_init(adapter, (IWineDXGIFactory *)factory, i); if (FAILED(hr)) { UINT j; ERR("Failed to initialize adapter, hr %#x.\n", hr); HeapFree(GetProcessHeap(), 0, adapter); for (j = 0; j < i; ++j) { IDXGIAdapter_Release(factory->adapters[j]); } goto fail; } factory->adapters[i] = (IDXGIAdapter *)adapter; } return S_OK; fail: HeapFree(GetProcessHeap(), 0, factory->adapters); EnterCriticalSection(&dxgi_cs); IWineD3D_Release(factory->wined3d); LeaveCriticalSection(&dxgi_cs); return hr; }