Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygendirectx.c
Go to the documentation of this file.
00001 /* 00002 * IDirect3D8 implementation 00003 * 00004 * Copyright 2002-2004 Jason Edmeades 00005 * Copyright 2003-2004 Raphael Junqueira 00006 * Copyright 2004 Christian Costa 00007 * 00008 * This library is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Lesser General Public 00010 * License as published by the Free Software Foundation; either 00011 * version 2.1 of the License, or (at your option) any later version. 00012 * 00013 * This library is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with this library; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 00021 */ 00022 00023 #include "config.h" 00024 00025 #include <stdarg.h> 00026 00027 #define NONAMELESSUNION 00028 #define NONAMELESSSTRUCT 00029 #include "windef.h" 00030 #include "winbase.h" 00031 #include "wingdi.h" 00032 #include "winuser.h" 00033 #include "wine/debug.h" 00034 #include "wine/unicode.h" 00035 00036 #include "d3d8_private.h" 00037 00038 WINE_DEFAULT_DEBUG_CHANNEL(d3d8); 00039 00040 static inline IDirect3D8Impl *impl_from_IDirect3D8(IDirect3D8 *iface) 00041 { 00042 return CONTAINING_RECORD(iface, IDirect3D8Impl, IDirect3D8_iface); 00043 } 00044 00045 static HRESULT WINAPI IDirect3D8Impl_QueryInterface(LPDIRECT3D8 iface, REFIID riid,LPVOID *ppobj) 00046 { 00047 IDirect3D8Impl *This = impl_from_IDirect3D8(iface); 00048 00049 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj); 00050 00051 if (IsEqualGUID(riid, &IID_IUnknown) 00052 || IsEqualGUID(riid, &IID_IDirect3D8)) { 00053 IUnknown_AddRef(iface); 00054 *ppobj = This; 00055 return S_OK; 00056 } 00057 00058 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid),ppobj); 00059 *ppobj = NULL; 00060 return E_NOINTERFACE; 00061 } 00062 00063 static ULONG WINAPI IDirect3D8Impl_AddRef(LPDIRECT3D8 iface) 00064 { 00065 IDirect3D8Impl *This = impl_from_IDirect3D8(iface); 00066 ULONG ref = InterlockedIncrement(&This->ref); 00067 00068 TRACE("%p increasing refcount to %u.\n", iface, ref); 00069 00070 return ref; 00071 } 00072 00073 static ULONG WINAPI IDirect3D8Impl_Release(LPDIRECT3D8 iface) 00074 { 00075 IDirect3D8Impl *This = impl_from_IDirect3D8(iface); 00076 ULONG ref = InterlockedDecrement(&This->ref); 00077 00078 TRACE("%p decreasing refcount to %u.\n", iface, ref); 00079 00080 if (ref == 0) { 00081 TRACE("Releasing wined3d %p\n", This->WineD3D); 00082 00083 wined3d_mutex_lock(); 00084 wined3d_decref(This->WineD3D); 00085 wined3d_mutex_unlock(); 00086 00087 HeapFree(GetProcessHeap(), 0, This); 00088 } 00089 00090 return ref; 00091 } 00092 00093 static HRESULT WINAPI IDirect3D8Impl_RegisterSoftwareDevice(LPDIRECT3D8 iface, 00094 void* pInitializeFunction) 00095 { 00096 IDirect3D8Impl *This = impl_from_IDirect3D8(iface); 00097 HRESULT hr; 00098 00099 TRACE("iface %p, init_function %p.\n", iface, pInitializeFunction); 00100 00101 wined3d_mutex_lock(); 00102 hr = wined3d_register_software_device(This->WineD3D, pInitializeFunction); 00103 wined3d_mutex_unlock(); 00104 00105 return hr; 00106 } 00107 00108 static UINT WINAPI IDirect3D8Impl_GetAdapterCount(LPDIRECT3D8 iface) 00109 { 00110 IDirect3D8Impl *This = impl_from_IDirect3D8(iface); 00111 HRESULT hr; 00112 00113 TRACE("iface %p.\n", iface); 00114 00115 wined3d_mutex_lock(); 00116 hr = wined3d_get_adapter_count(This->WineD3D); 00117 wined3d_mutex_unlock(); 00118 00119 return hr; 00120 } 00121 00122 static HRESULT WINAPI IDirect3D8Impl_GetAdapterIdentifier(LPDIRECT3D8 iface, UINT Adapter, 00123 DWORD Flags, D3DADAPTER_IDENTIFIER8 *pIdentifier) 00124 { 00125 IDirect3D8Impl *This = impl_from_IDirect3D8(iface); 00126 struct wined3d_adapter_identifier adapter_id; 00127 HRESULT hr; 00128 00129 TRACE("iface %p, adapter %u, flags %#x, identifier %p.\n", 00130 iface, Adapter, Flags, pIdentifier); 00131 00132 adapter_id.driver = pIdentifier->Driver; 00133 adapter_id.driver_size = sizeof(pIdentifier->Driver); 00134 adapter_id.description = pIdentifier->Description; 00135 adapter_id.description_size = sizeof(pIdentifier->Description); 00136 adapter_id.device_name = NULL; /* d3d9 only */ 00137 adapter_id.device_name_size = 0; /* d3d9 only */ 00138 00139 wined3d_mutex_lock(); 00140 hr = wined3d_get_adapter_identifier(This->WineD3D, Adapter, Flags, &adapter_id); 00141 wined3d_mutex_unlock(); 00142 00143 pIdentifier->DriverVersion = adapter_id.driver_version; 00144 pIdentifier->VendorId = adapter_id.vendor_id; 00145 pIdentifier->DeviceId = adapter_id.device_id; 00146 pIdentifier->SubSysId = adapter_id.subsystem_id; 00147 pIdentifier->Revision = adapter_id.revision; 00148 memcpy(&pIdentifier->DeviceIdentifier, &adapter_id.device_identifier, sizeof(pIdentifier->DeviceIdentifier)); 00149 pIdentifier->WHQLLevel = adapter_id.whql_level; 00150 00151 return hr; 00152 } 00153 00154 static UINT WINAPI IDirect3D8Impl_GetAdapterModeCount(LPDIRECT3D8 iface,UINT Adapter) 00155 { 00156 IDirect3D8Impl *This = impl_from_IDirect3D8(iface); 00157 HRESULT hr; 00158 00159 TRACE("iface %p, adapter %u.\n", iface, Adapter); 00160 00161 wined3d_mutex_lock(); 00162 hr = wined3d_get_adapter_mode_count(This->WineD3D, Adapter, 0); 00163 wined3d_mutex_unlock(); 00164 00165 return hr; 00166 } 00167 00168 static HRESULT WINAPI IDirect3D8Impl_EnumAdapterModes(LPDIRECT3D8 iface, UINT Adapter, UINT Mode, 00169 D3DDISPLAYMODE* pMode) 00170 { 00171 IDirect3D8Impl *This = impl_from_IDirect3D8(iface); 00172 HRESULT hr; 00173 00174 TRACE("iface %p, adapter %u, mode_idx %u, mode %p.\n", 00175 iface, Adapter, Mode, pMode); 00176 00177 wined3d_mutex_lock(); 00178 hr = wined3d_enum_adapter_modes(This->WineD3D, Adapter, WINED3DFMT_UNKNOWN, 00179 Mode, (struct wined3d_display_mode *)pMode); 00180 wined3d_mutex_unlock(); 00181 00182 if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format); 00183 00184 return hr; 00185 } 00186 00187 static HRESULT WINAPI IDirect3D8Impl_GetAdapterDisplayMode(LPDIRECT3D8 iface, UINT Adapter, 00188 D3DDISPLAYMODE* pMode) 00189 { 00190 IDirect3D8Impl *This = impl_from_IDirect3D8(iface); 00191 HRESULT hr; 00192 00193 TRACE("iface %p, adapter %u, mode %p.\n", 00194 iface, Adapter, pMode); 00195 00196 wined3d_mutex_lock(); 00197 hr = wined3d_get_adapter_display_mode(This->WineD3D, Adapter, (struct wined3d_display_mode *)pMode); 00198 wined3d_mutex_unlock(); 00199 00200 if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format); 00201 00202 return hr; 00203 } 00204 00205 static HRESULT WINAPI IDirect3D8Impl_CheckDeviceType(LPDIRECT3D8 iface, UINT Adapter, 00206 D3DDEVTYPE CheckType, D3DFORMAT DisplayFormat, D3DFORMAT BackBufferFormat, BOOL Windowed) 00207 { 00208 IDirect3D8Impl *This = impl_from_IDirect3D8(iface); 00209 HRESULT hr; 00210 00211 TRACE("iface %p, adapter %u, device_type %#x, display_format %#x, backbuffer_format %#x, windowed %#x.\n", 00212 iface, Adapter, CheckType, DisplayFormat, BackBufferFormat, Windowed); 00213 00214 wined3d_mutex_lock(); 00215 hr = wined3d_check_device_type(This->WineD3D, Adapter, CheckType, wined3dformat_from_d3dformat(DisplayFormat), 00216 wined3dformat_from_d3dformat(BackBufferFormat), Windowed); 00217 wined3d_mutex_unlock(); 00218 00219 return hr; 00220 } 00221 00222 static HRESULT WINAPI IDirect3D8Impl_CheckDeviceFormat(LPDIRECT3D8 iface, UINT Adapter, 00223 D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, DWORD Usage, D3DRESOURCETYPE RType, 00224 D3DFORMAT CheckFormat) 00225 { 00226 IDirect3D8Impl *This = impl_from_IDirect3D8(iface); 00227 enum wined3d_resource_type wined3d_rtype; 00228 HRESULT hr; 00229 00230 TRACE("iface %p, adapter %u, device_type %#x, adapter_format %#x, usage %#x, resource_type %#x, format %#x.\n", 00231 iface, Adapter, DeviceType, AdapterFormat, Usage, RType, CheckFormat); 00232 00233 switch(RType) { 00234 case D3DRTYPE_VERTEXBUFFER: 00235 case D3DRTYPE_INDEXBUFFER: 00236 wined3d_rtype = WINED3D_RTYPE_BUFFER; 00237 break; 00238 00239 default: 00240 wined3d_rtype = RType; 00241 break; 00242 } 00243 00244 wined3d_mutex_lock(); 00245 hr = wined3d_check_device_format(This->WineD3D, Adapter, DeviceType, wined3dformat_from_d3dformat(AdapterFormat), 00246 Usage, wined3d_rtype, wined3dformat_from_d3dformat(CheckFormat), SURFACE_OPENGL); 00247 wined3d_mutex_unlock(); 00248 00249 return hr; 00250 } 00251 00252 static HRESULT WINAPI IDirect3D8Impl_CheckDeviceMultiSampleType(IDirect3D8 *iface, UINT Adapter, 00253 D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat, BOOL Windowed, 00254 D3DMULTISAMPLE_TYPE MultiSampleType) 00255 { 00256 IDirect3D8Impl *This = impl_from_IDirect3D8(iface); 00257 HRESULT hr; 00258 00259 TRACE("iface %p, adapter %u, device_type %#x, format %#x, windowed %#x, multisample_type %#x.\n", 00260 iface, Adapter, DeviceType, SurfaceFormat, Windowed, MultiSampleType); 00261 00262 wined3d_mutex_lock(); 00263 hr = wined3d_check_device_multisample_type(This->WineD3D, Adapter, DeviceType, 00264 wined3dformat_from_d3dformat(SurfaceFormat), Windowed, 00265 (enum wined3d_multisample_type)MultiSampleType, NULL); 00266 wined3d_mutex_unlock(); 00267 00268 return hr; 00269 } 00270 00271 static HRESULT WINAPI IDirect3D8Impl_CheckDepthStencilMatch(IDirect3D8 *iface, UINT Adapter, 00272 D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, D3DFORMAT RenderTargetFormat, 00273 D3DFORMAT DepthStencilFormat) 00274 { 00275 IDirect3D8Impl *This = impl_from_IDirect3D8(iface); 00276 HRESULT hr; 00277 00278 TRACE("iface %p, adapter %u, device_type %#x, adapter_format %#x, rt_format %#x, ds_format %#x.\n", 00279 iface, Adapter, DeviceType, AdapterFormat, RenderTargetFormat, DepthStencilFormat); 00280 00281 wined3d_mutex_lock(); 00282 hr = wined3d_check_depth_stencil_match(This->WineD3D, Adapter, DeviceType, 00283 wined3dformat_from_d3dformat(AdapterFormat), wined3dformat_from_d3dformat(RenderTargetFormat), 00284 wined3dformat_from_d3dformat(DepthStencilFormat)); 00285 wined3d_mutex_unlock(); 00286 00287 return hr; 00288 } 00289 00290 void fixup_caps(WINED3DCAPS *caps) 00291 { 00292 /* D3D8 doesn't support SM 2.0 or higher, so clamp to 1.x */ 00293 if (caps->PixelShaderVersion) 00294 caps->PixelShaderVersion = D3DPS_VERSION(1,4); 00295 else 00296 caps->PixelShaderVersion = D3DPS_VERSION(0,0); 00297 if (caps->VertexShaderVersion) 00298 caps->VertexShaderVersion = D3DVS_VERSION(1,1); 00299 else 00300 caps->VertexShaderVersion = D3DVS_VERSION(0,0); 00301 caps->MaxVertexShaderConst = min(D3D8_MAX_VERTEX_SHADER_CONSTANTF, caps->MaxVertexShaderConst); 00302 00303 caps->StencilCaps &= ~WINED3DSTENCILCAPS_TWOSIDED; 00304 } 00305 00306 static HRESULT WINAPI IDirect3D8Impl_GetDeviceCaps(LPDIRECT3D8 iface, UINT Adapter, 00307 D3DDEVTYPE DeviceType, D3DCAPS8* pCaps) 00308 { 00309 IDirect3D8Impl *This = impl_from_IDirect3D8(iface); 00310 HRESULT hrc = D3D_OK; 00311 WINED3DCAPS *pWineCaps; 00312 00313 TRACE("iface %p, adapter %u, device_type %#x, caps %p.\n", iface, Adapter, DeviceType, pCaps); 00314 00315 if(NULL == pCaps){ 00316 return D3DERR_INVALIDCALL; 00317 } 00318 pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS)); 00319 if(pWineCaps == NULL){ 00320 return D3DERR_INVALIDCALL; /*well this is what MSDN says to return*/ 00321 } 00322 00323 wined3d_mutex_lock(); 00324 hrc = wined3d_get_device_caps(This->WineD3D, Adapter, DeviceType, pWineCaps); 00325 wined3d_mutex_unlock(); 00326 00327 fixup_caps(pWineCaps); 00328 WINECAPSTOD3D8CAPS(pCaps, pWineCaps) 00329 HeapFree(GetProcessHeap(), 0, pWineCaps); 00330 00331 TRACE("(%p) returning %p\n", This, pCaps); 00332 return hrc; 00333 } 00334 00335 static HMONITOR WINAPI IDirect3D8Impl_GetAdapterMonitor(LPDIRECT3D8 iface, UINT Adapter) 00336 { 00337 IDirect3D8Impl *This = impl_from_IDirect3D8(iface); 00338 HMONITOR ret; 00339 00340 TRACE("iface %p, adapter %u.\n", iface, Adapter); 00341 00342 wined3d_mutex_lock(); 00343 ret = wined3d_get_adapter_monitor(This->WineD3D, Adapter); 00344 wined3d_mutex_unlock(); 00345 00346 return ret; 00347 } 00348 00349 static HRESULT WINAPI IDirect3D8Impl_CreateDevice(IDirect3D8 *iface, UINT adapter, 00350 D3DDEVTYPE device_type, HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters, 00351 IDirect3DDevice8 **device) 00352 { 00353 IDirect3D8Impl *This = impl_from_IDirect3D8(iface); 00354 IDirect3DDevice8Impl *object; 00355 HRESULT hr; 00356 00357 TRACE("iface %p, adapter %u, device_type %#x, focus_window %p, flags %#x, parameters %p, device %p.\n", 00358 iface, adapter, device_type, focus_window, flags, parameters, device); 00359 00360 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); 00361 if (!object) 00362 { 00363 ERR("Failed to allocate device memory.\n"); 00364 return E_OUTOFMEMORY; 00365 } 00366 00367 hr = device_init(object, This, This->WineD3D, adapter, device_type, focus_window, flags, parameters); 00368 if (FAILED(hr)) 00369 { 00370 WARN("Failed to initialize device, hr %#x.\n", hr); 00371 HeapFree(GetProcessHeap(), 0, object); 00372 return hr; 00373 } 00374 00375 TRACE("Created device %p.\n", object); 00376 *device = &object->IDirect3DDevice8_iface; 00377 00378 return D3D_OK; 00379 } 00380 00381 const IDirect3D8Vtbl Direct3D8_Vtbl = 00382 { 00383 /* IUnknown */ 00384 IDirect3D8Impl_QueryInterface, 00385 IDirect3D8Impl_AddRef, 00386 IDirect3D8Impl_Release, 00387 /* IDirect3D8 */ 00388 IDirect3D8Impl_RegisterSoftwareDevice, 00389 IDirect3D8Impl_GetAdapterCount, 00390 IDirect3D8Impl_GetAdapterIdentifier, 00391 IDirect3D8Impl_GetAdapterModeCount, 00392 IDirect3D8Impl_EnumAdapterModes, 00393 IDirect3D8Impl_GetAdapterDisplayMode, 00394 IDirect3D8Impl_CheckDeviceType, 00395 IDirect3D8Impl_CheckDeviceFormat, 00396 IDirect3D8Impl_CheckDeviceMultiSampleType, 00397 IDirect3D8Impl_CheckDepthStencilMatch, 00398 IDirect3D8Impl_GetDeviceCaps, 00399 IDirect3D8Impl_GetAdapterMonitor, 00400 IDirect3D8Impl_CreateDevice 00401 }; Generated on Sat May 26 2012 04:20:34 for ReactOS by
1.7.6.1
|