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/wined3d_interface.h"
39 #include "wine/list.h"
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;
47 #define INTERFACE IParent
48 DECLARE_INTERFACE_(IParent,IUnknown)
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;
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)
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;
78 /* Callbacks for implicit object destruction */
79 extern ULONG WINAPI D3D7CB_DestroySwapChain(IWineD3DSwapChain *pSwapChain);
81 extern ULONG WINAPI D3D7CB_DestroyDepthStencilSurface(IWineD3DSurface *pSurface);
83 /*****************************************************************************
84 * IDirectDraw implementation structure
85 *****************************************************************************/
89 IWineD3DVertexDeclaration *decl;
92 struct IDirectDrawImpl
95 ICOM_VFIELD_MULTI(IDirectDraw7);
96 ICOM_VFIELD_MULTI(IDirectDraw4);
97 ICOM_VFIELD_MULTI(IDirectDraw3);
98 ICOM_VFIELD_MULTI(IDirectDraw2);
99 ICOM_VFIELD_MULTI(IDirectDraw);
100 ICOM_VFIELD_MULTI(IDirect3D7);
101 ICOM_VFIELD_MULTI(IDirect3D3);
102 ICOM_VFIELD_MULTI(IDirect3D2);
103 ICOM_VFIELD_MULTI(IDirect3D);
105 /* See comment in IDirectDraw::AddRef */
106 LONG ref7, ref4, ref2, ref3, ref1, numIfaces;
108 /* WineD3D linkage */
110 IWineD3DDevice *wineD3DDevice;
111 IDirectDrawSurfaceImpl *DepthStencilBuffer;
112 BOOL d3d_initialized;
114 /* Misc ddraw fields */
120 /* DirectDraw things, which are not handled by WineD3D */
121 DWORD cooperative_level;
123 DWORD orig_width, orig_height;
129 IDirectDrawSurfaceImpl *d3d_target;
131 IDirect3DDeviceImpl *d3ddevice;
138 /* The surface type to request */
139 WINED3DSURFTYPE ImplType;
142 /* Our private window class */
146 /* Helpers for surface creation */
147 IDirectDrawSurfaceImpl *tex_root;
150 /* For the dll unload cleanup code */
151 struct list ddraw_list_entry;
152 /* The surface list - can't relay this to WineD3D
155 struct list surface_list;
159 struct FvfToDecl *decls;
160 UINT numConvertedDecls, declArraySize;
163 /* Declare the VTables. They can be found ddraw.c */
164 const IDirectDraw7Vtbl IDirectDraw7_Vtbl;
165 const IDirectDraw4Vtbl IDirectDraw4_Vtbl;
166 const IDirectDraw3Vtbl IDirectDraw3_Vtbl;
167 const IDirectDraw2Vtbl IDirectDraw2_Vtbl;
168 const IDirectDrawVtbl IDirectDraw1_Vtbl;
170 /* Helper structures */
171 typedef struct EnumDisplayModesCBS
174 LPDDENUMMODESCALLBACK2 callback;
175 } EnumDisplayModesCBS;
177 typedef struct EnumSurfacesCBS
180 LPDDENUMSURFACESCALLBACK7 callback;
181 LPDDSURFACEDESC2 pDDSD;
185 /* Utility functions */
187 DDRAW_Convert_DDSCAPS_1_To_2(const DDSCAPS* pIn,
190 DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(const DDDEVICEIDENTIFIER2* pIn,
191 DDDEVICEIDENTIFIER* pOut);
193 IDirectDrawImpl_Destroy(IDirectDrawImpl *This);
196 IDirectDrawImpl_RecreateSurfacesCallback(IDirectDrawSurface7 *surf,
197 DDSURFACEDESC2 *desc,
199 IWineD3DVertexDeclaration *
200 IDirectDrawImpl_FindDecl(IDirectDrawImpl *This,
204 remove_ddraw_object(IDirectDrawImpl *ddraw);
206 /* The default surface type */
207 extern WINED3DSURFTYPE DefaultSurfaceType;
209 /*****************************************************************************
210 * IDirectDrawSurface implementation structure
211 *****************************************************************************/
213 struct IDirectDrawSurfaceImpl
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);
223 IUnknown *ifaceToRelease;
227 /* Connections to other Objects */
228 IDirectDrawImpl *ddraw;
229 IWineD3DSurface *WineD3DSurface;
230 IWineD3DTexture *wineD3DTexture;
232 /* This implementation handles attaching surfaces to other surfaces */
233 IDirectDrawSurfaceImpl *next_attached;
234 IDirectDrawSurfaceImpl *first_attached;
235 IDirectDrawSurfaceImpl *next_complex;
236 IDirectDrawSurfaceImpl *first_complex;
238 /* Surface description, for GetAttachedSurface */
239 DDSURFACEDESC2 surface_desc;
242 DWORD uniqueness_value;
244 WINED3DSURFTYPE ImplType;
246 /* For D3DDevice creation */
249 /* Clipper objects */
250 IDirectDrawClipperImpl *clipper;
252 /* For the ddraw surface list */
253 struct list surface_list_entry;
258 /* VTable declaration. It's located in surface.c / surface_thunks.c */
259 const IDirectDrawSurface7Vtbl IDirectDrawSurface7_Vtbl;
260 const IDirectDrawSurface3Vtbl IDirectDrawSurface3_Vtbl;
261 const IDirectDrawGammaControlVtbl IDirectDrawGammaControl_Vtbl;
262 const IDirect3DTexture2Vtbl IDirect3DTexture2_Vtbl;
263 const IDirect3DTextureVtbl IDirect3DTexture1_Vtbl;
265 /* Get the number of bytes per pixel for a given surface */
266 #define PFGET_BPP(pf) (pf.dwFlags&DDPF_PALETTEINDEXED8?1:((pf.dwRGBBitCount+7)/8))
267 #define GET_BPP(desc) PFGET_BPP(desc.ddpfPixelFormat)
269 /*****************************************************************************
270 * IParent Implementation
271 *****************************************************************************/
274 /* IUnknown fields */
275 ICOM_VFIELD_MULTI(IParent);
278 /* IParentImpl fields */
283 const IParentVtbl IParent_Vtbl;
285 /*****************************************************************************
286 * IDirect3DDevice implementation
287 *****************************************************************************/
290 DDrawHandle_Unknown = 0,
291 DDrawHandle_Texture = 1,
292 DDrawHandle_Material = 2,
293 DDrawHandle_Matrix = 3,
294 DDrawHandle_StateBlock = 4
300 DDrawHandleTypes type;
303 struct IDirect3DDeviceImpl
306 ICOM_VFIELD_MULTI(IDirect3DDevice7);
307 ICOM_VFIELD_MULTI(IDirect3DDevice3);
308 ICOM_VFIELD_MULTI(IDirect3DDevice2);
309 ICOM_VFIELD_MULTI(IDirect3DDevice);
312 /* Other object connections */
313 IWineD3DDevice *wineD3DDevice;
314 IDirectDrawImpl *ddraw;
315 IWineD3DIndexBuffer *indexbuffer;
316 IDirectDrawSurfaceImpl *target;
317 BOOL OffScreenTarget;
319 /* Viewport management */
320 IDirect3DViewportImpl *viewport_list;
321 IDirect3DViewportImpl *current_viewport;
322 D3DVIEWPORT7 active_viewport;
327 /* Rendering functions to wrap D3D(1-3) to D3D7 */
328 D3DPRIMITIVETYPE primitive_type;
332 LPBYTE vertex_buffer;
336 /* Handle management */
337 struct HandleEntry *Handles;
341 /* Vtables in various versions */
342 const IDirect3DDevice7Vtbl IDirect3DDevice7_Vtbl;
343 const IDirect3DDevice3Vtbl IDirect3DDevice3_Vtbl;
344 const IDirect3DDevice2Vtbl IDirect3DDevice2_Vtbl;
345 const IDirect3DDeviceVtbl IDirect3DDevice1_Vtbl;
348 const GUID IID_D3DDEVICE_WineD3D;
350 /* Helper functions */
351 HRESULT IDirect3DImpl_GetCaps(IWineD3D *WineD3D, D3DDEVICEDESC *Desc123, D3DDEVICEDESC7 *Desc7);
352 DWORD IDirect3DDeviceImpl_CreateHandle(IDirect3DDeviceImpl *This);
355 struct EnumTextureFormatsCBS
357 LPD3DENUMTEXTUREFORMATSCALLBACK cbv2;
358 LPD3DENUMPIXELFORMATSCALLBACK cbv7;
362 /*****************************************************************************
363 * IDirect3D implementation
364 *****************************************************************************/
366 /* No implementation structure as this is only another interface to DirectDraw */
369 const IDirect3DVtbl IDirect3D1_Vtbl;
370 const IDirect3D2Vtbl IDirect3D2_Vtbl;
371 const IDirect3D3Vtbl IDirect3D3_Vtbl;
372 const IDirect3D7Vtbl IDirect3D7_Vtbl;
374 /* Structure for EnumZBufferFormats */
375 struct EnumZBufferFormatsData
377 LPD3DENUMPIXELFORMATSCALLBACK Callback;
381 /*****************************************************************************
382 * IDirectDrawClipper implementation structure
383 *****************************************************************************/
384 struct IDirectDrawClipperImpl
386 /* IUnknown fields */
387 ICOM_VFIELD_MULTI(IDirectDrawClipper);
390 /* IDirectDrawClipper fields */
393 IDirectDrawImpl* ddraw_owner;
394 struct IDirectDrawClipperImpl* prev_ddraw;
395 struct IDirectDrawClipperImpl* next_ddraw;
398 const IDirectDrawClipperVtbl IDirectDrawClipper_Vtbl;
400 /*****************************************************************************
401 * IDirectDrawPalette implementation structure
402 *****************************************************************************/
403 struct IDirectDrawPaletteImpl
405 /* IUnknown fields */
406 ICOM_VFIELD_MULTI(IDirectDrawPalette);
410 IWineD3DPalette *wineD3DPalette;
412 /* IDirectDrawPalette fields */
413 IDirectDrawImpl *ddraw_owner;
414 IUnknown *ifaceToRelease;
416 const IDirectDrawPaletteVtbl IDirectDrawPalette_Vtbl;
418 /******************************************************************************
419 * DirectDraw ClassFactory implementation - incomplete
420 ******************************************************************************/
423 ICOM_VFIELD_MULTI(IClassFactory);
426 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, REFIID iid, LPVOID *ppObj);
429 /* Helper structures */
430 struct object_creation_info
433 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, REFIID riid,
437 /******************************************************************************
438 * IDirect3DLight implementation structure - Wraps to D3D7
439 ******************************************************************************/
440 struct IDirect3DLightImpl
442 ICOM_VFIELD_MULTI(IDirect3DLight);
445 /* IDirect3DLight fields */
446 IDirectDrawImpl *ddraw;
448 /* If this light is active for one viewport, put the viewport here */
449 IDirect3DViewportImpl *active_viewport;
456 /* Chained list used for adding / removing from viewports */
457 IDirect3DLightImpl *next;
459 /* Activation function */
460 void (*activate)(IDirect3DLightImpl*);
461 void (*desactivate)(IDirect3DLightImpl*);
462 void (*update)(IDirect3DLightImpl*);
466 const IDirect3DLightVtbl IDirect3DLight_Vtbl;
468 /* Helper functions */
469 void light_update(IDirect3DLightImpl* This);
470 void light_activate(IDirect3DLightImpl* This);
471 void light_desactivate(IDirect3DLightImpl* This);
473 /******************************************************************************
474 * IDirect3DMaterial implementation structure - Wraps to D3D7
475 ******************************************************************************/
476 struct IDirect3DMaterialImpl
478 ICOM_VFIELD_MULTI(IDirect3DMaterial3);
479 ICOM_VFIELD_MULTI(IDirect3DMaterial2);
480 ICOM_VFIELD_MULTI(IDirect3DMaterial);
483 /* IDirect3DMaterial2 fields */
484 IDirectDrawImpl *ddraw;
485 IDirect3DDeviceImpl *active_device;
490 void (*activate)(IDirect3DMaterialImpl* this);
493 /* VTables in various versions */
494 const IDirect3DMaterialVtbl IDirect3DMaterial_Vtbl;
495 const IDirect3DMaterial2Vtbl IDirect3DMaterial2_Vtbl;
496 const IDirect3DMaterial3Vtbl IDirect3DMaterial3_Vtbl;
498 /* Helper functions */
499 void material_activate(IDirect3DMaterialImpl* This);
501 /*****************************************************************************
502 * IDirect3DViewport - Wraps to D3D7
503 *****************************************************************************/
504 struct IDirect3DViewportImpl
506 ICOM_VFIELD_MULTI(IDirect3DViewport3);
509 /* IDirect3DViewport fields */
510 IDirectDrawImpl *ddraw;
512 /* If this viewport is active for one device, put the device here */
513 IDirect3DDeviceImpl *active_device;
526 /* Activation function */
527 void (*activate)(IDirect3DViewportImpl*);
529 /* Field used to chain viewports together */
530 IDirect3DViewportImpl *next;
533 IDirect3DLightImpl *lights;
535 /* Background material */
536 IDirect3DMaterialImpl *background;
540 const IDirect3DViewport3Vtbl IDirect3DViewport3_Vtbl;
542 /* Helper functions */
543 void viewport_activate(IDirect3DViewportImpl* This);
545 /*****************************************************************************
546 * IDirect3DExecuteBuffer - Wraps to D3D7
547 *****************************************************************************/
548 struct IDirect3DExecuteBufferImpl
551 ICOM_VFIELD_MULTI(IDirect3DExecuteBuffer);
554 /* IDirect3DExecuteBuffer fields */
555 IDirectDrawImpl *ddraw;
556 IDirect3DDeviceImpl *d3ddev;
558 D3DEXECUTEBUFFERDESC desc;
561 /* This buffer will store the transformed vertices */
566 /* This flags is set to TRUE if we allocated ourselves the
573 const IDirect3DExecuteBufferVtbl IDirect3DExecuteBuffer_Vtbl;
575 /* The execute function */
577 IDirect3DExecuteBufferImpl_Execute(IDirect3DExecuteBufferImpl *This,
578 IDirect3DDeviceImpl *Device,
579 IDirect3DViewportImpl *ViewportImpl);
581 /*****************************************************************************
582 * IDirect3DVertexBuffer
583 *****************************************************************************/
584 struct IDirect3DVertexBufferImpl
586 /*** IUnknown Methods ***/
587 ICOM_VFIELD_MULTI(IDirect3DVertexBuffer7);
588 ICOM_VFIELD_MULTI(IDirect3DVertexBuffer);
591 /*** WineD3D and ddraw links ***/
592 IWineD3DVertexBuffer *wineD3DVertexBuffer;
593 IWineD3DVertexDeclaration *wineD3DVertexDeclaration;
594 IDirectDrawImpl *ddraw;
596 /*** Storage for D3D7 specific things ***/
601 const IDirect3DVertexBuffer7Vtbl IDirect3DVertexBuffer7_Vtbl;
602 const IDirect3DVertexBufferVtbl IDirect3DVertexBuffer1_Vtbl;
604 /*****************************************************************************
605 * Helper functions from utils.c
606 *****************************************************************************/
608 #define GET_TEXCOUNT_FROM_FVF(d3dvtVertexType) \
609 (((d3dvtVertexType) & D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT)
611 #define GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType, tex_num) \
612 (((((d3dvtVertexType) >> (16 + (2 * (tex_num)))) + 1) & 0x03) + 1)
614 void PixelFormat_WineD3DtoDD(DDPIXELFORMAT *DDPixelFormat, WINED3DFORMAT WineD3DFormat);
615 WINED3DFORMAT PixelFormat_DD2WineD3D(const DDPIXELFORMAT *DDPixelFormat);
616 void DDRAW_dump_surface_desc(const DDSURFACEDESC2 *lpddsd);
617 void DDRAW_dump_pixelformat(const DDPIXELFORMAT *PixelFormat);
618 void dump_D3DMATRIX(const D3DMATRIX *mat);
619 void DDRAW_dump_DDCAPS(const DDCAPS *lpcaps);
620 DWORD get_flexible_vertex_size(DWORD d3dvtVertexType);
621 void DDRAW_dump_DDSCAPS2(const DDSCAPS2 *in);
622 void DDRAW_dump_cooperativelevel(DWORD cooplevel);
624 /* This only needs to be here as long the processvertices functionality of
625 * IDirect3DExecuteBuffer isn't in WineD3D */
626 void multiply_matrix(LPD3DMATRIX dest, const D3DMATRIX *src1, const D3DMATRIX *src2);
628 /* Used for generic dumping */
635 #define FE(x) { x, #x }
641 void (*func)(const void *);
646 #define ME(x,f,e) { x, #x, (void (*)(const void *))(f), offsetof(STRUCT, e) }
648 #define DD_STRUCT_COPY_BYSIZE(to,from) \
650 DWORD __size = (to)->dwSize; \
651 DWORD __copysize = __size; \
652 DWORD __resetsize = __size; \
653 assert(to != from); \
654 if (__resetsize > sizeof(*to)) \
655 __resetsize = sizeof(*to); \
656 memset(to,0,__resetsize); \
657 if ((from)->dwSize < __size) \
658 __copysize = (from)->dwSize; \
659 memcpy(to,from,__copysize); \
660 (to)->dwSize = __size;/*restore size*/ \
666 HRESULT hr_ddraw_from_wined3d(HRESULT hr);