2 * IDirect3DSurface8 implementation
4 * Copyright 2005 Oliver Stieber
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "d3d8_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
26 /* IDirect3DSurface8 IUnknown parts follow: */
27 static HRESULT WINAPI IDirect3DSurface8Impl_QueryInterface(LPDIRECT3DSURFACE8 iface, REFIID riid, LPVOID *ppobj) {
28 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
30 if (IsEqualGUID(riid, &IID_IUnknown)
31 || IsEqualGUID(riid, &IID_IDirect3DResource8)
32 || IsEqualGUID(riid, &IID_IDirect3DSurface8)) {
33 IUnknown_AddRef(iface);
38 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
43 static ULONG WINAPI IDirect3DSurface8Impl_AddRef(LPDIRECT3DSURFACE8 iface) {
44 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
46 TRACE("(%p)\n", This);
48 if (This->forwardReference) {
49 /* Forward refcounting */
50 TRACE("(%p) : Forwarding to %p\n", This, This->forwardReference);
51 return IUnknown_AddRef(This->forwardReference);
53 /* No container, handle our own refcounting */
54 ULONG ref = InterlockedIncrement(&This->ref);
55 if(ref == 1 && This->parentDevice) IUnknown_AddRef(This->parentDevice);
56 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
61 static ULONG WINAPI IDirect3DSurface8Impl_Release(LPDIRECT3DSURFACE8 iface) {
62 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
64 TRACE("(%p)\n", This);
66 if (This->forwardReference) {
67 /* Forward refcounting */
68 TRACE("(%p) : Forwarding to %p\n", This, This->forwardReference);
69 return IUnknown_Release(This->forwardReference);
71 /* No container, handle our own refcounting */
72 ULONG ref = InterlockedDecrement(&This->ref);
73 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
76 if (This->parentDevice) IUnknown_Release(This->parentDevice);
77 /* Implicit surfaces are destroyed with the device, not if refcount reaches 0. */
78 if (!This->isImplicit) {
79 EnterCriticalSection(&d3d8_cs);
80 IWineD3DSurface_Release(This->wineD3DSurface);
81 LeaveCriticalSection(&d3d8_cs);
82 HeapFree(GetProcessHeap(), 0, This);
90 /* IDirect3DSurface8 IDirect3DResource8 Interface follow: */
91 static HRESULT WINAPI IDirect3DSurface8Impl_GetDevice(LPDIRECT3DSURFACE8 iface, IDirect3DDevice8 **ppDevice) {
92 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
94 TRACE("(%p)->(%p)\n", This, ppDevice);
96 EnterCriticalSection(&d3d8_cs);
97 hr = IDirect3DResource8Impl_GetDevice((LPDIRECT3DRESOURCE8) This, ppDevice);
98 LeaveCriticalSection(&d3d8_cs);
102 static HRESULT WINAPI IDirect3DSurface8Impl_SetPrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid, CONST void *pData, DWORD SizeOfData, DWORD Flags) {
103 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
105 TRACE("(%p) Relay\n", This);
107 EnterCriticalSection(&d3d8_cs);
108 hr = IWineD3DSurface_SetPrivateData(This->wineD3DSurface, refguid, pData, SizeOfData, Flags);
109 LeaveCriticalSection(&d3d8_cs);
113 static HRESULT WINAPI IDirect3DSurface8Impl_GetPrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid, void *pData, DWORD *pSizeOfData) {
114 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
116 TRACE("(%p) Relay\n", This);
118 EnterCriticalSection(&d3d8_cs);
119 hr = IWineD3DSurface_GetPrivateData(This->wineD3DSurface, refguid, pData, pSizeOfData);
120 LeaveCriticalSection(&d3d8_cs);
124 static HRESULT WINAPI IDirect3DSurface8Impl_FreePrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid) {
125 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
127 TRACE("(%p) Relay\n", This);
129 EnterCriticalSection(&d3d8_cs);
130 hr = IWineD3DSurface_FreePrivateData(This->wineD3DSurface, refguid);
131 LeaveCriticalSection(&d3d8_cs);
135 /* IDirect3DSurface8 Interface follow: */
136 static HRESULT WINAPI IDirect3DSurface8Impl_GetContainer(LPDIRECT3DSURFACE8 iface, REFIID riid, void **ppContainer) {
137 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
140 TRACE("(%p) Relay\n", This);
142 if (!This->container) return E_NOINTERFACE;
144 res = IUnknown_QueryInterface(This->container, riid, ppContainer);
146 TRACE("(%p) : returning %p\n", This, *ppContainer);
150 static HRESULT WINAPI IDirect3DSurface8Impl_GetDesc(LPDIRECT3DSURFACE8 iface, D3DSURFACE_DESC *pDesc) {
151 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
152 WINED3DSURFACE_DESC wined3ddesc;
154 TRACE("(%p) Relay\n", This);
156 /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
157 memset(&wined3ddesc, 0, sizeof(wined3ddesc));
158 wined3ddesc.Format = (WINED3DFORMAT *)&pDesc->Format;
159 wined3ddesc.Type = (WINED3DRESOURCETYPE *)&pDesc->Type;
160 wined3ddesc.Usage = &pDesc->Usage;
161 wined3ddesc.Pool = (WINED3DPOOL *) &pDesc->Pool;
162 wined3ddesc.Size = &pDesc->Size;
163 wined3ddesc.MultiSampleType = (WINED3DMULTISAMPLE_TYPE *) &pDesc->MultiSampleType;
164 wined3ddesc.Width = &pDesc->Width;
165 wined3ddesc.Height = &pDesc->Height;
167 EnterCriticalSection(&d3d8_cs);
168 hr = IWineD3DSurface_GetDesc(This->wineD3DSurface, &wined3ddesc);
169 LeaveCriticalSection(&d3d8_cs);
171 if (SUCCEEDED(hr)) pDesc->Format = d3dformat_from_wined3dformat(pDesc->Format);
176 static HRESULT WINAPI IDirect3DSurface8Impl_LockRect(LPDIRECT3DSURFACE8 iface, D3DLOCKED_RECT *pLockedRect, CONST RECT *pRect, DWORD Flags) {
177 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
179 TRACE("(%p) Relay\n", This);
180 TRACE("(%p) calling IWineD3DSurface_LockRect %p %p %p %d\n", This, This->wineD3DSurface, pLockedRect, pRect, Flags);
182 EnterCriticalSection(&d3d8_cs);
184 D3DSURFACE_DESC desc;
185 IDirect3DSurface8_GetDesc(iface, &desc);
187 if ((pRect->left < 0)
189 || (pRect->left >= pRect->right)
190 || (pRect->top >= pRect->bottom)
191 || (pRect->right > desc.Width)
192 || (pRect->bottom > desc.Height)) {
193 WARN("Trying to lock an invalid rectangle, returning D3DERR_INVALIDCALL\n");
194 LeaveCriticalSection(&d3d8_cs);
195 return D3DERR_INVALIDCALL;
199 hr = IWineD3DSurface_LockRect(This->wineD3DSurface, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
200 LeaveCriticalSection(&d3d8_cs);
204 static HRESULT WINAPI IDirect3DSurface8Impl_UnlockRect(LPDIRECT3DSURFACE8 iface) {
205 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
207 TRACE("(%p) Relay\n", This);
209 EnterCriticalSection(&d3d8_cs);
210 hr = IWineD3DSurface_UnlockRect(This->wineD3DSurface);
211 LeaveCriticalSection(&d3d8_cs);
214 case WINEDDERR_NOTLOCKED: return D3DERR_INVALIDCALL;
219 const IDirect3DSurface8Vtbl Direct3DSurface8_Vtbl =
222 IDirect3DSurface8Impl_QueryInterface,
223 IDirect3DSurface8Impl_AddRef,
224 IDirect3DSurface8Impl_Release,
225 /* IDirect3DResource8 */
226 IDirect3DSurface8Impl_GetDevice,
227 IDirect3DSurface8Impl_SetPrivateData,
228 IDirect3DSurface8Impl_GetPrivateData,
229 IDirect3DSurface8Impl_FreePrivateData,
230 /* IDirect3DSurface8 */
231 IDirect3DSurface8Impl_GetContainer,
232 IDirect3DSurface8Impl_GetDesc,
233 IDirect3DSurface8Impl_LockRect,
234 IDirect3DSurface8Impl_UnlockRect