Use shell icon cache instead of an own IExtractIcon implementation.
[wine] / dlls / ddraw / surface_fakezbuffer.c
1 /*              DirectDraw/Direct3D Z-Buffer stand in
2  *
3  * Copyright 2000 TransGaming Technologies Inc.
4  *
5  * This class provides a DirectDrawSurface implementation that represents
6  * a Z-Buffer surface. However it does not store an image and does not
7  * support Lock/Unlock or GetDC. It is merely a placeholder required by the
8  * Direct3D architecture.
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23  */
24
25 #include "config.h"
26
27 #include <stdarg.h>
28 #include <stdlib.h>
29 #include <assert.h>
30
31 #define NONAMELESSUNION
32 #define NONAMELESSSTRUCT
33
34 #define CONST_VTABLE
35
36 #include "windef.h"
37 #include "winbase.h"
38 #include "wingdi.h"
39 #include "ddraw.h"
40 #include "d3d.h"
41
42 #include "wine/debug.h"
43
44 #include "ddcomimpl.h"
45 #include "ddraw_private.h"
46 #include "d3d_private.h"
47
48 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
49
50 static const IDirectDrawSurface7Vtbl FakeZBuffer_IDirectDrawSurface7_VTable;
51
52 #ifdef HAVE_OPENGL
53 static void zbuffer_lock_update(IDirectDrawSurfaceImpl* This, LPCRECT pRect, DWORD dwFlags)
54 {
55     /* Note that this does not do anything for now... At least it's not needed for Grim Fandango :-) */
56 }
57
58 static void zbuffer_unlock_update(IDirectDrawSurfaceImpl* This, LPCRECT pRect)
59 {
60     ((FakeZBuffer_DirectDrawSurfaceImpl *) This->private)->in_memory = TRUE;
61 }
62
63 static BOOLEAN zbuffer_get_dirty_status(IDirectDrawSurfaceImpl* This, LPCRECT pRect)
64 {
65     if (((FakeZBuffer_DirectDrawSurfaceImpl *) This->private)->in_memory) {
66         ((FakeZBuffer_DirectDrawSurfaceImpl *) This->private)->in_memory = FALSE;
67         return TRUE;
68     }
69     return FALSE;
70 }
71 #endif
72
73 HRESULT FakeZBuffer_DirectDrawSurface_Construct(IDirectDrawSurfaceImpl *This,
74                                                 IDirectDrawImpl *pDD,
75                                                 const DDSURFACEDESC2 *pDDSD)
76 {
77     HRESULT hr;
78     BYTE zdepth = 16; /* Default value.. Should use the one from GL */
79     
80     assert(pDDSD->ddsCaps.dwCaps & DDSCAPS_ZBUFFER);
81
82     hr = Main_DirectDrawSurface_Construct(This, pDD, pDDSD);
83     if (FAILED(hr)) return hr;
84
85     ICOM_INIT_INTERFACE(This, IDirectDrawSurface7,
86                         FakeZBuffer_IDirectDrawSurface7_VTable);
87
88     This->final_release = FakeZBuffer_DirectDrawSurface_final_release;
89     This->duplicate_surface = FakeZBuffer_DirectDrawSurface_duplicate_surface;
90
91 #ifdef HAVE_OPENGL     
92     if (opengl_initialized) {
93         This->lock_update = zbuffer_lock_update;
94         This->unlock_update = zbuffer_unlock_update;
95         This->get_dirty_status = zbuffer_get_dirty_status;
96     }
97 #endif
98         
99     
100     /* Beginning of some D3D hacks :-) */
101     if (This->surface_desc.dwFlags & DDSD_ZBUFFERBITDEPTH) {
102         zdepth = This->surface_desc.u2.dwMipMapCount; /* This is where the Z buffer depth is stored in 'old' versions */
103     }
104     
105     if ((This->surface_desc.dwFlags & DDSD_PIXELFORMAT) == 0) {
106         This->surface_desc.dwFlags |= DDSD_PIXELFORMAT;
107         This->surface_desc.u4.ddpfPixelFormat.dwSize = sizeof(This->surface_desc.u4.ddpfPixelFormat);
108         This->surface_desc.u4.ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
109         This->surface_desc.u4.ddpfPixelFormat.u1.dwZBufferBitDepth = zdepth;
110     }
111     if ((This->surface_desc.dwFlags & DDSD_PITCH) == 0) {
112         This->surface_desc.dwFlags |= DDSD_PITCH;
113         This->surface_desc.u1.lPitch = ((zdepth + 7) / 8) * This->surface_desc.dwWidth;
114     }
115     This->surface_desc.lpSurface = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
116                                              This->surface_desc.u1.lPitch * This->surface_desc.dwHeight);
117     
118     return DD_OK;
119 }
120
121 /* Not an API */
122 HRESULT FakeZBuffer_DirectDrawSurface_Create(IDirectDrawImpl* pDD,
123                                              const DDSURFACEDESC2* pDDSD,
124                                              LPDIRECTDRAWSURFACE7* ppSurf,
125                                              IUnknown* pUnkOuter)
126 {
127     IDirectDrawSurfaceImpl* This;
128     HRESULT hr;
129     assert(pUnkOuter == NULL);
130
131     This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
132                      sizeof(*This)
133                      + sizeof(FakeZBuffer_DirectDrawSurfaceImpl));
134     if (This == NULL) return E_OUTOFMEMORY;
135
136     This->private = (FakeZBuffer_DirectDrawSurfaceImpl*)(This+1);
137
138     hr = FakeZBuffer_DirectDrawSurface_Construct(This, pDD, pDDSD);
139     if (FAILED(hr))
140         HeapFree(GetProcessHeap(), 0, This);
141     else
142         *ppSurf = ICOM_INTERFACE(This, IDirectDrawSurface7);
143
144     return hr;
145 }
146
147 void
148 FakeZBuffer_DirectDrawSurface_final_release(IDirectDrawSurfaceImpl* This)
149 {
150     Main_DirectDrawSurface_final_release(This);
151 }
152
153 HRESULT
154 FakeZBuffer_DirectDrawSurface_duplicate_surface(IDirectDrawSurfaceImpl* This,
155                                                 LPDIRECTDRAWSURFACE7* ppDup)
156 {
157     return FakeZBuffer_DirectDrawSurface_Create(This->ddraw_owner,
158                                                 &This->surface_desc, ppDup,
159                                                 NULL);
160 }
161
162 /* put your breakpoint/abort call here */
163 static HRESULT cant_do_that(const char *s)
164 {
165     FIXME("attempt to %s fake z-buffer\n", s);
166     return DDERR_UNSUPPORTED;
167 }
168
169 HRESULT WINAPI
170 FakeZBuffer_DirectDrawSurface_Blt(LPDIRECTDRAWSURFACE7 iface, LPRECT rdst,
171                                   LPDIRECTDRAWSURFACE7 src, LPRECT rsrc,
172                                   DWORD dwFlags, LPDDBLTFX lpbltfx)
173 {
174     IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
175
176     if (TRACE_ON(ddraw)) {
177         TRACE("(%p)->(%p,%p,%p,%08lx,%p)\n", This,rdst,src,rsrc,dwFlags,lpbltfx);
178         if (rdst) TRACE("\tdestrect :%ldx%ld-%ldx%ld\n",rdst->left,rdst->top,rdst->right,rdst->bottom);
179         if (rsrc) TRACE("\tsrcrect  :%ldx%ld-%ldx%ld\n",rsrc->left,rsrc->top,rsrc->right,rsrc->bottom);
180         TRACE("\tflags: ");
181         DDRAW_dump_DDBLT(dwFlags);
182         if (dwFlags & DDBLT_DDFX) {
183             TRACE("\tblitfx: ");
184             DDRAW_dump_DDBLTFX(lpbltfx->dwDDFX);
185         }
186     }
187
188     /* We only support the BLT with DEPTH_FILL for now */
189     if ((dwFlags & DDBLT_DEPTHFILL) && (This->ddraw_owner->d3d_private != NULL)) {
190         if (This->ddraw_owner->current_device != NULL) {
191             D3DRECT rect;
192             if (rdst) {
193                 rect.u1.x1 = rdst->left;
194                 rect.u2.y1 = rdst->top;
195                 rect.u3.x2 = rdst->right;
196                 rect.u4.y2 = rdst->bottom;
197             }
198             This->ddraw_owner->current_device->clear(This->ddraw_owner->current_device,
199                                                      (rdst == NULL ? 0 : 1), &rect,
200                                                      D3DCLEAR_ZBUFFER,
201                                                      0x00000000,
202                                                      ((double) lpbltfx->u5.dwFillDepth) / 4294967295.0,
203                                                      0x00000000);
204             return DD_OK;
205         }
206     }
207
208     return cant_do_that("blt to a");
209 }
210
211 HRESULT WINAPI
212 FakeZBuffer_DirectDrawSurface_BltFast(LPDIRECTDRAWSURFACE7 iface, DWORD dstx,
213                                       DWORD dsty, LPDIRECTDRAWSURFACE7 src,
214                                       LPRECT rsrc, DWORD trans)
215 {
216     IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
217
218     if (TRACE_ON(ddraw)) {
219         FIXME("(%p)->(%ld,%ld,%p,%p,%08lx)\n",
220                 This,dstx,dsty,src,rsrc,trans
221         );
222         FIXME("\ttrans:");
223         if (FIXME_ON(ddraw))
224           DDRAW_dump_DDBLTFAST(trans);
225         if (rsrc)
226           FIXME("\tsrcrect: %ldx%ld-%ldx%ld\n",rsrc->left,rsrc->top,rsrc->right,rsrc->bottom);
227         else
228           FIXME(" srcrect: NULL\n");
229     }
230
231     return cant_do_that("bltfast to a");
232 }
233
234 HRESULT WINAPI
235 FakeZBuffer_DirectDrawSurface_GetDC(LPDIRECTDRAWSURFACE7 iface, HDC *phDC)
236 {
237     return cant_do_that("get a DC for a");
238 }
239
240 HRESULT WINAPI
241 FakeZBuffer_DirectDrawSurface_ReleaseDC(LPDIRECTDRAWSURFACE7 iface, HDC hDC)
242 {
243     return cant_do_that("release a DC for a");
244 }
245
246 HRESULT WINAPI
247 FakeZBuffer_DirectDrawSurface_Restore(LPDIRECTDRAWSURFACE7 iface)
248 {
249     return DD_OK;
250 }
251
252 HRESULT WINAPI
253 FakeZBuffer_DirectDrawSurface_SetSurfaceDesc(LPDIRECTDRAWSURFACE7 iface,
254                                              LPDDSURFACEDESC2 pDDSD,
255                                              DWORD dwFlags)
256 {
257     /* XXX */
258     abort();
259     return E_FAIL;
260 }
261
262
263 static const IDirectDrawSurface7Vtbl FakeZBuffer_IDirectDrawSurface7_VTable=
264 {
265     Main_DirectDrawSurface_QueryInterface,
266     Main_DirectDrawSurface_AddRef,
267     Main_DirectDrawSurface_Release,
268     Main_DirectDrawSurface_AddAttachedSurface,
269     Main_DirectDrawSurface_AddOverlayDirtyRect,
270     FakeZBuffer_DirectDrawSurface_Blt,
271     Main_DirectDrawSurface_BltBatch,
272     FakeZBuffer_DirectDrawSurface_BltFast,
273     Main_DirectDrawSurface_DeleteAttachedSurface,
274     Main_DirectDrawSurface_EnumAttachedSurfaces,
275     Main_DirectDrawSurface_EnumOverlayZOrders,
276     Main_DirectDrawSurface_Flip,
277     Main_DirectDrawSurface_GetAttachedSurface,
278     Main_DirectDrawSurface_GetBltStatus,
279     Main_DirectDrawSurface_GetCaps,
280     Main_DirectDrawSurface_GetClipper,
281     Main_DirectDrawSurface_GetColorKey,
282     FakeZBuffer_DirectDrawSurface_GetDC,
283     Main_DirectDrawSurface_GetFlipStatus,
284     Main_DirectDrawSurface_GetOverlayPosition,
285     Main_DirectDrawSurface_GetPalette,
286     Main_DirectDrawSurface_GetPixelFormat,
287     Main_DirectDrawSurface_GetSurfaceDesc,
288     Main_DirectDrawSurface_Initialize,
289     Main_DirectDrawSurface_IsLost,
290     Main_DirectDrawSurface_Lock,
291     FakeZBuffer_DirectDrawSurface_ReleaseDC,
292     FakeZBuffer_DirectDrawSurface_Restore,
293     Main_DirectDrawSurface_SetClipper,
294     Main_DirectDrawSurface_SetColorKey,
295     Main_DirectDrawSurface_SetOverlayPosition,
296     Main_DirectDrawSurface_SetPalette,
297     Main_DirectDrawSurface_Unlock,
298     Main_DirectDrawSurface_UpdateOverlay,
299     Main_DirectDrawSurface_UpdateOverlayDisplay,
300     Main_DirectDrawSurface_UpdateOverlayZOrder,
301     Main_DirectDrawSurface_GetDDInterface,
302     Main_DirectDrawSurface_PageLock,
303     Main_DirectDrawSurface_PageUnlock,
304     FakeZBuffer_DirectDrawSurface_SetSurfaceDesc,
305     Main_DirectDrawSurface_SetPrivateData,
306     Main_DirectDrawSurface_GetPrivateData,
307     Main_DirectDrawSurface_FreePrivateData,
308     Main_DirectDrawSurface_GetUniquenessValue,
309     Main_DirectDrawSurface_ChangeUniquenessValue,
310     Main_DirectDrawSurface_SetPriority,
311     Main_DirectDrawSurface_GetPriority,
312     Main_DirectDrawSurface_SetLOD,
313     Main_DirectDrawSurface_GetLOD
314 };