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