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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "d3d9_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
27 /* IDirect3DSurface9 IUnknown parts follow: */
28 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 IUnknown_AddRef(iface);
39 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
43 ULONG WINAPI IDirect3DSurface9Impl_AddRef(LPDIRECT3DSURFACE9 iface) {
44 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
45 IUnknown *containerParent = NULL;
47 TRACE("(%p)\n", This);
49 IWineD3DSurface_GetContainerParent(This->wineD3DSurface, &containerParent);
50 if (containerParent) {
51 /* Forward to the containerParent */
52 TRACE("(%p) : Forwarding to %p\n", This, containerParent);
53 return IUnknown_AddRef(containerParent);
55 /* No container, handle our own refcounting */
56 ULONG ref = InterlockedIncrement(&This->ref);
57 TRACE("(%p) : AddRef from %ld\n", This, ref - 1);
64 ULONG WINAPI IDirect3DSurface9Impl_Release(LPDIRECT3DSURFACE9 iface) {
65 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
66 IUnknown *containerParent = NULL;
68 TRACE("(%p)\n", This);
70 IWineD3DSurface_GetContainerParent(This->wineD3DSurface, &containerParent);
71 if (containerParent) {
72 /* Forward to the containerParent */
73 TRACE("(%p) : Forwarding to %p\n", This, containerParent);
74 return IUnknown_Release(containerParent);
76 /* No container, handle our own refcounting */
77 ULONG ref = InterlockedDecrement(&This->ref);
78 TRACE("(%p) : ReleaseRef to %ld\n", This, ref);
81 IWineD3DSurface_Release(This->wineD3DSurface);
82 HeapFree(GetProcessHeap(), 0, This);
89 /* IDirect3DSurface9 IDirect3DResource9 Interface follow: */
90 HRESULT WINAPI IDirect3DSurface9Impl_GetDevice(LPDIRECT3DSURFACE9 iface, IDirect3DDevice9** ppDevice) {
91 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
92 return IDirect3DResource9Impl_GetDevice((LPDIRECT3DRESOURCE9) This, ppDevice);
95 HRESULT WINAPI IDirect3DSurface9Impl_SetPrivateData(LPDIRECT3DSURFACE9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
96 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
97 TRACE("(%p) Relay\n", This);
98 return IWineD3DSurface_SetPrivateData(This->wineD3DSurface, refguid, pData, SizeOfData, Flags);
101 HRESULT WINAPI IDirect3DSurface9Impl_GetPrivateData(LPDIRECT3DSURFACE9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
102 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
103 TRACE("(%p) Relay\n", This);
104 return IWineD3DSurface_GetPrivateData(This->wineD3DSurface, refguid, pData, pSizeOfData);
107 HRESULT WINAPI IDirect3DSurface9Impl_FreePrivateData(LPDIRECT3DSURFACE9 iface, REFGUID refguid) {
108 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
109 TRACE("(%p) Relay\n", This);
110 return IWineD3DSurface_FreePrivateData(This->wineD3DSurface, refguid);
113 DWORD WINAPI IDirect3DSurface9Impl_SetPriority(LPDIRECT3DSURFACE9 iface, DWORD PriorityNew) {
114 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
115 TRACE("(%p) Relay\n", This);
116 return IWineD3DSurface_SetPriority(This->wineD3DSurface, PriorityNew);
119 DWORD WINAPI IDirect3DSurface9Impl_GetPriority(LPDIRECT3DSURFACE9 iface) {
120 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
121 TRACE("(%p) Relay\n", This);
122 return IWineD3DSurface_GetPriority(This->wineD3DSurface);
125 void WINAPI IDirect3DSurface9Impl_PreLoad(LPDIRECT3DSURFACE9 iface) {
126 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
127 TRACE("(%p) Relay\n", This);
128 IWineD3DSurface_PreLoad(This->wineD3DSurface);
132 D3DRESOURCETYPE WINAPI IDirect3DSurface9Impl_GetType(LPDIRECT3DSURFACE9 iface) {
133 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
134 TRACE("(%p) Relay\n", This);
135 return IWineD3DSurface_GetType(This->wineD3DSurface);
138 /* IDirect3DSurface9 Interface follow: */
139 HRESULT WINAPI IDirect3DSurface9Impl_GetContainer(LPDIRECT3DSURFACE9 iface, REFIID riid, void** ppContainer) {
140 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
141 IWineD3DBase *wineD3DContainer = NULL;
142 IUnknown *wineD3DContainerParent = NULL;
145 TRACE("(This %p, riid %s, ppContainer %p)\n", This, debugstr_guid(riid), ppContainer);
148 ERR("Called without a valid ppContainer\n");
151 /* Get the WineD3D container. */
152 res = IWineD3DSurface_GetContainer(This->wineD3DSurface, &IID_IWineD3DBase, (void **)&wineD3DContainer);
153 if (res != D3D_OK) return res;
155 if (!wineD3DContainer) {
156 ERR("IWineD3DSurface_GetContainer should never return NULL\n");
160 IWineD3DBase_GetParent(wineD3DContainer, &wineD3DContainerParent);
161 IUnknown_Release(wineD3DContainer);
163 if (!wineD3DContainerParent) {
164 ERR("IWineD3DBase_GetParent should never return NULL\n");
167 /* Now, query the interface of the parent for the riid */
168 res = IUnknown_QueryInterface(wineD3DContainerParent, riid, ppContainer);
169 IUnknown_Release(wineD3DContainerParent);
171 TRACE("Returning ppContainer %p, *ppContainer %p\n", ppContainer, *ppContainer);
176 HRESULT WINAPI IDirect3DSurface9Impl_GetDesc(LPDIRECT3DSURFACE9 iface, D3DSURFACE_DESC* pDesc) {
177 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
178 WINED3DSURFACE_DESC wined3ddesc;
180 TRACE("(%p) Relay\n", This);
182 /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
183 wined3ddesc.Format = (WINED3DFORMAT *)&pDesc->Format;
184 wined3ddesc.Type = (WINED3DRESOURCETYPE *)&pDesc->Type;
185 wined3ddesc.Usage = &pDesc->Usage;
186 wined3ddesc.Pool = (WINED3DPOOL *) &pDesc->Pool;
187 wined3ddesc.Size = &tmpInt;
188 wined3ddesc.MultiSampleType = (WINED3DMULTISAMPLE_TYPE *) &pDesc->MultiSampleType;
189 wined3ddesc.MultiSampleQuality = &pDesc->MultiSampleQuality;
190 wined3ddesc.Width = &pDesc->Width;
191 wined3ddesc.Height = &pDesc->Height;
193 return IWineD3DSurface_GetDesc(This->wineD3DSurface, &wined3ddesc);
196 HRESULT WINAPI IDirect3DSurface9Impl_LockRect(LPDIRECT3DSURFACE9 iface, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
197 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
198 TRACE("(%p) Relay\n", This);
199 TRACE("(%p) calling IWineD3DSurface_LockRect %p %p %p %ld\n", This, This->wineD3DSurface, pLockedRect, pRect, Flags);
200 return IWineD3DSurface_LockRect(This->wineD3DSurface, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
203 HRESULT WINAPI IDirect3DSurface9Impl_UnlockRect(LPDIRECT3DSURFACE9 iface) {
204 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
205 TRACE("(%p) Relay\n", This);
206 return IWineD3DSurface_UnlockRect(This->wineD3DSurface);
209 HRESULT WINAPI IDirect3DSurface9Impl_GetDC(LPDIRECT3DSURFACE9 iface, HDC* phdc) {
210 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
211 TRACE("(%p) Relay\n", This);
212 return IWineD3DSurface_GetDC(This->wineD3DSurface, phdc);
215 HRESULT WINAPI IDirect3DSurface9Impl_ReleaseDC(LPDIRECT3DSURFACE9 iface, HDC hdc) {
216 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
217 TRACE("(%p) Relay\n", This);
218 return IWineD3DSurface_ReleaseDC(This->wineD3DSurface, hdc);
222 const IDirect3DSurface9Vtbl Direct3DSurface9_Vtbl =
225 IDirect3DSurface9Impl_QueryInterface,
226 IDirect3DSurface9Impl_AddRef,
227 IDirect3DSurface9Impl_Release,
228 /* IDirect3DResource9 */
229 IDirect3DSurface9Impl_GetDevice,
230 IDirect3DSurface9Impl_SetPrivateData,
231 IDirect3DSurface9Impl_GetPrivateData,
232 IDirect3DSurface9Impl_FreePrivateData,
233 IDirect3DSurface9Impl_SetPriority,
234 IDirect3DSurface9Impl_GetPriority,
235 IDirect3DSurface9Impl_PreLoad,
236 IDirect3DSurface9Impl_GetType,
237 /* IDirect3DSurface9 */
238 IDirect3DSurface9Impl_GetContainer,
239 IDirect3DSurface9Impl_GetDesc,
240 IDirect3DSurface9Impl_LockRect,
241 IDirect3DSurface9Impl_UnlockRect,
242 IDirect3DSurface9Impl_GetDC,
243 IDirect3DSurface9Impl_ReleaseDC