Various fixes, typos corrected and clarifying trace points.
[wine] / dlls / d3d8 / surface.c
1 /*
2  * IDirect3DSurface8 implementation
3  *
4  * Copyright 2002 Jason Edmeades
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "windef.h"
22 #include "winbase.h"
23 #include "winuser.h"
24 #include "wingdi.h"
25 #include "wine/debug.h"
26
27 #include "d3d8_private.h"
28
29 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
30
31 /* IDirect3DVolume IUnknown parts follow: */
32 HRESULT WINAPI IDirect3DSurface8Impl_QueryInterface(LPDIRECT3DSURFACE8 iface,REFIID riid,LPVOID *ppobj)
33 {
34     ICOM_THIS(IDirect3DSurface8Impl,iface);
35
36     if (IsEqualGUID(riid, &IID_IUnknown)
37         || IsEqualGUID(riid, &IID_IClassFactory)) {
38         IDirect3DSurface8Impl_AddRef(iface);
39         *ppobj = This;
40         return D3D_OK;
41     }
42
43     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
44     return E_NOINTERFACE;
45 }
46
47 ULONG WINAPI IDirect3DSurface8Impl_AddRef(LPDIRECT3DSURFACE8 iface) {
48     ICOM_THIS(IDirect3DSurface8Impl,iface);
49     TRACE("(%p) : AddRef from %ld\n", This, This->ref);
50     return ++(This->ref);
51 }
52
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);
57     if (ref == 0) {
58         HeapFree(GetProcessHeap(), 0, This->allocatedMemory);
59         HeapFree(GetProcessHeap(), 0, This);
60     }
61     return ref;
62 }
63
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;
69
70     /* Note  Calling this method will increase the internal reference count 
71        on the IDirect3DDevice8 interface. */
72     IDirect3DDevice8Impl_AddRef(*ppDevice);
73
74     return D3D_OK;
75 }
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;
79 }
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;
83 }
84 HRESULT WINAPI IDirect3DSurface8Impl_FreePrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid) {
85     ICOM_THIS(IDirect3DSurface8Impl,iface);
86     FIXME("(%p) : stub\n", This);    return D3D_OK;
87 }
88 HRESULT WINAPI IDirect3DSurface8Impl_GetContainer(LPDIRECT3DSURFACE8 iface, REFIID riid,void** ppContainer) {
89     ICOM_THIS(IDirect3DSurface8Impl,iface);
90
91     /* If the surface is created using CreateImageSurface, CreateRenderTarget, 
92         or CreateDepthStencilSurface, the surface is considered stand alone. In this case, 
93         GetContainer will return the Direct3D device used to create the surface. */
94     TRACE("(%p) : returning %p\n", This, This->Container);
95     *ppContainer = This->Container;
96     return D3D_OK;
97 }
98 HRESULT WINAPI IDirect3DSurface8Impl_GetDesc(LPDIRECT3DSURFACE8 iface, D3DSURFACE_DESC *pDesc) {
99     ICOM_THIS(IDirect3DSurface8Impl,iface);
100
101     TRACE("(%p) : copying into %p\n", This, pDesc);
102     memcpy(pDesc, &This->myDesc, sizeof(D3DSURFACE_DESC));
103     return D3D_OK;
104 }
105 HRESULT WINAPI IDirect3DSurface8Impl_LockRect(LPDIRECT3DSURFACE8 iface, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect,DWORD Flags) {
106     ICOM_THIS(IDirect3DSurface8Impl,iface);
107     /* fixme: should we really lock as such? */
108     TRACE("(%p) : rect=%p, output prect=%p, allMem=%p\n", This, pRect, pLockedRect, This->allocatedMemory);
109
110     pLockedRect->Pitch = This->bytesPerPixel * This->myDesc.Width;  /* Bytes / row */
111     if (!pRect) {
112         pLockedRect->pBits = This->allocatedMemory;
113     } else {
114         TRACE("Lock Rect (%p) = l %d, t %d, r %d, b %d\n", pRect, pRect->left, pRect->top, pRect->right, pRect->bottom);
115         pLockedRect->pBits = This->allocatedMemory + (pLockedRect->Pitch * pRect->top) + (pRect->left * This->bytesPerPixel);
116     }
117     TRACE("returning pBits=%p, pitch=%d\n", pLockedRect->pBits, pLockedRect->Pitch);
118     return D3D_OK;
119 }
120 HRESULT WINAPI IDirect3DSurface8Impl_UnlockRect(LPDIRECT3DSURFACE8 iface) {
121     ICOM_THIS(IDirect3DSurface8Impl,iface);
122     TRACE("(%p) : stub\n", This);
123     if (This->Container) {
124         IDirect3DBaseTexture8 *cont = This->Container;
125
126         /* Now setup the texture appropraitly */
127         int containerType = IDirect3DBaseTexture8Impl_GetType(cont);
128         if (containerType == D3DRTYPE_TEXTURE) {
129             IDirect3DTexture8Impl *pTexture = (IDirect3DTexture8Impl *)cont;
130             pTexture->Dirty = TRUE;
131         } else if (containerType == D3DRTYPE_CUBETEXTURE) {
132             IDirect3DCubeTexture8Impl *pTexture = (IDirect3DCubeTexture8Impl *)cont;
133             pTexture->Dirty = TRUE;
134
135         } else {
136             FIXME("Set dirty on container type %d\n", containerType);
137         }
138     }
139     return D3D_OK;
140 }
141
142
143 ICOM_VTABLE(IDirect3DSurface8) Direct3DSurface8_Vtbl =
144 {
145     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
146     IDirect3DSurface8Impl_QueryInterface,
147     IDirect3DSurface8Impl_AddRef,
148     IDirect3DSurface8Impl_Release,
149     IDirect3DSurface8Impl_GetDevice,
150     IDirect3DSurface8Impl_SetPrivateData,
151     IDirect3DSurface8Impl_GetPrivateData,
152     IDirect3DSurface8Impl_FreePrivateData,
153     IDirect3DSurface8Impl_GetContainer,
154     IDirect3DSurface8Impl_GetDesc,
155     IDirect3DSurface8Impl_LockRect,
156     IDirect3DSurface8Impl_UnlockRect,
157 };