Use W calls rather than A in CreatePipe.
[wine] / dlls / ddraw / dsurface / 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 #include "windef.h"
34 #include "winbase.h"
35 #include "wingdi.h"
36 #include "ddraw.h"
37 #include "d3d.h"
38
39 #include "wine/debug.h"
40
41 #include "ddcomimpl.h"
42 #include "ddraw_private.h"
43 #include "d3d_private.h"
44 #include "dsurface/main.h"
45 #include "dsurface/fakezbuffer.h"
46
47 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
48
49 static IDirectDrawSurface7Vtbl FakeZBuffer_IDirectDrawSurface7_VTable;
50
51 #ifdef HAVE_OPENGL
52 static void zbuffer_lock_update(IDirectDrawSurfaceImpl* This, LPCRECT pRect, DWORD dwFlags)
53 {
54     /* Note that this does not do anything for now... At least it's not needed for Grim Fandango :-) */
55 }
56
57 static void zbuffer_unlock_update(IDirectDrawSurfaceImpl* This, LPCRECT pRect)
58 {
59     ((FakeZBuffer_DirectDrawSurfaceImpl *) This->private)->in_memory = TRUE;
60 }
61
62 static BOOLEAN zbuffer_get_dirty_status(IDirectDrawSurfaceImpl* This, LPCRECT pRect)
63 {
64     if (((FakeZBuffer_DirectDrawSurfaceImpl *) This->private)->in_memory == TRUE) {
65         ((FakeZBuffer_DirectDrawSurfaceImpl *) This->private)->in_memory = FALSE;
66         return TRUE;
67     }
68     return FALSE;
69 }
70 #endif
71
72 HRESULT FakeZBuffer_DirectDrawSurface_Construct(IDirectDrawSurfaceImpl *This,
73                                                 IDirectDrawImpl *pDD,
74                                                 const DDSURFACEDESC2 *pDDSD)
75 {
76     HRESULT hr;
77     BYTE zdepth = 16; /* Default value.. Should use the one from GL */
78     
79     assert(pDDSD->ddsCaps.dwCaps & DDSCAPS_ZBUFFER);
80
81     hr = Main_DirectDrawSurface_Construct(This, pDD, pDDSD);
82     if (FAILED(hr)) return hr;
83
84     ICOM_INIT_INTERFACE(This, IDirectDrawSurface7,
85                         FakeZBuffer_IDirectDrawSurface7_VTable);
86
87     This->final_release = FakeZBuffer_DirectDrawSurface_final_release;
88     This->duplicate_surface = FakeZBuffer_DirectDrawSurface_duplicate_surface;
89
90 #ifdef HAVE_OPENGL     
91     if (opengl_initialized) {
92         This->lock_update = zbuffer_lock_update;
93         This->unlock_update = zbuffer_unlock_update;
94         This->get_dirty_status = zbuffer_get_dirty_status;
95     }
96 #endif
97         
98     
99     /* Beginning of some D3D hacks :-) */
100     if (This->surface_desc.dwFlags & DDSD_ZBUFFERBITDEPTH) {
101         zdepth = This->surface_desc.u2.dwMipMapCount; /* This is where the Z buffer depth is stored in 'old' versions */
102     }
103     
104     if ((This->surface_desc.dwFlags & DDSD_PIXELFORMAT) == 0) {
105         This->surface_desc.dwFlags |= DDSD_PIXELFORMAT;
106         This->surface_desc.u4.ddpfPixelFormat.dwSize = sizeof(This->surface_desc.u4.ddpfPixelFormat);
107         This->surface_desc.u4.ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
108         This->surface_desc.u4.ddpfPixelFormat.u1.dwZBufferBitDepth = zdepth;
109     }
110     if ((This->surface_desc.dwFlags & DDSD_PITCH) == 0) {
111         This->surface_desc.dwFlags |= DDSD_PITCH;
112         This->surface_desc.u1.lPitch = ((zdepth + 7) / 8) * This->surface_desc.dwWidth;
113     }
114     This->surface_desc.lpSurface = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
115                                              This->surface_desc.u1.lPitch * This->surface_desc.dwHeight);
116     
117     return DD_OK;
118 }
119
120 /* Not an API */
121 HRESULT FakeZBuffer_DirectDrawSurface_Create(IDirectDrawImpl* pDD,
122                                              const DDSURFACEDESC2* pDDSD,
123                                              LPDIRECTDRAWSURFACE7* ppSurf,
124                                              IUnknown* pUnkOuter)
125 {
126     IDirectDrawSurfaceImpl* This;
127     HRESULT hr;
128     assert(pUnkOuter == NULL);
129
130     This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
131                      sizeof(*This)
132                      + sizeof(FakeZBuffer_DirectDrawSurfaceImpl));
133     if (This == NULL) return E_OUTOFMEMORY;
134
135     This->private = (FakeZBuffer_DirectDrawSurfaceImpl*)(This+1);
136
137     hr = FakeZBuffer_DirectDrawSurface_Construct(This, pDD, pDDSD);
138     if (FAILED(hr))
139         HeapFree(GetProcessHeap(), 0, This);
140     else
141         *ppSurf = ICOM_INTERFACE(This, IDirectDrawSurface7);
142
143     return hr;
144 }
145
146 void
147 FakeZBuffer_DirectDrawSurface_final_release(IDirectDrawSurfaceImpl* This)
148 {
149     Main_DirectDrawSurface_final_release(This);
150 }
151
152 HRESULT
153 FakeZBuffer_DirectDrawSurface_duplicate_surface(IDirectDrawSurfaceImpl* This,
154                                                 LPDIRECTDRAWSURFACE7* ppDup)
155 {
156     return FakeZBuffer_DirectDrawSurface_Create(This->ddraw_owner,
157                                                 &This->surface_desc, ppDup,
158                                                 NULL);
159 }
160
161 /* put your breakpoint/abort call here */
162 static HRESULT cant_do_that(const char *s)
163 {
164     FIXME("attempt to %s fake z-buffer\n", s);
165     return DDERR_UNSUPPORTED;
166 }
167
168 HRESULT WINAPI
169 FakeZBuffer_DirectDrawSurface_Blt(LPDIRECTDRAWSURFACE7 iface, LPRECT rdst,
170                                   LPDIRECTDRAWSURFACE7 src, LPRECT rsrc,
171                                   DWORD dwFlags, LPDDBLTFX lpbltfx)
172 {
173     IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
174
175     if (TRACE_ON(ddraw)) {
176         TRACE("(%p)->(%p,%p,%p,%08lx,%p)\n", This,rdst,src,rsrc,dwFlags,lpbltfx);
177         if (rdst) TRACE("\tdestrect :%ldx%ld-%ldx%ld\n",rdst->left,rdst->top,rdst->right,rdst->bottom);
178         if (rsrc) TRACE("\tsrcrect  :%ldx%ld-%ldx%ld\n",rsrc->left,rsrc->top,rsrc->right,rsrc->bottom);
179         TRACE("\tflags: ");
180         DDRAW_dump_DDBLT(dwFlags);
181         if (dwFlags & DDBLT_DDFX) {
182             TRACE("\tblitfx: ");
183             DDRAW_dump_DDBLTFX(lpbltfx->dwDDFX);
184         }
185     }
186
187     /* We only support the BLT with DEPTH_FILL for now */
188     if ((dwFlags & DDBLT_DEPTHFILL) && (This->ddraw_owner->d3d_private != NULL)) {
189         if (This->ddraw_owner->current_device != NULL) {
190             D3DRECT rect;
191             if (rdst) {
192                 rect.u1.x1 = rdst->left;
193                 rect.u2.y1 = rdst->top;
194                 rect.u3.x2 = rdst->right;
195                 rect.u4.y2 = rdst->bottom;
196             }
197             This->ddraw_owner->current_device->clear(This->ddraw_owner->current_device,
198                                                      (rdst == NULL ? 0 : 1), &rect,
199                                                      D3DCLEAR_ZBUFFER,
200                                                      0x00000000,
201                                                      ((double) lpbltfx->u5.dwFillDepth) / 4294967295.0,
202                                                      0x00000000);
203             return DD_OK;
204         }
205     }
206
207     return cant_do_that("blt to a");
208 }
209
210 HRESULT WINAPI
211 FakeZBuffer_DirectDrawSurface_BltFast(LPDIRECTDRAWSURFACE7 iface, DWORD dstx,
212                                       DWORD dsty, LPDIRECTDRAWSURFACE7 src,
213                                       LPRECT rsrc, DWORD trans)
214 {
215     IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
216
217     if (TRACE_ON(ddraw)) {
218         FIXME("(%p)->(%ld,%ld,%p,%p,%08lx)\n",
219                 This,dstx,dsty,src,rsrc,trans
220         );
221         FIXME("\ttrans:");
222         if (FIXME_ON(ddraw))
223           DDRAW_dump_DDBLTFAST(trans);
224         if (rsrc)
225           FIXME("\tsrcrect: %ldx%ld-%ldx%ld\n",rsrc->left,rsrc->top,rsrc->right,rsrc->bottom);
226         else
227           FIXME(" srcrect: NULL\n");
228     }
229
230     return cant_do_that("bltfast to a");
231 }
232
233 HRESULT WINAPI
234 FakeZBuffer_DirectDrawSurface_GetDC(LPDIRECTDRAWSURFACE7 iface, HDC *phDC)
235 {
236     return cant_do_that("get a DC for a");
237 }
238
239 HRESULT WINAPI
240 FakeZBuffer_DirectDrawSurface_ReleaseDC(LPDIRECTDRAWSURFACE7 iface, HDC hDC)
241 {
242     return cant_do_that("release a DC for a");
243 }
244
245 HRESULT WINAPI
246 FakeZBuffer_DirectDrawSurface_Restore(LPDIRECTDRAWSURFACE7 iface)
247 {
248     return DD_OK;
249 }
250
251 HRESULT WINAPI
252 FakeZBuffer_DirectDrawSurface_SetSurfaceDesc(LPDIRECTDRAWSURFACE7 iface,
253                                              LPDDSURFACEDESC2 pDDSD,
254                                              DWORD dwFlags)
255 {
256     /* XXX */
257     abort();
258     return E_FAIL;
259 }
260
261
262 static IDirectDrawSurface7Vtbl FakeZBuffer_IDirectDrawSurface7_VTable=
263 {
264     Main_DirectDrawSurface_QueryInterface,
265     Main_DirectDrawSurface_AddRef,
266     Main_DirectDrawSurface_Release,
267     Main_DirectDrawSurface_AddAttachedSurface,
268     Main_DirectDrawSurface_AddOverlayDirtyRect,
269     FakeZBuffer_DirectDrawSurface_Blt,
270     Main_DirectDrawSurface_BltBatch,
271     FakeZBuffer_DirectDrawSurface_BltFast,
272     Main_DirectDrawSurface_DeleteAttachedSurface,
273     Main_DirectDrawSurface_EnumAttachedSurfaces,
274     Main_DirectDrawSurface_EnumOverlayZOrders,
275     Main_DirectDrawSurface_Flip,
276     Main_DirectDrawSurface_GetAttachedSurface,
277     Main_DirectDrawSurface_GetBltStatus,
278     Main_DirectDrawSurface_GetCaps,
279     Main_DirectDrawSurface_GetClipper,
280     Main_DirectDrawSurface_GetColorKey,
281     FakeZBuffer_DirectDrawSurface_GetDC,
282     Main_DirectDrawSurface_GetFlipStatus,
283     Main_DirectDrawSurface_GetOverlayPosition,
284     Main_DirectDrawSurface_GetPalette,
285     Main_DirectDrawSurface_GetPixelFormat,
286     Main_DirectDrawSurface_GetSurfaceDesc,
287     Main_DirectDrawSurface_Initialize,
288     Main_DirectDrawSurface_IsLost,
289     Main_DirectDrawSurface_Lock,
290     FakeZBuffer_DirectDrawSurface_ReleaseDC,
291     FakeZBuffer_DirectDrawSurface_Restore,
292     Main_DirectDrawSurface_SetClipper,
293     Main_DirectDrawSurface_SetColorKey,
294     Main_DirectDrawSurface_SetOverlayPosition,
295     Main_DirectDrawSurface_SetPalette,
296     Main_DirectDrawSurface_Unlock,
297     Main_DirectDrawSurface_UpdateOverlay,
298     Main_DirectDrawSurface_UpdateOverlayDisplay,
299     Main_DirectDrawSurface_UpdateOverlayZOrder,
300     Main_DirectDrawSurface_GetDDInterface,
301     Main_DirectDrawSurface_PageLock,
302     Main_DirectDrawSurface_PageUnlock,
303     FakeZBuffer_DirectDrawSurface_SetSurfaceDesc,
304     Main_DirectDrawSurface_SetPrivateData,
305     Main_DirectDrawSurface_GetPrivateData,
306     Main_DirectDrawSurface_FreePrivateData,
307     Main_DirectDrawSurface_GetUniquenessValue,
308     Main_DirectDrawSurface_ChangeUniquenessValue,
309     Main_DirectDrawSurface_SetPriority,
310     Main_DirectDrawSurface_GetPriority,
311     Main_DirectDrawSurface_SetLOD,
312     Main_DirectDrawSurface_GetLOD
313 };