include/mscvpdb.h: Use flexible array members for the rest of structures.
[wine.git] / dlls / ddraw / ddraw_private.h
blob7d08ffea3617ab057c82bd7a1d18b7106d153444
1 /*
2 * Copyright 2006 Stefan Dösinger
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.
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.
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
19 #ifndef __WINE_DLLS_DDRAW_DDRAW_PRIVATE_H
20 #define __WINE_DLLS_DDRAW_DDRAW_PRIVATE_H
22 #include <assert.h>
23 #include <limits.h>
24 #include <math.h>
25 #include <stdbool.h>
26 #define COBJMACROS
27 #include "wine/debug.h"
29 #include "winbase.h"
30 #include "wingdi.h"
31 #include "winuser.h"
33 #include "d3d.h"
34 #include "ddraw.h"
35 #ifdef DDRAW_INIT_GUID
36 #include "initguid.h"
37 #endif
38 #include "wine/list.h"
39 #include "wine/wined3d.h"
41 extern const struct wined3d_parent_ops ddraw_null_wined3d_parent_ops;
42 extern DWORD force_refresh_rate;
44 /*****************************************************************************
45 * IDirectDraw implementation structure
46 *****************************************************************************/
47 struct FvfToDecl
49 DWORD fvf;
50 struct wined3d_vertex_declaration *decl;
53 #define DDRAW_INITIALIZED 0x00000001
54 #define DDRAW_D3D_INITIALIZED 0x00000002
55 #define DDRAW_RESTORE_MODE 0x00000004
56 #define DDRAW_NO3D 0x00000008
57 #define DDRAW_SCL_DDRAW1 0x00000010
58 #define DDRAW_SCL_RECURSIVE 0x00000020
59 #define DDRAW_SWAPPED 0x00000040
61 #define DDRAW_STRIDE_ALIGNMENT 8
63 #define DDRAW_WINED3D_FLAGS (WINED3D_LEGACY_DEPTH_BIAS | WINED3D_RESTORE_MODE_ON_ACTIVATE \
64 | WINED3D_FOCUS_MESSAGES | WINED3D_PIXEL_CENTER_INTEGER | WINED3D_LEGACY_UNBOUND_RESOURCE_COLOR \
65 | WINED3D_NO_PRIMITIVE_RESTART | WINED3D_LEGACY_CUBEMAP_FILTERING | WINED3D_NO_DRAW_INDIRECT)
67 #define DDRAW_WINED3D_SWAPCHAIN_FLAGS (WINED3D_SWAPCHAIN_ALLOW_MODE_SWITCH \
68 | WINED3D_SWAPCHAIN_IMPLICIT | WINED3D_SWAPCHAIN_REGISTER_TOPMOST_TIMER)
70 #define DDRAW_MAX_ACTIVE_LIGHTS 32
71 #define DDRAW_MAX_TEXTURES 8
73 enum ddraw_device_state
75 DDRAW_DEVICE_STATE_OK,
76 DDRAW_DEVICE_STATE_LOST,
77 DDRAW_DEVICE_STATE_NOT_RESTORED,
80 struct ddraw
82 /* Interfaces */
83 IDirectDraw7 IDirectDraw7_iface;
84 IDirectDraw4 IDirectDraw4_iface;
85 IDirectDraw2 IDirectDraw2_iface;
86 IDirectDraw IDirectDraw_iface;
87 IDirect3D7 IDirect3D7_iface;
88 IDirect3D3 IDirect3D3_iface;
89 IDirect3D2 IDirect3D2_iface;
90 IDirect3D IDirect3D_iface;
91 struct wined3d_device_parent device_parent;
93 /* See comment in IDirectDraw::AddRef */
94 LONG ref7, ref4, ref2, ref3, ref1, numIfaces;
96 struct wined3d *wined3d;
97 struct wined3d_adapter *wined3d_adapter;
98 struct wined3d_output *wined3d_output;
99 struct wined3d_device *wined3d_device;
100 struct wined3d_device_context *immediate_context;
101 DWORD flags;
102 LONG device_state;
104 struct ddraw_surface *primary;
105 RECT primary_lock;
106 struct wined3d_texture *gdi_surface;
107 struct wined3d_swapchain *wined3d_swapchain;
108 struct wined3d_swapchain_state_parent state_parent;
109 HWND swapchain_window;
111 /* DirectDraw things, which are not handled by WineD3D */
112 DWORD cooperative_level;
114 /* D3D things */
115 HWND d3d_window;
116 struct list d3ddevice_list;
117 int d3dversion;
119 /* Various HWNDs */
120 HWND focuswindow;
121 HWND devicewindow;
122 HWND dest_window;
124 /* For the dll unload cleanup code */
125 struct list ddraw_list_entry;
126 /* The surface list - can't relay this to WineD3D
127 * because of IParent
129 struct list surface_list;
131 /* FVF management */
132 struct FvfToDecl *decls;
133 UINT numConvertedDecls, declArraySize;
135 unsigned int frames;
136 DWORD prev_frame_time;
139 #define DDRAW_WINDOW_CLASS_NAME "DirectDrawDeviceWnd"
141 HRESULT ddraw_init(struct ddraw *ddraw, DWORD flags, enum wined3d_device_type device_type);
142 void ddraw_d3dcaps1_from_7(D3DDEVICEDESC *caps1, D3DDEVICEDESC7 *caps7);
143 HRESULT ddraw_get_d3dcaps(const struct ddraw *ddraw, D3DDEVICEDESC7 *caps);
144 void ddraw_update_lost_surfaces(struct ddraw *ddraw);
146 static inline void ddraw_set_swapchain_window(struct ddraw *ddraw, HWND window)
148 if (window == GetDesktopWindow())
149 window = NULL;
150 ddraw->swapchain_window = window;
153 /* Utility functions */
154 void DDRAW_Convert_DDSCAPS_1_To_2(const DDSCAPS *pIn, DDSCAPS2 *pOut);
155 void DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(const DDDEVICEIDENTIFIER2 *pIn, DDDEVICEIDENTIFIER *pOut);
156 struct wined3d_vertex_declaration *ddraw_find_decl(struct ddraw *ddraw, DWORD fvf);
158 #define DDRAW_SURFACE_LOCATION_DEFAULT 0x00000001
159 #define DDRAW_SURFACE_LOCATION_DRAW 0x00000002
161 struct ddraw_surface
163 /* IUnknown fields */
164 IDirectDrawSurface7 IDirectDrawSurface7_iface;
165 IDirectDrawSurface4 IDirectDrawSurface4_iface;
166 IDirectDrawSurface3 IDirectDrawSurface3_iface;
167 IDirectDrawSurface2 IDirectDrawSurface2_iface;
168 IDirectDrawSurface IDirectDrawSurface_iface;
169 IDirectDrawGammaControl IDirectDrawGammaControl_iface;
170 IDirect3DTexture2 IDirect3DTexture2_iface;
171 IDirect3DTexture IDirect3DTexture_iface;
173 LONG ref7, ref4, ref3, ref2, ref1, iface_count, gamma_count;
174 IUnknown *ifaceToRelease;
175 IUnknown *texture_outer;
177 int version;
179 /* Connections to other Objects */
180 struct ddraw *ddraw;
181 unsigned int texture_location;
182 struct wined3d_texture *wined3d_texture;
183 struct wined3d_texture *draw_texture;
184 unsigned int sub_resource_idx;
185 struct wined3d_rendertarget_view *wined3d_rtv;
186 struct wined3d_private_store private_store;
187 struct d3d_device *device1;
189 /* This implementation handles attaching surfaces to other surfaces */
190 struct ddraw_surface *next_attached;
191 struct ddraw_surface *first_attached;
192 IUnknown *attached_iface;
194 /* Complex surfaces are organized in a tree, although the tree is degenerated to a list in most cases.
195 * In mipmap and primary surfaces each level has only one attachment, which is the next surface level.
196 * Only the cube texture root has 6 surfaces attached, which then have a normal mipmap chain attached
197 * to them. So hardcode the array to 6, a dynamic array or a list would be an overkill.
199 #define MAX_COMPLEX_ATTACHED 6
200 struct ddraw_surface *complex_array[MAX_COMPLEX_ATTACHED];
201 /* You can't traverse the tree upwards. Only a flag for Surface::Release because it's needed there,
202 * but no pointer to prevent temptations to traverse it in the wrong direction.
204 unsigned int is_root : 1;
205 unsigned int is_lost : 1;
206 unsigned int sysmem_fallback : 1;
208 /* Surface description, for GetAttachedSurface */
209 DDSURFACEDESC2 surface_desc;
211 /* Clipper objects */
212 struct ddraw_clipper *clipper;
213 struct ddraw_palette *palette;
215 /* For the ddraw surface list */
216 struct list surface_list_entry;
218 DWORD Handle;
219 HDC dc;
222 struct ddraw_texture
224 unsigned int version;
225 DDSURFACEDESC2 surface_desc;
227 struct ddraw_surface *root;
228 struct wined3d_device *wined3d_device;
230 void *texture_memory;
233 HRESULT ddraw_surface_create(struct ddraw *ddraw, const DDSURFACEDESC2 *surface_desc,
234 struct ddraw_surface **surface, IUnknown *outer_unknown, unsigned int version);
235 struct wined3d_rendertarget_view *ddraw_surface_get_rendertarget_view(struct ddraw_surface *surface);
236 HRESULT ddraw_surface_update_frontbuffer(struct ddraw_surface *surface,
237 const RECT *rect, BOOL read, unsigned int swap_interval);
239 static inline struct ddraw_surface *impl_from_IDirect3DTexture(IDirect3DTexture *iface)
241 return CONTAINING_RECORD(iface, struct ddraw_surface, IDirect3DTexture_iface);
244 static inline struct ddraw_surface *impl_from_IDirect3DTexture2(IDirect3DTexture2 *iface)
246 return CONTAINING_RECORD(iface, struct ddraw_surface, IDirect3DTexture2_iface);
249 static inline struct ddraw_surface *impl_from_IDirectDrawSurface(IDirectDrawSurface *iface)
251 return CONTAINING_RECORD(iface, struct ddraw_surface, IDirectDrawSurface_iface);
254 static inline struct ddraw_surface *impl_from_IDirectDrawSurface2(IDirectDrawSurface2 *iface)
256 return CONTAINING_RECORD(iface, struct ddraw_surface, IDirectDrawSurface2_iface);
259 static inline struct ddraw_surface *impl_from_IDirectDrawSurface3(IDirectDrawSurface3 *iface)
261 return CONTAINING_RECORD(iface, struct ddraw_surface, IDirectDrawSurface3_iface);
264 static inline struct ddraw_surface *impl_from_IDirectDrawSurface4(IDirectDrawSurface4 *iface)
266 return CONTAINING_RECORD(iface, struct ddraw_surface, IDirectDrawSurface4_iface);
269 static inline struct ddraw_surface *impl_from_IDirectDrawSurface7(IDirectDrawSurface7 *iface)
271 return CONTAINING_RECORD(iface, struct ddraw_surface, IDirectDrawSurface7_iface);
274 struct ddraw_surface *unsafe_impl_from_IDirectDrawSurface(IDirectDrawSurface *iface);
275 struct ddraw_surface *unsafe_impl_from_IDirectDrawSurface4(IDirectDrawSurface4 *iface);
276 struct ddraw_surface *unsafe_impl_from_IDirectDrawSurface7(IDirectDrawSurface7 *iface);
278 struct ddraw_surface *unsafe_impl_from_IDirect3DTexture(IDirect3DTexture *iface);
279 struct ddraw_surface *unsafe_impl_from_IDirect3DTexture2(IDirect3DTexture2 *iface);
281 #define DDRAW_INVALID_HANDLE ~0U
283 enum ddraw_handle_type
285 DDRAW_HANDLE_FREE,
286 DDRAW_HANDLE_MATERIAL,
287 DDRAW_HANDLE_MATRIX,
288 DDRAW_HANDLE_STATEBLOCK,
289 DDRAW_HANDLE_SURFACE,
292 struct ddraw_handle_entry
294 void *object;
295 enum ddraw_handle_type type;
298 struct ddraw_handle_table
300 struct ddraw_handle_entry *entries;
301 struct ddraw_handle_entry *free_entries;
302 UINT table_size;
303 UINT entry_count;
306 BOOL ddraw_handle_table_init(struct ddraw_handle_table *t, UINT initial_size);
307 void ddraw_handle_table_destroy(struct ddraw_handle_table *t);
308 DWORD ddraw_allocate_handle(struct ddraw_handle_table *t, void *object, enum ddraw_handle_type type);
309 void *ddraw_free_handle(struct ddraw_handle_table *t, DWORD handle, enum ddraw_handle_type type);
310 void *ddraw_get_object(struct ddraw_handle_table *t, DWORD handle, enum ddraw_handle_type type);
312 struct d3d_device
314 /* IUnknown */
315 IDirect3DDevice7 IDirect3DDevice7_iface;
316 IDirect3DDevice3 IDirect3DDevice3_iface;
317 IDirect3DDevice2 IDirect3DDevice2_iface;
318 IDirect3DDevice IDirect3DDevice_iface;
319 IUnknown IUnknown_inner;
320 LONG ref;
321 UINT version;
322 BOOL hardware_device;
323 BOOL have_draw_textures;
325 IUnknown *outer_unknown;
326 struct wined3d_device *wined3d_device;
327 struct wined3d_device_context *immediate_context;
328 struct ddraw *ddraw;
329 struct list ddraw_entry;
330 IUnknown *rt_iface;
331 struct ddraw_surface *target, *target_ds;
333 struct wined3d_streaming_buffer vertex_buffer, index_buffer;
335 /* Viewport management */
336 struct list viewport_list;
337 struct d3d_viewport *current_viewport;
338 D3DVIEWPORT7 active_viewport;
340 /* Required to keep track which of two available texture blending modes in d3ddevice3 is used */
341 BOOL legacyTextureBlending;
342 D3DTEXTUREBLEND texture_map_blend;
344 struct wined3d_matrix legacy_projection, legacy_clipspace;
346 /* Light state */
347 DWORD material;
349 /* Rendering functions to wrap D3D(1-3) to D3D7 */
350 D3DPRIMITIVETYPE primitive_type;
351 DWORD vertex_type;
352 DWORD render_flags;
353 DWORD nb_vertices;
354 BYTE *sysmem_vertex_buffer;
355 DWORD vertex_size;
356 DWORD buffer_size;
358 /* Handle management */
359 struct ddraw_handle_table handle_table;
360 D3DMATRIXHANDLE world, proj, view;
362 struct wined3d_vec4 user_clip_planes[D3DMAXUSERCLIPPLANES];
364 struct wined3d_stateblock *recording, *state, *update_state;
365 const struct wined3d_stateblock_state *stateblock_state;
367 /* For temporary saving state during reset. */
368 struct wined3d_stateblock *saved_state;
371 HRESULT d3d_device_create(struct ddraw *ddraw, const GUID *guid, struct ddraw_surface *target, IUnknown *rt_iface,
372 UINT version, struct d3d_device **device, IUnknown *outer_unknown);
373 enum wined3d_depth_buffer_type d3d_device_update_depth_stencil(struct d3d_device *device);
375 /* The IID */
376 extern const GUID IID_D3DDEVICE_WineD3D;
378 static inline struct d3d_device *impl_from_IDirect3DDevice(IDirect3DDevice *iface)
380 return CONTAINING_RECORD(iface, struct d3d_device, IDirect3DDevice_iface);
383 static inline struct d3d_device *impl_from_IDirect3DDevice2(IDirect3DDevice2 *iface)
385 return CONTAINING_RECORD(iface, struct d3d_device, IDirect3DDevice2_iface);
388 static inline struct d3d_device *impl_from_IDirect3DDevice3(IDirect3DDevice3 *iface)
390 return CONTAINING_RECORD(iface, struct d3d_device, IDirect3DDevice3_iface);
393 static inline struct d3d_device *impl_from_IDirect3DDevice7(IDirect3DDevice7 *iface)
395 return CONTAINING_RECORD(iface, struct d3d_device, IDirect3DDevice7_iface);
398 struct d3d_device *unsafe_impl_from_IDirect3DDevice(IDirect3DDevice *iface);
399 struct d3d_device *unsafe_impl_from_IDirect3DDevice2(IDirect3DDevice2 *iface);
400 struct d3d_device *unsafe_impl_from_IDirect3DDevice3(IDirect3DDevice3 *iface);
401 struct d3d_device *unsafe_impl_from_IDirect3DDevice7(IDirect3DDevice7 *iface);
403 struct ddraw_clipper
405 IDirectDrawClipper IDirectDrawClipper_iface;
406 LONG ref;
407 HWND window;
408 HRGN region;
409 BOOL initialized;
412 HRESULT ddraw_clipper_init(struct ddraw_clipper *clipper);
413 struct ddraw_clipper *unsafe_impl_from_IDirectDrawClipper(IDirectDrawClipper *iface);
414 BOOL ddraw_clipper_is_valid(const struct ddraw_clipper *clipper);
416 /*****************************************************************************
417 * IDirectDrawPalette implementation structure
418 *****************************************************************************/
419 struct ddraw_palette
421 /* IUnknown fields */
422 IDirectDrawPalette IDirectDrawPalette_iface;
423 LONG ref;
425 struct wined3d_palette *wined3d_palette;
426 struct ddraw *ddraw;
427 IUnknown *ifaceToRelease;
428 DWORD flags;
431 static inline struct ddraw_palette *impl_from_IDirectDrawPalette(IDirectDrawPalette *iface)
433 return CONTAINING_RECORD(iface, struct ddraw_palette, IDirectDrawPalette_iface);
436 struct ddraw_palette *unsafe_impl_from_IDirectDrawPalette(IDirectDrawPalette *iface);
438 HRESULT ddraw_palette_init(struct ddraw_palette *palette,
439 struct ddraw *ddraw, DWORD flags, PALETTEENTRY *entries);
441 /* Helper structures */
442 struct object_creation_info
444 const CLSID *clsid;
445 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, REFIID riid,
446 void **ppObj);
449 /******************************************************************************
450 * IDirect3DLight implementation structure - Wraps to D3D7
451 ******************************************************************************/
452 struct d3d_light
454 IDirect3DLight IDirect3DLight_iface;
455 LONG ref;
457 /* IDirect3DLight fields */
458 struct ddraw *ddraw;
460 /* If this light is active for one viewport, put the viewport here */
461 struct d3d_viewport *active_viewport;
463 D3DLIGHT2 light;
464 D3DLIGHT7 light7;
466 DWORD active_light_index;
468 struct list entry;
471 /* Helper functions */
472 void light_activate(struct d3d_light *light);
473 void light_deactivate(struct d3d_light *light);
474 void d3d_light_init(struct d3d_light *light, struct ddraw *ddraw);
475 struct d3d_light *unsafe_impl_from_IDirect3DLight(IDirect3DLight *iface);
477 /******************************************************************************
478 * IDirect3DMaterial implementation structure - Wraps to D3D7
479 ******************************************************************************/
480 struct d3d_material
482 IDirect3DMaterial3 IDirect3DMaterial3_iface;
483 IDirect3DMaterial2 IDirect3DMaterial2_iface;
484 IDirect3DMaterial IDirect3DMaterial_iface;
485 LONG ref;
487 /* IDirect3DMaterial2 fields */
488 struct ddraw *ddraw;
489 struct d3d_device *active_device;
491 D3DMATERIAL mat;
492 DWORD Handle;
495 /* Helper functions */
496 void material_activate(struct d3d_material *material);
497 struct d3d_material *d3d_material_create(struct ddraw *ddraw);
499 enum ddraw_viewport_version
501 DDRAW_VIEWPORT_VERSION_NONE,
502 DDRAW_VIEWPORT_VERSION_1,
503 DDRAW_VIEWPORT_VERSION_2,
506 /*****************************************************************************
507 * IDirect3DViewport - Wraps to D3D7
508 *****************************************************************************/
509 struct d3d_viewport
511 IDirect3DViewport3 IDirect3DViewport3_iface;
512 LONG ref;
514 /* IDirect3DViewport fields */
515 struct ddraw *ddraw;
517 /* If this viewport is active for one device, put the device here */
518 struct d3d_device *active_device;
520 DWORD active_lights_count;
521 DWORD map_lights;
523 enum ddraw_viewport_version version;
525 union
527 D3DVIEWPORT vp1;
528 D3DVIEWPORT2 vp2;
529 } viewports;
531 struct list entry;
532 struct list light_list;
533 struct d3d_material *background;
536 struct d3d_viewport *unsafe_impl_from_IDirect3DViewport3(IDirect3DViewport3 *iface);
537 struct d3d_viewport *unsafe_impl_from_IDirect3DViewport2(IDirect3DViewport2 *iface);
538 struct d3d_viewport *unsafe_impl_from_IDirect3DViewport(IDirect3DViewport *iface);
540 /* Helper functions */
541 void viewport_activate(struct d3d_viewport *viewport, BOOL ignore_lights);
542 void viewport_deactivate(struct d3d_viewport *viewport);
543 void d3d_viewport_init(struct d3d_viewport *viewport, struct ddraw *ddraw);
545 /*****************************************************************************
546 * IDirect3DExecuteBuffer - Wraps to D3D7
547 *****************************************************************************/
548 struct d3d_execute_buffer
550 IDirect3DExecuteBuffer IDirect3DExecuteBuffer_iface;
551 LONG ref;
552 /* IDirect3DExecuteBuffer fields */
553 struct ddraw *ddraw;
554 struct d3d_device *d3ddev;
556 D3DEXECUTEBUFFERDESC desc;
557 D3DEXECUTEDATA data;
559 /* This buffer will store the transformed vertices */
560 unsigned int index_size, index_pos;
561 unsigned int vertex_size, src_vertex_pos;
562 struct wined3d_buffer *src_vertex_buffer, *dst_vertex_buffer, *index_buffer;
564 /* This flags is set to TRUE if we allocated ourselves the
565 * data buffer
567 BOOL need_free;
570 HRESULT d3d_execute_buffer_init(struct d3d_execute_buffer *execute_buffer,
571 struct d3d_device *device, D3DEXECUTEBUFFERDESC *desc);
572 struct d3d_execute_buffer *unsafe_impl_from_IDirect3DExecuteBuffer(IDirect3DExecuteBuffer *iface);
574 /* The execute function */
575 HRESULT d3d_execute_buffer_execute(struct d3d_execute_buffer *execute_buffer,
576 struct d3d_device *device);
578 /*****************************************************************************
579 * IDirect3DVertexBuffer
580 *****************************************************************************/
581 struct d3d_vertex_buffer
583 IDirect3DVertexBuffer7 IDirect3DVertexBuffer7_iface;
584 LONG ref;
585 unsigned int version;
587 /*** WineD3D and ddraw links ***/
588 struct wined3d_buffer *wined3d_buffer;
589 struct wined3d_vertex_declaration *wined3d_declaration;
590 struct ddraw *ddraw;
592 /*** Storage for D3D7 specific things ***/
593 DWORD Caps;
594 DWORD fvf;
595 DWORD size;
596 BOOL dynamic;
597 bool discarded;
598 bool sysmem;
601 HRESULT d3d_vertex_buffer_create(struct d3d_vertex_buffer **buffer, struct ddraw *ddraw,
602 D3DVERTEXBUFFERDESC *desc);
603 struct d3d_vertex_buffer *unsafe_impl_from_IDirect3DVertexBuffer(IDirect3DVertexBuffer *iface);
604 struct d3d_vertex_buffer *unsafe_impl_from_IDirect3DVertexBuffer7(IDirect3DVertexBuffer7 *iface);
606 /*****************************************************************************
607 * Helper functions from utils.c
608 *****************************************************************************/
610 #define GET_TEXCOUNT_FROM_FVF(d3dvtVertexType) \
611 (((d3dvtVertexType) & D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT)
613 #define GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType, tex_num) \
614 (((((d3dvtVertexType) >> (16 + (2 * (tex_num)))) + 1) & 0x03) + 1)
616 void ddrawformat_from_wined3dformat(DDPIXELFORMAT *ddraw_format,
617 enum wined3d_format_id wined3d_format);
618 BOOL wined3d_colour_from_ddraw_colour(const DDPIXELFORMAT *pf, const struct ddraw_palette *palette,
619 DWORD colour, struct wined3d_color *wined3d_colour);
620 enum wined3d_format_id wined3dformat_from_ddrawformat(const DDPIXELFORMAT *format);
621 unsigned int wined3dmapflags_from_ddrawmapflags(unsigned int flags);
622 void DDRAW_dump_surface_desc(const DDSURFACEDESC2 *lpddsd);
623 void dump_D3DMATRIX(const D3DMATRIX *mat);
624 void DDRAW_dump_DDCAPS(const DDCAPS *lpcaps);
625 DWORD get_flexible_vertex_size(DWORD d3dvtVertexType);
626 void DDRAW_dump_DDSCAPS2(const DDSCAPS2 *in);
627 void DDRAW_dump_cooperativelevel(DWORD cooplevel);
628 void DDSD_to_DDSD2(const DDSURFACEDESC *in, DDSURFACEDESC2 *out);
629 void DDSD2_to_DDSD(const DDSURFACEDESC2 *in, DDSURFACEDESC *out);
631 void multiply_matrix(struct wined3d_matrix *dst, const struct wined3d_matrix *src1,
632 const struct wined3d_matrix *src2);
634 static inline BOOL format_is_compressed(const DDPIXELFORMAT *format)
636 return (format->dwFlags & DDPF_FOURCC) && (format->dwFourCC == WINED3DFMT_DXT1
637 || format->dwFourCC == WINED3DFMT_DXT2 || format->dwFourCC == WINED3DFMT_DXT3
638 || format->dwFourCC == WINED3DFMT_DXT4 || format->dwFourCC == WINED3DFMT_DXT5);
641 static inline BOOL format_is_paletteindexed(const DDPIXELFORMAT *fmt)
643 DWORD flags = DDPF_PALETTEINDEXED1 | DDPF_PALETTEINDEXED2 | DDPF_PALETTEINDEXED4
644 | DDPF_PALETTEINDEXED8 | DDPF_PALETTEINDEXEDTO8;
645 return !!(fmt->dwFlags & flags);
648 static inline BOOL ddraw_surface_can_be_lost(const struct ddraw_surface *surface)
650 DWORD caps = surface->surface_desc.ddsCaps.dwCaps;
652 /* Testing with DDCREATE_EMULATIONONLY showed that primary surfaces and Z buffers can
653 * be lost even if created with explicit DDCAPS_SYSTEMMEMORY. Textures can or cannot be lost
654 * depending on whether _SYSTEMMEMORY was given explicitly by the application. */
655 if (!(caps & DDSCAPS_SYSTEMMEMORY) || caps & (DDSCAPS_PRIMARYSURFACE | DDSCAPS_ZBUFFER))
656 return TRUE;
658 return surface->sysmem_fallback;
661 #define DDRAW_SURFACE_READ 0x00000001
662 #define DDRAW_SURFACE_WRITE 0x00000002
663 #define DDRAW_SURFACE_RW (DDRAW_SURFACE_READ | DDRAW_SURFACE_WRITE)
665 static inline struct wined3d_texture *ddraw_surface_get_default_texture(struct ddraw_surface *surface, unsigned int flags)
667 if (surface->draw_texture)
669 if (flags & DDRAW_SURFACE_READ && !(surface->texture_location & DDRAW_SURFACE_LOCATION_DEFAULT))
671 wined3d_device_context_copy_sub_resource_region(surface->ddraw->immediate_context,
672 wined3d_texture_get_resource(surface->wined3d_texture), surface->sub_resource_idx, 0, 0, 0,
673 wined3d_texture_get_resource(surface->draw_texture), surface->sub_resource_idx, NULL, 0);
674 surface->texture_location |= DDRAW_SURFACE_LOCATION_DEFAULT;
677 if (flags & DDRAW_SURFACE_WRITE)
678 surface->texture_location = DDRAW_SURFACE_LOCATION_DEFAULT;
680 return surface->wined3d_texture;
683 static inline struct wined3d_texture *ddraw_surface_get_draw_texture(struct ddraw_surface *surface, unsigned int flags)
685 if (!surface->draw_texture)
686 return surface->wined3d_texture;
688 if (flags & DDRAW_SURFACE_READ && !(surface->texture_location & DDRAW_SURFACE_LOCATION_DRAW))
690 wined3d_device_context_copy_sub_resource_region(surface->ddraw->immediate_context,
691 wined3d_texture_get_resource(surface->draw_texture), surface->sub_resource_idx, 0, 0, 0,
692 wined3d_texture_get_resource(surface->wined3d_texture), surface->sub_resource_idx, NULL, 0);
693 surface->texture_location |= DDRAW_SURFACE_LOCATION_DRAW;
696 if (flags & DDRAW_SURFACE_WRITE)
697 surface->texture_location = DDRAW_SURFACE_LOCATION_DRAW;
699 return surface->draw_texture;
702 static inline struct wined3d_texture *ddraw_surface_get_any_texture(struct ddraw_surface *surface, unsigned int flags)
704 if ((surface->texture_location & DDRAW_SURFACE_LOCATION_DEFAULT)
705 || (surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY))
706 return ddraw_surface_get_default_texture(surface, flags);
708 assert(surface->texture_location & DDRAW_SURFACE_LOCATION_DRAW);
709 return ddraw_surface_get_draw_texture(surface, flags);
712 void d3d_device_sync_surfaces(struct d3d_device *device);
714 /* Used for generic dumping */
715 struct flag_info
717 DWORD val;
718 const char *name;
721 #define FE(x) { x, #x }
723 struct member_info
725 DWORD val;
726 const char *name;
727 void (*func)(const void *);
728 ptrdiff_t offset;
731 /* Structure copy */
732 #define ME(x,f,e) { x, #x, (void (*)(const void *))(f), offsetof(STRUCT, e) }
734 #define DD_STRUCT_COPY_BYSIZE_(to,from,to_size,from_size) \
735 do { \
736 DWORD __size = (to)->dwSize; \
737 DWORD __resetsize = min(to_size, sizeof(*to)); \
738 DWORD __copysize = min(__resetsize, from_size); \
739 assert(to != from); \
740 memcpy(to, from, __copysize); \
741 memset((char*)(to) + __copysize, 0, __resetsize - __copysize); \
742 (to)->dwSize = __size; /* restore size */ \
743 } while (0)
745 #define DD_STRUCT_COPY_BYSIZE(to,from) DD_STRUCT_COPY_BYSIZE_(to,from,(to)->dwSize,(from)->dwSize)
747 HRESULT hr_ddraw_from_wined3d(HRESULT hr);
749 void viewport_alloc_active_light_index(struct d3d_light *light);
750 void viewport_free_active_light_index(struct d3d_light *light);
752 #endif