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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "d3d8_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
26 /* IDirect3DSurface8 IUnknown parts follow: */
27 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);
42 ULONG WINAPI IDirect3DSurface8Impl_AddRef(LPDIRECT3DSURFACE8 iface) {
43 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
44 IUnknown *containerParent = NULL;
46 TRACE("(%p)\n", This);
48 IWineD3DSurface_GetContainerParent(This->wineD3DSurface, &containerParent);
49 if (containerParent) {
50 /* Forward to the containerParent */
51 TRACE("(%p) : Forwarding to %p\n", This, containerParent);
52 return IUnknown_AddRef(containerParent);
54 /* No container, handle our own refcounting */
55 ULONG ref = InterlockedIncrement(&This->ref);
56 TRACE("(%p) : AddRef from %ld\n", This, ref - 1);
61 ULONG WINAPI IDirect3DSurface8Impl_Release(LPDIRECT3DSURFACE8 iface) {
62 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
63 IUnknown *containerParent = NULL;
65 TRACE("(%p)\n", This);
67 IWineD3DSurface_GetContainerParent(This->wineD3DSurface, &containerParent);
68 if (containerParent) {
69 /* Forward to the containerParent */
70 TRACE("(%p) : Forwarding to %p\n", This, containerParent);
71 return IUnknown_Release(containerParent);
73 /* No container, handle our own refcounting */
74 ULONG ref = InterlockedDecrement(&This->ref);
75 TRACE("(%p) : ReleaseRef to %ld\n", This, ref);
78 IWineD3DSurface_Release(This->wineD3DSurface);
79 HeapFree(GetProcessHeap(), 0, This);
86 /* IDirect3DSurface8 IDirect3DResource8 Interface follow: */
87 HRESULT WINAPI IDirect3DSurface8Impl_GetDevice(LPDIRECT3DSURFACE8 iface, IDirect3DDevice8 **ppDevice) {
88 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
89 return IDirect3DResource8Impl_GetDevice((LPDIRECT3DRESOURCE8) This, ppDevice);
92 HRESULT WINAPI IDirect3DSurface8Impl_SetPrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid, CONST void *pData, DWORD SizeOfData, DWORD Flags) {
93 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
94 TRACE("(%p) Relay\n", This);
95 return IWineD3DSurface_SetPrivateData(This->wineD3DSurface, refguid, pData, SizeOfData, Flags);
98 HRESULT WINAPI IDirect3DSurface8Impl_GetPrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid, void *pData, DWORD *pSizeOfData) {
99 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
100 TRACE("(%p) Relay\n", This);
101 return IWineD3DSurface_GetPrivateData(This->wineD3DSurface, refguid, pData, pSizeOfData);
104 HRESULT WINAPI IDirect3DSurface8Impl_FreePrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid) {
105 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
106 TRACE("(%p) Relay\n", This);
107 return IWineD3DSurface_FreePrivateData(This->wineD3DSurface, refguid);
110 /* IDirect3DSurface8 Interface follow: */
111 HRESULT WINAPI IDirect3DSurface8Impl_GetContainer(LPDIRECT3DSURFACE8 iface, REFIID riid, void **ppContainer) {
112 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
114 IUnknown *IWineContainer = NULL;
116 TRACE("(%p) Relay\n", This);
118 /* The container returned from IWineD3DSurface_GetContainer is either an IWineD3DDevice,
119 one of the subclasses of IWineD3DBaseTexture or an IWineD3DSwapChain */
120 /* Get the IUnknown container. */
121 res = IWineD3DSurface_GetContainer(This->wineD3DSurface, &IID_IUnknown, (void **)&IWineContainer);
122 if (res == D3D_OK && IWineContainer != NULL) {
124 /* Now find out what kind of container it is (so that we can get its parent)*/
125 IUnknown *IUnknownParent = NULL;
126 IUnknown *myContainer = NULL;
127 if (D3D_OK == IUnknown_QueryInterface(IWineContainer, &IID_IWineD3DDevice, (void **)&myContainer)) {
128 IWineD3DDevice_GetParent((IWineD3DDevice *)IWineContainer, &IUnknownParent);
129 IUnknown_Release(myContainer);
131 if (D3D_OK == IUnknown_QueryInterface(IWineContainer, &IID_IWineD3DBaseTexture, (void **)&myContainer)) {
132 IWineD3DBaseTexture_GetParent((IWineD3DBaseTexture *)IWineContainer, &IUnknownParent);
133 IUnknown_Release(myContainer);
135 if (D3D_OK == IUnknown_QueryInterface(IWineContainer, &IID_IWineD3DSwapChain, (void **)&myContainer)) {
136 IWineD3DSwapChain_GetParent((IWineD3DSwapChain *)IWineContainer, &IUnknownParent);
137 IUnknown_Release(myContainer);
139 FIXME("Container is of unknown interface\n");
142 IUnknown_Release((IWineD3DDevice *)IWineContainer);
144 /* Now, query the interface of the parent for the riid */
145 if (IUnknownParent != NULL) {
146 res = IUnknown_QueryInterface(IUnknownParent, riid, ppContainer);
148 IUnknown_Release(IUnknownParent);
152 TRACE("(%p) : returning %p\n", This, *ppContainer);
156 HRESULT WINAPI IDirect3DSurface8Impl_GetDesc(LPDIRECT3DSURFACE8 iface, D3DSURFACE_DESC *pDesc) {
157 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
158 WINED3DSURFACE_DESC wined3ddesc;
160 TRACE("(%p) Relay\n", This);
162 /* As d3d8 and d3d8 structures differ, pass in ptrs to where data needs to go */
163 memset(&wined3ddesc, 0, sizeof(wined3ddesc));
164 wined3ddesc.Format = (WINED3DFORMAT *)&pDesc->Format;
165 wined3ddesc.Type = (WINED3DRESOURCETYPE *)&pDesc->Type;
166 wined3ddesc.Usage = &pDesc->Usage;
167 wined3ddesc.Pool = (WINED3DPOOL *) &pDesc->Pool;
168 wined3ddesc.Size = &tmpInt;
169 wined3ddesc.MultiSampleType = (WINED3DMULTISAMPLE_TYPE *) &pDesc->MultiSampleType;
170 wined3ddesc.Width = &pDesc->Width;
171 wined3ddesc.Height = &pDesc->Height;
173 return IWineD3DSurface_GetDesc(This->wineD3DSurface, &wined3ddesc);
176 HRESULT WINAPI IDirect3DSurface8Impl_LockRect(LPDIRECT3DSURFACE8 iface, D3DLOCKED_RECT *pLockedRect, CONST RECT *pRect, DWORD Flags) {
177 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
178 TRACE("(%p) Relay\n", This);
179 TRACE("(%p) calling IWineD3DSurface_LockRect %p %p %p %ld\n", This, This->wineD3DSurface, pLockedRect, pRect, Flags);
180 return IWineD3DSurface_LockRect(This->wineD3DSurface, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
183 HRESULT WINAPI IDirect3DSurface8Impl_UnlockRect(LPDIRECT3DSURFACE8 iface) {
184 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
185 TRACE("(%p) Relay\n", This);
186 return IWineD3DSurface_UnlockRect(This->wineD3DSurface);
189 const IDirect3DSurface8Vtbl Direct3DSurface8_Vtbl =
192 IDirect3DSurface8Impl_QueryInterface,
193 IDirect3DSurface8Impl_AddRef,
194 IDirect3DSurface8Impl_Release,
195 /* IDirect3DResource8 */
196 IDirect3DSurface8Impl_GetDevice,
197 IDirect3DSurface8Impl_SetPrivateData,
198 IDirect3DSurface8Impl_GetPrivateData,
199 IDirect3DSurface8Impl_FreePrivateData,
200 /* IDirect3DSurface8 */
201 IDirect3DSurface8Impl_GetContainer,
202 IDirect3DSurface8Impl_GetDesc,
203 IDirect3DSurface8Impl_LockRect,
204 IDirect3DSurface8Impl_UnlockRect