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