2 * Copyright 2006 Stefan Dösinger
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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! */
36 #include "ddcomimpl.h"
38 #include "wine/list.h"
39 #ifdef DDRAW_INIT_GUID
42 #include "wine/wined3d.h"
44 /*****************************************************************************
45 * IParent - a helper interface
46 *****************************************************************************/
47 DEFINE_GUID(IID_IParent, 0xc20e4c88, 0x74e7, 0x4940, 0xba, 0x9f, 0x2e, 0x32, 0x3f, 0x9d, 0xc9, 0x81);
48 typedef struct IParent *LPPARENT, *PPARENT;
50 #define INTERFACE IParent
51 DECLARE_INTERFACE_(IParent,IUnknown)
53 /*** IUnknown methods ***/
54 STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE;
55 STDMETHOD_(ULONG,AddRef)(THIS) PURE;
56 STDMETHOD_(ULONG,Release)(THIS) PURE;
60 #if !defined(__cplusplus) || defined(CINTERFACE)
61 /*** IUnknown methods ***/
62 #define IParent_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b)
63 #define IParent_AddRef(p) (p)->lpVtbl->AddRef(p)
64 #define IParent_Release(p) (p)->lpVtbl->Release(p)
68 /* Typdef the interfaces */
69 typedef struct IDirectDrawImpl IDirectDrawImpl;
70 typedef struct IDirectDrawSurfaceImpl IDirectDrawSurfaceImpl;
71 typedef struct IDirectDrawClipperImpl IDirectDrawClipperImpl;
72 typedef struct IDirectDrawPaletteImpl IDirectDrawPaletteImpl;
73 typedef struct IDirect3DDeviceImpl IDirect3DDeviceImpl;
74 typedef struct IDirect3DLightImpl IDirect3DLightImpl;
75 typedef struct IDirect3DViewportImpl IDirect3DViewportImpl;
76 typedef struct IDirect3DMaterialImpl IDirect3DMaterialImpl;
77 typedef struct IDirect3DExecuteBufferImpl IDirect3DExecuteBufferImpl;
78 typedef struct IDirect3DVertexBufferImpl IDirect3DVertexBufferImpl;
79 typedef struct IParentImpl IParentImpl;
81 /* Callbacks for implicit object destruction */
82 extern ULONG WINAPI D3D7CB_DestroySwapChain(IWineD3DSwapChain *pSwapChain);
84 extern ULONG WINAPI D3D7CB_DestroyDepthStencilSurface(IWineD3DSurface *pSurface);
86 /* Global critical section */
87 extern CRITICAL_SECTION ddraw_cs;
89 extern DWORD force_refresh_rate;
91 /*****************************************************************************
92 * IDirectDraw implementation structure
93 *****************************************************************************/
97 IWineD3DVertexDeclaration *decl;
100 struct IDirectDrawImpl
102 /* IUnknown fields */
103 ICOM_VFIELD_MULTI(IDirectDraw7);
104 ICOM_VFIELD_MULTI(IDirectDraw4);
105 ICOM_VFIELD_MULTI(IDirectDraw3);
106 ICOM_VFIELD_MULTI(IDirectDraw2);
107 ICOM_VFIELD_MULTI(IDirectDraw);
108 ICOM_VFIELD_MULTI(IDirect3D7);
109 ICOM_VFIELD_MULTI(IDirect3D3);
110 ICOM_VFIELD_MULTI(IDirect3D2);
111 ICOM_VFIELD_MULTI(IDirect3D);
112 const IWineD3DDeviceParentVtbl *device_parent_vtbl;
114 /* See comment in IDirectDraw::AddRef */
115 LONG ref7, ref4, ref2, ref3, ref1, numIfaces;
117 /* WineD3D linkage */
119 IWineD3DDevice *wineD3DDevice;
120 IDirectDrawSurfaceImpl *DepthStencilBuffer;
121 BOOL d3d_initialized;
123 /* Misc ddraw fields */
129 /* DirectDraw things, which are not handled by WineD3D */
130 DWORD cooperative_level;
132 DWORD orig_width, orig_height;
136 IDirectDrawSurfaceImpl *d3d_target;
138 IDirect3DDeviceImpl *d3ddevice;
146 /* The surface type to request */
147 WINED3DSURFTYPE ImplType;
150 /* Our private window class */
154 /* Helpers for surface creation */
155 IDirectDrawSurfaceImpl *tex_root;
158 /* For the dll unload cleanup code */
159 struct list ddraw_list_entry;
160 /* The surface list - can't relay this to WineD3D
163 struct list surface_list;
167 struct FvfToDecl *decls;
168 UINT numConvertedDecls, declArraySize;
171 /* Declare the VTables. They can be found ddraw.c */
172 extern const IDirectDraw7Vtbl IDirectDraw7_Vtbl;
173 extern const IDirectDraw4Vtbl IDirectDraw4_Vtbl;
174 extern const IDirectDraw3Vtbl IDirectDraw3_Vtbl;
175 extern const IDirectDraw2Vtbl IDirectDraw2_Vtbl;
176 extern const IDirectDrawVtbl IDirectDraw1_Vtbl;
177 extern const IWineD3DDeviceParentVtbl ddraw_wined3d_device_parent_vtbl;
179 /* Helper structures */
180 typedef struct EnumDisplayModesCBS
183 LPDDENUMMODESCALLBACK2 callback;
184 } EnumDisplayModesCBS;
186 typedef struct EnumSurfacesCBS
189 LPDDENUMSURFACESCALLBACK7 callback;
190 LPDDSURFACEDESC2 pDDSD;
194 /* Utility functions */
196 DDRAW_Convert_DDSCAPS_1_To_2(const DDSCAPS* pIn,
199 DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(const DDDEVICEIDENTIFIER2* pIn,
200 DDDEVICEIDENTIFIER* pOut);
202 IDirectDrawImpl_Destroy(IDirectDrawImpl *This);
205 IDirectDrawImpl_RecreateSurfacesCallback(IDirectDrawSurface7 *surf,
206 DDSURFACEDESC2 *desc,
208 IWineD3DVertexDeclaration *
209 IDirectDrawImpl_FindDecl(IDirectDrawImpl *This,
212 /* The default surface type */
213 extern WINED3DSURFTYPE DefaultSurfaceType;
215 /*****************************************************************************
216 * IDirectDrawSurface implementation structure
217 *****************************************************************************/
219 struct IDirectDrawSurfaceImpl
221 /* IUnknown fields */
222 ICOM_VFIELD_MULTI(IDirectDrawSurface7);
223 ICOM_VFIELD_MULTI(IDirectDrawSurface3);
224 ICOM_VFIELD_MULTI(IDirectDrawGammaControl);
225 ICOM_VFIELD_MULTI(IDirect3DTexture2);
226 ICOM_VFIELD_MULTI(IDirect3DTexture);
229 IUnknown *ifaceToRelease;
233 /* Connections to other Objects */
234 IDirectDrawImpl *ddraw;
235 IWineD3DSurface *WineD3DSurface;
236 IWineD3DBaseTexture *wineD3DTexture;
237 IWineD3DSwapChain *wineD3DSwapChain;
239 /* This implementation handles attaching surfaces to other surfaces */
240 IDirectDrawSurfaceImpl *next_attached;
241 IDirectDrawSurfaceImpl *first_attached;
243 /* Complex surfaces are organized in a tree, although the tree is degenerated to a list in most cases.
244 * In mipmap and primary surfaces each level has only one attachment, which is the next surface level.
245 * Only the cube texture root has 6 surfaces attached, which then have a normal mipmap chain attached
246 * to them. So hardcode the array to 6, a dynamic array or a list would be an overkill.
248 #define MAX_COMPLEX_ATTACHED 6
249 IDirectDrawSurfaceImpl *complex_array[MAX_COMPLEX_ATTACHED];
250 /* You can't traverse the tree upwards. Only a flag for Surface::Release because its needed there,
251 * but no pointer to prevent temptations to traverse it in the wrong direction.
253 BOOL is_complex_root;
255 /* Surface description, for GetAttachedSurface */
256 DDSURFACEDESC2 surface_desc;
259 DWORD uniqueness_value;
261 WINED3DSURFTYPE ImplType;
263 /* For D3DDevice creation */
266 /* Clipper objects */
267 IDirectDrawClipperImpl *clipper;
269 /* For the ddraw surface list */
270 struct list surface_list_entry;
275 /* VTable declaration. It's located in surface.c / surface_thunks.c */
276 extern const IDirectDrawSurface7Vtbl IDirectDrawSurface7_Vtbl;
277 extern const IDirectDrawSurface3Vtbl IDirectDrawSurface3_Vtbl;
278 extern const IDirectDrawGammaControlVtbl IDirectDrawGammaControl_Vtbl;
279 extern const IDirect3DTexture2Vtbl IDirect3DTexture2_Vtbl;
280 extern const IDirect3DTextureVtbl IDirect3DTexture1_Vtbl;
282 HRESULT WINAPI IDirectDrawSurfaceImpl_AddAttachedSurface(IDirectDrawSurfaceImpl *This, IDirectDrawSurfaceImpl *Surf);
283 void IDirectDrawSurfaceImpl_Destroy(IDirectDrawSurfaceImpl *This);
285 /* Get the number of bytes per pixel for a given surface */
286 #define PFGET_BPP(pf) (pf.dwFlags&DDPF_PALETTEINDEXED8?1:((pf.dwRGBBitCount+7)/8))
287 #define GET_BPP(desc) PFGET_BPP(desc.ddpfPixelFormat)
289 /*****************************************************************************
290 * IParent Implementation
291 *****************************************************************************/
294 /* IUnknown fields */
295 ICOM_VFIELD_MULTI(IParent);
298 /* IParentImpl fields */
303 extern const IParentVtbl IParent_Vtbl;
305 /*****************************************************************************
306 * IDirect3DDevice implementation
307 *****************************************************************************/
310 DDrawHandle_Unknown = 0,
311 DDrawHandle_Texture = 1,
312 DDrawHandle_Material = 2,
313 DDrawHandle_Matrix = 3,
314 DDrawHandle_StateBlock = 4
320 DDrawHandleTypes type;
323 struct IDirect3DDeviceImpl
326 ICOM_VFIELD_MULTI(IDirect3DDevice7);
327 ICOM_VFIELD_MULTI(IDirect3DDevice3);
328 ICOM_VFIELD_MULTI(IDirect3DDevice2);
329 ICOM_VFIELD_MULTI(IDirect3DDevice);
332 /* Other object connections */
333 IWineD3DDevice *wineD3DDevice;
334 IDirectDrawImpl *ddraw;
335 IWineD3DIndexBuffer *indexbuffer;
336 IDirectDrawSurfaceImpl *target;
337 BOOL OffScreenTarget;
339 /* Viewport management */
340 IDirect3DViewportImpl *viewport_list;
341 IDirect3DViewportImpl *current_viewport;
342 D3DVIEWPORT7 active_viewport;
344 /* Required to keep track which of two available texture blending modes in d3ddevice3 is used */
345 BOOL legacyTextureBlending;
350 /* Rendering functions to wrap D3D(1-3) to D3D7 */
351 D3DPRIMITIVETYPE primitive_type;
355 LPBYTE vertex_buffer;
359 /* Handle management */
360 struct HandleEntry *Handles;
362 D3DMATRIXHANDLE world, proj, view;
365 /* Vtables in various versions */
366 extern const IDirect3DDevice7Vtbl IDirect3DDevice7_FPUSetup_Vtbl;
367 extern const IDirect3DDevice7Vtbl IDirect3DDevice7_FPUPreserve_Vtbl;
368 extern const IDirect3DDevice3Vtbl IDirect3DDevice3_Vtbl;
369 extern const IDirect3DDevice2Vtbl IDirect3DDevice2_Vtbl;
370 extern const IDirect3DDeviceVtbl IDirect3DDevice1_Vtbl;
373 extern const GUID IID_D3DDEVICE_WineD3D;
375 /* Helper functions */
376 HRESULT IDirect3DImpl_GetCaps(IWineD3D *WineD3D, D3DDEVICEDESC *Desc123, D3DDEVICEDESC7 *Desc7);
377 DWORD IDirect3DDeviceImpl_CreateHandle(IDirect3DDeviceImpl *This);
378 WINED3DZBUFFERTYPE IDirect3DDeviceImpl_UpdateDepthStencil(IDirect3DDeviceImpl *This);
381 struct EnumTextureFormatsCBS
383 LPD3DENUMTEXTUREFORMATSCALLBACK cbv2;
384 LPD3DENUMPIXELFORMATSCALLBACK cbv7;
388 /*****************************************************************************
389 * IDirect3D implementation
390 *****************************************************************************/
392 /* No implementation structure as this is only another interface to DirectDraw */
395 extern const IDirect3DVtbl IDirect3D1_Vtbl;
396 extern const IDirect3D2Vtbl IDirect3D2_Vtbl;
397 extern const IDirect3D3Vtbl IDirect3D3_Vtbl;
398 extern const IDirect3D7Vtbl IDirect3D7_Vtbl;
400 /* Structure for EnumZBufferFormats */
401 struct EnumZBufferFormatsData
403 LPD3DENUMPIXELFORMATSCALLBACK Callback;
407 /*****************************************************************************
408 * IDirectDrawClipper implementation structure
409 *****************************************************************************/
410 struct IDirectDrawClipperImpl
412 /* IUnknown fields */
413 ICOM_VFIELD_MULTI(IDirectDrawClipper);
416 IWineD3DClipper *wineD3DClipper;
417 IDirectDrawImpl *ddraw_owner;
420 extern const IDirectDrawClipperVtbl IDirectDrawClipper_Vtbl;
422 typeof(WineDirect3DCreateClipper) *pWineDirect3DCreateClipper;
424 /*****************************************************************************
425 * IDirectDrawPalette implementation structure
426 *****************************************************************************/
427 struct IDirectDrawPaletteImpl
429 /* IUnknown fields */
430 ICOM_VFIELD_MULTI(IDirectDrawPalette);
434 IWineD3DPalette *wineD3DPalette;
436 /* IDirectDrawPalette fields */
437 IDirectDrawImpl *ddraw_owner;
438 IUnknown *ifaceToRelease;
440 extern const IDirectDrawPaletteVtbl IDirectDrawPalette_Vtbl;
442 /******************************************************************************
443 * DirectDraw ClassFactory implementation - incomplete
444 ******************************************************************************/
447 ICOM_VFIELD_MULTI(IClassFactory);
450 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, REFIID iid, LPVOID *ppObj);
453 /* Helper structures */
454 struct object_creation_info
457 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, REFIID riid,
461 /******************************************************************************
462 * IDirect3DLight implementation structure - Wraps to D3D7
463 ******************************************************************************/
464 struct IDirect3DLightImpl
466 ICOM_VFIELD_MULTI(IDirect3DLight);
469 /* IDirect3DLight fields */
470 IDirectDrawImpl *ddraw;
472 /* If this light is active for one viewport, put the viewport here */
473 IDirect3DViewportImpl *active_viewport;
480 /* Chained list used for adding / removing from viewports */
481 IDirect3DLightImpl *next;
483 /* Activation function */
484 void (*activate)(IDirect3DLightImpl*);
485 void (*desactivate)(IDirect3DLightImpl*);
486 void (*update)(IDirect3DLightImpl*);
490 extern const IDirect3DLightVtbl IDirect3DLight_Vtbl;
492 /* Helper functions */
493 void light_update(IDirect3DLightImpl* This);
494 void light_activate(IDirect3DLightImpl* This);
495 void light_desactivate(IDirect3DLightImpl* This);
497 /******************************************************************************
498 * IDirect3DMaterial implementation structure - Wraps to D3D7
499 ******************************************************************************/
500 struct IDirect3DMaterialImpl
502 ICOM_VFIELD_MULTI(IDirect3DMaterial3);
503 ICOM_VFIELD_MULTI(IDirect3DMaterial2);
504 ICOM_VFIELD_MULTI(IDirect3DMaterial);
507 /* IDirect3DMaterial2 fields */
508 IDirectDrawImpl *ddraw;
509 IDirect3DDeviceImpl *active_device;
514 void (*activate)(IDirect3DMaterialImpl* this);
517 /* VTables in various versions */
518 extern const IDirect3DMaterialVtbl IDirect3DMaterial_Vtbl;
519 extern const IDirect3DMaterial2Vtbl IDirect3DMaterial2_Vtbl;
520 extern const IDirect3DMaterial3Vtbl IDirect3DMaterial3_Vtbl;
522 /* Helper functions */
523 void material_activate(IDirect3DMaterialImpl* This);
525 /*****************************************************************************
526 * IDirect3DViewport - Wraps to D3D7
527 *****************************************************************************/
528 struct IDirect3DViewportImpl
530 ICOM_VFIELD_MULTI(IDirect3DViewport3);
533 /* IDirect3DViewport fields */
534 IDirectDrawImpl *ddraw;
536 /* If this viewport is active for one device, put the device here */
537 IDirect3DDeviceImpl *active_device;
550 /* Activation function */
551 void (*activate)(IDirect3DViewportImpl*, BOOL);
553 /* Field used to chain viewports together */
554 IDirect3DViewportImpl *next;
557 IDirect3DLightImpl *lights;
559 /* Background material */
560 IDirect3DMaterialImpl *background;
564 extern const IDirect3DViewport3Vtbl IDirect3DViewport3_Vtbl;
566 /* Helper functions */
567 void viewport_activate(IDirect3DViewportImpl* This, BOOL ignore_lights);
569 /*****************************************************************************
570 * IDirect3DExecuteBuffer - Wraps to D3D7
571 *****************************************************************************/
572 struct IDirect3DExecuteBufferImpl
575 ICOM_VFIELD_MULTI(IDirect3DExecuteBuffer);
578 /* IDirect3DExecuteBuffer fields */
579 IDirectDrawImpl *ddraw;
580 IDirect3DDeviceImpl *d3ddev;
582 D3DEXECUTEBUFFERDESC desc;
585 /* This buffer will store the transformed vertices */
590 /* This flags is set to TRUE if we allocated ourselves the
597 extern const IDirect3DExecuteBufferVtbl IDirect3DExecuteBuffer_Vtbl;
599 /* The execute function */
601 IDirect3DExecuteBufferImpl_Execute(IDirect3DExecuteBufferImpl *This,
602 IDirect3DDeviceImpl *Device,
603 IDirect3DViewportImpl *ViewportImpl);
605 /*****************************************************************************
606 * IDirect3DVertexBuffer
607 *****************************************************************************/
608 struct IDirect3DVertexBufferImpl
610 /*** IUnknown Methods ***/
611 ICOM_VFIELD_MULTI(IDirect3DVertexBuffer7);
612 ICOM_VFIELD_MULTI(IDirect3DVertexBuffer);
615 /*** WineD3D and ddraw links ***/
616 IWineD3DVertexBuffer *wineD3DVertexBuffer;
617 IWineD3DVertexDeclaration *wineD3DVertexDeclaration;
618 IDirectDrawImpl *ddraw;
620 /*** Storage for D3D7 specific things ***/
625 extern const IDirect3DVertexBuffer7Vtbl IDirect3DVertexBuffer7_Vtbl;
626 extern const IDirect3DVertexBufferVtbl IDirect3DVertexBuffer1_Vtbl;
628 /*****************************************************************************
629 * Helper functions from utils.c
630 *****************************************************************************/
632 #define GET_TEXCOUNT_FROM_FVF(d3dvtVertexType) \
633 (((d3dvtVertexType) & D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT)
635 #define GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType, tex_num) \
636 (((((d3dvtVertexType) >> (16 + (2 * (tex_num)))) + 1) & 0x03) + 1)
638 void PixelFormat_WineD3DtoDD(DDPIXELFORMAT *DDPixelFormat, WINED3DFORMAT WineD3DFormat);
639 WINED3DFORMAT PixelFormat_DD2WineD3D(const DDPIXELFORMAT *DDPixelFormat);
640 void DDRAW_dump_surface_desc(const DDSURFACEDESC2 *lpddsd);
641 void dump_D3DMATRIX(const D3DMATRIX *mat);
642 void DDRAW_dump_DDCAPS(const DDCAPS *lpcaps);
643 DWORD get_flexible_vertex_size(DWORD d3dvtVertexType);
644 void DDRAW_dump_DDSCAPS2(const DDSCAPS2 *in);
645 void DDRAW_dump_cooperativelevel(DWORD cooplevel);
647 /* This only needs to be here as long the processvertices functionality of
648 * IDirect3DExecuteBuffer isn't in WineD3D */
649 void multiply_matrix(LPD3DMATRIX dest, const D3DMATRIX *src1, const D3DMATRIX *src2);
651 /* Helper function in main.c */
652 BOOL LoadWineD3D(void);
654 /* Used for generic dumping */
661 #define FE(x) { x, #x }
667 void (*func)(const void *);
672 #define ME(x,f,e) { x, #x, (void (*)(const void *))(f), offsetof(STRUCT, e) }
674 #define DD_STRUCT_COPY_BYSIZE(to,from) \
676 DWORD __size = (to)->dwSize; \
677 DWORD __copysize = __size; \
678 DWORD __resetsize = __size; \
679 assert(to != from); \
680 if (__resetsize > sizeof(*to)) \
681 __resetsize = sizeof(*to); \
682 memset(to,0,__resetsize); \
683 if ((from)->dwSize < __size) \
684 __copysize = (from)->dwSize; \
685 memcpy(to,from,__copysize); \
686 (to)->dwSize = __size;/*restore size*/ \
692 HRESULT hr_ddraw_from_wined3d(HRESULT hr);