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