Fixed lvalue casts.
[wine] / dlls / d3d9 / surface.c
1 /*
2  * IDirect3DSurface9 implementation
3  *
4  * Copyright 2002-2003 Jason Edmeades
5  *                     Raphael Junqueira
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include "config.h"
23
24 #include <stdarg.h>
25 #include <stdio.h>
26
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winuser.h"
32 #include "wingdi.h"
33 #include "wine/debug.h"
34
35 #include "d3d9_private.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(d3d_surface);
38
39 /* IDirect3DSurface9 IUnknown parts follow: */
40 HRESULT WINAPI IDirect3DSurface9Impl_QueryInterface(LPDIRECT3DSURFACE9 iface, REFIID riid, LPVOID* ppobj) {
41     ICOM_THIS(IDirect3DSurface9Impl,iface);
42
43     if (IsEqualGUID(riid, &IID_IUnknown)
44         || IsEqualGUID(riid, &IID_IDirect3DResource9)
45         || IsEqualGUID(riid, &IID_IDirect3DSurface9)) {
46         IDirect3DSurface9Impl_AddRef(iface);
47         *ppobj = This;
48         return D3D_OK;
49     }
50
51     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
52     return E_NOINTERFACE;
53 }
54
55 ULONG WINAPI IDirect3DSurface9Impl_AddRef(LPDIRECT3DSURFACE9 iface) {
56     ICOM_THIS(IDirect3DSurface9Impl,iface);
57     TRACE("(%p) : AddRef from %ld\n", This, This->ref);
58     return ++(This->ref);
59 }
60
61 ULONG WINAPI IDirect3DSurface9Impl_Release(LPDIRECT3DSURFACE9 iface) {
62     ICOM_THIS(IDirect3DSurface9Impl,iface);
63     ULONG ref = --This->ref;
64     TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
65     if (ref == 0) {
66       HeapFree(GetProcessHeap(), 0, This->allocatedMemory);
67       HeapFree(GetProcessHeap(), 0, This);
68     }
69     return ref;
70 }
71
72 /* IDirect3DSurface9 IDirect3DResource9 Interface follow: */
73 HRESULT WINAPI IDirect3DSurface9Impl_GetDevice(LPDIRECT3DSURFACE9 iface, IDirect3DDevice9** ppDevice) {
74     ICOM_THIS(IDirect3DSurface9Impl,iface);
75     return IDirect3DResource9Impl_GetDevice((LPDIRECT3DRESOURCE9) This, ppDevice);
76 }
77
78 HRESULT WINAPI IDirect3DSurface9Impl_SetPrivateData(LPDIRECT3DSURFACE9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
79     ICOM_THIS(IDirect3DSurface9Impl,iface);
80     FIXME("(%p) : stub\n", This);    
81     return D3D_OK;
82 }
83
84 HRESULT WINAPI IDirect3DSurface9Impl_GetPrivateData(LPDIRECT3DSURFACE9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
85     ICOM_THIS(IDirect3DSurface9Impl,iface);
86     FIXME("(%p) : stub\n", This);    
87     return D3D_OK;
88 }
89
90 HRESULT WINAPI IDirect3DSurface9Impl_FreePrivateData(LPDIRECT3DSURFACE9 iface, REFGUID refguid) {
91     ICOM_THIS(IDirect3DSurface9Impl,iface);
92     FIXME("(%p) : stub\n", This);    
93     return D3D_OK;
94 }
95
96 DWORD   WINAPI IDirect3DSurface9Impl_SetPriority(LPDIRECT3DSURFACE9 iface, DWORD PriorityNew) {
97     ICOM_THIS(IDirect3DSurface9Impl,iface);
98     return IDirect3DResource9Impl_SetPriority((LPDIRECT3DRESOURCE9) This, PriorityNew);
99 }
100
101 DWORD   WINAPI IDirect3DSurface9Impl_GetPriority(LPDIRECT3DSURFACE9 iface) {
102     ICOM_THIS(IDirect3DSurface9Impl,iface);
103     return IDirect3DResource9Impl_GetPriority((LPDIRECT3DRESOURCE9) This);
104 }
105
106 void    WINAPI IDirect3DSurface9Impl_PreLoad(LPDIRECT3DSURFACE9 iface) {
107     ICOM_THIS(IDirect3DSurface9Impl,iface);
108     FIXME("(%p) : stub\n", This);    
109     return ;
110 }
111
112 D3DRESOURCETYPE WINAPI IDirect3DSurface9Impl_GetType(LPDIRECT3DSURFACE9 iface) {
113     ICOM_THIS(IDirect3DSurface9Impl,iface);
114     return IDirect3DResource9Impl_GetType((LPDIRECT3DRESOURCE9) This);
115 }
116
117 /* IDirect3DSurface9 Interface follow: */
118 HRESULT WINAPI IDirect3DSurface9Impl_GetContainer(LPDIRECT3DSURFACE9 iface, REFIID riid, void** ppContainer) {
119     ICOM_THIS(IDirect3DSurface9Impl,iface);
120     HRESULT res;
121     res = IUnknown_QueryInterface(This->Container, riid, ppContainer);
122     if (E_NOINTERFACE == res) { 
123       /**
124        * If the surface is created using CreateImageSurface, CreateRenderTarget, 
125        * or CreateDepthStencilSurface, the surface is considered stand alone. In this case, 
126        * GetContainer will return the Direct3D device used to create the surface. 
127        */
128       res = IUnknown_QueryInterface(This->Container, &IID_IDirect3DDevice9, ppContainer);
129     }
130     TRACE("(%p) : returning %p\n", This, *ppContainer);
131     return res;
132 }
133
134 HRESULT WINAPI IDirect3DSurface9Impl_GetDesc(LPDIRECT3DSURFACE9 iface, D3DSURFACE_DESC* pDesc) {
135     ICOM_THIS(IDirect3DSurface9Impl,iface);
136     TRACE("(%p) : copying into %p\n", This, pDesc);
137     memcpy(pDesc, &This->myDesc, sizeof(D3DSURFACE_DESC));
138     return D3D_OK;
139 }
140
141 HRESULT WINAPI IDirect3DSurface9Impl_LockRect(LPDIRECT3DSURFACE9 iface, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
142     ICOM_THIS(IDirect3DSurface9Impl,iface);
143     FIXME("(%p) : stub\n", This);
144     return D3D_OK;
145 }
146
147 HRESULT WINAPI IDirect3DSurface9Impl_UnlockRect(LPDIRECT3DSURFACE9 iface) {
148     ICOM_THIS(IDirect3DSurface9Impl,iface);
149     FIXME("(%p) : stub\n", This);
150     return D3D_OK;
151 }
152
153 HRESULT WINAPI IDirect3DSurface9Impl_GetDC(LPDIRECT3DSURFACE9 iface, HDC* phdc) {
154     ICOM_THIS(IDirect3DSurface9Impl,iface);
155     FIXME("(%p) : stub\n", This);
156     return D3D_OK;
157 }
158
159 HRESULT WINAPI IDirect3DSurface9Impl_ReleaseDC(LPDIRECT3DSURFACE9 iface, HDC hdc) {
160     ICOM_THIS(IDirect3DSurface9Impl,iface);
161     FIXME("(%p) : stub\n", This);
162     return D3D_OK;
163 }
164
165
166 ICOM_VTABLE(IDirect3DSurface9) Direct3DSurface9_Vtbl =
167 {
168     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
169     IDirect3DSurface9Impl_QueryInterface,
170     IDirect3DSurface9Impl_AddRef,
171     IDirect3DSurface9Impl_Release,
172     IDirect3DSurface9Impl_GetDevice,
173     IDirect3DSurface9Impl_SetPrivateData,
174     IDirect3DSurface9Impl_GetPrivateData,
175     IDirect3DSurface9Impl_FreePrivateData,
176     IDirect3DSurface9Impl_SetPriority,
177     IDirect3DSurface9Impl_GetPriority,
178     IDirect3DSurface9Impl_PreLoad,
179     IDirect3DSurface9Impl_GetType,
180     IDirect3DSurface9Impl_GetContainer,
181     IDirect3DSurface9Impl_GetDesc,
182     IDirect3DSurface9Impl_LockRect,
183     IDirect3DSurface9Impl_UnlockRect,
184     IDirect3DSurface9Impl_GetDC,
185     IDirect3DSurface9Impl_ReleaseDC
186 };