Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygensurface.c
Go to the documentation of this file.
00001 /* 00002 * IDirect3DSurface9 implementation 00003 * 00004 * Copyright 2002-2005 Jason Edmeades 00005 * Raphael Junqueira 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 00020 */ 00021 00022 #include "config.h" 00023 #include <assert.h> 00024 #include "d3d9_private.h" 00025 00026 WINE_DEFAULT_DEBUG_CHANNEL(d3d9); 00027 00028 static inline IDirect3DSurface9Impl *impl_from_IDirect3DSurface9(IDirect3DSurface9 *iface) 00029 { 00030 return CONTAINING_RECORD(iface, IDirect3DSurface9Impl, IDirect3DSurface9_iface); 00031 } 00032 00033 /* IDirect3DSurface9 IUnknown parts follow: */ 00034 static HRESULT WINAPI IDirect3DSurface9Impl_QueryInterface(IDirect3DSurface9 *iface, REFIID riid, 00035 void **ppobj) 00036 { 00037 IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface); 00038 00039 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj); 00040 00041 if (IsEqualGUID(riid, &IID_IUnknown) 00042 || IsEqualGUID(riid, &IID_IDirect3DResource9) 00043 || IsEqualGUID(riid, &IID_IDirect3DSurface9)) { 00044 IDirect3DSurface9_AddRef(iface); 00045 *ppobj = This; 00046 return S_OK; 00047 } 00048 00049 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj); 00050 *ppobj = NULL; 00051 return E_NOINTERFACE; 00052 } 00053 00054 static ULONG WINAPI IDirect3DSurface9Impl_AddRef(IDirect3DSurface9 *iface) 00055 { 00056 IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface); 00057 00058 TRACE("iface %p.\n", iface); 00059 00060 if (This->forwardReference) { 00061 /* Forward refcounting */ 00062 TRACE("(%p) : Forwarding to %p\n", This, This->forwardReference); 00063 return IUnknown_AddRef(This->forwardReference); 00064 } else { 00065 /* No container, handle our own refcounting */ 00066 ULONG ref = InterlockedIncrement(&This->ref); 00067 00068 TRACE("%p increasing refcount to %u.\n", iface, ref); 00069 00070 if (ref == 1) 00071 { 00072 if (This->parentDevice) IDirect3DDevice9Ex_AddRef(This->parentDevice); 00073 wined3d_mutex_lock(); 00074 wined3d_surface_incref(This->wined3d_surface); 00075 wined3d_mutex_unlock(); 00076 } 00077 00078 return ref; 00079 } 00080 00081 } 00082 00083 static ULONG WINAPI IDirect3DSurface9Impl_Release(IDirect3DSurface9 *iface) 00084 { 00085 IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface); 00086 00087 TRACE("iface %p.\n", iface); 00088 00089 if (This->forwardReference) { 00090 /* Forward to the containerParent */ 00091 TRACE("(%p) : Forwarding to %p\n", This, This->forwardReference); 00092 return IUnknown_Release(This->forwardReference); 00093 } else { 00094 /* No container, handle our own refcounting */ 00095 ULONG ref = InterlockedDecrement(&This->ref); 00096 00097 TRACE("%p decreasing refcount to %u.\n", iface, ref); 00098 00099 if (ref == 0) { 00100 IDirect3DDevice9Ex *parentDevice = This->parentDevice; 00101 00102 wined3d_mutex_lock(); 00103 wined3d_surface_decref(This->wined3d_surface); 00104 wined3d_mutex_unlock(); 00105 00106 /* Release the device last, as it may cause the device to be destroyed. */ 00107 if (parentDevice) IDirect3DDevice9Ex_Release(parentDevice); 00108 } 00109 00110 return ref; 00111 } 00112 } 00113 00114 /* IDirect3DSurface9 IDirect3DResource9 Interface follow: */ 00115 static HRESULT WINAPI IDirect3DSurface9Impl_GetDevice(IDirect3DSurface9 *iface, 00116 IDirect3DDevice9 **device) 00117 { 00118 IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface); 00119 00120 TRACE("iface %p, device %p.\n", iface, device); 00121 00122 if (This->forwardReference) 00123 { 00124 IDirect3DResource9 *resource; 00125 HRESULT hr; 00126 00127 hr = IUnknown_QueryInterface(This->forwardReference, &IID_IDirect3DResource9, (void **)&resource); 00128 if (SUCCEEDED(hr)) 00129 { 00130 hr = IDirect3DResource9_GetDevice(resource, device); 00131 IDirect3DResource9_Release(resource); 00132 00133 TRACE("Returning device %p.\n", *device); 00134 } 00135 00136 return hr; 00137 } 00138 00139 *device = (IDirect3DDevice9 *)This->parentDevice; 00140 IDirect3DDevice9_AddRef(*device); 00141 00142 TRACE("Returning device %p.\n", *device); 00143 00144 return D3D_OK; 00145 } 00146 00147 static HRESULT WINAPI IDirect3DSurface9Impl_SetPrivateData(IDirect3DSurface9 *iface, REFGUID guid, 00148 const void *data, DWORD data_size, DWORD flags) 00149 { 00150 IDirect3DSurface9Impl *surface = impl_from_IDirect3DSurface9(iface); 00151 struct wined3d_resource *resource; 00152 HRESULT hr; 00153 00154 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n", 00155 iface, debugstr_guid(guid), data, data_size, flags); 00156 00157 wined3d_mutex_lock(); 00158 resource = wined3d_surface_get_resource(surface->wined3d_surface); 00159 hr = wined3d_resource_set_private_data(resource, guid, data, data_size, flags); 00160 wined3d_mutex_unlock(); 00161 00162 return hr; 00163 } 00164 00165 static HRESULT WINAPI IDirect3DSurface9Impl_GetPrivateData(IDirect3DSurface9 *iface, REFGUID guid, 00166 void *data, DWORD *data_size) 00167 { 00168 IDirect3DSurface9Impl *surface = impl_from_IDirect3DSurface9(iface); 00169 struct wined3d_resource *resource; 00170 HRESULT hr; 00171 00172 TRACE("iface %p, guid %s, data %p, data_size %p.\n", 00173 iface, debugstr_guid(guid), data, data_size); 00174 00175 wined3d_mutex_lock(); 00176 resource = wined3d_surface_get_resource(surface->wined3d_surface); 00177 hr = wined3d_resource_get_private_data(resource, guid, data, data_size); 00178 wined3d_mutex_unlock(); 00179 00180 return hr; 00181 } 00182 00183 static HRESULT WINAPI IDirect3DSurface9Impl_FreePrivateData(IDirect3DSurface9 *iface, REFGUID guid) 00184 { 00185 IDirect3DSurface9Impl *surface = impl_from_IDirect3DSurface9(iface); 00186 struct wined3d_resource *resource; 00187 HRESULT hr; 00188 00189 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid)); 00190 00191 wined3d_mutex_lock(); 00192 resource = wined3d_surface_get_resource(surface->wined3d_surface); 00193 hr = wined3d_resource_free_private_data(resource, guid); 00194 wined3d_mutex_unlock(); 00195 00196 return hr; 00197 } 00198 00199 static DWORD WINAPI IDirect3DSurface9Impl_SetPriority(IDirect3DSurface9 *iface, DWORD PriorityNew) 00200 { 00201 IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface); 00202 HRESULT hr; 00203 00204 TRACE("iface %p, priority %u.\n", iface, PriorityNew); 00205 00206 wined3d_mutex_lock(); 00207 hr = wined3d_surface_set_priority(This->wined3d_surface, PriorityNew); 00208 wined3d_mutex_unlock(); 00209 00210 return hr; 00211 } 00212 00213 static DWORD WINAPI IDirect3DSurface9Impl_GetPriority(IDirect3DSurface9 *iface) 00214 { 00215 IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface); 00216 HRESULT hr; 00217 00218 TRACE("iface %p.\n", iface); 00219 00220 wined3d_mutex_lock(); 00221 hr = wined3d_surface_get_priority(This->wined3d_surface); 00222 wined3d_mutex_unlock(); 00223 00224 return hr; 00225 } 00226 00227 static void WINAPI IDirect3DSurface9Impl_PreLoad(IDirect3DSurface9 *iface) 00228 { 00229 IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface); 00230 00231 TRACE("iface %p.\n", iface); 00232 00233 wined3d_mutex_lock(); 00234 wined3d_surface_preload(This->wined3d_surface); 00235 wined3d_mutex_unlock(); 00236 } 00237 00238 static D3DRESOURCETYPE WINAPI IDirect3DSurface9Impl_GetType(IDirect3DSurface9 *iface) 00239 { 00240 TRACE("iface %p.\n", iface); 00241 00242 return D3DRTYPE_SURFACE; 00243 } 00244 00245 /* IDirect3DSurface9 Interface follow: */ 00246 static HRESULT WINAPI IDirect3DSurface9Impl_GetContainer(IDirect3DSurface9 *iface, REFIID riid, 00247 void **ppContainer) 00248 { 00249 IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface); 00250 HRESULT res; 00251 00252 TRACE("iface %p, riid %s, container %p.\n", iface, debugstr_guid(riid), ppContainer); 00253 00254 if (!This->container) return E_NOINTERFACE; 00255 00256 res = IUnknown_QueryInterface(This->container, riid, ppContainer); 00257 00258 TRACE("Returning ppContainer %p, *ppContainer %p\n", ppContainer, *ppContainer); 00259 00260 return res; 00261 } 00262 00263 static HRESULT WINAPI IDirect3DSurface9Impl_GetDesc(IDirect3DSurface9 *iface, D3DSURFACE_DESC *desc) 00264 { 00265 IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface); 00266 struct wined3d_resource_desc wined3d_desc; 00267 struct wined3d_resource *wined3d_resource; 00268 00269 TRACE("iface %p, desc %p.\n", iface, desc); 00270 00271 wined3d_mutex_lock(); 00272 wined3d_resource = wined3d_surface_get_resource(This->wined3d_surface); 00273 wined3d_resource_get_desc(wined3d_resource, &wined3d_desc); 00274 wined3d_mutex_unlock(); 00275 00276 desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format); 00277 desc->Type = wined3d_desc.resource_type; 00278 desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK; 00279 desc->Pool = wined3d_desc.pool; 00280 desc->MultiSampleType = wined3d_desc.multisample_type; 00281 desc->MultiSampleQuality = wined3d_desc.multisample_quality; 00282 desc->Width = wined3d_desc.width; 00283 desc->Height = wined3d_desc.height; 00284 00285 return D3D_OK; 00286 } 00287 00288 static HRESULT WINAPI IDirect3DSurface9Impl_LockRect(IDirect3DSurface9 *iface, 00289 D3DLOCKED_RECT *pLockedRect, const RECT *pRect, DWORD Flags) 00290 { 00291 IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface); 00292 HRESULT hr; 00293 00294 TRACE("iface %p, locked_rect %p, rect %p, flags %#x.\n", iface, pLockedRect, pRect, Flags); 00295 00296 wined3d_mutex_lock(); 00297 hr = wined3d_surface_map(This->wined3d_surface, (struct wined3d_mapped_rect *)pLockedRect, pRect, Flags); 00298 wined3d_mutex_unlock(); 00299 00300 return hr; 00301 } 00302 00303 static HRESULT WINAPI IDirect3DSurface9Impl_UnlockRect(IDirect3DSurface9 *iface) 00304 { 00305 IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface); 00306 HRESULT hr; 00307 00308 TRACE("iface %p.\n", iface); 00309 00310 wined3d_mutex_lock(); 00311 hr = wined3d_surface_unmap(This->wined3d_surface); 00312 wined3d_mutex_unlock(); 00313 00314 switch(hr) 00315 { 00316 case WINEDDERR_NOTLOCKED: return D3DERR_INVALIDCALL; 00317 default: return hr; 00318 } 00319 } 00320 00321 static HRESULT WINAPI IDirect3DSurface9Impl_GetDC(IDirect3DSurface9 *iface, HDC* phdc) 00322 { 00323 IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface); 00324 HRESULT hr; 00325 00326 TRACE("iface %p, hdc %p.\n", iface, phdc); 00327 00328 if(!This->getdc_supported) 00329 { 00330 WARN("Surface does not support GetDC, returning D3DERR_INVALIDCALL\n"); 00331 /* Don't touch the DC */ 00332 return D3DERR_INVALIDCALL; 00333 } 00334 00335 wined3d_mutex_lock(); 00336 hr = wined3d_surface_getdc(This->wined3d_surface, phdc); 00337 wined3d_mutex_unlock(); 00338 00339 return hr; 00340 } 00341 00342 static HRESULT WINAPI IDirect3DSurface9Impl_ReleaseDC(IDirect3DSurface9 *iface, HDC hdc) 00343 { 00344 IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface); 00345 HRESULT hr; 00346 00347 TRACE("iface %p, hdc %p.\n", iface, hdc); 00348 00349 wined3d_mutex_lock(); 00350 hr = wined3d_surface_releasedc(This->wined3d_surface, hdc); 00351 wined3d_mutex_unlock(); 00352 00353 switch (hr) 00354 { 00355 case WINEDDERR_NODC: return D3DERR_INVALIDCALL; 00356 default: return hr; 00357 } 00358 } 00359 00360 static const IDirect3DSurface9Vtbl Direct3DSurface9_Vtbl = 00361 { 00362 /* IUnknown */ 00363 IDirect3DSurface9Impl_QueryInterface, 00364 IDirect3DSurface9Impl_AddRef, 00365 IDirect3DSurface9Impl_Release, 00366 /* IDirect3DResource9 */ 00367 IDirect3DSurface9Impl_GetDevice, 00368 IDirect3DSurface9Impl_SetPrivateData, 00369 IDirect3DSurface9Impl_GetPrivateData, 00370 IDirect3DSurface9Impl_FreePrivateData, 00371 IDirect3DSurface9Impl_SetPriority, 00372 IDirect3DSurface9Impl_GetPriority, 00373 IDirect3DSurface9Impl_PreLoad, 00374 IDirect3DSurface9Impl_GetType, 00375 /* IDirect3DSurface9 */ 00376 IDirect3DSurface9Impl_GetContainer, 00377 IDirect3DSurface9Impl_GetDesc, 00378 IDirect3DSurface9Impl_LockRect, 00379 IDirect3DSurface9Impl_UnlockRect, 00380 IDirect3DSurface9Impl_GetDC, 00381 IDirect3DSurface9Impl_ReleaseDC 00382 }; 00383 00384 static void STDMETHODCALLTYPE surface_wined3d_object_destroyed(void *parent) 00385 { 00386 HeapFree(GetProcessHeap(), 0, parent); 00387 } 00388 00389 static const struct wined3d_parent_ops d3d9_surface_wined3d_parent_ops = 00390 { 00391 surface_wined3d_object_destroyed, 00392 }; 00393 00394 HRESULT surface_init(IDirect3DSurface9Impl *surface, IDirect3DDevice9Impl *device, 00395 UINT width, UINT height, D3DFORMAT format, BOOL lockable, BOOL discard, UINT level, 00396 DWORD usage, D3DPOOL pool, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality) 00397 { 00398 DWORD flags = 0; 00399 HRESULT hr; 00400 00401 surface->IDirect3DSurface9_iface.lpVtbl = &Direct3DSurface9_Vtbl; 00402 surface->ref = 1; 00403 00404 switch (format) 00405 { 00406 case D3DFMT_A8R8G8B8: 00407 case D3DFMT_X8R8G8B8: 00408 case D3DFMT_R5G6B5: 00409 case D3DFMT_X1R5G5B5: 00410 case D3DFMT_A1R5G5B5: 00411 case D3DFMT_R8G8B8: 00412 surface->getdc_supported = TRUE; 00413 break; 00414 00415 default: 00416 surface->getdc_supported = FALSE; 00417 break; 00418 } 00419 00420 /* FIXME: Check MAX bounds of MultisampleQuality. */ 00421 if (multisample_quality > 0) 00422 { 00423 FIXME("Multisample quality set to %u, substituting 0.\n", multisample_quality); 00424 multisample_quality = 0; 00425 } 00426 00427 if (lockable) 00428 flags |= WINED3D_SURFACE_MAPPABLE; 00429 if (discard) 00430 flags |= WINED3D_SURFACE_DISCARD; 00431 00432 wined3d_mutex_lock(); 00433 hr = wined3d_surface_create(device->wined3d_device, width, height, wined3dformat_from_d3dformat(format), 00434 level, usage & WINED3DUSAGE_MASK, (enum wined3d_pool)pool, multisample_type, multisample_quality, 00435 SURFACE_OPENGL, flags, surface, &d3d9_surface_wined3d_parent_ops, &surface->wined3d_surface); 00436 wined3d_mutex_unlock(); 00437 if (FAILED(hr)) 00438 { 00439 WARN("Failed to create wined3d surface, hr %#x.\n", hr); 00440 return hr; 00441 } 00442 00443 surface->parentDevice = &device->IDirect3DDevice9Ex_iface; 00444 IDirect3DDevice9Ex_AddRef(surface->parentDevice); 00445 00446 return D3D_OK; 00447 } 00448 00449 IDirect3DSurface9Impl *unsafe_impl_from_IDirect3DSurface9(IDirect3DSurface9 *iface) 00450 { 00451 if (!iface) 00452 return NULL; 00453 assert(iface->lpVtbl == &Direct3DSurface9_Vtbl); 00454 00455 return impl_from_IDirect3DSurface9(iface); 00456 } Generated on Sat May 26 2012 04:20:37 for ReactOS by
1.7.6.1
|