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