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