push 2f3ca95c4974ba229fa47d638b3044f50788f3bd
[wine/hacks.git] / dlls / dxgi / device.c
blob3c10f9918e67b3a193c776773dfb36ac6dcd1c2f
1 /*
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
20 #include "config.h"
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);
41 *object = iface;
42 return S_OK;
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));
53 *object = NULL;
54 return E_NOINTERFACE;
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);
64 return 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);
74 if (!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);
84 return refcount;
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);
94 return E_NOTIMPL;
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);
102 return E_NOTIMPL;
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);
110 return E_NOTIMPL;
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);
117 return E_NOTIMPL;
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;
126 HRESULT hr;
128 TRACE("iface %p, adapter %p\n", iface, adapter);
130 EnterCriticalSection(&dxgi_cs);
132 hr = IWineD3DDevice_GetCreationParameters(This->wined3d_device, &create_parameters);
133 if (FAILED(hr))
135 LeaveCriticalSection(&dxgi_cs);
136 return hr;
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;
149 HRESULT hr;
150 UINT i;
151 UINT j;
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);
157 if (FAILED(hr))
159 ERR("Device should implement IWineD3DDeviceParent\n");
160 return E_FAIL;
163 FIXME("Implement DXGI<->wined3d format and usage conversion\n");
165 memset(surface, 0, surface_count * sizeof(*surface));
166 for (i = 0; i < surface_count; ++i)
168 IWineD3DSurface *wined3d_surface;
169 IUnknown *parent;
171 hr = IWineD3DDeviceParent_CreateSurface(device_parent, NULL, desc->Width, desc->Height, desc->Format,
172 usage, WINED3DPOOL_DEFAULT, 0, WINED3DCUBEMAP_FACE_POSITIVE_X, &wined3d_surface);
173 if (FAILED(hr))
175 ERR("CreateSurface failed, returning %#x\n", hr);
176 goto fail;
179 hr = IWineD3DSurface_GetParent(wined3d_surface, &parent);
180 IWineD3DSurface_Release(wined3d_surface);
181 if (FAILED(hr))
183 ERR("GetParent failed, returning %#x\n", hr);
184 goto fail;
187 hr = IUnknown_QueryInterface(parent, &IID_IDXGISurface, (void **)&surface[i]);
188 IUnknown_Release(parent);
189 if (FAILED(hr))
191 ERR("Surface should implement IDXGISurface\n");
192 goto fail;
195 TRACE("Created IDXGISurface %p (%u/%u)\n", surface[i], i + 1, surface_count);
197 IWineD3DDeviceParent_Release(device_parent);
199 return S_OK;
201 fail:
202 for (j = 0; j < i; ++j)
204 IDXGISurface_Release(surface[i]);
206 IWineD3DDeviceParent_Release(device_parent);
207 return hr;
210 static HRESULT STDMETHODCALLTYPE dxgi_device_QueryResourceResidency(IWineDXGIDevice *iface,
211 IUnknown *const *resources, DXGI_RESIDENCY *residency, UINT resource_count)
213 FIXME("iface %p, resources %p, residency %p, resource_count %u stub!\n",
214 iface, resources, residency, resource_count);
216 return E_NOTIMPL;
219 static HRESULT STDMETHODCALLTYPE dxgi_device_SetGPUThreadPriority(IWineDXGIDevice *iface, INT priority)
221 FIXME("iface %p, priority %d stub!\n", iface, priority);
223 return E_NOTIMPL;
226 static HRESULT STDMETHODCALLTYPE dxgi_device_GetGPUThreadPriority(IWineDXGIDevice *iface, INT *priority)
228 FIXME("iface %p, priority %p stub!\n", iface, priority);
230 return E_NOTIMPL;
233 /* IWineDXGIDevice methods */
235 static IWineD3DDevice * STDMETHODCALLTYPE dxgi_device_get_wined3d_device(IWineDXGIDevice *iface)
237 struct dxgi_device *This = (struct dxgi_device *)iface;
239 TRACE("iface %p\n", iface);
241 EnterCriticalSection(&dxgi_cs);
242 IWineD3DDevice_AddRef(This->wined3d_device);
243 LeaveCriticalSection(&dxgi_cs);
244 return This->wined3d_device;
247 static HRESULT STDMETHODCALLTYPE dxgi_device_create_surface(IWineDXGIDevice *iface, const DXGI_SURFACE_DESC *desc,
248 DXGI_USAGE usage, const DXGI_SHARED_RESOURCE *shared_resource, IUnknown *outer, void **surface)
250 struct dxgi_surface *object;
252 FIXME("iface %p, desc %p, usage %#x, shared_resource %p, outer %p, surface %p partial stub!\n",
253 iface, desc, usage, shared_resource, outer, surface);
255 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
256 if (!object)
258 ERR("Failed to allocate DXGI surface object memory\n");
259 return E_OUTOFMEMORY;
262 object->vtbl = &dxgi_surface_vtbl;
263 object->inner_unknown_vtbl = &dxgi_surface_inner_unknown_vtbl;
264 object->refcount = 1;
266 if (outer)
268 object->outer_unknown = outer;
269 *surface = &object->inner_unknown_vtbl;
271 else
273 object->outer_unknown = (IUnknown *)&object->inner_unknown_vtbl;
274 *surface = object;
277 TRACE("Created IDXGISurface %p\n", object);
279 return S_OK;
282 const struct IWineDXGIDeviceVtbl dxgi_device_vtbl =
284 /* IUnknown methods */
285 dxgi_device_QueryInterface,
286 dxgi_device_AddRef,
287 dxgi_device_Release,
288 /* IDXGIObject methods */
289 dxgi_device_SetPrivateData,
290 dxgi_device_SetPrivateDataInterface,
291 dxgi_device_GetPrivateData,
292 dxgi_device_GetParent,
293 /* IDXGIDevice methods */
294 dxgi_device_GetAdapter,
295 dxgi_device_CreateSurface,
296 dxgi_device_QueryResourceResidency,
297 dxgi_device_SetGPUThreadPriority,
298 dxgi_device_GetGPUThreadPriority,
299 /* IWineDXGIAdapter methods */
300 dxgi_device_get_wined3d_device,
301 dxgi_device_create_surface,