2 * Copyright 2000-2001 TransGaming Technologies Inc.
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.
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.
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
19 #ifndef __WINE_DLLS_DDRAW_DDRAW_PRIVATE_H
20 #define __WINE_DLLS_DDRAW_DDRAW_PRIVATE_H
22 /* MAY NOT CONTAIN X11 or DGA specific includes/defines/structs! */
32 #include "ddcomimpl.h"
35 /* XXX Put this somewhere proper. */
36 #define DD_STRUCT_INIT(x) \
38 memset((x), 0, sizeof(*(x))); \
39 (x)->dwSize = sizeof(*x); \
42 #define DD_STRUCT_COPY_BYSIZE(to,from) \
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*/ \
53 /*****************************************************************************
54 * IDirectDraw implementation structure
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;
63 typedef void (*pixel_convert_func)(void *src, void *dst, DWORD width,
64 DWORD height, LONG pitch,
65 IDirectDrawPaletteImpl *palette);
67 typedef void (*palette_convert_func)(LPPALETTEENTRY palent,
68 void *screen_palette, DWORD start,
71 struct IDirectDrawImpl
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);
84 /* TRUE if created via DirectDrawCreateEx or CoCreateInstance,
85 * FALSE if created via DirectDrawCreate. */
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;
95 IDirectDrawSurfaceImpl* primary_surface;
97 DDRAWI_DIRECTDRAW_LCL local;
101 DWORD cooperative_level;
102 WNDPROC original_wndproc;
106 DDPIXELFORMAT pixelformat;
108 /* Should each of these go into some structure? */
109 DWORD orig_width, orig_height;
111 DDPIXELFORMAT orig_pixelformat;
113 /* Called when the refcount goes to 0. */
114 void (*final_release)(IDirectDrawImpl *This);
116 HRESULT (*set_exclusive_mode)(IDirectDrawImpl *This, DWORD dwExcl);
118 HRESULT (*create_palette)(IDirectDrawImpl* This, DWORD dwFlags,
119 LPDIRECTDRAWPALETTE* ppPalette,
120 LPUNKNOWN pUnkOuter);
122 /* Surface creation functions. For all of these, pOuter == NULL. */
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);
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,
134 IDirectDrawSurfaceImpl* primary);
136 /* shiny happy offscreenplain surfaces */
137 HRESULT (*create_offscreen)(IDirectDrawImpl* This,
138 const DDSURFACEDESC2* pDDSD,
139 LPDIRECTDRAWSURFACE7* ppSurf,
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);
148 HRESULT (*create_zbuffer)(IDirectDrawImpl* This,
149 const DDSURFACEDESC2* pDDSD,
150 LPDIRECTDRAWSURFACE7* ppSurf, LPUNKNOWN pOuter);
154 /* Everything below here is still questionable. */
156 DDPIXELFORMAT screen_pixelformat;
159 pixel_convert_func pixel_convert;
160 palette_convert_func palette_convert;
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;
167 /* IDirect3D fields */
170 /* Used as a callback function to create a texture */
171 HRESULT (*d3d_create_texture)(IDirectDrawImpl *d3d, IDirectDrawSurfaceImpl *tex, BOOLEAN at_creation, IDirectDrawSurfaceImpl *main);
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);
177 /* This is needed for delayed texture creation and Z buffer blits */
178 IDirect3DDeviceImpl *current_device;
180 /* This is for the fake mainWindow */
186 /*****************************************************************************
187 * IDirectDrawPalette implementation structure
189 struct IDirectDrawPaletteImpl
191 /* IUnknown fields */
192 ICOM_VFIELD_MULTI(IDirectDrawPalette);
195 DDRAWI_DDRAWPALETTE_LCL local;
196 DDRAWI_DDRAWPALETTE_GBL global;
198 /* IDirectDrawPalette fields */
200 WORD palVersion, palNumEntries; /* LOGPALETTE */
201 PALETTEENTRY palents[256];
202 /* This is to store the palette in 'screen format' */
203 int screen_palents[256];
205 VOID (*final_release)(IDirectDrawPaletteImpl* This);
207 IDirectDrawImpl* ddraw_owner;
208 IDirectDrawPaletteImpl* prev_ddraw;
209 IDirectDrawPaletteImpl* next_ddraw;
214 /*****************************************************************************
215 * IDirectDrawClipper implementation structure
217 struct IDirectDrawClipperImpl
219 /* IUnknown fields */
220 ICOM_VFIELD_MULTI(IDirectDrawClipper);
223 /* IDirectDrawClipper fields */
226 IDirectDrawImpl* ddraw_owner;
227 IDirectDrawClipperImpl* prev_ddraw;
228 IDirectDrawClipperImpl* next_ddraw;
231 /*****************************************************************************
232 * IDirectDrawSurface implementation structure
235 struct IDirectDrawSurfaceImpl
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);
245 struct IDirectDrawSurfaceImpl* attached; /* attached surfaces */
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;
252 IDirectDrawImpl* ddraw_owner;
253 IDirectDrawSurfaceImpl* surface_owner;
255 IDirectDrawPaletteImpl* palette; /* strong ref */
256 IDirectDrawClipperImpl* clipper; /* strong ref */
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;
266 DDSURFACEDESC2 surface_desc;
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,
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);
295 struct PrivateData* private_data;
302 DWORD uniqueness_value;
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;
321 void (*lock_update_prev)(IDirectDrawSurfaceImpl* This, LPCRECT pRect, DWORD dwFlags);
322 void (*unlock_update_prev)(IDirectDrawSurfaceImpl* This, LPCRECT pRect);
325 /*****************************************************************************
326 * Driver initialisation functions.
328 BOOL DDRAW_HAL_Init(HINSTANCE, DWORD, LPVOID);
329 BOOL DDRAW_User_Init(HINSTANCE, DWORD, LPVOID);
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);
336 /* For IDirectDraw7::Initialize. */
337 HRESULT (*init)(IDirectDrawImpl *, const GUID*);
340 void DDRAW_register_driver(const ddraw_driver*);
342 const ddraw_driver* DDRAW_FindDriver(const GUID* guid);
344 /******************************************************************************
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)
354 LONG DDRAW_width_bpp_to_pitch(DWORD width, DWORD bpp);
357 unsigned short bpp,depth;
358 unsigned int rmask,gmask,bmask;
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);
367 ConvertMode screen, dest;
371 extern Convert ModeEmulations[8];
372 extern int _common_depth_to_pixelformat(DWORD depth,LPDIRECTDRAW ddraw);
373 extern BOOL opengl_initialized;
375 /******************************************************************************
376 * Structure conversion (for thunks)
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);
382 /******************************************************************************
383 * Debugging / Flags output functions
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) ;
401 /* Used for generic dumping */
408 #define FE(x) { x, #x }
414 void (*func)(const void *);
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) }
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);
424 #endif /* __WINE_DLLS_DDRAW_DDRAW_PRIVATE_H */