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