d3d: Callback infrastructure for implicit depth stencil surface destruction in IWineD...
[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 "ddcomimpl.h"
37
38 #include "wine/wined3d_interface.h"
39 #include "wine/list.h"
40
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;
46
47 #define INTERFACE IParent
48 DECLARE_INTERFACE_(IParent,IUnknown)
49 {
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;
54 };
55 #undef INTERFACE
56
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)
62 #endif
63
64
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;
77
78 /* Callbacks for implicit object destruction */
79 extern ULONG WINAPI D3D7CB_DestroyDepthStencilSurface(IWineD3DSurface *pSurface);
80
81 /*****************************************************************************
82  * IDirectDraw implementation structure
83  *****************************************************************************/
84
85 struct IDirectDrawImpl
86 {
87     /* IUnknown fields */
88     ICOM_VFIELD_MULTI(IDirectDraw7);
89     ICOM_VFIELD_MULTI(IDirectDraw4);
90     ICOM_VFIELD_MULTI(IDirectDraw2);
91     ICOM_VFIELD_MULTI(IDirectDraw);
92     ICOM_VFIELD_MULTI(IDirect3D7);
93     ICOM_VFIELD_MULTI(IDirect3D3);
94     ICOM_VFIELD_MULTI(IDirect3D2);
95     ICOM_VFIELD_MULTI(IDirect3D);
96
97     /* See comment in IDirectDraw::AddRef */
98     LONG                    ref7, ref4, ref2, ref1, numIfaces;
99
100     /* WineD3D linkage */
101     IWineD3D                *wineD3D;
102     IWineD3DDevice          *wineD3DDevice;
103     IDirectDrawSurfaceImpl  *DepthStencilBuffer;
104     BOOL                    d3d_initialized;
105
106     /* Misc ddraw fields */
107     UINT                    total_vidmem;
108     DWORD                   cur_scanline;
109     BOOL                    fake_vblank;
110     BOOL                    initialized;
111
112     /* DirectDraw things, which are not handled by WineD3D */
113     DWORD                   cooperative_level;
114
115     DWORD                   orig_width, orig_height;
116     DWORD                   orig_bpp;
117
118     DDCAPS                  caps;
119
120     LONG                    style;
121     LONG                    exStyle;
122
123     /* D3D things */
124     IDirectDrawSurfaceImpl  *d3d_target;
125     HWND                    d3d_window;
126     IDirect3DDeviceImpl     *d3ddevice;
127     int                     d3dversion;
128
129     /* Various HWNDs */
130     HWND                    focuswindow;
131     HWND                    devicewindow;
132
133     /* The surface type to request */
134     WINED3DSURFTYPE         ImplType;
135
136
137     /* Our private window class */
138     char classname[32];
139     WNDCLASSA wnd_class;
140
141     /* Helpers for surface creation */
142     IDirectDrawSurfaceImpl *tex_root;
143     BOOL                    depthstencil;
144
145     /* For the dll unload cleanup code */
146     struct list ddraw_list_entry;
147     /* The surface list - can't relay this to WineD3D
148      * because of IParent
149      */
150     struct list surface_list;
151     LONG surfaces;
152 };
153
154 /* Declare the VTables. They can be found ddraw.c */
155 const IDirectDraw7Vtbl IDirectDraw7_Vtbl;
156 const IDirectDraw4Vtbl IDirectDraw4_Vtbl;
157 const IDirectDraw2Vtbl IDirectDraw2_Vtbl;
158 const IDirectDrawVtbl  IDirectDraw1_Vtbl;
159
160 /* Helper structures */
161 typedef struct EnumDisplayModesCBS
162 {
163     void *context;
164     LPDDENUMMODESCALLBACK2 callback;
165 } EnumDisplayModesCBS;
166
167 typedef struct EnumSurfacesCBS
168 {
169     void *context;
170     LPDDENUMSURFACESCALLBACK7 callback;
171     LPDDSURFACEDESC2 pDDSD;
172     DWORD Flags;
173 } EnumSurfacesCBS;
174
175 /* Utility functions */
176 void
177 DDRAW_Convert_DDSCAPS_1_To_2(const DDSCAPS* pIn,
178                              DDSCAPS2* pOut);
179 void
180 DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(const DDDEVICEIDENTIFIER2* pIn,
181                                         DDDEVICEIDENTIFIER* pOut);
182 void
183 IDirectDrawImpl_Destroy(IDirectDrawImpl *This);
184
185 HRESULT WINAPI
186 IDirectDrawImpl_RecreateSurfacesCallback(IDirectDrawSurface7 *surf,
187                                          DDSURFACEDESC2 *desc,
188                                          void *Context);
189 void
190 remove_ddraw_object(IDirectDrawImpl *ddraw);
191
192 /* The default surface type */
193 extern WINED3DSURFTYPE DefaultSurfaceType;
194
195 /*****************************************************************************
196  * IDirectDrawSurface implementation structure
197  *****************************************************************************/
198
199 struct IDirectDrawSurfaceImpl
200 {
201     /* IUnknown fields */
202     ICOM_VFIELD_MULTI(IDirectDrawSurface7);
203     ICOM_VFIELD_MULTI(IDirectDrawSurface3);
204     ICOM_VFIELD_MULTI(IDirectDrawGammaControl);
205     ICOM_VFIELD_MULTI(IDirect3DTexture2);
206     ICOM_VFIELD_MULTI(IDirect3DTexture);
207
208     LONG                     ref;
209     IUnknown                *ifaceToRelease;
210
211     int                     version;
212
213     /* Connections to other Objects */
214     IDirectDrawImpl         *ddraw;
215     IWineD3DSurface         *WineD3DSurface;
216     IWineD3DTexture         *wineD3DTexture;
217
218     /* This implementation handles attaching surfaces to other surfaces */
219     IDirectDrawSurfaceImpl  *next_attached;
220     IDirectDrawSurfaceImpl  *first_attached;
221     IDirectDrawSurfaceImpl  *next_complex;
222     IDirectDrawSurfaceImpl  *first_complex;
223
224     /* Surface description, for GetAttachedSurface */
225     DDSURFACEDESC2          surface_desc;
226
227     /* Misc things */
228     DWORD                   uniqueness_value;
229     UINT                    mipmap_level;
230     WINED3DSURFTYPE         ImplType;
231
232     /* For D3DDevice creation */
233     BOOL                    isRenderTarget;
234
235     /* Clipper objects */
236     IDirectDrawClipperImpl  *clipper;
237
238     /* For the ddraw surface list */
239     struct list             surface_list_entry;
240
241     DWORD                   Handle;
242 };
243
244 /* VTable declaration. It's located in surface.c / surface_thunks.c */
245 const IDirectDrawSurface7Vtbl IDirectDrawSurface7_Vtbl;
246 const IDirectDrawSurface3Vtbl IDirectDrawSurface3_Vtbl;
247 const IDirectDrawGammaControlVtbl IDirectDrawGammaControl_Vtbl;
248 const IDirect3DTexture2Vtbl IDirect3DTexture2_Vtbl;
249 const IDirect3DTextureVtbl IDirect3DTexture1_Vtbl;
250
251 /* Get the number of bytes per pixel for a given surface */
252 #define PFGET_BPP(pf) (pf.dwFlags&DDPF_PALETTEINDEXED8?1:((pf.dwRGBBitCount+7)/8))
253 #define GET_BPP(desc) PFGET_BPP(desc.ddpfPixelFormat)
254
255 /*****************************************************************************
256  * IParent Implementation
257  *****************************************************************************/
258 struct IParentImpl
259 {
260     /* IUnknown fields */
261     ICOM_VFIELD_MULTI(IParent);
262     LONG                    ref;
263
264     /* IParentImpl fields */
265     IUnknown      *child;
266
267 };
268
269 const IParentVtbl IParent_Vtbl;
270
271 /*****************************************************************************
272  * IDirect3DDevice implementation
273  *****************************************************************************/
274 typedef enum
275 {
276     DDrawHandle_Unknown       = 0,
277     DDrawHandle_Texture       = 1,
278     DDrawHandle_Material      = 2,
279     DDrawHandle_Matrix        = 3,
280     DDrawHandle_StateBlock    = 4
281 } DDrawHandleTypes;
282
283 struct HandleEntry
284 {
285     void    *ptr;
286     DDrawHandleTypes      type;
287 };
288
289 struct IDirect3DDeviceImpl
290 {
291     /* IUnknown */
292     ICOM_VFIELD_MULTI(IDirect3DDevice7);
293     ICOM_VFIELD_MULTI(IDirect3DDevice3);
294     ICOM_VFIELD_MULTI(IDirect3DDevice2);
295     ICOM_VFIELD_MULTI(IDirect3DDevice);
296     LONG                    ref;
297
298     /* Other object connections */
299     IWineD3DDevice          *wineD3DDevice;
300     IDirectDrawImpl         *ddraw;
301     IWineD3DIndexBuffer     *indexbuffer;
302     IDirectDrawSurfaceImpl  *target;
303     BOOL                    OffScreenTarget;
304
305     /* Viewport management */
306     IDirect3DViewportImpl *viewport_list;
307     IDirect3DViewportImpl *current_viewport;
308     D3DVIEWPORT7 active_viewport;
309
310     /* Light state */
311     DWORD material;
312
313     /* Rendering functions to wrap D3D(1-3) to D3D7 */
314     D3DPRIMITIVETYPE primitive_type;
315     DWORD vertex_type;
316     DWORD render_flags;
317     DWORD nb_vertices;
318     LPBYTE vertex_buffer;
319     DWORD vertex_size;
320     DWORD buffer_size;
321
322     /* Handle management */
323     struct HandleEntry      *Handles;
324     DWORD                    numHandles;
325 };
326
327 /* Vtables in various versions */
328 const IDirect3DDevice7Vtbl IDirect3DDevice7_Vtbl;
329 const IDirect3DDevice3Vtbl IDirect3DDevice3_Vtbl;
330 const IDirect3DDevice2Vtbl IDirect3DDevice2_Vtbl;
331 const IDirect3DDeviceVtbl  IDirect3DDevice1_Vtbl;
332
333 /* The IID */
334 const GUID IID_D3DDEVICE_WineD3D;
335
336 /* Helper functions */
337 HRESULT IDirect3DImpl_GetCaps(IWineD3D *WineD3D, D3DDEVICEDESC *Desc123, D3DDEVICEDESC7 *Desc7);
338 DWORD IDirect3DDeviceImpl_CreateHandle(IDirect3DDeviceImpl *This);
339
340 /* Structures */
341 struct EnumTextureFormatsCBS
342 {
343     LPD3DENUMTEXTUREFORMATSCALLBACK cbv2;
344     LPD3DENUMPIXELFORMATSCALLBACK cbv7;
345     void *Context;
346 };
347
348 /*****************************************************************************
349  * IDirect3D implementation
350  *****************************************************************************/
351
352 /* No implementation structure as this is only another interface to DirectDraw */
353
354 /* the Vtables */
355 const IDirect3DVtbl  IDirect3D1_Vtbl;
356 const IDirect3D2Vtbl IDirect3D2_Vtbl;
357 const IDirect3D3Vtbl IDirect3D3_Vtbl;
358 const IDirect3D7Vtbl IDirect3D7_Vtbl;
359
360 /* Structure for EnumZBufferFormats */
361 struct EnumZBufferFormatsData
362 {
363     LPD3DENUMPIXELFORMATSCALLBACK Callback;
364     void *Context;
365 };
366
367 /*****************************************************************************
368  * IDirectDrawClipper implementation structure
369  *****************************************************************************/
370 struct IDirectDrawClipperImpl
371 {
372     /* IUnknown fields */
373     ICOM_VFIELD_MULTI(IDirectDrawClipper);
374     LONG ref;
375
376     /* IDirectDrawClipper fields */
377     HWND hWnd;
378
379     IDirectDrawImpl* ddraw_owner;
380     struct IDirectDrawClipperImpl* prev_ddraw;
381     struct IDirectDrawClipperImpl* next_ddraw;
382 };
383
384 const IDirectDrawClipperVtbl IDirectDrawClipper_Vtbl;
385
386 /*****************************************************************************
387  * IDirectDrawPalette implementation structure
388  *****************************************************************************/
389 struct IDirectDrawPaletteImpl
390 {
391     /* IUnknown fields */
392     ICOM_VFIELD_MULTI(IDirectDrawPalette);
393     LONG ref;
394
395     /* WineD3D uplink */
396     IWineD3DPalette           *wineD3DPalette;
397
398     /* IDirectDrawPalette fields */
399     IDirectDrawImpl           *ddraw_owner;
400     IUnknown                  *ifaceToRelease;
401 };
402 const IDirectDrawPaletteVtbl IDirectDrawPalette_Vtbl;
403
404 /******************************************************************************
405  * DirectDraw ClassFactory implementation - incomplete
406  ******************************************************************************/
407 typedef struct
408 {
409     ICOM_VFIELD_MULTI(IClassFactory);
410
411     LONG ref;
412     HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, REFIID iid, LPVOID *ppObj);
413 } IClassFactoryImpl;
414
415 /* Helper structures */
416 struct object_creation_info
417 {
418     const CLSID *clsid;
419     HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, REFIID riid,
420                                  void **ppObj);
421 };
422
423 /******************************************************************************
424  * IDirect3DLight implementation structure - Wraps to D3D7
425  ******************************************************************************/
426 struct IDirect3DLightImpl
427 {
428     ICOM_VFIELD_MULTI(IDirect3DLight);
429     LONG ref;
430
431     /* IDirect3DLight fields */
432     IDirectDrawImpl           *ddraw;
433
434     /* If this light is active for one viewport, put the viewport here */
435     IDirect3DViewportImpl     *active_viewport;
436
437     D3DLIGHT2 light;
438     D3DLIGHT7 light7;
439
440     DWORD dwLightIndex;
441
442     /* Chained list used for adding / removing from viewports */
443     IDirect3DLightImpl        *next;
444
445     /* Activation function */
446     void                      (*activate)(IDirect3DLightImpl*);
447     void                      (*desactivate)(IDirect3DLightImpl*);
448     void                      (*update)(IDirect3DLightImpl*);
449 };
450
451 /* Vtable */
452 const IDirect3DLightVtbl IDirect3DLight_Vtbl;
453
454 /* Helper functions */
455 void light_update(IDirect3DLightImpl* This);
456 void light_activate(IDirect3DLightImpl* This);
457 void light_desactivate(IDirect3DLightImpl* This);
458
459 /******************************************************************************
460  * IDirect3DMaterial implementation structure - Wraps to D3D7
461  ******************************************************************************/
462 struct IDirect3DMaterialImpl
463 {
464     ICOM_VFIELD_MULTI(IDirect3DMaterial3);
465     ICOM_VFIELD_MULTI(IDirect3DMaterial2);
466     ICOM_VFIELD_MULTI(IDirect3DMaterial);
467     LONG  ref;
468
469     /* IDirect3DMaterial2 fields */
470     IDirectDrawImpl               *ddraw;
471     IDirect3DDeviceImpl           *active_device;
472
473     D3DMATERIAL mat;
474     DWORD Handle;
475
476     void (*activate)(IDirect3DMaterialImpl* this);
477 };
478
479 /* VTables in various versions */
480 const IDirect3DMaterialVtbl IDirect3DMaterial_Vtbl;
481 const IDirect3DMaterial2Vtbl IDirect3DMaterial2_Vtbl;
482 const IDirect3DMaterial3Vtbl IDirect3DMaterial3_Vtbl;
483
484 /* Helper functions */
485 void material_activate(IDirect3DMaterialImpl* This);
486
487 /*****************************************************************************
488  * IDirect3DViewport - Wraps to D3D7
489  *****************************************************************************/
490 struct IDirect3DViewportImpl
491 {
492     ICOM_VFIELD_MULTI(IDirect3DViewport3);
493     LONG ref;
494
495     /* IDirect3DViewport fields */
496     IDirectDrawImpl           *ddraw;
497
498     /* If this viewport is active for one device, put the device here */
499     IDirect3DDeviceImpl       *active_device;
500
501     DWORD                     num_lights;
502     DWORD                     map_lights;
503
504     int                       use_vp2;
505
506     union
507     {
508         D3DVIEWPORT vp1;
509         D3DVIEWPORT2 vp2;
510     } viewports;
511
512     /* Activation function */
513     void                      (*activate)(IDirect3DViewportImpl*);
514
515     /* Field used to chain viewports together */
516     IDirect3DViewportImpl     *next;
517
518     /* Lights list */
519     IDirect3DLightImpl        *lights;
520
521     /* Background material */
522     IDirect3DMaterialImpl     *background;
523 };
524
525 /* Vtable */
526 const IDirect3DViewport3Vtbl IDirect3DViewport3_Vtbl;
527
528 /* Helper functions */
529 void viewport_activate(IDirect3DViewportImpl* This);
530
531 /*****************************************************************************
532  * IDirect3DExecuteBuffer - Wraps to D3D7
533  *****************************************************************************/
534 struct IDirect3DExecuteBufferImpl
535 {
536     /* IUnknown */
537     ICOM_VFIELD_MULTI(IDirect3DExecuteBuffer);
538     LONG                 ref;
539
540     /* IDirect3DExecuteBuffer fields */
541     IDirectDrawImpl      *ddraw;
542     IDirect3DDeviceImpl  *d3ddev;
543
544     D3DEXECUTEBUFFERDESC desc;
545     D3DEXECUTEDATA       data;
546
547     /* This buffer will store the transformed vertices */
548     void                 *vertex_data;
549     WORD                 *indices;
550     int                  nb_indices;
551
552     /* This flags is set to TRUE if we allocated ourselves the
553      * data buffer
554      */
555     BOOL                 need_free;
556 };
557
558 /* The VTable */
559 const IDirect3DExecuteBufferVtbl IDirect3DExecuteBuffer_Vtbl;
560
561 /* The execute function */
562 void
563 IDirect3DExecuteBufferImpl_Execute(IDirect3DExecuteBufferImpl *This,
564                                    IDirect3DDeviceImpl *Device,
565                                    IDirect3DViewportImpl *ViewportImpl);
566
567 /*****************************************************************************
568  * IDirect3DVertexBuffer
569  *****************************************************************************/
570 struct IDirect3DVertexBufferImpl
571 {
572     /*** IUnknown Methods ***/
573     ICOM_VFIELD_MULTI(IDirect3DVertexBuffer7);
574     ICOM_VFIELD_MULTI(IDirect3DVertexBuffer);
575     LONG                 ref;
576
577     /*** WineD3D link ***/
578     IWineD3DVertexBuffer *wineD3DVertexBuffer;
579
580     /*** Storage for D3D7 specific things ***/
581     DWORD                Caps;
582 };
583
584 /* The Vtables */
585 const IDirect3DVertexBuffer7Vtbl IDirect3DVertexBuffer7_Vtbl;
586 const IDirect3DVertexBufferVtbl IDirect3DVertexBuffer1_Vtbl;
587
588 /*****************************************************************************
589  * Helper functions from utils.c
590  *****************************************************************************/
591
592 #define GET_TEXCOUNT_FROM_FVF(d3dvtVertexType) \
593     (((d3dvtVertexType) & D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT)
594
595 #define GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType, tex_num) \
596     (((((d3dvtVertexType) >> (16 + (2 * (tex_num)))) + 1) & 0x03) + 1)
597
598 void PixelFormat_WineD3DtoDD(DDPIXELFORMAT *DDPixelFormat, WINED3DFORMAT WineD3DFormat);
599 WINED3DFORMAT PixelFormat_DD2WineD3D(DDPIXELFORMAT *DDPixelFormat);
600 void DDRAW_dump_surface_desc(const DDSURFACEDESC2 *lpddsd);
601 void DDRAW_dump_pixelformat(const DDPIXELFORMAT *PixelFormat);
602 void dump_D3DMATRIX(D3DMATRIX *mat);
603 void DDRAW_dump_DDCAPS(const DDCAPS *lpcaps);
604 DWORD get_flexible_vertex_size(DWORD d3dvtVertexType);
605 void DDRAW_dump_DDSCAPS2(const DDSCAPS2 *in);
606 void DDRAW_dump_cooperativelevel(DWORD cooplevel);
607
608 /* This only needs to be here as long the processvertices functionality of
609  * IDirect3DExecuteBuffer isn't in WineD3D */
610 void multiply_matrix(LPD3DMATRIX dest, LPD3DMATRIX src1, LPD3DMATRIX src2);
611
612 /* Used for generic dumping */
613 typedef struct
614 {
615     DWORD val;
616     const char* name;
617 } flag_info;
618
619 #define FE(x) { x, #x }
620
621 typedef struct
622 {
623     DWORD val;
624     const char* name;
625     void (*func)(const void *);
626     ptrdiff_t offset;
627 } member_info;
628
629 /* Structure copy */
630 #define DDRAW_dump_flags(flags,names,num_names) DDRAW_dump_flags_(flags, names, num_names, 1)
631 #define ME(x,f,e) { x, #x, (void (*)(const void *))(f), offsetof(STRUCT, e) }
632
633 #define DD_STRUCT_COPY_BYSIZE(to,from)                  \
634         do {                                            \
635                 DWORD __size = (to)->dwSize;            \
636                 DWORD __copysize = __size;              \
637                 DWORD __resetsize = __size;             \
638                 assert(to != from);                     \
639                 if (__resetsize > sizeof(*to))          \
640                     __resetsize = sizeof(*to);          \
641                 memset(to,0,__resetsize);               \
642                 if ((from)->dwSize < __size)            \
643                     __copysize = (from)->dwSize;        \
644                 memcpy(to,from,__copysize);             \
645                 (to)->dwSize = __size;/*restore size*/  \
646         } while (0)
647
648
649 #endif
650
651 HRESULT hr_ddraw_from_wined3d(HRESULT hr);