- Defer of IDirect3DVertexShader_SetConstant, waiting for
[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_IDirect3DSurface8)) {
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      */
73     IDirect3DDevice8Impl_AddRef(*ppDevice);
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     HRESULT res;
91     /*
92     TRACE("(%p) : returning %p\n", This, This->Container);
93     *ppContainer = This->Container;
94     return D3D_OK;
95     */
96     res = IUnknown_QueryInterface(This->Container, riid, ppContainer);
97     if (E_NOINTERFACE == res) { 
98       /**
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. 
102        */
103       res = IUnknown_QueryInterface(This->Container, &IID_IDirect3DDevice8, ppContainer);
104     }
105     TRACE("(%p) : returning %p\n", This, *ppContainer);
106     return res;
107 }
108 HRESULT WINAPI IDirect3DSurface8Impl_GetDesc(LPDIRECT3DSURFACE8 iface, D3DSURFACE_DESC *pDesc) {
109     ICOM_THIS(IDirect3DSurface8Impl,iface);
110
111     TRACE("(%p) : copying into %p\n", This, pDesc);
112     memcpy(pDesc, &This->myDesc, sizeof(D3DSURFACE_DESC));
113     return D3D_OK;
114 }
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);
119
120     pLockedRect->Pitch = This->bytesPerPixel * This->myDesc.Width;  /* Bytes / row */
121     if (!pRect) {
122         pLockedRect->pBits = This->allocatedMemory;
123     } else {
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);
126     }
127     TRACE("returning pBits=%p, pitch=%d\n", pLockedRect->pBits, pLockedRect->Pitch);
128     return D3D_OK;
129 }
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;
135
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;
144
145         } else {
146             FIXME("Set dirty on container type %d\n", containerType);
147         }
148     }
149     return D3D_OK;
150 }
151
152
153 ICOM_VTABLE(IDirect3DSurface8) Direct3DSurface8_Vtbl =
154 {
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,
167 };