2 * Copyright 2008 Henri Verbeet for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "wine/port.h"
23 #include "dxgi_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(dxgi);
27 /* IUnknown methods */
29 static HRESULT STDMETHODCALLTYPE dxgi_device_QueryInterface(IWineDXGIDevice *iface, REFIID riid, void **object)
31 struct dxgi_device *This = (struct dxgi_device *)iface;
33 TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object);
35 if (IsEqualGUID(riid, &IID_IUnknown)
36 || IsEqualGUID(riid, &IID_IDXGIObject)
37 || IsEqualGUID(riid, &IID_IDXGIDevice)
38 || IsEqualGUID(riid, &IID_IWineDXGIDevice))
40 IUnknown_AddRef(iface);
45 if (This->child_layer)
47 TRACE("forwarding to child layer %p\n", This->child_layer);
48 return IUnknown_QueryInterface(This->child_layer, riid, object);
51 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
57 static ULONG STDMETHODCALLTYPE dxgi_device_AddRef(IWineDXGIDevice *iface)
59 struct dxgi_device *This = (struct dxgi_device *)iface;
60 ULONG refcount = InterlockedIncrement(&This->refcount);
62 TRACE("%p increasing refcount to %u\n", This, refcount);
67 static ULONG STDMETHODCALLTYPE dxgi_device_Release(IWineDXGIDevice *iface)
69 struct dxgi_device *This = (struct dxgi_device *)iface;
70 ULONG refcount = InterlockedDecrement(&This->refcount);
72 TRACE("%p decreasing refcount to %u\n", This, refcount);
76 if (This->child_layer) IUnknown_Release(This->child_layer);
77 EnterCriticalSection(&dxgi_cs);
78 IWineD3DDevice_Release(This->wined3d_device);
79 LeaveCriticalSection(&dxgi_cs);
80 IWineDXGIFactory_Release(This->factory);
81 HeapFree(GetProcessHeap(), 0, This);
87 /* IDXGIObject methods */
89 static HRESULT STDMETHODCALLTYPE dxgi_device_SetPrivateData(IWineDXGIDevice *iface,
90 REFGUID guid, UINT data_size, const void *data)
92 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n", iface, debugstr_guid(guid), data_size, data);
97 static HRESULT STDMETHODCALLTYPE dxgi_device_SetPrivateDataInterface(IWineDXGIDevice *iface,
98 REFGUID guid, const IUnknown *object)
100 FIXME("iface %p, guid %s, object %p stub!\n", iface, debugstr_guid(guid), object);
105 static HRESULT STDMETHODCALLTYPE dxgi_device_GetPrivateData(IWineDXGIDevice *iface,
106 REFGUID guid, UINT *data_size, void *data)
108 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n", iface, debugstr_guid(guid), data_size, data);
113 static HRESULT STDMETHODCALLTYPE dxgi_device_GetParent(IWineDXGIDevice *iface, REFIID riid, void **parent)
115 FIXME("iface %p, riid %s, parent %p stub!\n", iface, debugstr_guid(riid), parent);
120 /* IDXGIDevice methods */
122 static HRESULT STDMETHODCALLTYPE dxgi_device_GetAdapter(IWineDXGIDevice *iface, IDXGIAdapter **adapter)
124 struct dxgi_device *This = (struct dxgi_device *)iface;
125 WINED3DDEVICE_CREATION_PARAMETERS create_parameters;
128 TRACE("iface %p, adapter %p\n", iface, adapter);
130 EnterCriticalSection(&dxgi_cs);
132 hr = IWineD3DDevice_GetCreationParameters(This->wined3d_device, &create_parameters);
135 LeaveCriticalSection(&dxgi_cs);
139 LeaveCriticalSection(&dxgi_cs);
141 return IWineDXGIFactory_EnumAdapters(This->factory, create_parameters.AdapterOrdinal, adapter);
144 static HRESULT STDMETHODCALLTYPE dxgi_device_CreateSurface(IWineDXGIDevice *iface,
145 const DXGI_SURFACE_DESC *desc, UINT surface_count, DXGI_USAGE usage,
146 const DXGI_SHARED_RESOURCE *shared_resource, IDXGISurface **surface)
148 IWineD3DDeviceParent *device_parent;
153 TRACE("iface %p, desc %p, surface_count %u, usage %#x, shared_resource %p, surface %p\n",
154 iface, desc, surface_count, usage, shared_resource, surface);
156 hr = IWineDXGIDevice_QueryInterface(iface, &IID_IWineD3DDeviceParent, (void **)&device_parent);
159 ERR("Device should implement IWineD3DDeviceParent\n");
163 FIXME("Implement DXGI<->wined3d usage conversion\n");
165 memset(surface, 0, surface_count * sizeof(*surface));
166 for (i = 0; i < surface_count; ++i)
168 IWineD3DSurface *wined3d_surface;
171 hr = IWineD3DDeviceParent_CreateSurface(device_parent, NULL, desc->Width, desc->Height,
172 wined3dformat_from_dxgi_format(desc->Format), usage, WINED3DPOOL_DEFAULT, 0,
173 WINED3DCUBEMAP_FACE_POSITIVE_X, &wined3d_surface);
176 ERR("CreateSurface failed, returning %#x\n", hr);
180 hr = IWineD3DSurface_GetParent(wined3d_surface, &parent);
181 IWineD3DSurface_Release(wined3d_surface);
184 ERR("GetParent failed, returning %#x\n", hr);
188 hr = IUnknown_QueryInterface(parent, &IID_IDXGISurface, (void **)&surface[i]);
189 IUnknown_Release(parent);
192 ERR("Surface should implement IDXGISurface\n");
196 TRACE("Created IDXGISurface %p (%u/%u)\n", surface[i], i + 1, surface_count);
198 IWineD3DDeviceParent_Release(device_parent);
203 for (j = 0; j < i; ++j)
205 IDXGISurface_Release(surface[i]);
207 IWineD3DDeviceParent_Release(device_parent);
211 static HRESULT STDMETHODCALLTYPE dxgi_device_QueryResourceResidency(IWineDXGIDevice *iface,
212 IUnknown *const *resources, DXGI_RESIDENCY *residency, UINT resource_count)
214 FIXME("iface %p, resources %p, residency %p, resource_count %u stub!\n",
215 iface, resources, residency, resource_count);
220 static HRESULT STDMETHODCALLTYPE dxgi_device_SetGPUThreadPriority(IWineDXGIDevice *iface, INT priority)
222 FIXME("iface %p, priority %d stub!\n", iface, priority);
227 static HRESULT STDMETHODCALLTYPE dxgi_device_GetGPUThreadPriority(IWineDXGIDevice *iface, INT *priority)
229 FIXME("iface %p, priority %p stub!\n", iface, priority);
234 /* IWineDXGIDevice methods */
236 static IWineD3DDevice * STDMETHODCALLTYPE dxgi_device_get_wined3d_device(IWineDXGIDevice *iface)
238 struct dxgi_device *This = (struct dxgi_device *)iface;
240 TRACE("iface %p\n", iface);
242 EnterCriticalSection(&dxgi_cs);
243 IWineD3DDevice_AddRef(This->wined3d_device);
244 LeaveCriticalSection(&dxgi_cs);
245 return This->wined3d_device;
248 static HRESULT STDMETHODCALLTYPE dxgi_device_create_surface(IWineDXGIDevice *iface, const DXGI_SURFACE_DESC *desc,
249 DXGI_USAGE usage, const DXGI_SHARED_RESOURCE *shared_resource, IUnknown *outer, void **surface)
251 struct dxgi_surface *object;
253 FIXME("iface %p, desc %p, usage %#x, shared_resource %p, outer %p, surface %p partial stub!\n",
254 iface, desc, usage, shared_resource, outer, surface);
256 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
259 ERR("Failed to allocate DXGI surface object memory\n");
260 return E_OUTOFMEMORY;
263 object->vtbl = &dxgi_surface_vtbl;
264 object->inner_unknown_vtbl = &dxgi_surface_inner_unknown_vtbl;
265 object->refcount = 1;
269 object->outer_unknown = outer;
270 *surface = &object->inner_unknown_vtbl;
274 object->outer_unknown = (IUnknown *)&object->inner_unknown_vtbl;
278 TRACE("Created IDXGISurface %p\n", object);
283 const struct IWineDXGIDeviceVtbl dxgi_device_vtbl =
285 /* IUnknown methods */
286 dxgi_device_QueryInterface,
289 /* IDXGIObject methods */
290 dxgi_device_SetPrivateData,
291 dxgi_device_SetPrivateDataInterface,
292 dxgi_device_GetPrivateData,
293 dxgi_device_GetParent,
294 /* IDXGIDevice methods */
295 dxgi_device_GetAdapter,
296 dxgi_device_CreateSurface,
297 dxgi_device_QueryResourceResidency,
298 dxgi_device_SetGPUThreadPriority,
299 dxgi_device_GetGPUThreadPriority,
300 /* IWineDXGIAdapter methods */
301 dxgi_device_get_wined3d_device,
302 dxgi_device_create_surface,