push c6fcfc519a04d046be60ec60e33d075a2146cc03
[wine/hacks.git] / dlls / dxgi / device.c
blob69ba3e595bd5897cf7a6a59ea7e6be4675ae348c
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(IDXGIDevice *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))
39 IUnknown_AddRef(iface);
40 *object = iface;
41 return S_OK;
44 if (This->child_layer)
46 TRACE("forwarding to child layer %p\n", This->child_layer);
47 return IUnknown_QueryInterface(This->child_layer, riid, object);
50 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
52 *object = NULL;
53 return E_NOINTERFACE;
56 static ULONG STDMETHODCALLTYPE dxgi_device_AddRef(IDXGIDevice *iface)
58 struct dxgi_device *This = (struct dxgi_device *)iface;
59 ULONG refcount = InterlockedIncrement(&This->refcount);
61 TRACE("%p increasing refcount to %u\n", This, refcount);
63 return refcount;
66 static ULONG STDMETHODCALLTYPE dxgi_device_Release(IDXGIDevice *iface)
68 struct dxgi_device *This = (struct dxgi_device *)iface;
69 ULONG refcount = InterlockedDecrement(&This->refcount);
71 TRACE("%p decreasing refcount to %u\n", This, refcount);
73 if (!refcount)
75 if (This->child_layer) IUnknown_Release(This->child_layer);
76 EnterCriticalSection(&dxgi_cs);
77 IWineD3DDevice_Release(This->wined3d_device);
78 LeaveCriticalSection(&dxgi_cs);
79 IWineDXGIFactory_Release(This->factory);
80 HeapFree(GetProcessHeap(), 0, This);
83 return refcount;
86 /* IDXGIObject methods */
88 static HRESULT STDMETHODCALLTYPE dxgi_device_SetPrivateData(IDXGIDevice *iface, REFGUID guid, UINT data_size, const void *data)
90 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n", iface, debugstr_guid(guid), data_size, data);
92 return E_NOTIMPL;
95 static HRESULT STDMETHODCALLTYPE dxgi_device_SetPrivateDataInterface(IDXGIDevice *iface, REFGUID guid, const IUnknown *object)
97 FIXME("iface %p, guid %s, object %p stub!\n", iface, debugstr_guid(guid), object);
99 return E_NOTIMPL;
102 static HRESULT STDMETHODCALLTYPE dxgi_device_GetPrivateData(IDXGIDevice *iface, REFGUID guid, UINT *data_size, void *data)
104 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n", iface, debugstr_guid(guid), data_size, data);
106 return E_NOTIMPL;
109 static HRESULT STDMETHODCALLTYPE dxgi_device_GetParent(IDXGIDevice *iface, REFIID riid, void **parent)
111 FIXME("iface %p, riid %s, parent %p stub!\n", iface, debugstr_guid(riid), parent);
113 return E_NOTIMPL;
116 /* IDXGIDevice methods */
118 static HRESULT STDMETHODCALLTYPE dxgi_device_GetAdapter(IDXGIDevice *iface, IDXGIAdapter **adapter)
120 struct dxgi_device *This = (struct dxgi_device *)iface;
121 WINED3DDEVICE_CREATION_PARAMETERS create_parameters;
122 HRESULT hr;
124 TRACE("iface %p, adapter %p\n", iface, adapter);
126 EnterCriticalSection(&dxgi_cs);
128 hr = IWineD3DDevice_GetCreationParameters(This->wined3d_device, &create_parameters);
129 if (FAILED(hr))
131 LeaveCriticalSection(&dxgi_cs);
132 return hr;
135 LeaveCriticalSection(&dxgi_cs);
137 return IWineDXGIFactory_EnumAdapters(This->factory, create_parameters.AdapterOrdinal, adapter);
140 static HRESULT STDMETHODCALLTYPE dxgi_device_CreateSurface(IDXGIDevice *iface,
141 const DXGI_SURFACE_DESC *desc, UINT surface_count, DXGI_USAGE usage,
142 const DXGI_SHARED_RESOURCE *shared_resource, IDXGISurface **surface)
144 struct dxgi_surface *object;
145 HRESULT hr;
146 UINT i;
148 FIXME("iface %p, desc %p, surface_count %u, usage %#x, shared_resource %p, surface %p partial stub!\n",
149 iface, desc, surface_count, usage, shared_resource, surface);
151 memset(surface, 0, surface_count * sizeof(*surface));
152 for (i = 0; i < surface_count; ++i)
154 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
155 if (!object)
157 ERR("Failed to allocate DXGI surface object memory\n");
158 hr = E_OUTOFMEMORY;
159 goto fail;
162 object->vtbl = &dxgi_surface_vtbl;
163 object->refcount = 1;
164 surface[i] = (IDXGISurface *)object;
166 TRACE("Created IDXGISurface %p (%u/%u)\n", object, i + 1, surface_count);
169 return S_OK;
171 fail:
172 for (i = 0; i < surface_count; ++i)
174 HeapFree(GetProcessHeap(), 0, surface[i]);
176 return hr;
179 static HRESULT STDMETHODCALLTYPE dxgi_device_QueryResourceResidency(IDXGIDevice *iface,
180 IUnknown *const *resources, DXGI_RESIDENCY *residency, UINT resource_count)
182 FIXME("iface %p, resources %p, residency %p, resource_count %u stub!\n",
183 iface, resources, residency, resource_count);
185 return E_NOTIMPL;
188 static HRESULT STDMETHODCALLTYPE dxgi_device_SetGPUThreadPriority(IDXGIDevice *iface, INT priority)
190 FIXME("iface %p, priority %d stub!\n", iface, priority);
192 return E_NOTIMPL;
195 static HRESULT STDMETHODCALLTYPE dxgi_device_GetGPUThreadPriority(IDXGIDevice *iface, INT *priority)
197 FIXME("iface %p, priority %p stub!\n", iface, priority);
199 return E_NOTIMPL;
202 const struct IDXGIDeviceVtbl dxgi_device_vtbl =
204 /* IUnknown methods */
205 dxgi_device_QueryInterface,
206 dxgi_device_AddRef,
207 dxgi_device_Release,
208 /* IDXGIObject methods */
209 dxgi_device_SetPrivateData,
210 dxgi_device_SetPrivateDataInterface,
211 dxgi_device_GetPrivateData,
212 dxgi_device_GetParent,
213 /* IDXGIDevice methods */
214 dxgi_device_GetAdapter,
215 dxgi_device_CreateSurface,
216 dxgi_device_QueryResourceResidency,
217 dxgi_device_SetGPUThreadPriority,
218 dxgi_device_GetGPUThreadPriority,