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