makefiles: Add resource files to the standard object files list.
[wine.git] / dlls / dxgi / device.c
blobbf079d5daafa20b413170e981fd2846dc0f2b3af
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 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,
172 wined3dformat_from_dxgi_format(desc->Format), usage, WINED3DPOOL_DEFAULT, 0,
173 WINED3DCUBEMAP_FACE_POSITIVE_X, &wined3d_surface);
174 if (FAILED(hr))
176 ERR("CreateSurface failed, returning %#x\n", hr);
177 goto fail;
180 hr = IWineD3DSurface_GetParent(wined3d_surface, &parent);
181 IWineD3DSurface_Release(wined3d_surface);
182 if (FAILED(hr))
184 ERR("GetParent failed, returning %#x\n", hr);
185 goto fail;
188 hr = IUnknown_QueryInterface(parent, &IID_IDXGISurface, (void **)&surface[i]);
189 IUnknown_Release(parent);
190 if (FAILED(hr))
192 ERR("Surface should implement IDXGISurface\n");
193 goto fail;
196 TRACE("Created IDXGISurface %p (%u/%u)\n", surface[i], i + 1, surface_count);
198 IWineD3DDeviceParent_Release(device_parent);
200 return S_OK;
202 fail:
203 for (j = 0; j < i; ++j)
205 IDXGISurface_Release(surface[i]);
207 IWineD3DDeviceParent_Release(device_parent);
208 return hr;
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);
217 return E_NOTIMPL;
220 static HRESULT STDMETHODCALLTYPE dxgi_device_SetGPUThreadPriority(IWineDXGIDevice *iface, INT priority)
222 FIXME("iface %p, priority %d stub!\n", iface, priority);
224 return E_NOTIMPL;
227 static HRESULT STDMETHODCALLTYPE dxgi_device_GetGPUThreadPriority(IWineDXGIDevice *iface, INT *priority)
229 FIXME("iface %p, priority %p stub!\n", iface, priority);
231 return E_NOTIMPL;
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));
257 if (!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;
267 if (outer)
269 object->outer_unknown = outer;
270 *surface = &object->inner_unknown_vtbl;
272 else
274 object->outer_unknown = (IUnknown *)&object->inner_unknown_vtbl;
275 *surface = object;
278 TRACE("Created IDXGISurface %p\n", object);
280 return S_OK;
283 static HRESULT STDMETHODCALLTYPE dxgi_device_create_swapchain(IWineDXGIDevice *iface,
284 WINED3DPRESENT_PARAMETERS *present_parameters, IWineD3DSwapChain **wined3d_swapchain)
286 struct dxgi_device *This = (struct dxgi_device *)iface;
287 struct dxgi_swapchain *object;
288 HRESULT hr;
290 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
291 if (!object)
293 ERR("Failed to allocate DXGI swapchain object memory\n");
294 return E_OUTOFMEMORY;
297 object->vtbl = &dxgi_swapchain_vtbl;
298 object->refcount = 1;
300 hr = IWineD3DDevice_CreateSwapChain(This->wined3d_device, present_parameters,
301 &object->wined3d_swapchain, (IUnknown *)object, SURFACE_OPENGL);
302 if (FAILED(hr))
304 WARN("Failed to create a swapchain, returning %#x\n", hr);
305 HeapFree(GetProcessHeap(), 0, object);
306 return hr;
308 *wined3d_swapchain = object->wined3d_swapchain;
310 TRACE("Created IDXGISwapChain %p\n", object);
312 return S_OK;
315 const struct IWineDXGIDeviceVtbl dxgi_device_vtbl =
317 /* IUnknown methods */
318 dxgi_device_QueryInterface,
319 dxgi_device_AddRef,
320 dxgi_device_Release,
321 /* IDXGIObject methods */
322 dxgi_device_SetPrivateData,
323 dxgi_device_SetPrivateDataInterface,
324 dxgi_device_GetPrivateData,
325 dxgi_device_GetParent,
326 /* IDXGIDevice methods */
327 dxgi_device_GetAdapter,
328 dxgi_device_CreateSurface,
329 dxgi_device_QueryResourceResidency,
330 dxgi_device_SetGPUThreadPriority,
331 dxgi_device_GetGPUThreadPriority,
332 /* IWineDXGIAdapter methods */
333 dxgi_device_get_wined3d_device,
334 dxgi_device_create_surface,
335 dxgi_device_create_swapchain,