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