2 * IDirect3DSurface8 implementation
4 * Copyright 2002 Jason Edmeades
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
25 #include "wine/debug.h"
27 #include "d3d8_private.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
31 /* IDirect3DVolume IUnknown parts follow: */
32 HRESULT WINAPI IDirect3DSurface8Impl_QueryInterface(LPDIRECT3DSURFACE8 iface,REFIID riid,LPVOID *ppobj)
34 ICOM_THIS(IDirect3DSurface8Impl,iface);
36 if (IsEqualGUID(riid, &IID_IUnknown)
37 || IsEqualGUID(riid, &IID_IDirect3DSurface8)) {
38 IDirect3DSurface8Impl_AddRef(iface);
43 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
47 ULONG WINAPI IDirect3DSurface8Impl_AddRef(LPDIRECT3DSURFACE8 iface) {
48 ICOM_THIS(IDirect3DSurface8Impl,iface);
49 TRACE("(%p) : AddRef from %ld\n", This, This->ref);
53 ULONG WINAPI IDirect3DSurface8Impl_Release(LPDIRECT3DSURFACE8 iface) {
54 ICOM_THIS(IDirect3DSurface8Impl,iface);
55 ULONG ref = --This->ref;
56 TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
58 HeapFree(GetProcessHeap(), 0, This->allocatedMemory);
59 HeapFree(GetProcessHeap(), 0, This);
64 /* IDirect3DSurface8: */
65 HRESULT WINAPI IDirect3DSurface8Impl_GetDevice(LPDIRECT3DSURFACE8 iface, IDirect3DDevice8** ppDevice) {
66 ICOM_THIS(IDirect3DSurface8Impl,iface);
67 TRACE("(%p) : returning %p\n", This, This->Device);
68 *ppDevice = (LPDIRECT3DDEVICE8) This->Device;
70 * Note Calling this method will increase the internal reference count
71 * on the IDirect3DDevice8 interface.
73 IDirect3DDevice8Impl_AddRef(*ppDevice);
76 HRESULT WINAPI IDirect3DSurface8Impl_SetPrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
77 ICOM_THIS(IDirect3DSurface8Impl,iface);
78 FIXME("(%p) : stub\n", This); return D3D_OK;
80 HRESULT WINAPI IDirect3DSurface8Impl_GetPrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
81 ICOM_THIS(IDirect3DSurface8Impl,iface);
82 FIXME("(%p) : stub\n", This); return D3D_OK;
84 HRESULT WINAPI IDirect3DSurface8Impl_FreePrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid) {
85 ICOM_THIS(IDirect3DSurface8Impl,iface);
86 FIXME("(%p) : stub\n", This); return D3D_OK;
88 HRESULT WINAPI IDirect3DSurface8Impl_GetContainer(LPDIRECT3DSURFACE8 iface, REFIID riid, void** ppContainer) {
89 ICOM_THIS(IDirect3DSurface8Impl,iface);
92 TRACE("(%p) : returning %p\n", This, This->Container);
93 *ppContainer = This->Container;
96 res = IUnknown_QueryInterface(This->Container, riid, ppContainer);
97 if (E_NOINTERFACE == res) {
99 * If the surface is created using CreateImageSurface, CreateRenderTarget,
100 * or CreateDepthStencilSurface, the surface is considered stand alone. In this case,
101 * GetContainer will return the Direct3D device used to create the surface.
103 res = IUnknown_QueryInterface(This->Container, &IID_IDirect3DDevice8, ppContainer);
105 TRACE("(%p) : returning %p\n", This, *ppContainer);
108 HRESULT WINAPI IDirect3DSurface8Impl_GetDesc(LPDIRECT3DSURFACE8 iface, D3DSURFACE_DESC *pDesc) {
109 ICOM_THIS(IDirect3DSurface8Impl,iface);
111 TRACE("(%p) : copying into %p\n", This, pDesc);
112 memcpy(pDesc, &This->myDesc, sizeof(D3DSURFACE_DESC));
115 HRESULT WINAPI IDirect3DSurface8Impl_LockRect(LPDIRECT3DSURFACE8 iface, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect,DWORD Flags) {
116 ICOM_THIS(IDirect3DSurface8Impl,iface);
117 /* fixme: should we really lock as such? */
118 TRACE("(%p) : rect=%p, output prect=%p, allMem=%p\n", This, pRect, pLockedRect, This->allocatedMemory);
120 pLockedRect->Pitch = This->bytesPerPixel * This->myDesc.Width; /* Bytes / row */
122 pLockedRect->pBits = This->allocatedMemory;
124 TRACE("Lock Rect (%p) = l %ld, t %ld, r %ld, b %ld\n", pRect, pRect->left, pRect->top, pRect->right, pRect->bottom);
125 pLockedRect->pBits = This->allocatedMemory + (pLockedRect->Pitch * pRect->top) + (pRect->left * This->bytesPerPixel);
127 TRACE("returning pBits=%p, pitch=%d\n", pLockedRect->pBits, pLockedRect->Pitch);
130 HRESULT WINAPI IDirect3DSurface8Impl_UnlockRect(LPDIRECT3DSURFACE8 iface) {
131 ICOM_THIS(IDirect3DSurface8Impl,iface);
132 TRACE("(%p) : stub\n", This);
133 if (This->Container) {
134 IDirect3DBaseTexture8 *cont = (IDirect3DBaseTexture8*) This->Container;
136 /* Now setup the texture appropraitly */
137 int containerType = IDirect3DBaseTexture8Impl_GetType(cont);
138 if (containerType == D3DRTYPE_TEXTURE) {
139 IDirect3DTexture8Impl *pTexture = (IDirect3DTexture8Impl *)cont;
140 pTexture->Dirty = TRUE;
141 } else if (containerType == D3DRTYPE_CUBETEXTURE) {
142 IDirect3DCubeTexture8Impl *pTexture = (IDirect3DCubeTexture8Impl *)cont;
143 pTexture->Dirty = TRUE;
146 FIXME("Set dirty on container type %d\n", containerType);
153 ICOM_VTABLE(IDirect3DSurface8) Direct3DSurface8_Vtbl =
155 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
156 IDirect3DSurface8Impl_QueryInterface,
157 IDirect3DSurface8Impl_AddRef,
158 IDirect3DSurface8Impl_Release,
159 IDirect3DSurface8Impl_GetDevice,
160 IDirect3DSurface8Impl_SetPrivateData,
161 IDirect3DSurface8Impl_GetPrivateData,
162 IDirect3DSurface8Impl_FreePrivateData,
163 IDirect3DSurface8Impl_GetContainer,
164 IDirect3DSurface8Impl_GetDesc,
165 IDirect3DSurface8Impl_LockRect,
166 IDirect3DSurface8Impl_UnlockRect,