Avoid warnings.
[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 <stdarg.h>
25 #include <stdio.h>
26
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wtypes.h"
30 #include "wingdi.h"
31 #include "winuser.h"
32 #include "ddraw.h"
33 #include "d3d.h"
34 #include "ddcomimpl.h"
35 #include "ddrawi.h"
36
37 /* XXX Put this somewhere proper. */
38 #define DD_STRUCT_INIT(x)                       \
39         do {                                    \
40                 memset((x), 0, sizeof(*(x)));   \
41                 (x)->dwSize = sizeof(*x);       \
42         } while (0)
43
44 #define DD_STRUCT_COPY_BYSIZE(to,from)                  \
45         do {                                            \
46                 DWORD __size = (to)->dwSize;            \
47                 DWORD __copysize = __size;              \
48                 DWORD __resetsize = __size;             \
49                 if (__resetsize > sizeof(*to))          \
50                     __resetsize = sizeof(*to);          \
51                 memset(to,0,__resetsize);               \
52                 if ((from)->dwSize < __size)            \
53                     __copysize = (from)->dwSize;        \
54                 memcpy(to,from,__copysize);             \
55                 (to)->dwSize = __size;/*restore size*/  \
56         } while (0)
57
58 #define MAKE_FOURCC(a,b,c,d) ((a << 0) | (b << 8) | (c << 16) | (d << 24))
59
60 /*****************************************************************************
61  * IDirectDraw implementation structure
62  */
63
64 typedef struct IDirectDrawImpl IDirectDrawImpl;
65 typedef struct IDirectDrawPaletteImpl IDirectDrawPaletteImpl;
66 typedef struct IDirectDrawClipperImpl IDirectDrawClipperImpl;
67 typedef struct IDirectDrawSurfaceImpl IDirectDrawSurfaceImpl;
68 typedef struct IDirect3DDeviceImpl IDirect3DDeviceImpl;
69
70 typedef void (*pixel_convert_func)(void *src, void *dst, DWORD width,
71                                    DWORD height, LONG pitch,
72                                    IDirectDrawPaletteImpl *palette);
73
74 typedef void (*palette_convert_func)(LPPALETTEENTRY palent,
75                                      void *screen_palette, DWORD start,
76                                      DWORD count);
77
78 struct IDirectDrawImpl
79 {
80     ICOM_VFIELD_MULTI(IDirectDraw7);
81     ICOM_VFIELD_MULTI(IDirectDraw4);
82     ICOM_VFIELD_MULTI(IDirectDraw2);
83     ICOM_VFIELD_MULTI(IDirectDraw);
84     ICOM_VFIELD_MULTI(IDirect3D7);
85     ICOM_VFIELD_MULTI(IDirect3D3);
86     ICOM_VFIELD_MULTI(IDirect3D2);
87     ICOM_VFIELD_MULTI(IDirect3D);
88
89     DWORD ref;
90
91     /* TRUE if created via DirectDrawCreateEx or CoCreateInstance,
92      * FALSE if created via DirectDrawCreate. */
93     BOOL ex;
94
95     /* Linked list of surfaces, joined by next_ddraw in IDirectSurfaceImpl. */
96     IDirectDrawSurfaceImpl* surfaces;
97     /* Linked list of palettes, joined by next_ddraw. */
98     IDirectDrawPaletteImpl* palettes;
99     /* Linked list of clippers, joined by next_ddraw. */
100     IDirectDrawClipperImpl* clippers;
101
102     IDirectDrawSurfaceImpl* primary_surface;
103
104     DDRAWI_DIRECTDRAW_LCL local;
105     DDCAPS caps;
106
107     HWND window;
108     DWORD cooperative_level;
109     WNDPROC original_wndproc;
110
111     DWORD width, height;
112     LONG pitch;
113     DDPIXELFORMAT pixelformat;
114     DWORD cur_scanline;
115
116     /* Should each of these go into some structure? */
117     DWORD orig_width, orig_height;
118     LONG orig_pitch;
119     DDPIXELFORMAT orig_pixelformat;
120
121     /* Called when the refcount goes to 0. */
122     void (*final_release)(IDirectDrawImpl *This);
123
124     HRESULT (*set_exclusive_mode)(IDirectDrawImpl *This, DWORD dwExcl);
125
126     HRESULT (*create_palette)(IDirectDrawImpl* This, DWORD dwFlags,
127                               LPDIRECTDRAWPALETTE* ppPalette,
128                               LPUNKNOWN pUnkOuter);
129
130     /* Surface creation functions. For all of these, pOuter == NULL. */
131
132     /* Do not create any backbuffers or the flipping chain. */
133     HRESULT (*create_primary)(IDirectDrawImpl* This,
134                               const DDSURFACEDESC2* pDDSD,
135                               LPDIRECTDRAWSURFACE7* ppSurf, LPUNKNOWN pOuter);
136
137     /* Primary may be NULL if we are creating an unattached backbuffer. */
138     HRESULT (*create_backbuffer)(IDirectDrawImpl* This,
139                                  const DDSURFACEDESC2* pDDSD,
140                                  LPDIRECTDRAWSURFACE7* ppSurf,
141                                  LPUNKNOWN pOuter,
142                                  IDirectDrawSurfaceImpl* primary);
143
144     /* shiny happy offscreenplain surfaces */
145     HRESULT (*create_offscreen)(IDirectDrawImpl* This,
146                                 const DDSURFACEDESC2* pDDSD,
147                                 LPDIRECTDRAWSURFACE7* ppSurf,
148                                 LPUNKNOWN pOuter);
149
150     /* dwMipMapLevel is specified as per OpenGL. (i.e. 0 is base) */
151     HRESULT (*create_texture)(IDirectDrawImpl* This,
152                               const DDSURFACEDESC2* pDDSD,
153                               LPDIRECTDRAWSURFACE7* ppSurf, LPUNKNOWN pOuter,
154                               DWORD dwMipMapLevel);
155
156     HRESULT (*create_zbuffer)(IDirectDrawImpl* This,
157                               const DDSURFACEDESC2* pDDSD,
158                               LPDIRECTDRAWSURFACE7* ppSurf, LPUNKNOWN pOuter);
159
160     LPVOID      private;
161
162     /* Everything below here is still questionable. */
163
164     DDPIXELFORMAT screen_pixelformat;
165
166     int           pixmap_depth;
167     pixel_convert_func pixel_convert;
168     palette_convert_func palette_convert;
169
170     /* Use to fool some too strict games */
171     INT32 (*allocate_memory)(IDirectDrawImpl *This, DWORD mem);
172     void (*free_memory)(IDirectDrawImpl *This, DWORD mem);
173     DWORD total_vidmem, available_vidmem;
174     
175     /* IDirect3D fields */
176     LPVOID d3d_private;
177
178     /* Used as a callback function to create a texture */
179     HRESULT (*d3d_create_texture)(IDirectDrawImpl *d3d, IDirectDrawSurfaceImpl *tex, BOOLEAN at_creation, IDirectDrawSurfaceImpl *main);
180
181     /* Used as a callback for Devices to tell to the D3D object it's been created */
182     HRESULT (*d3d_added_device)(IDirectDrawImpl *d3d, IDirect3DDeviceImpl *device);
183     HRESULT (*d3d_removed_device)(IDirectDrawImpl *d3d, IDirect3DDeviceImpl *device);
184
185     /* This is needed for delayed texture creation and Z buffer blits */
186     IDirect3DDeviceImpl *current_device;
187
188     /* This is for the fake mainWindow */
189     ATOM        winclass;
190     PAINTSTRUCT ps;
191     BOOL        paintable;
192 };
193
194 /*****************************************************************************
195  * IDirectDrawPalette implementation structure
196  */
197 struct IDirectDrawPaletteImpl
198 {
199     /* IUnknown fields */
200     ICOM_VFIELD_MULTI(IDirectDrawPalette);
201     DWORD ref;
202
203     DDRAWI_DDRAWPALETTE_LCL local;
204     DDRAWI_DDRAWPALETTE_GBL global;
205
206     /* IDirectDrawPalette fields */
207     HPALETTE            hpal;
208     WORD                palVersion, palNumEntries; /* LOGPALETTE */
209     PALETTEENTRY        palents[256];
210     /* This is to store the palette in 'screen format' */
211     int                 screen_palents[256];
212
213     VOID (*final_release)(IDirectDrawPaletteImpl* This);
214
215     IDirectDrawImpl* ddraw_owner;
216     IDirectDrawPaletteImpl* prev_ddraw;
217     IDirectDrawPaletteImpl* next_ddraw;
218
219     LPVOID              private;
220 };
221
222 /*****************************************************************************
223  * IDirectDrawClipper implementation structure
224  */
225 struct IDirectDrawClipperImpl
226 {
227     /* IUnknown fields */
228     ICOM_VFIELD_MULTI(IDirectDrawClipper);
229     DWORD ref;
230
231     /* IDirectDrawClipper fields */
232     HWND hWnd;
233
234     IDirectDrawImpl* ddraw_owner;
235     IDirectDrawClipperImpl* prev_ddraw;
236     IDirectDrawClipperImpl* next_ddraw;
237 };
238
239 /*****************************************************************************
240  * IDirectDrawSurface implementation structure
241  */
242
243 struct IDirectDrawSurfaceImpl
244 {
245     /* IUnknown fields */
246     ICOM_VFIELD_MULTI(IDirectDrawSurface7);
247     ICOM_VFIELD_MULTI(IDirectDrawSurface3);
248     ICOM_VFIELD_MULTI(IDirectDrawGammaControl);
249     ICOM_VFIELD_MULTI(IDirect3DTexture2);
250     ICOM_VFIELD_MULTI(IDirect3DTexture);
251     DWORD ref;
252
253     struct IDirectDrawSurfaceImpl* attached; /* attached surfaces */
254
255     struct IDirectDrawSurfaceImpl* next_ddraw; /* ddraw surface chain */
256     struct IDirectDrawSurfaceImpl* prev_ddraw;
257     struct IDirectDrawSurfaceImpl* next_attached; /* attached surface chain */
258     struct IDirectDrawSurfaceImpl* prev_attached;
259
260     IDirectDrawImpl* ddraw_owner;
261     IDirectDrawSurfaceImpl* surface_owner;
262
263     IDirectDrawPaletteImpl* palette; /* strong ref */
264     IDirectDrawClipperImpl* clipper; /* strong ref */
265
266     DDRAWI_DDRAWSURFACE_LCL local;
267     DDRAWI_DDRAWSURFACE_MORE more;
268     /* FIXME: since Flip should swap the GBL structures, they should
269      * probably not be embedded into the IDirectDrawSurfaceImpl structure... */
270     LPDDRAWI_DDRAWSURFACE_GBL_MORE gmore;
271     DDRAWI_DDRAWSURFACE_GBL global;
272     DDRAWI_DDRAWSURFACE_GBL_MORE global_more;
273
274     DDSURFACEDESC2 surface_desc;
275
276     HDC hDC;
277     RECT lastlockrect;
278     DWORD lastlocktype;
279     BOOL dc_in_use;
280
281     HRESULT (*duplicate_surface)(IDirectDrawSurfaceImpl* src,
282                                  LPDIRECTDRAWSURFACE7* dst);
283     void (*final_release)(IDirectDrawSurfaceImpl *This);
284     HRESULT (*late_allocate)(IDirectDrawSurfaceImpl *This);
285     BOOL (*attach)(IDirectDrawSurfaceImpl *This, IDirectDrawSurfaceImpl *to);
286     BOOL (*detach)(IDirectDrawSurfaceImpl *This);
287     void (*lock_update)(IDirectDrawSurfaceImpl* This, LPCRECT pRect, DWORD dwFlags);
288     void (*unlock_update)(IDirectDrawSurfaceImpl* This, LPCRECT pRect);
289     void (*lose_surface)(IDirectDrawSurfaceImpl* This);
290     BOOL (*flip_data)(IDirectDrawSurfaceImpl* front,
291                       IDirectDrawSurfaceImpl* back,
292                       DWORD dwFlags);
293     void (*flip_update)(IDirectDrawSurfaceImpl* front, DWORD dwFlags);
294     HRESULT (*get_dc)(IDirectDrawSurfaceImpl* This, HDC* phDC);
295     HRESULT (*release_dc)(IDirectDrawSurfaceImpl* This, HDC hDC);
296     void (*set_palette)(IDirectDrawSurfaceImpl* This, IDirectDrawPaletteImpl* pal);
297     void (*update_palette)(IDirectDrawSurfaceImpl* This, IDirectDrawPaletteImpl* pal,
298                            DWORD dwStart, DWORD dwCount, LPPALETTEENTRY palent);
299     HWND (*get_display_window)(IDirectDrawSurfaceImpl *This);
300     HRESULT (*get_gamma_ramp)(IDirectDrawSurfaceImpl *This, DWORD dwFlags, LPDDGAMMARAMP lpGammaRamp);
301     HRESULT (*set_gamma_ramp)(IDirectDrawSurfaceImpl *This, DWORD dwFlags, LPDDGAMMARAMP lpGammaRamp);
302
303     struct PrivateData* private_data;
304
305     DWORD max_lod;
306     DWORD priority;
307
308     BOOL lost;
309
310     DWORD uniqueness_value;
311
312     LPVOID private;
313
314     /* Everything below here is dodgy. */
315     /* For Direct3D use */
316     LPVOID aux_ctx, aux_data;
317     void (*aux_release)(LPVOID ctx, LPVOID data);
318     BOOL (*aux_flip)(LPVOID ctx, LPVOID data);
319     void (*aux_unlock)(LPVOID ctx, LPVOID data, LPRECT lpRect);
320     HRESULT (*aux_blt)(struct IDirectDrawSurfaceImpl *This, LPRECT rdst, LPDIRECTDRAWSURFACE7 src, LPRECT rsrc, DWORD dwFlags, LPDDBLTFX lpbltfx);
321     HRESULT (*aux_bltfast)(struct IDirectDrawSurfaceImpl *This, DWORD dstx, DWORD dsty, LPDIRECTDRAWSURFACE7 src, LPRECT rsrc, DWORD trans);
322     HRESULT (*aux_setcolorkey_cb)(struct IDirectDrawSurfaceImpl *texture, DWORD dwFlags, LPDDCOLORKEY ckey );
323     /* This is to get the D3DDevice object associated to this surface */
324     struct IDirect3DDeviceImpl *d3ddevice;
325     /* This is for texture */
326     IDirectDrawSurfaceImpl *mip_main;
327     int mipmap_level;
328     LPVOID tex_private;
329     void (*lock_update_prev)(IDirectDrawSurfaceImpl* This, LPCRECT pRect, DWORD dwFlags);
330     void (*unlock_update_prev)(IDirectDrawSurfaceImpl* This, LPCRECT pRect);
331     BOOLEAN (*get_dirty_status)(IDirectDrawSurfaceImpl* This, LPCRECT pRect);
332 };
333
334 /*****************************************************************************
335  * Driver initialisation functions.
336  */
337 BOOL DDRAW_HAL_Init(HINSTANCE, DWORD, LPVOID);
338 BOOL DDRAW_User_Init(HINSTANCE, DWORD, LPVOID);
339
340 typedef struct {
341     const DDDEVICEIDENTIFIER2* info;
342     int preference;     /* how good we are. dga might get 100, xlib 50*/
343     HRESULT (*create)(const GUID*, LPDIRECTDRAW7*, LPUNKNOWN, BOOL ex);
344
345     /* For IDirectDraw7::Initialize. */
346     HRESULT (*init)(IDirectDrawImpl *, const GUID*);
347 } ddraw_driver;
348
349 void DDRAW_register_driver(const ddraw_driver*);
350
351 const ddraw_driver* DDRAW_FindDriver(const GUID* guid);
352
353 /******************************************************************************
354  * Random utilities
355  */
356
357 /* Get DDSCAPS of surface (shortcutmacro) */
358 #define SDDSCAPS(iface) ((iface)->s.surface_desc.ddsCaps.dwCaps)
359 /* Get the number of bytes per pixel for a given surface */
360 #define PFGET_BPP(pf) (pf.dwFlags&DDPF_PALETTEINDEXED8?1:((pf.u1.dwRGBBitCount+7)/8))
361 #define GET_BPP(desc) PFGET_BPP(desc.u4.ddpfPixelFormat)
362
363 LONG DDRAW_width_bpp_to_pitch(DWORD width, DWORD bpp);
364
365 typedef struct {
366     unsigned short      bpp,depth;
367     unsigned int        rmask,gmask,bmask;
368 } ConvertMode;
369
370 typedef struct {
371     void (*pixel_convert)(void *src, void *dst, DWORD width, DWORD height, LONG pitch, IDirectDrawPaletteImpl* palette);
372     void (*palette_convert)(LPPALETTEENTRY palent, void *screen_palette, DWORD start, DWORD count);
373 } ConvertFuncs;
374
375 typedef struct {
376     ConvertMode screen, dest;
377     ConvertFuncs funcs;
378 } Convert;
379
380 extern Convert ModeEmulations[8];
381 extern int _common_depth_to_pixelformat(DWORD depth,LPDIRECTDRAW ddraw);
382 extern BOOL opengl_initialized;
383 extern BOOL s3tc_initialized;
384
385 typedef void (*FUNC_FETCH_2D_TEXEL_RGBA_DXT1)(int srcRowStride, const BYTE *pixdata, int i, int j, void *texel);
386 typedef void (*FUNC_FETCH_2D_TEXEL_RGBA_DXT3)(int srcRowStride, const BYTE *pixdata, int i, int j, void *texel);
387 typedef void (*FUNC_FETCH_2D_TEXEL_RGBA_DXT5)(int srcRowStride, const BYTE *pixdata, int i, int j, void *texel);
388
389 extern FUNC_FETCH_2D_TEXEL_RGBA_DXT1 fetch_2d_texel_rgba_dxt1;
390 extern FUNC_FETCH_2D_TEXEL_RGBA_DXT3 fetch_2d_texel_rgba_dxt3;
391 extern FUNC_FETCH_2D_TEXEL_RGBA_DXT5 fetch_2d_texel_rgba_dxt5;
392
393 /******************************************************************************
394  * Structure conversion (for thunks)
395  */
396 void DDRAW_Convert_DDSCAPS_1_To_2(const DDSCAPS* pIn, DDSCAPS2* pOut);
397 void DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(const DDDEVICEIDENTIFIER2* pIn,
398                                              DDDEVICEIDENTIFIER* pOut);
399
400 /******************************************************************************
401  * Debugging / Flags output functions
402  */
403 extern void DDRAW_dump_DDBLTFX(DWORD flagmask);
404 extern void DDRAW_dump_DDBLTFAST(DWORD flagmask);
405 extern void DDRAW_dump_DDBLT(DWORD flagmask);
406 extern void DDRAW_dump_DDSCAPS(const DDSCAPS *in);
407 extern void DDRAW_dump_DDSCAPS2(const DDSCAPS2 *in);
408 extern void DDRAW_dump_pixelformat_flag(DWORD flagmask);
409 extern void DDRAW_dump_paletteformat(DWORD dwFlags);
410 extern void DDRAW_dump_pixelformat(const DDPIXELFORMAT *in);
411 extern void DDRAW_dump_colorkeyflag(DWORD ck);
412 extern void DDRAW_dump_surface_desc(const DDSURFACEDESC2 *lpddsd);
413 extern void DDRAW_dump_cooperativelevel(DWORD cooplevel);
414 extern void DDRAW_dump_lockflag(DWORD lockflag);
415 extern void DDRAW_dump_DDCOLORKEY(const DDCOLORKEY *in);
416 extern void DDRAW_dump_DDCAPS(const DDCAPS *lpcaps);
417 extern void DDRAW_dump_surface_to_disk(IDirectDrawSurfaceImpl *surface, FILE *f, int scale) ;
418
419 /* Used for generic dumping */
420 typedef struct
421 {
422     DWORD val;
423     const char* name;
424 } flag_info;
425
426 #define FE(x) { x, #x }
427
428 typedef struct
429 {
430     DWORD val;
431     const char* name;
432     void (*func)(const void *);
433     ptrdiff_t offset;
434 } member_info;
435
436 #define DDRAW_dump_flags(flags,names,num_names) DDRAW_dump_flags_(flags, names, num_names, 1)
437 #define ME(x,f,e) { x, #x, (void (*)(const void *))(f), offsetof(STRUCT, e) }
438
439 extern void DDRAW_dump_flags_(DWORD flags, const flag_info* names, size_t num_names, int newline);
440 extern void DDRAW_dump_members(DWORD flags, const void* data, const member_info* mems, size_t num_mems);
441
442 #endif /* __WINE_DLLS_DDRAW_DDRAW_PRIVATE_H */