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