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_adapter_QueryInterface(IWineDXGIAdapter
*iface
, REFIID riid
, void **object
)
31 TRACE("iface %p, riid %s, object %p\n", iface
, debugstr_guid(riid
), object
);
33 if (IsEqualGUID(riid
, &IID_IUnknown
)
34 || IsEqualGUID(riid
, &IID_IDXGIObject
)
35 || IsEqualGUID(riid
, &IID_IDXGIAdapter
)
36 || IsEqualGUID(riid
, &IID_IWineDXGIAdapter
))
38 IUnknown_AddRef(iface
);
43 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid
));
49 static ULONG STDMETHODCALLTYPE
dxgi_adapter_AddRef(IWineDXGIAdapter
*iface
)
51 struct dxgi_adapter
*This
= (struct dxgi_adapter
*)iface
;
52 ULONG refcount
= InterlockedIncrement(&This
->refcount
);
54 TRACE("%p increasing refcount to %u\n", This
, refcount
);
59 static ULONG STDMETHODCALLTYPE
dxgi_adapter_Release(IWineDXGIAdapter
*iface
)
61 struct dxgi_adapter
*This
= (struct dxgi_adapter
*)iface
;
62 ULONG refcount
= InterlockedDecrement(&This
->refcount
);
64 TRACE("%p decreasing refcount to %u\n", This
, refcount
);
68 IDXGIOutput_Release(This
->output
);
69 HeapFree(GetProcessHeap(), 0, This
);
75 /* IDXGIObject methods */
77 static HRESULT STDMETHODCALLTYPE
dxgi_adapter_SetPrivateData(IWineDXGIAdapter
*iface
,
78 REFGUID guid
, UINT data_size
, const void *data
)
80 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n", iface
, debugstr_guid(guid
), data_size
, data
);
85 static HRESULT STDMETHODCALLTYPE
dxgi_adapter_SetPrivateDataInterface(IWineDXGIAdapter
*iface
,
86 REFGUID guid
, const IUnknown
*object
)
88 FIXME("iface %p, guid %s, object %p stub!\n", iface
, debugstr_guid(guid
), object
);
93 static HRESULT STDMETHODCALLTYPE
dxgi_adapter_GetPrivateData(IWineDXGIAdapter
*iface
,
94 REFGUID guid
, UINT
*data_size
, void *data
)
96 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n", iface
, debugstr_guid(guid
), data_size
, data
);
101 static HRESULT STDMETHODCALLTYPE
dxgi_adapter_GetParent(IWineDXGIAdapter
*iface
, REFIID riid
, void **parent
)
103 struct dxgi_adapter
*This
= (struct dxgi_adapter
*)iface
;
105 TRACE("iface %p, riid %s, parent %p\n", iface
, debugstr_guid(riid
), parent
);
107 return IWineDXGIFactory_QueryInterface(This
->parent
, riid
, parent
);
110 /* IDXGIAdapter methods */
112 static HRESULT STDMETHODCALLTYPE
dxgi_adapter_EnumOutputs(IWineDXGIAdapter
*iface
,
113 UINT output_idx
, IDXGIOutput
**output
)
115 struct dxgi_adapter
*This
= (struct dxgi_adapter
*)iface
;
117 TRACE("iface %p, output_idx %u, output %p.\n", iface
, output_idx
, output
);
122 return DXGI_ERROR_NOT_FOUND
;
125 *output
= This
->output
;
126 IDXGIOutput_AddRef(*output
);
128 TRACE("Returning output %p.\n", output
);
133 static HRESULT STDMETHODCALLTYPE
dxgi_adapter_GetDesc(IWineDXGIAdapter
*iface
, DXGI_ADAPTER_DESC
*desc
)
135 struct dxgi_adapter
*This
= (struct dxgi_adapter
*)iface
;
136 WINED3DADAPTER_IDENTIFIER adapter_id
;
137 char description
[128];
141 TRACE("iface %p, desc %p.\n", iface
, desc
);
143 if (!desc
) return E_INVALIDARG
;
145 wined3d
= IWineDXGIFactory_get_wined3d(This
->parent
);
146 adapter_id
.driver_size
= 0;
147 adapter_id
.description
= description
;
148 adapter_id
.description_size
= sizeof(description
);
149 adapter_id
.device_name_size
= 0;
151 EnterCriticalSection(&dxgi_cs
);
152 hr
= IWineD3D_GetAdapterIdentifier(wined3d
, This
->ordinal
, 0, &adapter_id
);
153 IWineD3D_Release(wined3d
);
154 LeaveCriticalSection(&dxgi_cs
);
158 if (!MultiByteToWideChar(CP_ACP
, 0, description
, -1, desc
->Description
, 128))
160 DWORD err
= GetLastError();
161 ERR("Failed to translate description %s (%#x).\n", debugstr_a(description
), err
);
165 desc
->VendorId
= adapter_id
.vendor_id
;
166 desc
->DeviceId
= adapter_id
.device_id
;
167 desc
->SubSysId
= adapter_id
.subsystem_id
;
168 desc
->Revision
= adapter_id
.revision
;
169 desc
->DedicatedVideoMemory
= adapter_id
.video_memory
;
170 desc
->DedicatedSystemMemory
= 0; /* FIXME */
171 desc
->SharedSystemMemory
= 0; /* FIXME */
172 memcpy(&desc
->AdapterLuid
, &adapter_id
.adapter_luid
, sizeof(desc
->AdapterLuid
));
178 static HRESULT STDMETHODCALLTYPE
dxgi_adapter_CheckInterfaceSupport(IWineDXGIAdapter
*iface
,
179 REFGUID guid
, LARGE_INTEGER
*umd_version
)
181 FIXME("iface %p, guid %s, umd_version %p stub!\n", iface
, debugstr_guid(guid
), umd_version
);
186 /* IWineDXGIAdapter methods */
188 static UINT STDMETHODCALLTYPE
dxgi_adapter_get_ordinal(IWineDXGIAdapter
*iface
)
190 struct dxgi_adapter
*This
= (struct dxgi_adapter
*)iface
;
192 TRACE("iface %p, returning %u\n", iface
, This
->ordinal
);
194 return This
->ordinal
;
197 static const struct IWineDXGIAdapterVtbl dxgi_adapter_vtbl
=
199 /* IUnknown methods */
200 dxgi_adapter_QueryInterface
,
202 dxgi_adapter_Release
,
203 /* IDXGIObject methods */
204 dxgi_adapter_SetPrivateData
,
205 dxgi_adapter_SetPrivateDataInterface
,
206 dxgi_adapter_GetPrivateData
,
207 dxgi_adapter_GetParent
,
208 /* IDXGIAdapter methods */
209 dxgi_adapter_EnumOutputs
,
210 dxgi_adapter_GetDesc
,
211 dxgi_adapter_CheckInterfaceSupport
,
212 /* IWineDXGIAdapter methods */
213 dxgi_adapter_get_ordinal
,
216 HRESULT
dxgi_adapter_init(struct dxgi_adapter
*adapter
, IWineDXGIFactory
*parent
, UINT ordinal
)
218 struct dxgi_output
*output
;
220 adapter
->vtbl
= &dxgi_adapter_vtbl
;
221 adapter
->parent
= parent
;
222 adapter
->refcount
= 1;
223 adapter
->ordinal
= ordinal
;
225 output
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*output
));
228 return E_OUTOFMEMORY
;
230 dxgi_output_init(output
, adapter
);
231 adapter
->output
= (IDXGIOutput
*)output
;