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"
40 /*****************************************************************************
41 * IParent - a helper interface
42 *****************************************************************************/
43 DEFINE_GUID(IID_IParent
, 0xc20e4c88, 0x74e7, 0x4940, 0xba, 0x9f, 0x2e, 0x32, 0x3f, 0x9d, 0xc9, 0x81);
44 typedef struct IParent
*LPPARENT
, *PPARENT
;
46 #define INTERFACE IParent
47 DECLARE_INTERFACE_(IParent
,IUnknown
)
49 /*** IUnknown methods ***/
50 STDMETHOD_(HRESULT
,QueryInterface
)(THIS_ REFIID riid
, void** ppvObject
) PURE
;
51 STDMETHOD_(ULONG
,AddRef
)(THIS
) PURE
;
52 STDMETHOD_(ULONG
,Release
)(THIS
) PURE
;
56 #if !defined(__cplusplus) || defined(CINTERFACE)
57 /*** IUnknown methods ***/
58 #define IParent_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b)
59 #define IParent_AddRef(p) (p)->lpVtbl->AddRef(p)
60 #define IParent_Release(p) (p)->lpVtbl->Release(p)
64 /* Typdef the interfaces */
65 typedef struct IDirectDrawImpl IDirectDrawImpl
;
66 typedef struct IDirectDrawSurfaceImpl IDirectDrawSurfaceImpl
;
67 typedef struct IDirectDrawClipperImpl IDirectDrawClipperImpl
;
68 typedef struct IDirectDrawPaletteImpl IDirectDrawPaletteImpl
;
69 typedef struct IDirect3DDeviceImpl IDirect3DDeviceImpl
;
70 typedef struct IDirect3DLightImpl IDirect3DLightImpl
;
71 typedef struct IDirect3DViewportImpl IDirect3DViewportImpl
;
72 typedef struct IDirect3DMaterialImpl IDirect3DMaterialImpl
;
73 typedef struct IDirect3DExecuteBufferImpl IDirect3DExecuteBufferImpl
;
74 typedef struct IDirect3DVertexBufferImpl IDirect3DVertexBufferImpl
;
75 typedef struct IParentImpl IParentImpl
;
77 /*****************************************************************************
78 * IDirectDraw implementation structure
79 *****************************************************************************/
81 struct IDirectDrawImpl
84 ICOM_VFIELD_MULTI(IDirectDraw7
);
85 ICOM_VFIELD_MULTI(IDirectDraw4
);
86 ICOM_VFIELD_MULTI(IDirectDraw2
);
87 ICOM_VFIELD_MULTI(IDirectDraw
);
88 ICOM_VFIELD_MULTI(IDirect3D7
);
89 ICOM_VFIELD_MULTI(IDirect3D3
);
90 ICOM_VFIELD_MULTI(IDirect3D2
);
91 ICOM_VFIELD_MULTI(IDirect3D
);
97 IWineD3DDevice
*wineD3DDevice
;
98 IDirectDrawSurfaceImpl
*DepthStencilBuffer
;
101 /* misc ddraw fields */
107 /* DirectDraw things, which are not handled by WineD3D */
108 DWORD cooperative_level
;
110 DWORD orig_width
, orig_height
;
119 IDirectDrawSurfaceImpl
*d3d_target
;
121 IDirect3DDeviceImpl
*d3ddevice
;
127 /* The surface type to request */
128 WINED3DSURFTYPE ImplType
;
130 /* The surface list - can't relay this to WineD3D
133 IDirectDrawSurfaceImpl
*surface_list
;
135 /* Our private window class */
139 /* Helpers for surface creation */
140 IDirectDrawSurfaceImpl
*tex_root
;
143 /* For the dll unload cleanup code */
144 IDirectDrawImpl
*next
;
149 /* Declare the VTables. They can be found ddraw.c */
150 const IDirectDraw7Vtbl IDirectDraw7_Vtbl
;
151 const IDirectDraw4Vtbl IDirectDraw4_Vtbl
;
152 const IDirectDraw2Vtbl IDirectDraw2_Vtbl
;
153 const IDirectDrawVtbl IDirectDraw1_Vtbl
;
155 /* Helper structures */
156 typedef struct EnumDisplayModesCBS
159 LPDDENUMMODESCALLBACK2 callback
;
160 } EnumDisplayModesCBS
;
162 typedef struct EnumSurfacesCBS
165 LPDDENUMSURFACESCALLBACK7 callback
;
166 LPDDSURFACEDESC2 pDDSD
;
170 /* Utility functions */
172 DDRAW_Convert_DDSCAPS_1_To_2(const DDSCAPS
* pIn
,
175 DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(const DDDEVICEIDENTIFIER2
* pIn
,
176 DDDEVICEIDENTIFIER
* pOut
);
178 IDirectDrawImpl_Destroy(IDirectDrawImpl
*This
);
181 IDirectDrawImpl_RecreateSurfacesCallback(IDirectDrawSurface7
*surf
,
182 DDSURFACEDESC2
*desc
,
184 /* The cleanup list */
185 extern IDirectDrawImpl
*ddraw_list
;
187 /* The default surface type */
188 extern WINED3DSURFTYPE DefaultSurfaceType
;
190 /*****************************************************************************
191 * IDirectDrawSurface implementation structure
192 *****************************************************************************/
194 struct IDirectDrawSurfaceImpl
196 /* IUnknown fields */
197 ICOM_VFIELD_MULTI(IDirectDrawSurface7
);
198 ICOM_VFIELD_MULTI(IDirectDrawSurface3
);
199 ICOM_VFIELD_MULTI(IDirectDrawGammaControl
);
200 ICOM_VFIELD_MULTI(IDirect3DTexture2
);
201 ICOM_VFIELD_MULTI(IDirect3DTexture
);
207 /* Connections to other Objects */
208 IDirectDrawImpl
*ddraw
;
209 IWineD3DSurface
*WineD3DSurface
;
210 IWineD3DTexture
*wineD3DTexture
;
212 /* This implementation handles attaching surfaces to other surfaces */
213 IDirectDrawSurfaceImpl
*next_attached
;
214 IDirectDrawSurfaceImpl
*first_attached
;
215 IDirectDrawSurfaceImpl
*next_complex
;
216 IDirectDrawSurfaceImpl
*first_complex
;
218 /* Surface description, for GetAttachedSurface */
219 DDSURFACEDESC2 surface_desc
;
222 DWORD uniqueness_value
;
224 WINED3DSURFTYPE ImplType
;
226 /* For D3DDevice creation */
229 /* Clipper objects */
230 IDirectDrawClipperImpl
*clipper
;
232 /* For the ddraw surface list */
233 IDirectDrawSurfaceImpl
*next
;
234 IDirectDrawSurfaceImpl
*prev
;
239 /* VTable declaration. It's located in surface.c / surface_thunks.c */
240 const IDirectDrawSurface7Vtbl IDirectDrawSurface7_Vtbl
;
241 const IDirectDrawSurface3Vtbl IDirectDrawSurface3_Vtbl
;
242 const IDirectDrawGammaControlVtbl IDirectDrawGammaControl_Vtbl
;
243 const IDirect3DTexture2Vtbl IDirect3DTexture2_Vtbl
;
244 const IDirect3DTextureVtbl IDirect3DTexture1_Vtbl
;
246 /* Get the number of bytes per pixel for a given surface */
247 #define PFGET_BPP(pf) (pf.dwFlags&DDPF_PALETTEINDEXED8?1:((pf.dwRGBBitCount+7)/8))
248 #define GET_BPP(desc) PFGET_BPP(desc.ddpfPixelFormat)
250 /*****************************************************************************
251 * IParent Implementation
252 *****************************************************************************/
255 /* IUnknown fields */
256 ICOM_VFIELD_MULTI(IParent
);
259 /* IParentImpl fields */
264 const IParentVtbl IParent_Vtbl
;
266 /*****************************************************************************
267 * IDirect3DDevice implementation
268 *****************************************************************************/
271 DDrawHandle_Unknown
= 0,
272 DDrawHandle_Texture
= 1,
273 DDrawHandle_Material
= 2
279 DDrawHandleTypes type
;
282 struct IDirect3DDeviceImpl
285 ICOM_VFIELD_MULTI(IDirect3DDevice7
);
286 ICOM_VFIELD_MULTI(IDirect3DDevice3
);
287 ICOM_VFIELD_MULTI(IDirect3DDevice2
);
288 ICOM_VFIELD_MULTI(IDirect3DDevice
);
291 /* Other object connections */
292 IWineD3DDevice
*wineD3DDevice
;
293 IDirectDrawImpl
*ddraw
;
294 IWineD3DIndexBuffer
*indexbuffer
;
295 IDirectDrawSurfaceImpl
*target
;
296 BOOL OffScreenTarget
;
298 /* Viewport management */
299 IDirect3DViewportImpl
*viewport_list
;
300 IDirect3DViewportImpl
*current_viewport
;
301 D3DVIEWPORT7 active_viewport
;
306 /* Rendering functions to wrap D3D(1-3) to D3D7 */
307 D3DPRIMITIVETYPE primitive_type
;
311 LPBYTE vertex_buffer
;
315 /* Handle management */
316 struct HandleEntry
*Handles
;
320 /* Vtables in various versions */
321 const IDirect3DDevice7Vtbl IDirect3DDevice7_Vtbl
;
322 const IDirect3DDevice3Vtbl IDirect3DDevice3_Vtbl
;
323 const IDirect3DDevice2Vtbl IDirect3DDevice2_Vtbl
;
324 const IDirect3DDeviceVtbl IDirect3DDevice1_Vtbl
;
327 const GUID IID_D3DDEVICE_WineD3D
;
329 /* Helper functions */
330 HRESULT
IDirect3DImpl_GetCaps(IWineD3D
*WineD3D
, D3DDEVICEDESC
*Desc123
, D3DDEVICEDESC7
*Desc7
);
331 DWORD
IDirect3DDeviceImpl_CreateHandle(IDirect3DDeviceImpl
*This
);
334 struct EnumTextureFormatsCBS
336 LPD3DENUMTEXTUREFORMATSCALLBACK cbv2
;
337 LPD3DENUMPIXELFORMATSCALLBACK cbv7
;
341 /*****************************************************************************
342 * IDirect3D implementation
343 *****************************************************************************/
345 /* No implementation structure as this is only another interface to DirectDraw */
348 const IDirect3DVtbl IDirect3D1_Vtbl
;
349 const IDirect3D2Vtbl IDirect3D2_Vtbl
;
350 const IDirect3D3Vtbl IDirect3D3_Vtbl
;
351 const IDirect3D7Vtbl IDirect3D7_Vtbl
;
353 /* Structure for EnumZBufferFormats */
354 struct EnumZBufferFormatsData
356 LPD3DENUMPIXELFORMATSCALLBACK Callback
;
360 /*****************************************************************************
361 * IDirectDrawClipper implementation structure
362 *****************************************************************************/
363 struct IDirectDrawClipperImpl
365 /* IUnknown fields */
366 ICOM_VFIELD_MULTI(IDirectDrawClipper
);
369 /* IDirectDrawClipper fields */
372 IDirectDrawImpl
* ddraw_owner
;
373 struct IDirectDrawClipperImpl
* prev_ddraw
;
374 struct IDirectDrawClipperImpl
* next_ddraw
;
377 const IDirectDrawClipperVtbl IDirectDrawClipper_Vtbl
;
379 /*****************************************************************************
380 * IDirectDrawPalette implementation structure
381 *****************************************************************************/
382 struct IDirectDrawPaletteImpl
384 /* IUnknown fields */
385 ICOM_VFIELD_MULTI(IDirectDrawPalette
);
389 IWineD3DPalette
*wineD3DPalette
;
391 /* IDirectDrawPalette fields */
392 IDirectDrawImpl
*ddraw_owner
;
394 const IDirectDrawPaletteVtbl IDirectDrawPalette_Vtbl
;
396 /******************************************************************************
397 * DirectDraw ClassFactory Implementation - incomplete
398 ******************************************************************************/
401 ICOM_VFIELD_MULTI(IClassFactory
);
404 HRESULT (*pfnCreateInstance
)(IUnknown
*pUnkOuter
, REFIID iid
, LPVOID
*ppObj
);
407 /* Helper structures */
408 struct object_creation_info
411 HRESULT (*pfnCreateInstance
)(IUnknown
*pUnkOuter
, REFIID riid
,
415 /******************************************************************************
416 * IDirect3DLight implementation structure - Wraps to D3D7
417 ******************************************************************************/
418 struct IDirect3DLightImpl
420 ICOM_VFIELD_MULTI(IDirect3DLight
);
423 /* IDirect3DLight fields */
424 IDirectDrawImpl
*ddraw
;
426 /* If this light is active for one viewport, put the viewport here */
427 IDirect3DViewportImpl
*active_viewport
;
434 /* Chained list used for adding / removing from viewports */
435 IDirect3DLightImpl
*next
;
437 /* Activation function */
438 void (*activate
)(IDirect3DLightImpl
*);
439 void (*desactivate
)(IDirect3DLightImpl
*);
440 void (*update
)(IDirect3DLightImpl
*);
444 const IDirect3DLightVtbl IDirect3DLight_Vtbl
;
446 /* Helper functions */
447 void light_update(IDirect3DLightImpl
* This
);
448 void light_activate(IDirect3DLightImpl
* This
);
449 void light_desactivate(IDirect3DLightImpl
* This
);
451 /******************************************************************************
452 * IDirect3DMaterial implementation structure - Wraps to D3D7
453 ******************************************************************************/
454 struct IDirect3DMaterialImpl
456 ICOM_VFIELD_MULTI(IDirect3DMaterial3
);
457 ICOM_VFIELD_MULTI(IDirect3DMaterial2
);
458 ICOM_VFIELD_MULTI(IDirect3DMaterial
);
461 /* IDirect3DMaterial2 fields */
462 IDirectDrawImpl
*ddraw
;
463 IDirect3DDeviceImpl
*active_device
;
468 void (*activate
)(IDirect3DMaterialImpl
* this);
471 /* VTables in varios versions */
472 const IDirect3DMaterialVtbl IDirect3DMaterial_Vtbl
;
473 const IDirect3DMaterial2Vtbl IDirect3DMaterial2_Vtbl
;
474 const IDirect3DMaterial3Vtbl IDirect3DMaterial3_Vtbl
;
476 /* Helper functions */
477 void material_activate(IDirect3DMaterialImpl
* This
);
479 /*****************************************************************************
480 * IDirect3DViewport - Wraps to D3D7
481 *****************************************************************************/
482 struct IDirect3DViewportImpl
484 ICOM_VFIELD_MULTI(IDirect3DViewport3
);
487 /* IDirect3DViewport fields */
488 IDirectDrawImpl
*ddraw
;
490 /* If this viewport is active for one device, put the device here */
491 IDirect3DDeviceImpl
*active_device
;
504 /* Activation function */
505 void (*activate
)(IDirect3DViewportImpl
*);
507 /* Field used to chain viewports together */
508 IDirect3DViewportImpl
*next
;
511 IDirect3DLightImpl
*lights
;
513 /* Background material */
514 IDirect3DMaterialImpl
*background
;
518 const IDirect3DViewport3Vtbl IDirect3DViewport3_Vtbl
;
520 /* Helper functions */
521 void viewport_activate(IDirect3DViewportImpl
* This
);
523 /*****************************************************************************
524 * IDirect3DExecuteBuffer - Wraps to D3D7
525 *****************************************************************************/
526 struct IDirect3DExecuteBufferImpl
529 ICOM_VFIELD_MULTI(IDirect3DExecuteBuffer
);
532 /* IDirect3DExecuteBuffer fields */
533 IDirectDrawImpl
*ddraw
;
534 IDirect3DDeviceImpl
*d3ddev
;
536 D3DEXECUTEBUFFERDESC desc
;
539 /* This buffer will store the transformed vertices */
544 /* This flags is set to TRUE if we allocated ourselves the
551 const IDirect3DExecuteBufferVtbl IDirect3DExecuteBuffer_Vtbl
;
553 /* The execute function */
555 IDirect3DExecuteBufferImpl_Execute(IDirect3DExecuteBufferImpl
*This
,
556 IDirect3DDeviceImpl
*Device
,
557 IDirect3DViewportImpl
*ViewportImpl
);
559 /*****************************************************************************
560 * IDirect3DVertexBuffer
561 *****************************************************************************/
562 struct IDirect3DVertexBufferImpl
564 /*** IUnknown Methods ***/
565 ICOM_VFIELD_MULTI(IDirect3DVertexBuffer7
);
566 ICOM_VFIELD_MULTI(IDirect3DVertexBuffer
);
569 /*** WineD3D link ***/
570 IWineD3DVertexBuffer
*wineD3DVertexBuffer
;
572 /*** Storage for D3D7 specific things ***/
577 const IDirect3DVertexBuffer7Vtbl IDirect3DVertexBuffer7_Vtbl
;
578 const IDirect3DVertexBufferVtbl IDirect3DVertexBuffer1_Vtbl
;
580 /*****************************************************************************
581 * Helper functions from utils.c
582 *****************************************************************************/
584 #define GET_TEXCOUNT_FROM_FVF(d3dvtVertexType) \
585 (((d3dvtVertexType) & D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT)
587 #define GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType, tex_num) \
588 (((((d3dvtVertexType) >> (16 + (2 * (tex_num)))) + 1) & 0x03) + 1)
590 void PixelFormat_WineD3DtoDD(DDPIXELFORMAT
*DDPixelFormat
, WINED3DFORMAT WineD3DFormat
);
591 WINED3DFORMAT
PixelFormat_DD2WineD3D(DDPIXELFORMAT
*DDPixelFormat
);
592 void DDRAW_dump_surface_desc(const DDSURFACEDESC2
*lpddsd
);
593 void DDRAW_dump_pixelformat(const DDPIXELFORMAT
*PixelFormat
);
594 void dump_D3DMATRIX(D3DMATRIX
*mat
);
595 void DDRAW_dump_DDCAPS(const DDCAPS
*lpcaps
);
596 DWORD
get_flexible_vertex_size(DWORD d3dvtVertexType
);
597 void DDRAW_dump_DDSCAPS2(const DDSCAPS2
*in
);
598 void DDRAW_dump_cooperativelevel(DWORD cooplevel
);
600 /* This only needs to be here as long the processvertices functionality of
601 * IDirect3DExecuteBuffer isn't in WineD3D */
602 void multiply_matrix(LPD3DMATRIX dest
, LPD3DMATRIX src1
, LPD3DMATRIX src2
);
604 /* Used for generic dumping */
611 #define FE(x) { x, #x }
617 void (*func
)(const void *);
622 #define DDRAW_dump_flags(flags,names,num_names) DDRAW_dump_flags_(flags, names, num_names, 1)
623 #define ME(x,f,e) { x, #x, (void (*)(const void *))(f), offsetof(STRUCT, e) }
625 #define DD_STRUCT_COPY_BYSIZE(to,from) \
627 DWORD __size = (to)->dwSize; \
628 DWORD __copysize = __size; \
629 DWORD __resetsize = __size; \
630 assert(to != from); \
631 if (__resetsize > sizeof(*to)) \
632 __resetsize = sizeof(*to); \
633 memset(to,0,__resetsize); \
634 if ((from)->dwSize < __size) \
635 __copysize = (from)->dwSize; \
636 memcpy(to,from,__copysize); \
637 (to)->dwSize = __size;/*restore size*/ \
643 HRESULT
hr_ddraw_from_wined3d(HRESULT hr
);