ddraw: Do not crash when Clipper is NULL.
[wine] / dlls / ddraw / ddraw_private.h
1 /*
2  * Copyright 2006 Stefan Dösinger
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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 "ddrawi.h"
34 #include "d3d.h"
35
36 #include "ddcomimpl.h"
37
38 #include "wine/wined3d_interface.h"
39 #include "wine/list.h"
40
41 /*****************************************************************************
42  * IParent - a helper interface
43  *****************************************************************************/
44 DEFINE_GUID(IID_IParent, 0xc20e4c88, 0x74e7, 0x4940, 0xba, 0x9f, 0x2e, 0x32, 0x3f, 0x9d, 0xc9, 0x81);
45 typedef struct IParent *LPPARENT, *PPARENT;
46
47 #define INTERFACE IParent
48 DECLARE_INTERFACE_(IParent,IUnknown)
49 {
50     /*** IUnknown methods ***/
51     STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE;
52     STDMETHOD_(ULONG,AddRef)(THIS) PURE;
53     STDMETHOD_(ULONG,Release)(THIS) PURE;
54 };
55 #undef INTERFACE
56
57 #if !defined(__cplusplus) || defined(CINTERFACE)
58 /*** IUnknown methods ***/
59 #define IParent_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b)
60 #define IParent_AddRef(p)             (p)->lpVtbl->AddRef(p)
61 #define IParent_Release(p)            (p)->lpVtbl->Release(p)
62 #endif
63
64
65 /* Typdef the interfaces */
66 typedef struct IDirectDrawImpl            IDirectDrawImpl;
67 typedef struct IDirectDrawSurfaceImpl     IDirectDrawSurfaceImpl;
68 typedef struct IDirectDrawClipperImpl     IDirectDrawClipperImpl;
69 typedef struct IDirectDrawPaletteImpl     IDirectDrawPaletteImpl;
70 typedef struct IDirect3DDeviceImpl        IDirect3DDeviceImpl;
71 typedef struct IDirect3DLightImpl         IDirect3DLightImpl;
72 typedef struct IDirect3DViewportImpl      IDirect3DViewportImpl;
73 typedef struct IDirect3DMaterialImpl      IDirect3DMaterialImpl;
74 typedef struct IDirect3DExecuteBufferImpl IDirect3DExecuteBufferImpl;
75 typedef struct IDirect3DVertexBufferImpl  IDirect3DVertexBufferImpl;
76 typedef struct IParentImpl                IParentImpl;
77
78 /* Callbacks for implicit object destruction */
79 extern ULONG WINAPI D3D7CB_DestroySwapChain(IWineD3DSwapChain *pSwapChain);
80
81 extern ULONG WINAPI D3D7CB_DestroyDepthStencilSurface(IWineD3DSurface *pSurface);
82
83 /* Global critical section */
84 extern CRITICAL_SECTION ddraw_cs;
85
86 /*****************************************************************************
87  * IDirectDraw implementation structure
88  *****************************************************************************/
89 struct FvfToDecl
90 {
91     DWORD fvf;
92     IWineD3DVertexDeclaration *decl;
93 };
94
95 struct IDirectDrawImpl
96 {
97     /* IUnknown fields */
98     ICOM_VFIELD_MULTI(IDirectDraw7);
99     ICOM_VFIELD_MULTI(IDirectDraw4);
100     ICOM_VFIELD_MULTI(IDirectDraw3);
101     ICOM_VFIELD_MULTI(IDirectDraw2);
102     ICOM_VFIELD_MULTI(IDirectDraw);
103     ICOM_VFIELD_MULTI(IDirect3D7);
104     ICOM_VFIELD_MULTI(IDirect3D3);
105     ICOM_VFIELD_MULTI(IDirect3D2);
106     ICOM_VFIELD_MULTI(IDirect3D);
107
108     /* See comment in IDirectDraw::AddRef */
109     LONG                    ref7, ref4, ref2, ref3, ref1, numIfaces;
110
111     /* WineD3D linkage */
112     IWineD3D                *wineD3D;
113     IWineD3DDevice          *wineD3DDevice;
114     IDirectDrawSurfaceImpl  *DepthStencilBuffer;
115     BOOL                    d3d_initialized;
116
117     /* Misc ddraw fields */
118     UINT                    total_vidmem;
119     DWORD                   cur_scanline;
120     BOOL                    fake_vblank;
121     BOOL                    initialized;
122
123     /* DirectDraw things, which are not handled by WineD3D */
124     DWORD                   cooperative_level;
125
126     DWORD                   orig_width, orig_height;
127     DWORD                   orig_bpp;
128
129     DDCAPS                  caps;
130
131     /* D3D things */
132     IDirectDrawSurfaceImpl  *d3d_target;
133     HWND                    d3d_window;
134     IDirect3DDeviceImpl     *d3ddevice;
135     int                     d3dversion;
136
137     /* Various HWNDs */
138     HWND                    focuswindow;
139     HWND                    devicewindow;
140
141     /* The surface type to request */
142     WINED3DSURFTYPE         ImplType;
143
144
145     /* Our private window class */
146     char classname[32];
147     WNDCLASSA wnd_class;
148
149     /* Helpers for surface creation */
150     IDirectDrawSurfaceImpl *tex_root;
151     BOOL                    depthstencil;
152
153     /* For the dll unload cleanup code */
154     struct list ddraw_list_entry;
155     /* The surface list - can't relay this to WineD3D
156      * because of IParent
157      */
158     struct list surface_list;
159     LONG surfaces;
160
161     /* FVF management */
162     struct FvfToDecl       *decls;
163     UINT                    numConvertedDecls, declArraySize;
164 };
165
166 /* Declare the VTables. They can be found ddraw.c */
167 const IDirectDraw7Vtbl IDirectDraw7_Vtbl;
168 const IDirectDraw4Vtbl IDirectDraw4_Vtbl;
169 const IDirectDraw3Vtbl IDirectDraw3_Vtbl;
170 const IDirectDraw2Vtbl IDirectDraw2_Vtbl;
171 const IDirectDrawVtbl  IDirectDraw1_Vtbl;
172
173 /* Helper structures */
174 typedef struct EnumDisplayModesCBS
175 {
176     void *context;
177     LPDDENUMMODESCALLBACK2 callback;
178 } EnumDisplayModesCBS;
179
180 typedef struct EnumSurfacesCBS
181 {
182     void *context;
183     LPDDENUMSURFACESCALLBACK7 callback;
184     LPDDSURFACEDESC2 pDDSD;
185     DWORD Flags;
186 } EnumSurfacesCBS;
187
188 /* Utility functions */
189 void
190 DDRAW_Convert_DDSCAPS_1_To_2(const DDSCAPS* pIn,
191                              DDSCAPS2* pOut);
192 void
193 DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(const DDDEVICEIDENTIFIER2* pIn,
194                                         DDDEVICEIDENTIFIER* pOut);
195 void
196 IDirectDrawImpl_Destroy(IDirectDrawImpl *This);
197
198 HRESULT WINAPI
199 IDirectDrawImpl_RecreateSurfacesCallback(IDirectDrawSurface7 *surf,
200                                          DDSURFACEDESC2 *desc,
201                                          void *Context);
202 IWineD3DVertexDeclaration *
203 IDirectDrawImpl_FindDecl(IDirectDrawImpl *This,
204                          DWORD fvf);
205
206 /* The default surface type */
207 extern WINED3DSURFTYPE DefaultSurfaceType;
208
209 /*****************************************************************************
210  * IDirectDrawSurface implementation structure
211  *****************************************************************************/
212
213 struct IDirectDrawSurfaceImpl
214 {
215     /* IUnknown fields */
216     ICOM_VFIELD_MULTI(IDirectDrawSurface7);
217     ICOM_VFIELD_MULTI(IDirectDrawSurface3);
218     ICOM_VFIELD_MULTI(IDirectDrawGammaControl);
219     ICOM_VFIELD_MULTI(IDirect3DTexture2);
220     ICOM_VFIELD_MULTI(IDirect3DTexture);
221
222     LONG                     ref;
223     IUnknown                *ifaceToRelease;
224
225     int                     version;
226
227     /* Connections to other Objects */
228     IDirectDrawImpl         *ddraw;
229     IWineD3DSurface         *WineD3DSurface;
230     IWineD3DBaseTexture     *wineD3DTexture;
231
232     /* This implementation handles attaching surfaces to other surfaces */
233     IDirectDrawSurfaceImpl  *next_attached;
234     IDirectDrawSurfaceImpl  *first_attached;
235
236     /* Complex surfaces are organized in a tree, although the tree is degenerated to a list in most cases.
237      * In mipmap and primary surfaces each level has only one attachment, which is the next surface level.
238      * Only the cube texture root has 6 surfaces attached, which then have a normal mipmap chain attached
239      * to them. So hardcode the array to 6, a dynamic array or a list would be an overkill.
240      */
241 #define MAX_COMPLEX_ATTACHED 6
242     IDirectDrawSurfaceImpl  *complex_array[MAX_COMPLEX_ATTACHED];
243     /* You can't traverse the tree upwards. Only a flag for Surface::Release because its needed there,
244      * but no pointer to prevent temptations to traverse it in the wrong direction.
245      */
246     BOOL                    is_complex_root;
247
248     /* Surface description, for GetAttachedSurface */
249     DDSURFACEDESC2          surface_desc;
250
251     /* Misc things */
252     DWORD                   uniqueness_value;
253     UINT                    mipmap_level;
254     WINED3DSURFTYPE         ImplType;
255
256     /* For D3DDevice creation */
257     BOOL                    isRenderTarget;
258
259     /* Clipper objects */
260     IDirectDrawClipperImpl  *clipper;
261
262     /* For the ddraw surface list */
263     struct list             surface_list_entry;
264
265     DWORD                   Handle;
266 };
267
268 /* VTable declaration. It's located in surface.c / surface_thunks.c */
269 const IDirectDrawSurface7Vtbl IDirectDrawSurface7_Vtbl;
270 const IDirectDrawSurface3Vtbl IDirectDrawSurface3_Vtbl;
271 const IDirectDrawGammaControlVtbl IDirectDrawGammaControl_Vtbl;
272 const IDirect3DTexture2Vtbl IDirect3DTexture2_Vtbl;
273 const IDirect3DTextureVtbl IDirect3DTexture1_Vtbl;
274
275 HRESULT WINAPI IDirectDrawSurfaceImpl_AddAttachedSurface(IDirectDrawSurfaceImpl *This, IDirectDrawSurfaceImpl *Surf);
276
277 /* Get the number of bytes per pixel for a given surface */
278 #define PFGET_BPP(pf) (pf.dwFlags&DDPF_PALETTEINDEXED8?1:((pf.dwRGBBitCount+7)/8))
279 #define GET_BPP(desc) PFGET_BPP(desc.ddpfPixelFormat)
280
281 /*****************************************************************************
282  * IParent Implementation
283  *****************************************************************************/
284 struct IParentImpl
285 {
286     /* IUnknown fields */
287     ICOM_VFIELD_MULTI(IParent);
288     LONG                    ref;
289
290     /* IParentImpl fields */
291     IUnknown      *child;
292
293 };
294
295 const IParentVtbl IParent_Vtbl;
296
297 /*****************************************************************************
298  * IDirect3DDevice implementation
299  *****************************************************************************/
300 typedef enum
301 {
302     DDrawHandle_Unknown       = 0,
303     DDrawHandle_Texture       = 1,
304     DDrawHandle_Material      = 2,
305     DDrawHandle_Matrix        = 3,
306     DDrawHandle_StateBlock    = 4
307 } DDrawHandleTypes;
308
309 struct HandleEntry
310 {
311     void    *ptr;
312     DDrawHandleTypes      type;
313 };
314
315 struct IDirect3DDeviceImpl
316 {
317     /* IUnknown */
318     ICOM_VFIELD_MULTI(IDirect3DDevice7);
319     ICOM_VFIELD_MULTI(IDirect3DDevice3);
320     ICOM_VFIELD_MULTI(IDirect3DDevice2);
321     ICOM_VFIELD_MULTI(IDirect3DDevice);
322     LONG                    ref;
323
324     /* Other object connections */
325     IWineD3DDevice          *wineD3DDevice;
326     IDirectDrawImpl         *ddraw;
327     IWineD3DIndexBuffer     *indexbuffer;
328     IDirectDrawSurfaceImpl  *target;
329     BOOL                    OffScreenTarget;
330
331     /* Viewport management */
332     IDirect3DViewportImpl *viewport_list;
333     IDirect3DViewportImpl *current_viewport;
334     D3DVIEWPORT7 active_viewport;
335
336     /* Light state */
337     DWORD material;
338
339     /* Rendering functions to wrap D3D(1-3) to D3D7 */
340     D3DPRIMITIVETYPE primitive_type;
341     DWORD vertex_type;
342     DWORD render_flags;
343     DWORD nb_vertices;
344     LPBYTE vertex_buffer;
345     DWORD vertex_size;
346     DWORD buffer_size;
347
348     /* Handle management */
349     struct HandleEntry      *Handles;
350     DWORD                    numHandles;
351 };
352
353 /* Vtables in various versions */
354 const IDirect3DDevice7Vtbl IDirect3DDevice7_Vtbl;
355 const IDirect3DDevice3Vtbl IDirect3DDevice3_Vtbl;
356 const IDirect3DDevice2Vtbl IDirect3DDevice2_Vtbl;
357 const IDirect3DDeviceVtbl  IDirect3DDevice1_Vtbl;
358
359 /* The IID */
360 const GUID IID_D3DDEVICE_WineD3D;
361
362 /* Helper functions */
363 HRESULT IDirect3DImpl_GetCaps(IWineD3D *WineD3D, D3DDEVICEDESC *Desc123, D3DDEVICEDESC7 *Desc7);
364 DWORD IDirect3DDeviceImpl_CreateHandle(IDirect3DDeviceImpl *This);
365 WINED3DZBUFFERTYPE IDirect3DDeviceImpl_UpdateDepthStencil(IDirect3DDeviceImpl *This);
366
367 /* Structures */
368 struct EnumTextureFormatsCBS
369 {
370     LPD3DENUMTEXTUREFORMATSCALLBACK cbv2;
371     LPD3DENUMPIXELFORMATSCALLBACK cbv7;
372     void *Context;
373 };
374
375 /*****************************************************************************
376  * IDirect3D implementation
377  *****************************************************************************/
378
379 /* No implementation structure as this is only another interface to DirectDraw */
380
381 /* the Vtables */
382 const IDirect3DVtbl  IDirect3D1_Vtbl;
383 const IDirect3D2Vtbl IDirect3D2_Vtbl;
384 const IDirect3D3Vtbl IDirect3D3_Vtbl;
385 const IDirect3D7Vtbl IDirect3D7_Vtbl;
386
387 /* Structure for EnumZBufferFormats */
388 struct EnumZBufferFormatsData
389 {
390     LPD3DENUMPIXELFORMATSCALLBACK Callback;
391     void *Context;
392 };
393
394 /*****************************************************************************
395  * IDirectDrawClipper implementation structure
396  *****************************************************************************/
397 struct IDirectDrawClipperImpl
398 {
399     /* IUnknown fields */
400     ICOM_VFIELD_MULTI(IDirectDrawClipper);
401     LONG ref;
402
403     IWineD3DClipper           *wineD3DClipper;
404     IDirectDrawImpl           *ddraw_owner;
405 };
406
407 const IDirectDrawClipperVtbl IDirectDrawClipper_Vtbl;
408
409 typedef IWineD3DClipper* (WINAPI *fnWineDirect3DCreateClipper)(IUnknown *);
410 fnWineDirect3DCreateClipper pWineDirect3DCreateClipper;
411
412 /*****************************************************************************
413  * IDirectDrawPalette implementation structure
414  *****************************************************************************/
415 struct IDirectDrawPaletteImpl
416 {
417     /* IUnknown fields */
418     ICOM_VFIELD_MULTI(IDirectDrawPalette);
419     LONG ref;
420
421     /* WineD3D uplink */
422     IWineD3DPalette           *wineD3DPalette;
423
424     /* IDirectDrawPalette fields */
425     IDirectDrawImpl           *ddraw_owner;
426     IUnknown                  *ifaceToRelease;
427 };
428 const IDirectDrawPaletteVtbl IDirectDrawPalette_Vtbl;
429
430 /******************************************************************************
431  * DirectDraw ClassFactory implementation - incomplete
432  ******************************************************************************/
433 typedef struct
434 {
435     ICOM_VFIELD_MULTI(IClassFactory);
436
437     LONG ref;
438     HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, REFIID iid, LPVOID *ppObj);
439 } IClassFactoryImpl;
440
441 /* Helper structures */
442 struct object_creation_info
443 {
444     const CLSID *clsid;
445     HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, REFIID riid,
446                                  void **ppObj);
447 };
448
449 /******************************************************************************
450  * IDirect3DLight implementation structure - Wraps to D3D7
451  ******************************************************************************/
452 struct IDirect3DLightImpl
453 {
454     ICOM_VFIELD_MULTI(IDirect3DLight);
455     LONG ref;
456
457     /* IDirect3DLight fields */
458     IDirectDrawImpl           *ddraw;
459
460     /* If this light is active for one viewport, put the viewport here */
461     IDirect3DViewportImpl     *active_viewport;
462
463     D3DLIGHT2 light;
464     D3DLIGHT7 light7;
465
466     DWORD dwLightIndex;
467
468     /* Chained list used for adding / removing from viewports */
469     IDirect3DLightImpl        *next;
470
471     /* Activation function */
472     void                      (*activate)(IDirect3DLightImpl*);
473     void                      (*desactivate)(IDirect3DLightImpl*);
474     void                      (*update)(IDirect3DLightImpl*);
475 };
476
477 /* Vtable */
478 const IDirect3DLightVtbl IDirect3DLight_Vtbl;
479
480 /* Helper functions */
481 void light_update(IDirect3DLightImpl* This);
482 void light_activate(IDirect3DLightImpl* This);
483 void light_desactivate(IDirect3DLightImpl* This);
484
485 /******************************************************************************
486  * IDirect3DMaterial implementation structure - Wraps to D3D7
487  ******************************************************************************/
488 struct IDirect3DMaterialImpl
489 {
490     ICOM_VFIELD_MULTI(IDirect3DMaterial3);
491     ICOM_VFIELD_MULTI(IDirect3DMaterial2);
492     ICOM_VFIELD_MULTI(IDirect3DMaterial);
493     LONG  ref;
494
495     /* IDirect3DMaterial2 fields */
496     IDirectDrawImpl               *ddraw;
497     IDirect3DDeviceImpl           *active_device;
498
499     D3DMATERIAL mat;
500     DWORD Handle;
501
502     void (*activate)(IDirect3DMaterialImpl* this);
503 };
504
505 /* VTables in various versions */
506 const IDirect3DMaterialVtbl IDirect3DMaterial_Vtbl;
507 const IDirect3DMaterial2Vtbl IDirect3DMaterial2_Vtbl;
508 const IDirect3DMaterial3Vtbl IDirect3DMaterial3_Vtbl;
509
510 /* Helper functions */
511 void material_activate(IDirect3DMaterialImpl* This);
512
513 /*****************************************************************************
514  * IDirect3DViewport - Wraps to D3D7
515  *****************************************************************************/
516 struct IDirect3DViewportImpl
517 {
518     ICOM_VFIELD_MULTI(IDirect3DViewport3);
519     LONG ref;
520
521     /* IDirect3DViewport fields */
522     IDirectDrawImpl           *ddraw;
523
524     /* If this viewport is active for one device, put the device here */
525     IDirect3DDeviceImpl       *active_device;
526
527     DWORD                     num_lights;
528     DWORD                     map_lights;
529
530     int                       use_vp2;
531
532     union
533     {
534         D3DVIEWPORT vp1;
535         D3DVIEWPORT2 vp2;
536     } viewports;
537
538     /* Activation function */
539     void                      (*activate)(IDirect3DViewportImpl*);
540
541     /* Field used to chain viewports together */
542     IDirect3DViewportImpl     *next;
543
544     /* Lights list */
545     IDirect3DLightImpl        *lights;
546
547     /* Background material */
548     IDirect3DMaterialImpl     *background;
549 };
550
551 /* Vtable */
552 const IDirect3DViewport3Vtbl IDirect3DViewport3_Vtbl;
553
554 /* Helper functions */
555 void viewport_activate(IDirect3DViewportImpl* This);
556
557 /*****************************************************************************
558  * IDirect3DExecuteBuffer - Wraps to D3D7
559  *****************************************************************************/
560 struct IDirect3DExecuteBufferImpl
561 {
562     /* IUnknown */
563     ICOM_VFIELD_MULTI(IDirect3DExecuteBuffer);
564     LONG                 ref;
565
566     /* IDirect3DExecuteBuffer fields */
567     IDirectDrawImpl      *ddraw;
568     IDirect3DDeviceImpl  *d3ddev;
569
570     D3DEXECUTEBUFFERDESC desc;
571     D3DEXECUTEDATA       data;
572
573     /* This buffer will store the transformed vertices */
574     void                 *vertex_data;
575     WORD                 *indices;
576     int                  nb_indices;
577
578     /* This flags is set to TRUE if we allocated ourselves the
579      * data buffer
580      */
581     BOOL                 need_free;
582 };
583
584 /* The VTable */
585 const IDirect3DExecuteBufferVtbl IDirect3DExecuteBuffer_Vtbl;
586
587 /* The execute function */
588 void
589 IDirect3DExecuteBufferImpl_Execute(IDirect3DExecuteBufferImpl *This,
590                                    IDirect3DDeviceImpl *Device,
591                                    IDirect3DViewportImpl *ViewportImpl);
592
593 /*****************************************************************************
594  * IDirect3DVertexBuffer
595  *****************************************************************************/
596 struct IDirect3DVertexBufferImpl
597 {
598     /*** IUnknown Methods ***/
599     ICOM_VFIELD_MULTI(IDirect3DVertexBuffer7);
600     ICOM_VFIELD_MULTI(IDirect3DVertexBuffer);
601     LONG                 ref;
602
603     /*** WineD3D and ddraw links ***/
604     IWineD3DVertexBuffer *wineD3DVertexBuffer;
605     IWineD3DVertexDeclaration *wineD3DVertexDeclaration;
606     IDirectDrawImpl *ddraw;
607
608     /*** Storage for D3D7 specific things ***/
609     DWORD                Caps;
610 };
611
612 /* The Vtables */
613 const IDirect3DVertexBuffer7Vtbl IDirect3DVertexBuffer7_Vtbl;
614 const IDirect3DVertexBufferVtbl IDirect3DVertexBuffer1_Vtbl;
615
616 /*****************************************************************************
617  * Helper functions from utils.c
618  *****************************************************************************/
619
620 #define GET_TEXCOUNT_FROM_FVF(d3dvtVertexType) \
621     (((d3dvtVertexType) & D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT)
622
623 #define GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType, tex_num) \
624     (((((d3dvtVertexType) >> (16 + (2 * (tex_num)))) + 1) & 0x03) + 1)
625
626 void PixelFormat_WineD3DtoDD(DDPIXELFORMAT *DDPixelFormat, WINED3DFORMAT WineD3DFormat);
627 WINED3DFORMAT PixelFormat_DD2WineD3D(const DDPIXELFORMAT *DDPixelFormat);
628 void DDRAW_dump_surface_desc(const DDSURFACEDESC2 *lpddsd);
629 void DDRAW_dump_pixelformat(const DDPIXELFORMAT *PixelFormat);
630 void dump_D3DMATRIX(const D3DMATRIX *mat);
631 void DDRAW_dump_DDCAPS(const DDCAPS *lpcaps);
632 DWORD get_flexible_vertex_size(DWORD d3dvtVertexType);
633 void DDRAW_dump_DDSCAPS2(const DDSCAPS2 *in);
634 void DDRAW_dump_cooperativelevel(DWORD cooplevel);
635
636 /* This only needs to be here as long the processvertices functionality of
637  * IDirect3DExecuteBuffer isn't in WineD3D */
638 void multiply_matrix(LPD3DMATRIX dest, const D3DMATRIX *src1, const D3DMATRIX *src2);
639
640 /* Used for generic dumping */
641 typedef struct
642 {
643     DWORD val;
644     const char* name;
645 } flag_info;
646
647 #define FE(x) { x, #x }
648
649 typedef struct
650 {
651     DWORD val;
652     const char* name;
653     void (*func)(const void *);
654     ptrdiff_t offset;
655 } member_info;
656
657 /* Structure copy */
658 #define ME(x,f,e) { x, #x, (void (*)(const void *))(f), offsetof(STRUCT, e) }
659
660 #define DD_STRUCT_COPY_BYSIZE(to,from)                  \
661         do {                                            \
662                 DWORD __size = (to)->dwSize;            \
663                 DWORD __copysize = __size;              \
664                 DWORD __resetsize = __size;             \
665                 assert(to != from);                     \
666                 if (__resetsize > sizeof(*to))          \
667                     __resetsize = sizeof(*to);          \
668                 memset(to,0,__resetsize);               \
669                 if ((from)->dwSize < __size)            \
670                     __copysize = (from)->dwSize;        \
671                 memcpy(to,from,__copysize);             \
672                 (to)->dwSize = __size;/*restore size*/  \
673         } while (0)
674
675
676 #endif
677
678 HRESULT hr_ddraw_from_wined3d(HRESULT hr);