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
27 #include "wine/debug.h"
29 #include "d3d8_private.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
33 /* IDirect3DVolume IUnknown parts follow: */
34 HRESULT WINAPI IDirect3DSurface8Impl_QueryInterface(LPDIRECT3DSURFACE8 iface,REFIID riid,LPVOID *ppobj)
36 ICOM_THIS(IDirect3DSurface8Impl,iface);
38 if (IsEqualGUID(riid, &IID_IUnknown)
39 || IsEqualGUID(riid, &IID_IDirect3DSurface8)) {
40 IDirect3DSurface8Impl_AddRef(iface);
45 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
49 ULONG WINAPI IDirect3DSurface8Impl_AddRef(LPDIRECT3DSURFACE8 iface) {
50 ICOM_THIS(IDirect3DSurface8Impl,iface);
51 TRACE("(%p) : AddRef from %ld\n", This, This->ref);
55 ULONG WINAPI IDirect3DSurface8Impl_Release(LPDIRECT3DSURFACE8 iface) {
56 ICOM_THIS(IDirect3DSurface8Impl,iface);
57 ULONG ref = --This->ref;
58 TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
60 HeapFree(GetProcessHeap(), 0, This->allocatedMemory);
61 HeapFree(GetProcessHeap(), 0, This);
66 /* IDirect3DSurface8: */
67 HRESULT WINAPI IDirect3DSurface8Impl_GetDevice(LPDIRECT3DSURFACE8 iface, IDirect3DDevice8** ppDevice) {
68 ICOM_THIS(IDirect3DSurface8Impl,iface);
69 TRACE("(%p) : returning %p\n", This, This->Device);
70 *ppDevice = (LPDIRECT3DDEVICE8) This->Device;
72 * Note Calling this method will increase the internal reference count
73 * on the IDirect3DDevice8 interface.
75 IDirect3DDevice8Impl_AddRef(*ppDevice);
78 HRESULT WINAPI IDirect3DSurface8Impl_SetPrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
79 ICOM_THIS(IDirect3DSurface8Impl,iface);
80 FIXME("(%p) : stub\n", This); return D3D_OK;
82 HRESULT WINAPI IDirect3DSurface8Impl_GetPrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
83 ICOM_THIS(IDirect3DSurface8Impl,iface);
84 FIXME("(%p) : stub\n", This); return D3D_OK;
86 HRESULT WINAPI IDirect3DSurface8Impl_FreePrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid) {
87 ICOM_THIS(IDirect3DSurface8Impl,iface);
88 FIXME("(%p) : stub\n", This); return D3D_OK;
90 HRESULT WINAPI IDirect3DSurface8Impl_GetContainer(LPDIRECT3DSURFACE8 iface, REFIID riid, void** ppContainer) {
91 ICOM_THIS(IDirect3DSurface8Impl,iface);
94 TRACE("(%p) : returning %p\n", This, This->Container);
95 *ppContainer = This->Container;
98 res = IUnknown_QueryInterface(This->Container, riid, ppContainer);
99 if (E_NOINTERFACE == res) {
101 * If the surface is created using CreateImageSurface, CreateRenderTarget,
102 * or CreateDepthStencilSurface, the surface is considered stand alone. In this case,
103 * GetContainer will return the Direct3D device used to create the surface.
105 res = IUnknown_QueryInterface(This->Container, &IID_IDirect3DDevice8, ppContainer);
107 TRACE("(%p) : returning %p\n", This, *ppContainer);
110 HRESULT WINAPI IDirect3DSurface8Impl_GetDesc(LPDIRECT3DSURFACE8 iface, D3DSURFACE_DESC *pDesc) {
111 ICOM_THIS(IDirect3DSurface8Impl,iface);
113 TRACE("(%p) : copying into %p\n", This, pDesc);
114 memcpy(pDesc, &This->myDesc, sizeof(D3DSURFACE_DESC));
117 HRESULT WINAPI IDirect3DSurface8Impl_LockRect(LPDIRECT3DSURFACE8 iface, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect,DWORD Flags) {
118 ICOM_THIS(IDirect3DSurface8Impl,iface);
119 /* fixme: should we really lock as such? */
120 TRACE("(%p) : rect=%p, output prect=%p, allMem=%p\n", This, pRect, pLockedRect, This->allocatedMemory);
122 pLockedRect->Pitch = This->bytesPerPixel * This->myDesc.Width; /* Bytes / row */
124 pLockedRect->pBits = This->allocatedMemory;
126 TRACE("Lock Rect (%p) = l %ld, t %ld, r %ld, b %ld\n", pRect, pRect->left, pRect->top, pRect->right, pRect->bottom);
127 pLockedRect->pBits = This->allocatedMemory + (pLockedRect->Pitch * pRect->top) + (pRect->left * This->bytesPerPixel);
129 TRACE("returning pBits=%p, pitch=%d\n", pLockedRect->pBits, pLockedRect->Pitch);
132 HRESULT WINAPI IDirect3DSurface8Impl_UnlockRect(LPDIRECT3DSURFACE8 iface) {
133 ICOM_THIS(IDirect3DSurface8Impl,iface);
134 TRACE("(%p) : stub\n", This);
135 if (This->Container) {
136 IDirect3DBaseTexture8 *cont = (IDirect3DBaseTexture8*) This->Container;
138 /* Now setup the texture appropraitly */
139 int containerType = IDirect3DBaseTexture8Impl_GetType(cont);
140 if (containerType == D3DRTYPE_TEXTURE) {
141 IDirect3DTexture8Impl *pTexture = (IDirect3DTexture8Impl *)cont;
142 pTexture->Dirty = TRUE;
143 } else if (containerType == D3DRTYPE_CUBETEXTURE) {
144 IDirect3DCubeTexture8Impl *pTexture = (IDirect3DCubeTexture8Impl *)cont;
145 pTexture->Dirty = TRUE;
148 FIXME("Set dirty on container type %d\n", containerType);
155 ICOM_VTABLE(IDirect3DSurface8) Direct3DSurface8_Vtbl =
157 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
158 IDirect3DSurface8Impl_QueryInterface,
159 IDirect3DSurface8Impl_AddRef,
160 IDirect3DSurface8Impl_Release,
161 IDirect3DSurface8Impl_GetDevice,
162 IDirect3DSurface8Impl_SetPrivateData,
163 IDirect3DSurface8Impl_GetPrivateData,
164 IDirect3DSurface8Impl_FreePrivateData,
165 IDirect3DSurface8Impl_GetContainer,
166 IDirect3DSurface8Impl_GetDesc,
167 IDirect3DSurface8Impl_LockRect,
168 IDirect3DSurface8Impl_UnlockRect,