2 * Copyright 1997-2000 Marcus Meissner
3 * Copyright 1998-2000 Lionel Ulmer
4 * Copyright 2000-2001 TransGaming Technologies Inc.
5 * Copyright 2006 Stefan Dösinger
6 * Copyright 2008 Denver Gingerich
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
26 #include "ddraw_private.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(ddraw
);
30 /* Device identifier. Don't relay it to WineD3D */
31 static const DDDEVICEIDENTIFIER2 deviceidentifier
=
35 { { 0x00010001, 0x00010001 } },
37 /* a8373c10-7ac4-4deb-849a-009844d08b2d */
38 {0xa8373c10,0x7ac4,0x4deb, {0x84,0x9a,0x00,0x98,0x44,0xd0,0x8b,0x2d}},
42 static struct enum_device_entry
44 char interface_name
[100];
45 char device_name
[100];
46 const GUID
*device_guid
;
51 "WINE Direct3D7 Hardware Transform and Lighting acceleration using WineD3D",
53 &IID_IDirect3DTnLHalDevice
,
58 "WINE Direct3D7 Hardware acceleration using WineD3D",
60 &IID_IDirect3DHALDevice
,
65 "WINE Direct3D7 RGB Software Emulation using WineD3D",
67 &IID_IDirect3DRGBDevice
,
71 static void STDMETHODCALLTYPE
ddraw_null_wined3d_object_destroyed(void *parent
) {}
73 const struct wined3d_parent_ops ddraw_null_wined3d_parent_ops
=
75 ddraw_null_wined3d_object_destroyed
,
78 static inline struct ddraw
*impl_from_IDirectDraw(IDirectDraw
*iface
)
80 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw_iface
);
83 static inline struct ddraw
*impl_from_IDirectDraw2(IDirectDraw2
*iface
)
85 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw2_iface
);
88 static inline struct ddraw
*impl_from_IDirectDraw4(IDirectDraw4
*iface
)
90 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw4_iface
);
93 static inline struct ddraw
*impl_from_IDirectDraw7(IDirectDraw7
*iface
)
95 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw7_iface
);
98 static inline struct ddraw
*impl_from_IDirect3D(IDirect3D
*iface
)
100 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D_iface
);
103 static inline struct ddraw
*impl_from_IDirect3D2(IDirect3D2
*iface
)
105 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D2_iface
);
108 static inline struct ddraw
*impl_from_IDirect3D3(IDirect3D3
*iface
)
110 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D3_iface
);
113 static inline struct ddraw
*impl_from_IDirect3D7(IDirect3D7
*iface
)
115 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D7_iface
);
118 /*****************************************************************************
120 *****************************************************************************/
122 /*****************************************************************************
123 * IDirectDraw7::QueryInterface
125 * Queries different interfaces of the DirectDraw object. It can return
126 * IDirectDraw interfaces in version 1, 2, 4 and 7, and IDirect3D interfaces
127 * in version 1, 2, 3 and 7. An IDirect3DDevice can be created with this
129 * The returned interface is AddRef()-ed before it's returned
131 * Used for version 1, 2, 4 and 7
134 * refiid: Interface ID asked for
135 * obj: Used to return the interface pointer
138 * S_OK if an interface was found
139 * E_NOINTERFACE if the requested interface wasn't found
141 *****************************************************************************/
142 static HRESULT WINAPI
ddraw7_QueryInterface(IDirectDraw7
*iface
, REFIID refiid
, void **obj
)
144 struct ddraw
*This
= impl_from_IDirectDraw7(iface
);
146 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(refiid
), obj
);
148 /* Can change surface impl type */
149 wined3d_mutex_lock();
151 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
156 wined3d_mutex_unlock();
157 return DDERR_INVALIDPARAMS
;
160 /* Check DirectDraw Interfaces */
161 if ( IsEqualGUID( &IID_IUnknown
, refiid
) ||
162 IsEqualGUID( &IID_IDirectDraw7
, refiid
) )
164 *obj
= &This
->IDirectDraw7_iface
;
165 TRACE("(%p) Returning IDirectDraw7 interface at %p\n", This
, *obj
);
167 else if ( IsEqualGUID( &IID_IDirectDraw4
, refiid
) )
169 *obj
= &This
->IDirectDraw4_iface
;
170 TRACE("(%p) Returning IDirectDraw4 interface at %p\n", This
, *obj
);
172 else if ( IsEqualGUID( &IID_IDirectDraw3
, refiid
) )
174 /* This Interface exists in ddrawex.dll, it is implemented in a wrapper */
175 WARN("IDirectDraw3 is not valid in ddraw.dll\n");
177 wined3d_mutex_unlock();
178 return E_NOINTERFACE
;
180 else if ( IsEqualGUID( &IID_IDirectDraw2
, refiid
) )
182 *obj
= &This
->IDirectDraw2_iface
;
183 TRACE("(%p) Returning IDirectDraw2 interface at %p\n", This
, *obj
);
185 else if ( IsEqualGUID( &IID_IDirectDraw
, refiid
) )
187 *obj
= &This
->IDirectDraw_iface
;
188 TRACE("(%p) Returning IDirectDraw interface at %p\n", This
, *obj
);
192 * The refcount unit test revealed that an IDirect3D7 interface can only be queried
193 * from a DirectDraw object that was created as an IDirectDraw7 interface. No idea
194 * who had this idea and why. The older interfaces can query and IDirect3D version
195 * because they are all created as IDirectDraw(1). This isn't really crucial behavior,
196 * and messy to implement with the common creation function, so it has been left out here.
198 else if ( IsEqualGUID( &IID_IDirect3D
, refiid
) ||
199 IsEqualGUID( &IID_IDirect3D2
, refiid
) ||
200 IsEqualGUID( &IID_IDirect3D3
, refiid
) ||
201 IsEqualGUID( &IID_IDirect3D7
, refiid
) )
203 /* Check the surface implementation */
204 if (DefaultSurfaceType
!= WINED3D_SURFACE_TYPE_OPENGL
)
206 WARN("The app requests a Direct3D interface, but non-opengl surfaces where set in winecfg\n");
207 /* Do not abort here, only reject 3D Device creation */
210 if ( IsEqualGUID( &IID_IDirect3D
, refiid
) )
212 This
->d3dversion
= 1;
213 *obj
= &This
->IDirect3D_iface
;
214 TRACE(" returning Direct3D interface at %p.\n", *obj
);
216 else if ( IsEqualGUID( &IID_IDirect3D2
, refiid
) )
218 This
->d3dversion
= 2;
219 *obj
= &This
->IDirect3D2_iface
;
220 TRACE(" returning Direct3D2 interface at %p.\n", *obj
);
222 else if ( IsEqualGUID( &IID_IDirect3D3
, refiid
) )
224 This
->d3dversion
= 3;
225 *obj
= &This
->IDirect3D3_iface
;
226 TRACE(" returning Direct3D3 interface at %p.\n", *obj
);
228 else if(IsEqualGUID( &IID_IDirect3D7
, refiid
))
230 This
->d3dversion
= 7;
231 *obj
= &This
->IDirect3D7_iface
;
232 TRACE(" returning Direct3D7 interface at %p.\n", *obj
);
235 /* Unknown interface */
238 ERR("(%p)->(%s, %p): No interface found\n", This
, debugstr_guid(refiid
), obj
);
239 wined3d_mutex_unlock();
240 return E_NOINTERFACE
;
243 IUnknown_AddRef( (IUnknown
*) *obj
);
244 wined3d_mutex_unlock();
249 static HRESULT WINAPI
ddraw4_QueryInterface(IDirectDraw4
*iface
, REFIID riid
, void **object
)
251 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
253 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
255 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
258 static HRESULT WINAPI
ddraw2_QueryInterface(IDirectDraw2
*iface
, REFIID riid
, void **object
)
260 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
262 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
264 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
267 static HRESULT WINAPI
ddraw1_QueryInterface(IDirectDraw
*iface
, REFIID riid
, void **object
)
269 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
271 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
273 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
276 static HRESULT WINAPI
d3d7_QueryInterface(IDirect3D7
*iface
, REFIID riid
, void **object
)
278 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
280 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
282 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
285 static HRESULT WINAPI
d3d3_QueryInterface(IDirect3D3
*iface
, REFIID riid
, void **object
)
287 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
289 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
291 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
294 static HRESULT WINAPI
d3d2_QueryInterface(IDirect3D2
*iface
, REFIID riid
, void **object
)
296 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
298 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
300 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
303 static HRESULT WINAPI
d3d1_QueryInterface(IDirect3D
*iface
, REFIID riid
, void **object
)
305 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
307 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
309 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
312 /*****************************************************************************
313 * IDirectDraw7::AddRef
315 * Increases the interfaces refcount, basically
317 * DDraw refcounting is a bit tricky. The different DirectDraw interface
318 * versions have individual refcounts, but the IDirect3D interfaces do not.
319 * All interfaces are from one object, that means calling QueryInterface on an
320 * IDirectDraw7 interface for an IDirectDraw4 interface does not create a new
323 * That means all AddRef and Release implementations of IDirectDrawX work
324 * with their own counter, and IDirect3DX::AddRef thunk to IDirectDraw (1),
325 * except of IDirect3D7 which thunks to IDirectDraw7
327 * Returns: The new refcount
329 *****************************************************************************/
330 static ULONG WINAPI
ddraw7_AddRef(IDirectDraw7
*iface
)
332 struct ddraw
*This
= impl_from_IDirectDraw7(iface
);
333 ULONG ref
= InterlockedIncrement(&This
->ref7
);
335 TRACE("%p increasing refcount to %u.\n", This
, ref
);
337 if(ref
== 1) InterlockedIncrement(&This
->numIfaces
);
342 static ULONG WINAPI
ddraw4_AddRef(IDirectDraw4
*iface
)
344 struct ddraw
*This
= impl_from_IDirectDraw4(iface
);
345 ULONG ref
= InterlockedIncrement(&This
->ref4
);
347 TRACE("%p increasing refcount to %u.\n", This
, ref
);
349 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
354 static ULONG WINAPI
ddraw2_AddRef(IDirectDraw2
*iface
)
356 struct ddraw
*This
= impl_from_IDirectDraw2(iface
);
357 ULONG ref
= InterlockedIncrement(&This
->ref2
);
359 TRACE("%p increasing refcount to %u.\n", This
, ref
);
361 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
366 static ULONG WINAPI
ddraw1_AddRef(IDirectDraw
*iface
)
368 struct ddraw
*This
= impl_from_IDirectDraw(iface
);
369 ULONG ref
= InterlockedIncrement(&This
->ref1
);
371 TRACE("%p increasing refcount to %u.\n", This
, ref
);
373 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
378 static ULONG WINAPI
d3d7_AddRef(IDirect3D7
*iface
)
380 struct ddraw
*This
= impl_from_IDirect3D7(iface
);
382 TRACE("iface %p.\n", iface
);
384 return ddraw7_AddRef(&This
->IDirectDraw7_iface
);
387 static ULONG WINAPI
d3d3_AddRef(IDirect3D3
*iface
)
389 struct ddraw
*This
= impl_from_IDirect3D3(iface
);
391 TRACE("iface %p.\n", iface
);
393 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
396 static ULONG WINAPI
d3d2_AddRef(IDirect3D2
*iface
)
398 struct ddraw
*This
= impl_from_IDirect3D2(iface
);
400 TRACE("iface %p.\n", iface
);
402 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
405 static ULONG WINAPI
d3d1_AddRef(IDirect3D
*iface
)
407 struct ddraw
*This
= impl_from_IDirect3D(iface
);
409 TRACE("iface %p.\n", iface
);
411 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
414 void ddraw_destroy_swapchain(struct ddraw
*ddraw
)
416 TRACE("Destroying the swapchain.\n");
418 wined3d_swapchain_decref(ddraw
->wined3d_swapchain
);
419 ddraw
->wined3d_swapchain
= NULL
;
421 if (DefaultSurfaceType
== WINED3D_SURFACE_TYPE_OPENGL
)
425 for (i
= 0; i
< ddraw
->numConvertedDecls
; ++i
)
427 wined3d_vertex_declaration_decref(ddraw
->decls
[i
].decl
);
429 HeapFree(GetProcessHeap(), 0, ddraw
->decls
);
430 ddraw
->numConvertedDecls
= 0;
432 if (FAILED(wined3d_device_uninit_3d(ddraw
->wined3d_device
)))
434 ERR("Failed to uninit 3D.\n");
438 /* Free the d3d window if one was created. */
439 if (ddraw
->d3d_window
&& ddraw
->d3d_window
!= ddraw
->dest_window
)
441 TRACE("Destroying the hidden render window %p.\n", ddraw
->d3d_window
);
442 DestroyWindow(ddraw
->d3d_window
);
443 ddraw
->d3d_window
= 0;
447 ddraw
->d3d_initialized
= FALSE
;
451 wined3d_device_uninit_gdi(ddraw
->wined3d_device
);
454 ddraw_set_swapchain_window(ddraw
, NULL
);
456 TRACE("Swapchain destroyed.\n");
459 /*****************************************************************************
462 * Destroys a ddraw object if all refcounts are 0. This is to share code
463 * between the IDirectDrawX::Release functions
466 * This: DirectDraw object to destroy
468 *****************************************************************************/
469 static void ddraw_destroy(struct ddraw
*This
)
471 IDirectDraw7_SetCooperativeLevel(&This
->IDirectDraw7_iface
, NULL
, DDSCL_NORMAL
);
472 IDirectDraw7_RestoreDisplayMode(&This
->IDirectDraw7_iface
);
474 /* Destroy the device window if we created one */
475 if(This
->devicewindow
!= 0)
477 TRACE(" (%p) Destroying the device window %p\n", This
, This
->devicewindow
);
478 DestroyWindow(This
->devicewindow
);
479 This
->devicewindow
= 0;
482 wined3d_mutex_lock();
483 list_remove(&This
->ddraw_list_entry
);
484 wined3d_mutex_unlock();
486 if (This
->wined3d_swapchain
)
487 ddraw_destroy_swapchain(This
);
488 wined3d_device_decref(This
->wined3d_device
);
489 wined3d_decref(This
->wined3d
);
491 /* Now free the object */
492 HeapFree(GetProcessHeap(), 0, This
);
495 /*****************************************************************************
496 * IDirectDraw7::Release
498 * Decreases the refcount. If the refcount falls to 0, the object is destroyed
500 * Returns: The new refcount
501 *****************************************************************************/
502 static ULONG WINAPI
ddraw7_Release(IDirectDraw7
*iface
)
504 struct ddraw
*This
= impl_from_IDirectDraw7(iface
);
505 ULONG ref
= InterlockedDecrement(&This
->ref7
);
507 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
509 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
515 static ULONG WINAPI
ddraw4_Release(IDirectDraw4
*iface
)
517 struct ddraw
*This
= impl_from_IDirectDraw4(iface
);
518 ULONG ref
= InterlockedDecrement(&This
->ref4
);
520 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
522 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
528 static ULONG WINAPI
ddraw2_Release(IDirectDraw2
*iface
)
530 struct ddraw
*This
= impl_from_IDirectDraw2(iface
);
531 ULONG ref
= InterlockedDecrement(&This
->ref2
);
533 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
535 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
541 static ULONG WINAPI
ddraw1_Release(IDirectDraw
*iface
)
543 struct ddraw
*This
= impl_from_IDirectDraw(iface
);
544 ULONG ref
= InterlockedDecrement(&This
->ref1
);
546 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
548 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
554 static ULONG WINAPI
d3d7_Release(IDirect3D7
*iface
)
556 struct ddraw
*This
= impl_from_IDirect3D7(iface
);
558 TRACE("iface %p.\n", iface
);
560 return ddraw7_Release(&This
->IDirectDraw7_iface
);
563 static ULONG WINAPI
d3d3_Release(IDirect3D3
*iface
)
565 struct ddraw
*This
= impl_from_IDirect3D3(iface
);
567 TRACE("iface %p.\n", iface
);
569 return ddraw1_Release(&This
->IDirectDraw_iface
);
572 static ULONG WINAPI
d3d2_Release(IDirect3D2
*iface
)
574 struct ddraw
*This
= impl_from_IDirect3D2(iface
);
576 TRACE("iface %p.\n", iface
);
578 return ddraw1_Release(&This
->IDirectDraw_iface
);
581 static ULONG WINAPI
d3d1_Release(IDirect3D
*iface
)
583 struct ddraw
*This
= impl_from_IDirect3D(iface
);
585 TRACE("iface %p.\n", iface
);
587 return ddraw1_Release(&This
->IDirectDraw_iface
);
590 /*****************************************************************************
591 * IDirectDraw methods
592 *****************************************************************************/
594 static HRESULT
ddraw_set_focus_window(struct ddraw
*ddraw
, HWND window
)
596 /* FIXME: This looks wrong, exclusive mode should imply a destination
598 if ((ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
) && ddraw
->dest_window
)
600 TRACE("Setting DDSCL_SETFOCUSWINDOW with an already set window, returning DDERR_HWNDALREADYSET.\n");
601 return DDERR_HWNDALREADYSET
;
604 ddraw
->focuswindow
= window
;
606 /* Use the focus window for drawing too. */
607 ddraw
->dest_window
= ddraw
->focuswindow
;
612 static HRESULT
ddraw_attach_d3d_device(struct ddraw
*ddraw
,
613 struct wined3d_swapchain_desc
*swapchain_desc
)
615 HWND window
= swapchain_desc
->device_window
;
618 TRACE("ddraw %p.\n", ddraw
);
620 if (!window
|| window
== GetDesktopWindow())
622 window
= CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME
, "Hidden D3D Window",
623 WS_DISABLED
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
624 NULL
, NULL
, NULL
, NULL
);
627 ERR("Failed to create window, last error %#x.\n", GetLastError());
631 ShowWindow(window
, SW_HIDE
); /* Just to be sure */
632 WARN("No window for the Direct3DDevice, created hidden window %p.\n", window
);
634 swapchain_desc
->device_window
= window
;
638 TRACE("Using existing window %p for Direct3D rendering.\n", window
);
640 ddraw
->d3d_window
= window
;
642 /* Set this NOW, otherwise creating the depth stencil surface will cause a
643 * recursive loop until ram or emulated video memory is full. */
644 ddraw
->d3d_initialized
= TRUE
;
645 hr
= wined3d_device_init_3d(ddraw
->wined3d_device
, swapchain_desc
);
648 ddraw
->d3d_initialized
= FALSE
;
652 ddraw
->declArraySize
= 2;
653 ddraw
->decls
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ddraw
->decls
) * ddraw
->declArraySize
);
656 ERR("Error allocating an array for the converted vertex decls.\n");
657 ddraw
->declArraySize
= 0;
658 hr
= wined3d_device_uninit_3d(ddraw
->wined3d_device
);
659 return E_OUTOFMEMORY
;
662 TRACE("Successfully initialized 3D.\n");
667 static HRESULT
ddraw_create_swapchain(struct ddraw
*ddraw
, HWND window
, BOOL windowed
)
669 struct wined3d_swapchain_desc swapchain_desc
;
670 struct wined3d_display_mode mode
;
671 HRESULT hr
= WINED3D_OK
;
673 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
675 ERR("Failed to get display mode.\n");
679 memset(&swapchain_desc
, 0, sizeof(swapchain_desc
));
680 swapchain_desc
.backbuffer_width
= mode
.width
;
681 swapchain_desc
.backbuffer_height
= mode
.height
;
682 swapchain_desc
.backbuffer_format
= mode
.format_id
;
683 swapchain_desc
.swap_effect
= WINED3D_SWAP_EFFECT_COPY
;
684 swapchain_desc
.device_window
= window
;
685 swapchain_desc
.windowed
= windowed
;
687 if (DefaultSurfaceType
== WINED3D_SURFACE_TYPE_OPENGL
)
688 hr
= ddraw_attach_d3d_device(ddraw
, &swapchain_desc
);
690 hr
= wined3d_device_init_gdi(ddraw
->wined3d_device
, &swapchain_desc
);
694 ERR("Failed to create swapchain, hr %#x.\n", hr
);
698 if (!(ddraw
->wined3d_swapchain
= wined3d_device_get_swapchain(ddraw
->wined3d_device
, 0)))
700 ERR("Failed to get swapchain.\n");
701 return DDERR_INVALIDPARAMS
;
704 wined3d_swapchain_incref(ddraw
->wined3d_swapchain
);
705 ddraw_set_swapchain_window(ddraw
, window
);
710 /*****************************************************************************
711 * IDirectDraw7::SetCooperativeLevel
713 * Sets the cooperative level for the DirectDraw object, and the window
714 * assigned to it. The cooperative level determines the general behavior
715 * of the DirectDraw application
717 * Warning: This is quite tricky, as it's not really documented which
718 * cooperative levels can be combined with each other. If a game fails
719 * after this function, try to check the cooperative levels passed on
720 * Windows, and if it returns something different.
722 * If you think that this function caused the failure because it writes a
723 * fixme, be sure to run again with a +ddraw trace.
725 * What is known about cooperative levels (See the ddraw modes test):
726 * DDSCL_EXCLUSIVE and DDSCL_FULLSCREEN must be used with each other
727 * DDSCL_NORMAL is not compatible with DDSCL_EXCLUSIVE or DDSCL_FULLSCREEN
728 * DDSCL_SETFOCUSWINDOW can be passed only in DDSCL_NORMAL mode, but after that
729 * DDSCL_FULLSCREEN can be activated
730 * DDSCL_SETFOCUSWINDOW may only be used with DDSCL_NOWINDOWCHANGES
732 * Handled flags: DDSCL_NORMAL, DDSCL_FULLSCREEN, DDSCL_EXCLUSIVE,
733 * DDSCL_SETFOCUSWINDOW (partially),
734 * DDSCL_MULTITHREADED (work in progress)
736 * Unhandled flags, which should be implemented
737 * DDSCL_SETDEVICEWINDOW: Sets a window specially used for rendering (I don't
738 * expect any difference to a normal window for wine)
739 * DDSCL_CREATEDEVICEWINDOW: Tells ddraw to create its own window for
740 * rendering (Possible test case: Half-Life)
742 * Unsure about these: DDSCL_FPUSETUP DDSCL_FPURESERVE
744 * These don't seem very important for wine:
745 * DDSCL_ALLOWREBOOT, DDSCL_NOWINDOWCHANGES, DDSCL_ALLOWMODEX
748 * DD_OK if the cooperative level was set successfully
749 * DDERR_INVALIDPARAMS if the passed cooperative level combination is invalid
750 * DDERR_HWNDALREADYSET if DDSCL_SETFOCUSWINDOW is passed in exclusive mode
751 * (Probably others too, have to investigate)
753 *****************************************************************************/
754 static HRESULT WINAPI
ddraw7_SetCooperativeLevel(IDirectDraw7
*iface
, HWND hwnd
, DWORD cooplevel
)
756 struct ddraw
*This
= impl_from_IDirectDraw7(iface
);
757 struct wined3d_surface
*rt
= NULL
, *ds
;
758 struct wined3d_stateblock
*stateblock
;
759 BOOL restore_state
= FALSE
;
763 TRACE("iface %p, window %p, flags %#x.\n", iface
, hwnd
, cooplevel
);
764 DDRAW_dump_cooperativelevel(cooplevel
);
766 wined3d_mutex_lock();
768 /* Get the old window */
769 window
= This
->dest_window
;
771 /* Tests suggest that we need one of them: */
772 if(!(cooplevel
& (DDSCL_SETFOCUSWINDOW
|
776 TRACE("Incorrect cooplevel flags, returning DDERR_INVALIDPARAMS\n");
777 wined3d_mutex_unlock();
778 return DDERR_INVALIDPARAMS
;
781 if ((cooplevel
& DDSCL_CREATEDEVICEWINDOW
) && !(cooplevel
& DDSCL_EXCLUSIVE
))
783 WARN("DDSCL_CREATEDEVICEWINDOW requires DDSCL_EXCLUSIVE.\n");
784 wined3d_mutex_unlock();
785 return DDERR_INVALIDPARAMS
;
788 /* Handle those levels first which set various hwnds */
789 if ((cooplevel
& DDSCL_SETFOCUSWINDOW
) && !(cooplevel
& DDSCL_CREATEDEVICEWINDOW
))
791 /* This isn't compatible with a lot of flags */
792 if (cooplevel
& (DDSCL_MULTITHREADED
797 | DDSCL_SETDEVICEWINDOW
802 WARN("Called with incompatible flags, returning DDERR_INVALIDPARAMS.\n");
803 wined3d_mutex_unlock();
804 return DDERR_INVALIDPARAMS
;
807 hr
= ddraw_set_focus_window(This
, hwnd
);
808 wined3d_mutex_unlock();
812 if (cooplevel
& DDSCL_EXCLUSIVE
)
814 if (!(cooplevel
& DDSCL_FULLSCREEN
) || !(hwnd
|| (cooplevel
& DDSCL_CREATEDEVICEWINDOW
)))
816 WARN("DDSCL_EXCLUSIVE requires DDSCL_FULLSCREEN and a window.\n");
817 wined3d_mutex_unlock();
818 return DDERR_INVALIDPARAMS
;
821 if (cooplevel
& DDSCL_CREATEDEVICEWINDOW
)
825 if (!This
->focuswindow
&& !(cooplevel
& DDSCL_SETFOCUSWINDOW
))
827 WARN("No focus window set.\n");
828 wined3d_mutex_unlock();
829 return DDERR_NOFOCUSWINDOW
;
832 device_window
= CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME
, "DirectDrawDeviceWnd",
833 WS_POPUP
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
834 NULL
, NULL
, NULL
, NULL
);
837 ERR("Failed to create window, last error %#x.\n", GetLastError());
838 wined3d_mutex_unlock();
842 ShowWindow(device_window
, SW_SHOW
);
843 TRACE("Created a device window %p.\n", device_window
);
845 /* Native apparently leaks the created device window if setting the
846 * focus window below fails. */
847 This
->cooperative_level
|= DDSCL_CREATEDEVICEWINDOW
;
848 This
->devicewindow
= device_window
;
850 if (cooplevel
& DDSCL_SETFOCUSWINDOW
)
854 wined3d_mutex_unlock();
858 if (FAILED(hr
= ddraw_set_focus_window(This
, hwnd
)))
860 wined3d_mutex_unlock();
865 hwnd
= device_window
;
870 if (This
->cooperative_level
& DDSCL_CREATEDEVICEWINDOW
)
871 DestroyWindow(This
->devicewindow
);
872 This
->devicewindow
= NULL
;
873 This
->focuswindow
= NULL
;
876 if ((This
->cooperative_level
& DDSCL_EXCLUSIVE
)
877 && (hwnd
!= window
|| !(cooplevel
& DDSCL_EXCLUSIVE
)))
878 wined3d_device_release_focus_window(This
->wined3d_device
);
880 if ((cooplevel
& DDSCL_FULLSCREEN
) != (This
->cooperative_level
& DDSCL_FULLSCREEN
) || hwnd
!= window
)
882 if (This
->cooperative_level
& DDSCL_FULLSCREEN
)
883 wined3d_device_restore_fullscreen_window(This
->wined3d_device
, window
);
885 if (cooplevel
& DDSCL_FULLSCREEN
)
887 struct wined3d_display_mode display_mode
;
889 wined3d_get_adapter_display_mode(This
->wined3d
, WINED3DADAPTER_DEFAULT
, &display_mode
, NULL
);
890 wined3d_device_setup_fullscreen_window(This
->wined3d_device
, hwnd
,
891 display_mode
.width
, display_mode
.height
);
895 if ((cooplevel
& DDSCL_EXCLUSIVE
)
896 && (hwnd
!= window
|| !(This
->cooperative_level
& DDSCL_EXCLUSIVE
)))
898 hr
= wined3d_device_acquire_focus_window(This
->wined3d_device
, hwnd
);
901 ERR("Failed to acquire focus window, hr %#x.\n", hr
);
902 wined3d_mutex_unlock();
907 /* Don't override focus windows or private device windows */
908 if (hwnd
&& !This
->focuswindow
&& !This
->devicewindow
&& (hwnd
!= window
))
909 This
->dest_window
= hwnd
;
911 if (cooplevel
& DDSCL_MULTITHREADED
&& !(This
->cooperative_level
& DDSCL_MULTITHREADED
))
912 wined3d_device_set_multithreaded(This
->wined3d_device
);
914 if (This
->wined3d_swapchain
)
916 if (DefaultSurfaceType
!= WINED3D_SURFACE_TYPE_GDI
)
918 restore_state
= TRUE
;
920 if (FAILED(hr
= wined3d_stateblock_create(This
->wined3d_device
, WINED3D_SBT_ALL
, &stateblock
)))
922 ERR("Failed to create stateblock, hr %#x.\n", hr
);
923 wined3d_mutex_unlock();
927 if (FAILED(hr
= wined3d_stateblock_capture(stateblock
)))
929 ERR("Failed to capture stateblock, hr %#x.\n", hr
);
930 wined3d_stateblock_decref(stateblock
);
931 wined3d_mutex_unlock();
935 rt
= wined3d_device_get_render_target(This
->wined3d_device
, 0);
936 if (rt
== This
->wined3d_frontbuffer
)
939 wined3d_surface_incref(rt
);
941 wined3d_device_get_depth_stencil(This
->wined3d_device
, &ds
);
944 ddraw_destroy_swapchain(This
);
947 if (FAILED(hr
= ddraw_create_swapchain(This
, This
->dest_window
, !(cooplevel
& DDSCL_FULLSCREEN
))))
948 ERR("Failed to create swapchain, hr %#x.\n", hr
);
954 wined3d_device_set_depth_stencil(This
->wined3d_device
, ds
);
955 wined3d_surface_decref(ds
);
960 wined3d_device_set_render_target(This
->wined3d_device
, 0, rt
, FALSE
);
961 wined3d_surface_decref(rt
);
964 hr
= wined3d_stateblock_apply(stateblock
);
965 wined3d_stateblock_decref(stateblock
);
968 ERR("Failed to apply stateblock, hr %#x.\n", hr
);
969 wined3d_mutex_unlock();
974 /* Unhandled flags */
975 if(cooplevel
& DDSCL_ALLOWREBOOT
)
976 WARN("(%p) Unhandled flag DDSCL_ALLOWREBOOT, harmless\n", This
);
977 if(cooplevel
& DDSCL_ALLOWMODEX
)
978 WARN("(%p) Unhandled flag DDSCL_ALLOWMODEX, harmless\n", This
);
979 if(cooplevel
& DDSCL_FPUSETUP
)
980 WARN("(%p) Unhandled flag DDSCL_FPUSETUP, harmless\n", This
);
982 /* Store the cooperative_level */
983 This
->cooperative_level
= cooplevel
;
984 TRACE("SetCooperativeLevel retuning DD_OK\n");
985 wined3d_mutex_unlock();
990 static HRESULT WINAPI
ddraw4_SetCooperativeLevel(IDirectDraw4
*iface
, HWND window
, DWORD flags
)
992 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
994 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
996 return ddraw7_SetCooperativeLevel(&ddraw
->IDirectDraw7_iface
, window
, flags
);
999 static HRESULT WINAPI
ddraw2_SetCooperativeLevel(IDirectDraw2
*iface
, HWND window
, DWORD flags
)
1001 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1003 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1005 return ddraw7_SetCooperativeLevel(&ddraw
->IDirectDraw7_iface
, window
, flags
);
1008 static HRESULT WINAPI
ddraw1_SetCooperativeLevel(IDirectDraw
*iface
, HWND window
, DWORD flags
)
1010 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1012 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1014 return ddraw7_SetCooperativeLevel(&ddraw
->IDirectDraw7_iface
, window
, flags
);
1017 /*****************************************************************************
1019 * Helper function for SetDisplayMode and RestoreDisplayMode
1021 * Implements DirectDraw's SetDisplayMode, but ignores the value of
1022 * ForceRefreshRate, since it is already handled by
1023 * ddraw7_SetDisplayMode. RestoreDisplayMode can use this function
1024 * without worrying that ForceRefreshRate will override the refresh rate. For
1025 * argument and return value documentation, see
1026 * ddraw7_SetDisplayMode.
1028 *****************************************************************************/
1029 static HRESULT
ddraw_set_display_mode(struct ddraw
*ddraw
, DWORD Width
, DWORD Height
,
1030 DWORD BPP
, DWORD RefreshRate
, DWORD Flags
)
1032 struct wined3d_display_mode mode
;
1033 enum wined3d_format_id format
;
1036 TRACE("ddraw %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n", ddraw
, Width
,
1037 Height
, BPP
, RefreshRate
, Flags
);
1039 wined3d_mutex_lock();
1040 if( !Width
|| !Height
)
1042 ERR("Width %u, Height %u, what to do?\n", Width
, Height
);
1043 /* It looks like Need for Speed Porsche Unleashed expects DD_OK here */
1044 wined3d_mutex_unlock();
1050 case 8: format
= WINED3DFMT_P8_UINT
; break;
1051 case 15: format
= WINED3DFMT_B5G5R5X1_UNORM
; break;
1052 case 16: format
= WINED3DFMT_B5G6R5_UNORM
; break;
1053 case 24: format
= WINED3DFMT_B8G8R8_UNORM
; break;
1054 case 32: format
= WINED3DFMT_B8G8R8X8_UNORM
; break;
1055 default: format
= WINED3DFMT_UNKNOWN
; break;
1058 /* Check the exclusive mode
1059 if(!(ddraw->cooperative_level & DDSCL_EXCLUSIVE))
1060 return DDERR_NOEXCLUSIVEMODE;
1061 * This is WRONG. Don't know if the SDK is completely
1062 * wrong and if there are any conditions when DDERR_NOEXCLUSIVE
1063 * is returned, but Half-Life 1.1.1.1 (Steam version)
1068 mode
.height
= Height
;
1069 mode
.refresh_rate
= RefreshRate
;
1070 mode
.format_id
= format
;
1071 mode
.scanline_ordering
= WINED3D_SCANLINE_ORDERING_UNKNOWN
;
1073 /* TODO: The possible return values from msdn suggest that
1074 * the screen mode can't be changed if a surface is locked
1075 * or some drawing is in progress
1078 /* TODO: Lose the primary surface */
1079 hr
= wined3d_set_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
);
1081 wined3d_mutex_unlock();
1085 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
1090 /*****************************************************************************
1091 * IDirectDraw7::SetDisplayMode
1093 * Sets the display screen resolution, color depth and refresh frequency
1094 * when in fullscreen mode (in theory).
1095 * Possible return values listed in the SDK suggest that this method fails
1096 * when not in fullscreen mode, but this is wrong. Windows 2000 happily sets
1097 * the display mode in DDSCL_NORMAL mode without an hwnd specified.
1098 * It seems to be valid to pass 0 for With and Height, this has to be tested
1099 * It could mean that the current video mode should be left as-is. (But why
1103 * Height, Width: Screen dimension
1104 * BPP: Color depth in Bits per pixel
1105 * Refreshrate: Screen refresh rate
1106 * Flags: Other stuff
1111 *****************************************************************************/
1112 static HRESULT WINAPI
ddraw7_SetDisplayMode(IDirectDraw7
*iface
, DWORD Width
, DWORD Height
,
1113 DWORD BPP
, DWORD RefreshRate
, DWORD Flags
)
1115 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1117 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1118 iface
, Width
, Height
, BPP
, RefreshRate
, Flags
);
1120 if (force_refresh_rate
!= 0)
1122 TRACE("ForceRefreshRate overriding passed-in refresh rate (%u Hz) to %u Hz\n",
1123 RefreshRate
, force_refresh_rate
);
1124 RefreshRate
= force_refresh_rate
;
1127 return ddraw_set_display_mode(ddraw
, Width
, Height
, BPP
, RefreshRate
, Flags
);
1130 static HRESULT WINAPI
ddraw4_SetDisplayMode(IDirectDraw4
*iface
, DWORD width
, DWORD height
,
1131 DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1133 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1135 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1136 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1138 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, refresh_rate
, flags
);
1141 static HRESULT WINAPI
ddraw2_SetDisplayMode(IDirectDraw2
*iface
,
1142 DWORD width
, DWORD height
, DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1144 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1146 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1147 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1149 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, refresh_rate
, flags
);
1152 static HRESULT WINAPI
ddraw1_SetDisplayMode(IDirectDraw
*iface
, DWORD width
, DWORD height
, DWORD bpp
)
1154 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1156 TRACE("iface %p, width %u, height %u, bpp %u.\n", iface
, width
, height
, bpp
);
1158 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, 0, 0);
1161 /*****************************************************************************
1162 * IDirectDraw7::RestoreDisplayMode
1164 * Restores the display mode to what it was at creation time. Basically.
1166 * A problem arises when there are 2 DirectDraw objects using the same hwnd:
1167 * -> DD_1 finds the screen at 1400x1050x32 when created, sets it to 640x480x16
1168 * -> DD_2 is created, finds the screen at 640x480x16, sets it to 1024x768x32
1169 * -> DD_1 is released. The screen should be left at 1024x768x32.
1170 * -> DD_2 is released. The screen should be set to 1400x1050x32
1171 * This case is unhandled right now, but Empire Earth does it this way.
1172 * (But perhaps there is something in SetCooperativeLevel to prevent this)
1174 * The msdn says that this method resets the display mode to what it was before
1175 * SetDisplayMode was called. What if SetDisplayModes is called 2 times??
1179 * DDERR_NOEXCLUSIVE mode if the device isn't in fullscreen mode
1181 *****************************************************************************/
1182 static HRESULT WINAPI
ddraw7_RestoreDisplayMode(IDirectDraw7
*iface
)
1184 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1186 TRACE("iface %p.\n", iface
);
1188 return ddraw_set_display_mode(ddraw
, ddraw
->orig_width
, ddraw
->orig_height
, ddraw
->orig_bpp
, 0, 0);
1191 static HRESULT WINAPI
ddraw4_RestoreDisplayMode(IDirectDraw4
*iface
)
1193 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1195 TRACE("iface %p.\n", iface
);
1197 return ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
1200 static HRESULT WINAPI
ddraw2_RestoreDisplayMode(IDirectDraw2
*iface
)
1202 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1204 TRACE("iface %p.\n", iface
);
1206 return ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
1209 static HRESULT WINAPI
ddraw1_RestoreDisplayMode(IDirectDraw
*iface
)
1211 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1213 TRACE("iface %p.\n", iface
);
1215 return ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
1218 /*****************************************************************************
1219 * IDirectDraw7::GetCaps
1221 * Returns the drives capabilities
1223 * Used for version 1, 2, 4 and 7
1226 * DriverCaps: Structure to write the Hardware accelerated caps to
1227 * HelCaps: Structure to write the emulation caps to
1230 * This implementation returns DD_OK only
1232 *****************************************************************************/
1233 static HRESULT WINAPI
ddraw7_GetCaps(IDirectDraw7
*iface
, DDCAPS
*DriverCaps
, DDCAPS
*HELCaps
)
1235 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1237 WINED3DCAPS winecaps
;
1239 DDSCAPS2 ddscaps
= {0, 0, 0, 0};
1241 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, DriverCaps
, HELCaps
);
1243 /* One structure must be != NULL */
1244 if (!DriverCaps
&& !HELCaps
)
1246 WARN("Invalid parameters.\n");
1247 return DDERR_INVALIDPARAMS
;
1250 memset(&caps
, 0, sizeof(caps
));
1251 memset(&winecaps
, 0, sizeof(winecaps
));
1252 caps
.dwSize
= sizeof(caps
);
1254 wined3d_mutex_lock();
1255 hr
= wined3d_device_get_device_caps(ddraw
->wined3d_device
, &winecaps
);
1258 WARN("IWineD3DDevice::GetDeviceCaps failed\n");
1259 wined3d_mutex_unlock();
1263 hr
= IDirectDraw7_GetAvailableVidMem(iface
, &ddscaps
, &caps
.dwVidMemTotal
, &caps
.dwVidMemFree
);
1264 wined3d_mutex_unlock();
1266 WARN("IDirectDraw7::GetAvailableVidMem failed\n");
1270 caps
.dwCaps
= winecaps
.ddraw_caps
.caps
;
1271 caps
.dwCaps2
= winecaps
.ddraw_caps
.caps2
;
1272 caps
.dwCKeyCaps
= winecaps
.ddraw_caps
.color_key_caps
;
1273 caps
.dwFXCaps
= winecaps
.ddraw_caps
.fx_caps
;
1274 caps
.dwPalCaps
= winecaps
.ddraw_caps
.pal_caps
;
1275 caps
.ddsCaps
.dwCaps
= winecaps
.ddraw_caps
.dds_caps
;
1276 caps
.dwSVBCaps
= winecaps
.ddraw_caps
.svb_caps
;
1277 caps
.dwSVBCKeyCaps
= winecaps
.ddraw_caps
.svb_color_key_caps
;
1278 caps
.dwSVBFXCaps
= winecaps
.ddraw_caps
.svb_fx_caps
;
1279 caps
.dwVSBCaps
= winecaps
.ddraw_caps
.vsb_caps
;
1280 caps
.dwVSBCKeyCaps
= winecaps
.ddraw_caps
.vsb_color_key_caps
;
1281 caps
.dwVSBFXCaps
= winecaps
.ddraw_caps
.vsb_fx_caps
;
1282 caps
.dwSSBCaps
= winecaps
.ddraw_caps
.ssb_caps
;
1283 caps
.dwSSBCKeyCaps
= winecaps
.ddraw_caps
.ssb_color_key_caps
;
1284 caps
.dwSSBFXCaps
= winecaps
.ddraw_caps
.ssb_fx_caps
;
1286 /* Even if WineD3D supports 3D rendering, remove the cap if ddraw is configured
1289 if (DefaultSurfaceType
== WINED3D_SURFACE_TYPE_GDI
)
1291 caps
.dwCaps
&= ~DDCAPS_3D
;
1292 caps
.ddsCaps
.dwCaps
&= ~(DDSCAPS_3DDEVICE
| DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
| DDSCAPS_ZBUFFER
);
1294 if (winecaps
.ddraw_caps
.stride_align
)
1296 caps
.dwCaps
|= DDCAPS_ALIGNSTRIDE
;
1297 caps
.dwAlignStrideAlign
= winecaps
.ddraw_caps
.stride_align
;
1302 DD_STRUCT_COPY_BYSIZE(DriverCaps
, &caps
);
1303 if (TRACE_ON(ddraw
))
1305 TRACE("Driver Caps :\n");
1306 DDRAW_dump_DDCAPS(DriverCaps
);
1312 DD_STRUCT_COPY_BYSIZE(HELCaps
, &caps
);
1313 if (TRACE_ON(ddraw
))
1315 TRACE("HEL Caps :\n");
1316 DDRAW_dump_DDCAPS(HELCaps
);
1323 static HRESULT WINAPI
ddraw4_GetCaps(IDirectDraw4
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1325 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1327 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1329 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1332 static HRESULT WINAPI
ddraw2_GetCaps(IDirectDraw2
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1334 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1336 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1338 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1341 static HRESULT WINAPI
ddraw1_GetCaps(IDirectDraw
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1343 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1345 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1347 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1350 /*****************************************************************************
1351 * IDirectDraw7::Compact
1353 * No idea what it does, MSDN says it's not implemented.
1356 * DD_OK, but this is unchecked
1358 *****************************************************************************/
1359 static HRESULT WINAPI
ddraw7_Compact(IDirectDraw7
*iface
)
1361 TRACE("iface %p.\n", iface
);
1366 static HRESULT WINAPI
ddraw4_Compact(IDirectDraw4
*iface
)
1368 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1370 TRACE("iface %p.\n", iface
);
1372 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1375 static HRESULT WINAPI
ddraw2_Compact(IDirectDraw2
*iface
)
1377 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1379 TRACE("iface %p.\n", iface
);
1381 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1384 static HRESULT WINAPI
ddraw1_Compact(IDirectDraw
*iface
)
1386 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1388 TRACE("iface %p.\n", iface
);
1390 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1393 /*****************************************************************************
1394 * IDirectDraw7::GetDisplayMode
1396 * Returns information about the current display mode
1398 * Exists in Version 1, 2, 4 and 7
1401 * DDSD: Address of a surface description structure to write the info to
1406 *****************************************************************************/
1407 static HRESULT WINAPI
ddraw7_GetDisplayMode(IDirectDraw7
*iface
, DDSURFACEDESC2
*DDSD
)
1409 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1410 struct wined3d_display_mode mode
;
1414 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
1416 wined3d_mutex_lock();
1417 /* This seems sane */
1420 wined3d_mutex_unlock();
1421 return DDERR_INVALIDPARAMS
;
1424 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
1426 ERR("Failed to get display mode, hr %#x.\n", hr
);
1427 wined3d_mutex_unlock();
1431 Size
= DDSD
->dwSize
;
1432 memset(DDSD
, 0, Size
);
1434 DDSD
->dwSize
= Size
;
1435 DDSD
->dwFlags
|= DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
| DDSD_PITCH
| DDSD_REFRESHRATE
;
1436 DDSD
->dwWidth
= mode
.width
;
1437 DDSD
->dwHeight
= mode
.height
;
1438 DDSD
->u2
.dwRefreshRate
= 60;
1439 DDSD
->ddsCaps
.dwCaps
= 0;
1440 DDSD
->u4
.ddpfPixelFormat
.dwSize
= sizeof(DDSD
->u4
.ddpfPixelFormat
);
1441 PixelFormat_WineD3DtoDD(&DDSD
->u4
.ddpfPixelFormat
, mode
.format_id
);
1442 DDSD
->u1
.lPitch
= mode
.width
* DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8;
1446 TRACE("Returning surface desc :\n");
1447 DDRAW_dump_surface_desc(DDSD
);
1450 wined3d_mutex_unlock();
1455 static HRESULT WINAPI
ddraw4_GetDisplayMode(IDirectDraw4
*iface
, DDSURFACEDESC2
*surface_desc
)
1457 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1459 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1461 return ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, surface_desc
);
1464 static HRESULT WINAPI
ddraw2_GetDisplayMode(IDirectDraw2
*iface
, DDSURFACEDESC
*surface_desc
)
1466 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1468 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1470 /* FIXME: Test sizes, properly convert surface_desc */
1471 return ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1474 static HRESULT WINAPI
ddraw1_GetDisplayMode(IDirectDraw
*iface
, DDSURFACEDESC
*surface_desc
)
1476 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1478 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1480 /* FIXME: Test sizes, properly convert surface_desc */
1481 return ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1484 /*****************************************************************************
1485 * IDirectDraw7::GetFourCCCodes
1487 * Returns an array of supported FourCC codes.
1489 * Exists in Version 1, 2, 4 and 7
1492 * NumCodes: Contains the number of Codes that Codes can carry. Returns the number
1493 * of enumerated codes
1494 * Codes: Pointer to an array of DWORDs where the supported codes are written
1498 * Always returns DD_OK, as it's a stub for now
1500 *****************************************************************************/
1501 static HRESULT WINAPI
ddraw7_GetFourCCCodes(IDirectDraw7
*iface
, DWORD
*NumCodes
, DWORD
*Codes
)
1503 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1504 static const enum wined3d_format_id formats
[] =
1506 WINED3DFMT_YUY2
, WINED3DFMT_UYVY
, WINED3DFMT_YV12
,
1507 WINED3DFMT_DXT1
, WINED3DFMT_DXT2
, WINED3DFMT_DXT3
, WINED3DFMT_DXT4
, WINED3DFMT_DXT5
,
1508 WINED3DFMT_ATI2N
, WINED3DFMT_NVHU
, WINED3DFMT_NVHS
1510 struct wined3d_display_mode mode
;
1511 DWORD count
= 0, i
, outsize
;
1514 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, NumCodes
, Codes
);
1516 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
1518 ERR("Failed to get display mode, hr %#x.\n", hr
);
1522 outsize
= NumCodes
&& Codes
? *NumCodes
: 0;
1524 for (i
= 0; i
< (sizeof(formats
) / sizeof(formats
[0])); ++i
)
1526 hr
= wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, WINED3D_DEVICE_TYPE_HAL
,
1527 mode
.format_id
, 0, WINED3D_RTYPE_SURFACE
, formats
[i
], DefaultSurfaceType
);
1530 if (count
< outsize
)
1531 Codes
[count
] = formats
[i
];
1536 TRACE("Returning %u FourCC codes\n", count
);
1543 static HRESULT WINAPI
ddraw4_GetFourCCCodes(IDirectDraw4
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1545 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1547 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1549 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1552 static HRESULT WINAPI
ddraw2_GetFourCCCodes(IDirectDraw2
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1554 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1556 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1558 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1561 static HRESULT WINAPI
ddraw1_GetFourCCCodes(IDirectDraw
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1563 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1565 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1567 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1570 static HRESULT WINAPI
ddraw7_GetMonitorFrequency(IDirectDraw7
*iface
, DWORD
*frequency
)
1572 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1573 struct wined3d_display_mode mode
;
1576 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1578 wined3d_mutex_lock();
1579 hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
);
1580 wined3d_mutex_unlock();
1583 WARN("Failed to get display mode, hr %#x.\n", hr
);
1587 *frequency
= mode
.refresh_rate
;
1592 static HRESULT WINAPI
ddraw4_GetMonitorFrequency(IDirectDraw4
*iface
, DWORD
*frequency
)
1594 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1596 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1598 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1601 static HRESULT WINAPI
ddraw2_GetMonitorFrequency(IDirectDraw2
*iface
, DWORD
*frequency
)
1603 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1605 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1607 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1610 static HRESULT WINAPI
ddraw1_GetMonitorFrequency(IDirectDraw
*iface
, DWORD
*frequency
)
1612 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1614 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1616 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1619 static HRESULT WINAPI
ddraw7_GetVerticalBlankStatus(IDirectDraw7
*iface
, BOOL
*status
)
1621 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1622 struct wined3d_raster_status raster_status
;
1625 TRACE("iface %p, status %p.\n", iface
, status
);
1628 return DDERR_INVALIDPARAMS
;
1630 wined3d_mutex_lock();
1631 hr
= wined3d_get_adapter_raster_status(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &raster_status
);
1632 wined3d_mutex_unlock();
1635 WARN("Failed to get raster status, hr %#x.\n", hr
);
1639 *status
= raster_status
.in_vblank
;
1644 static HRESULT WINAPI
ddraw4_GetVerticalBlankStatus(IDirectDraw4
*iface
, BOOL
*status
)
1646 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1648 TRACE("iface %p, status %p.\n", iface
, status
);
1650 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1653 static HRESULT WINAPI
ddraw2_GetVerticalBlankStatus(IDirectDraw2
*iface
, BOOL
*status
)
1655 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1657 TRACE("iface %p, status %p.\n", iface
, status
);
1659 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1662 static HRESULT WINAPI
ddraw1_GetVerticalBlankStatus(IDirectDraw
*iface
, BOOL
*status
)
1664 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1666 TRACE("iface %p, status %p.\n", iface
, status
);
1668 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1671 /*****************************************************************************
1672 * IDirectDraw7::GetAvailableVidMem
1674 * Returns the total and free video memory
1677 * Caps: Specifies the memory type asked for
1678 * total: Pointer to a DWORD to be filled with the total memory
1679 * free: Pointer to a DWORD to be filled with the free memory
1683 * DDERR_INVALIDPARAMS of free and total are NULL
1685 *****************************************************************************/
1686 static HRESULT WINAPI
ddraw7_GetAvailableVidMem(IDirectDraw7
*iface
, DDSCAPS2
*Caps
, DWORD
*total
,
1689 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1692 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, Caps
, total
, free
);
1694 if (TRACE_ON(ddraw
))
1696 TRACE("Asked for memory with description: ");
1697 DDRAW_dump_DDSCAPS2(Caps
);
1699 wined3d_mutex_lock();
1701 /* Todo: System memory vs local video memory vs non-local video memory
1702 * The MSDN also mentions differences between texture memory and other
1703 * resources, but that's not important
1706 if( (!total
) && (!free
) )
1708 wined3d_mutex_unlock();
1709 return DDERR_INVALIDPARAMS
;
1713 *free
= wined3d_device_get_available_texture_mem(ddraw
->wined3d_device
);
1716 struct wined3d_adapter_identifier desc
= {0};
1718 hr
= wined3d_get_adapter_identifier(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, 0, &desc
);
1719 *total
= desc
.video_memory
;
1722 wined3d_mutex_unlock();
1727 static HRESULT WINAPI
ddraw4_GetAvailableVidMem(IDirectDraw4
*iface
,
1728 DDSCAPS2
*caps
, DWORD
*total
, DWORD
*free
)
1730 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1732 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1734 return ddraw7_GetAvailableVidMem(&ddraw
->IDirectDraw7_iface
, caps
, total
, free
);
1737 static HRESULT WINAPI
ddraw2_GetAvailableVidMem(IDirectDraw2
*iface
,
1738 DDSCAPS
*caps
, DWORD
*total
, DWORD
*free
)
1740 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1743 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1745 DDRAW_Convert_DDSCAPS_1_To_2(caps
, &caps2
);
1746 return ddraw7_GetAvailableVidMem(&ddraw
->IDirectDraw7_iface
, &caps2
, total
, free
);
1749 /*****************************************************************************
1750 * IDirectDraw7::Initialize
1752 * Initializes a DirectDraw interface.
1755 * GUID: Interface identifier. Well, don't know what this is really good
1759 * Returns DD_OK on the first call,
1760 * DDERR_ALREADYINITIALIZED on repeated calls
1762 *****************************************************************************/
1763 static HRESULT WINAPI
ddraw7_Initialize(IDirectDraw7
*iface
, GUID
*guid
)
1765 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1767 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1769 if (ddraw
->initialized
)
1770 return DDERR_ALREADYINITIALIZED
;
1772 /* FIXME: To properly take the GUID into account we should call
1773 * ddraw_init() here instead of in DDRAW_Create(). */
1775 FIXME("Ignoring guid %s.\n", debugstr_guid(guid
));
1777 ddraw
->initialized
= TRUE
;
1781 static HRESULT WINAPI
ddraw4_Initialize(IDirectDraw4
*iface
, GUID
*guid
)
1783 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1785 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1787 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
1790 static HRESULT WINAPI
ddraw2_Initialize(IDirectDraw2
*iface
, GUID
*guid
)
1792 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1794 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1796 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
1799 static HRESULT WINAPI
ddraw1_Initialize(IDirectDraw
*iface
, GUID
*guid
)
1801 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1803 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1805 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
1808 static HRESULT WINAPI
d3d1_Initialize(IDirect3D
*iface
, REFIID riid
)
1810 TRACE("iface %p, riid %s.\n", iface
, debugstr_guid(riid
));
1812 return DDERR_ALREADYINITIALIZED
;
1815 /*****************************************************************************
1816 * IDirectDraw7::FlipToGDISurface
1818 * "Makes the surface that the GDI writes to the primary surface"
1819 * Looks like some windows specific thing we don't have to care about.
1820 * According to MSDN it permits GDI dialog boxes in FULLSCREEN mode. Good to
1821 * show error boxes ;)
1822 * Well, just return DD_OK.
1825 * Always returns DD_OK
1827 *****************************************************************************/
1828 static HRESULT WINAPI
ddraw7_FlipToGDISurface(IDirectDraw7
*iface
)
1830 FIXME("iface %p stub!\n", iface
);
1835 static HRESULT WINAPI
ddraw4_FlipToGDISurface(IDirectDraw4
*iface
)
1837 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1839 TRACE("iface %p.\n", iface
);
1841 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
1844 static HRESULT WINAPI
ddraw2_FlipToGDISurface(IDirectDraw2
*iface
)
1846 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1848 TRACE("iface %p.\n", iface
);
1850 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
1853 static HRESULT WINAPI
ddraw1_FlipToGDISurface(IDirectDraw
*iface
)
1855 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1857 TRACE("iface %p.\n", iface
);
1859 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
1862 /*****************************************************************************
1863 * IDirectDraw7::WaitForVerticalBlank
1865 * This method allows applications to get in sync with the vertical blank
1867 * The wormhole demo in the DirectX 7 sdk uses this call, and it doesn't
1868 * redraw the screen, most likely because of this stub
1871 * Flags: one of DDWAITVB_BLOCKBEGIN, DDWAITVB_BLOCKBEGINEVENT
1872 * or DDWAITVB_BLOCKEND
1873 * h: Not used, according to MSDN
1876 * Always returns DD_OK
1878 *****************************************************************************/
1879 static HRESULT WINAPI
ddraw7_WaitForVerticalBlank(IDirectDraw7
*iface
, DWORD Flags
, HANDLE event
)
1883 TRACE("iface %p, flags %#x, event %p.\n", iface
, Flags
, event
);
1885 /* This function is called often, so print the fixme only once */
1888 FIXME("iface %p, flags %#x, event %p stub!\n", iface
, Flags
, event
);
1892 /* MSDN says DDWAITVB_BLOCKBEGINEVENT is not supported */
1893 if(Flags
& DDWAITVB_BLOCKBEGINEVENT
)
1894 return DDERR_UNSUPPORTED
; /* unchecked */
1899 static HRESULT WINAPI
ddraw4_WaitForVerticalBlank(IDirectDraw4
*iface
, DWORD flags
, HANDLE event
)
1901 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1903 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
1905 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
1908 static HRESULT WINAPI
ddraw2_WaitForVerticalBlank(IDirectDraw2
*iface
, DWORD flags
, HANDLE event
)
1910 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1912 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
1914 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
1917 static HRESULT WINAPI
ddraw1_WaitForVerticalBlank(IDirectDraw
*iface
, DWORD flags
, HANDLE event
)
1919 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1921 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
1923 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
1926 static HRESULT WINAPI
ddraw7_GetScanLine(IDirectDraw7
*iface
, DWORD
*Scanline
)
1928 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1929 struct wined3d_raster_status raster_status
;
1932 TRACE("iface %p, line %p.\n", iface
, Scanline
);
1934 wined3d_mutex_lock();
1935 hr
= wined3d_get_adapter_raster_status(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &raster_status
);
1936 wined3d_mutex_unlock();
1939 WARN("Failed to get raster status, hr %#x.\n", hr
);
1943 *Scanline
= raster_status
.scan_line
;
1945 if (raster_status
.in_vblank
)
1946 return DDERR_VERTICALBLANKINPROGRESS
;
1951 static HRESULT WINAPI
ddraw4_GetScanLine(IDirectDraw4
*iface
, DWORD
*line
)
1953 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1955 TRACE("iface %p, line %p.\n", iface
, line
);
1957 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
1960 static HRESULT WINAPI
ddraw2_GetScanLine(IDirectDraw2
*iface
, DWORD
*line
)
1962 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1964 TRACE("iface %p, line %p.\n", iface
, line
);
1966 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
1969 static HRESULT WINAPI
ddraw1_GetScanLine(IDirectDraw
*iface
, DWORD
*line
)
1971 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1973 TRACE("iface %p, line %p.\n", iface
, line
);
1975 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
1978 /*****************************************************************************
1979 * IDirectDraw7::TestCooperativeLevel
1981 * Informs the application about the state of the video adapter, depending
1982 * on the cooperative level
1985 * DD_OK if the device is in a sane state
1986 * DDERR_NOEXCLUSIVEMODE or DDERR_EXCLUSIVEMODEALREADYSET
1987 * if the state is not correct(See below)
1989 *****************************************************************************/
1990 static HRESULT WINAPI
ddraw7_TestCooperativeLevel(IDirectDraw7
*iface
)
1992 TRACE("iface %p.\n", iface
);
1997 static HRESULT WINAPI
ddraw4_TestCooperativeLevel(IDirectDraw4
*iface
)
1999 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2001 TRACE("iface %p.\n", iface
);
2003 return ddraw7_TestCooperativeLevel(&ddraw
->IDirectDraw7_iface
);
2006 /*****************************************************************************
2007 * IDirectDraw7::GetGDISurface
2009 * Returns the surface that GDI is treating as the primary surface.
2010 * For Wine this is the front buffer
2013 * GDISurface: Address to write the surface pointer to
2016 * DD_OK if the surface was found
2017 * DDERR_NOTFOUND if the GDI surface wasn't found
2019 *****************************************************************************/
2020 static HRESULT WINAPI
ddraw7_GetGDISurface(IDirectDraw7
*iface
, IDirectDrawSurface7
**GDISurface
)
2022 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2024 TRACE("iface %p, surface %p.\n", iface
, GDISurface
);
2026 wined3d_mutex_lock();
2028 if (!(*GDISurface
= &ddraw
->primary
->IDirectDrawSurface7_iface
))
2030 WARN("Primary not created yet.\n");
2031 wined3d_mutex_unlock();
2032 return DDERR_NOTFOUND
;
2034 IDirectDrawSurface7_AddRef(*GDISurface
);
2036 wined3d_mutex_unlock();
2041 static HRESULT WINAPI
ddraw4_GetGDISurface(IDirectDraw4
*iface
, IDirectDrawSurface4
**surface
)
2043 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2044 struct ddraw_surface
*surface_impl
;
2045 IDirectDrawSurface7
*surface7
;
2048 TRACE("iface %p, surface %p.\n", iface
, surface
);
2050 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2056 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2057 *surface
= &surface_impl
->IDirectDrawSurface4_iface
;
2058 IDirectDrawSurface4_AddRef(*surface
);
2059 IDirectDrawSurface7_Release(surface7
);
2064 static HRESULT WINAPI
ddraw2_GetGDISurface(IDirectDraw2
*iface
, IDirectDrawSurface
**surface
)
2066 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2067 struct ddraw_surface
*surface_impl
;
2068 IDirectDrawSurface7
*surface7
;
2071 TRACE("iface %p, surface %p.\n", iface
, surface
);
2073 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2079 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2080 *surface
= &surface_impl
->IDirectDrawSurface_iface
;
2081 IDirectDrawSurface_AddRef(*surface
);
2082 IDirectDrawSurface7_Release(surface7
);
2087 static HRESULT WINAPI
ddraw1_GetGDISurface(IDirectDraw
*iface
, IDirectDrawSurface
**surface
)
2089 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2090 struct ddraw_surface
*surface_impl
;
2091 IDirectDrawSurface7
*surface7
;
2094 TRACE("iface %p, surface %p.\n", iface
, surface
);
2096 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2102 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2103 *surface
= &surface_impl
->IDirectDrawSurface_iface
;
2104 IDirectDrawSurface_AddRef(*surface
);
2105 IDirectDrawSurface7_Release(surface7
);
2110 struct displaymodescallback_context
2112 LPDDENUMMODESCALLBACK func
;
2116 static HRESULT CALLBACK
EnumDisplayModesCallbackThunk(DDSURFACEDESC2
*surface_desc
, void *context
)
2118 struct displaymodescallback_context
*cbcontext
= context
;
2121 DDSD2_to_DDSD(surface_desc
, &desc
);
2122 return cbcontext
->func(&desc
, cbcontext
->context
);
2125 /*****************************************************************************
2126 * IDirectDraw7::EnumDisplayModes
2128 * Enumerates the supported Display modes. The modes can be filtered with
2129 * the DDSD parameter.
2132 * Flags: can be DDEDM_REFRESHRATES and DDEDM_STANDARDVGAMODES. For old ddraw
2133 * versions (3 and older?) this is reserved and must be 0.
2134 * DDSD: Surface description to filter the modes
2135 * Context: Pointer passed back to the callback function
2136 * cb: Application-provided callback function
2140 * DDERR_INVALIDPARAMS if the callback wasn't set
2142 *****************************************************************************/
2143 static HRESULT WINAPI
ddraw7_EnumDisplayModes(IDirectDraw7
*iface
, DWORD Flags
,
2144 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMMODESCALLBACK2 cb
)
2146 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2147 struct wined3d_display_mode
*enum_modes
= NULL
;
2148 struct wined3d_display_mode mode
;
2149 unsigned int modenum
, fmt
;
2150 DDSURFACEDESC2 callback_sd
;
2151 unsigned enum_mode_count
= 0, enum_mode_array_size
= 0;
2152 DDPIXELFORMAT pixelformat
;
2154 static const enum wined3d_format_id checkFormatList
[] =
2156 WINED3DFMT_B8G8R8X8_UNORM
,
2157 WINED3DFMT_B5G6R5_UNORM
,
2161 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2162 iface
, Flags
, DDSD
, Context
, cb
);
2165 return DDERR_INVALIDPARAMS
;
2167 wined3d_mutex_lock();
2168 if(!(Flags
& DDEDM_REFRESHRATES
))
2170 enum_mode_array_size
= 16;
2171 enum_modes
= HeapAlloc(GetProcessHeap(), 0, sizeof(*enum_modes
) * enum_mode_array_size
);
2174 ERR("Out of memory\n");
2175 wined3d_mutex_unlock();
2176 return DDERR_OUTOFMEMORY
;
2180 pixelformat
.dwSize
= sizeof(pixelformat
);
2181 for(fmt
= 0; fmt
< (sizeof(checkFormatList
) / sizeof(checkFormatList
[0])); fmt
++)
2184 while (wined3d_enum_adapter_modes(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, checkFormatList
[fmt
],
2185 WINED3D_SCANLINE_ORDERING_UNKNOWN
, modenum
++, &mode
) == WINED3D_OK
)
2187 PixelFormat_WineD3DtoDD(&pixelformat
, mode
.format_id
);
2190 if (DDSD
->dwFlags
& DDSD_WIDTH
&& mode
.width
!= DDSD
->dwWidth
)
2192 if (DDSD
->dwFlags
& DDSD_HEIGHT
&& mode
.height
!= DDSD
->dwHeight
)
2194 if (DDSD
->dwFlags
& DDSD_REFRESHRATE
&& mode
.refresh_rate
!= DDSD
->u2
.dwRefreshRate
)
2196 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
2197 && pixelformat
.u1
.dwRGBBitCount
!= DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
)
2201 if(!(Flags
& DDEDM_REFRESHRATES
))
2203 /* DX docs state EnumDisplayMode should return only unique modes. If DDEDM_REFRESHRATES is not set, refresh
2204 * rate doesn't matter when determining if the mode is unique. So modes only differing in refresh rate have
2205 * to be reduced to a single unique result in such case.
2210 for (i
= 0; i
< enum_mode_count
; i
++)
2212 if (enum_modes
[i
].width
== mode
.width
&& enum_modes
[i
].height
== mode
.height
2213 && enum_modes
[i
].format_id
== mode
.format_id
)
2223 memset(&callback_sd
, 0, sizeof(callback_sd
));
2224 callback_sd
.dwSize
= sizeof(callback_sd
);
2225 callback_sd
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
2227 callback_sd
.dwFlags
= DDSD_HEIGHT
|DDSD_WIDTH
|DDSD_PIXELFORMAT
|DDSD_PITCH
|DDSD_REFRESHRATE
;
2228 if (Flags
& DDEDM_REFRESHRATES
)
2229 callback_sd
.u2
.dwRefreshRate
= mode
.refresh_rate
;
2231 callback_sd
.dwWidth
= mode
.width
;
2232 callback_sd
.dwHeight
= mode
.height
;
2234 callback_sd
.u4
.ddpfPixelFormat
=pixelformat
;
2236 /* Calc pitch and DWORD align like MSDN says */
2237 callback_sd
.u1
.lPitch
= (callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8) * mode
.width
;
2238 callback_sd
.u1
.lPitch
= (callback_sd
.u1
.lPitch
+ 3) & ~3;
2240 TRACE("Enumerating %dx%dx%d @%d\n", callback_sd
.dwWidth
, callback_sd
.dwHeight
, callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
,
2241 callback_sd
.u2
.dwRefreshRate
);
2243 if(cb(&callback_sd
, Context
) == DDENUMRET_CANCEL
)
2245 TRACE("Application asked to terminate the enumeration\n");
2246 HeapFree(GetProcessHeap(), 0, enum_modes
);
2247 wined3d_mutex_unlock();
2251 if(!(Flags
& DDEDM_REFRESHRATES
))
2253 if (enum_mode_count
== enum_mode_array_size
)
2255 struct wined3d_display_mode
*new_enum_modes
;
2257 enum_mode_array_size
*= 2;
2258 new_enum_modes
= HeapReAlloc(GetProcessHeap(), 0, enum_modes
,
2259 sizeof(*new_enum_modes
) * enum_mode_array_size
);
2260 if (!new_enum_modes
)
2262 ERR("Out of memory\n");
2263 HeapFree(GetProcessHeap(), 0, enum_modes
);
2264 wined3d_mutex_unlock();
2265 return DDERR_OUTOFMEMORY
;
2268 enum_modes
= new_enum_modes
;
2271 enum_modes
[enum_mode_count
++] = mode
;
2276 TRACE("End of enumeration\n");
2277 HeapFree(GetProcessHeap(), 0, enum_modes
);
2278 wined3d_mutex_unlock();
2283 static HRESULT WINAPI
ddraw4_EnumDisplayModes(IDirectDraw4
*iface
, DWORD flags
,
2284 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK2 callback
)
2286 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2288 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2289 iface
, flags
, surface_desc
, context
, callback
);
2291 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
, surface_desc
, context
, callback
);
2294 static HRESULT WINAPI
ddraw2_EnumDisplayModes(IDirectDraw2
*iface
, DWORD flags
,
2295 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2297 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2298 struct displaymodescallback_context cbcontext
;
2299 DDSURFACEDESC2 surface_desc2
;
2301 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2302 iface
, flags
, surface_desc
, context
, callback
);
2304 cbcontext
.func
= callback
;
2305 cbcontext
.context
= context
;
2307 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2308 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
,
2309 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2312 static HRESULT WINAPI
ddraw1_EnumDisplayModes(IDirectDraw
*iface
, DWORD flags
,
2313 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2315 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2316 struct displaymodescallback_context cbcontext
;
2317 DDSURFACEDESC2 surface_desc2
;
2319 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2320 iface
, flags
, surface_desc
, context
, callback
);
2322 cbcontext
.func
= callback
;
2323 cbcontext
.context
= context
;
2325 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2326 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
,
2327 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2330 /*****************************************************************************
2331 * IDirectDraw7::EvaluateMode
2333 * Used with IDirectDraw7::StartModeTest to test video modes.
2334 * EvaluateMode is used to pass or fail a mode, and continue with the next
2338 * Flags: DDEM_MODEPASSED or DDEM_MODEFAILED
2339 * Timeout: Returns the amount of seconds left before the mode would have
2340 * been failed automatically
2343 * This implementation always DD_OK, because it's a stub
2345 *****************************************************************************/
2346 static HRESULT WINAPI
ddraw7_EvaluateMode(IDirectDraw7
*iface
, DWORD Flags
, DWORD
*Timeout
)
2348 FIXME("iface %p, flags %#x, timeout %p stub!\n", iface
, Flags
, Timeout
);
2350 /* When implementing this, implement it in WineD3D */
2355 /*****************************************************************************
2356 * IDirectDraw7::GetDeviceIdentifier
2358 * Returns the device identifier, which gives information about the driver
2359 * Our device identifier is defined at the beginning of this file.
2362 * DDDI: Address for the returned structure
2363 * Flags: Can be DDGDI_GETHOSTIDENTIFIER
2366 * On success it returns DD_OK
2367 * DDERR_INVALIDPARAMS if DDDI is NULL
2369 *****************************************************************************/
2370 static HRESULT WINAPI
ddraw7_GetDeviceIdentifier(IDirectDraw7
*iface
,
2371 DDDEVICEIDENTIFIER2
*DDDI
, DWORD Flags
)
2373 TRACE("iface %p, device_identifier %p, flags %#x.\n", iface
, DDDI
, Flags
);
2376 return DDERR_INVALIDPARAMS
;
2378 /* The DDGDI_GETHOSTIDENTIFIER returns the information about the 2D
2379 * host adapter, if there's a secondary 3D adapter. This doesn't apply
2380 * to any modern hardware, nor is it interesting for Wine, so ignore it.
2381 * Size of DDDEVICEIDENTIFIER2 may be aligned to 8 bytes and thus 4
2382 * bytes too long. So only copy the relevant part of the structure
2385 memcpy(DDDI
, &deviceidentifier
, FIELD_OFFSET(DDDEVICEIDENTIFIER2
, dwWHQLLevel
) + sizeof(DWORD
));
2389 static HRESULT WINAPI
ddraw4_GetDeviceIdentifier(IDirectDraw4
*iface
,
2390 DDDEVICEIDENTIFIER
*identifier
, DWORD flags
)
2392 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2393 DDDEVICEIDENTIFIER2 identifier2
;
2396 TRACE("iface %p, identifier %p, flags %#x.\n", iface
, identifier
, flags
);
2398 hr
= ddraw7_GetDeviceIdentifier(&ddraw
->IDirectDraw7_iface
, &identifier2
, flags
);
2399 DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(&identifier2
, identifier
);
2404 /*****************************************************************************
2405 * IDirectDraw7::GetSurfaceFromDC
2407 * Returns the Surface for a GDI device context handle.
2408 * Is this related to IDirectDrawSurface::GetDC ???
2411 * hdc: hdc to return the surface for
2412 * Surface: Address to write the surface pointer to
2415 * Always returns DD_OK because it's a stub
2417 *****************************************************************************/
2418 static HRESULT WINAPI
ddraw7_GetSurfaceFromDC(IDirectDraw7
*iface
, HDC hdc
,
2419 IDirectDrawSurface7
**Surface
)
2421 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2422 struct wined3d_surface
*wined3d_surface
;
2423 struct ddraw_surface
*surface_impl
;
2426 TRACE("iface %p, dc %p, surface %p.\n", iface
, hdc
, Surface
);
2428 if (!Surface
) return E_INVALIDARG
;
2430 hr
= wined3d_device_get_surface_from_dc(ddraw
->wined3d_device
, hdc
, &wined3d_surface
);
2433 TRACE("No surface found for dc %p.\n", hdc
);
2435 return DDERR_NOTFOUND
;
2438 surface_impl
= wined3d_surface_get_parent(wined3d_surface
);
2439 *Surface
= &surface_impl
->IDirectDrawSurface7_iface
;
2440 IDirectDrawSurface7_AddRef(*Surface
);
2441 TRACE("Returning surface %p.\n", Surface
);
2445 static HRESULT WINAPI
ddraw4_GetSurfaceFromDC(IDirectDraw4
*iface
, HDC dc
,
2446 IDirectDrawSurface4
**surface
)
2448 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2449 struct ddraw_surface
*surface_impl
;
2450 IDirectDrawSurface7
*surface7
;
2453 TRACE("iface %p, dc %p, surface %p.\n", iface
, dc
, surface
);
2455 if (!surface
) return E_INVALIDARG
;
2457 hr
= ddraw7_GetSurfaceFromDC(&ddraw
->IDirectDraw7_iface
, dc
, &surface7
);
2463 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2464 /* Tests say this is true */
2465 *surface
= (IDirectDrawSurface4
*)&surface_impl
->IDirectDrawSurface_iface
;
2466 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
2467 IDirectDrawSurface7_Release(surface7
);
2472 /*****************************************************************************
2473 * IDirectDraw7::RestoreAllSurfaces
2475 * Calls the restore method of all surfaces
2480 * Always returns DD_OK because it's a stub
2482 *****************************************************************************/
2483 static HRESULT WINAPI
ddraw7_RestoreAllSurfaces(IDirectDraw7
*iface
)
2485 FIXME("iface %p stub!\n", iface
);
2487 /* This isn't hard to implement: Enumerate all WineD3D surfaces,
2488 * get their parent and call their restore method. Do not implement
2489 * it in WineD3D, as restoring a surface means re-creating the
2495 static HRESULT WINAPI
ddraw4_RestoreAllSurfaces(IDirectDraw4
*iface
)
2497 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2499 TRACE("iface %p.\n", iface
);
2501 return ddraw7_RestoreAllSurfaces(&ddraw
->IDirectDraw7_iface
);
2504 /*****************************************************************************
2505 * IDirectDraw7::StartModeTest
2507 * Tests the specified video modes to update the system registry with
2508 * refresh rate information. StartModeTest starts the mode test,
2509 * EvaluateMode is used to fail or pass a mode. If EvaluateMode
2510 * isn't called within 15 seconds, the mode is failed automatically
2512 * As refresh rates are handled by the X server, I don't think this
2513 * Method is important
2516 * Modes: An array of mode specifications
2517 * NumModes: The number of modes in Modes
2518 * Flags: Some flags...
2521 * Returns DDERR_TESTFINISHED if flags contains DDSMT_ISTESTREQUIRED,
2522 * if no modes are passed, DDERR_INVALIDPARAMS is returned,
2525 *****************************************************************************/
2526 static HRESULT WINAPI
ddraw7_StartModeTest(IDirectDraw7
*iface
, SIZE
*Modes
, DWORD NumModes
, DWORD Flags
)
2528 FIXME("iface %p, modes %p, mode_count %u, flags %#x partial stub!\n",
2529 iface
, Modes
, NumModes
, Flags
);
2531 /* This looks sane */
2532 if( (!Modes
) || (NumModes
== 0) ) return DDERR_INVALIDPARAMS
;
2534 /* DDSMT_ISTESTREQUIRED asks if a mode test is necessary.
2535 * As it is not, DDERR_TESTFINISHED is returned
2536 * (hopefully that's correct
2538 if(Flags & DDSMT_ISTESTREQUIRED) return DDERR_TESTFINISHED;
2539 * well, that value doesn't (yet) exist in the wine headers, so ignore it
2545 /*****************************************************************************
2546 * ddraw_create_surface
2548 * A helper function for IDirectDraw7::CreateSurface. It creates a new surface
2549 * with the passed parameters.
2552 * DDSD: Description of the surface to create
2553 * Surf: Address to store the interface pointer at
2558 *****************************************************************************/
2559 static HRESULT
ddraw_create_surface(struct ddraw
*ddraw
, DDSURFACEDESC2
*pDDSD
,
2560 struct ddraw_surface
**surface
, UINT level
, UINT version
)
2564 TRACE("ddraw %p, surface_desc %p, surface %p, level %u.\n",
2565 ddraw
, pDDSD
, surface
, level
);
2567 if (TRACE_ON(ddraw
))
2569 TRACE("Requesting surface desc:\n");
2570 DDRAW_dump_surface_desc(pDDSD
);
2573 if ((pDDSD
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
) && DefaultSurfaceType
!= WINED3D_SURFACE_TYPE_OPENGL
)
2575 WARN("The application requests a 3D capable surface, but a non-OpenGL surface type was set in the registry.\n");
2576 /* Do not fail surface creation, only fail 3D device creation. */
2579 /* Create the Surface object */
2580 *surface
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(**surface
));
2583 ERR("Failed to allocate surface memory.\n");
2584 return DDERR_OUTOFVIDEOMEMORY
;
2587 hr
= ddraw_surface_init(*surface
, ddraw
, pDDSD
, level
, version
);
2590 WARN("Failed to initialize surface, hr %#x.\n", hr
);
2591 HeapFree(GetProcessHeap(), 0, *surface
);
2595 /* Increase the surface counter, and attach the surface */
2596 list_add_head(&ddraw
->surface_list
, &(*surface
)->surface_list_entry
);
2598 TRACE("Created surface %p.\n", *surface
);
2603 static HRESULT CDECL
ddraw_reset_enum_callback(struct wined3d_resource
*resource
)
2608 /*****************************************************************************
2609 * IDirectDraw7::CreateSurface
2611 * Creates a new IDirectDrawSurface object and returns its interface.
2613 * The surface connections with wined3d are a bit tricky. Basically it works
2616 * |------------------------| |-----------------|
2617 * | DDraw surface | | WineD3DSurface |
2619 * | WineD3DSurface |-------------->| |
2620 * | Child |<------------->| Parent |
2621 * |------------------------| |-----------------|
2623 * The DDraw surface is the parent of the wined3d surface, and it releases
2624 * the WineD3DSurface when the ddraw surface is destroyed.
2626 * However, for all surfaces which can be in a container in WineD3D,
2627 * we have to do this. These surfaces are usually complex surfaces,
2628 * so this concerns primary surfaces with a front and a back buffer,
2631 * |------------------------| |-----------------|
2632 * | DDraw surface | | Container |
2634 * | Child |<------------->| Parent |
2635 * | Texture |<------------->| |
2636 * | WineD3DSurface |<----| | Levels |<--|
2637 * | Complex connection | | | | |
2638 * |------------------------| | |-----------------| |
2642 * | |------------------| | |-----------------| |
2643 * | | IParent | |-------->| WineD3DSurface | |
2645 * | | Child |<------------->| Parent | |
2646 * | | | | Container |<--|
2647 * | |------------------| |-----------------| |
2649 * | |----------------------| |
2650 * | | DDraw surface 2 | |
2652 * |<->| Complex root Child | |
2654 * | | WineD3DSurface |<----| |
2655 * | |----------------------| | |
2657 * | |---------------------| | |-----------------| |
2658 * | | IParent | |----->| WineD3DSurface | |
2660 * | | Child |<---------->| Parent | |
2661 * | |---------------------| | Container |<--|
2662 * | |-----------------| |
2664 * | ---More surfaces can follow--- |
2666 * The reason is that the IWineD3DSwapchain(render target container)
2667 * and the IWineD3DTexure(Texture container) release the parents
2668 * of their surface's children, but by releasing the complex root
2669 * the surfaces which are complexly attached to it are destroyed
2670 * too. See IDirectDrawSurface::Release for a more detailed
2674 * DDSD: Description of the surface to create
2675 * Surf: Address to store the interface pointer at
2676 * UnkOuter: Basically for aggregation support, but ddraw doesn't support
2677 * aggregation, so it has to be NULL
2681 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
2682 * DDERR_* if an error occurs
2684 *****************************************************************************/
2685 static HRESULT
CreateSurface(struct ddraw
*ddraw
, DDSURFACEDESC2
*DDSD
,
2686 struct ddraw_surface
**surface
, IUnknown
*UnkOuter
, UINT version
)
2688 struct ddraw_surface
*object
= NULL
;
2689 struct wined3d_display_mode mode
;
2691 DDSURFACEDESC2 desc2
;
2692 const DWORD sysvidmem
= DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
2694 TRACE("ddraw %p, surface_desc %p, surface %p, outer_unknown %p.\n", ddraw
, DDSD
, surface
, UnkOuter
);
2696 /* Some checks before we start */
2697 if (TRACE_ON(ddraw
))
2699 TRACE(" (%p) Requesting surface desc :\n", ddraw
);
2700 DDRAW_dump_surface_desc(DDSD
);
2703 if (UnkOuter
!= NULL
)
2705 FIXME("(%p) : outer != NULL?\n", ddraw
);
2706 return CLASS_E_NOAGGREGATION
; /* unchecked */
2711 FIXME("(%p) You want to get back a surface? Don't give NULL ptrs!\n", ddraw
);
2712 return E_POINTER
; /* unchecked */
2715 if (!(DDSD
->dwFlags
& DDSD_CAPS
))
2717 /* DVIDEO.DLL does forget the DDSD_CAPS flag ... *sigh* */
2718 DDSD
->dwFlags
|= DDSD_CAPS
;
2721 if (DDSD
->ddsCaps
.dwCaps
& DDSCAPS_ALLOCONLOAD
)
2723 /* If the surface is of the 'alloconload' type, ignore the LPSURFACE field */
2724 DDSD
->dwFlags
&= ~DDSD_LPSURFACE
;
2727 if ((DDSD
->dwFlags
& DDSD_LPSURFACE
) && (DDSD
->lpSurface
== NULL
))
2729 /* Frank Herbert's Dune specifies a null pointer for the surface, ignore the LPSURFACE field */
2730 WARN("(%p) Null surface pointer specified, ignore it!\n", ddraw
);
2731 DDSD
->dwFlags
&= ~DDSD_LPSURFACE
;
2734 if((DDSD
->ddsCaps
.dwCaps
& (DDSCAPS_FLIP
| DDSCAPS_PRIMARYSURFACE
)) == (DDSCAPS_FLIP
| DDSCAPS_PRIMARYSURFACE
) &&
2735 !(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
))
2737 TRACE("(%p): Attempt to create a flipable primary surface without DDSCL_EXCLUSIVE set\n",
2740 return DDERR_NOEXCLUSIVEMODE
;
2743 if((DDSD
->ddsCaps
.dwCaps
& (DDSCAPS_BACKBUFFER
| DDSCAPS_PRIMARYSURFACE
)) == (DDSCAPS_BACKBUFFER
| DDSCAPS_PRIMARYSURFACE
))
2745 WARN("Application wanted to create back buffer primary surface\n");
2746 return DDERR_INVALIDCAPS
;
2749 if((DDSD
->ddsCaps
.dwCaps
& sysvidmem
) == sysvidmem
)
2751 /* This is a special switch in ddrawex.dll, but not allowed in ddraw.dll */
2752 WARN("Application tries to put the surface in both system and video memory\n");
2754 return DDERR_INVALIDCAPS
;
2757 /* Check cube maps but only if the size includes them */
2758 if (DDSD
->dwSize
>= sizeof(DDSURFACEDESC2
))
2760 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
&&
2761 !(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
))
2763 WARN("Cube map faces requested without cube map flag\n");
2764 return DDERR_INVALIDCAPS
;
2766 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
&&
2767 (DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
) == 0)
2769 WARN("Cube map without faces requested\n");
2770 return DDERR_INVALIDPARAMS
;
2773 /* Quick tests confirm those can be created, but we don't do that yet */
2774 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
&&
2775 (DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
) != DDSCAPS2_CUBEMAP_ALLFACES
)
2777 FIXME("Partial cube maps not supported yet\n");
2781 /* According to the msdn this flag is ignored by CreateSurface */
2782 if (DDSD
->dwSize
>= sizeof(DDSURFACEDESC2
))
2783 DDSD
->ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
2785 /* Modify some flags */
2786 copy_to_surfacedesc2(&desc2
, DDSD
);
2787 desc2
.u4
.ddpfPixelFormat
.dwSize
=sizeof(DDPIXELFORMAT
); /* Just to be sure */
2789 /* Get the video mode from WineD3D - we will need it */
2790 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
2792 ERR("Failed to get display mode, hr %#x.\n", hr
);
2794 switch (ddraw
->orig_bpp
)
2797 mode
.format_id
= WINED3DFMT_P8_UINT
;
2801 mode
.format_id
= WINED3DFMT_B5G5R5X1_UNORM
;
2805 mode
.format_id
= WINED3DFMT_B5G6R5_UNORM
;
2809 mode
.format_id
= WINED3DFMT_B8G8R8_UNORM
;
2813 mode
.format_id
= WINED3DFMT_B8G8R8X8_UNORM
;
2816 mode
.width
= ddraw
->orig_width
;
2817 mode
.height
= ddraw
->orig_height
;
2820 /* No pixelformat given? Use the current screen format */
2821 if(!(desc2
.dwFlags
& DDSD_PIXELFORMAT
))
2823 desc2
.dwFlags
|= DDSD_PIXELFORMAT
;
2824 desc2
.u4
.ddpfPixelFormat
.dwSize
=sizeof(DDPIXELFORMAT
);
2826 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, mode
.format_id
);
2829 /* No Width or no Height? Use the original screen size
2831 if(!(desc2
.dwFlags
& DDSD_WIDTH
) ||
2832 !(desc2
.dwFlags
& DDSD_HEIGHT
) )
2834 /* Invalid for non-render targets */
2835 if(!(desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
2837 WARN("Creating a non-Primary surface without Width or Height info, returning DDERR_INVALIDPARAMS\n");
2839 return DDERR_INVALIDPARAMS
;
2842 desc2
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
2843 desc2
.dwWidth
= mode
.width
;
2844 desc2
.dwHeight
= mode
.height
;
2847 if (!desc2
.dwWidth
|| !desc2
.dwHeight
)
2848 return DDERR_INVALIDPARAMS
;
2850 /* Mipmap count fixes */
2851 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
2853 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_COMPLEX
)
2855 if(desc2
.dwFlags
& DDSD_MIPMAPCOUNT
)
2857 /* Mipmap count is given, should not be 0 */
2858 if( desc2
.u2
.dwMipMapCount
== 0 )
2859 return DDERR_INVALIDPARAMS
;
2863 /* Undocumented feature: Create sublevels until
2864 * either the width or the height is 1
2866 DWORD min
= desc2
.dwWidth
< desc2
.dwHeight
?
2867 desc2
.dwWidth
: desc2
.dwHeight
;
2868 desc2
.u2
.dwMipMapCount
= 0;
2871 desc2
.u2
.dwMipMapCount
+= 1;
2878 /* Not-complex mipmap -> Mipmapcount = 1 */
2879 desc2
.u2
.dwMipMapCount
= 1;
2882 /* There's a mipmap count in the created surface in any case */
2883 desc2
.dwFlags
|= DDSD_MIPMAPCOUNT
;
2885 /* If no mipmap is given, the texture has only one level */
2887 /* The first surface is a front buffer, the back buffer is created afterwards */
2888 if( (desc2
.dwFlags
& DDSD_CAPS
) && (desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) )
2890 desc2
.ddsCaps
.dwCaps
|= DDSCAPS_FRONTBUFFER
;
2893 /* The root surface in a cube map is positive x */
2894 if(desc2
.ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
2896 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
2897 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
2900 if ((desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) && (ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
))
2902 struct wined3d_swapchain_desc swapchain_desc
;
2904 hr
= wined3d_swapchain_get_desc(ddraw
->wined3d_swapchain
, &swapchain_desc
);
2907 ERR("Failed to get present parameters.\n");
2911 swapchain_desc
.backbuffer_width
= mode
.width
;
2912 swapchain_desc
.backbuffer_height
= mode
.height
;
2913 swapchain_desc
.backbuffer_format
= mode
.format_id
;
2915 hr
= wined3d_device_reset(ddraw
->wined3d_device
,
2916 &swapchain_desc
, NULL
, ddraw_reset_enum_callback
);
2919 ERR("Failed to reset device.\n");
2924 /* Create the first surface */
2925 hr
= ddraw_create_surface(ddraw
, &desc2
, &object
, 0, version
);
2928 WARN("ddraw_create_surface failed, hr %#x.\n", hr
);
2931 object
->is_complex_root
= TRUE
;
2935 /* Create Additional surfaces if necessary
2936 * This applies to Primary surfaces which have a back buffer count
2937 * set, but not to mipmap textures. In case of Mipmap textures,
2938 * wineD3D takes care of the creation of additional surfaces
2940 if(DDSD
->dwFlags
& DDSD_BACKBUFFERCOUNT
)
2942 struct ddraw_surface
*last
= object
;
2945 desc2
.ddsCaps
.dwCaps
&= ~DDSCAPS_FRONTBUFFER
; /* It's not a front buffer */
2946 desc2
.ddsCaps
.dwCaps
|= DDSCAPS_BACKBUFFER
;
2947 desc2
.dwBackBufferCount
= 0;
2949 for (i
= 0; i
< DDSD
->dwBackBufferCount
; ++i
)
2951 struct ddraw_surface
*object2
= NULL
;
2953 if (FAILED(hr
= ddraw_create_surface(ddraw
, &desc2
, &object2
, 0, version
)))
2956 IDirectDrawSurface7_Release(&object
->IDirectDrawSurface7_iface
);
2957 else if (version
== 4)
2958 IDirectDrawSurface4_Release(&object
->IDirectDrawSurface4_iface
);
2960 IDirectDrawSurface_Release(&object
->IDirectDrawSurface_iface
);
2965 /* Add the new surface to the complex attachment array. */
2966 last
->complex_array
[0] = object2
;
2969 /* Remove the (possible) back buffer cap from the new surface
2970 * description, because only one surface in the flipping chain is a
2971 * back buffer, one is a front buffer, the others are just primary
2973 desc2
.ddsCaps
.dwCaps
&= ~DDSCAPS_BACKBUFFER
;
2977 if (desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
2978 ddraw
->primary
= object
;
2980 /* Create a WineD3DTexture if a texture was requested */
2981 if (desc2
.ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
2982 ddraw_surface_create_texture(object
);
2987 static HRESULT WINAPI
ddraw7_CreateSurface(IDirectDraw7
*iface
, DDSURFACEDESC2
*surface_desc
,
2988 IDirectDrawSurface7
**surface
, IUnknown
*outer_unknown
)
2990 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2991 struct ddraw_surface
*impl
;
2994 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2995 iface
, surface_desc
, surface
, outer_unknown
);
2997 wined3d_mutex_lock();
2999 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
3001 WARN("Cooperative level not set.\n");
3002 wined3d_mutex_unlock();
3003 return DDERR_NOCOOPERATIVELEVELSET
;
3006 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
3008 WARN("Application supplied invalid surface descriptor\n");
3009 wined3d_mutex_unlock();
3010 return DDERR_INVALIDPARAMS
;
3013 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
3015 if (TRACE_ON(ddraw
))
3017 TRACE(" (%p) Requesting surface desc :\n", iface
);
3018 DDRAW_dump_surface_desc(surface_desc
);
3021 WARN("Application tried to create an explicit front or back buffer\n");
3022 wined3d_mutex_unlock();
3023 return DDERR_INVALIDCAPS
;
3026 hr
= CreateSurface(ddraw
, surface_desc
, &impl
, outer_unknown
, 7);
3027 wined3d_mutex_unlock();
3034 *surface
= &impl
->IDirectDrawSurface7_iface
;
3035 IDirectDraw7_AddRef(iface
);
3036 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3041 static HRESULT WINAPI
ddraw4_CreateSurface(IDirectDraw4
*iface
,
3042 DDSURFACEDESC2
*surface_desc
, IDirectDrawSurface4
**surface
, IUnknown
*outer_unknown
)
3044 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3045 struct ddraw_surface
*impl
;
3048 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3049 iface
, surface_desc
, surface
, outer_unknown
);
3051 wined3d_mutex_lock();
3053 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
3055 WARN("Cooperative level not set.\n");
3056 wined3d_mutex_unlock();
3057 return DDERR_NOCOOPERATIVELEVELSET
;
3060 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
3062 WARN("Application supplied invalid surface descriptor\n");
3063 wined3d_mutex_unlock();
3064 return DDERR_INVALIDPARAMS
;
3067 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
3069 if (TRACE_ON(ddraw
))
3071 TRACE(" (%p) Requesting surface desc :\n", iface
);
3072 DDRAW_dump_surface_desc(surface_desc
);
3075 WARN("Application tried to create an explicit front or back buffer\n");
3076 wined3d_mutex_unlock();
3077 return DDERR_INVALIDCAPS
;
3080 hr
= CreateSurface(ddraw
, surface_desc
, &impl
, outer_unknown
, 4);
3081 wined3d_mutex_unlock();
3088 *surface
= &impl
->IDirectDrawSurface4_iface
;
3089 IDirectDraw4_AddRef(iface
);
3090 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3095 static HRESULT WINAPI
ddraw2_CreateSurface(IDirectDraw2
*iface
,
3096 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
3098 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3099 struct ddraw_surface
*impl
;
3101 DDSURFACEDESC2 surface_desc2
;
3103 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3104 iface
, surface_desc
, surface
, outer_unknown
);
3106 wined3d_mutex_lock();
3108 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
3110 WARN("Cooperative level not set.\n");
3111 wined3d_mutex_unlock();
3112 return DDERR_NOCOOPERATIVELEVELSET
;
3115 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3117 WARN("Application supplied invalid surface descriptor\n");
3118 wined3d_mutex_unlock();
3119 return DDERR_INVALIDPARAMS
;
3122 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3123 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
3125 if (TRACE_ON(ddraw
))
3127 TRACE(" (%p) Requesting surface desc :\n", iface
);
3128 DDRAW_dump_surface_desc((LPDDSURFACEDESC2
)surface_desc
);
3131 WARN("Application tried to create an explicit front or back buffer\n");
3132 wined3d_mutex_unlock();
3133 return DDERR_INVALIDCAPS
;
3136 hr
= CreateSurface(ddraw
, &surface_desc2
, &impl
, outer_unknown
, 2);
3137 wined3d_mutex_unlock();
3144 *surface
= &impl
->IDirectDrawSurface_iface
;
3145 impl
->ifaceToRelease
= NULL
;
3150 static HRESULT WINAPI
ddraw1_CreateSurface(IDirectDraw
*iface
,
3151 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
3153 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3154 struct ddraw_surface
*impl
;
3156 DDSURFACEDESC2 surface_desc2
;
3158 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3159 iface
, surface_desc
, surface
, outer_unknown
);
3161 wined3d_mutex_lock();
3163 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
3165 WARN("Cooperative level not set.\n");
3166 wined3d_mutex_unlock();
3167 return DDERR_NOCOOPERATIVELEVELSET
;
3170 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3172 WARN("Application supplied invalid surface descriptor\n");
3173 wined3d_mutex_unlock();
3174 return DDERR_INVALIDPARAMS
;
3177 /* Remove front buffer flag, this causes failure in v7, and its added to normal
3178 * primaries anyway. */
3179 surface_desc
->ddsCaps
.dwCaps
&= ~DDSCAPS_FRONTBUFFER
;
3180 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3181 hr
= CreateSurface(ddraw
, &surface_desc2
, &impl
, outer_unknown
, 1);
3182 wined3d_mutex_unlock();
3189 *surface
= &impl
->IDirectDrawSurface_iface
;
3190 impl
->ifaceToRelease
= NULL
;
3195 #define DDENUMSURFACES_SEARCHTYPE (DDENUMSURFACES_CANBECREATED|DDENUMSURFACES_DOESEXIST)
3196 #define DDENUMSURFACES_MATCHTYPE (DDENUMSURFACES_ALL|DDENUMSURFACES_MATCH|DDENUMSURFACES_NOMATCH)
3199 Main_DirectDraw_DDPIXELFORMAT_Match(const DDPIXELFORMAT
*requested
,
3200 const DDPIXELFORMAT
*provided
)
3202 /* Some flags must be present in both or neither for a match. */
3203 static const DWORD must_match
= DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
3204 | DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_FOURCC
3205 | DDPF_ZBUFFER
| DDPF_STENCILBUFFER
;
3207 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3210 if ((requested
->dwFlags
& must_match
) != (provided
->dwFlags
& must_match
))
3213 if (requested
->dwFlags
& DDPF_FOURCC
)
3214 if (requested
->dwFourCC
!= provided
->dwFourCC
)
3217 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_ALPHA
3218 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
3219 if (requested
->u1
.dwRGBBitCount
!= provided
->u1
.dwRGBBitCount
)
3222 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3223 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
3224 if (requested
->u2
.dwRBitMask
!= provided
->u2
.dwRBitMask
)
3227 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_BUMPDUDV
))
3228 if (requested
->u3
.dwGBitMask
!= provided
->u3
.dwGBitMask
)
3231 /* I could be wrong about the bumpmapping. MSDN docs are vague. */
3232 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3234 if (requested
->u4
.dwBBitMask
!= provided
->u4
.dwBBitMask
)
3237 if (requested
->dwFlags
& (DDPF_ALPHAPIXELS
|DDPF_ZPIXELS
))
3238 if (requested
->u5
.dwRGBAlphaBitMask
!= provided
->u5
.dwRGBAlphaBitMask
)
3244 static BOOL
ddraw_match_surface_desc(const DDSURFACEDESC2
*requested
, const DDSURFACEDESC2
*provided
)
3253 #define CMP(FLAG, FIELD) \
3254 { DDSD_##FLAG, offsetof(DDSURFACEDESC2, FIELD), \
3255 sizeof(((DDSURFACEDESC2 *)(NULL))->FIELD) }
3257 static const struct compare_info compare
[] =
3259 CMP(ALPHABITDEPTH
, dwAlphaBitDepth
),
3260 CMP(BACKBUFFERCOUNT
, dwBackBufferCount
),
3262 CMP(CKDESTBLT
, ddckCKDestBlt
),
3263 CMP(CKDESTOVERLAY
, u3
/* ddckCKDestOverlay */),
3264 CMP(CKSRCBLT
, ddckCKSrcBlt
),
3265 CMP(CKSRCOVERLAY
, ddckCKSrcOverlay
),
3266 CMP(HEIGHT
, dwHeight
),
3267 CMP(LINEARSIZE
, u1
/* dwLinearSize */),
3268 CMP(LPSURFACE
, lpSurface
),
3269 CMP(MIPMAPCOUNT
, u2
/* dwMipMapCount */),
3270 CMP(PITCH
, u1
/* lPitch */),
3271 /* PIXELFORMAT: manual */
3272 CMP(REFRESHRATE
, u2
/* dwRefreshRate */),
3273 CMP(TEXTURESTAGE
, dwTextureStage
),
3274 CMP(WIDTH
, dwWidth
),
3275 /* ZBUFFERBITDEPTH: "obsolete" */
3282 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3285 for (i
=0; i
< sizeof(compare
)/sizeof(compare
[0]); i
++)
3287 if (requested
->dwFlags
& compare
[i
].flag
3288 && memcmp((const char *)provided
+ compare
[i
].offset
,
3289 (const char *)requested
+ compare
[i
].offset
,
3290 compare
[i
].size
) != 0)
3294 if (requested
->dwFlags
& DDSD_PIXELFORMAT
)
3296 if (!Main_DirectDraw_DDPIXELFORMAT_Match(&requested
->u4
.ddpfPixelFormat
,
3297 &provided
->u4
.ddpfPixelFormat
))
3304 #undef DDENUMSURFACES_SEARCHTYPE
3305 #undef DDENUMSURFACES_MATCHTYPE
3307 struct surfacescallback2_context
3309 LPDDENUMSURFACESCALLBACK2 func
;
3313 struct surfacescallback_context
3315 LPDDENUMSURFACESCALLBACK func
;
3319 static HRESULT CALLBACK
EnumSurfacesCallback2Thunk(IDirectDrawSurface7
*surface
,
3320 DDSURFACEDESC2
*surface_desc
, void *context
)
3322 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3323 struct surfacescallback2_context
*cbcontext
= context
;
3325 IDirectDrawSurface4_AddRef(&surface_impl
->IDirectDrawSurface4_iface
);
3326 IDirectDrawSurface7_Release(surface
);
3328 return cbcontext
->func(&surface_impl
->IDirectDrawSurface4_iface
,
3329 surface_desc
, cbcontext
->context
);
3332 static HRESULT CALLBACK
EnumSurfacesCallbackThunk(IDirectDrawSurface7
*surface
,
3333 DDSURFACEDESC2
*surface_desc
, void *context
)
3335 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3336 struct surfacescallback_context
*cbcontext
= context
;
3338 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
3339 IDirectDrawSurface7_Release(surface
);
3341 return cbcontext
->func(&surface_impl
->IDirectDrawSurface_iface
,
3342 (DDSURFACEDESC
*)surface_desc
, cbcontext
->context
);
3345 /*****************************************************************************
3346 * IDirectDraw7::EnumSurfaces
3348 * Loops through all surfaces attached to this device and calls the
3349 * application callback. This can't be relayed to WineD3DDevice,
3350 * because some WineD3DSurfaces' parents are IParent objects
3353 * Flags: Some filtering flags. See IDirectDrawImpl_EnumSurfacesCallback
3354 * DDSD: Description to filter for
3355 * Context: Application-provided pointer, it's passed unmodified to the
3357 * Callback: Address to call for each surface
3360 * DDERR_INVALIDPARAMS if the callback is NULL
3363 *****************************************************************************/
3364 static HRESULT WINAPI
ddraw7_EnumSurfaces(IDirectDraw7
*iface
, DWORD Flags
,
3365 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMSURFACESCALLBACK7 Callback
)
3367 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
3368 struct ddraw_surface
*surf
;
3370 DDSURFACEDESC2 desc
;
3371 struct list
*entry
, *entry2
;
3373 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3374 iface
, Flags
, DDSD
, Context
, Callback
);
3376 all
= Flags
& DDENUMSURFACES_ALL
;
3377 nomatch
= Flags
& DDENUMSURFACES_NOMATCH
;
3380 return DDERR_INVALIDPARAMS
;
3382 wined3d_mutex_lock();
3384 /* Use the _SAFE enumeration, the app may destroy enumerated surfaces */
3385 LIST_FOR_EACH_SAFE(entry
, entry2
, &ddraw
->surface_list
)
3387 surf
= LIST_ENTRY(entry
, struct ddraw_surface
, surface_list_entry
);
3389 if (!surf
->iface_count
)
3391 WARN("Not enumerating surface %p because it doesn't have any references.\n", surf
);
3395 if (all
|| (nomatch
!= ddraw_match_surface_desc(DDSD
, &surf
->surface_desc
)))
3397 TRACE("Enumerating surface %p.\n", surf
);
3398 desc
= surf
->surface_desc
;
3399 IDirectDrawSurface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
3400 if (Callback(&surf
->IDirectDrawSurface7_iface
, &desc
, Context
) != DDENUMRET_OK
)
3402 wined3d_mutex_unlock();
3408 wined3d_mutex_unlock();
3413 static HRESULT WINAPI
ddraw4_EnumSurfaces(IDirectDraw4
*iface
, DWORD flags
,
3414 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
3416 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3417 struct surfacescallback2_context cbcontext
;
3419 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3420 iface
, flags
, surface_desc
, context
, callback
);
3422 cbcontext
.func
= callback
;
3423 cbcontext
.context
= context
;
3425 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
, surface_desc
,
3426 &cbcontext
, EnumSurfacesCallback2Thunk
);
3429 static HRESULT WINAPI
ddraw2_EnumSurfaces(IDirectDraw2
*iface
, DWORD flags
,
3430 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3432 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3433 struct surfacescallback_context cbcontext
;
3434 DDSURFACEDESC2 surface_desc2
;
3436 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3437 iface
, flags
, surface_desc
, context
, callback
);
3439 cbcontext
.func
= callback
;
3440 cbcontext
.context
= context
;
3442 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3443 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
,
3444 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3447 static HRESULT WINAPI
ddraw1_EnumSurfaces(IDirectDraw
*iface
, DWORD flags
,
3448 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3450 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3451 struct surfacescallback_context cbcontext
;
3452 DDSURFACEDESC2 surface_desc2
;
3454 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3455 iface
, flags
, surface_desc
, context
, callback
);
3457 cbcontext
.func
= callback
;
3458 cbcontext
.context
= context
;
3460 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3461 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
,
3462 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3465 /*****************************************************************************
3466 * DirectDrawCreateClipper (DDRAW.@)
3468 * Creates a new IDirectDrawClipper object.
3471 * Clipper: Address to write the interface pointer to
3472 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3476 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3477 * E_OUTOFMEMORY if allocating the object failed
3479 *****************************************************************************/
3480 HRESULT WINAPI
DirectDrawCreateClipper(DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3482 struct ddraw_clipper
*object
;
3485 TRACE("flags %#x, clipper %p, outer_unknown %p.\n",
3486 flags
, clipper
, outer_unknown
);
3489 return CLASS_E_NOAGGREGATION
;
3491 wined3d_mutex_lock();
3493 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3496 wined3d_mutex_unlock();
3497 return E_OUTOFMEMORY
;
3500 hr
= ddraw_clipper_init(object
);
3503 WARN("Failed to initialize clipper, hr %#x.\n", hr
);
3504 HeapFree(GetProcessHeap(), 0, object
);
3505 wined3d_mutex_unlock();
3509 TRACE("Created clipper %p.\n", object
);
3510 *clipper
= &object
->IDirectDrawClipper_iface
;
3511 wined3d_mutex_unlock();
3516 /*****************************************************************************
3517 * IDirectDraw7::CreateClipper
3519 * Creates a DDraw clipper. See DirectDrawCreateClipper for details
3521 *****************************************************************************/
3522 static HRESULT WINAPI
ddraw7_CreateClipper(IDirectDraw7
*iface
, DWORD Flags
,
3523 IDirectDrawClipper
**Clipper
, IUnknown
*UnkOuter
)
3525 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3526 iface
, Flags
, Clipper
, UnkOuter
);
3528 return DirectDrawCreateClipper(Flags
, Clipper
, UnkOuter
);
3531 static HRESULT WINAPI
ddraw4_CreateClipper(IDirectDraw4
*iface
, DWORD flags
,
3532 IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3534 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3536 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3537 iface
, flags
, clipper
, outer_unknown
);
3539 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3542 static HRESULT WINAPI
ddraw2_CreateClipper(IDirectDraw2
*iface
,
3543 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3545 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3547 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3548 iface
, flags
, clipper
, outer_unknown
);
3550 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3553 static HRESULT WINAPI
ddraw1_CreateClipper(IDirectDraw
*iface
,
3554 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3556 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3558 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3559 iface
, flags
, clipper
, outer_unknown
);
3561 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3564 /*****************************************************************************
3565 * IDirectDraw7::CreatePalette
3567 * Creates a new IDirectDrawPalette object
3570 * Flags: The flags for the new clipper
3571 * ColorTable: Color table to assign to the new clipper
3572 * Palette: Address to write the interface pointer to
3573 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3577 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3578 * E_OUTOFMEMORY if allocating the object failed
3580 *****************************************************************************/
3581 static HRESULT WINAPI
ddraw7_CreatePalette(IDirectDraw7
*iface
, DWORD Flags
,
3582 PALETTEENTRY
*ColorTable
, IDirectDrawPalette
**Palette
, IUnknown
*pUnkOuter
)
3584 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
3585 struct ddraw_palette
*object
;
3588 TRACE("iface %p, flags %#x, color_table %p, palette %p, outer_unknown %p.\n",
3589 iface
, Flags
, ColorTable
, Palette
, pUnkOuter
);
3592 return CLASS_E_NOAGGREGATION
;
3594 wined3d_mutex_lock();
3596 /* The refcount test shows that a cooplevel is required for this */
3597 if (!ddraw
->cooperative_level
)
3599 WARN("No cooperative level set, returning DDERR_NOCOOPERATIVELEVELSET\n");
3600 wined3d_mutex_unlock();
3601 return DDERR_NOCOOPERATIVELEVELSET
;
3604 object
= HeapAlloc(GetProcessHeap(), 0, sizeof(*object
));
3607 ERR("Out of memory when allocating memory for a palette implementation\n");
3608 wined3d_mutex_unlock();
3609 return E_OUTOFMEMORY
;
3612 hr
= ddraw_palette_init(object
, ddraw
, Flags
, ColorTable
);
3615 WARN("Failed to initialize palette, hr %#x.\n", hr
);
3616 HeapFree(GetProcessHeap(), 0, object
);
3617 wined3d_mutex_unlock();
3621 TRACE("Created palette %p.\n", object
);
3622 *Palette
= &object
->IDirectDrawPalette_iface
;
3623 wined3d_mutex_unlock();
3628 static HRESULT WINAPI
ddraw4_CreatePalette(IDirectDraw4
*iface
, DWORD flags
, PALETTEENTRY
*entries
,
3629 IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3631 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3634 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3635 iface
, flags
, entries
, palette
, outer_unknown
);
3637 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3638 if (SUCCEEDED(hr
) && *palette
)
3640 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3641 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3642 IDirectDraw4_AddRef(iface
);
3643 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3648 static HRESULT WINAPI
ddraw2_CreatePalette(IDirectDraw2
*iface
, DWORD flags
,
3649 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3651 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3654 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3655 iface
, flags
, entries
, palette
, outer_unknown
);
3657 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3658 if (SUCCEEDED(hr
) && *palette
)
3660 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3661 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3662 impl
->ifaceToRelease
= NULL
;
3668 static HRESULT WINAPI
ddraw1_CreatePalette(IDirectDraw
*iface
, DWORD flags
,
3669 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3671 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3674 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3675 iface
, flags
, entries
, palette
, outer_unknown
);
3677 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3678 if (SUCCEEDED(hr
) && *palette
)
3680 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3681 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3682 impl
->ifaceToRelease
= NULL
;
3688 /*****************************************************************************
3689 * IDirectDraw7::DuplicateSurface
3691 * Duplicates a surface. The surface memory points to the same memory as
3692 * the original surface, and it's released when the last surface referencing
3693 * it is released. I guess that's beyond Wine's surface management right now
3694 * (Idea: create a new DDraw surface with the same WineD3DSurface. I need a
3695 * test application to implement this)
3698 * Src: Address of the source surface
3699 * Dest: Address to write the new surface pointer to
3702 * See IDirectDraw7::CreateSurface
3704 *****************************************************************************/
3705 static HRESULT WINAPI
ddraw7_DuplicateSurface(IDirectDraw7
*iface
,
3706 IDirectDrawSurface7
*Src
, IDirectDrawSurface7
**Dest
)
3708 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirectDrawSurface7(Src
);
3710 FIXME("iface %p, src %p, dst %p partial stub!\n", iface
, Src
, Dest
);
3712 /* For now, simply create a new, independent surface */
3713 return IDirectDraw7_CreateSurface(iface
, &src_surface
->surface_desc
, Dest
, NULL
);
3716 static HRESULT WINAPI
ddraw4_DuplicateSurface(IDirectDraw4
*iface
, IDirectDrawSurface4
*src
,
3717 IDirectDrawSurface4
**dst
)
3719 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src
);
3720 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3721 struct ddraw_surface
*dst_impl
;
3722 IDirectDrawSurface7
*dst7
;
3725 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3727 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3728 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3734 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3735 *dst
= &dst_impl
->IDirectDrawSurface4_iface
;
3736 IDirectDrawSurface4_AddRef(*dst
);
3737 IDirectDrawSurface7_Release(dst7
);
3742 static HRESULT WINAPI
ddraw2_DuplicateSurface(IDirectDraw2
*iface
,
3743 IDirectDrawSurface
*src
, IDirectDrawSurface
**dst
)
3745 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3746 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3747 struct ddraw_surface
*dst_impl
;
3748 IDirectDrawSurface7
*dst7
;
3751 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3753 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3754 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3757 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3758 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3759 IDirectDrawSurface_AddRef(*dst
);
3760 IDirectDrawSurface7_Release(dst7
);
3765 static HRESULT WINAPI
ddraw1_DuplicateSurface(IDirectDraw
*iface
, IDirectDrawSurface
*src
,
3766 IDirectDrawSurface
**dst
)
3768 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3769 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3770 struct ddraw_surface
*dst_impl
;
3771 IDirectDrawSurface7
*dst7
;
3774 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3776 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3777 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3780 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3781 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3782 IDirectDrawSurface_AddRef(*dst
);
3783 IDirectDrawSurface7_Release(dst7
);
3788 /*****************************************************************************
3789 * IDirect3D7::EnumDevices
3791 * The EnumDevices method for IDirect3D7. It enumerates all supported
3792 * D3D7 devices. Currently the T&L, HAL and RGB devices are enumerated.
3795 * callback: Function to call for each enumerated device
3796 * context: Pointer to pass back to the app
3799 * D3D_OK, or the return value of the GetCaps call
3801 *****************************************************************************/
3802 static HRESULT WINAPI
d3d7_EnumDevices(IDirect3D7
*iface
, LPD3DENUMDEVICESCALLBACK7 callback
, void *context
)
3804 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
3805 D3DDEVICEDESC7 device_desc7
;
3806 D3DDEVICEDESC device_desc1
;
3810 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3813 return DDERR_INVALIDPARAMS
;
3815 wined3d_mutex_lock();
3817 hr
= IDirect3DImpl_GetCaps(ddraw
->wined3d
, &device_desc1
, &device_desc7
);
3820 wined3d_mutex_unlock();
3824 for (i
= 0; i
< sizeof(device_list7
)/sizeof(device_list7
[0]); i
++)
3828 device_desc7
.deviceGUID
= *device_list7
[i
].device_guid
;
3829 ret
= callback(device_list7
[i
].interface_name
, device_list7
[i
].device_name
, &device_desc7
, context
);
3830 if (ret
!= DDENUMRET_OK
)
3832 TRACE("Application cancelled the enumeration.\n");
3833 wined3d_mutex_unlock();
3838 TRACE("End of enumeration.\n");
3840 wined3d_mutex_unlock();
3845 /*****************************************************************************
3846 * IDirect3D3::EnumDevices
3848 * Enumerates all supported Direct3DDevice interfaces. This is the
3849 * implementation for Direct3D 1 to Direc3D 3, Version 7 has its own.
3851 * Version 1, 2 and 3
3854 * callback: Application-provided routine to call for each enumerated device
3855 * Context: Pointer to pass to the callback
3858 * D3D_OK on success,
3859 * The result of IDirect3DImpl_GetCaps if it failed
3861 *****************************************************************************/
3862 static HRESULT WINAPI
d3d3_EnumDevices(IDirect3D3
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3864 static CHAR wined3d_description
[] = "Wine D3DDevice using WineD3D and OpenGL";
3866 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3867 D3DDEVICEDESC device_desc1
, hal_desc
, hel_desc
;
3868 D3DDEVICEDESC7 device_desc7
;
3871 /* Some games (Motoracer 2 demo) have the bad idea to modify the device
3872 * name string. Let's put the string in a sufficiently sized array in
3873 * writable memory. */
3874 char device_name
[50];
3875 strcpy(device_name
,"Direct3D HEL");
3877 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3880 return DDERR_INVALIDPARAMS
;
3882 wined3d_mutex_lock();
3884 hr
= IDirect3DImpl_GetCaps(ddraw
->wined3d
, &device_desc1
, &device_desc7
);
3887 wined3d_mutex_unlock();
3891 /* Do I have to enumerate the reference id? Note from old d3d7:
3892 * "It seems that enumerating the reference IID on Direct3D 1 games
3893 * (AvP / Motoracer2) breaks them". So do not enumerate this iid in V1
3895 * There's a registry key HKLM\Software\Microsoft\Direct3D\Drivers,
3896 * EnumReference which enables / disables enumerating the reference
3897 * rasterizer. It's a DWORD, 0 means disabled, 2 means enabled. The
3898 * enablerefrast.reg and disablerefrast.reg files in the DirectX 7.0 sdk
3899 * demo directory suggest this.
3901 * Some games(GTA 2) seem to use the second enumerated device, so I have
3902 * to enumerate at least 2 devices. So enumerate the reference device to
3905 * Other games (Rollcage) tell emulation and hal device apart by certain
3906 * flags. Rollcage expects D3DPTEXTURECAPS_POW2 to be set (yeah, it is a
3907 * limitation flag), and it refuses all devices that have the perspective
3908 * flag set. This way it refuses the emulation device, and HAL devices
3909 * never have POW2 unset in d3d7 on windows. */
3910 if (ddraw
->d3dversion
!= 1)
3912 static CHAR reference_description
[] = "RGB Direct3D emulation";
3914 TRACE("Enumerating WineD3D D3DDevice interface.\n");
3915 hal_desc
= device_desc1
;
3916 hel_desc
= device_desc1
;
3917 /* The rgb device has the pow2 flag set in the hel caps, but not in the hal caps. */
3918 hal_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3919 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3920 hal_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3921 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3922 /* RGB, RAMP and MMX devices have a HAL dcmColorModel of 0 */
3923 hal_desc
.dcmColorModel
= 0;
3925 hr
= callback((GUID
*)&IID_IDirect3DRGBDevice
, reference_description
,
3926 device_name
, &hal_desc
, &hel_desc
, context
);
3927 if (hr
!= D3DENUMRET_OK
)
3929 TRACE("Application cancelled the enumeration.\n");
3930 wined3d_mutex_unlock();
3935 strcpy(device_name
,"Direct3D HAL");
3937 TRACE("Enumerating HAL Direct3D device.\n");
3938 hal_desc
= device_desc1
;
3939 hel_desc
= device_desc1
;
3941 /* The hal device does not have the pow2 flag set in hel, but in hal. */
3942 hel_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3943 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3944 hel_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3945 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3946 /* HAL devices have a HEL dcmColorModel of 0 */
3947 hel_desc
.dcmColorModel
= 0;
3949 hr
= callback((GUID
*)&IID_IDirect3DHALDevice
, wined3d_description
,
3950 device_name
, &hal_desc
, &hel_desc
, context
);
3951 if (hr
!= D3DENUMRET_OK
)
3953 TRACE("Application cancelled the enumeration.\n");
3954 wined3d_mutex_unlock();
3958 TRACE("End of enumeration.\n");
3960 wined3d_mutex_unlock();
3965 static HRESULT WINAPI
d3d2_EnumDevices(IDirect3D2
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3967 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3969 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3971 return d3d3_EnumDevices(&ddraw
->IDirect3D3_iface
, callback
, context
);
3974 static HRESULT WINAPI
d3d1_EnumDevices(IDirect3D
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3976 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3978 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3980 return d3d3_EnumDevices(&ddraw
->IDirect3D3_iface
, callback
, context
);
3983 /*****************************************************************************
3984 * IDirect3D3::CreateLight
3986 * Creates an IDirect3DLight interface. This interface is used in
3987 * Direct3D3 or earlier for lighting. In Direct3D7 it has been replaced
3988 * by the DIRECT3DLIGHT7 structure. Wine's Direct3DLight implementation
3989 * uses the IDirect3DDevice7 interface with D3D7 lights.
3991 * Version 1, 2 and 3
3994 * light: Address to store the new interface pointer
3995 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
4000 * DDERR_OUTOFMEMORY if memory allocation failed
4001 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
4003 *****************************************************************************/
4004 static HRESULT WINAPI
d3d3_CreateLight(IDirect3D3
*iface
, IDirect3DLight
**light
,
4005 IUnknown
*outer_unknown
)
4007 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4008 struct d3d_light
*object
;
4010 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
4012 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4014 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
4017 ERR("Failed to allocate light memory.\n");
4018 return DDERR_OUTOFMEMORY
;
4021 d3d_light_init(object
, ddraw
);
4023 TRACE("Created light %p.\n", object
);
4024 *light
= &object
->IDirect3DLight_iface
;
4029 static HRESULT WINAPI
d3d2_CreateLight(IDirect3D2
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
4031 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4033 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
4035 return d3d3_CreateLight(&ddraw
->IDirect3D3_iface
, light
, outer_unknown
);
4038 static HRESULT WINAPI
d3d1_CreateLight(IDirect3D
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
4040 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4042 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
4044 return d3d3_CreateLight(&ddraw
->IDirect3D3_iface
, light
, outer_unknown
);
4047 /*****************************************************************************
4048 * IDirect3D3::CreateMaterial
4050 * Creates an IDirect3DMaterial interface. This interface is used by Direct3D3
4051 * and older versions. The IDirect3DMaterial implementation wraps its
4052 * functionality to IDirect3DDevice7::SetMaterial and friends.
4054 * Version 1, 2 and 3
4057 * material: Address to store the new interface's pointer to
4058 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
4063 * DDERR_OUTOFMEMORY if memory allocation failed
4064 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
4066 *****************************************************************************/
4067 static HRESULT WINAPI
d3d3_CreateMaterial(IDirect3D3
*iface
, IDirect3DMaterial3
**material
,
4068 IUnknown
*outer_unknown
)
4070 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4071 struct d3d_material
*object
;
4073 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4075 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4077 object
= d3d_material_create(ddraw
);
4080 ERR("Failed to allocate material memory.\n");
4081 return DDERR_OUTOFMEMORY
;
4084 TRACE("Created material %p.\n", object
);
4085 *material
= &object
->IDirect3DMaterial3_iface
;
4090 static HRESULT WINAPI
d3d2_CreateMaterial(IDirect3D2
*iface
, IDirect3DMaterial2
**material
,
4091 IUnknown
*outer_unknown
)
4093 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4094 struct d3d_material
*object
;
4096 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4098 object
= d3d_material_create(ddraw
);
4101 ERR("Failed to allocate material memory.\n");
4102 return DDERR_OUTOFMEMORY
;
4105 TRACE("Created material %p.\n", object
);
4106 *material
= &object
->IDirect3DMaterial2_iface
;
4111 static HRESULT WINAPI
d3d1_CreateMaterial(IDirect3D
*iface
, IDirect3DMaterial
**material
,
4112 IUnknown
*outer_unknown
)
4114 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4115 struct d3d_material
*object
;
4117 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4119 object
= d3d_material_create(ddraw
);
4122 ERR("Failed to allocate material memory.\n");
4123 return DDERR_OUTOFMEMORY
;
4126 TRACE("Created material %p.\n", object
);
4127 *material
= &object
->IDirect3DMaterial_iface
;
4132 /*****************************************************************************
4133 * IDirect3D3::CreateViewport
4135 * Creates an IDirect3DViewport interface. This interface is used
4136 * by Direct3D and earlier versions for Viewport management. In Direct3D7
4137 * it has been replaced by a viewport structure and
4138 * IDirect3DDevice7::*Viewport. Wine's IDirect3DViewport implementation
4139 * uses the IDirect3DDevice7 methods for its functionality
4142 * Viewport: Address to store the new interface pointer
4143 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
4148 * DDERR_OUTOFMEMORY if memory allocation failed
4149 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
4151 *****************************************************************************/
4152 static HRESULT WINAPI
d3d3_CreateViewport(IDirect3D3
*iface
, IDirect3DViewport3
**viewport
,
4153 IUnknown
*outer_unknown
)
4155 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4156 struct d3d_viewport
*object
;
4158 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4160 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4162 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
4165 ERR("Failed to allocate viewport memory.\n");
4166 return DDERR_OUTOFMEMORY
;
4169 d3d_viewport_init(object
, ddraw
);
4171 TRACE("Created viewport %p.\n", object
);
4172 *viewport
= &object
->IDirect3DViewport3_iface
;
4177 static HRESULT WINAPI
d3d2_CreateViewport(IDirect3D2
*iface
, IDirect3DViewport2
**viewport
, IUnknown
*outer_unknown
)
4179 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4181 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4183 return d3d3_CreateViewport(&ddraw
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
4187 static HRESULT WINAPI
d3d1_CreateViewport(IDirect3D
*iface
, IDirect3DViewport
**viewport
, IUnknown
*outer_unknown
)
4189 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4191 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4193 return d3d3_CreateViewport(&ddraw
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
4197 /*****************************************************************************
4198 * IDirect3D3::FindDevice
4200 * This method finds a device with the requested properties and returns a
4201 * device description
4205 * fds: Describes the requested device characteristics
4206 * fdr: Returns the device description
4210 * DDERR_INVALIDPARAMS if no device was found
4212 *****************************************************************************/
4213 static HRESULT WINAPI
d3d3_FindDevice(IDirect3D3
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4215 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4216 D3DDEVICEDESC7 desc7
;
4217 D3DDEVICEDESC desc1
;
4220 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4222 if (!fds
|| !fdr
) return DDERR_INVALIDPARAMS
;
4224 if (fds
->dwSize
!= sizeof(D3DFINDDEVICESEARCH
)
4225 || fdr
->dwSize
!= sizeof(D3DFINDDEVICERESULT
))
4226 return DDERR_INVALIDPARAMS
;
4228 if ((fds
->dwFlags
& D3DFDS_COLORMODEL
)
4229 && fds
->dcmColorModel
!= D3DCOLOR_RGB
)
4231 WARN("Trying to request a non-RGB D3D color model. Not supported.\n");
4232 return DDERR_INVALIDPARAMS
; /* No real idea what to return here :-) */
4235 if (fds
->dwFlags
& D3DFDS_GUID
)
4237 TRACE("Trying to match guid %s.\n", debugstr_guid(&(fds
->guid
)));
4238 if (!IsEqualGUID(&IID_D3DDEVICE_WineD3D
, &fds
->guid
)
4239 && !IsEqualGUID(&IID_IDirect3DHALDevice
, &fds
->guid
)
4240 && !IsEqualGUID(&IID_IDirect3DRGBDevice
, &fds
->guid
))
4242 WARN("No match for this GUID.\n");
4243 return DDERR_NOTFOUND
;
4248 hr
= IDirect3DImpl_GetCaps(ddraw
->wined3d
, &desc1
, &desc7
);
4249 if (hr
!= D3D_OK
) return hr
;
4251 /* Now return our own GUID */
4252 fdr
->guid
= IID_D3DDEVICE_WineD3D
;
4253 fdr
->ddHwDesc
= desc1
;
4254 fdr
->ddSwDesc
= desc1
;
4256 TRACE("Returning Wine's wined3d device with (undumped) capabilities.\n");
4261 static HRESULT WINAPI
d3d2_FindDevice(IDirect3D2
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4263 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4265 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4267 return d3d3_FindDevice(&ddraw
->IDirect3D3_iface
, fds
, fdr
);
4270 static HRESULT WINAPI
d3d1_FindDevice(IDirect3D
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4272 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4274 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4276 return d3d3_FindDevice(&ddraw
->IDirect3D3_iface
, fds
, fdr
);
4279 /*****************************************************************************
4280 * IDirect3D7::CreateDevice
4282 * Creates an IDirect3DDevice7 interface.
4284 * Version 2, 3 and 7. IDirect3DDevice 1 interfaces are interfaces to
4285 * DirectDraw surfaces and are created with
4286 * IDirectDrawSurface::QueryInterface. This method uses CreateDevice to
4287 * create the device object and QueryInterfaces for IDirect3DDevice
4290 * refiid: IID of the device to create
4291 * Surface: Initial rendertarget
4292 * Device: Address to return the interface pointer
4296 * DDERR_OUTOFMEMORY if memory allocation failed
4297 * DDERR_INVALIDPARAMS if a device exists already
4299 *****************************************************************************/
4300 static HRESULT WINAPI
d3d7_CreateDevice(IDirect3D7
*iface
, REFCLSID riid
,
4301 IDirectDrawSurface7
*surface
, IDirect3DDevice7
**device
)
4303 struct ddraw_surface
*target
= unsafe_impl_from_IDirectDrawSurface7(surface
);
4304 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4305 struct d3d_device
*object
;
4308 TRACE("iface %p, riid %s, surface %p, device %p.\n", iface
, debugstr_guid(riid
), surface
, device
);
4310 wined3d_mutex_lock();
4311 hr
= d3d_device_create(ddraw
, target
, 7, &object
, NULL
);
4313 *device
= &object
->IDirect3DDevice7_iface
;
4316 WARN("Failed to create device, hr %#x.\n", hr
);
4319 wined3d_mutex_unlock();
4324 static HRESULT WINAPI
d3d3_CreateDevice(IDirect3D3
*iface
, REFCLSID riid
,
4325 IDirectDrawSurface4
*surface
, IDirect3DDevice3
**device
, IUnknown
*outer_unknown
)
4327 struct ddraw_surface
*surface_impl
= unsafe_impl_from_IDirectDrawSurface4(surface
);
4328 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4329 struct d3d_device
*device_impl
;
4332 TRACE("iface %p, riid %s, surface %p, device %p, outer_unknown %p.\n",
4333 iface
, debugstr_guid(riid
), surface
, device
, outer_unknown
);
4336 return CLASS_E_NOAGGREGATION
;
4338 wined3d_mutex_lock();
4339 hr
= d3d_device_create(ddraw
, surface_impl
, 3, &device_impl
, NULL
);
4341 *device
= &device_impl
->IDirect3DDevice3_iface
;
4344 WARN("Failed to create device, hr %#x.\n", hr
);
4347 wined3d_mutex_unlock();
4352 static HRESULT WINAPI
d3d2_CreateDevice(IDirect3D2
*iface
, REFCLSID riid
,
4353 IDirectDrawSurface
*surface
, IDirect3DDevice2
**device
)
4355 struct ddraw_surface
*surface_impl
= unsafe_impl_from_IDirectDrawSurface(surface
);
4356 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4357 struct d3d_device
*device_impl
;
4360 TRACE("iface %p, riid %s, surface %p, device %p.\n",
4361 iface
, debugstr_guid(riid
), surface
, device
);
4363 wined3d_mutex_lock();
4364 hr
= d3d_device_create(ddraw
, surface_impl
, 2, &device_impl
, NULL
);
4366 *device
= &device_impl
->IDirect3DDevice2_iface
;
4369 WARN("Failed to create device, hr %#x.\n", hr
);
4372 wined3d_mutex_unlock();
4377 /*****************************************************************************
4378 * IDirect3D7::CreateVertexBuffer
4380 * Creates a new vertex buffer object and returns a IDirect3DVertexBuffer7
4386 * desc: Requested Vertex buffer properties
4387 * vertex_buffer: Address to return the interface pointer at
4388 * flags: Some flags, should be 0
4392 * DDERR_OUTOFMEMORY if memory allocation failed
4393 * The return value of IWineD3DDevice::CreateVertexBuffer if this call fails
4394 * DDERR_INVALIDPARAMS if desc or vertex_buffer are NULL
4396 *****************************************************************************/
4397 static HRESULT WINAPI
d3d7_CreateVertexBuffer(IDirect3D7
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4398 IDirect3DVertexBuffer7
**vertex_buffer
, DWORD flags
)
4400 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4401 struct d3d_vertex_buffer
*object
;
4404 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x.\n",
4405 iface
, desc
, vertex_buffer
, flags
);
4407 if (!vertex_buffer
|| !desc
) return DDERR_INVALIDPARAMS
;
4409 hr
= d3d_vertex_buffer_create(&object
, ddraw
, desc
);
4412 TRACE("Created vertex buffer %p.\n", object
);
4413 *vertex_buffer
= &object
->IDirect3DVertexBuffer7_iface
;
4416 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4421 static HRESULT WINAPI
d3d3_CreateVertexBuffer(IDirect3D3
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4422 IDirect3DVertexBuffer
**vertex_buffer
, DWORD flags
, IUnknown
*outer_unknown
)
4424 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4425 struct d3d_vertex_buffer
*object
;
4428 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x, outer_unknown %p.\n",
4429 iface
, desc
, vertex_buffer
, flags
, outer_unknown
);
4432 return CLASS_E_NOAGGREGATION
;
4433 if (!vertex_buffer
|| !desc
)
4434 return DDERR_INVALIDPARAMS
;
4436 hr
= d3d_vertex_buffer_create(&object
, ddraw
, desc
);
4439 TRACE("Created vertex buffer %p.\n", object
);
4440 *vertex_buffer
= &object
->IDirect3DVertexBuffer_iface
;
4443 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4448 /*****************************************************************************
4449 * IDirect3D7::EnumZBufferFormats
4451 * Enumerates all supported Z buffer pixel formats
4457 * callback: callback to call for each pixel format
4458 * context: Pointer to pass back to the callback
4462 * DDERR_INVALIDPARAMS if callback is NULL
4463 * For details, see IWineD3DDevice::EnumZBufferFormats
4465 *****************************************************************************/
4466 static HRESULT WINAPI
d3d7_EnumZBufferFormats(IDirect3D7
*iface
, REFCLSID device_iid
,
4467 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4469 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4470 struct wined3d_display_mode mode
;
4471 enum wined3d_device_type type
;
4475 /* Order matters. Specifically, BattleZone II (full version) expects the
4476 * 16-bit depth formats to be listed before the 24 and 32 ones. */
4477 static const enum wined3d_format_id formats
[] =
4479 WINED3DFMT_S1_UINT_D15_UNORM
,
4480 WINED3DFMT_D16_UNORM
,
4481 WINED3DFMT_X8D24_UNORM
,
4482 WINED3DFMT_S4X4_UINT_D24_UNORM
,
4483 WINED3DFMT_D24_UNORM_S8_UINT
,
4484 WINED3DFMT_D32_UNORM
,
4487 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4488 iface
, debugstr_guid(device_iid
), callback
, context
);
4490 if (!callback
) return DDERR_INVALIDPARAMS
;
4492 if (IsEqualGUID(device_iid
, &IID_IDirect3DHALDevice
)
4493 || IsEqualGUID(device_iid
, &IID_IDirect3DTnLHalDevice
)
4494 || IsEqualGUID(device_iid
, &IID_D3DDEVICE_WineD3D
))
4496 TRACE("Asked for HAL device.\n");
4497 type
= WINED3D_DEVICE_TYPE_HAL
;
4499 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRGBDevice
)
4500 || IsEqualGUID(device_iid
, &IID_IDirect3DMMXDevice
))
4502 TRACE("Asked for SW device.\n");
4503 type
= WINED3D_DEVICE_TYPE_SW
;
4505 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRefDevice
))
4507 TRACE("Asked for REF device.\n");
4508 type
= WINED3D_DEVICE_TYPE_REF
;
4510 else if (IsEqualGUID(device_iid
, &IID_IDirect3DNullDevice
))
4512 TRACE("Asked for NULLREF device.\n");
4513 type
= WINED3D_DEVICE_TYPE_NULLREF
;
4517 FIXME("Unexpected device GUID %s.\n", debugstr_guid(device_iid
));
4518 type
= WINED3D_DEVICE_TYPE_HAL
;
4521 wined3d_mutex_lock();
4522 /* We need an adapter format from somewhere to please wined3d and WGL.
4523 * Use the current display mode. So far all cards offer the same depth
4524 * stencil format for all modes, but if some do not and applications do
4525 * not like that we'll have to find some workaround, like iterating over
4526 * all imaginable formats and collecting all the depth stencil formats we
4528 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
4530 ERR("Failed to get display mode, hr %#x.\n", hr
);
4531 wined3d_mutex_unlock();
4535 for (i
= 0; i
< (sizeof(formats
) / sizeof(*formats
)); ++i
)
4537 hr
= wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, type
, mode
.format_id
,
4538 WINED3DUSAGE_DEPTHSTENCIL
, WINED3D_RTYPE_SURFACE
, formats
[i
], WINED3D_SURFACE_TYPE_OPENGL
);
4541 DDPIXELFORMAT pformat
;
4543 memset(&pformat
, 0, sizeof(pformat
));
4544 pformat
.dwSize
= sizeof(pformat
);
4545 PixelFormat_WineD3DtoDD(&pformat
, formats
[i
]);
4547 TRACE("Enumerating wined3d format %#x.\n", formats
[i
]);
4548 hr
= callback(&pformat
, context
);
4549 if (hr
!= DDENUMRET_OK
)
4551 TRACE("Format enumeration cancelled by application.\n");
4552 wined3d_mutex_unlock();
4558 /* Historically some windows drivers used dwZBufferBitDepth=24 for WINED3DFMT_X8D24_UNORM,
4559 * while others used dwZBufferBitDepth=32. In either case the pitch matches a 32 bits per
4560 * pixel format, so we use dwZBufferBitDepth=32. Some games expect 24. Windows Vista and
4561 * newer enumerate both versions, so we do the same(bug 22434) */
4562 hr
= wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, type
, mode
.format_id
,
4563 WINED3DUSAGE_DEPTHSTENCIL
, WINED3D_RTYPE_SURFACE
, WINED3DFMT_X8D24_UNORM
, WINED3D_SURFACE_TYPE_OPENGL
);
4566 DDPIXELFORMAT x8d24
=
4568 sizeof(x8d24
), DDPF_ZBUFFER
, 0,
4569 {24}, {0x00000000}, {0x00ffffff}, {0x00000000}
4571 TRACE("Enumerating WINED3DFMT_X8D24_UNORM, dwZBufferBitDepth=24 version\n");
4572 callback(&x8d24
, context
);
4575 TRACE("End of enumeration.\n");
4577 wined3d_mutex_unlock();
4582 static HRESULT WINAPI
d3d3_EnumZBufferFormats(IDirect3D3
*iface
, REFCLSID device_iid
,
4583 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4585 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4587 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4588 iface
, debugstr_guid(device_iid
), callback
, context
);
4590 return d3d7_EnumZBufferFormats(&ddraw
->IDirect3D7_iface
, device_iid
, callback
, context
);
4593 /*****************************************************************************
4594 * IDirect3D7::EvictManagedTextures
4596 * Removes all managed textures (=surfaces with DDSCAPS2_TEXTUREMANAGE or
4597 * DDSCAPS2_D3DTEXTUREMANAGE caps) to be removed from video memory.
4602 * D3D_OK, because it's a stub
4604 *****************************************************************************/
4605 static HRESULT WINAPI
d3d7_EvictManagedTextures(IDirect3D7
*iface
)
4607 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4609 TRACE("iface %p!\n", iface
);
4611 wined3d_mutex_lock();
4612 if (ddraw
->d3d_initialized
)
4613 wined3d_device_evict_managed_resources(ddraw
->wined3d_device
);
4614 wined3d_mutex_unlock();
4619 static HRESULT WINAPI
d3d3_EvictManagedTextures(IDirect3D3
*iface
)
4621 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4623 TRACE("iface %p.\n", iface
);
4625 return d3d7_EvictManagedTextures(&ddraw
->IDirect3D7_iface
);
4628 /*****************************************************************************
4629 * IDirect3DImpl_GetCaps
4631 * This function retrieves the device caps from wined3d
4632 * and converts it into a D3D7 and D3D - D3D3 structure
4633 * This is a helper function called from various places in ddraw
4636 * wined3d: The interface to get the caps from
4637 * desc1: Old D3D <3 structure to fill (needed)
4638 * desc7: D3D7 device desc structure to fill (needed)
4641 * D3D_OK on success, or the return value of IWineD3D::GetCaps
4643 *****************************************************************************/
4644 HRESULT
IDirect3DImpl_GetCaps(const struct wined3d
*wined3d
, D3DDEVICEDESC
*desc1
, D3DDEVICEDESC7
*desc7
)
4646 WINED3DCAPS wined3d_caps
;
4649 TRACE("wined3d %p, desc1 %p, desc7 %p.\n", wined3d
, desc1
, desc7
);
4651 memset(&wined3d_caps
, 0, sizeof(wined3d_caps
));
4653 wined3d_mutex_lock();
4654 hr
= wined3d_get_device_caps(wined3d
, 0, WINED3D_DEVICE_TYPE_HAL
, &wined3d_caps
);
4655 wined3d_mutex_unlock();
4658 WARN("Failed to get device caps, hr %#x.\n", hr
);
4662 /* Copy the results into the d3d7 and d3d3 structures */
4663 desc7
->dwDevCaps
= wined3d_caps
.DevCaps
;
4664 desc7
->dpcLineCaps
.dwMiscCaps
= wined3d_caps
.PrimitiveMiscCaps
;
4665 desc7
->dpcLineCaps
.dwRasterCaps
= wined3d_caps
.RasterCaps
;
4666 desc7
->dpcLineCaps
.dwZCmpCaps
= wined3d_caps
.ZCmpCaps
;
4667 desc7
->dpcLineCaps
.dwSrcBlendCaps
= wined3d_caps
.SrcBlendCaps
;
4668 desc7
->dpcLineCaps
.dwDestBlendCaps
= wined3d_caps
.DestBlendCaps
;
4669 desc7
->dpcLineCaps
.dwAlphaCmpCaps
= wined3d_caps
.AlphaCmpCaps
;
4670 desc7
->dpcLineCaps
.dwShadeCaps
= wined3d_caps
.ShadeCaps
;
4671 desc7
->dpcLineCaps
.dwTextureCaps
= wined3d_caps
.TextureCaps
;
4672 desc7
->dpcLineCaps
.dwTextureFilterCaps
= wined3d_caps
.TextureFilterCaps
;
4673 desc7
->dpcLineCaps
.dwTextureAddressCaps
= wined3d_caps
.TextureAddressCaps
;
4675 desc7
->dwMaxTextureWidth
= wined3d_caps
.MaxTextureWidth
;
4676 desc7
->dwMaxTextureHeight
= wined3d_caps
.MaxTextureHeight
;
4678 desc7
->dwMaxTextureRepeat
= wined3d_caps
.MaxTextureRepeat
;
4679 desc7
->dwMaxTextureAspectRatio
= wined3d_caps
.MaxTextureAspectRatio
;
4680 desc7
->dwMaxAnisotropy
= wined3d_caps
.MaxAnisotropy
;
4681 desc7
->dvMaxVertexW
= wined3d_caps
.MaxVertexW
;
4683 desc7
->dvGuardBandLeft
= wined3d_caps
.GuardBandLeft
;
4684 desc7
->dvGuardBandTop
= wined3d_caps
.GuardBandTop
;
4685 desc7
->dvGuardBandRight
= wined3d_caps
.GuardBandRight
;
4686 desc7
->dvGuardBandBottom
= wined3d_caps
.GuardBandBottom
;
4688 desc7
->dvExtentsAdjust
= wined3d_caps
.ExtentsAdjust
;
4689 desc7
->dwStencilCaps
= wined3d_caps
.StencilCaps
;
4691 desc7
->dwFVFCaps
= wined3d_caps
.FVFCaps
;
4692 desc7
->dwTextureOpCaps
= wined3d_caps
.TextureOpCaps
;
4694 desc7
->dwVertexProcessingCaps
= wined3d_caps
.VertexProcessingCaps
;
4695 desc7
->dwMaxActiveLights
= wined3d_caps
.MaxActiveLights
;
4697 /* Remove all non-d3d7 caps */
4698 desc7
->dwDevCaps
&= (
4699 D3DDEVCAPS_FLOATTLVERTEX
| D3DDEVCAPS_SORTINCREASINGZ
| D3DDEVCAPS_SORTDECREASINGZ
|
4700 D3DDEVCAPS_SORTEXACT
| D3DDEVCAPS_EXECUTESYSTEMMEMORY
| D3DDEVCAPS_EXECUTEVIDEOMEMORY
|
4701 D3DDEVCAPS_TLVERTEXSYSTEMMEMORY
| D3DDEVCAPS_TLVERTEXVIDEOMEMORY
| D3DDEVCAPS_TEXTURESYSTEMMEMORY
|
4702 D3DDEVCAPS_TEXTUREVIDEOMEMORY
| D3DDEVCAPS_DRAWPRIMTLVERTEX
| D3DDEVCAPS_CANRENDERAFTERFLIP
|
4703 D3DDEVCAPS_TEXTURENONLOCALVIDMEM
| D3DDEVCAPS_DRAWPRIMITIVES2
| D3DDEVCAPS_SEPARATETEXTUREMEMORIES
|
4704 D3DDEVCAPS_DRAWPRIMITIVES2EX
| D3DDEVCAPS_HWTRANSFORMANDLIGHT
| D3DDEVCAPS_CANBLTSYSTONONLOCAL
|
4705 D3DDEVCAPS_HWRASTERIZATION
);
4707 desc7
->dwStencilCaps
&= (
4708 D3DSTENCILCAPS_KEEP
| D3DSTENCILCAPS_ZERO
| D3DSTENCILCAPS_REPLACE
|
4709 D3DSTENCILCAPS_INCRSAT
| D3DSTENCILCAPS_DECRSAT
| D3DSTENCILCAPS_INVERT
|
4710 D3DSTENCILCAPS_INCR
| D3DSTENCILCAPS_DECR
);
4714 desc7
->dwTextureOpCaps
&= (
4715 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
| D3DTEXOPCAPS_SELECTARG2
|
4716 D3DTEXOPCAPS_MODULATE
| D3DTEXOPCAPS_MODULATE2X
| D3DTEXOPCAPS_MODULATE4X
|
4717 D3DTEXOPCAPS_ADD
| D3DTEXOPCAPS_ADDSIGNED
| D3DTEXOPCAPS_ADDSIGNED2X
|
4718 D3DTEXOPCAPS_SUBTRACT
| D3DTEXOPCAPS_ADDSMOOTH
| D3DTEXOPCAPS_BLENDTEXTUREALPHA
|
4719 D3DTEXOPCAPS_BLENDFACTORALPHA
| D3DTEXOPCAPS_BLENDTEXTUREALPHAPM
| D3DTEXOPCAPS_BLENDCURRENTALPHA
|
4720 D3DTEXOPCAPS_PREMODULATE
| D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA
|
4721 D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA
| D3DTEXOPCAPS_BUMPENVMAP
|
4722 D3DTEXOPCAPS_BUMPENVMAPLUMINANCE
| D3DTEXOPCAPS_DOTPRODUCT3
);
4724 desc7
->dwVertexProcessingCaps
&= (
4725 D3DVTXPCAPS_TEXGEN
| D3DVTXPCAPS_MATERIALSOURCE7
| D3DVTXPCAPS_VERTEXFOG
|
4726 D3DVTXPCAPS_DIRECTIONALLIGHTS
| D3DVTXPCAPS_POSITIONALLIGHTS
| D3DVTXPCAPS_LOCALVIEWER
);
4728 desc7
->dpcLineCaps
.dwMiscCaps
&= (
4729 D3DPMISCCAPS_MASKPLANES
| D3DPMISCCAPS_MASKZ
| D3DPMISCCAPS_LINEPATTERNREP
|
4730 D3DPMISCCAPS_CONFORMANT
| D3DPMISCCAPS_CULLNONE
| D3DPMISCCAPS_CULLCW
|
4731 D3DPMISCCAPS_CULLCCW
);
4733 desc7
->dpcLineCaps
.dwRasterCaps
&= (
4734 D3DPRASTERCAPS_DITHER
| D3DPRASTERCAPS_ROP2
| D3DPRASTERCAPS_XOR
|
4735 D3DPRASTERCAPS_PAT
| D3DPRASTERCAPS_ZTEST
| D3DPRASTERCAPS_SUBPIXEL
|
4736 D3DPRASTERCAPS_SUBPIXELX
| D3DPRASTERCAPS_FOGVERTEX
| D3DPRASTERCAPS_FOGTABLE
|
4737 D3DPRASTERCAPS_STIPPLE
| D3DPRASTERCAPS_ANTIALIASSORTDEPENDENT
| D3DPRASTERCAPS_ANTIALIASSORTINDEPENDENT
|
4738 D3DPRASTERCAPS_ANTIALIASEDGES
| D3DPRASTERCAPS_MIPMAPLODBIAS
| D3DPRASTERCAPS_ZBIAS
|
4739 D3DPRASTERCAPS_ZBUFFERLESSHSR
| D3DPRASTERCAPS_FOGRANGE
| D3DPRASTERCAPS_ANISOTROPY
|
4740 D3DPRASTERCAPS_WBUFFER
| D3DPRASTERCAPS_TRANSLUCENTSORTINDEPENDENT
| D3DPRASTERCAPS_WFOG
|
4741 D3DPRASTERCAPS_ZFOG
);
4743 desc7
->dpcLineCaps
.dwZCmpCaps
&= (
4744 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
4745 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
4746 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
4748 desc7
->dpcLineCaps
.dwSrcBlendCaps
&= (
4749 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
4750 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
4751 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
4752 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
4753 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
4755 desc7
->dpcLineCaps
.dwDestBlendCaps
&= (
4756 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
4757 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
4758 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
4759 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
4760 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
4762 desc7
->dpcLineCaps
.dwAlphaCmpCaps
&= (
4763 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
4764 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
4765 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
4767 desc7
->dpcLineCaps
.dwShadeCaps
&= (
4768 D3DPSHADECAPS_COLORFLATMONO
| D3DPSHADECAPS_COLORFLATRGB
| D3DPSHADECAPS_COLORGOURAUDMONO
|
4769 D3DPSHADECAPS_COLORGOURAUDRGB
| D3DPSHADECAPS_COLORPHONGMONO
| D3DPSHADECAPS_COLORPHONGRGB
|
4770 D3DPSHADECAPS_SPECULARFLATMONO
| D3DPSHADECAPS_SPECULARFLATRGB
| D3DPSHADECAPS_SPECULARGOURAUDMONO
|
4771 D3DPSHADECAPS_SPECULARGOURAUDRGB
| D3DPSHADECAPS_SPECULARPHONGMONO
| D3DPSHADECAPS_SPECULARPHONGRGB
|
4772 D3DPSHADECAPS_ALPHAFLATBLEND
| D3DPSHADECAPS_ALPHAFLATSTIPPLED
| D3DPSHADECAPS_ALPHAGOURAUDBLEND
|
4773 D3DPSHADECAPS_ALPHAGOURAUDSTIPPLED
| D3DPSHADECAPS_ALPHAPHONGBLEND
| D3DPSHADECAPS_ALPHAPHONGSTIPPLED
|
4774 D3DPSHADECAPS_FOGFLAT
| D3DPSHADECAPS_FOGGOURAUD
| D3DPSHADECAPS_FOGPHONG
);
4776 desc7
->dpcLineCaps
.dwTextureCaps
&= (
4777 D3DPTEXTURECAPS_PERSPECTIVE
| D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_ALPHA
|
4778 D3DPTEXTURECAPS_TRANSPARENCY
| D3DPTEXTURECAPS_BORDER
| D3DPTEXTURECAPS_SQUAREONLY
|
4779 D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE
| D3DPTEXTURECAPS_ALPHAPALETTE
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
|
4780 D3DPTEXTURECAPS_PROJECTED
| D3DPTEXTURECAPS_CUBEMAP
| D3DPTEXTURECAPS_COLORKEYBLEND
);
4782 desc7
->dpcLineCaps
.dwTextureFilterCaps
&= (
4783 D3DPTFILTERCAPS_NEAREST
| D3DPTFILTERCAPS_LINEAR
| D3DPTFILTERCAPS_MIPNEAREST
|
4784 D3DPTFILTERCAPS_MIPLINEAR
| D3DPTFILTERCAPS_LINEARMIPNEAREST
| D3DPTFILTERCAPS_LINEARMIPLINEAR
|
4785 D3DPTFILTERCAPS_MINFPOINT
| D3DPTFILTERCAPS_MINFLINEAR
| D3DPTFILTERCAPS_MINFANISOTROPIC
|
4786 D3DPTFILTERCAPS_MIPFPOINT
| D3DPTFILTERCAPS_MIPFLINEAR
| D3DPTFILTERCAPS_MAGFPOINT
|
4787 D3DPTFILTERCAPS_MAGFLINEAR
| D3DPTFILTERCAPS_MAGFANISOTROPIC
| D3DPTFILTERCAPS_MAGFAFLATCUBIC
|
4788 D3DPTFILTERCAPS_MAGFGAUSSIANCUBIC
);
4790 desc7
->dpcLineCaps
.dwTextureBlendCaps
&= (
4791 D3DPTBLENDCAPS_DECAL
| D3DPTBLENDCAPS_MODULATE
| D3DPTBLENDCAPS_DECALALPHA
|
4792 D3DPTBLENDCAPS_MODULATEALPHA
| D3DPTBLENDCAPS_DECALMASK
| D3DPTBLENDCAPS_MODULATEMASK
|
4793 D3DPTBLENDCAPS_COPY
| D3DPTBLENDCAPS_ADD
);
4795 desc7
->dpcLineCaps
.dwTextureAddressCaps
&= (
4796 D3DPTADDRESSCAPS_WRAP
| D3DPTADDRESSCAPS_MIRROR
| D3DPTADDRESSCAPS_CLAMP
|
4797 D3DPTADDRESSCAPS_BORDER
| D3DPTADDRESSCAPS_INDEPENDENTUV
);
4799 if (!(desc7
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
))
4801 /* DirectX7 always has the np2 flag set, no matter what the card
4802 * supports. Some old games (Rollcage) check the caps incorrectly.
4803 * If wined3d supports nonpow2 textures it also has np2 conditional
4805 desc7
->dpcLineCaps
.dwTextureCaps
|= D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
;
4808 /* Fill the missing members, and do some fixup */
4809 desc7
->dpcLineCaps
.dwSize
= sizeof(desc7
->dpcLineCaps
);
4810 desc7
->dpcLineCaps
.dwTextureBlendCaps
= D3DPTBLENDCAPS_ADD
| D3DPTBLENDCAPS_MODULATEMASK
|
4811 D3DPTBLENDCAPS_COPY
| D3DPTBLENDCAPS_DECAL
|
4812 D3DPTBLENDCAPS_DECALALPHA
| D3DPTBLENDCAPS_DECALMASK
|
4813 D3DPTBLENDCAPS_MODULATE
| D3DPTBLENDCAPS_MODULATEALPHA
;
4814 desc7
->dpcLineCaps
.dwStippleWidth
= 32;
4815 desc7
->dpcLineCaps
.dwStippleHeight
= 32;
4816 /* Use the same for the TriCaps */
4817 desc7
->dpcTriCaps
= desc7
->dpcLineCaps
;
4819 desc7
->dwDeviceRenderBitDepth
= DDBD_16
| DDBD_24
| DDBD_32
;
4820 desc7
->dwDeviceZBufferBitDepth
= DDBD_16
| DDBD_24
;
4821 desc7
->dwMinTextureWidth
= 1;
4822 desc7
->dwMinTextureHeight
= 1;
4824 /* Convert DWORDs safely to WORDs */
4825 if (wined3d_caps
.MaxTextureBlendStages
> 0xffff) desc7
->wMaxTextureBlendStages
= 0xffff;
4826 else desc7
->wMaxTextureBlendStages
= (WORD
)wined3d_caps
.MaxTextureBlendStages
;
4827 if (wined3d_caps
.MaxSimultaneousTextures
> 0xffff) desc7
->wMaxSimultaneousTextures
= 0xffff;
4828 else desc7
->wMaxSimultaneousTextures
= (WORD
)wined3d_caps
.MaxSimultaneousTextures
;
4830 if (wined3d_caps
.MaxUserClipPlanes
> 0xffff) desc7
->wMaxUserClipPlanes
= 0xffff;
4831 else desc7
->wMaxUserClipPlanes
= (WORD
)wined3d_caps
.MaxUserClipPlanes
;
4832 if (wined3d_caps
.MaxVertexBlendMatrices
> 0xffff) desc7
->wMaxVertexBlendMatrices
= 0xffff;
4833 else desc7
->wMaxVertexBlendMatrices
= (WORD
)wined3d_caps
.MaxVertexBlendMatrices
;
4835 desc7
->deviceGUID
= IID_IDirect3DTnLHalDevice
;
4837 desc7
->dwReserved1
= 0;
4838 desc7
->dwReserved2
= 0;
4839 desc7
->dwReserved3
= 0;
4840 desc7
->dwReserved4
= 0;
4842 /* Fill the old structure */
4843 memset(desc1
, 0, sizeof(*desc1
));
4844 desc1
->dwSize
= sizeof(D3DDEVICEDESC
);
4845 desc1
->dwFlags
= D3DDD_COLORMODEL
4847 | D3DDD_TRANSFORMCAPS
4849 | D3DDD_LIGHTINGCAPS
4852 | D3DDD_DEVICERENDERBITDEPTH
4853 | D3DDD_DEVICEZBUFFERBITDEPTH
4854 | D3DDD_MAXBUFFERSIZE
4855 | D3DDD_MAXVERTEXCOUNT
;
4857 desc1
->dcmColorModel
= D3DCOLOR_RGB
;
4858 desc1
->dwDevCaps
= desc7
->dwDevCaps
;
4859 desc1
->dtcTransformCaps
.dwSize
= sizeof(D3DTRANSFORMCAPS
);
4860 desc1
->dtcTransformCaps
.dwCaps
= D3DTRANSFORMCAPS_CLIP
;
4861 desc1
->bClipping
= TRUE
;
4862 desc1
->dlcLightingCaps
.dwSize
= sizeof(D3DLIGHTINGCAPS
);
4863 desc1
->dlcLightingCaps
.dwCaps
= D3DLIGHTCAPS_DIRECTIONAL
4864 | D3DLIGHTCAPS_PARALLELPOINT
4865 | D3DLIGHTCAPS_POINT
4866 | D3DLIGHTCAPS_SPOT
;
4868 desc1
->dlcLightingCaps
.dwLightingModel
= D3DLIGHTINGMODEL_RGB
;
4869 desc1
->dlcLightingCaps
.dwNumLights
= desc7
->dwMaxActiveLights
;
4871 desc1
->dpcLineCaps
.dwSize
= sizeof(D3DPRIMCAPS
);
4872 desc1
->dpcLineCaps
.dwMiscCaps
= desc7
->dpcLineCaps
.dwMiscCaps
;
4873 desc1
->dpcLineCaps
.dwRasterCaps
= desc7
->dpcLineCaps
.dwRasterCaps
;
4874 desc1
->dpcLineCaps
.dwZCmpCaps
= desc7
->dpcLineCaps
.dwZCmpCaps
;
4875 desc1
->dpcLineCaps
.dwSrcBlendCaps
= desc7
->dpcLineCaps
.dwSrcBlendCaps
;
4876 desc1
->dpcLineCaps
.dwDestBlendCaps
= desc7
->dpcLineCaps
.dwDestBlendCaps
;
4877 desc1
->dpcLineCaps
.dwShadeCaps
= desc7
->dpcLineCaps
.dwShadeCaps
;
4878 desc1
->dpcLineCaps
.dwTextureCaps
= desc7
->dpcLineCaps
.dwTextureCaps
;
4879 desc1
->dpcLineCaps
.dwTextureFilterCaps
= desc7
->dpcLineCaps
.dwTextureFilterCaps
;
4880 desc1
->dpcLineCaps
.dwTextureBlendCaps
= desc7
->dpcLineCaps
.dwTextureBlendCaps
;
4881 desc1
->dpcLineCaps
.dwTextureAddressCaps
= desc7
->dpcLineCaps
.dwTextureAddressCaps
;
4882 desc1
->dpcLineCaps
.dwStippleWidth
= desc7
->dpcLineCaps
.dwStippleWidth
;
4883 desc1
->dpcLineCaps
.dwAlphaCmpCaps
= desc7
->dpcLineCaps
.dwAlphaCmpCaps
;
4885 desc1
->dpcTriCaps
.dwSize
= sizeof(D3DPRIMCAPS
);
4886 desc1
->dpcTriCaps
.dwMiscCaps
= desc7
->dpcTriCaps
.dwMiscCaps
;
4887 desc1
->dpcTriCaps
.dwRasterCaps
= desc7
->dpcTriCaps
.dwRasterCaps
;
4888 desc1
->dpcTriCaps
.dwZCmpCaps
= desc7
->dpcTriCaps
.dwZCmpCaps
;
4889 desc1
->dpcTriCaps
.dwSrcBlendCaps
= desc7
->dpcTriCaps
.dwSrcBlendCaps
;
4890 desc1
->dpcTriCaps
.dwDestBlendCaps
= desc7
->dpcTriCaps
.dwDestBlendCaps
;
4891 desc1
->dpcTriCaps
.dwShadeCaps
= desc7
->dpcTriCaps
.dwShadeCaps
;
4892 desc1
->dpcTriCaps
.dwTextureCaps
= desc7
->dpcTriCaps
.dwTextureCaps
;
4893 desc1
->dpcTriCaps
.dwTextureFilterCaps
= desc7
->dpcTriCaps
.dwTextureFilterCaps
;
4894 desc1
->dpcTriCaps
.dwTextureBlendCaps
= desc7
->dpcTriCaps
.dwTextureBlendCaps
;
4895 desc1
->dpcTriCaps
.dwTextureAddressCaps
= desc7
->dpcTriCaps
.dwTextureAddressCaps
;
4896 desc1
->dpcTriCaps
.dwStippleWidth
= desc7
->dpcTriCaps
.dwStippleWidth
;
4897 desc1
->dpcTriCaps
.dwAlphaCmpCaps
= desc7
->dpcTriCaps
.dwAlphaCmpCaps
;
4899 desc1
->dwDeviceRenderBitDepth
= desc7
->dwDeviceRenderBitDepth
;
4900 desc1
->dwDeviceZBufferBitDepth
= desc7
->dwDeviceZBufferBitDepth
;
4901 desc1
->dwMaxBufferSize
= 0;
4902 desc1
->dwMaxVertexCount
= 65536;
4903 desc1
->dwMinTextureWidth
= desc7
->dwMinTextureWidth
;
4904 desc1
->dwMinTextureHeight
= desc7
->dwMinTextureHeight
;
4905 desc1
->dwMaxTextureWidth
= desc7
->dwMaxTextureWidth
;
4906 desc1
->dwMaxTextureHeight
= desc7
->dwMaxTextureHeight
;
4907 desc1
->dwMinStippleWidth
= 1;
4908 desc1
->dwMinStippleHeight
= 1;
4909 desc1
->dwMaxStippleWidth
= 32;
4910 desc1
->dwMaxStippleHeight
= 32;
4911 desc1
->dwMaxTextureRepeat
= desc7
->dwMaxTextureRepeat
;
4912 desc1
->dwMaxTextureAspectRatio
= desc7
->dwMaxTextureAspectRatio
;
4913 desc1
->dwMaxAnisotropy
= desc7
->dwMaxAnisotropy
;
4914 desc1
->dvGuardBandLeft
= desc7
->dvGuardBandLeft
;
4915 desc1
->dvGuardBandRight
= desc7
->dvGuardBandRight
;
4916 desc1
->dvGuardBandTop
= desc7
->dvGuardBandTop
;
4917 desc1
->dvGuardBandBottom
= desc7
->dvGuardBandBottom
;
4918 desc1
->dvExtentsAdjust
= desc7
->dvExtentsAdjust
;
4919 desc1
->dwStencilCaps
= desc7
->dwStencilCaps
;
4920 desc1
->dwFVFCaps
= desc7
->dwFVFCaps
;
4921 desc1
->dwTextureOpCaps
= desc7
->dwTextureOpCaps
;
4922 desc1
->wMaxTextureBlendStages
= desc7
->wMaxTextureBlendStages
;
4923 desc1
->wMaxSimultaneousTextures
= desc7
->wMaxSimultaneousTextures
;
4928 /*****************************************************************************
4929 * IDirectDraw7 VTable
4930 *****************************************************************************/
4931 static const struct IDirectDraw7Vtbl ddraw7_vtbl
=
4934 ddraw7_QueryInterface
,
4939 ddraw7_CreateClipper
,
4940 ddraw7_CreatePalette
,
4941 ddraw7_CreateSurface
,
4942 ddraw7_DuplicateSurface
,
4943 ddraw7_EnumDisplayModes
,
4944 ddraw7_EnumSurfaces
,
4945 ddraw7_FlipToGDISurface
,
4947 ddraw7_GetDisplayMode
,
4948 ddraw7_GetFourCCCodes
,
4949 ddraw7_GetGDISurface
,
4950 ddraw7_GetMonitorFrequency
,
4952 ddraw7_GetVerticalBlankStatus
,
4954 ddraw7_RestoreDisplayMode
,
4955 ddraw7_SetCooperativeLevel
,
4956 ddraw7_SetDisplayMode
,
4957 ddraw7_WaitForVerticalBlank
,
4959 ddraw7_GetAvailableVidMem
,
4961 ddraw7_GetSurfaceFromDC
,
4963 ddraw7_RestoreAllSurfaces
,
4964 ddraw7_TestCooperativeLevel
,
4965 ddraw7_GetDeviceIdentifier
,
4967 ddraw7_StartModeTest
,
4971 static const struct IDirectDraw4Vtbl ddraw4_vtbl
=
4974 ddraw4_QueryInterface
,
4979 ddraw4_CreateClipper
,
4980 ddraw4_CreatePalette
,
4981 ddraw4_CreateSurface
,
4982 ddraw4_DuplicateSurface
,
4983 ddraw4_EnumDisplayModes
,
4984 ddraw4_EnumSurfaces
,
4985 ddraw4_FlipToGDISurface
,
4987 ddraw4_GetDisplayMode
,
4988 ddraw4_GetFourCCCodes
,
4989 ddraw4_GetGDISurface
,
4990 ddraw4_GetMonitorFrequency
,
4992 ddraw4_GetVerticalBlankStatus
,
4994 ddraw4_RestoreDisplayMode
,
4995 ddraw4_SetCooperativeLevel
,
4996 ddraw4_SetDisplayMode
,
4997 ddraw4_WaitForVerticalBlank
,
4999 ddraw4_GetAvailableVidMem
,
5001 ddraw4_GetSurfaceFromDC
,
5003 ddraw4_RestoreAllSurfaces
,
5004 ddraw4_TestCooperativeLevel
,
5005 ddraw4_GetDeviceIdentifier
,
5008 static const struct IDirectDraw2Vtbl ddraw2_vtbl
=
5011 ddraw2_QueryInterface
,
5016 ddraw2_CreateClipper
,
5017 ddraw2_CreatePalette
,
5018 ddraw2_CreateSurface
,
5019 ddraw2_DuplicateSurface
,
5020 ddraw2_EnumDisplayModes
,
5021 ddraw2_EnumSurfaces
,
5022 ddraw2_FlipToGDISurface
,
5024 ddraw2_GetDisplayMode
,
5025 ddraw2_GetFourCCCodes
,
5026 ddraw2_GetGDISurface
,
5027 ddraw2_GetMonitorFrequency
,
5029 ddraw2_GetVerticalBlankStatus
,
5031 ddraw2_RestoreDisplayMode
,
5032 ddraw2_SetCooperativeLevel
,
5033 ddraw2_SetDisplayMode
,
5034 ddraw2_WaitForVerticalBlank
,
5036 ddraw2_GetAvailableVidMem
,
5039 static const struct IDirectDrawVtbl ddraw1_vtbl
=
5042 ddraw1_QueryInterface
,
5047 ddraw1_CreateClipper
,
5048 ddraw1_CreatePalette
,
5049 ddraw1_CreateSurface
,
5050 ddraw1_DuplicateSurface
,
5051 ddraw1_EnumDisplayModes
,
5052 ddraw1_EnumSurfaces
,
5053 ddraw1_FlipToGDISurface
,
5055 ddraw1_GetDisplayMode
,
5056 ddraw1_GetFourCCCodes
,
5057 ddraw1_GetGDISurface
,
5058 ddraw1_GetMonitorFrequency
,
5060 ddraw1_GetVerticalBlankStatus
,
5062 ddraw1_RestoreDisplayMode
,
5063 ddraw1_SetCooperativeLevel
,
5064 ddraw1_SetDisplayMode
,
5065 ddraw1_WaitForVerticalBlank
,
5068 static const struct IDirect3D7Vtbl d3d7_vtbl
=
5070 /* IUnknown methods */
5071 d3d7_QueryInterface
,
5074 /* IDirect3D7 methods */
5077 d3d7_CreateVertexBuffer
,
5078 d3d7_EnumZBufferFormats
,
5079 d3d7_EvictManagedTextures
5082 static const struct IDirect3D3Vtbl d3d3_vtbl
=
5084 /* IUnknown methods */
5085 d3d3_QueryInterface
,
5088 /* IDirect3D3 methods */
5091 d3d3_CreateMaterial
,
5092 d3d3_CreateViewport
,
5095 d3d3_CreateVertexBuffer
,
5096 d3d3_EnumZBufferFormats
,
5097 d3d3_EvictManagedTextures
5100 static const struct IDirect3D2Vtbl d3d2_vtbl
=
5102 /* IUnknown methods */
5103 d3d2_QueryInterface
,
5106 /* IDirect3D2 methods */
5109 d3d2_CreateMaterial
,
5110 d3d2_CreateViewport
,
5115 static const struct IDirect3DVtbl d3d1_vtbl
=
5117 /* IUnknown methods */
5118 d3d1_QueryInterface
,
5121 /* IDirect3D methods */
5125 d3d1_CreateMaterial
,
5126 d3d1_CreateViewport
,
5130 /*****************************************************************************
5133 * Finds the WineD3D vertex declaration for a specific fvf, and creates one
5134 * if none was found.
5136 * This function is in ddraw.c and the DDraw object space because D3D7
5137 * vertex buffers are created using the IDirect3D interface to the ddraw
5138 * object, so they can be valid across D3D devices(theoretically. The ddraw
5139 * object also owns the wined3d device
5143 * fvf: Fvf to find the decl for
5146 * NULL in case of an error, the vertex declaration for the FVF otherwise.
5148 *****************************************************************************/
5149 struct wined3d_vertex_declaration
*ddraw_find_decl(struct ddraw
*This
, DWORD fvf
)
5151 struct wined3d_vertex_declaration
*pDecl
= NULL
;
5153 int p
, low
, high
; /* deliberately signed */
5154 struct FvfToDecl
*convertedDecls
= This
->decls
;
5156 TRACE("Searching for declaration for fvf %08x... ", fvf
);
5159 high
= This
->numConvertedDecls
- 1;
5160 while(low
<= high
) {
5161 p
= (low
+ high
) >> 1;
5163 if(convertedDecls
[p
].fvf
== fvf
) {
5164 TRACE("found %p\n", convertedDecls
[p
].decl
);
5165 return convertedDecls
[p
].decl
;
5166 } else if(convertedDecls
[p
].fvf
< fvf
) {
5172 TRACE("not found. Creating and inserting at position %d.\n", low
);
5174 hr
= wined3d_vertex_declaration_create_from_fvf(This
->wined3d_device
,
5175 fvf
, This
, &ddraw_null_wined3d_parent_ops
, &pDecl
);
5176 if (hr
!= S_OK
) return NULL
;
5178 if(This
->declArraySize
== This
->numConvertedDecls
) {
5179 int grow
= max(This
->declArraySize
/ 2, 8);
5180 convertedDecls
= HeapReAlloc(GetProcessHeap(), 0, convertedDecls
,
5181 sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
+ grow
));
5182 if (!convertedDecls
)
5184 wined3d_vertex_declaration_decref(pDecl
);
5187 This
->decls
= convertedDecls
;
5188 This
->declArraySize
+= grow
;
5191 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
, sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
- low
));
5192 convertedDecls
[low
].decl
= pDecl
;
5193 convertedDecls
[low
].fvf
= fvf
;
5194 This
->numConvertedDecls
++;
5196 TRACE("Returning %p. %d decls in array\n", pDecl
, This
->numConvertedDecls
);
5200 static inline struct ddraw
*ddraw_from_device_parent(struct wined3d_device_parent
*device_parent
)
5202 return CONTAINING_RECORD(device_parent
, struct ddraw
, device_parent
);
5205 static void CDECL
device_parent_wined3d_device_created(struct wined3d_device_parent
*device_parent
,
5206 struct wined3d_device
*device
)
5208 TRACE("device_parent %p, device %p.\n", device_parent
, device
);
5211 /* This is run from device_process_message() in wined3d, we can't take the
5213 static void CDECL
device_parent_mode_changed(struct wined3d_device_parent
*device_parent
)
5215 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
5216 MONITORINFO monitor_info
;
5221 TRACE("device_parent %p.\n", device_parent
);
5223 if (!(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
) || !ddraw
->swapchain_window
)
5225 TRACE("Nothing to resize.\n");
5229 monitor
= MonitorFromWindow(ddraw
->swapchain_window
, MONITOR_DEFAULTTOPRIMARY
);
5230 monitor_info
.cbSize
= sizeof(monitor_info
);
5231 if (!(ret
= GetMonitorInfoW(monitor
, &monitor_info
)))
5233 ERR("Failed to get monitor info.\n");
5237 r
= &monitor_info
.rcMonitor
;
5238 TRACE("Resizing window %p to %s.\n", ddraw
->swapchain_window
, wine_dbgstr_rect(r
));
5240 if (!(ret
= SetWindowPos(ddraw
->swapchain_window
, HWND_TOP
, r
->left
, r
->top
,
5241 r
->right
- r
->left
, r
->bottom
- r
->top
, SWP_SHOWWINDOW
| SWP_NOACTIVATE
)))
5242 ERR("Failed to resize window.\n");
5245 static HRESULT CDECL
device_parent_create_texture_surface(struct wined3d_device_parent
*device_parent
,
5246 void *container_parent
, UINT width
, UINT height
, enum wined3d_format_id format
, DWORD usage
,
5247 enum wined3d_pool pool
, UINT level
, enum wined3d_cubemap_face face
, struct wined3d_surface
**surface
)
5249 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
5250 struct ddraw_surface
*tex_root
= container_parent
;
5251 DDSURFACEDESC2 desc
= tex_root
->surface_desc
;
5252 struct ddraw_surface
*ddraw_surface
;
5255 TRACE("device_parent %p, container_parent %p, width %u, height %u, format %#x, usage %#x,\n"
5256 "\tpool %#x, level %u, face %u, surface %p.\n",
5257 device_parent
, container_parent
, width
, height
, format
, usage
, pool
, level
, face
, surface
);
5259 /* The ddraw root surface is created before the wined3d texture. */
5260 if (!level
&& face
== WINED3D_CUBEMAP_FACE_POSITIVE_X
)
5262 ddraw_surface
= tex_root
;
5266 desc
.dwWidth
= width
;
5267 desc
.dwHeight
= height
;
5269 desc
.ddsCaps
.dwCaps2
|= DDSCAPS2_MIPMAPSUBLEVEL
;
5271 desc
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
5273 if (desc
.ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5275 desc
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
5279 case WINED3D_CUBEMAP_FACE_POSITIVE_X
:
5280 desc
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
5283 case WINED3D_CUBEMAP_FACE_NEGATIVE_X
:
5284 desc
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEX
;
5287 case WINED3D_CUBEMAP_FACE_POSITIVE_Y
:
5288 desc
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEY
;
5291 case WINED3D_CUBEMAP_FACE_NEGATIVE_Y
:
5292 desc
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEY
;
5295 case WINED3D_CUBEMAP_FACE_POSITIVE_Z
:
5296 desc
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEZ
;
5299 case WINED3D_CUBEMAP_FACE_NEGATIVE_Z
:
5300 desc
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEZ
;
5304 ERR("Unexpected cube face.\n");
5305 return DDERR_INVALIDPARAMS
;
5310 /* FIXME: Validate that format, usage, pool, etc. really make sense. */
5311 if (FAILED(hr
= ddraw_create_surface(ddraw
, &desc
, &ddraw_surface
, level
, tex_root
->version
)))
5315 *surface
= ddraw_surface
->wined3d_surface
;
5316 wined3d_surface_incref(*surface
);
5321 static void STDMETHODCALLTYPE
ddraw_frontbuffer_destroyed(void *parent
)
5323 struct ddraw
*ddraw
= parent
;
5324 ddraw
->wined3d_frontbuffer
= NULL
;
5327 static const struct wined3d_parent_ops ddraw_frontbuffer_parent_ops
=
5329 ddraw_frontbuffer_destroyed
,
5332 static HRESULT CDECL
device_parent_create_swapchain_surface(struct wined3d_device_parent
*device_parent
,
5333 void *container_parent
, UINT width
, UINT height
, enum wined3d_format_id format_id
, DWORD usage
,
5334 enum wined3d_multisample_type multisample_type
, DWORD multisample_quality
, struct wined3d_surface
**surface
)
5336 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
5339 TRACE("device_parent %p, container_parent %p, width %u, height %u, format_id %#x, usage %#x,\n"
5340 "\tmultisample_type %#x, multisample_quality %u, surface %p.\n",
5341 device_parent
, container_parent
, width
, height
, format_id
, usage
,
5342 multisample_type
, multisample_quality
, surface
);
5344 if (ddraw
->wined3d_frontbuffer
)
5346 ERR("Frontbuffer already created.\n");
5350 if (SUCCEEDED(hr
= wined3d_surface_create(ddraw
->wined3d_device
, width
, height
, format_id
, 0,
5351 usage
, WINED3D_POOL_DEFAULT
, multisample_type
, multisample_quality
, DefaultSurfaceType
,
5352 WINED3D_SURFACE_MAPPABLE
, ddraw
, &ddraw_frontbuffer_parent_ops
, surface
)))
5353 ddraw
->wined3d_frontbuffer
= *surface
;
5358 static HRESULT CDECL
device_parent_create_volume(struct wined3d_device_parent
*device_parent
,
5359 void *container_parent
, UINT width
, UINT height
, UINT depth
, enum wined3d_format_id format
,
5360 enum wined3d_pool pool
, DWORD usage
, struct wined3d_volume
**volume
)
5362 TRACE("device_parent %p, container_parent %p, width %u, height %u, depth %u, "
5363 "format %#x, pool %#x, usage %#x, volume %p.\n",
5364 device_parent
, container_parent
, width
, height
, depth
,
5365 format
, pool
, usage
, volume
);
5367 ERR("Not implemented!\n");
5372 static HRESULT CDECL
device_parent_create_swapchain(struct wined3d_device_parent
*device_parent
,
5373 struct wined3d_swapchain_desc
*desc
, struct wined3d_swapchain
**swapchain
)
5375 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
5378 TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent
, desc
, swapchain
);
5380 if (ddraw
->wined3d_swapchain
)
5382 ERR("Swapchain already created.\n");
5386 hr
= wined3d_swapchain_create(ddraw
->wined3d_device
, desc
,
5387 DefaultSurfaceType
, NULL
, &ddraw_null_wined3d_parent_ops
, swapchain
);
5389 WARN("Failed to create swapchain, hr %#x.\n", hr
);
5394 static const struct wined3d_device_parent_ops ddraw_wined3d_device_parent_ops
=
5396 device_parent_wined3d_device_created
,
5397 device_parent_mode_changed
,
5398 device_parent_create_swapchain_surface
,
5399 device_parent_create_texture_surface
,
5400 device_parent_create_volume
,
5401 device_parent_create_swapchain
,
5404 HRESULT
ddraw_init(struct ddraw
*ddraw
, enum wined3d_device_type device_type
)
5409 ddraw
->IDirectDraw7_iface
.lpVtbl
= &ddraw7_vtbl
;
5410 ddraw
->IDirectDraw_iface
.lpVtbl
= &ddraw1_vtbl
;
5411 ddraw
->IDirectDraw2_iface
.lpVtbl
= &ddraw2_vtbl
;
5412 ddraw
->IDirectDraw4_iface
.lpVtbl
= &ddraw4_vtbl
;
5413 ddraw
->IDirect3D_iface
.lpVtbl
= &d3d1_vtbl
;
5414 ddraw
->IDirect3D2_iface
.lpVtbl
= &d3d2_vtbl
;
5415 ddraw
->IDirect3D3_iface
.lpVtbl
= &d3d3_vtbl
;
5416 ddraw
->IDirect3D7_iface
.lpVtbl
= &d3d7_vtbl
;
5417 ddraw
->device_parent
.ops
= &ddraw_wined3d_device_parent_ops
;
5418 ddraw
->numIfaces
= 1;
5421 /* Get the current screen settings. */
5423 ddraw
->orig_bpp
= GetDeviceCaps(hDC
, BITSPIXEL
) * GetDeviceCaps(hDC
, PLANES
);
5425 ddraw
->orig_width
= GetSystemMetrics(SM_CXSCREEN
);
5426 ddraw
->orig_height
= GetSystemMetrics(SM_CYSCREEN
);
5428 ddraw
->wined3d
= wined3d_create(7, WINED3D_LEGACY_DEPTH_BIAS
);
5429 if (!ddraw
->wined3d
)
5431 WARN("Failed to create a wined3d object.\n");
5432 return E_OUTOFMEMORY
;
5435 hr
= wined3d_device_create(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, device_type
,
5436 NULL
, 0, 8, &ddraw
->device_parent
, &ddraw
->wined3d_device
);
5439 WARN("Failed to create a wined3d device, hr %#x.\n", hr
);
5440 wined3d_decref(ddraw
->wined3d
);
5444 list_init(&ddraw
->surface_list
);