e9f5acf6fa1761768f94e544ffdf067044b38678
[reactos.git] / reactos / dll / directx / wine / 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 #include <config.h>
23 #include <wine/port.h>
24
25 #define _INC_WINDOWS
26 #define COM_NO_WINDOWS_H
27
28 #include <assert.h>
29 #define COBJMACROS
30 #define NONAMELESSSTRUCT
31 #define NONAMELESSUNION
32
33 #include <wine/debug.h>
34 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
35
36 #include <winbase.h>
37 #include <wingdi.h>
38 #include <winuser.h>
39
40 #include <initguid.h>
41 #include <d3d.h>
42
43 #include <wine/list.h>
44 #include <wine/wined3d.h>
45
46 extern const struct wined3d_parent_ops ddraw_null_wined3d_parent_ops DECLSPEC_HIDDEN;
47 extern DWORD force_refresh_rate DECLSPEC_HIDDEN;
48
49 /*****************************************************************************
50 * IDirectDraw implementation structure
51 *****************************************************************************/
52 struct FvfToDecl
53 {
54 DWORD fvf;
55 struct wined3d_vertex_declaration *decl;
56 };
57
58 #define DDRAW_INITIALIZED 0x00000001
59 #define DDRAW_D3D_INITIALIZED 0x00000002
60 #define DDRAW_RESTORE_MODE 0x00000004
61 #define DDRAW_NO3D 0x00000008
62 #define DDRAW_SCL_DDRAW1 0x00000010
63
64 #define DDRAW_STRIDE_ALIGNMENT 8
65
66 struct ddraw
67 {
68 /* Interfaces */
69 IDirectDraw7 IDirectDraw7_iface;
70 IDirectDraw4 IDirectDraw4_iface;
71 IDirectDraw2 IDirectDraw2_iface;
72 IDirectDraw IDirectDraw_iface;
73 IDirect3D7 IDirect3D7_iface;
74 IDirect3D3 IDirect3D3_iface;
75 IDirect3D2 IDirect3D2_iface;
76 IDirect3D IDirect3D_iface;
77 struct wined3d_device_parent device_parent;
78
79 /* See comment in IDirectDraw::AddRef */
80 LONG ref7, ref4, ref2, ref3, ref1, numIfaces;
81
82 struct wined3d *wined3d;
83 struct wined3d_device *wined3d_device;
84 DWORD flags;
85
86 struct ddraw_surface *primary;
87 RECT primary_lock;
88 struct wined3d_surface *wined3d_frontbuffer;
89 struct wined3d_swapchain *wined3d_swapchain;
90 HWND swapchain_window;
91
92 /* DirectDraw things, which are not handled by WineD3D */
93 DWORD cooperative_level;
94
95 /* D3D things */
96 HWND d3d_window;
97 struct d3d_device *d3ddevice;
98 int d3dversion;
99
100 /* Various HWNDs */
101 HWND focuswindow;
102 HWND devicewindow;
103 HWND dest_window;
104
105 /* For the dll unload cleanup code */
106 struct list ddraw_list_entry;
107 /* The surface list - can't relay this to WineD3D
108 * because of IParent
109 */
110 struct list surface_list;
111
112 /* FVF management */
113 struct FvfToDecl *decls;
114 UINT numConvertedDecls, declArraySize;
115 };
116
117 #define DDRAW_WINDOW_CLASS_NAME "DirectDrawDeviceWnd"
118
119 HRESULT ddraw_init(struct ddraw *ddraw, enum wined3d_device_type device_type) DECLSPEC_HIDDEN;
120 void ddraw_destroy_swapchain(struct ddraw *ddraw) DECLSPEC_HIDDEN;
121
122 static inline void ddraw_set_swapchain_window(struct ddraw *ddraw, HWND window)
123 {
124 if (window == GetDesktopWindow())
125 window = NULL;
126 ddraw->swapchain_window = window;
127 }
128
129 /* Utility functions */
130 void DDRAW_Convert_DDSCAPS_1_To_2(const DDSCAPS *pIn, DDSCAPS2 *pOut) DECLSPEC_HIDDEN;
131 void DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(const DDDEVICEIDENTIFIER2 *pIn, DDDEVICEIDENTIFIER *pOut) DECLSPEC_HIDDEN;
132 struct wined3d_vertex_declaration *ddraw_find_decl(struct ddraw *ddraw, DWORD fvf) DECLSPEC_HIDDEN;
133
134 struct ddraw_surface
135 {
136 /* IUnknown fields */
137 IDirectDrawSurface7 IDirectDrawSurface7_iface;
138 IDirectDrawSurface4 IDirectDrawSurface4_iface;
139 IDirectDrawSurface3 IDirectDrawSurface3_iface;
140 IDirectDrawSurface2 IDirectDrawSurface2_iface;
141 IDirectDrawSurface IDirectDrawSurface_iface;
142 IDirectDrawGammaControl IDirectDrawGammaControl_iface;
143 IDirect3DTexture2 IDirect3DTexture2_iface;
144 IDirect3DTexture IDirect3DTexture_iface;
145
146 LONG ref7, ref4, ref3, ref2, ref1, iface_count, gamma_count;
147 IUnknown *ifaceToRelease;
148 IUnknown *texture_outer;
149
150 int version;
151
152 /* Connections to other Objects */
153 struct ddraw *ddraw;
154 struct wined3d_surface *wined3d_surface;
155 struct wined3d_texture *wined3d_texture;
156 struct d3d_device *device1;
157
158 /* This implementation handles attaching surfaces to other surfaces */
159 struct ddraw_surface *next_attached;
160 struct ddraw_surface *first_attached;
161 IUnknown *attached_iface;
162
163 /* Complex surfaces are organized in a tree, although the tree is degenerated to a list in most cases.
164 * In mipmap and primary surfaces each level has only one attachment, which is the next surface level.
165 * Only the cube texture root has 6 surfaces attached, which then have a normal mipmap chain attached
166 * to them. So hardcode the array to 6, a dynamic array or a list would be an overkill.
167 */
168 #define MAX_COMPLEX_ATTACHED 6
169 struct ddraw_surface *complex_array[MAX_COMPLEX_ATTACHED];
170 /* You can't traverse the tree upwards. Only a flag for Surface::Release because its needed there,
171 * but no pointer to prevent temptations to traverse it in the wrong direction.
172 */
173 BOOL is_complex_root;
174
175 /* Surface description, for GetAttachedSurface */
176 DDSURFACEDESC2 surface_desc;
177
178 /* Misc things */
179 DWORD uniqueness_value;
180 UINT mipmap_level;
181
182 /* Clipper objects */
183 struct ddraw_clipper *clipper;
184
185 /* For the ddraw surface list */
186 struct list surface_list_entry;
187
188 DWORD Handle;
189 };
190
191 HRESULT ddraw_surface_create_texture(struct ddraw_surface *surface, DWORD surface_flags) DECLSPEC_HIDDEN;
192 HRESULT ddraw_surface_init(struct ddraw_surface *surface, struct ddraw *ddraw,
193 DDSURFACEDESC2 *desc, DWORD flags, UINT version) DECLSPEC_HIDDEN;
194 ULONG ddraw_surface_release_iface(struct ddraw_surface *This) DECLSPEC_HIDDEN;
195
196 static inline struct ddraw_surface *impl_from_IDirect3DTexture(IDirect3DTexture *iface)
197 {
198 return CONTAINING_RECORD(iface, struct ddraw_surface, IDirect3DTexture_iface);
199 }
200
201 static inline struct ddraw_surface *impl_from_IDirect3DTexture2(IDirect3DTexture2 *iface)
202 {
203 return CONTAINING_RECORD(iface, struct ddraw_surface, IDirect3DTexture2_iface);
204 }
205
206 static inline struct ddraw_surface *impl_from_IDirectDrawSurface(IDirectDrawSurface *iface)
207 {
208 return CONTAINING_RECORD(iface, struct ddraw_surface, IDirectDrawSurface_iface);
209 }
210
211 static inline struct ddraw_surface *impl_from_IDirectDrawSurface2(IDirectDrawSurface2 *iface)
212 {
213 return CONTAINING_RECORD(iface, struct ddraw_surface, IDirectDrawSurface2_iface);
214 }
215
216 static inline struct ddraw_surface *impl_from_IDirectDrawSurface3(IDirectDrawSurface3 *iface)
217 {
218 return CONTAINING_RECORD(iface, struct ddraw_surface, IDirectDrawSurface3_iface);
219 }
220
221 static inline struct ddraw_surface *impl_from_IDirectDrawSurface4(IDirectDrawSurface4 *iface)
222 {
223 return CONTAINING_RECORD(iface, struct ddraw_surface, IDirectDrawSurface4_iface);
224 }
225
226 static inline struct ddraw_surface *impl_from_IDirectDrawSurface7(IDirectDrawSurface7 *iface)
227 {
228 return CONTAINING_RECORD(iface, struct ddraw_surface, IDirectDrawSurface7_iface);
229 }
230
231 struct ddraw_surface *unsafe_impl_from_IDirectDrawSurface(IDirectDrawSurface *iface) DECLSPEC_HIDDEN;
232 struct ddraw_surface *unsafe_impl_from_IDirectDrawSurface4(IDirectDrawSurface4 *iface) DECLSPEC_HIDDEN;
233 struct ddraw_surface *unsafe_impl_from_IDirectDrawSurface7(IDirectDrawSurface7 *iface) DECLSPEC_HIDDEN;
234
235 struct ddraw_surface *unsafe_impl_from_IDirect3DTexture(IDirect3DTexture *iface) DECLSPEC_HIDDEN;
236 struct ddraw_surface *unsafe_impl_from_IDirect3DTexture2(IDirect3DTexture2 *iface) DECLSPEC_HIDDEN;
237
238 #define DDRAW_INVALID_HANDLE ~0U
239
240 enum ddraw_handle_type
241 {
242 DDRAW_HANDLE_FREE,
243 DDRAW_HANDLE_MATERIAL,
244 DDRAW_HANDLE_MATRIX,
245 DDRAW_HANDLE_STATEBLOCK,
246 DDRAW_HANDLE_SURFACE,
247 };
248
249 struct ddraw_handle_entry
250 {
251 void *object;
252 enum ddraw_handle_type type;
253 };
254
255 struct ddraw_handle_table
256 {
257 struct ddraw_handle_entry *entries;
258 struct ddraw_handle_entry *free_entries;
259 UINT table_size;
260 UINT entry_count;
261 };
262
263 BOOL ddraw_handle_table_init(struct ddraw_handle_table *t, UINT initial_size) DECLSPEC_HIDDEN;
264 void ddraw_handle_table_destroy(struct ddraw_handle_table *t) DECLSPEC_HIDDEN;
265 DWORD ddraw_allocate_handle(struct ddraw_handle_table *t, void *object, enum ddraw_handle_type type) DECLSPEC_HIDDEN;
266 void *ddraw_free_handle(struct ddraw_handle_table *t, DWORD handle, enum ddraw_handle_type type) DECLSPEC_HIDDEN;
267 void *ddraw_get_object(struct ddraw_handle_table *t, DWORD handle, enum ddraw_handle_type type) DECLSPEC_HIDDEN;
268
269 struct d3d_device
270 {
271 /* IUnknown */
272 IDirect3DDevice7 IDirect3DDevice7_iface;
273 IDirect3DDevice3 IDirect3DDevice3_iface;
274 IDirect3DDevice2 IDirect3DDevice2_iface;
275 IDirect3DDevice IDirect3DDevice_iface;
276 IUnknown IUnknown_inner;
277 LONG ref;
278 UINT version;
279
280 IUnknown *outer_unknown;
281 struct wined3d_device *wined3d_device;
282 struct ddraw *ddraw;
283 struct ddraw_surface *target;
284
285 struct wined3d_buffer *index_buffer;
286 UINT index_buffer_size;
287 UINT index_buffer_pos;
288
289 struct wined3d_buffer *vertex_buffer;
290 UINT vertex_buffer_size;
291 UINT vertex_buffer_pos;
292
293 /* Viewport management */
294 struct list viewport_list;
295 struct d3d_viewport *current_viewport;
296 D3DVIEWPORT7 active_viewport;
297
298 /* Required to keep track which of two available texture blending modes in d3ddevice3 is used */
299 BOOL legacyTextureBlending;
300
301 D3DMATRIX legacy_projection;
302 D3DMATRIX legacy_clipspace;
303
304 /* Light state */
305 DWORD material;
306
307 /* Rendering functions to wrap D3D(1-3) to D3D7 */
308 D3DPRIMITIVETYPE primitive_type;
309 DWORD vertex_type;
310 DWORD render_flags;
311 DWORD nb_vertices;
312 LPBYTE sysmem_vertex_buffer;
313 DWORD vertex_size;
314 DWORD buffer_size;
315
316 /* Handle management */
317 struct ddraw_handle_table handle_table;
318 D3DMATRIXHANDLE world, proj, view;
319 };
320
321 HRESULT d3d_device_create(struct ddraw *ddraw, struct ddraw_surface *target,
322 UINT version, struct d3d_device **device, IUnknown *outer_unknown) DECLSPEC_HIDDEN;
323 enum wined3d_depth_buffer_type d3d_device_update_depth_stencil(struct d3d_device *device) DECLSPEC_HIDDEN;
324
325 /* The IID */
326 extern const GUID IID_D3DDEVICE_WineD3D DECLSPEC_HIDDEN;
327
328 /* Helper functions */
329 HRESULT IDirect3DImpl_GetCaps(const struct wined3d *wined3d,
330 D3DDEVICEDESC *Desc123, D3DDEVICEDESC7 *Desc7) DECLSPEC_HIDDEN;
331
332 static inline struct d3d_device *impl_from_IDirect3DDevice(IDirect3DDevice *iface)
333 {
334 return CONTAINING_RECORD(iface, struct d3d_device, IDirect3DDevice_iface);
335 }
336
337 static inline struct d3d_device *impl_from_IDirect3DDevice2(IDirect3DDevice2 *iface)
338 {
339 return CONTAINING_RECORD(iface, struct d3d_device, IDirect3DDevice2_iface);
340 }
341
342 static inline struct d3d_device *impl_from_IDirect3DDevice3(IDirect3DDevice3 *iface)
343 {
344 return CONTAINING_RECORD(iface, struct d3d_device, IDirect3DDevice3_iface);
345 }
346
347 static inline struct d3d_device *impl_from_IDirect3DDevice7(IDirect3DDevice7 *iface)
348 {
349 return CONTAINING_RECORD(iface, struct d3d_device, IDirect3DDevice7_iface);
350 }
351
352 struct d3d_device *unsafe_impl_from_IDirect3DDevice(IDirect3DDevice *iface) DECLSPEC_HIDDEN;
353 struct d3d_device *unsafe_impl_from_IDirect3DDevice2(IDirect3DDevice2 *iface) DECLSPEC_HIDDEN;
354 struct d3d_device *unsafe_impl_from_IDirect3DDevice3(IDirect3DDevice3 *iface) DECLSPEC_HIDDEN;
355 struct d3d_device *unsafe_impl_from_IDirect3DDevice7(IDirect3DDevice7 *iface) DECLSPEC_HIDDEN;
356
357 struct ddraw_clipper
358 {
359 IDirectDrawClipper IDirectDrawClipper_iface;
360 LONG ref;
361 HWND window;
362 HRGN region;
363 BOOL initialized;
364 };
365
366 HRESULT ddraw_clipper_init(struct ddraw_clipper *clipper) DECLSPEC_HIDDEN;
367 struct ddraw_clipper *unsafe_impl_from_IDirectDrawClipper(IDirectDrawClipper *iface) DECLSPEC_HIDDEN;
368
369 /*****************************************************************************
370 * IDirectDrawPalette implementation structure
371 *****************************************************************************/
372 struct ddraw_palette
373 {
374 /* IUnknown fields */
375 IDirectDrawPalette IDirectDrawPalette_iface;
376 LONG ref;
377
378 struct wined3d_palette *wineD3DPalette;
379
380 /* IDirectDrawPalette fields */
381 IUnknown *ifaceToRelease;
382 };
383
384 static inline struct ddraw_palette *impl_from_IDirectDrawPalette(IDirectDrawPalette *iface)
385 {
386 return CONTAINING_RECORD(iface, struct ddraw_palette, IDirectDrawPalette_iface);
387 }
388
389 struct ddraw_palette *unsafe_impl_from_IDirectDrawPalette(IDirectDrawPalette *iface) DECLSPEC_HIDDEN;
390
391 HRESULT ddraw_palette_init(struct ddraw_palette *palette,
392 struct ddraw *ddraw, DWORD flags, PALETTEENTRY *entries) DECLSPEC_HIDDEN;
393
394 /* Helper structures */
395 struct object_creation_info
396 {
397 const CLSID *clsid;
398 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, REFIID riid,
399 void **ppObj);
400 };
401
402 /******************************************************************************
403 * IDirect3DLight implementation structure - Wraps to D3D7
404 ******************************************************************************/
405 struct d3d_light
406 {
407 IDirect3DLight IDirect3DLight_iface;
408 LONG ref;
409
410 /* IDirect3DLight fields */
411 struct ddraw *ddraw;
412
413 /* If this light is active for one viewport, put the viewport here */
414 struct d3d_viewport *active_viewport;
415
416 D3DLIGHT2 light;
417 D3DLIGHT7 light7;
418
419 DWORD dwLightIndex;
420
421 struct list entry;
422 };
423
424 /* Helper functions */
425 void light_activate(struct d3d_light *light) DECLSPEC_HIDDEN;
426 void light_deactivate(struct d3d_light *light) DECLSPEC_HIDDEN;
427 void d3d_light_init(struct d3d_light *light, struct ddraw *ddraw) DECLSPEC_HIDDEN;
428 struct d3d_light *unsafe_impl_from_IDirect3DLight(IDirect3DLight *iface) DECLSPEC_HIDDEN;
429
430 /******************************************************************************
431 * IDirect3DMaterial implementation structure - Wraps to D3D7
432 ******************************************************************************/
433 struct d3d_material
434 {
435 IDirect3DMaterial3 IDirect3DMaterial3_iface;
436 IDirect3DMaterial2 IDirect3DMaterial2_iface;
437 IDirect3DMaterial IDirect3DMaterial_iface;
438 LONG ref;
439
440 /* IDirect3DMaterial2 fields */
441 struct ddraw *ddraw;
442 struct d3d_device *active_device;
443
444 D3DMATERIAL mat;
445 DWORD Handle;
446 };
447
448 /* Helper functions */
449 void material_activate(struct d3d_material *material) DECLSPEC_HIDDEN;
450 struct d3d_material *d3d_material_create(struct ddraw *ddraw) DECLSPEC_HIDDEN;
451
452 /*****************************************************************************
453 * IDirect3DViewport - Wraps to D3D7
454 *****************************************************************************/
455 struct d3d_viewport
456 {
457 IDirect3DViewport3 IDirect3DViewport3_iface;
458 LONG ref;
459
460 /* IDirect3DViewport fields */
461 struct ddraw *ddraw;
462
463 /* If this viewport is active for one device, put the device here */
464 struct d3d_device *active_device;
465
466 DWORD num_lights;
467 DWORD map_lights;
468
469 int use_vp2;
470
471 union
472 {
473 D3DVIEWPORT vp1;
474 D3DVIEWPORT2 vp2;
475 } viewports;
476
477 struct list entry;
478 struct list light_list;
479 struct d3d_material *background;
480 };
481
482 struct d3d_viewport *unsafe_impl_from_IDirect3DViewport3(IDirect3DViewport3 *iface) DECLSPEC_HIDDEN;
483 struct d3d_viewport *unsafe_impl_from_IDirect3DViewport2(IDirect3DViewport2 *iface) DECLSPEC_HIDDEN;
484 struct d3d_viewport *unsafe_impl_from_IDirect3DViewport(IDirect3DViewport *iface) DECLSPEC_HIDDEN;
485
486 /* Helper functions */
487 void viewport_activate(struct d3d_viewport *viewport, BOOL ignore_lights) DECLSPEC_HIDDEN;
488 void d3d_viewport_init(struct d3d_viewport *viewport, struct ddraw *ddraw) DECLSPEC_HIDDEN;
489
490 /*****************************************************************************
491 * IDirect3DExecuteBuffer - Wraps to D3D7
492 *****************************************************************************/
493 struct d3d_execute_buffer
494 {
495 IDirect3DExecuteBuffer IDirect3DExecuteBuffer_iface;
496 LONG ref;
497 /* IDirect3DExecuteBuffer fields */
498 struct ddraw *ddraw;
499 struct d3d_device *d3ddev;
500
501 D3DEXECUTEBUFFERDESC desc;
502 D3DEXECUTEDATA data;
503
504 /* This buffer will store the transformed vertices */
505 void *vertex_data;
506 WORD *indices;
507 unsigned int nb_indices;
508 unsigned int nb_vertices;
509
510 /* This flags is set to TRUE if we allocated ourselves the
511 * data buffer
512 */
513 BOOL need_free;
514 };
515
516 HRESULT d3d_execute_buffer_init(struct d3d_execute_buffer *execute_buffer,
517 struct d3d_device *device, D3DEXECUTEBUFFERDESC *desc) DECLSPEC_HIDDEN;
518 struct d3d_execute_buffer *unsafe_impl_from_IDirect3DExecuteBuffer(IDirect3DExecuteBuffer *iface) DECLSPEC_HIDDEN;
519
520 /* The execute function */
521 HRESULT d3d_execute_buffer_execute(struct d3d_execute_buffer *execute_buffer,
522 struct d3d_device *device, struct d3d_viewport *viewport) DECLSPEC_HIDDEN;
523
524 /*****************************************************************************
525 * IDirect3DVertexBuffer
526 *****************************************************************************/
527 struct d3d_vertex_buffer
528 {
529 IDirect3DVertexBuffer7 IDirect3DVertexBuffer7_iface;
530 IDirect3DVertexBuffer IDirect3DVertexBuffer_iface;
531 LONG ref;
532
533 /*** WineD3D and ddraw links ***/
534 struct wined3d_buffer *wineD3DVertexBuffer;
535 struct wined3d_vertex_declaration *wineD3DVertexDeclaration;
536 struct ddraw *ddraw;
537
538 /*** Storage for D3D7 specific things ***/
539 DWORD Caps;
540 DWORD fvf;
541 DWORD size;
542 BOOL dynamic;
543
544 BOOL read_since_last_map;
545 };
546
547 HRESULT d3d_vertex_buffer_create(struct d3d_vertex_buffer **buffer, struct ddraw *ddraw,
548 D3DVERTEXBUFFERDESC *desc) DECLSPEC_HIDDEN;
549 struct d3d_vertex_buffer *unsafe_impl_from_IDirect3DVertexBuffer(IDirect3DVertexBuffer *iface) DECLSPEC_HIDDEN;
550 struct d3d_vertex_buffer *unsafe_impl_from_IDirect3DVertexBuffer7(IDirect3DVertexBuffer7 *iface) DECLSPEC_HIDDEN;
551
552 /*****************************************************************************
553 * Helper functions from utils.c
554 *****************************************************************************/
555
556 #define GET_TEXCOUNT_FROM_FVF(d3dvtVertexType) \
557 (((d3dvtVertexType) & D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT)
558
559 #define GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType, tex_num) \
560 (((((d3dvtVertexType) >> (16 + (2 * (tex_num)))) + 1) & 0x03) + 1)
561
562 void ddrawformat_from_wined3dformat(DDPIXELFORMAT *ddraw_format,
563 enum wined3d_format_id wined3d_format) DECLSPEC_HIDDEN;
564 enum wined3d_format_id wined3dformat_from_ddrawformat(const DDPIXELFORMAT *format) DECLSPEC_HIDDEN;
565 void DDRAW_dump_surface_desc(const DDSURFACEDESC2 *lpddsd) DECLSPEC_HIDDEN;
566 void dump_D3DMATRIX(const D3DMATRIX *mat) DECLSPEC_HIDDEN;
567 void DDRAW_dump_DDCAPS(const DDCAPS *lpcaps) DECLSPEC_HIDDEN;
568 DWORD get_flexible_vertex_size(DWORD d3dvtVertexType) DECLSPEC_HIDDEN;
569 void DDRAW_dump_DDSCAPS2(const DDSCAPS2 *in) DECLSPEC_HIDDEN;
570 void DDRAW_dump_cooperativelevel(DWORD cooplevel) DECLSPEC_HIDDEN;
571 void DDSD_to_DDSD2(const DDSURFACEDESC *in, DDSURFACEDESC2 *out) DECLSPEC_HIDDEN;
572 void DDSD2_to_DDSD(const DDSURFACEDESC2 *in, DDSURFACEDESC *out) DECLSPEC_HIDDEN;
573
574 void multiply_matrix(D3DMATRIX *dst, const D3DMATRIX *src1, const D3DMATRIX *src2) DECLSPEC_HIDDEN;
575
576 /* Used for generic dumping */
577 struct flag_info
578 {
579 DWORD val;
580 const char *name;
581 };
582
583 #define FE(x) { x, #x }
584
585 struct member_info
586 {
587 DWORD val;
588 const char *name;
589 void (*func)(const void *);
590 ptrdiff_t offset;
591 };
592
593 /* Structure copy */
594 #define ME(x,f,e) { x, #x, (void (*)(const void *))(f), offsetof(STRUCT, e) }
595
596 #define DD_STRUCT_COPY_BYSIZE_(to,from,from_size) \
597 do { \
598 DWORD __size = (to)->dwSize; \
599 DWORD __resetsize = min(__size, sizeof(*to)); \
600 DWORD __copysize = min(__resetsize, from_size); \
601 assert(to != from); \
602 memcpy(to, from, __copysize); \
603 memset((char*)(to) + __copysize, 0, __resetsize - __copysize); \
604 (to)->dwSize = __size; /* restore size */ \
605 } while (0)
606
607 #define DD_STRUCT_COPY_BYSIZE(to,from) DD_STRUCT_COPY_BYSIZE_(to,from,(from)->dwSize)
608
609 #define SIZEOF_END_PADDING(type, last_field) \
610 (sizeof(type) - offsetof(type, last_field) - sizeof(((type *)0)->last_field))
611
612 static inline void copy_to_surfacedesc2(DDSURFACEDESC2 *to, DDSURFACEDESC2 *from)
613 {
614 DWORD from_size = from->dwSize;
615 if (from_size == sizeof(DDSURFACEDESC))
616 from_size -= SIZEOF_END_PADDING(DDSURFACEDESC, ddsCaps);
617 to->dwSize = sizeof(DDSURFACEDESC2); /* for struct copy */
618 DD_STRUCT_COPY_BYSIZE_(to, from, from_size);
619 }
620
621 HRESULT hr_ddraw_from_wined3d(HRESULT hr) DECLSPEC_HIDDEN;
622
623 #endif