Fix obviously wrong condition in an "if" statement.
[wine/wine-kai.git] / dlls / ddraw / ddraw_private.h
blobb583dae4d82e36fffdf4744b955868ae7fd314e3
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;
115 /* Should each of these go into some structure? */
116 DWORD orig_width, orig_height;
117 LONG orig_pitch;
118 DDPIXELFORMAT orig_pixelformat;
120 /* Called when the refcount goes to 0. */
121 void (*final_release)(IDirectDrawImpl *This);
123 HRESULT (*set_exclusive_mode)(IDirectDrawImpl *This, DWORD dwExcl);
125 HRESULT (*create_palette)(IDirectDrawImpl* This, DWORD dwFlags,
126 LPDIRECTDRAWPALETTE* ppPalette,
127 LPUNKNOWN pUnkOuter);
129 /* Surface creation functions. For all of these, pOuter == NULL. */
131 /* Do not create any backbuffers or the flipping chain. */
132 HRESULT (*create_primary)(IDirectDrawImpl* This,
133 const DDSURFACEDESC2* pDDSD,
134 LPDIRECTDRAWSURFACE7* ppSurf, LPUNKNOWN pOuter);
136 /* Primary may be NULL if we are creating an unattached backbuffer. */
137 HRESULT (*create_backbuffer)(IDirectDrawImpl* This,
138 const DDSURFACEDESC2* pDDSD,
139 LPDIRECTDRAWSURFACE7* ppSurf,
140 LPUNKNOWN pOuter,
141 IDirectDrawSurfaceImpl* primary);
143 /* shiny happy offscreenplain surfaces */
144 HRESULT (*create_offscreen)(IDirectDrawImpl* This,
145 const DDSURFACEDESC2* pDDSD,
146 LPDIRECTDRAWSURFACE7* ppSurf,
147 LPUNKNOWN pOuter);
149 /* dwMipMapLevel is specified as per OpenGL. (i.e. 0 is base) */
150 HRESULT (*create_texture)(IDirectDrawImpl* This,
151 const DDSURFACEDESC2* pDDSD,
152 LPDIRECTDRAWSURFACE7* ppSurf, LPUNKNOWN pOuter,
153 DWORD dwMipMapLevel);
155 HRESULT (*create_zbuffer)(IDirectDrawImpl* This,
156 const DDSURFACEDESC2* pDDSD,
157 LPDIRECTDRAWSURFACE7* ppSurf, LPUNKNOWN pOuter);
159 LPVOID private;
161 /* Everything below here is still questionable. */
163 DDPIXELFORMAT screen_pixelformat;
165 int pixmap_depth;
166 pixel_convert_func pixel_convert;
167 palette_convert_func palette_convert;
169 /* Use to fool some too strict games */
170 INT32 (*allocate_memory)(IDirectDrawImpl *This, DWORD mem);
171 void (*free_memory)(IDirectDrawImpl *This, DWORD mem);
172 DWORD total_vidmem, available_vidmem;
174 /* IDirect3D fields */
175 LPVOID d3d_private;
177 /* Used as a callback function to create a texture */
178 HRESULT (*d3d_create_texture)(IDirectDrawImpl *d3d, IDirectDrawSurfaceImpl *tex, BOOLEAN at_creation, IDirectDrawSurfaceImpl *main);
180 /* Used as a callback for Devices to tell to the D3D object it's been created */
181 HRESULT (*d3d_added_device)(IDirectDrawImpl *d3d, IDirect3DDeviceImpl *device);
182 HRESULT (*d3d_removed_device)(IDirectDrawImpl *d3d, IDirect3DDeviceImpl *device);
184 /* This is needed for delayed texture creation and Z buffer blits */
185 IDirect3DDeviceImpl *current_device;
187 /* This is for the fake mainWindow */
188 ATOM winclass;
189 PAINTSTRUCT ps;
190 BOOL paintable;
193 /*****************************************************************************
194 * IDirectDrawPalette implementation structure
196 struct IDirectDrawPaletteImpl
198 /* IUnknown fields */
199 ICOM_VFIELD_MULTI(IDirectDrawPalette);
200 DWORD ref;
202 DDRAWI_DDRAWPALETTE_LCL local;
203 DDRAWI_DDRAWPALETTE_GBL global;
205 /* IDirectDrawPalette fields */
206 HPALETTE hpal;
207 WORD palVersion, palNumEntries; /* LOGPALETTE */
208 PALETTEENTRY palents[256];
209 /* This is to store the palette in 'screen format' */
210 int screen_palents[256];
212 VOID (*final_release)(IDirectDrawPaletteImpl* This);
214 IDirectDrawImpl* ddraw_owner;
215 IDirectDrawPaletteImpl* prev_ddraw;
216 IDirectDrawPaletteImpl* next_ddraw;
218 LPVOID private;
221 /*****************************************************************************
222 * IDirectDrawClipper implementation structure
224 struct IDirectDrawClipperImpl
226 /* IUnknown fields */
227 ICOM_VFIELD_MULTI(IDirectDrawClipper);
228 DWORD ref;
230 /* IDirectDrawClipper fields */
231 HWND hWnd;
233 IDirectDrawImpl* ddraw_owner;
234 IDirectDrawClipperImpl* prev_ddraw;
235 IDirectDrawClipperImpl* next_ddraw;
238 /*****************************************************************************
239 * IDirectDrawSurface implementation structure
242 struct IDirectDrawSurfaceImpl
244 /* IUnknown fields */
245 ICOM_VFIELD_MULTI(IDirectDrawSurface7);
246 ICOM_VFIELD_MULTI(IDirectDrawSurface3);
247 ICOM_VFIELD_MULTI(IDirectDrawGammaControl);
248 ICOM_VFIELD_MULTI(IDirect3DTexture2);
249 ICOM_VFIELD_MULTI(IDirect3DTexture);
250 DWORD ref;
252 struct IDirectDrawSurfaceImpl* attached; /* attached surfaces */
254 struct IDirectDrawSurfaceImpl* next_ddraw; /* ddraw surface chain */
255 struct IDirectDrawSurfaceImpl* prev_ddraw;
256 struct IDirectDrawSurfaceImpl* next_attached; /* attached surface chain */
257 struct IDirectDrawSurfaceImpl* prev_attached;
259 IDirectDrawImpl* ddraw_owner;
260 IDirectDrawSurfaceImpl* surface_owner;
262 IDirectDrawPaletteImpl* palette; /* strong ref */
263 IDirectDrawClipperImpl* clipper; /* strong ref */
265 DDRAWI_DDRAWSURFACE_LCL local;
266 DDRAWI_DDRAWSURFACE_MORE more;
267 /* FIXME: since Flip should swap the GBL structures, they should
268 * probably not be embedded into the IDirectDrawSurfaceImpl structure... */
269 LPDDRAWI_DDRAWSURFACE_GBL_MORE gmore;
270 DDRAWI_DDRAWSURFACE_GBL global;
271 DDRAWI_DDRAWSURFACE_GBL_MORE global_more;
273 DDSURFACEDESC2 surface_desc;
275 HDC hDC;
276 RECT lastlockrect;
277 DWORD lastlocktype;
278 BOOL dc_in_use;
280 HRESULT (*duplicate_surface)(IDirectDrawSurfaceImpl* src,
281 LPDIRECTDRAWSURFACE7* dst);
282 void (*final_release)(IDirectDrawSurfaceImpl *This);
283 HRESULT (*late_allocate)(IDirectDrawSurfaceImpl *This);
284 BOOL (*attach)(IDirectDrawSurfaceImpl *This, IDirectDrawSurfaceImpl *to);
285 BOOL (*detach)(IDirectDrawSurfaceImpl *This);
286 void (*lock_update)(IDirectDrawSurfaceImpl* This, LPCRECT pRect, DWORD dwFlags);
287 void (*unlock_update)(IDirectDrawSurfaceImpl* This, LPCRECT pRect);
288 void (*lose_surface)(IDirectDrawSurfaceImpl* This);
289 BOOL (*flip_data)(IDirectDrawSurfaceImpl* front,
290 IDirectDrawSurfaceImpl* back,
291 DWORD dwFlags);
292 void (*flip_update)(IDirectDrawSurfaceImpl* front, DWORD dwFlags);
293 HRESULT (*get_dc)(IDirectDrawSurfaceImpl* This, HDC* phDC);
294 HRESULT (*release_dc)(IDirectDrawSurfaceImpl* This, HDC hDC);
295 void (*set_palette)(IDirectDrawSurfaceImpl* This, IDirectDrawPaletteImpl* pal);
296 void (*update_palette)(IDirectDrawSurfaceImpl* This, IDirectDrawPaletteImpl* pal,
297 DWORD dwStart, DWORD dwCount, LPPALETTEENTRY palent);
298 HWND (*get_display_window)(IDirectDrawSurfaceImpl *This);
299 HRESULT (*get_gamma_ramp)(IDirectDrawSurfaceImpl *This, DWORD dwFlags, LPDDGAMMARAMP lpGammaRamp);
300 HRESULT (*set_gamma_ramp)(IDirectDrawSurfaceImpl *This, DWORD dwFlags, LPDDGAMMARAMP lpGammaRamp);
302 struct PrivateData* private_data;
304 DWORD max_lod;
305 DWORD priority;
307 BOOL lost;
309 DWORD uniqueness_value;
311 LPVOID private;
313 /* Everything below here is dodgy. */
314 /* For Direct3D use */
315 LPVOID aux_ctx, aux_data;
316 void (*aux_release)(LPVOID ctx, LPVOID data);
317 BOOL (*aux_flip)(LPVOID ctx, LPVOID data);
318 void (*aux_unlock)(LPVOID ctx, LPVOID data, LPRECT lpRect);
319 HRESULT (*aux_blt)(struct IDirectDrawSurfaceImpl *This, LPRECT rdst, LPDIRECTDRAWSURFACE7 src, LPRECT rsrc, DWORD dwFlags, LPDDBLTFX lpbltfx);
320 HRESULT (*aux_bltfast)(struct IDirectDrawSurfaceImpl *This, DWORD dstx, DWORD dsty, LPDIRECTDRAWSURFACE7 src, LPRECT rsrc, DWORD trans);
321 HRESULT (*aux_setcolorkey_cb)(struct IDirectDrawSurfaceImpl *texture, DWORD dwFlags, LPDDCOLORKEY ckey );
322 /* This is to get the D3DDevice object associated to this surface */
323 struct IDirect3DDeviceImpl *d3ddevice;
324 /* This is for texture */
325 IDirectDrawSurfaceImpl *mip_main;
326 int mipmap_level;
327 LPVOID tex_private;
328 void (*lock_update_prev)(IDirectDrawSurfaceImpl* This, LPCRECT pRect, DWORD dwFlags);
329 void (*unlock_update_prev)(IDirectDrawSurfaceImpl* This, LPCRECT pRect);
330 BOOLEAN (*get_dirty_status)(IDirectDrawSurfaceImpl* This, LPCRECT pRect);
333 /*****************************************************************************
334 * Driver initialisation functions.
336 BOOL DDRAW_HAL_Init(HINSTANCE, DWORD, LPVOID);
337 BOOL DDRAW_User_Init(HINSTANCE, DWORD, LPVOID);
339 typedef struct {
340 const DDDEVICEIDENTIFIER2* info;
341 int preference; /* how good we are. dga might get 100, xlib 50*/
342 HRESULT (*create)(const GUID*, LPDIRECTDRAW7*, LPUNKNOWN, BOOL ex);
344 /* For IDirectDraw7::Initialize. */
345 HRESULT (*init)(IDirectDrawImpl *, const GUID*);
346 } ddraw_driver;
348 void DDRAW_register_driver(const ddraw_driver*);
350 const ddraw_driver* DDRAW_FindDriver(const GUID* guid);
352 /******************************************************************************
353 * Random utilities
356 /* Get DDSCAPS of surface (shortcutmacro) */
357 #define SDDSCAPS(iface) ((iface)->s.surface_desc.ddsCaps.dwCaps)
358 /* Get the number of bytes per pixel for a given surface */
359 #define PFGET_BPP(pf) (pf.dwFlags&DDPF_PALETTEINDEXED8?1:((pf.u1.dwRGBBitCount+7)/8))
360 #define GET_BPP(desc) PFGET_BPP(desc.u4.ddpfPixelFormat)
362 LONG DDRAW_width_bpp_to_pitch(DWORD width, DWORD bpp);
364 typedef struct {
365 unsigned short bpp,depth;
366 unsigned int rmask,gmask,bmask;
367 } ConvertMode;
369 typedef struct {
370 void (*pixel_convert)(void *src, void *dst, DWORD width, DWORD height, LONG pitch, IDirectDrawPaletteImpl* palette);
371 void (*palette_convert)(LPPALETTEENTRY palent, void *screen_palette, DWORD start, DWORD count);
372 } ConvertFuncs;
374 typedef struct {
375 ConvertMode screen, dest;
376 ConvertFuncs funcs;
377 } Convert;
379 extern Convert ModeEmulations[8];
380 extern int _common_depth_to_pixelformat(DWORD depth,LPDIRECTDRAW ddraw);
381 extern BOOL opengl_initialized;
382 extern BOOL s3tc_initialized;
384 typedef void (*FUNC_FETCH_2D_TEXEL_RGBA_DXT1)(int srcRowStride, const BYTE *pixdata, int i, int j, void *texel);
385 typedef void (*FUNC_FETCH_2D_TEXEL_RGBA_DXT3)(int srcRowStride, const BYTE *pixdata, int i, int j, void *texel);
386 typedef void (*FUNC_FETCH_2D_TEXEL_RGBA_DXT5)(int srcRowStride, const BYTE *pixdata, int i, int j, void *texel);
388 extern FUNC_FETCH_2D_TEXEL_RGBA_DXT1 fetch_2d_texel_rgba_dxt1;
389 extern FUNC_FETCH_2D_TEXEL_RGBA_DXT3 fetch_2d_texel_rgba_dxt3;
390 extern FUNC_FETCH_2D_TEXEL_RGBA_DXT5 fetch_2d_texel_rgba_dxt5;
392 /******************************************************************************
393 * Structure conversion (for thunks)
395 void DDRAW_Convert_DDSCAPS_1_To_2(const DDSCAPS* pIn, DDSCAPS2* pOut);
396 void DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(const DDDEVICEIDENTIFIER2* pIn,
397 DDDEVICEIDENTIFIER* pOut);
399 /******************************************************************************
400 * Debugging / Flags output functions
402 extern void DDRAW_dump_DDBLTFX(DWORD flagmask);
403 extern void DDRAW_dump_DDBLTFAST(DWORD flagmask);
404 extern void DDRAW_dump_DDBLT(DWORD flagmask);
405 extern void DDRAW_dump_DDSCAPS(const DDSCAPS *in);
406 extern void DDRAW_dump_DDSCAPS2(const DDSCAPS2 *in);
407 extern void DDRAW_dump_pixelformat_flag(DWORD flagmask);
408 extern void DDRAW_dump_paletteformat(DWORD dwFlags);
409 extern void DDRAW_dump_pixelformat(const DDPIXELFORMAT *in);
410 extern void DDRAW_dump_colorkeyflag(DWORD ck);
411 extern void DDRAW_dump_surface_desc(const DDSURFACEDESC2 *lpddsd);
412 extern void DDRAW_dump_cooperativelevel(DWORD cooplevel);
413 extern void DDRAW_dump_lockflag(DWORD lockflag);
414 extern void DDRAW_dump_DDCOLORKEY(const DDCOLORKEY *in);
415 extern void DDRAW_dump_DDCAPS(const DDCAPS *lpcaps);
416 extern void DDRAW_dump_surface_to_disk(IDirectDrawSurfaceImpl *surface, FILE *f, int scale) ;
418 /* Used for generic dumping */
419 typedef struct
421 DWORD val;
422 const char* name;
423 } flag_info;
425 #define FE(x) { x, #x }
427 typedef struct
429 DWORD val;
430 const char* name;
431 void (*func)(const void *);
432 ptrdiff_t offset;
433 } member_info;
435 #define DDRAW_dump_flags(flags,names,num_names) DDRAW_dump_flags_(flags, names, num_names, 1)
436 #define ME(x,f,e) { x, #x, (void (*)(const void *))(f), offsetof(STRUCT, e) }
438 extern void DDRAW_dump_flags_(DWORD flags, const flag_info* names, size_t num_names, int newline);
439 extern void DDRAW_dump_members(DWORD flags, const void* data, const member_info* mems, size_t num_mems);
441 #endif /* __WINE_DLLS_DDRAW_DDRAW_PRIVATE_H */