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);
93 /* See comment in IDirectDraw::AddRef */
94 LONG ref7, ref4, ref2, ref1, numIfaces;
98 IWineD3DDevice *wineD3DDevice;
99 IDirectDrawSurfaceImpl *DepthStencilBuffer;
100 BOOL d3d_initialized;
102 /* Misc ddraw fields */
108 /* DirectDraw things, which are not handled by WineD3D */
109 DWORD cooperative_level;
111 DWORD orig_width, orig_height;
120 IDirectDrawSurfaceImpl *d3d_target;
122 IDirect3DDeviceImpl *d3ddevice;
129 /* The surface type to request */
130 WINED3DSURFTYPE ImplType;
132 /* The surface list - can't relay this to WineD3D
135 IDirectDrawSurfaceImpl *surface_list;
137 /* Our private window class */
141 /* Helpers for surface creation */
142 IDirectDrawSurfaceImpl *tex_root;
145 /* For the dll unload cleanup code */
146 IDirectDrawImpl *next;
150 /* Declare the VTables. They can be found ddraw.c */
151 const IDirectDraw7Vtbl IDirectDraw7_Vtbl;
152 const IDirectDraw4Vtbl IDirectDraw4_Vtbl;
153 const IDirectDraw2Vtbl IDirectDraw2_Vtbl;
154 const IDirectDrawVtbl IDirectDraw1_Vtbl;
156 /* Helper structures */
157 typedef struct EnumDisplayModesCBS
160 LPDDENUMMODESCALLBACK2 callback;
161 } EnumDisplayModesCBS;
163 typedef struct EnumSurfacesCBS
166 LPDDENUMSURFACESCALLBACK7 callback;
167 LPDDSURFACEDESC2 pDDSD;
171 /* Utility functions */
173 DDRAW_Convert_DDSCAPS_1_To_2(const DDSCAPS* pIn,
176 DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(const DDDEVICEIDENTIFIER2* pIn,
177 DDDEVICEIDENTIFIER* pOut);
179 IDirectDrawImpl_Destroy(IDirectDrawImpl *This);
182 IDirectDrawImpl_RecreateSurfacesCallback(IDirectDrawSurface7 *surf,
183 DDSURFACEDESC2 *desc,
185 /* The cleanup list */
186 extern IDirectDrawImpl *ddraw_list;
188 /* The default surface type */
189 extern WINED3DSURFTYPE DefaultSurfaceType;
191 /*****************************************************************************
192 * IDirectDrawSurface implementation structure
193 *****************************************************************************/
195 struct IDirectDrawSurfaceImpl
197 /* IUnknown fields */
198 ICOM_VFIELD_MULTI(IDirectDrawSurface7);
199 ICOM_VFIELD_MULTI(IDirectDrawSurface3);
200 ICOM_VFIELD_MULTI(IDirectDrawGammaControl);
201 ICOM_VFIELD_MULTI(IDirect3DTexture2);
202 ICOM_VFIELD_MULTI(IDirect3DTexture);
205 IUnknown *ifaceToRelease;
209 /* Connections to other Objects */
210 IDirectDrawImpl *ddraw;
211 IWineD3DSurface *WineD3DSurface;
212 IWineD3DTexture *wineD3DTexture;
214 /* This implementation handles attaching surfaces to other surfaces */
215 IDirectDrawSurfaceImpl *next_attached;
216 IDirectDrawSurfaceImpl *first_attached;
217 IDirectDrawSurfaceImpl *next_complex;
218 IDirectDrawSurfaceImpl *first_complex;
220 /* Surface description, for GetAttachedSurface */
221 DDSURFACEDESC2 surface_desc;
224 DWORD uniqueness_value;
226 WINED3DSURFTYPE ImplType;
228 /* For D3DDevice creation */
231 /* Clipper objects */
232 IDirectDrawClipperImpl *clipper;
234 /* For the ddraw surface list */
235 IDirectDrawSurfaceImpl *next;
236 IDirectDrawSurfaceImpl *prev;
241 /* VTable declaration. It's located in surface.c / surface_thunks.c */
242 const IDirectDrawSurface7Vtbl IDirectDrawSurface7_Vtbl;
243 const IDirectDrawSurface3Vtbl IDirectDrawSurface3_Vtbl;
244 const IDirectDrawGammaControlVtbl IDirectDrawGammaControl_Vtbl;
245 const IDirect3DTexture2Vtbl IDirect3DTexture2_Vtbl;
246 const IDirect3DTextureVtbl IDirect3DTexture1_Vtbl;
248 /* Get the number of bytes per pixel for a given surface */
249 #define PFGET_BPP(pf) (pf.dwFlags&DDPF_PALETTEINDEXED8?1:((pf.dwRGBBitCount+7)/8))
250 #define GET_BPP(desc) PFGET_BPP(desc.ddpfPixelFormat)
252 /*****************************************************************************
253 * IParent Implementation
254 *****************************************************************************/
257 /* IUnknown fields */
258 ICOM_VFIELD_MULTI(IParent);
261 /* IParentImpl fields */
266 const IParentVtbl IParent_Vtbl;
268 /*****************************************************************************
269 * IDirect3DDevice implementation
270 *****************************************************************************/
273 DDrawHandle_Unknown = 0,
274 DDrawHandle_Texture = 1,
275 DDrawHandle_Material = 2,
276 DDrawHandle_Matrix = 3
282 DDrawHandleTypes type;
285 struct IDirect3DDeviceImpl
288 ICOM_VFIELD_MULTI(IDirect3DDevice7);
289 ICOM_VFIELD_MULTI(IDirect3DDevice3);
290 ICOM_VFIELD_MULTI(IDirect3DDevice2);
291 ICOM_VFIELD_MULTI(IDirect3DDevice);
294 /* Other object connections */
295 IWineD3DDevice *wineD3DDevice;
296 IDirectDrawImpl *ddraw;
297 IWineD3DIndexBuffer *indexbuffer;
298 IDirectDrawSurfaceImpl *target;
299 BOOL OffScreenTarget;
301 /* Viewport management */
302 IDirect3DViewportImpl *viewport_list;
303 IDirect3DViewportImpl *current_viewport;
304 D3DVIEWPORT7 active_viewport;
309 /* Rendering functions to wrap D3D(1-3) to D3D7 */
310 D3DPRIMITIVETYPE primitive_type;
314 LPBYTE vertex_buffer;
318 /* Handle management */
319 struct HandleEntry *Handles;
323 /* Vtables in various versions */
324 const IDirect3DDevice7Vtbl IDirect3DDevice7_Vtbl;
325 const IDirect3DDevice3Vtbl IDirect3DDevice3_Vtbl;
326 const IDirect3DDevice2Vtbl IDirect3DDevice2_Vtbl;
327 const IDirect3DDeviceVtbl IDirect3DDevice1_Vtbl;
330 const GUID IID_D3DDEVICE_WineD3D;
332 /* Helper functions */
333 HRESULT IDirect3DImpl_GetCaps(IWineD3D *WineD3D, D3DDEVICEDESC *Desc123, D3DDEVICEDESC7 *Desc7);
334 DWORD IDirect3DDeviceImpl_CreateHandle(IDirect3DDeviceImpl *This);
337 struct EnumTextureFormatsCBS
339 LPD3DENUMTEXTUREFORMATSCALLBACK cbv2;
340 LPD3DENUMPIXELFORMATSCALLBACK cbv7;
344 /*****************************************************************************
345 * IDirect3D implementation
346 *****************************************************************************/
348 /* No implementation structure as this is only another interface to DirectDraw */
351 const IDirect3DVtbl IDirect3D1_Vtbl;
352 const IDirect3D2Vtbl IDirect3D2_Vtbl;
353 const IDirect3D3Vtbl IDirect3D3_Vtbl;
354 const IDirect3D7Vtbl IDirect3D7_Vtbl;
356 /* Structure for EnumZBufferFormats */
357 struct EnumZBufferFormatsData
359 LPD3DENUMPIXELFORMATSCALLBACK Callback;
363 /*****************************************************************************
364 * IDirectDrawClipper implementation structure
365 *****************************************************************************/
366 struct IDirectDrawClipperImpl
368 /* IUnknown fields */
369 ICOM_VFIELD_MULTI(IDirectDrawClipper);
372 /* IDirectDrawClipper fields */
375 IDirectDrawImpl* ddraw_owner;
376 struct IDirectDrawClipperImpl* prev_ddraw;
377 struct IDirectDrawClipperImpl* next_ddraw;
380 const IDirectDrawClipperVtbl IDirectDrawClipper_Vtbl;
382 /*****************************************************************************
383 * IDirectDrawPalette implementation structure
384 *****************************************************************************/
385 struct IDirectDrawPaletteImpl
387 /* IUnknown fields */
388 ICOM_VFIELD_MULTI(IDirectDrawPalette);
392 IWineD3DPalette *wineD3DPalette;
394 /* IDirectDrawPalette fields */
395 IDirectDrawImpl *ddraw_owner;
396 IUnknown *ifaceToRelease;
398 const IDirectDrawPaletteVtbl IDirectDrawPalette_Vtbl;
400 /******************************************************************************
401 * DirectDraw ClassFactory implementation - incomplete
402 ******************************************************************************/
405 ICOM_VFIELD_MULTI(IClassFactory);
408 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, REFIID iid, LPVOID *ppObj);
411 /* Helper structures */
412 struct object_creation_info
415 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, REFIID riid,
419 /******************************************************************************
420 * IDirect3DLight implementation structure - Wraps to D3D7
421 ******************************************************************************/
422 struct IDirect3DLightImpl
424 ICOM_VFIELD_MULTI(IDirect3DLight);
427 /* IDirect3DLight fields */
428 IDirectDrawImpl *ddraw;
430 /* If this light is active for one viewport, put the viewport here */
431 IDirect3DViewportImpl *active_viewport;
438 /* Chained list used for adding / removing from viewports */
439 IDirect3DLightImpl *next;
441 /* Activation function */
442 void (*activate)(IDirect3DLightImpl*);
443 void (*desactivate)(IDirect3DLightImpl*);
444 void (*update)(IDirect3DLightImpl*);
448 const IDirect3DLightVtbl IDirect3DLight_Vtbl;
450 /* Helper functions */
451 void light_update(IDirect3DLightImpl* This);
452 void light_activate(IDirect3DLightImpl* This);
453 void light_desactivate(IDirect3DLightImpl* This);
455 /******************************************************************************
456 * IDirect3DMaterial implementation structure - Wraps to D3D7
457 ******************************************************************************/
458 struct IDirect3DMaterialImpl
460 ICOM_VFIELD_MULTI(IDirect3DMaterial3);
461 ICOM_VFIELD_MULTI(IDirect3DMaterial2);
462 ICOM_VFIELD_MULTI(IDirect3DMaterial);
465 /* IDirect3DMaterial2 fields */
466 IDirectDrawImpl *ddraw;
467 IDirect3DDeviceImpl *active_device;
472 void (*activate)(IDirect3DMaterialImpl* this);
475 /* VTables in various versions */
476 const IDirect3DMaterialVtbl IDirect3DMaterial_Vtbl;
477 const IDirect3DMaterial2Vtbl IDirect3DMaterial2_Vtbl;
478 const IDirect3DMaterial3Vtbl IDirect3DMaterial3_Vtbl;
480 /* Helper functions */
481 void material_activate(IDirect3DMaterialImpl* This);
483 /*****************************************************************************
484 * IDirect3DViewport - Wraps to D3D7
485 *****************************************************************************/
486 struct IDirect3DViewportImpl
488 ICOM_VFIELD_MULTI(IDirect3DViewport3);
491 /* IDirect3DViewport fields */
492 IDirectDrawImpl *ddraw;
494 /* If this viewport is active for one device, put the device here */
495 IDirect3DDeviceImpl *active_device;
508 /* Activation function */
509 void (*activate)(IDirect3DViewportImpl*);
511 /* Field used to chain viewports together */
512 IDirect3DViewportImpl *next;
515 IDirect3DLightImpl *lights;
517 /* Background material */
518 IDirect3DMaterialImpl *background;
522 const IDirect3DViewport3Vtbl IDirect3DViewport3_Vtbl;
524 /* Helper functions */
525 void viewport_activate(IDirect3DViewportImpl* This);
527 /*****************************************************************************
528 * IDirect3DExecuteBuffer - Wraps to D3D7
529 *****************************************************************************/
530 struct IDirect3DExecuteBufferImpl
533 ICOM_VFIELD_MULTI(IDirect3DExecuteBuffer);
536 /* IDirect3DExecuteBuffer fields */
537 IDirectDrawImpl *ddraw;
538 IDirect3DDeviceImpl *d3ddev;
540 D3DEXECUTEBUFFERDESC desc;
543 /* This buffer will store the transformed vertices */
548 /* This flags is set to TRUE if we allocated ourselves the
555 const IDirect3DExecuteBufferVtbl IDirect3DExecuteBuffer_Vtbl;
557 /* The execute function */
559 IDirect3DExecuteBufferImpl_Execute(IDirect3DExecuteBufferImpl *This,
560 IDirect3DDeviceImpl *Device,
561 IDirect3DViewportImpl *ViewportImpl);
563 /*****************************************************************************
564 * IDirect3DVertexBuffer
565 *****************************************************************************/
566 struct IDirect3DVertexBufferImpl
568 /*** IUnknown Methods ***/
569 ICOM_VFIELD_MULTI(IDirect3DVertexBuffer7);
570 ICOM_VFIELD_MULTI(IDirect3DVertexBuffer);
573 /*** WineD3D link ***/
574 IWineD3DVertexBuffer *wineD3DVertexBuffer;
576 /*** Storage for D3D7 specific things ***/
581 const IDirect3DVertexBuffer7Vtbl IDirect3DVertexBuffer7_Vtbl;
582 const IDirect3DVertexBufferVtbl IDirect3DVertexBuffer1_Vtbl;
584 /*****************************************************************************
585 * Helper functions from utils.c
586 *****************************************************************************/
588 #define GET_TEXCOUNT_FROM_FVF(d3dvtVertexType) \
589 (((d3dvtVertexType) & D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT)
591 #define GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType, tex_num) \
592 (((((d3dvtVertexType) >> (16 + (2 * (tex_num)))) + 1) & 0x03) + 1)
594 void PixelFormat_WineD3DtoDD(DDPIXELFORMAT *DDPixelFormat, WINED3DFORMAT WineD3DFormat);
595 WINED3DFORMAT PixelFormat_DD2WineD3D(DDPIXELFORMAT *DDPixelFormat);
596 void DDRAW_dump_surface_desc(const DDSURFACEDESC2 *lpddsd);
597 void DDRAW_dump_pixelformat(const DDPIXELFORMAT *PixelFormat);
598 void dump_D3DMATRIX(D3DMATRIX *mat);
599 void DDRAW_dump_DDCAPS(const DDCAPS *lpcaps);
600 DWORD get_flexible_vertex_size(DWORD d3dvtVertexType);
601 void DDRAW_dump_DDSCAPS2(const DDSCAPS2 *in);
602 void DDRAW_dump_cooperativelevel(DWORD cooplevel);
604 /* This only needs to be here as long the processvertices functionality of
605 * IDirect3DExecuteBuffer isn't in WineD3D */
606 void multiply_matrix(LPD3DMATRIX dest, LPD3DMATRIX src1, LPD3DMATRIX src2);
608 /* Used for generic dumping */
615 #define FE(x) { x, #x }
621 void (*func)(const void *);
626 #define DDRAW_dump_flags(flags,names,num_names) DDRAW_dump_flags_(flags, names, num_names, 1)
627 #define ME(x,f,e) { x, #x, (void (*)(const void *))(f), offsetof(STRUCT, e) }
629 #define DD_STRUCT_COPY_BYSIZE(to,from) \
631 DWORD __size = (to)->dwSize; \
632 DWORD __copysize = __size; \
633 DWORD __resetsize = __size; \
634 assert(to != from); \
635 if (__resetsize > sizeof(*to)) \
636 __resetsize = sizeof(*to); \
637 memset(to,0,__resetsize); \
638 if ((from)->dwSize < __size) \
639 __copysize = (from)->dwSize; \
640 memcpy(to,from,__copysize); \
641 (to)->dwSize = __size;/*restore size*/ \
647 HRESULT hr_ddraw_from_wined3d(HRESULT hr);