- added some tracing in the fake ZBuffer methods
[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 <stdlib.h>
28 #include <assert.h>
29
30 #include "ddraw.h"
31 #include "d3d.h"
32
33 #include "wine/debug.h"
34
35 #include "ddcomimpl.h"
36 #include "ddraw_private.h"
37 #include "d3d_private.h"
38 #include "dsurface/main.h"
39 #include "dsurface/fakezbuffer.h"
40
41 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
42
43 static ICOM_VTABLE(IDirectDrawSurface7) FakeZBuffer_IDirectDrawSurface7_VTable;
44
45 HRESULT FakeZBuffer_DirectDrawSurface_Construct(IDirectDrawSurfaceImpl *This,
46                                                 IDirectDrawImpl *pDD,
47                                                 const DDSURFACEDESC2 *pDDSD)
48 {
49     HRESULT hr;
50
51     assert(pDDSD->ddsCaps.dwCaps & DDSCAPS_ZBUFFER);
52
53     hr = Main_DirectDrawSurface_Construct(This, pDD, pDDSD);
54     if (FAILED(hr)) return hr;
55
56     ICOM_INIT_INTERFACE(This, IDirectDrawSurface7,
57                         FakeZBuffer_IDirectDrawSurface7_VTable);
58
59     This->final_release = FakeZBuffer_DirectDrawSurface_final_release;
60     This->duplicate_surface = FakeZBuffer_DirectDrawSurface_duplicate_surface;
61
62     return DD_OK;
63 }
64
65 /* Not an API */
66 HRESULT FakeZBuffer_DirectDrawSurface_Create(IDirectDrawImpl* pDD,
67                                              const DDSURFACEDESC2* pDDSD,
68                                              LPDIRECTDRAWSURFACE7* ppSurf,
69                                              IUnknown* pUnkOuter)
70 {
71     IDirectDrawSurfaceImpl* This;
72     HRESULT hr;
73     assert(pUnkOuter == NULL);
74
75     This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
76                      sizeof(*This)
77                      + sizeof(FakeZBuffer_DirectDrawSurfaceImpl));
78     if (This == NULL) return E_OUTOFMEMORY;
79
80     This->private = (FakeZBuffer_DirectDrawSurfaceImpl*)(This+1);
81
82     hr = FakeZBuffer_DirectDrawSurface_Construct(This, pDD, pDDSD);
83     if (FAILED(hr))
84         HeapFree(GetProcessHeap(), 0, This);
85     else
86         *ppSurf = ICOM_INTERFACE(This, IDirectDrawSurface7);
87
88     return hr;
89 }
90
91 void
92 FakeZBuffer_DirectDrawSurface_final_release(IDirectDrawSurfaceImpl* This)
93 {
94     Main_DirectDrawSurface_final_release(This);
95 }
96
97 HRESULT
98 FakeZBuffer_DirectDrawSurface_duplicate_surface(IDirectDrawSurfaceImpl* This,
99                                                 LPDIRECTDRAWSURFACE7* ppDup)
100 {
101     return FakeZBuffer_DirectDrawSurface_Create(This->ddraw_owner,
102                                                 &This->surface_desc, ppDup,
103                                                 NULL);
104 }
105
106 /* put your breakpoint/abort call here */
107 static HRESULT cant_do_that(const char *s)
108 {
109     FIXME("attempt to %s fake z-buffer\n", s);
110     return DDERR_UNSUPPORTED;
111 }
112
113 HRESULT WINAPI
114 FakeZBuffer_DirectDrawSurface_Blt(LPDIRECTDRAWSURFACE7 iface, LPRECT rdst,
115                                   LPDIRECTDRAWSURFACE7 src, LPRECT rsrc,
116                                   DWORD dwFlags, LPDDBLTFX lpbltfx)
117 {
118     ICOM_THIS(IDirectDrawSurfaceImpl,iface);
119
120     if (TRACE_ON(ddraw)) {
121         TRACE("(%p)->(%p,%p,%p,%08lx,%p)\n", This,rdst,src,rsrc,dwFlags,lpbltfx);
122         if (rdst) TRACE("\tdestrect :%dx%d-%dx%d\n",rdst->left,rdst->top,rdst->right,rdst->bottom);
123         if (rsrc) TRACE("\tsrcrect  :%dx%d-%dx%d\n",rsrc->left,rsrc->top,rsrc->right,rsrc->bottom);
124         TRACE("\tflags: ");
125         DDRAW_dump_DDBLT(dwFlags);
126         if (dwFlags & DDBLT_DDFX) {
127             TRACE("\tblitfx: ");
128             DDRAW_dump_DDBLTFX(lpbltfx->dwDDFX);
129         }
130     }
131
132     /* We only support the BLT with DEPTH_FILL for now */
133     if (This->ddraw_owner->d3d != NULL) {
134         if (This->ddraw_owner->d3d->current_device != NULL) {
135             This->ddraw_owner->d3d->current_device->clear(This->ddraw_owner->d3d->current_device,
136                                                           0, NULL, /* Clear the whole screen */
137                                                           D3DCLEAR_ZBUFFER,
138                                                           0x00000000,
139                                                           ((double) lpbltfx->u5.dwFillDepth) / 4294967295.0,
140                                                           0x00000000);
141             return DD_OK;
142         }
143     }
144
145     return cant_do_that("blt to a");
146 }
147
148 HRESULT WINAPI
149 FakeZBuffer_DirectDrawSurface_BltFast(LPDIRECTDRAWSURFACE7 iface, DWORD dstx,
150                                       DWORD dsty, LPDIRECTDRAWSURFACE7 src,
151                                       LPRECT rsrc, DWORD trans)
152 {
153     ICOM_THIS(IDirectDrawSurfaceImpl,iface);
154
155     if (TRACE_ON(ddraw)) {
156         FIXME("(%p)->(%ld,%ld,%p,%p,%08lx)\n",
157                 This,dstx,dsty,src,rsrc,trans
158         );
159         FIXME("\ttrans:");
160         if (FIXME_ON(ddraw))
161           DDRAW_dump_DDBLTFAST(trans);
162         if (rsrc)
163           FIXME("\tsrcrect: %dx%d-%dx%d\n",rsrc->left,rsrc->top,rsrc->right,rsrc->bottom);
164         else
165           FIXME(" srcrect: NULL\n");
166     }
167
168     return cant_do_that("bltfast to a");
169 }
170
171 HRESULT WINAPI
172 FakeZBuffer_DirectDrawSurface_GetDC(LPDIRECTDRAWSURFACE7 iface, HDC *phDC)
173 {
174     return cant_do_that("get a DC for a");
175 }
176
177 HRESULT WINAPI
178 FakeZBuffer_DirectDrawSurface_ReleaseDC(LPDIRECTDRAWSURFACE7 iface, HDC hDC)
179 {
180     return cant_do_that("release a DC for a");
181 }
182
183 HRESULT WINAPI
184 FakeZBuffer_DirectDrawSurface_Restore(LPDIRECTDRAWSURFACE7 iface)
185 {
186     return DD_OK;
187 }
188
189 HRESULT WINAPI
190 FakeZBuffer_DirectDrawSurface_SetSurfaceDesc(LPDIRECTDRAWSURFACE7 iface,
191                                              LPDDSURFACEDESC2 pDDSD,
192                                              DWORD dwFlags)
193 {
194     /* XXX */
195     abort();
196     return E_FAIL;
197 }
198
199
200 static ICOM_VTABLE(IDirectDrawSurface7) FakeZBuffer_IDirectDrawSurface7_VTable=
201 {
202     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
203     Main_DirectDrawSurface_QueryInterface,
204     Main_DirectDrawSurface_AddRef,
205     Main_DirectDrawSurface_Release,
206     Main_DirectDrawSurface_AddAttachedSurface,
207     Main_DirectDrawSurface_AddOverlayDirtyRect,
208     FakeZBuffer_DirectDrawSurface_Blt,
209     Main_DirectDrawSurface_BltBatch,
210     FakeZBuffer_DirectDrawSurface_BltFast,
211     Main_DirectDrawSurface_DeleteAttachedSurface,
212     Main_DirectDrawSurface_EnumAttachedSurfaces,
213     Main_DirectDrawSurface_EnumOverlayZOrders,
214     Main_DirectDrawSurface_Flip,
215     Main_DirectDrawSurface_GetAttachedSurface,
216     Main_DirectDrawSurface_GetBltStatus,
217     Main_DirectDrawSurface_GetCaps,
218     Main_DirectDrawSurface_GetClipper,
219     Main_DirectDrawSurface_GetColorKey,
220     FakeZBuffer_DirectDrawSurface_GetDC,
221     Main_DirectDrawSurface_GetFlipStatus,
222     Main_DirectDrawSurface_GetOverlayPosition,
223     Main_DirectDrawSurface_GetPalette,
224     Main_DirectDrawSurface_GetPixelFormat,
225     Main_DirectDrawSurface_GetSurfaceDesc,
226     Main_DirectDrawSurface_Initialize,
227     Main_DirectDrawSurface_IsLost,
228     Main_DirectDrawSurface_Lock,
229     FakeZBuffer_DirectDrawSurface_ReleaseDC,
230     FakeZBuffer_DirectDrawSurface_Restore,
231     Main_DirectDrawSurface_SetClipper,
232     Main_DirectDrawSurface_SetColorKey,
233     Main_DirectDrawSurface_SetOverlayPosition,
234     Main_DirectDrawSurface_SetPalette,
235     Main_DirectDrawSurface_Unlock,
236     Main_DirectDrawSurface_UpdateOverlay,
237     Main_DirectDrawSurface_UpdateOverlayDisplay,
238     Main_DirectDrawSurface_UpdateOverlayZOrder,
239     Main_DirectDrawSurface_GetDDInterface,
240     Main_DirectDrawSurface_PageLock,
241     Main_DirectDrawSurface_PageUnlock,
242     FakeZBuffer_DirectDrawSurface_SetSurfaceDesc,
243     Main_DirectDrawSurface_SetPrivateData,
244     Main_DirectDrawSurface_GetPrivateData,
245     Main_DirectDrawSurface_FreePrivateData,
246     Main_DirectDrawSurface_GetUniquenessValue,
247     Main_DirectDrawSurface_ChangeUniquenessValue,
248     Main_DirectDrawSurface_SetPriority,
249     Main_DirectDrawSurface_GetPriority,
250     Main_DirectDrawSurface_SetLOD,
251     Main_DirectDrawSurface_GetLOD
252 };