2 * IDirect3DSurface9 implementation
4 * Copyright 2002-2005 Jason Edmeades
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "d3d9_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
27 /* IDirect3DSurface9 IUnknown parts follow: */
28 static HRESULT WINAPI IDirect3DSurface9Impl_QueryInterface(LPDIRECT3DSURFACE9 iface, REFIID riid, LPVOID* ppobj) {
29 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
31 if (IsEqualGUID(riid, &IID_IUnknown)
32 || IsEqualGUID(riid, &IID_IDirect3DResource9)
33 || IsEqualGUID(riid, &IID_IDirect3DSurface9)) {
34 IDirect3DSurface9_AddRef(iface);
39 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
44 static ULONG WINAPI IDirect3DSurface9Impl_AddRef(LPDIRECT3DSURFACE9 iface) {
45 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
47 TRACE("(%p)\n", This);
49 if (This->forwardReference) {
50 /* Forward refcounting */
51 TRACE("(%p) : Forwarding to %p\n", This, This->forwardReference);
52 return IUnknown_AddRef(This->forwardReference);
54 /* No container, handle our own refcounting */
55 ULONG ref = InterlockedIncrement(&This->ref);
56 if(ref == 1 && This->parentDevice) IDirect3DDevice9Ex_AddRef(This->parentDevice);
57 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
64 static ULONG WINAPI IDirect3DSurface9Impl_Release(LPDIRECT3DSURFACE9 iface) {
65 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
67 TRACE("(%p)\n", This);
69 if (This->forwardReference) {
70 /* Forward to the containerParent */
71 TRACE("(%p) : Forwarding to %p\n", This, This->forwardReference);
72 return IUnknown_Release(This->forwardReference);
74 /* No container, handle our own refcounting */
75 ULONG ref = InterlockedDecrement(&This->ref);
76 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
79 if (This->parentDevice) IDirect3DDevice9Ex_Release(This->parentDevice);
80 if (!This->isImplicit) {
82 IWineD3DSurface_Release(This->wineD3DSurface);
83 wined3d_mutex_unlock();
85 HeapFree(GetProcessHeap(), 0, This);
93 /* IDirect3DSurface9 IDirect3DResource9 Interface follow: */
94 static HRESULT WINAPI IDirect3DSurface9Impl_GetDevice(LPDIRECT3DSURFACE9 iface, IDirect3DDevice9** ppDevice) {
95 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
96 IWineD3DDevice *wined3d_device;
98 TRACE("(%p)->(%p)\n", This, ppDevice);
100 wined3d_mutex_lock();
101 hr = IWineD3DSurface_GetDevice(This->wineD3DSurface, &wined3d_device);
104 IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
105 IWineD3DDevice_Release(wined3d_device);
107 wined3d_mutex_unlock();
112 static HRESULT WINAPI IDirect3DSurface9Impl_SetPrivateData(LPDIRECT3DSURFACE9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
113 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
115 TRACE("(%p) Relay\n", This);
117 wined3d_mutex_lock();
118 hr = IWineD3DSurface_SetPrivateData(This->wineD3DSurface, refguid, pData, SizeOfData, Flags);
119 wined3d_mutex_unlock();
124 static HRESULT WINAPI IDirect3DSurface9Impl_GetPrivateData(LPDIRECT3DSURFACE9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
125 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
127 TRACE("(%p) Relay\n", This);
129 wined3d_mutex_lock();
130 hr = IWineD3DSurface_GetPrivateData(This->wineD3DSurface, refguid, pData, pSizeOfData);
131 wined3d_mutex_unlock();
136 static HRESULT WINAPI IDirect3DSurface9Impl_FreePrivateData(LPDIRECT3DSURFACE9 iface, REFGUID refguid) {
137 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
139 TRACE("(%p) Relay\n", This);
141 wined3d_mutex_lock();
142 hr = IWineD3DSurface_FreePrivateData(This->wineD3DSurface, refguid);
143 wined3d_mutex_unlock();
148 static DWORD WINAPI IDirect3DSurface9Impl_SetPriority(LPDIRECT3DSURFACE9 iface, DWORD PriorityNew) {
149 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
151 TRACE("(%p) Relay\n", This);
153 wined3d_mutex_lock();
154 hr = IWineD3DSurface_SetPriority(This->wineD3DSurface, PriorityNew);
155 wined3d_mutex_unlock();
160 static DWORD WINAPI IDirect3DSurface9Impl_GetPriority(LPDIRECT3DSURFACE9 iface) {
161 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
163 TRACE("(%p) Relay\n", This);
165 wined3d_mutex_lock();
166 hr = IWineD3DSurface_GetPriority(This->wineD3DSurface);
167 wined3d_mutex_unlock();
172 static void WINAPI IDirect3DSurface9Impl_PreLoad(LPDIRECT3DSURFACE9 iface) {
173 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
174 TRACE("(%p) Relay\n", This);
176 wined3d_mutex_lock();
177 IWineD3DSurface_PreLoad(This->wineD3DSurface);
178 wined3d_mutex_unlock();
181 static D3DRESOURCETYPE WINAPI IDirect3DSurface9Impl_GetType(LPDIRECT3DSURFACE9 iface) {
182 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
184 TRACE("(%p) Relay\n", This);
186 wined3d_mutex_lock();
187 ret = IWineD3DSurface_GetType(This->wineD3DSurface);
188 wined3d_mutex_unlock();
193 /* IDirect3DSurface9 Interface follow: */
194 static HRESULT WINAPI IDirect3DSurface9Impl_GetContainer(LPDIRECT3DSURFACE9 iface, REFIID riid, void** ppContainer) {
195 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
198 TRACE("(This %p, riid %s, ppContainer %p)\n", This, debugstr_guid(riid), ppContainer);
200 if (!This->container) return E_NOINTERFACE;
203 ERR("Called without a valid ppContainer\n");
206 res = IUnknown_QueryInterface(This->container, riid, ppContainer);
208 TRACE("Returning ppContainer %p, *ppContainer %p\n", ppContainer, *ppContainer);
213 static HRESULT WINAPI IDirect3DSurface9Impl_GetDesc(LPDIRECT3DSURFACE9 iface, D3DSURFACE_DESC* pDesc) {
214 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
215 WINED3DSURFACE_DESC wined3ddesc;
217 TRACE("(%p) Relay\n", This);
219 wined3d_mutex_lock();
220 hr = IWineD3DSurface_GetDesc(This->wineD3DSurface, &wined3ddesc);
221 wined3d_mutex_unlock();
225 pDesc->Format = d3dformat_from_wined3dformat(wined3ddesc.format);
226 pDesc->Type = wined3ddesc.resource_type;
227 pDesc->Usage = wined3ddesc.usage;
228 pDesc->Pool = wined3ddesc.pool;
229 pDesc->MultiSampleType = wined3ddesc.multisample_type;
230 pDesc->MultiSampleQuality = wined3ddesc.multisample_quality;
231 pDesc->Width = wined3ddesc.width;
232 pDesc->Height = wined3ddesc.height;
238 static HRESULT WINAPI IDirect3DSurface9Impl_LockRect(LPDIRECT3DSURFACE9 iface, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
239 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
241 TRACE("(%p) Relay\n", This);
243 wined3d_mutex_lock();
244 TRACE("(%p) calling IWineD3DSurface_LockRect %p %p %p %d\n", This, This->wineD3DSurface, pLockedRect, pRect, Flags);
245 hr = IWineD3DSurface_LockRect(This->wineD3DSurface, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
246 wined3d_mutex_unlock();
251 static HRESULT WINAPI IDirect3DSurface9Impl_UnlockRect(LPDIRECT3DSURFACE9 iface) {
252 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
254 TRACE("(%p) Relay\n", This);
256 wined3d_mutex_lock();
257 hr = IWineD3DSurface_UnlockRect(This->wineD3DSurface);
258 wined3d_mutex_unlock();
262 case WINEDDERR_NOTLOCKED: return D3DERR_INVALIDCALL;
267 static HRESULT WINAPI IDirect3DSurface9Impl_GetDC(LPDIRECT3DSURFACE9 iface, HDC* phdc) {
268 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
270 TRACE("(%p) Relay\n", This);
272 if(!This->getdc_supported)
274 WARN("Surface does not support GetDC, returning D3DERR_INVALIDCALL\n");
275 /* Don't touch the DC */
276 return D3DERR_INVALIDCALL;
279 wined3d_mutex_lock();
280 hr = IWineD3DSurface_GetDC(This->wineD3DSurface, phdc);
281 wined3d_mutex_unlock();
286 static HRESULT WINAPI IDirect3DSurface9Impl_ReleaseDC(LPDIRECT3DSURFACE9 iface, HDC hdc) {
287 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
289 TRACE("(%p) Relay\n", This);
291 wined3d_mutex_lock();
292 hr = IWineD3DSurface_ReleaseDC(This->wineD3DSurface, hdc);
293 wined3d_mutex_unlock();
296 case WINEDDERR_NODC: return WINED3DERR_INVALIDCALL;
302 const IDirect3DSurface9Vtbl Direct3DSurface9_Vtbl =
305 IDirect3DSurface9Impl_QueryInterface,
306 IDirect3DSurface9Impl_AddRef,
307 IDirect3DSurface9Impl_Release,
308 /* IDirect3DResource9 */
309 IDirect3DSurface9Impl_GetDevice,
310 IDirect3DSurface9Impl_SetPrivateData,
311 IDirect3DSurface9Impl_GetPrivateData,
312 IDirect3DSurface9Impl_FreePrivateData,
313 IDirect3DSurface9Impl_SetPriority,
314 IDirect3DSurface9Impl_GetPriority,
315 IDirect3DSurface9Impl_PreLoad,
316 IDirect3DSurface9Impl_GetType,
317 /* IDirect3DSurface9 */
318 IDirect3DSurface9Impl_GetContainer,
319 IDirect3DSurface9Impl_GetDesc,
320 IDirect3DSurface9Impl_LockRect,
321 IDirect3DSurface9Impl_UnlockRect,
322 IDirect3DSurface9Impl_GetDC,
323 IDirect3DSurface9Impl_ReleaseDC