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