dxgi: Add a wined3d device to dxgi_device.
[wine] / dlls / dxgi / device.c
1 /*
2  * Copyright 2008 Henri Verbeet for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  *
18  */
19
20 #include "config.h"
21 #include "wine/port.h"
22
23 #include "dxgi_private.h"
24
25 WINE_DEFAULT_DEBUG_CHANNEL(dxgi);
26
27 /* IUnknown methods */
28
29 static HRESULT STDMETHODCALLTYPE dxgi_device_QueryInterface(IDXGIDevice *iface, REFIID riid, void **object)
30 {
31     struct dxgi_device *This = (struct dxgi_device *)iface;
32
33     TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object);
34
35     if (IsEqualGUID(riid, &IID_IUnknown)
36             || IsEqualGUID(riid, &IID_IDXGIObject)
37             || IsEqualGUID(riid, &IID_IDXGIDevice))
38     {
39         IUnknown_AddRef(iface);
40         *object = iface;
41         return S_OK;
42     }
43
44     if (This->child_layer)
45     {
46         TRACE("forwarding to child layer %p\n", This->child_layer);
47         return IUnknown_QueryInterface(This->child_layer, riid, object);
48     }
49
50     WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
51
52     *object = NULL;
53     return E_NOINTERFACE;
54 }
55
56 static ULONG STDMETHODCALLTYPE dxgi_device_AddRef(IDXGIDevice *iface)
57 {
58     struct dxgi_device *This = (struct dxgi_device *)iface;
59     ULONG refcount = InterlockedIncrement(&This->refcount);
60
61     TRACE("%p increasing refcount to %u\n", This, refcount);
62
63     return refcount;
64 }
65
66 static ULONG STDMETHODCALLTYPE dxgi_device_Release(IDXGIDevice *iface)
67 {
68     struct dxgi_device *This = (struct dxgi_device *)iface;
69     ULONG refcount = InterlockedDecrement(&This->refcount);
70
71     TRACE("%p decreasing refcount to %u\n", This, refcount);
72
73     if (!refcount)
74     {
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);
81     }
82
83     return refcount;
84 }
85
86 /* IDXGIObject methods */
87
88 static HRESULT STDMETHODCALLTYPE dxgi_device_SetPrivateData(IDXGIDevice *iface, REFGUID guid, UINT data_size, const void *data)
89 {
90     FIXME("iface %p, guid %s, data_size %u, data %p stub!\n", iface, debugstr_guid(guid), data_size, data);
91
92     return E_NOTIMPL;
93 }
94
95 static HRESULT STDMETHODCALLTYPE dxgi_device_SetPrivateDataInterface(IDXGIDevice *iface, REFGUID guid, const IUnknown *object)
96 {
97     FIXME("iface %p, guid %s, object %p stub!\n", iface, debugstr_guid(guid), object);
98
99     return E_NOTIMPL;
100 }
101
102 static HRESULT STDMETHODCALLTYPE dxgi_device_GetPrivateData(IDXGIDevice *iface, REFGUID guid, UINT *data_size, void *data)
103 {
104     FIXME("iface %p, guid %s, data_size %p, data %p stub!\n", iface, debugstr_guid(guid), data_size, data);
105
106     return E_NOTIMPL;
107 }
108
109 static HRESULT STDMETHODCALLTYPE dxgi_device_GetParent(IDXGIDevice *iface, REFIID riid, void **parent)
110 {
111     FIXME("iface %p, riid %s, parent %p stub!\n", iface, debugstr_guid(riid), parent);
112
113     return E_NOTIMPL;
114 }
115
116 /* IDXGIDevice methods */
117
118 static HRESULT STDMETHODCALLTYPE dxgi_device_GetAdapter(IDXGIDevice *iface, IDXGIAdapter **adapter)
119 {
120     FIXME("iface %p, adapter %p stub!\n", iface, adapter);
121
122     return E_NOTIMPL;
123 }
124
125 static HRESULT STDMETHODCALLTYPE dxgi_device_CreateSurface(IDXGIDevice *iface,
126         const DXGI_SURFACE_DESC *desc, UINT surface_count, DXGI_USAGE usage,
127         const DXGI_SHARED_RESOURCE *shared_resource, IDXGISurface **surface)
128 {
129     FIXME("iface %p, desc %p, surface_count %u, usage %#x, shared_resource %p, surface %p stub!\n",
130             iface, desc, surface_count, usage, shared_resource, surface);
131
132     return E_NOTIMPL;
133 }
134
135 static HRESULT STDMETHODCALLTYPE dxgi_device_QueryResourceResidency(IDXGIDevice *iface,
136         IUnknown *const *resources, DXGI_RESIDENCY *residency, UINT resource_count)
137 {
138     FIXME("iface %p, resources %p, residency %p, resource_count %u stub!\n",
139             iface, resources, residency, resource_count);
140
141     return E_NOTIMPL;
142 }
143
144 static HRESULT STDMETHODCALLTYPE dxgi_device_SetGPUThreadPriority(IDXGIDevice *iface, INT priority)
145 {
146     FIXME("iface %p, priority %d stub!\n", iface, priority);
147
148     return E_NOTIMPL;
149 }
150
151 static HRESULT STDMETHODCALLTYPE dxgi_device_GetGPUThreadPriority(IDXGIDevice *iface, INT *priority)
152 {
153     FIXME("iface %p, priority %p stub!\n", iface, priority);
154
155     return E_NOTIMPL;
156 }
157
158 const struct IDXGIDeviceVtbl dxgi_device_vtbl =
159 {
160     /* IUnknown methods */
161     dxgi_device_QueryInterface,
162     dxgi_device_AddRef,
163     dxgi_device_Release,
164     /* IDXGIObject methods */
165     dxgi_device_SetPrivateData,
166     dxgi_device_SetPrivateDataInterface,
167     dxgi_device_GetPrivateData,
168     dxgi_device_GetParent,
169     /* IDXGIDevice methods */
170     dxgi_device_GetAdapter,
171     dxgi_device_CreateSurface,
172     dxgi_device_QueryResourceResidency,
173     dxgi_device_SetGPUThreadPriority,
174     dxgi_device_GetGPUThreadPriority,
175 };