WTSFreeMemory stub.
[wine/hacks.git] / dlls / ddraw / ddraw_private.h
blob56da36629d489cddd6d2372c60fd1c1f9932d20a
1 /*
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! */
24 #include <stdarg.h>
25 #include <stdio.h>
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"
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)
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)
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,
76 DWORD count);
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);
89 DWORD ref;
91 /* TRUE if created via DirectDrawCreateEx or CoCreateInstance,
92 * FALSE if created via DirectDrawCreate. */
93 BOOL ex;
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;
105 DDCAPS caps;
107 HWND window;
108 DWORD cooperative_level;
109 WNDPROC original_wndproc;
111 DWORD width, height;
112 LONG pitch;
113 DDPIXELFORMAT pixelformat;
114 DWORD cur_scanline;
116 /* Should each of these go into some structure? */
117 DWORD orig_width, orig_height;
118 LONG orig_pitch;
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,
141 LPUNKNOWN pOuter,
142 IDirectDrawSurfaceImpl* primary);
144 /* shiny happy offscreenplain surfaces */
145 HRESULT (*create_offscreen)(IDirectDrawImpl* This,
146 const DDSURFACEDESC2* pDDSD,
147 LPDIRECTDRAWSURFACE7* ppSurf,
148 LPUNKNOWN pOuter);
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);
160 LPVOID private;
162 /* Everything below here is still questionable. */
164 DDPIXELFORMAT screen_pixelformat;
166 int pixmap_depth;
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 */
176 LPVOID d3d_private;
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 */
189 ATOM winclass;
190 PAINTSTRUCT ps;
191 BOOL paintable;
194 /*****************************************************************************
195 * IDirectDrawPalette implementation structure
197 struct IDirectDrawPaletteImpl
199 /* IUnknown fields */
200 ICOM_VFIELD_MULTI(IDirectDrawPalette);
201 DWORD ref;
203 DDRAWI_DDRAWPALETTE_LCL local;
204 DDRAWI_DDRAWPALETTE_GBL global;
206 /* IDirectDrawPalette fields */
207 HPALETTE hpal;
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;
219 LPVOID private;
222 /*****************************************************************************
223 * IDirectDrawClipper implementation structure
225 struct IDirectDrawClipperImpl
227 /* IUnknown fields */
228 ICOM_VFIELD_MULTI(IDirectDrawClipper);
229 DWORD ref;
231 /* IDirectDrawClipper fields */
232 HWND hWnd;
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);
251 DWORD ref;
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;
276 HDC hDC;
277 RECT lastlockrect;
278 DWORD lastlocktype;
279 BOOL dc_in_use;
280 BOOL locked;
282 HRESULT (*duplicate_surface)(IDirectDrawSurfaceImpl* src,
283 LPDIRECTDRAWSURFACE7* dst);
284 void (*final_release)(IDirectDrawSurfaceImpl *This);
285 HRESULT (*late_allocate)(IDirectDrawSurfaceImpl *This);
286 BOOL (*attach)(IDirectDrawSurfaceImpl *This, IDirectDrawSurfaceImpl *to);
287 BOOL (*detach)(IDirectDrawSurfaceImpl *This);
288 void (*lock_update)(IDirectDrawSurfaceImpl* This, LPCRECT pRect, DWORD dwFlags);
289 void (*unlock_update)(IDirectDrawSurfaceImpl* This, LPCRECT pRect);
290 void (*lose_surface)(IDirectDrawSurfaceImpl* This);
291 BOOL (*flip_data)(IDirectDrawSurfaceImpl* front,
292 IDirectDrawSurfaceImpl* back,
293 DWORD dwFlags);
294 void (*flip_update)(IDirectDrawSurfaceImpl* front, DWORD dwFlags);
295 HRESULT (*get_dc)(IDirectDrawSurfaceImpl* This, HDC* phDC);
296 HRESULT (*release_dc)(IDirectDrawSurfaceImpl* This, HDC hDC);
297 void (*set_palette)(IDirectDrawSurfaceImpl* This, IDirectDrawPaletteImpl* pal);
298 void (*update_palette)(IDirectDrawSurfaceImpl* This, IDirectDrawPaletteImpl* pal,
299 DWORD dwStart, DWORD dwCount, LPPALETTEENTRY palent);
300 HWND (*get_display_window)(IDirectDrawSurfaceImpl *This);
301 HRESULT (*get_gamma_ramp)(IDirectDrawSurfaceImpl *This, DWORD dwFlags, LPDDGAMMARAMP lpGammaRamp);
302 HRESULT (*set_gamma_ramp)(IDirectDrawSurfaceImpl *This, DWORD dwFlags, LPDDGAMMARAMP lpGammaRamp);
304 struct PrivateData* private_data;
306 DWORD max_lod;
307 DWORD priority;
309 BOOL lost;
311 DWORD uniqueness_value;
313 LPVOID private;
315 /* Everything below here is dodgy. */
316 /* For Direct3D use */
317 LPVOID aux_ctx, aux_data;
318 void (*aux_release)(LPVOID ctx, LPVOID data);
319 BOOL (*aux_flip)(LPVOID ctx, LPVOID data);
320 void (*aux_unlock)(LPVOID ctx, LPVOID data, LPRECT lpRect);
321 HRESULT (*aux_blt)(struct IDirectDrawSurfaceImpl *This, LPRECT rdst, LPDIRECTDRAWSURFACE7 src, LPRECT rsrc, DWORD dwFlags, LPDDBLTFX lpbltfx);
322 HRESULT (*aux_bltfast)(struct IDirectDrawSurfaceImpl *This, DWORD dstx, DWORD dsty, LPDIRECTDRAWSURFACE7 src, LPRECT rsrc, DWORD trans);
323 HRESULT (*aux_setcolorkey_cb)(struct IDirectDrawSurfaceImpl *texture, DWORD dwFlags, LPDDCOLORKEY ckey );
324 /* This is to get the D3DDevice object associated to this surface */
325 struct IDirect3DDeviceImpl *d3ddevice;
326 /* This is for texture */
327 IDirectDrawSurfaceImpl *mip_main;
328 int mipmap_level;
329 LPVOID tex_private;
330 void (*lock_update_prev)(IDirectDrawSurfaceImpl* This, LPCRECT pRect, DWORD dwFlags);
331 void (*unlock_update_prev)(IDirectDrawSurfaceImpl* This, LPCRECT pRect);
332 BOOLEAN (*get_dirty_status)(IDirectDrawSurfaceImpl* This, LPCRECT pRect);
335 /*****************************************************************************
336 * Driver initialisation functions.
338 BOOL DDRAW_HAL_Init(HINSTANCE, DWORD, LPVOID);
339 BOOL DDRAW_User_Init(HINSTANCE, DWORD, LPVOID);
341 typedef struct {
342 const DDDEVICEIDENTIFIER2* info;
343 int preference; /* how good we are. dga might get 100, xlib 50*/
344 HRESULT (*create)(const GUID*, LPDIRECTDRAW7*, LPUNKNOWN, BOOL ex);
346 /* For IDirectDraw7::Initialize. */
347 HRESULT (*init)(IDirectDrawImpl *, const GUID*);
348 } ddraw_driver;
350 void DDRAW_register_driver(const ddraw_driver*);
352 const ddraw_driver* DDRAW_FindDriver(const GUID* guid);
354 /******************************************************************************
355 * Random utilities
358 /* Get DDSCAPS of surface (shortcutmacro) */
359 #define SDDSCAPS(iface) ((iface)->s.surface_desc.ddsCaps.dwCaps)
360 /* Get the number of bytes per pixel for a given surface */
361 #define PFGET_BPP(pf) (pf.dwFlags&DDPF_PALETTEINDEXED8?1:((pf.u1.dwRGBBitCount+7)/8))
362 #define GET_BPP(desc) PFGET_BPP(desc.u4.ddpfPixelFormat)
364 LONG DDRAW_width_bpp_to_pitch(DWORD width, DWORD bpp);
366 typedef struct {
367 unsigned short bpp,depth;
368 unsigned int rmask,gmask,bmask;
369 } ConvertMode;
371 typedef struct {
372 void (*pixel_convert)(void *src, void *dst, DWORD width, DWORD height, LONG pitch, IDirectDrawPaletteImpl* palette);
373 void (*palette_convert)(LPPALETTEENTRY palent, void *screen_palette, DWORD start, DWORD count);
374 } ConvertFuncs;
376 typedef struct {
377 ConvertMode screen, dest;
378 ConvertFuncs funcs;
379 } Convert;
381 extern Convert ModeEmulations[8];
382 extern int _common_depth_to_pixelformat(DWORD depth,LPDIRECTDRAW ddraw);
383 extern BOOL opengl_initialized;
384 extern BOOL s3tc_initialized;
386 typedef void (*FUNC_FETCH_2D_TEXEL_RGBA_DXT1)(int srcRowStride, const BYTE *pixdata, int i, int j, void *texel);
387 typedef void (*FUNC_FETCH_2D_TEXEL_RGBA_DXT3)(int srcRowStride, const BYTE *pixdata, int i, int j, void *texel);
388 typedef void (*FUNC_FETCH_2D_TEXEL_RGBA_DXT5)(int srcRowStride, const BYTE *pixdata, int i, int j, void *texel);
390 extern FUNC_FETCH_2D_TEXEL_RGBA_DXT1 fetch_2d_texel_rgba_dxt1;
391 extern FUNC_FETCH_2D_TEXEL_RGBA_DXT3 fetch_2d_texel_rgba_dxt3;
392 extern FUNC_FETCH_2D_TEXEL_RGBA_DXT5 fetch_2d_texel_rgba_dxt5;
394 /******************************************************************************
395 * Structure conversion (for thunks)
397 void DDRAW_Convert_DDSCAPS_1_To_2(const DDSCAPS* pIn, DDSCAPS2* pOut);
398 void DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(const DDDEVICEIDENTIFIER2* pIn,
399 DDDEVICEIDENTIFIER* pOut);
401 /******************************************************************************
402 * Debugging / Flags output functions
404 extern void DDRAW_dump_DDBLTFX(DWORD flagmask);
405 extern void DDRAW_dump_DDBLTFAST(DWORD flagmask);
406 extern void DDRAW_dump_DDBLT(DWORD flagmask);
407 extern void DDRAW_dump_DDSCAPS(const DDSCAPS *in);
408 extern void DDRAW_dump_DDSCAPS2(const DDSCAPS2 *in);
409 extern void DDRAW_dump_pixelformat_flag(DWORD flagmask);
410 extern void DDRAW_dump_paletteformat(DWORD dwFlags);
411 extern void DDRAW_dump_pixelformat(const DDPIXELFORMAT *in);
412 extern void DDRAW_dump_colorkeyflag(DWORD ck);
413 extern void DDRAW_dump_surface_desc(const DDSURFACEDESC2 *lpddsd);
414 extern void DDRAW_dump_cooperativelevel(DWORD cooplevel);
415 extern void DDRAW_dump_lockflag(DWORD lockflag);
416 extern void DDRAW_dump_DDCOLORKEY(const DDCOLORKEY *in);
417 extern void DDRAW_dump_DDCAPS(const DDCAPS *lpcaps);
418 extern void DDRAW_dump_surface_to_disk(IDirectDrawSurfaceImpl *surface, FILE *f, int scale) ;
420 /* Used for generic dumping */
421 typedef struct
423 DWORD val;
424 const char* name;
425 } flag_info;
427 #define FE(x) { x, #x }
429 typedef struct
431 DWORD val;
432 const char* name;
433 void (*func)(const void *);
434 ptrdiff_t offset;
435 } member_info;
437 #define DDRAW_dump_flags(flags,names,num_names) DDRAW_dump_flags_(flags, names, num_names, 1)
438 #define ME(x,f,e) { x, #x, (void (*)(const void *))(f), offsetof(STRUCT, e) }
440 extern void DDRAW_dump_flags_(DWORD flags, const flag_info* names, size_t num_names, int newline);
441 extern void DDRAW_dump_members(DWORD flags, const void* data, const member_info* mems, size_t num_mems);
443 #endif /* __WINE_DLLS_DDRAW_DDRAW_PRIVATE_H */