Proper logging of DDSCAPS / DDSCAPS2 structures.
[wine] / dlls / ddraw / ddraw_private.h
1 /*
2  * Copyright 2000-2001 TransGaming Technologies Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19 #ifndef __WINE_DLLS_DDRAW_DDRAW_PRIVATE_H
20 #define __WINE_DLLS_DDRAW_DDRAW_PRIVATE_H
21
22 /* MAY NOT CONTAIN X11 or DGA specific includes/defines/structs! */
23
24 #include "winbase.h"
25 #include "wtypes.h"
26 #include "wingdi.h"
27 #include "winuser.h"
28 #include "ddraw.h"
29 #include "ddcomimpl.h"
30 #include "ddrawi.h"
31
32 /* XXX Put this somewhere proper. */
33 #define DD_STRUCT_INIT(x)                       \
34         do {                                    \
35                 memset((x), 0, sizeof(*(x)));   \
36                 (x)->dwSize = sizeof(*x);       \
37         } while (0)
38
39 #define DD_STRUCT_COPY_BYSIZE(to,from)                  \
40         do {                                            \
41                 DWORD __size = (to)->dwSize;            \
42                 DWORD __copysize = __size;              \
43                 memset(to,0,__size);                    \
44                 if ((from)->dwSize < __size)            \
45                     __copysize = (from)->dwSize;        \
46                 memcpy(to,from,__copysize);             \
47                 (to)->dwSize = __size;/*restore size*/  \
48         } while (0)
49
50 /*****************************************************************************
51  * IDirectDraw implementation structure
52  */
53
54 typedef struct IDirectDrawImpl IDirectDrawImpl;
55 typedef struct IDirectDrawPaletteImpl IDirectDrawPaletteImpl;
56 typedef struct IDirectDrawClipperImpl IDirectDrawClipperImpl;
57 typedef struct IDirectDrawSurfaceImpl IDirectDrawSurfaceImpl;
58
59 typedef void (*pixel_convert_func)(void *src, void *dst, DWORD width,
60                                    DWORD height, LONG pitch,
61                                    IDirectDrawPaletteImpl *palette);
62
63 typedef void (*palette_convert_func)(LPPALETTEENTRY palent,
64                                      void *screen_palette, DWORD start,
65                                      DWORD count);
66
67 struct IDirectDrawImpl
68 {
69     ICOM_VFIELD_MULTI(IDirectDraw7);
70     ICOM_VFIELD_MULTI(IDirectDraw4);
71     ICOM_VFIELD_MULTI(IDirectDraw2);
72     ICOM_VFIELD_MULTI(IDirectDraw);
73
74     DWORD ref;
75
76     /* TRUE if created via DirectDrawCreateEx or CoCreateInstance,
77      * FALSE if created via DirectDrawCreate. */
78     BOOL ex;
79
80     /* Linked list of surfaces, joined by next_ddraw in IDirectSurfaceImpl. */
81     IDirectDrawSurfaceImpl* surfaces;
82     /* Linked list of palettes, joined by next_ddraw. */
83     IDirectDrawPaletteImpl* palettes;
84     /* Linked list of clippers, joined by next_ddraw. */
85     IDirectDrawClipperImpl* clippers;
86
87     IDirectDrawSurfaceImpl* primary_surface;
88
89     DDRAWI_DIRECTDRAW_LCL local;
90     DDCAPS caps;
91
92     HWND window;
93     DWORD cooperative_level;
94     WNDPROC original_wndproc;
95
96     DWORD width, height;
97     LONG pitch;
98     DDPIXELFORMAT pixelformat;
99
100     /* Should each of these go into some structure? */
101     DWORD orig_width, orig_height;
102     LONG orig_pitch;
103     DDPIXELFORMAT orig_pixelformat;
104
105     /* Called when the refcount goes to 0. */
106     void (*final_release)(IDirectDrawImpl *This);
107
108     HRESULT (*set_exclusive_mode)(IDirectDrawImpl *This, DWORD dwExcl);
109
110     HRESULT (*create_palette)(IDirectDrawImpl* This, DWORD dwFlags,
111                               LPDIRECTDRAWPALETTE* ppPalette,
112                               LPUNKNOWN pUnkOuter);
113
114     /* Surface creation functions. For all of these, pOuter == NULL. */
115
116     /* Do not create any backbuffers or the flipping chain. */
117     HRESULT (*create_primary)(IDirectDrawImpl* This,
118                               const DDSURFACEDESC2* pDDSD,
119                               LPDIRECTDRAWSURFACE7* ppSurf, LPUNKNOWN pOuter);
120
121     /* Primary may be NULL if we are creating an unattached backbuffer. */
122     HRESULT (*create_backbuffer)(IDirectDrawImpl* This,
123                                  const DDSURFACEDESC2* pDDSD,
124                                  LPDIRECTDRAWSURFACE7* ppSurf,
125                                  LPUNKNOWN pOuter,
126                                  IDirectDrawSurfaceImpl* primary);
127
128     /* shiny happy offscreenplain surfaces */
129     HRESULT (*create_offscreen)(IDirectDrawImpl* This,
130                                 const DDSURFACEDESC2* pDDSD,
131                                 LPDIRECTDRAWSURFACE7* ppSurf,
132                                 LPUNKNOWN pOuter);
133
134     /* dwMipMapLevel is specified as per OpenGL. (i.e. 0 is base) */
135     HRESULT (*create_texture)(IDirectDrawImpl* This,
136                               const DDSURFACEDESC2* pDDSD,
137                               LPDIRECTDRAWSURFACE7* ppSurf, LPUNKNOWN pOuter,
138                               DWORD dwMipMapLevel);
139
140     HRESULT (*create_zbuffer)(IDirectDrawImpl* This,
141                               const DDSURFACEDESC2* pDDSD,
142                               LPDIRECTDRAWSURFACE7* ppSurf, LPUNKNOWN pOuter);
143
144     LPVOID      private;
145
146     /* Everything below here is still questionable. */
147
148     DDPIXELFORMAT screen_pixelformat;
149
150     int           pixmap_depth;
151     pixel_convert_func pixel_convert;
152     palette_convert_func palette_convert;
153
154     /* This is for the fake mainWindow */
155     ATOM        winclass;
156     PAINTSTRUCT ps;
157     BOOL        paintable;
158 };
159
160 /*****************************************************************************
161  * IDirectDrawPalette implementation structure
162  */
163 struct IDirectDrawPaletteImpl
164 {
165     /* IUnknown fields */
166     ICOM_VFIELD_MULTI(IDirectDrawPalette);
167     DWORD ref;
168
169     DDRAWI_DDRAWPALETTE_LCL local;
170     DDRAWI_DDRAWPALETTE_GBL global;
171
172     /* IDirectDrawPalette fields */
173     HPALETTE            hpal;
174     WORD                palVersion, palNumEntries; /* LOGPALETTE */
175     PALETTEENTRY        palents[256];
176     /* This is to store the palette in 'screen format' */
177     int                 screen_palents[256];
178
179     VOID (*final_release)(IDirectDrawPaletteImpl* This);
180
181     IDirectDrawImpl* ddraw_owner;
182     IDirectDrawPaletteImpl* prev_ddraw;
183     IDirectDrawPaletteImpl* next_ddraw;
184
185     LPVOID              private;
186 };
187
188 /*****************************************************************************
189  * IDirectDrawClipper implementation structure
190  */
191 struct IDirectDrawClipperImpl
192 {
193     /* IUnknown fields */
194     ICOM_VFIELD_MULTI(IDirectDrawClipper);
195     DWORD ref;
196
197     /* IDirectDrawClipper fields */
198     HWND hWnd;
199
200     IDirectDrawImpl* ddraw_owner;
201     IDirectDrawClipperImpl* prev_ddraw;
202     IDirectDrawClipperImpl* next_ddraw;
203 };
204
205 /*****************************************************************************
206  * IDirectDrawSurface implementation structure
207  */
208
209 struct IDirectDrawSurfaceImpl
210 {
211     /* IUnknown fields */
212     ICOM_VFIELD_MULTI(IDirectDrawSurface7);
213     ICOM_VFIELD_MULTI(IDirectDrawSurface3);
214     ICOM_VFIELD_MULTI(IDirectDrawGammaControl);
215     DWORD ref;
216
217     struct IDirectDrawSurfaceImpl* attached; /* attached surfaces */
218
219     struct IDirectDrawSurfaceImpl* next_ddraw; /* ddraw surface chain */
220     struct IDirectDrawSurfaceImpl* prev_ddraw;
221     struct IDirectDrawSurfaceImpl* next_attached; /* attached surface chain */
222     struct IDirectDrawSurfaceImpl* prev_attached;
223
224     IDirectDrawImpl* ddraw_owner;
225     IDirectDrawSurfaceImpl* surface_owner;
226
227     IDirectDrawPaletteImpl* palette; /* strong ref */
228     IDirectDrawClipperImpl* clipper; /* strong ref */
229
230     DDRAWI_DDRAWSURFACE_LCL local;
231     DDRAWI_DDRAWSURFACE_MORE more;
232     /* FIXME: since Flip should swap the GBL structures, they should
233      * probably not be embedded into the IDirectDrawSurfaceImpl structure... */
234     LPDDRAWI_DDRAWSURFACE_GBL_MORE gmore;
235     DDRAWI_DDRAWSURFACE_GBL global;
236     DDRAWI_DDRAWSURFACE_GBL_MORE global_more;
237
238     DDSURFACEDESC2 surface_desc;
239
240     HDC hDC;
241     RECT lastlockrect;
242     BOOL dc_in_use;
243
244     HRESULT (*duplicate_surface)(IDirectDrawSurfaceImpl* src,
245                                  LPDIRECTDRAWSURFACE7* dst);
246     void (*final_release)(IDirectDrawSurfaceImpl *This);
247     HRESULT (*late_allocate)(IDirectDrawSurfaceImpl *This);
248     BOOL (*attach)(IDirectDrawSurfaceImpl *This, IDirectDrawSurfaceImpl *to);
249     BOOL (*detach)(IDirectDrawSurfaceImpl *This);
250     void (*lock_update)(IDirectDrawSurfaceImpl* This, LPCRECT pRect, DWORD dwFlags);
251     void (*unlock_update)(IDirectDrawSurfaceImpl* This, LPCRECT pRect);
252     void (*lose_surface)(IDirectDrawSurfaceImpl* This);
253     BOOL (*flip_data)(IDirectDrawSurfaceImpl* front,
254                       IDirectDrawSurfaceImpl* back,
255                       DWORD dwFlags);
256     void (*flip_update)(IDirectDrawSurfaceImpl* front, DWORD dwFlags);
257     HRESULT (*get_dc)(IDirectDrawSurfaceImpl* This, HDC* phDC);
258     HRESULT (*release_dc)(IDirectDrawSurfaceImpl* This, HDC hDC);
259     void (*set_palette)(IDirectDrawSurfaceImpl* This, IDirectDrawPaletteImpl* pal);
260     void (*update_palette)(IDirectDrawSurfaceImpl* This, IDirectDrawPaletteImpl* pal,
261                            DWORD dwStart, DWORD dwCount, LPPALETTEENTRY palent);
262     HWND (*get_display_window)(IDirectDrawSurfaceImpl *This);
263     HRESULT (*get_gamma_ramp)(IDirectDrawSurfaceImpl *This, DWORD dwFlags, LPDDGAMMARAMP lpGammaRamp);
264     HRESULT (*set_gamma_ramp)(IDirectDrawSurfaceImpl *This, DWORD dwFlags, LPDDGAMMARAMP lpGammaRamp);
265
266     struct PrivateData* private_data;
267
268     DWORD max_lod;
269     DWORD priority;
270
271     BOOL lost;
272
273     DWORD uniqueness_value;
274
275     LPVOID private;
276
277     /* Everything below here is dodgy. */
278     /* For Direct3D use */
279     LPVOID                      aux_ctx, aux_data;
280     void (*aux_release)(LPVOID ctx, LPVOID data);
281     BOOL (*aux_flip)(LPVOID ctx, LPVOID data);
282     void (*aux_unlock)(LPVOID ctx, LPVOID data, LPRECT lpRect);
283     struct IDirect3DTexture2Impl*       texture;
284     HRESULT (WINAPI *SetColorKey_cb)(struct IDirect3DTexture2Impl *texture, DWORD dwFlags, LPDDCOLORKEY ckey ) ;
285 };
286
287 /*****************************************************************************
288  * Driver initialisation functions.
289  */
290 BOOL DDRAW_HAL_Init(HINSTANCE, DWORD, LPVOID);
291 BOOL DDRAW_User_Init(HINSTANCE, DWORD, LPVOID);
292
293 typedef struct {
294     const DDDEVICEIDENTIFIER2* info;
295     int preference;     /* how good we are. dga might get 100, xlib 50*/
296     HRESULT (*create)(const GUID*, LPDIRECTDRAW7*, LPUNKNOWN, BOOL ex);
297
298     /* For IDirectDraw7::Initialize. */
299     HRESULT (*init)(IDirectDrawImpl *, const GUID*);
300 } ddraw_driver;
301
302 void DDRAW_register_driver(const ddraw_driver*);
303
304 const ddraw_driver* DDRAW_FindDriver(const GUID* guid);
305
306 /******************************************************************************
307  * Random utilities
308  */
309
310 /* Get DDSCAPS of surface (shortcutmacro) */
311 #define SDDSCAPS(iface) ((iface)->s.surface_desc.ddsCaps.dwCaps)
312 /* Get the number of bytes per pixel for a given surface */
313 #define PFGET_BPP(pf) (pf.dwFlags&DDPF_PALETTEINDEXED8?1:((pf.u1.dwRGBBitCount+7)/8))
314 #define GET_BPP(desc) PFGET_BPP(desc.u4.ddpfPixelFormat)
315
316 LONG DDRAW_width_bpp_to_pitch(DWORD width, DWORD bpp);
317
318 typedef struct {
319     unsigned short      bpp,depth;
320     unsigned int        rmask,gmask,bmask;
321 } ConvertMode;
322
323 typedef struct {
324     void (*pixel_convert)(void *src, void *dst, DWORD width, DWORD height, LONG pitch, IDirectDrawPaletteImpl* palette);
325     void (*palette_convert)(LPPALETTEENTRY palent, void *screen_palette, DWORD start, DWORD count);
326 } ConvertFuncs;
327
328 typedef struct {
329     ConvertMode screen, dest;
330     ConvertFuncs funcs;
331 } Convert;
332
333 extern Convert ModeEmulations[8];
334 extern int _common_depth_to_pixelformat(DWORD depth,LPDIRECTDRAW ddraw);
335
336 extern HRESULT create_direct3d(LPVOID *obj,IDirectDrawImpl*);
337 extern HRESULT create_direct3d2(LPVOID *obj,IDirectDrawImpl*);
338 extern HRESULT create_direct3d3(LPVOID *obj,IDirectDrawImpl*);
339 extern HRESULT create_direct3d7(LPVOID *obj,IDirectDrawImpl*);
340
341 /******************************************************************************
342  * Structure conversion (for thunks)
343  */
344 void DDRAW_Convert_DDSCAPS_1_To_2(const DDSCAPS* pIn, DDSCAPS2* pOut);
345 void DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(const DDDEVICEIDENTIFIER2* pIn,
346                                              DDDEVICEIDENTIFIER* pOut);
347
348 /******************************************************************************
349  * Debugging / Flags output functions
350  */
351 extern void DDRAW_dump_DDBLTFX(DWORD flagmask);
352 extern void DDRAW_dump_DDBLTFAST(DWORD flagmask);
353 extern void DDRAW_dump_DDBLT(DWORD flagmask);
354 extern void DDRAW_dump_DDSCAPS(const DDSCAPS *in);
355 extern void DDRAW_dump_DDSCAPS2(const DDSCAPS2 *in);
356 extern void DDRAW_dump_pixelformat_flag(DWORD flagmask);
357 extern void DDRAW_dump_paletteformat(DWORD dwFlags);
358 extern void DDRAW_dump_pixelformat(const DDPIXELFORMAT *in);
359 extern void DDRAW_dump_colorkeyflag(DWORD ck);
360 extern void DDRAW_dump_surface_desc(const DDSURFACEDESC2 *lpddsd);
361 extern void DDRAW_dump_cooperativelevel(DWORD cooplevel);
362 extern void DDRAW_dump_DDCOLORKEY(const DDCOLORKEY *in);
363 extern void DDRAW_dump_DDCAPS(const DDCAPS *lpcaps);
364 #endif /* __WINE_DLLS_DDRAW_DDRAW_PRIVATE_H */