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