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! */
34 #include "ddcomimpl.h"
37 /* XXX Put this somewhere proper. */
38 #define DD_STRUCT_INIT(x) \
40 memset((x), 0, sizeof(*(x))); \
41 (x)->dwSize = sizeof(*x); \
44 #define DD_STRUCT_COPY_BYSIZE(to,from) \
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*/ \
58 #define MAKE_FOURCC(a,b,c,d) ((a << 0) | (b << 8) | (c << 16) | (d << 24))
60 /*****************************************************************************
61 * IDirectDraw implementation structure
64 typedef struct IDirectDrawImpl IDirectDrawImpl;
65 typedef struct IDirectDrawPaletteImpl IDirectDrawPaletteImpl;
66 typedef struct IDirectDrawClipperImpl IDirectDrawClipperImpl;
67 typedef struct IDirectDrawSurfaceImpl IDirectDrawSurfaceImpl;
68 typedef struct IDirect3DDeviceImpl IDirect3DDeviceImpl;
70 typedef void (*pixel_convert_func)(void *src, void *dst, DWORD width,
71 DWORD height, LONG pitch,
72 IDirectDrawPaletteImpl *palette);
74 typedef void (*palette_convert_func)(LPPALETTEENTRY palent,
75 void *screen_palette, DWORD start,
78 struct IDirectDrawImpl
80 ICOM_VFIELD_MULTI(IDirectDraw7);
81 ICOM_VFIELD_MULTI(IDirectDraw4);
82 ICOM_VFIELD_MULTI(IDirectDraw2);
83 ICOM_VFIELD_MULTI(IDirectDraw);
84 ICOM_VFIELD_MULTI(IDirect3D7);
85 ICOM_VFIELD_MULTI(IDirect3D3);
86 ICOM_VFIELD_MULTI(IDirect3D2);
87 ICOM_VFIELD_MULTI(IDirect3D);
91 /* TRUE if created via DirectDrawCreateEx or CoCreateInstance,
92 * FALSE if created via DirectDrawCreate. */
95 /* Linked list of surfaces, joined by next_ddraw in IDirectSurfaceImpl. */
96 IDirectDrawSurfaceImpl* surfaces;
97 /* Linked list of palettes, joined by next_ddraw. */
98 IDirectDrawPaletteImpl* palettes;
99 /* Linked list of clippers, joined by next_ddraw. */
100 IDirectDrawClipperImpl* clippers;
102 IDirectDrawSurfaceImpl* primary_surface;
104 DDRAWI_DIRECTDRAW_LCL local;
108 DWORD cooperative_level;
109 WNDPROC original_wndproc;
113 DDPIXELFORMAT pixelformat;
116 /* Should each of these go into some structure? */
117 DWORD orig_width, orig_height;
119 DDPIXELFORMAT orig_pixelformat;
121 /* Called when the refcount goes to 0. */
122 void (*final_release)(IDirectDrawImpl *This);
124 HRESULT (*set_exclusive_mode)(IDirectDrawImpl *This, DWORD dwExcl);
126 HRESULT (*create_palette)(IDirectDrawImpl* This, DWORD dwFlags,
127 LPDIRECTDRAWPALETTE* ppPalette,
128 LPUNKNOWN pUnkOuter);
130 /* Surface creation functions. For all of these, pOuter == NULL. */
132 /* Do not create any backbuffers or the flipping chain. */
133 HRESULT (*create_primary)(IDirectDrawImpl* This,
134 const DDSURFACEDESC2* pDDSD,
135 LPDIRECTDRAWSURFACE7* ppSurf, LPUNKNOWN pOuter);
137 /* Primary may be NULL if we are creating an unattached backbuffer. */
138 HRESULT (*create_backbuffer)(IDirectDrawImpl* This,
139 const DDSURFACEDESC2* pDDSD,
140 LPDIRECTDRAWSURFACE7* ppSurf,
142 IDirectDrawSurfaceImpl* primary);
144 /* shiny happy offscreenplain surfaces */
145 HRESULT (*create_offscreen)(IDirectDrawImpl* This,
146 const DDSURFACEDESC2* pDDSD,
147 LPDIRECTDRAWSURFACE7* ppSurf,
150 /* dwMipMapLevel is specified as per OpenGL. (i.e. 0 is base) */
151 HRESULT (*create_texture)(IDirectDrawImpl* This,
152 const DDSURFACEDESC2* pDDSD,
153 LPDIRECTDRAWSURFACE7* ppSurf, LPUNKNOWN pOuter,
154 DWORD dwMipMapLevel);
156 HRESULT (*create_zbuffer)(IDirectDrawImpl* This,
157 const DDSURFACEDESC2* pDDSD,
158 LPDIRECTDRAWSURFACE7* ppSurf, LPUNKNOWN pOuter);
162 /* Everything below here is still questionable. */
164 DDPIXELFORMAT screen_pixelformat;
167 pixel_convert_func pixel_convert;
168 palette_convert_func palette_convert;
170 /* Use to fool some too strict games */
171 INT32 (*allocate_memory)(IDirectDrawImpl *This, DWORD mem);
172 void (*free_memory)(IDirectDrawImpl *This, DWORD mem);
173 DWORD total_vidmem, available_vidmem;
175 /* IDirect3D fields */
178 /* Used as a callback function to create a texture */
179 HRESULT (*d3d_create_texture)(IDirectDrawImpl *d3d, IDirectDrawSurfaceImpl *tex, BOOLEAN at_creation, IDirectDrawSurfaceImpl *main);
181 /* Used as a callback for Devices to tell to the D3D object it's been created */
182 HRESULT (*d3d_added_device)(IDirectDrawImpl *d3d, IDirect3DDeviceImpl *device);
183 HRESULT (*d3d_removed_device)(IDirectDrawImpl *d3d, IDirect3DDeviceImpl *device);
185 /* This is needed for delayed texture creation and Z buffer blits */
186 IDirect3DDeviceImpl *current_device;
188 /* This is for the fake mainWindow */
194 /*****************************************************************************
195 * IDirectDrawPalette implementation structure
197 struct IDirectDrawPaletteImpl
199 /* IUnknown fields */
200 ICOM_VFIELD_MULTI(IDirectDrawPalette);
203 DDRAWI_DDRAWPALETTE_LCL local;
204 DDRAWI_DDRAWPALETTE_GBL global;
206 /* IDirectDrawPalette fields */
208 WORD palVersion, palNumEntries; /* LOGPALETTE */
209 PALETTEENTRY palents[256];
210 /* This is to store the palette in 'screen format' */
211 int screen_palents[256];
213 VOID (*final_release)(IDirectDrawPaletteImpl* This);
215 IDirectDrawImpl* ddraw_owner;
216 IDirectDrawPaletteImpl* prev_ddraw;
217 IDirectDrawPaletteImpl* next_ddraw;
222 /*****************************************************************************
223 * IDirectDrawClipper implementation structure
225 struct IDirectDrawClipperImpl
227 /* IUnknown fields */
228 ICOM_VFIELD_MULTI(IDirectDrawClipper);
231 /* IDirectDrawClipper fields */
234 IDirectDrawImpl* ddraw_owner;
235 IDirectDrawClipperImpl* prev_ddraw;
236 IDirectDrawClipperImpl* next_ddraw;
239 /*****************************************************************************
240 * IDirectDrawSurface implementation structure
243 struct IDirectDrawSurfaceImpl
245 /* IUnknown fields */
246 ICOM_VFIELD_MULTI(IDirectDrawSurface7);
247 ICOM_VFIELD_MULTI(IDirectDrawSurface3);
248 ICOM_VFIELD_MULTI(IDirectDrawGammaControl);
249 ICOM_VFIELD_MULTI(IDirect3DTexture2);
250 ICOM_VFIELD_MULTI(IDirect3DTexture);
253 struct IDirectDrawSurfaceImpl* attached; /* attached surfaces */
255 struct IDirectDrawSurfaceImpl* next_ddraw; /* ddraw surface chain */
256 struct IDirectDrawSurfaceImpl* prev_ddraw;
257 struct IDirectDrawSurfaceImpl* next_attached; /* attached surface chain */
258 struct IDirectDrawSurfaceImpl* prev_attached;
260 IDirectDrawImpl* ddraw_owner;
261 IDirectDrawSurfaceImpl* surface_owner;
263 IDirectDrawPaletteImpl* palette; /* strong ref */
264 IDirectDrawClipperImpl* clipper; /* strong ref */
266 DDRAWI_DDRAWSURFACE_LCL local;
267 DDRAWI_DDRAWSURFACE_MORE more;
268 /* FIXME: since Flip should swap the GBL structures, they should
269 * probably not be embedded into the IDirectDrawSurfaceImpl structure... */
270 LPDDRAWI_DDRAWSURFACE_GBL_MORE gmore;
271 DDRAWI_DDRAWSURFACE_GBL global;
272 DDRAWI_DDRAWSURFACE_GBL_MORE global_more;
274 DDSURFACEDESC2 surface_desc;
281 HRESULT (*duplicate_surface)(IDirectDrawSurfaceImpl* src,
282 LPDIRECTDRAWSURFACE7* dst);
283 void (*final_release)(IDirectDrawSurfaceImpl *This);
284 HRESULT (*late_allocate)(IDirectDrawSurfaceImpl *This);
285 BOOL (*attach)(IDirectDrawSurfaceImpl *This, IDirectDrawSurfaceImpl *to);
286 BOOL (*detach)(IDirectDrawSurfaceImpl *This);
287 void (*lock_update)(IDirectDrawSurfaceImpl* This, LPCRECT pRect, DWORD dwFlags);
288 void (*unlock_update)(IDirectDrawSurfaceImpl* This, LPCRECT pRect);
289 void (*lose_surface)(IDirectDrawSurfaceImpl* This);
290 BOOL (*flip_data)(IDirectDrawSurfaceImpl* front,
291 IDirectDrawSurfaceImpl* back,
293 void (*flip_update)(IDirectDrawSurfaceImpl* front, DWORD dwFlags);
294 HRESULT (*get_dc)(IDirectDrawSurfaceImpl* This, HDC* phDC);
295 HRESULT (*release_dc)(IDirectDrawSurfaceImpl* This, HDC hDC);
296 void (*set_palette)(IDirectDrawSurfaceImpl* This, IDirectDrawPaletteImpl* pal);
297 void (*update_palette)(IDirectDrawSurfaceImpl* This, IDirectDrawPaletteImpl* pal,
298 DWORD dwStart, DWORD dwCount, LPPALETTEENTRY palent);
299 HWND (*get_display_window)(IDirectDrawSurfaceImpl *This);
300 HRESULT (*get_gamma_ramp)(IDirectDrawSurfaceImpl *This, DWORD dwFlags, LPDDGAMMARAMP lpGammaRamp);
301 HRESULT (*set_gamma_ramp)(IDirectDrawSurfaceImpl *This, DWORD dwFlags, LPDDGAMMARAMP lpGammaRamp);
303 struct PrivateData* private_data;
310 DWORD uniqueness_value;
314 /* Everything below here is dodgy. */
315 /* For Direct3D use */
316 LPVOID aux_ctx, aux_data;
317 void (*aux_release)(LPVOID ctx, LPVOID data);
318 BOOL (*aux_flip)(LPVOID ctx, LPVOID data);
319 void (*aux_unlock)(LPVOID ctx, LPVOID data, LPRECT lpRect);
320 HRESULT (*aux_blt)(struct IDirectDrawSurfaceImpl *This, LPRECT rdst, LPDIRECTDRAWSURFACE7 src, LPRECT rsrc, DWORD dwFlags, LPDDBLTFX lpbltfx);
321 HRESULT (*aux_bltfast)(struct IDirectDrawSurfaceImpl *This, DWORD dstx, DWORD dsty, LPDIRECTDRAWSURFACE7 src, LPRECT rsrc, DWORD trans);
322 HRESULT (*aux_setcolorkey_cb)(struct IDirectDrawSurfaceImpl *texture, DWORD dwFlags, LPDDCOLORKEY ckey );
323 /* This is to get the D3DDevice object associated to this surface */
324 struct IDirect3DDeviceImpl *d3ddevice;
325 /* This is for texture */
326 IDirectDrawSurfaceImpl *mip_main;
329 void (*lock_update_prev)(IDirectDrawSurfaceImpl* This, LPCRECT pRect, DWORD dwFlags);
330 void (*unlock_update_prev)(IDirectDrawSurfaceImpl* This, LPCRECT pRect);
331 BOOLEAN (*get_dirty_status)(IDirectDrawSurfaceImpl* This, LPCRECT pRect);
334 /*****************************************************************************
335 * Driver initialisation functions.
337 BOOL DDRAW_HAL_Init(HINSTANCE, DWORD, LPVOID);
338 BOOL DDRAW_User_Init(HINSTANCE, DWORD, LPVOID);
341 const DDDEVICEIDENTIFIER2* info;
342 int preference; /* how good we are. dga might get 100, xlib 50*/
343 HRESULT (*create)(const GUID*, LPDIRECTDRAW7*, LPUNKNOWN, BOOL ex);
345 /* For IDirectDraw7::Initialize. */
346 HRESULT (*init)(IDirectDrawImpl *, const GUID*);
349 void DDRAW_register_driver(const ddraw_driver*);
351 const ddraw_driver* DDRAW_FindDriver(const GUID* guid);
353 /******************************************************************************
357 /* Get DDSCAPS of surface (shortcutmacro) */
358 #define SDDSCAPS(iface) ((iface)->s.surface_desc.ddsCaps.dwCaps)
359 /* Get the number of bytes per pixel for a given surface */
360 #define PFGET_BPP(pf) (pf.dwFlags&DDPF_PALETTEINDEXED8?1:((pf.u1.dwRGBBitCount+7)/8))
361 #define GET_BPP(desc) PFGET_BPP(desc.u4.ddpfPixelFormat)
363 LONG DDRAW_width_bpp_to_pitch(DWORD width, DWORD bpp);
366 unsigned short bpp,depth;
367 unsigned int rmask,gmask,bmask;
371 void (*pixel_convert)(void *src, void *dst, DWORD width, DWORD height, LONG pitch, IDirectDrawPaletteImpl* palette);
372 void (*palette_convert)(LPPALETTEENTRY palent, void *screen_palette, DWORD start, DWORD count);
376 ConvertMode screen, dest;
380 extern Convert ModeEmulations[8];
381 extern int _common_depth_to_pixelformat(DWORD depth,LPDIRECTDRAW ddraw);
382 extern BOOL opengl_initialized;
383 extern BOOL s3tc_initialized;
385 typedef void (*FUNC_FETCH_2D_TEXEL_RGBA_DXT1)(int srcRowStride, const BYTE *pixdata, int i, int j, void *texel);
386 typedef void (*FUNC_FETCH_2D_TEXEL_RGBA_DXT3)(int srcRowStride, const BYTE *pixdata, int i, int j, void *texel);
387 typedef void (*FUNC_FETCH_2D_TEXEL_RGBA_DXT5)(int srcRowStride, const BYTE *pixdata, int i, int j, void *texel);
389 extern FUNC_FETCH_2D_TEXEL_RGBA_DXT1 fetch_2d_texel_rgba_dxt1;
390 extern FUNC_FETCH_2D_TEXEL_RGBA_DXT3 fetch_2d_texel_rgba_dxt3;
391 extern FUNC_FETCH_2D_TEXEL_RGBA_DXT5 fetch_2d_texel_rgba_dxt5;
393 /******************************************************************************
394 * Structure conversion (for thunks)
396 void DDRAW_Convert_DDSCAPS_1_To_2(const DDSCAPS* pIn, DDSCAPS2* pOut);
397 void DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(const DDDEVICEIDENTIFIER2* pIn,
398 DDDEVICEIDENTIFIER* pOut);
400 /******************************************************************************
401 * Debugging / Flags output functions
403 extern void DDRAW_dump_DDBLTFX(DWORD flagmask);
404 extern void DDRAW_dump_DDBLTFAST(DWORD flagmask);
405 extern void DDRAW_dump_DDBLT(DWORD flagmask);
406 extern void DDRAW_dump_DDSCAPS(const DDSCAPS *in);
407 extern void DDRAW_dump_DDSCAPS2(const DDSCAPS2 *in);
408 extern void DDRAW_dump_pixelformat_flag(DWORD flagmask);
409 extern void DDRAW_dump_paletteformat(DWORD dwFlags);
410 extern void DDRAW_dump_pixelformat(const DDPIXELFORMAT *in);
411 extern void DDRAW_dump_colorkeyflag(DWORD ck);
412 extern void DDRAW_dump_surface_desc(const DDSURFACEDESC2 *lpddsd);
413 extern void DDRAW_dump_cooperativelevel(DWORD cooplevel);
414 extern void DDRAW_dump_lockflag(DWORD lockflag);
415 extern void DDRAW_dump_DDCOLORKEY(const DDCOLORKEY *in);
416 extern void DDRAW_dump_DDCAPS(const DDCAPS *lpcaps);
417 extern void DDRAW_dump_surface_to_disk(IDirectDrawSurfaceImpl *surface, FILE *f, int scale) ;
419 /* Used for generic dumping */
426 #define FE(x) { x, #x }
432 void (*func)(const void *);
436 #define DDRAW_dump_flags(flags,names,num_names) DDRAW_dump_flags_(flags, names, num_names, 1)
437 #define ME(x,f,e) { x, #x, (void (*)(const void *))(f), offsetof(STRUCT, e) }
439 extern void DDRAW_dump_flags_(DWORD flags, const flag_info* names, size_t num_names, int newline);
440 extern void DDRAW_dump_members(DWORD flags, const void* data, const member_info* mems, size_t num_mems);
442 #endif /* __WINE_DLLS_DDRAW_DDRAW_PRIVATE_H */