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
)))
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 (FAILED(hr
= wined3d_device_get_swapchain(ddraw
->wined3d_device
, 0, &ddraw
->wined3d_swapchain
)))
700 ERR("Failed to get swapchain, hr %#x.\n", hr
);
701 ddraw
->wined3d_swapchain
= NULL
;
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_stateblock
*stateblock
;
758 struct wined3d_surface
*rt
, *ds
;
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
);
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 wined3d_device_get_render_target(This
->wined3d_device
, 0, &rt
);
936 if (rt
== This
->wined3d_frontbuffer
)
938 wined3d_surface_decref(rt
);
942 wined3d_device_get_depth_stencil(This
->wined3d_device
, &ds
);
945 ddraw_destroy_swapchain(This
);
948 if (FAILED(hr
= ddraw_create_swapchain(This
, This
->dest_window
, !(cooplevel
& DDSCL_FULLSCREEN
))))
949 ERR("Failed to create swapchain, hr %#x.\n", hr
);
955 wined3d_device_set_depth_stencil(This
->wined3d_device
, ds
);
956 wined3d_surface_decref(ds
);
961 wined3d_device_set_render_target(This
->wined3d_device
, 0, rt
, FALSE
);
962 wined3d_surface_decref(rt
);
965 hr
= wined3d_stateblock_apply(stateblock
);
966 wined3d_stateblock_decref(stateblock
);
969 ERR("Failed to apply stateblock, hr %#x.\n", hr
);
970 wined3d_mutex_unlock();
975 /* Unhandled flags */
976 if(cooplevel
& DDSCL_ALLOWREBOOT
)
977 WARN("(%p) Unhandled flag DDSCL_ALLOWREBOOT, harmless\n", This
);
978 if(cooplevel
& DDSCL_ALLOWMODEX
)
979 WARN("(%p) Unhandled flag DDSCL_ALLOWMODEX, harmless\n", This
);
980 if(cooplevel
& DDSCL_FPUSETUP
)
981 WARN("(%p) Unhandled flag DDSCL_FPUSETUP, harmless\n", This
);
983 /* Store the cooperative_level */
984 This
->cooperative_level
= cooplevel
;
985 TRACE("SetCooperativeLevel retuning DD_OK\n");
986 wined3d_mutex_unlock();
991 static HRESULT WINAPI
ddraw4_SetCooperativeLevel(IDirectDraw4
*iface
, HWND window
, DWORD flags
)
993 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
995 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
997 return ddraw7_SetCooperativeLevel(&ddraw
->IDirectDraw7_iface
, window
, flags
);
1000 static HRESULT WINAPI
ddraw2_SetCooperativeLevel(IDirectDraw2
*iface
, HWND window
, DWORD flags
)
1002 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1004 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1006 return ddraw7_SetCooperativeLevel(&ddraw
->IDirectDraw7_iface
, window
, flags
);
1009 static HRESULT WINAPI
ddraw1_SetCooperativeLevel(IDirectDraw
*iface
, HWND window
, DWORD flags
)
1011 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1013 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1015 return ddraw7_SetCooperativeLevel(&ddraw
->IDirectDraw7_iface
, window
, flags
);
1018 /*****************************************************************************
1020 * Helper function for SetDisplayMode and RestoreDisplayMode
1022 * Implements DirectDraw's SetDisplayMode, but ignores the value of
1023 * ForceRefreshRate, since it is already handled by
1024 * ddraw7_SetDisplayMode. RestoreDisplayMode can use this function
1025 * without worrying that ForceRefreshRate will override the refresh rate. For
1026 * argument and return value documentation, see
1027 * ddraw7_SetDisplayMode.
1029 *****************************************************************************/
1030 static HRESULT
ddraw_set_display_mode(struct ddraw
*ddraw
, DWORD Width
, DWORD Height
,
1031 DWORD BPP
, DWORD RefreshRate
, DWORD Flags
)
1033 struct wined3d_display_mode mode
;
1034 enum wined3d_format_id format
;
1037 TRACE("ddraw %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n", ddraw
, Width
,
1038 Height
, BPP
, RefreshRate
, Flags
);
1040 wined3d_mutex_lock();
1041 if( !Width
|| !Height
)
1043 ERR("Width %u, Height %u, what to do?\n", Width
, Height
);
1044 /* It looks like Need for Speed Porsche Unleashed expects DD_OK here */
1045 wined3d_mutex_unlock();
1051 case 8: format
= WINED3DFMT_P8_UINT
; break;
1052 case 15: format
= WINED3DFMT_B5G5R5X1_UNORM
; break;
1053 case 16: format
= WINED3DFMT_B5G6R5_UNORM
; break;
1054 case 24: format
= WINED3DFMT_B8G8R8_UNORM
; break;
1055 case 32: format
= WINED3DFMT_B8G8R8X8_UNORM
; break;
1056 default: format
= WINED3DFMT_UNKNOWN
; break;
1059 /* Check the exclusive mode
1060 if(!(ddraw->cooperative_level & DDSCL_EXCLUSIVE))
1061 return DDERR_NOEXCLUSIVEMODE;
1062 * This is WRONG. Don't know if the SDK is completely
1063 * wrong and if there are any conditions when DDERR_NOEXCLUSIVE
1064 * is returned, but Half-Life 1.1.1.1 (Steam version)
1069 mode
.height
= Height
;
1070 mode
.refresh_rate
= RefreshRate
;
1071 mode
.format_id
= format
;
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_device_set_display_mode(ddraw
->wined3d_device
, 0, &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 /* The necessary members of LPDDSURFACEDESC and LPDDSURFACEDESC2 are equal,
1425 * so one method can be used for all versions (Hopefully) */
1426 hr
= wined3d_device_get_display_mode(ddraw
->wined3d_device
, 0, &mode
);
1429 ERR("Failed to get display mode, hr %#x.\n", hr
);
1430 wined3d_mutex_unlock();
1434 Size
= DDSD
->dwSize
;
1435 memset(DDSD
, 0, Size
);
1437 DDSD
->dwSize
= Size
;
1438 DDSD
->dwFlags
|= DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
| DDSD_PITCH
| DDSD_REFRESHRATE
;
1439 DDSD
->dwWidth
= mode
.width
;
1440 DDSD
->dwHeight
= mode
.height
;
1441 DDSD
->u2
.dwRefreshRate
= 60;
1442 DDSD
->ddsCaps
.dwCaps
= 0;
1443 DDSD
->u4
.ddpfPixelFormat
.dwSize
= sizeof(DDSD
->u4
.ddpfPixelFormat
);
1444 PixelFormat_WineD3DtoDD(&DDSD
->u4
.ddpfPixelFormat
, mode
.format_id
);
1445 DDSD
->u1
.lPitch
= mode
.width
* DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8;
1449 TRACE("Returning surface desc :\n");
1450 DDRAW_dump_surface_desc(DDSD
);
1453 wined3d_mutex_unlock();
1458 static HRESULT WINAPI
ddraw4_GetDisplayMode(IDirectDraw4
*iface
, DDSURFACEDESC2
*surface_desc
)
1460 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1462 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1464 return ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, surface_desc
);
1467 static HRESULT WINAPI
ddraw2_GetDisplayMode(IDirectDraw2
*iface
, DDSURFACEDESC
*surface_desc
)
1469 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1471 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1473 /* FIXME: Test sizes, properly convert surface_desc */
1474 return ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1477 static HRESULT WINAPI
ddraw1_GetDisplayMode(IDirectDraw
*iface
, DDSURFACEDESC
*surface_desc
)
1479 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1481 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1483 /* FIXME: Test sizes, properly convert surface_desc */
1484 return ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1487 /*****************************************************************************
1488 * IDirectDraw7::GetFourCCCodes
1490 * Returns an array of supported FourCC codes.
1492 * Exists in Version 1, 2, 4 and 7
1495 * NumCodes: Contains the number of Codes that Codes can carry. Returns the number
1496 * of enumerated codes
1497 * Codes: Pointer to an array of DWORDs where the supported codes are written
1501 * Always returns DD_OK, as it's a stub for now
1503 *****************************************************************************/
1504 static HRESULT WINAPI
ddraw7_GetFourCCCodes(IDirectDraw7
*iface
, DWORD
*NumCodes
, DWORD
*Codes
)
1506 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1507 static const enum wined3d_format_id formats
[] =
1509 WINED3DFMT_YUY2
, WINED3DFMT_UYVY
, WINED3DFMT_YV12
,
1510 WINED3DFMT_DXT1
, WINED3DFMT_DXT2
, WINED3DFMT_DXT3
, WINED3DFMT_DXT4
, WINED3DFMT_DXT5
,
1511 WINED3DFMT_ATI2N
, WINED3DFMT_NVHU
, WINED3DFMT_NVHS
1513 struct wined3d_display_mode mode
;
1514 DWORD count
= 0, i
, outsize
;
1517 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, NumCodes
, Codes
);
1519 wined3d_device_get_display_mode(ddraw
->wined3d_device
, 0, &mode
);
1521 outsize
= NumCodes
&& Codes
? *NumCodes
: 0;
1523 for (i
= 0; i
< (sizeof(formats
) / sizeof(formats
[0])); ++i
)
1525 hr
= wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, WINED3D_DEVICE_TYPE_HAL
,
1526 mode
.format_id
, 0, WINED3D_RTYPE_SURFACE
, formats
[i
], DefaultSurfaceType
);
1529 if (count
< outsize
)
1530 Codes
[count
] = formats
[i
];
1535 TRACE("Returning %u FourCC codes\n", count
);
1542 static HRESULT WINAPI
ddraw4_GetFourCCCodes(IDirectDraw4
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1544 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1546 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1548 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1551 static HRESULT WINAPI
ddraw2_GetFourCCCodes(IDirectDraw2
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1553 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1555 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1557 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1560 static HRESULT WINAPI
ddraw1_GetFourCCCodes(IDirectDraw
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1562 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1564 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1566 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1569 /*****************************************************************************
1570 * IDirectDraw7::GetMonitorFrequency
1572 * Returns the monitor's frequency
1574 * Exists in Version 1, 2, 4 and 7
1577 * Freq: Pointer to a DWORD to write the frequency to
1580 * Always returns DD_OK
1582 *****************************************************************************/
1583 static HRESULT WINAPI
ddraw7_GetMonitorFrequency(IDirectDraw7
*iface
, DWORD
*Freq
)
1585 FIXME("iface %p, frequency %p stub!\n", iface
, Freq
);
1587 /* Ideally this should be in WineD3D, as it concerns the screen setup,
1588 * but for now this should make the games happy
1594 static HRESULT WINAPI
ddraw4_GetMonitorFrequency(IDirectDraw4
*iface
, DWORD
*frequency
)
1596 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1598 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1600 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1603 static HRESULT WINAPI
ddraw2_GetMonitorFrequency(IDirectDraw2
*iface
, DWORD
*frequency
)
1605 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1607 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1609 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1612 static HRESULT WINAPI
ddraw1_GetMonitorFrequency(IDirectDraw
*iface
, DWORD
*frequency
)
1614 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1616 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1618 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1621 /*****************************************************************************
1622 * IDirectDraw7::GetVerticalBlankStatus
1624 * Returns the Vertical blank status of the monitor. This should be in WineD3D
1625 * too basically, but as it's a semi stub, I didn't create a function there
1628 * status: Pointer to a BOOL to be filled with the vertical blank status
1632 * DDERR_INVALIDPARAMS if status is NULL
1634 *****************************************************************************/
1635 static HRESULT WINAPI
ddraw7_GetVerticalBlankStatus(IDirectDraw7
*iface
, BOOL
*status
)
1637 static BOOL fake_vblank
;
1639 TRACE("iface %p, status %p.\n", iface
, status
);
1642 return DDERR_INVALIDPARAMS
;
1644 *status
= fake_vblank
;
1645 fake_vblank
= !fake_vblank
;
1650 static HRESULT WINAPI
ddraw4_GetVerticalBlankStatus(IDirectDraw4
*iface
, BOOL
*status
)
1652 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1654 TRACE("iface %p, status %p.\n", iface
, status
);
1656 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1659 static HRESULT WINAPI
ddraw2_GetVerticalBlankStatus(IDirectDraw2
*iface
, BOOL
*status
)
1661 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1663 TRACE("iface %p, status %p.\n", iface
, status
);
1665 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1668 static HRESULT WINAPI
ddraw1_GetVerticalBlankStatus(IDirectDraw
*iface
, BOOL
*status
)
1670 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1672 TRACE("iface %p, status %p.\n", iface
, status
);
1674 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1677 /*****************************************************************************
1678 * IDirectDraw7::GetAvailableVidMem
1680 * Returns the total and free video memory
1683 * Caps: Specifies the memory type asked for
1684 * total: Pointer to a DWORD to be filled with the total memory
1685 * free: Pointer to a DWORD to be filled with the free memory
1689 * DDERR_INVALIDPARAMS of free and total are NULL
1691 *****************************************************************************/
1692 static HRESULT WINAPI
ddraw7_GetAvailableVidMem(IDirectDraw7
*iface
, DDSCAPS2
*Caps
, DWORD
*total
,
1695 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1698 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, Caps
, total
, free
);
1700 if (TRACE_ON(ddraw
))
1702 TRACE("Asked for memory with description: ");
1703 DDRAW_dump_DDSCAPS2(Caps
);
1705 wined3d_mutex_lock();
1707 /* Todo: System memory vs local video memory vs non-local video memory
1708 * The MSDN also mentions differences between texture memory and other
1709 * resources, but that's not important
1712 if( (!total
) && (!free
) )
1714 wined3d_mutex_unlock();
1715 return DDERR_INVALIDPARAMS
;
1719 *free
= wined3d_device_get_available_texture_mem(ddraw
->wined3d_device
);
1722 struct wined3d_adapter_identifier desc
= {0};
1724 hr
= wined3d_get_adapter_identifier(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, 0, &desc
);
1725 *total
= desc
.video_memory
;
1728 wined3d_mutex_unlock();
1733 static HRESULT WINAPI
ddraw4_GetAvailableVidMem(IDirectDraw4
*iface
,
1734 DDSCAPS2
*caps
, DWORD
*total
, DWORD
*free
)
1736 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1738 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1740 return ddraw7_GetAvailableVidMem(&ddraw
->IDirectDraw7_iface
, caps
, total
, free
);
1743 static HRESULT WINAPI
ddraw2_GetAvailableVidMem(IDirectDraw2
*iface
,
1744 DDSCAPS
*caps
, DWORD
*total
, DWORD
*free
)
1746 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1749 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1751 DDRAW_Convert_DDSCAPS_1_To_2(caps
, &caps2
);
1752 return ddraw7_GetAvailableVidMem(&ddraw
->IDirectDraw7_iface
, &caps2
, total
, free
);
1755 /*****************************************************************************
1756 * IDirectDraw7::Initialize
1758 * Initializes a DirectDraw interface.
1761 * GUID: Interface identifier. Well, don't know what this is really good
1765 * Returns DD_OK on the first call,
1766 * DDERR_ALREADYINITIALIZED on repeated calls
1768 *****************************************************************************/
1769 static HRESULT WINAPI
ddraw7_Initialize(IDirectDraw7
*iface
, GUID
*guid
)
1771 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1773 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1775 if (ddraw
->initialized
)
1776 return DDERR_ALREADYINITIALIZED
;
1778 /* FIXME: To properly take the GUID into account we should call
1779 * ddraw_init() here instead of in DDRAW_Create(). */
1781 FIXME("Ignoring guid %s.\n", debugstr_guid(guid
));
1783 ddraw
->initialized
= TRUE
;
1787 static HRESULT WINAPI
ddraw4_Initialize(IDirectDraw4
*iface
, GUID
*guid
)
1789 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1791 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1793 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
1796 static HRESULT WINAPI
ddraw2_Initialize(IDirectDraw2
*iface
, GUID
*guid
)
1798 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1800 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1802 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
1805 static HRESULT WINAPI
ddraw1_Initialize(IDirectDraw
*iface
, GUID
*guid
)
1807 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1809 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1811 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
1814 static HRESULT WINAPI
d3d1_Initialize(IDirect3D
*iface
, REFIID riid
)
1816 TRACE("iface %p, riid %s.\n", iface
, debugstr_guid(riid
));
1818 return DDERR_ALREADYINITIALIZED
;
1821 /*****************************************************************************
1822 * IDirectDraw7::FlipToGDISurface
1824 * "Makes the surface that the GDI writes to the primary surface"
1825 * Looks like some windows specific thing we don't have to care about.
1826 * According to MSDN it permits GDI dialog boxes in FULLSCREEN mode. Good to
1827 * show error boxes ;)
1828 * Well, just return DD_OK.
1831 * Always returns DD_OK
1833 *****************************************************************************/
1834 static HRESULT WINAPI
ddraw7_FlipToGDISurface(IDirectDraw7
*iface
)
1836 FIXME("iface %p stub!\n", iface
);
1841 static HRESULT WINAPI
ddraw4_FlipToGDISurface(IDirectDraw4
*iface
)
1843 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1845 TRACE("iface %p.\n", iface
);
1847 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
1850 static HRESULT WINAPI
ddraw2_FlipToGDISurface(IDirectDraw2
*iface
)
1852 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1854 TRACE("iface %p.\n", iface
);
1856 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
1859 static HRESULT WINAPI
ddraw1_FlipToGDISurface(IDirectDraw
*iface
)
1861 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1863 TRACE("iface %p.\n", iface
);
1865 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
1868 /*****************************************************************************
1869 * IDirectDraw7::WaitForVerticalBlank
1871 * This method allows applications to get in sync with the vertical blank
1873 * The wormhole demo in the DirectX 7 sdk uses this call, and it doesn't
1874 * redraw the screen, most likely because of this stub
1877 * Flags: one of DDWAITVB_BLOCKBEGIN, DDWAITVB_BLOCKBEGINEVENT
1878 * or DDWAITVB_BLOCKEND
1879 * h: Not used, according to MSDN
1882 * Always returns DD_OK
1884 *****************************************************************************/
1885 static HRESULT WINAPI
ddraw7_WaitForVerticalBlank(IDirectDraw7
*iface
, DWORD Flags
, HANDLE event
)
1889 TRACE("iface %p, flags %#x, event %p.\n", iface
, Flags
, event
);
1891 /* This function is called often, so print the fixme only once */
1894 FIXME("iface %p, flags %#x, event %p stub!\n", iface
, Flags
, event
);
1898 /* MSDN says DDWAITVB_BLOCKBEGINEVENT is not supported */
1899 if(Flags
& DDWAITVB_BLOCKBEGINEVENT
)
1900 return DDERR_UNSUPPORTED
; /* unchecked */
1905 static HRESULT WINAPI
ddraw4_WaitForVerticalBlank(IDirectDraw4
*iface
, DWORD flags
, HANDLE event
)
1907 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1909 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
1911 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
1914 static HRESULT WINAPI
ddraw2_WaitForVerticalBlank(IDirectDraw2
*iface
, DWORD flags
, HANDLE event
)
1916 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1918 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
1920 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
1923 static HRESULT WINAPI
ddraw1_WaitForVerticalBlank(IDirectDraw
*iface
, DWORD flags
, HANDLE event
)
1925 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1927 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
1929 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
1932 /*****************************************************************************
1933 * IDirectDraw7::GetScanLine
1935 * Returns the scan line that is being drawn on the monitor
1938 * Scanline: Address to write the scan line value to
1941 * Always returns DD_OK
1943 *****************************************************************************/
1944 static HRESULT WINAPI
ddraw7_GetScanLine(IDirectDraw7
*iface
, DWORD
*Scanline
)
1946 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1947 struct wined3d_display_mode mode
;
1948 static BOOL hide
= FALSE
;
1949 DWORD time
, frame_progress
, lines
;
1951 TRACE("iface %p, line %p.\n", iface
, Scanline
);
1953 /* This function is called often, so print the fixme only once */
1956 FIXME("iface %p, line %p partial stub!\n", iface
, Scanline
);
1960 wined3d_mutex_lock();
1961 wined3d_device_get_display_mode(ddraw
->wined3d_device
, 0, &mode
);
1962 wined3d_mutex_unlock();
1964 /* Fake the line sweeping of the monitor */
1965 /* FIXME: We should synchronize with a source to keep the refresh rate */
1967 /* Simulate a 60Hz display */
1968 time
= GetTickCount();
1969 frame_progress
= time
& 15; /* time % (1000 / 60) */
1970 if (!frame_progress
)
1973 return DDERR_VERTICALBLANKINPROGRESS
;
1976 /* Convert frame_progress to estimated scan line. Return any line from
1977 * block determined by time. Some lines may be never returned */
1978 lines
= mode
.height
/ 15;
1979 *Scanline
= (frame_progress
- 1) * lines
+ time
% lines
;
1983 static HRESULT WINAPI
ddraw4_GetScanLine(IDirectDraw4
*iface
, DWORD
*line
)
1985 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1987 TRACE("iface %p, line %p.\n", iface
, line
);
1989 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
1992 static HRESULT WINAPI
ddraw2_GetScanLine(IDirectDraw2
*iface
, DWORD
*line
)
1994 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1996 TRACE("iface %p, line %p.\n", iface
, line
);
1998 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
2001 static HRESULT WINAPI
ddraw1_GetScanLine(IDirectDraw
*iface
, DWORD
*line
)
2003 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2005 TRACE("iface %p, line %p.\n", iface
, line
);
2007 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
2010 /*****************************************************************************
2011 * IDirectDraw7::TestCooperativeLevel
2013 * Informs the application about the state of the video adapter, depending
2014 * on the cooperative level
2017 * DD_OK if the device is in a sane state
2018 * DDERR_NOEXCLUSIVEMODE or DDERR_EXCLUSIVEMODEALREADYSET
2019 * if the state is not correct(See below)
2021 *****************************************************************************/
2022 static HRESULT WINAPI
ddraw7_TestCooperativeLevel(IDirectDraw7
*iface
)
2024 TRACE("iface %p.\n", iface
);
2029 static HRESULT WINAPI
ddraw4_TestCooperativeLevel(IDirectDraw4
*iface
)
2031 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2033 TRACE("iface %p.\n", iface
);
2035 return ddraw7_TestCooperativeLevel(&ddraw
->IDirectDraw7_iface
);
2038 /*****************************************************************************
2039 * IDirectDraw7::GetGDISurface
2041 * Returns the surface that GDI is treating as the primary surface.
2042 * For Wine this is the front buffer
2045 * GDISurface: Address to write the surface pointer to
2048 * DD_OK if the surface was found
2049 * DDERR_NOTFOUND if the GDI surface wasn't found
2051 *****************************************************************************/
2052 static HRESULT WINAPI
ddraw7_GetGDISurface(IDirectDraw7
*iface
, IDirectDrawSurface7
**GDISurface
)
2054 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2056 TRACE("iface %p, surface %p.\n", iface
, GDISurface
);
2058 wined3d_mutex_lock();
2060 if (!(*GDISurface
= &ddraw
->primary
->IDirectDrawSurface7_iface
))
2062 WARN("Primary not created yet.\n");
2063 wined3d_mutex_unlock();
2064 return DDERR_NOTFOUND
;
2066 IDirectDrawSurface7_AddRef(*GDISurface
);
2068 wined3d_mutex_unlock();
2073 static HRESULT WINAPI
ddraw4_GetGDISurface(IDirectDraw4
*iface
, IDirectDrawSurface4
**surface
)
2075 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2076 struct ddraw_surface
*surface_impl
;
2077 IDirectDrawSurface7
*surface7
;
2080 TRACE("iface %p, surface %p.\n", iface
, surface
);
2082 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2088 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2089 *surface
= &surface_impl
->IDirectDrawSurface4_iface
;
2090 IDirectDrawSurface4_AddRef(*surface
);
2091 IDirectDrawSurface7_Release(surface7
);
2096 static HRESULT WINAPI
ddraw2_GetGDISurface(IDirectDraw2
*iface
, IDirectDrawSurface
**surface
)
2098 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2099 struct ddraw_surface
*surface_impl
;
2100 IDirectDrawSurface7
*surface7
;
2103 TRACE("iface %p, surface %p.\n", iface
, surface
);
2105 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2111 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2112 *surface
= &surface_impl
->IDirectDrawSurface_iface
;
2113 IDirectDrawSurface_AddRef(*surface
);
2114 IDirectDrawSurface7_Release(surface7
);
2119 static HRESULT WINAPI
ddraw1_GetGDISurface(IDirectDraw
*iface
, IDirectDrawSurface
**surface
)
2121 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2122 struct ddraw_surface
*surface_impl
;
2123 IDirectDrawSurface7
*surface7
;
2126 TRACE("iface %p, surface %p.\n", iface
, surface
);
2128 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2134 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2135 *surface
= &surface_impl
->IDirectDrawSurface_iface
;
2136 IDirectDrawSurface_AddRef(*surface
);
2137 IDirectDrawSurface7_Release(surface7
);
2142 struct displaymodescallback_context
2144 LPDDENUMMODESCALLBACK func
;
2148 static HRESULT CALLBACK
EnumDisplayModesCallbackThunk(DDSURFACEDESC2
*surface_desc
, void *context
)
2150 struct displaymodescallback_context
*cbcontext
= context
;
2153 DDSD2_to_DDSD(surface_desc
, &desc
);
2154 return cbcontext
->func(&desc
, cbcontext
->context
);
2157 /*****************************************************************************
2158 * IDirectDraw7::EnumDisplayModes
2160 * Enumerates the supported Display modes. The modes can be filtered with
2161 * the DDSD parameter.
2164 * Flags: can be DDEDM_REFRESHRATES and DDEDM_STANDARDVGAMODES. For old ddraw
2165 * versions (3 and older?) this is reserved and must be 0.
2166 * DDSD: Surface description to filter the modes
2167 * Context: Pointer passed back to the callback function
2168 * cb: Application-provided callback function
2172 * DDERR_INVALIDPARAMS if the callback wasn't set
2174 *****************************************************************************/
2175 static HRESULT WINAPI
ddraw7_EnumDisplayModes(IDirectDraw7
*iface
, DWORD Flags
,
2176 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMMODESCALLBACK2 cb
)
2178 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2179 struct wined3d_display_mode
*enum_modes
= NULL
;
2180 struct wined3d_display_mode mode
;
2181 unsigned int modenum
, fmt
;
2182 DDSURFACEDESC2 callback_sd
;
2183 unsigned enum_mode_count
= 0, enum_mode_array_size
= 0;
2184 DDPIXELFORMAT pixelformat
;
2186 static const enum wined3d_format_id checkFormatList
[] =
2188 WINED3DFMT_B8G8R8X8_UNORM
,
2189 WINED3DFMT_B5G6R5_UNORM
,
2193 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2194 iface
, Flags
, DDSD
, Context
, cb
);
2197 return DDERR_INVALIDPARAMS
;
2199 wined3d_mutex_lock();
2200 if(!(Flags
& DDEDM_REFRESHRATES
))
2202 enum_mode_array_size
= 16;
2203 enum_modes
= HeapAlloc(GetProcessHeap(), 0, sizeof(*enum_modes
) * enum_mode_array_size
);
2206 ERR("Out of memory\n");
2207 wined3d_mutex_unlock();
2208 return DDERR_OUTOFMEMORY
;
2212 pixelformat
.dwSize
= sizeof(pixelformat
);
2213 for(fmt
= 0; fmt
< (sizeof(checkFormatList
) / sizeof(checkFormatList
[0])); fmt
++)
2216 while (wined3d_enum_adapter_modes(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
,
2217 checkFormatList
[fmt
], modenum
++, &mode
) == WINED3D_OK
)
2219 PixelFormat_WineD3DtoDD(&pixelformat
, mode
.format_id
);
2222 if (DDSD
->dwFlags
& DDSD_WIDTH
&& mode
.width
!= DDSD
->dwWidth
)
2224 if (DDSD
->dwFlags
& DDSD_HEIGHT
&& mode
.height
!= DDSD
->dwHeight
)
2226 if (DDSD
->dwFlags
& DDSD_REFRESHRATE
&& mode
.refresh_rate
!= DDSD
->u2
.dwRefreshRate
)
2228 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
2229 && pixelformat
.u1
.dwRGBBitCount
!= DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
)
2233 if(!(Flags
& DDEDM_REFRESHRATES
))
2235 /* DX docs state EnumDisplayMode should return only unique modes. If DDEDM_REFRESHRATES is not set, refresh
2236 * rate doesn't matter when determining if the mode is unique. So modes only differing in refresh rate have
2237 * to be reduced to a single unique result in such case.
2242 for (i
= 0; i
< enum_mode_count
; i
++)
2244 if (enum_modes
[i
].width
== mode
.width
&& enum_modes
[i
].height
== mode
.height
2245 && enum_modes
[i
].format_id
== mode
.format_id
)
2255 memset(&callback_sd
, 0, sizeof(callback_sd
));
2256 callback_sd
.dwSize
= sizeof(callback_sd
);
2257 callback_sd
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
2259 callback_sd
.dwFlags
= DDSD_HEIGHT
|DDSD_WIDTH
|DDSD_PIXELFORMAT
|DDSD_PITCH
|DDSD_REFRESHRATE
;
2260 if (Flags
& DDEDM_REFRESHRATES
)
2261 callback_sd
.u2
.dwRefreshRate
= mode
.refresh_rate
;
2263 callback_sd
.dwWidth
= mode
.width
;
2264 callback_sd
.dwHeight
= mode
.height
;
2266 callback_sd
.u4
.ddpfPixelFormat
=pixelformat
;
2268 /* Calc pitch and DWORD align like MSDN says */
2269 callback_sd
.u1
.lPitch
= (callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8) * mode
.width
;
2270 callback_sd
.u1
.lPitch
= (callback_sd
.u1
.lPitch
+ 3) & ~3;
2272 TRACE("Enumerating %dx%dx%d @%d\n", callback_sd
.dwWidth
, callback_sd
.dwHeight
, callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
,
2273 callback_sd
.u2
.dwRefreshRate
);
2275 if(cb(&callback_sd
, Context
) == DDENUMRET_CANCEL
)
2277 TRACE("Application asked to terminate the enumeration\n");
2278 HeapFree(GetProcessHeap(), 0, enum_modes
);
2279 wined3d_mutex_unlock();
2283 if(!(Flags
& DDEDM_REFRESHRATES
))
2285 if (enum_mode_count
== enum_mode_array_size
)
2287 struct wined3d_display_mode
*new_enum_modes
;
2289 enum_mode_array_size
*= 2;
2290 new_enum_modes
= HeapReAlloc(GetProcessHeap(), 0, enum_modes
,
2291 sizeof(*new_enum_modes
) * enum_mode_array_size
);
2292 if (!new_enum_modes
)
2294 ERR("Out of memory\n");
2295 HeapFree(GetProcessHeap(), 0, enum_modes
);
2296 wined3d_mutex_unlock();
2297 return DDERR_OUTOFMEMORY
;
2300 enum_modes
= new_enum_modes
;
2303 enum_modes
[enum_mode_count
++] = mode
;
2308 TRACE("End of enumeration\n");
2309 HeapFree(GetProcessHeap(), 0, enum_modes
);
2310 wined3d_mutex_unlock();
2315 static HRESULT WINAPI
ddraw4_EnumDisplayModes(IDirectDraw4
*iface
, DWORD flags
,
2316 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK2 callback
)
2318 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2320 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2321 iface
, flags
, surface_desc
, context
, callback
);
2323 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
, surface_desc
, context
, callback
);
2326 static HRESULT WINAPI
ddraw2_EnumDisplayModes(IDirectDraw2
*iface
, DWORD flags
,
2327 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2329 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2330 struct displaymodescallback_context cbcontext
;
2331 DDSURFACEDESC2 surface_desc2
;
2333 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2334 iface
, flags
, surface_desc
, context
, callback
);
2336 cbcontext
.func
= callback
;
2337 cbcontext
.context
= context
;
2339 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2340 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
,
2341 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2344 static HRESULT WINAPI
ddraw1_EnumDisplayModes(IDirectDraw
*iface
, DWORD flags
,
2345 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2347 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2348 struct displaymodescallback_context cbcontext
;
2349 DDSURFACEDESC2 surface_desc2
;
2351 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2352 iface
, flags
, surface_desc
, context
, callback
);
2354 cbcontext
.func
= callback
;
2355 cbcontext
.context
= context
;
2357 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2358 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
,
2359 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2362 /*****************************************************************************
2363 * IDirectDraw7::EvaluateMode
2365 * Used with IDirectDraw7::StartModeTest to test video modes.
2366 * EvaluateMode is used to pass or fail a mode, and continue with the next
2370 * Flags: DDEM_MODEPASSED or DDEM_MODEFAILED
2371 * Timeout: Returns the amount of seconds left before the mode would have
2372 * been failed automatically
2375 * This implementation always DD_OK, because it's a stub
2377 *****************************************************************************/
2378 static HRESULT WINAPI
ddraw7_EvaluateMode(IDirectDraw7
*iface
, DWORD Flags
, DWORD
*Timeout
)
2380 FIXME("iface %p, flags %#x, timeout %p stub!\n", iface
, Flags
, Timeout
);
2382 /* When implementing this, implement it in WineD3D */
2387 /*****************************************************************************
2388 * IDirectDraw7::GetDeviceIdentifier
2390 * Returns the device identifier, which gives information about the driver
2391 * Our device identifier is defined at the beginning of this file.
2394 * DDDI: Address for the returned structure
2395 * Flags: Can be DDGDI_GETHOSTIDENTIFIER
2398 * On success it returns DD_OK
2399 * DDERR_INVALIDPARAMS if DDDI is NULL
2401 *****************************************************************************/
2402 static HRESULT WINAPI
ddraw7_GetDeviceIdentifier(IDirectDraw7
*iface
,
2403 DDDEVICEIDENTIFIER2
*DDDI
, DWORD Flags
)
2405 TRACE("iface %p, device_identifier %p, flags %#x.\n", iface
, DDDI
, Flags
);
2408 return DDERR_INVALIDPARAMS
;
2410 /* The DDGDI_GETHOSTIDENTIFIER returns the information about the 2D
2411 * host adapter, if there's a secondary 3D adapter. This doesn't apply
2412 * to any modern hardware, nor is it interesting for Wine, so ignore it.
2413 * Size of DDDEVICEIDENTIFIER2 may be aligned to 8 bytes and thus 4
2414 * bytes too long. So only copy the relevant part of the structure
2417 memcpy(DDDI
, &deviceidentifier
, FIELD_OFFSET(DDDEVICEIDENTIFIER2
, dwWHQLLevel
) + sizeof(DWORD
));
2421 static HRESULT WINAPI
ddraw4_GetDeviceIdentifier(IDirectDraw4
*iface
,
2422 DDDEVICEIDENTIFIER
*identifier
, DWORD flags
)
2424 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2425 DDDEVICEIDENTIFIER2 identifier2
;
2428 TRACE("iface %p, identifier %p, flags %#x.\n", iface
, identifier
, flags
);
2430 hr
= ddraw7_GetDeviceIdentifier(&ddraw
->IDirectDraw7_iface
, &identifier2
, flags
);
2431 DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(&identifier2
, identifier
);
2436 /*****************************************************************************
2437 * IDirectDraw7::GetSurfaceFromDC
2439 * Returns the Surface for a GDI device context handle.
2440 * Is this related to IDirectDrawSurface::GetDC ???
2443 * hdc: hdc to return the surface for
2444 * Surface: Address to write the surface pointer to
2447 * Always returns DD_OK because it's a stub
2449 *****************************************************************************/
2450 static HRESULT WINAPI
ddraw7_GetSurfaceFromDC(IDirectDraw7
*iface
, HDC hdc
,
2451 IDirectDrawSurface7
**Surface
)
2453 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2454 struct wined3d_surface
*wined3d_surface
;
2455 struct ddraw_surface
*surface_impl
;
2458 TRACE("iface %p, dc %p, surface %p.\n", iface
, hdc
, Surface
);
2460 if (!Surface
) return E_INVALIDARG
;
2462 hr
= wined3d_device_get_surface_from_dc(ddraw
->wined3d_device
, hdc
, &wined3d_surface
);
2465 TRACE("No surface found for dc %p.\n", hdc
);
2467 return DDERR_NOTFOUND
;
2470 surface_impl
= wined3d_surface_get_parent(wined3d_surface
);
2471 *Surface
= &surface_impl
->IDirectDrawSurface7_iface
;
2472 IDirectDrawSurface7_AddRef(*Surface
);
2473 TRACE("Returning surface %p.\n", Surface
);
2477 static HRESULT WINAPI
ddraw4_GetSurfaceFromDC(IDirectDraw4
*iface
, HDC dc
,
2478 IDirectDrawSurface4
**surface
)
2480 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2481 struct ddraw_surface
*surface_impl
;
2482 IDirectDrawSurface7
*surface7
;
2485 TRACE("iface %p, dc %p, surface %p.\n", iface
, dc
, surface
);
2487 if (!surface
) return E_INVALIDARG
;
2489 hr
= ddraw7_GetSurfaceFromDC(&ddraw
->IDirectDraw7_iface
, dc
, &surface7
);
2495 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2496 /* Tests say this is true */
2497 *surface
= (IDirectDrawSurface4
*)&surface_impl
->IDirectDrawSurface_iface
;
2498 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
2499 IDirectDrawSurface7_Release(surface7
);
2504 /*****************************************************************************
2505 * IDirectDraw7::RestoreAllSurfaces
2507 * Calls the restore method of all surfaces
2512 * Always returns DD_OK because it's a stub
2514 *****************************************************************************/
2515 static HRESULT WINAPI
ddraw7_RestoreAllSurfaces(IDirectDraw7
*iface
)
2517 FIXME("iface %p stub!\n", iface
);
2519 /* This isn't hard to implement: Enumerate all WineD3D surfaces,
2520 * get their parent and call their restore method. Do not implement
2521 * it in WineD3D, as restoring a surface means re-creating the
2527 static HRESULT WINAPI
ddraw4_RestoreAllSurfaces(IDirectDraw4
*iface
)
2529 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2531 TRACE("iface %p.\n", iface
);
2533 return ddraw7_RestoreAllSurfaces(&ddraw
->IDirectDraw7_iface
);
2536 /*****************************************************************************
2537 * IDirectDraw7::StartModeTest
2539 * Tests the specified video modes to update the system registry with
2540 * refresh rate information. StartModeTest starts the mode test,
2541 * EvaluateMode is used to fail or pass a mode. If EvaluateMode
2542 * isn't called within 15 seconds, the mode is failed automatically
2544 * As refresh rates are handled by the X server, I don't think this
2545 * Method is important
2548 * Modes: An array of mode specifications
2549 * NumModes: The number of modes in Modes
2550 * Flags: Some flags...
2553 * Returns DDERR_TESTFINISHED if flags contains DDSMT_ISTESTREQUIRED,
2554 * if no modes are passed, DDERR_INVALIDPARAMS is returned,
2557 *****************************************************************************/
2558 static HRESULT WINAPI
ddraw7_StartModeTest(IDirectDraw7
*iface
, SIZE
*Modes
, DWORD NumModes
, DWORD Flags
)
2560 FIXME("iface %p, modes %p, mode_count %u, flags %#x partial stub!\n",
2561 iface
, Modes
, NumModes
, Flags
);
2563 /* This looks sane */
2564 if( (!Modes
) || (NumModes
== 0) ) return DDERR_INVALIDPARAMS
;
2566 /* DDSMT_ISTESTREQUIRED asks if a mode test is necessary.
2567 * As it is not, DDERR_TESTFINISHED is returned
2568 * (hopefully that's correct
2570 if(Flags & DDSMT_ISTESTREQUIRED) return DDERR_TESTFINISHED;
2571 * well, that value doesn't (yet) exist in the wine headers, so ignore it
2577 /*****************************************************************************
2578 * ddraw_create_surface
2580 * A helper function for IDirectDraw7::CreateSurface. It creates a new surface
2581 * with the passed parameters.
2584 * DDSD: Description of the surface to create
2585 * Surf: Address to store the interface pointer at
2590 *****************************************************************************/
2591 static HRESULT
ddraw_create_surface(struct ddraw
*ddraw
, DDSURFACEDESC2
*pDDSD
,
2592 struct ddraw_surface
**surface
, UINT level
, UINT version
)
2596 TRACE("ddraw %p, surface_desc %p, surface %p, level %u.\n",
2597 ddraw
, pDDSD
, surface
, level
);
2599 if (TRACE_ON(ddraw
))
2601 TRACE("Requesting surface desc:\n");
2602 DDRAW_dump_surface_desc(pDDSD
);
2605 if ((pDDSD
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
) && DefaultSurfaceType
!= WINED3D_SURFACE_TYPE_OPENGL
)
2607 WARN("The application requests a 3D capable surface, but a non-OpenGL surface type was set in the registry.\n");
2608 /* Do not fail surface creation, only fail 3D device creation. */
2611 /* Create the Surface object */
2612 *surface
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(**surface
));
2615 ERR("Failed to allocate surface memory.\n");
2616 return DDERR_OUTOFVIDEOMEMORY
;
2619 hr
= ddraw_surface_init(*surface
, ddraw
, pDDSD
, level
, version
);
2622 WARN("Failed to initialize surface, hr %#x.\n", hr
);
2623 HeapFree(GetProcessHeap(), 0, *surface
);
2627 /* Increase the surface counter, and attach the surface */
2628 list_add_head(&ddraw
->surface_list
, &(*surface
)->surface_list_entry
);
2630 TRACE("Created surface %p.\n", *surface
);
2634 /*****************************************************************************
2635 * CreateAdditionalSurfaces
2637 * Creates a new mipmap chain.
2640 * root: Root surface to attach the newly created chain to
2641 * count: number of surfaces to create
2642 * DDSD: Description of the surface. Intentionally not a pointer to avoid side
2643 * effects on the caller
2644 * CubeFaceRoot: Whether the new surface is a root of a cube map face. This
2645 * creates an additional surface without the mipmapping flags
2647 *****************************************************************************/
2648 static HRESULT
CreateAdditionalSurfaces(struct ddraw
*ddraw
, struct ddraw_surface
*root
,
2649 UINT count
, DDSURFACEDESC2 DDSD
, BOOL CubeFaceRoot
, UINT version
)
2651 struct ddraw_surface
*last
= root
;
2652 UINT i
, j
, level
= 0;
2655 for (i
= 0; i
< count
; ++i
)
2657 struct ddraw_surface
*object2
= NULL
;
2659 /* increase the mipmap level, but only if a mipmap is created
2660 * In this case, also halve the size
2662 if(DDSD
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
&& !CubeFaceRoot
)
2665 if(DDSD
.dwWidth
> 1) DDSD
.dwWidth
/= 2;
2666 if(DDSD
.dwHeight
> 1) DDSD
.dwHeight
/= 2;
2667 /* Set the mipmap sublevel flag according to msdn */
2668 DDSD
.ddsCaps
.dwCaps2
|= DDSCAPS2_MIPMAPSUBLEVEL
;
2672 DDSD
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
2674 CubeFaceRoot
= FALSE
;
2676 hr
= ddraw_create_surface(ddraw
, &DDSD
, &object2
, level
, version
);
2682 /* Add the new surface to the complex attachment array */
2683 for(j
= 0; j
< MAX_COMPLEX_ATTACHED
; j
++)
2685 if(last
->complex_array
[j
]) continue;
2686 last
->complex_array
[j
] = object2
;
2691 /* Remove the (possible) back buffer cap from the new surface description,
2692 * because only one surface in the flipping chain is a back buffer, one
2693 * is a front buffer, the others are just primary surfaces.
2695 DDSD
.ddsCaps
.dwCaps
&= ~DDSCAPS_BACKBUFFER
;
2700 static HRESULT CDECL
ddraw_reset_enum_callback(struct wined3d_resource
*resource
)
2705 /*****************************************************************************
2706 * IDirectDraw7::CreateSurface
2708 * Creates a new IDirectDrawSurface object and returns its interface.
2710 * The surface connections with wined3d are a bit tricky. Basically it works
2713 * |------------------------| |-----------------|
2714 * | DDraw surface | | WineD3DSurface |
2716 * | WineD3DSurface |-------------->| |
2717 * | Child |<------------->| Parent |
2718 * |------------------------| |-----------------|
2720 * The DDraw surface is the parent of the wined3d surface, and it releases
2721 * the WineD3DSurface when the ddraw surface is destroyed.
2723 * However, for all surfaces which can be in a container in WineD3D,
2724 * we have to do this. These surfaces are usually complex surfaces,
2725 * so this concerns primary surfaces with a front and a back buffer,
2728 * |------------------------| |-----------------|
2729 * | DDraw surface | | Container |
2731 * | Child |<------------->| Parent |
2732 * | Texture |<------------->| |
2733 * | WineD3DSurface |<----| | Levels |<--|
2734 * | Complex connection | | | | |
2735 * |------------------------| | |-----------------| |
2739 * | |------------------| | |-----------------| |
2740 * | | IParent | |-------->| WineD3DSurface | |
2742 * | | Child |<------------->| Parent | |
2743 * | | | | Container |<--|
2744 * | |------------------| |-----------------| |
2746 * | |----------------------| |
2747 * | | DDraw surface 2 | |
2749 * |<->| Complex root Child | |
2751 * | | WineD3DSurface |<----| |
2752 * | |----------------------| | |
2754 * | |---------------------| | |-----------------| |
2755 * | | IParent | |----->| WineD3DSurface | |
2757 * | | Child |<---------->| Parent | |
2758 * | |---------------------| | Container |<--|
2759 * | |-----------------| |
2761 * | ---More surfaces can follow--- |
2763 * The reason is that the IWineD3DSwapchain(render target container)
2764 * and the IWineD3DTexure(Texture container) release the parents
2765 * of their surface's children, but by releasing the complex root
2766 * the surfaces which are complexly attached to it are destroyed
2767 * too. See IDirectDrawSurface::Release for a more detailed
2771 * DDSD: Description of the surface to create
2772 * Surf: Address to store the interface pointer at
2773 * UnkOuter: Basically for aggregation support, but ddraw doesn't support
2774 * aggregation, so it has to be NULL
2778 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
2779 * DDERR_* if an error occurs
2781 *****************************************************************************/
2782 static HRESULT
CreateSurface(struct ddraw
*ddraw
, DDSURFACEDESC2
*DDSD
,
2783 struct ddraw_surface
**surface
, IUnknown
*UnkOuter
, UINT version
)
2785 struct ddraw_surface
*object
= NULL
;
2786 struct wined3d_display_mode mode
;
2788 LONG extra_surfaces
= 0;
2789 DDSURFACEDESC2 desc2
;
2790 const DWORD sysvidmem
= DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
2792 TRACE("ddraw %p, surface_desc %p, surface %p, outer_unknown %p.\n", ddraw
, DDSD
, surface
, UnkOuter
);
2794 /* Some checks before we start */
2795 if (TRACE_ON(ddraw
))
2797 TRACE(" (%p) Requesting surface desc :\n", ddraw
);
2798 DDRAW_dump_surface_desc(DDSD
);
2801 if (UnkOuter
!= NULL
)
2803 FIXME("(%p) : outer != NULL?\n", ddraw
);
2804 return CLASS_E_NOAGGREGATION
; /* unchecked */
2809 FIXME("(%p) You want to get back a surface? Don't give NULL ptrs!\n", ddraw
);
2810 return E_POINTER
; /* unchecked */
2813 if (!(DDSD
->dwFlags
& DDSD_CAPS
))
2815 /* DVIDEO.DLL does forget the DDSD_CAPS flag ... *sigh* */
2816 DDSD
->dwFlags
|= DDSD_CAPS
;
2819 if (DDSD
->ddsCaps
.dwCaps
& DDSCAPS_ALLOCONLOAD
)
2821 /* If the surface is of the 'alloconload' type, ignore the LPSURFACE field */
2822 DDSD
->dwFlags
&= ~DDSD_LPSURFACE
;
2825 if ((DDSD
->dwFlags
& DDSD_LPSURFACE
) && (DDSD
->lpSurface
== NULL
))
2827 /* Frank Herbert's Dune specifies a null pointer for the surface, ignore the LPSURFACE field */
2828 WARN("(%p) Null surface pointer specified, ignore it!\n", ddraw
);
2829 DDSD
->dwFlags
&= ~DDSD_LPSURFACE
;
2832 if((DDSD
->ddsCaps
.dwCaps
& (DDSCAPS_FLIP
| DDSCAPS_PRIMARYSURFACE
)) == (DDSCAPS_FLIP
| DDSCAPS_PRIMARYSURFACE
) &&
2833 !(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
))
2835 TRACE("(%p): Attempt to create a flipable primary surface without DDSCL_EXCLUSIVE set\n",
2838 return DDERR_NOEXCLUSIVEMODE
;
2841 if((DDSD
->ddsCaps
.dwCaps
& (DDSCAPS_BACKBUFFER
| DDSCAPS_PRIMARYSURFACE
)) == (DDSCAPS_BACKBUFFER
| DDSCAPS_PRIMARYSURFACE
))
2843 WARN("Application wanted to create back buffer primary surface\n");
2844 return DDERR_INVALIDCAPS
;
2847 if((DDSD
->ddsCaps
.dwCaps
& sysvidmem
) == sysvidmem
)
2849 /* This is a special switch in ddrawex.dll, but not allowed in ddraw.dll */
2850 WARN("Application tries to put the surface in both system and video memory\n");
2852 return DDERR_INVALIDCAPS
;
2855 /* Check cube maps but only if the size includes them */
2856 if (DDSD
->dwSize
>= sizeof(DDSURFACEDESC2
))
2858 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
&&
2859 !(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
))
2861 WARN("Cube map faces requested without cube map flag\n");
2862 return DDERR_INVALIDCAPS
;
2864 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
&&
2865 (DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
) == 0)
2867 WARN("Cube map without faces requested\n");
2868 return DDERR_INVALIDPARAMS
;
2871 /* Quick tests confirm those can be created, but we don't do that yet */
2872 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
&&
2873 (DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
) != DDSCAPS2_CUBEMAP_ALLFACES
)
2875 FIXME("Partial cube maps not supported yet\n");
2879 /* According to the msdn this flag is ignored by CreateSurface */
2880 if (DDSD
->dwSize
>= sizeof(DDSURFACEDESC2
))
2881 DDSD
->ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
2883 /* Modify some flags */
2884 copy_to_surfacedesc2(&desc2
, DDSD
);
2885 desc2
.u4
.ddpfPixelFormat
.dwSize
=sizeof(DDPIXELFORMAT
); /* Just to be sure */
2887 /* Get the video mode from WineD3D - we will need it */
2888 hr
= wined3d_device_get_display_mode(ddraw
->wined3d_device
, 0, &mode
);
2891 ERR("Failed to read display mode from wined3d\n");
2892 switch(ddraw
->orig_bpp
)
2895 mode
.format_id
= WINED3DFMT_P8_UINT
;
2899 mode
.format_id
= WINED3DFMT_B5G5R5X1_UNORM
;
2903 mode
.format_id
= WINED3DFMT_B5G6R5_UNORM
;
2907 mode
.format_id
= WINED3DFMT_B8G8R8_UNORM
;
2911 mode
.format_id
= WINED3DFMT_B8G8R8X8_UNORM
;
2914 mode
.width
= ddraw
->orig_width
;
2915 mode
.height
= ddraw
->orig_height
;
2918 /* No pixelformat given? Use the current screen format */
2919 if(!(desc2
.dwFlags
& DDSD_PIXELFORMAT
))
2921 desc2
.dwFlags
|= DDSD_PIXELFORMAT
;
2922 desc2
.u4
.ddpfPixelFormat
.dwSize
=sizeof(DDPIXELFORMAT
);
2924 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, mode
.format_id
);
2927 /* No Width or no Height? Use the original screen size
2929 if(!(desc2
.dwFlags
& DDSD_WIDTH
) ||
2930 !(desc2
.dwFlags
& DDSD_HEIGHT
) )
2932 /* Invalid for non-render targets */
2933 if(!(desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
2935 WARN("Creating a non-Primary surface without Width or Height info, returning DDERR_INVALIDPARAMS\n");
2937 return DDERR_INVALIDPARAMS
;
2940 desc2
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
2941 desc2
.dwWidth
= mode
.width
;
2942 desc2
.dwHeight
= mode
.height
;
2945 if (!desc2
.dwWidth
|| !desc2
.dwHeight
)
2946 return DDERR_INVALIDPARAMS
;
2948 /* Mipmap count fixes */
2949 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
2951 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_COMPLEX
)
2953 if(desc2
.dwFlags
& DDSD_MIPMAPCOUNT
)
2955 /* Mipmap count is given, should not be 0 */
2956 if( desc2
.u2
.dwMipMapCount
== 0 )
2957 return DDERR_INVALIDPARAMS
;
2961 /* Undocumented feature: Create sublevels until
2962 * either the width or the height is 1
2964 DWORD min
= desc2
.dwWidth
< desc2
.dwHeight
?
2965 desc2
.dwWidth
: desc2
.dwHeight
;
2966 desc2
.u2
.dwMipMapCount
= 0;
2969 desc2
.u2
.dwMipMapCount
+= 1;
2976 /* Not-complex mipmap -> Mipmapcount = 1 */
2977 desc2
.u2
.dwMipMapCount
= 1;
2979 extra_surfaces
= desc2
.u2
.dwMipMapCount
- 1;
2981 /* There's a mipmap count in the created surface in any case */
2982 desc2
.dwFlags
|= DDSD_MIPMAPCOUNT
;
2984 /* If no mipmap is given, the texture has only one level */
2986 /* The first surface is a front buffer, the back buffer is created afterwards */
2987 if( (desc2
.dwFlags
& DDSD_CAPS
) && (desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) )
2989 desc2
.ddsCaps
.dwCaps
|= DDSCAPS_FRONTBUFFER
;
2992 /* The root surface in a cube map is positive x */
2993 if(desc2
.ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
2995 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
2996 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
2999 if ((desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) && (ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
))
3001 struct wined3d_swapchain_desc swapchain_desc
;
3003 hr
= wined3d_swapchain_get_desc(ddraw
->wined3d_swapchain
, &swapchain_desc
);
3006 ERR("Failed to get present parameters.\n");
3010 swapchain_desc
.backbuffer_width
= mode
.width
;
3011 swapchain_desc
.backbuffer_height
= mode
.height
;
3012 swapchain_desc
.backbuffer_format
= mode
.format_id
;
3014 hr
= wined3d_device_reset(ddraw
->wined3d_device
,
3015 &swapchain_desc
, ddraw_reset_enum_callback
);
3018 ERR("Failed to reset device.\n");
3023 /* Create the first surface */
3024 hr
= ddraw_create_surface(ddraw
, &desc2
, &object
, 0, version
);
3027 WARN("ddraw_create_surface failed, hr %#x.\n", hr
);
3030 object
->is_complex_root
= TRUE
;
3034 /* Create Additional surfaces if necessary
3035 * This applies to Primary surfaces which have a back buffer count
3036 * set, but not to mipmap textures. In case of Mipmap textures,
3037 * wineD3D takes care of the creation of additional surfaces
3039 if(DDSD
->dwFlags
& DDSD_BACKBUFFERCOUNT
)
3041 extra_surfaces
= DDSD
->dwBackBufferCount
;
3042 desc2
.ddsCaps
.dwCaps
&= ~DDSCAPS_FRONTBUFFER
; /* It's not a front buffer */
3043 desc2
.ddsCaps
.dwCaps
|= DDSCAPS_BACKBUFFER
;
3044 desc2
.dwBackBufferCount
= 0;
3048 if(desc2
.ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
3050 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
3051 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEZ
;
3052 hr
|= CreateAdditionalSurfaces(ddraw
, object
, extra_surfaces
+ 1, desc2
, TRUE
, version
);
3053 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_NEGATIVEZ
;
3054 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEZ
;
3055 hr
|= CreateAdditionalSurfaces(ddraw
, object
, extra_surfaces
+ 1, desc2
, TRUE
, version
);
3056 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_POSITIVEZ
;
3057 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEY
;
3058 hr
|= CreateAdditionalSurfaces(ddraw
, object
, extra_surfaces
+ 1, desc2
, TRUE
, version
);
3059 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_NEGATIVEY
;
3060 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEY
;
3061 hr
|= CreateAdditionalSurfaces(ddraw
, object
, extra_surfaces
+ 1, desc2
, TRUE
, version
);
3062 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_POSITIVEY
;
3063 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEX
;
3064 hr
|= CreateAdditionalSurfaces(ddraw
, object
, extra_surfaces
+ 1, desc2
, TRUE
, version
);
3065 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_NEGATIVEX
;
3066 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
3069 hr
|= CreateAdditionalSurfaces(ddraw
, object
, extra_surfaces
, desc2
, FALSE
, version
);
3072 /* This destroys and possibly created surfaces too */
3074 IDirectDrawSurface7_Release(&object
->IDirectDrawSurface7_iface
);
3075 else if (version
== 4)
3076 IDirectDrawSurface4_Release(&object
->IDirectDrawSurface4_iface
);
3078 IDirectDrawSurface_Release(&object
->IDirectDrawSurface_iface
);
3083 if (desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
3084 ddraw
->primary
= object
;
3086 /* Create a WineD3DTexture if a texture was requested */
3087 if (desc2
.ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
3089 ddraw
->tex_root
= object
;
3090 ddraw_surface_create_texture(object
);
3091 ddraw
->tex_root
= NULL
;
3097 static HRESULT WINAPI
ddraw7_CreateSurface(IDirectDraw7
*iface
, DDSURFACEDESC2
*surface_desc
,
3098 IDirectDrawSurface7
**surface
, IUnknown
*outer_unknown
)
3100 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
3101 struct ddraw_surface
*impl
;
3104 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3105 iface
, surface_desc
, surface
, outer_unknown
);
3107 wined3d_mutex_lock();
3109 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
3111 WARN("Cooperative level not set.\n");
3112 wined3d_mutex_unlock();
3113 return DDERR_NOCOOPERATIVELEVELSET
;
3116 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
3118 WARN("Application supplied invalid surface descriptor\n");
3119 wined3d_mutex_unlock();
3120 return DDERR_INVALIDPARAMS
;
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(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_desc
, &impl
, outer_unknown
, 7);
3137 wined3d_mutex_unlock();
3144 *surface
= &impl
->IDirectDrawSurface7_iface
;
3145 IDirectDraw7_AddRef(iface
);
3146 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3151 static HRESULT WINAPI
ddraw4_CreateSurface(IDirectDraw4
*iface
,
3152 DDSURFACEDESC2
*surface_desc
, IDirectDrawSurface4
**surface
, IUnknown
*outer_unknown
)
3154 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3155 struct ddraw_surface
*impl
;
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(DDSURFACEDESC2
))
3172 WARN("Application supplied invalid surface descriptor\n");
3173 wined3d_mutex_unlock();
3174 return DDERR_INVALIDPARAMS
;
3177 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
3179 if (TRACE_ON(ddraw
))
3181 TRACE(" (%p) Requesting surface desc :\n", iface
);
3182 DDRAW_dump_surface_desc(surface_desc
);
3185 WARN("Application tried to create an explicit front or back buffer\n");
3186 wined3d_mutex_unlock();
3187 return DDERR_INVALIDCAPS
;
3190 hr
= CreateSurface(ddraw
, surface_desc
, &impl
, outer_unknown
, 4);
3191 wined3d_mutex_unlock();
3198 *surface
= &impl
->IDirectDrawSurface4_iface
;
3199 IDirectDraw4_AddRef(iface
);
3200 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3205 static HRESULT WINAPI
ddraw2_CreateSurface(IDirectDraw2
*iface
,
3206 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
3208 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3209 struct ddraw_surface
*impl
;
3211 DDSURFACEDESC2 surface_desc2
;
3213 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3214 iface
, surface_desc
, surface
, outer_unknown
);
3216 wined3d_mutex_lock();
3218 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
3220 WARN("Cooperative level not set.\n");
3221 wined3d_mutex_unlock();
3222 return DDERR_NOCOOPERATIVELEVELSET
;
3225 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3227 WARN("Application supplied invalid surface descriptor\n");
3228 wined3d_mutex_unlock();
3229 return DDERR_INVALIDPARAMS
;
3232 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3233 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
3235 if (TRACE_ON(ddraw
))
3237 TRACE(" (%p) Requesting surface desc :\n", iface
);
3238 DDRAW_dump_surface_desc((LPDDSURFACEDESC2
)surface_desc
);
3241 WARN("Application tried to create an explicit front or back buffer\n");
3242 wined3d_mutex_unlock();
3243 return DDERR_INVALIDCAPS
;
3246 hr
= CreateSurface(ddraw
, &surface_desc2
, &impl
, outer_unknown
, 2);
3247 wined3d_mutex_unlock();
3254 *surface
= &impl
->IDirectDrawSurface_iface
;
3255 impl
->ifaceToRelease
= NULL
;
3260 static HRESULT WINAPI
ddraw1_CreateSurface(IDirectDraw
*iface
,
3261 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
3263 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3264 struct ddraw_surface
*impl
;
3266 DDSURFACEDESC2 surface_desc2
;
3268 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3269 iface
, surface_desc
, surface
, outer_unknown
);
3271 wined3d_mutex_lock();
3273 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
3275 WARN("Cooperative level not set.\n");
3276 wined3d_mutex_unlock();
3277 return DDERR_NOCOOPERATIVELEVELSET
;
3280 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3282 WARN("Application supplied invalid surface descriptor\n");
3283 wined3d_mutex_unlock();
3284 return DDERR_INVALIDPARAMS
;
3287 /* Remove front buffer flag, this causes failure in v7, and its added to normal
3288 * primaries anyway. */
3289 surface_desc
->ddsCaps
.dwCaps
&= ~DDSCAPS_FRONTBUFFER
;
3290 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3291 hr
= CreateSurface(ddraw
, &surface_desc2
, &impl
, outer_unknown
, 1);
3292 wined3d_mutex_unlock();
3299 *surface
= &impl
->IDirectDrawSurface_iface
;
3300 impl
->ifaceToRelease
= NULL
;
3305 #define DDENUMSURFACES_SEARCHTYPE (DDENUMSURFACES_CANBECREATED|DDENUMSURFACES_DOESEXIST)
3306 #define DDENUMSURFACES_MATCHTYPE (DDENUMSURFACES_ALL|DDENUMSURFACES_MATCH|DDENUMSURFACES_NOMATCH)
3309 Main_DirectDraw_DDPIXELFORMAT_Match(const DDPIXELFORMAT
*requested
,
3310 const DDPIXELFORMAT
*provided
)
3312 /* Some flags must be present in both or neither for a match. */
3313 static const DWORD must_match
= DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
3314 | DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_FOURCC
3315 | DDPF_ZBUFFER
| DDPF_STENCILBUFFER
;
3317 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3320 if ((requested
->dwFlags
& must_match
) != (provided
->dwFlags
& must_match
))
3323 if (requested
->dwFlags
& DDPF_FOURCC
)
3324 if (requested
->dwFourCC
!= provided
->dwFourCC
)
3327 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_ALPHA
3328 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
3329 if (requested
->u1
.dwRGBBitCount
!= provided
->u1
.dwRGBBitCount
)
3332 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3333 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
3334 if (requested
->u2
.dwRBitMask
!= provided
->u2
.dwRBitMask
)
3337 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_BUMPDUDV
))
3338 if (requested
->u3
.dwGBitMask
!= provided
->u3
.dwGBitMask
)
3341 /* I could be wrong about the bumpmapping. MSDN docs are vague. */
3342 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3344 if (requested
->u4
.dwBBitMask
!= provided
->u4
.dwBBitMask
)
3347 if (requested
->dwFlags
& (DDPF_ALPHAPIXELS
|DDPF_ZPIXELS
))
3348 if (requested
->u5
.dwRGBAlphaBitMask
!= provided
->u5
.dwRGBAlphaBitMask
)
3354 static BOOL
ddraw_match_surface_desc(const DDSURFACEDESC2
*requested
, const DDSURFACEDESC2
*provided
)
3363 #define CMP(FLAG, FIELD) \
3364 { DDSD_##FLAG, offsetof(DDSURFACEDESC2, FIELD), \
3365 sizeof(((DDSURFACEDESC2 *)(NULL))->FIELD) }
3367 static const struct compare_info compare
[] =
3369 CMP(ALPHABITDEPTH
, dwAlphaBitDepth
),
3370 CMP(BACKBUFFERCOUNT
, dwBackBufferCount
),
3372 CMP(CKDESTBLT
, ddckCKDestBlt
),
3373 CMP(CKDESTOVERLAY
, u3
/* ddckCKDestOverlay */),
3374 CMP(CKSRCBLT
, ddckCKSrcBlt
),
3375 CMP(CKSRCOVERLAY
, ddckCKSrcOverlay
),
3376 CMP(HEIGHT
, dwHeight
),
3377 CMP(LINEARSIZE
, u1
/* dwLinearSize */),
3378 CMP(LPSURFACE
, lpSurface
),
3379 CMP(MIPMAPCOUNT
, u2
/* dwMipMapCount */),
3380 CMP(PITCH
, u1
/* lPitch */),
3381 /* PIXELFORMAT: manual */
3382 CMP(REFRESHRATE
, u2
/* dwRefreshRate */),
3383 CMP(TEXTURESTAGE
, dwTextureStage
),
3384 CMP(WIDTH
, dwWidth
),
3385 /* ZBUFFERBITDEPTH: "obsolete" */
3392 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3395 for (i
=0; i
< sizeof(compare
)/sizeof(compare
[0]); i
++)
3397 if (requested
->dwFlags
& compare
[i
].flag
3398 && memcmp((const char *)provided
+ compare
[i
].offset
,
3399 (const char *)requested
+ compare
[i
].offset
,
3400 compare
[i
].size
) != 0)
3404 if (requested
->dwFlags
& DDSD_PIXELFORMAT
)
3406 if (!Main_DirectDraw_DDPIXELFORMAT_Match(&requested
->u4
.ddpfPixelFormat
,
3407 &provided
->u4
.ddpfPixelFormat
))
3414 #undef DDENUMSURFACES_SEARCHTYPE
3415 #undef DDENUMSURFACES_MATCHTYPE
3417 struct surfacescallback2_context
3419 LPDDENUMSURFACESCALLBACK2 func
;
3423 struct surfacescallback_context
3425 LPDDENUMSURFACESCALLBACK func
;
3429 static HRESULT CALLBACK
EnumSurfacesCallback2Thunk(IDirectDrawSurface7
*surface
,
3430 DDSURFACEDESC2
*surface_desc
, void *context
)
3432 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3433 struct surfacescallback2_context
*cbcontext
= context
;
3435 IDirectDrawSurface4_AddRef(&surface_impl
->IDirectDrawSurface4_iface
);
3436 IDirectDrawSurface7_Release(surface
);
3438 return cbcontext
->func(&surface_impl
->IDirectDrawSurface4_iface
,
3439 surface_desc
, cbcontext
->context
);
3442 static HRESULT CALLBACK
EnumSurfacesCallbackThunk(IDirectDrawSurface7
*surface
,
3443 DDSURFACEDESC2
*surface_desc
, void *context
)
3445 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3446 struct surfacescallback_context
*cbcontext
= context
;
3448 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
3449 IDirectDrawSurface7_Release(surface
);
3451 return cbcontext
->func(&surface_impl
->IDirectDrawSurface_iface
,
3452 (DDSURFACEDESC
*)surface_desc
, cbcontext
->context
);
3455 /*****************************************************************************
3456 * IDirectDraw7::EnumSurfaces
3458 * Loops through all surfaces attached to this device and calls the
3459 * application callback. This can't be relayed to WineD3DDevice,
3460 * because some WineD3DSurfaces' parents are IParent objects
3463 * Flags: Some filtering flags. See IDirectDrawImpl_EnumSurfacesCallback
3464 * DDSD: Description to filter for
3465 * Context: Application-provided pointer, it's passed unmodified to the
3467 * Callback: Address to call for each surface
3470 * DDERR_INVALIDPARAMS if the callback is NULL
3473 *****************************************************************************/
3474 static HRESULT WINAPI
ddraw7_EnumSurfaces(IDirectDraw7
*iface
, DWORD Flags
,
3475 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMSURFACESCALLBACK7 Callback
)
3477 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
3478 struct ddraw_surface
*surf
;
3480 DDSURFACEDESC2 desc
;
3481 struct list
*entry
, *entry2
;
3483 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3484 iface
, Flags
, DDSD
, Context
, Callback
);
3486 all
= Flags
& DDENUMSURFACES_ALL
;
3487 nomatch
= Flags
& DDENUMSURFACES_NOMATCH
;
3490 return DDERR_INVALIDPARAMS
;
3492 wined3d_mutex_lock();
3494 /* Use the _SAFE enumeration, the app may destroy enumerated surfaces */
3495 LIST_FOR_EACH_SAFE(entry
, entry2
, &ddraw
->surface_list
)
3497 surf
= LIST_ENTRY(entry
, struct ddraw_surface
, surface_list_entry
);
3499 if (!surf
->iface_count
)
3501 WARN("Not enumerating surface %p because it doesn't have any references.\n", surf
);
3505 if (all
|| (nomatch
!= ddraw_match_surface_desc(DDSD
, &surf
->surface_desc
)))
3507 TRACE("Enumerating surface %p.\n", surf
);
3508 desc
= surf
->surface_desc
;
3509 IDirectDrawSurface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
3510 if (Callback(&surf
->IDirectDrawSurface7_iface
, &desc
, Context
) != DDENUMRET_OK
)
3512 wined3d_mutex_unlock();
3518 wined3d_mutex_unlock();
3523 static HRESULT WINAPI
ddraw4_EnumSurfaces(IDirectDraw4
*iface
, DWORD flags
,
3524 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
3526 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3527 struct surfacescallback2_context cbcontext
;
3529 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3530 iface
, flags
, surface_desc
, context
, callback
);
3532 cbcontext
.func
= callback
;
3533 cbcontext
.context
= context
;
3535 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
, surface_desc
,
3536 &cbcontext
, EnumSurfacesCallback2Thunk
);
3539 static HRESULT WINAPI
ddraw2_EnumSurfaces(IDirectDraw2
*iface
, DWORD flags
,
3540 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3542 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3543 struct surfacescallback_context cbcontext
;
3544 DDSURFACEDESC2 surface_desc2
;
3546 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3547 iface
, flags
, surface_desc
, context
, callback
);
3549 cbcontext
.func
= callback
;
3550 cbcontext
.context
= context
;
3552 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3553 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
,
3554 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3557 static HRESULT WINAPI
ddraw1_EnumSurfaces(IDirectDraw
*iface
, DWORD flags
,
3558 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3560 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3561 struct surfacescallback_context cbcontext
;
3562 DDSURFACEDESC2 surface_desc2
;
3564 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3565 iface
, flags
, surface_desc
, context
, callback
);
3567 cbcontext
.func
= callback
;
3568 cbcontext
.context
= context
;
3570 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3571 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
,
3572 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3575 /*****************************************************************************
3576 * DirectDrawCreateClipper (DDRAW.@)
3578 * Creates a new IDirectDrawClipper object.
3581 * Clipper: Address to write the interface pointer to
3582 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3586 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3587 * E_OUTOFMEMORY if allocating the object failed
3589 *****************************************************************************/
3590 HRESULT WINAPI
DirectDrawCreateClipper(DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3592 struct ddraw_clipper
*object
;
3595 TRACE("flags %#x, clipper %p, outer_unknown %p.\n",
3596 flags
, clipper
, outer_unknown
);
3599 return CLASS_E_NOAGGREGATION
;
3601 wined3d_mutex_lock();
3603 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3606 wined3d_mutex_unlock();
3607 return E_OUTOFMEMORY
;
3610 hr
= ddraw_clipper_init(object
);
3613 WARN("Failed to initialize clipper, hr %#x.\n", hr
);
3614 HeapFree(GetProcessHeap(), 0, object
);
3615 wined3d_mutex_unlock();
3619 TRACE("Created clipper %p.\n", object
);
3620 *clipper
= &object
->IDirectDrawClipper_iface
;
3621 wined3d_mutex_unlock();
3626 /*****************************************************************************
3627 * IDirectDraw7::CreateClipper
3629 * Creates a DDraw clipper. See DirectDrawCreateClipper for details
3631 *****************************************************************************/
3632 static HRESULT WINAPI
ddraw7_CreateClipper(IDirectDraw7
*iface
, DWORD Flags
,
3633 IDirectDrawClipper
**Clipper
, IUnknown
*UnkOuter
)
3635 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3636 iface
, Flags
, Clipper
, UnkOuter
);
3638 return DirectDrawCreateClipper(Flags
, Clipper
, UnkOuter
);
3641 static HRESULT WINAPI
ddraw4_CreateClipper(IDirectDraw4
*iface
, DWORD flags
,
3642 IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3644 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3646 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3647 iface
, flags
, clipper
, outer_unknown
);
3649 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3652 static HRESULT WINAPI
ddraw2_CreateClipper(IDirectDraw2
*iface
,
3653 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3655 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3657 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3658 iface
, flags
, clipper
, outer_unknown
);
3660 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3663 static HRESULT WINAPI
ddraw1_CreateClipper(IDirectDraw
*iface
,
3664 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3666 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3668 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3669 iface
, flags
, clipper
, outer_unknown
);
3671 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3674 /*****************************************************************************
3675 * IDirectDraw7::CreatePalette
3677 * Creates a new IDirectDrawPalette object
3680 * Flags: The flags for the new clipper
3681 * ColorTable: Color table to assign to the new clipper
3682 * Palette: Address to write the interface pointer to
3683 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3687 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3688 * E_OUTOFMEMORY if allocating the object failed
3690 *****************************************************************************/
3691 static HRESULT WINAPI
ddraw7_CreatePalette(IDirectDraw7
*iface
, DWORD Flags
,
3692 PALETTEENTRY
*ColorTable
, IDirectDrawPalette
**Palette
, IUnknown
*pUnkOuter
)
3694 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
3695 struct ddraw_palette
*object
;
3698 TRACE("iface %p, flags %#x, color_table %p, palette %p, outer_unknown %p.\n",
3699 iface
, Flags
, ColorTable
, Palette
, pUnkOuter
);
3702 return CLASS_E_NOAGGREGATION
;
3704 wined3d_mutex_lock();
3706 /* The refcount test shows that a cooplevel is required for this */
3707 if (!ddraw
->cooperative_level
)
3709 WARN("No cooperative level set, returning DDERR_NOCOOPERATIVELEVELSET\n");
3710 wined3d_mutex_unlock();
3711 return DDERR_NOCOOPERATIVELEVELSET
;
3714 object
= HeapAlloc(GetProcessHeap(), 0, sizeof(*object
));
3717 ERR("Out of memory when allocating memory for a palette implementation\n");
3718 wined3d_mutex_unlock();
3719 return E_OUTOFMEMORY
;
3722 hr
= ddraw_palette_init(object
, ddraw
, Flags
, ColorTable
);
3725 WARN("Failed to initialize palette, hr %#x.\n", hr
);
3726 HeapFree(GetProcessHeap(), 0, object
);
3727 wined3d_mutex_unlock();
3731 TRACE("Created palette %p.\n", object
);
3732 *Palette
= &object
->IDirectDrawPalette_iface
;
3733 wined3d_mutex_unlock();
3738 static HRESULT WINAPI
ddraw4_CreatePalette(IDirectDraw4
*iface
, DWORD flags
, PALETTEENTRY
*entries
,
3739 IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3741 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3744 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3745 iface
, flags
, entries
, palette
, outer_unknown
);
3747 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3748 if (SUCCEEDED(hr
) && *palette
)
3750 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3751 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3752 IDirectDraw4_AddRef(iface
);
3753 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3758 static HRESULT WINAPI
ddraw2_CreatePalette(IDirectDraw2
*iface
, DWORD flags
,
3759 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3761 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3764 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3765 iface
, flags
, entries
, palette
, outer_unknown
);
3767 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3768 if (SUCCEEDED(hr
) && *palette
)
3770 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3771 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3772 impl
->ifaceToRelease
= NULL
;
3778 static HRESULT WINAPI
ddraw1_CreatePalette(IDirectDraw
*iface
, DWORD flags
,
3779 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3781 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3784 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3785 iface
, flags
, entries
, palette
, outer_unknown
);
3787 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3788 if (SUCCEEDED(hr
) && *palette
)
3790 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3791 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3792 impl
->ifaceToRelease
= NULL
;
3798 /*****************************************************************************
3799 * IDirectDraw7::DuplicateSurface
3801 * Duplicates a surface. The surface memory points to the same memory as
3802 * the original surface, and it's released when the last surface referencing
3803 * it is released. I guess that's beyond Wine's surface management right now
3804 * (Idea: create a new DDraw surface with the same WineD3DSurface. I need a
3805 * test application to implement this)
3808 * Src: Address of the source surface
3809 * Dest: Address to write the new surface pointer to
3812 * See IDirectDraw7::CreateSurface
3814 *****************************************************************************/
3815 static HRESULT WINAPI
ddraw7_DuplicateSurface(IDirectDraw7
*iface
,
3816 IDirectDrawSurface7
*Src
, IDirectDrawSurface7
**Dest
)
3818 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirectDrawSurface7(Src
);
3820 FIXME("iface %p, src %p, dst %p partial stub!\n", iface
, Src
, Dest
);
3822 /* For now, simply create a new, independent surface */
3823 return IDirectDraw7_CreateSurface(iface
, &src_surface
->surface_desc
, Dest
, NULL
);
3826 static HRESULT WINAPI
ddraw4_DuplicateSurface(IDirectDraw4
*iface
, IDirectDrawSurface4
*src
,
3827 IDirectDrawSurface4
**dst
)
3829 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src
);
3830 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3831 struct ddraw_surface
*dst_impl
;
3832 IDirectDrawSurface7
*dst7
;
3835 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3837 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3838 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3844 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3845 *dst
= &dst_impl
->IDirectDrawSurface4_iface
;
3846 IDirectDrawSurface4_AddRef(*dst
);
3847 IDirectDrawSurface7_Release(dst7
);
3852 static HRESULT WINAPI
ddraw2_DuplicateSurface(IDirectDraw2
*iface
,
3853 IDirectDrawSurface
*src
, IDirectDrawSurface
**dst
)
3855 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3856 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3857 struct ddraw_surface
*dst_impl
;
3858 IDirectDrawSurface7
*dst7
;
3861 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3863 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3864 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3867 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3868 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3869 IDirectDrawSurface_AddRef(*dst
);
3870 IDirectDrawSurface7_Release(dst7
);
3875 static HRESULT WINAPI
ddraw1_DuplicateSurface(IDirectDraw
*iface
, IDirectDrawSurface
*src
,
3876 IDirectDrawSurface
**dst
)
3878 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3879 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3880 struct ddraw_surface
*dst_impl
;
3881 IDirectDrawSurface7
*dst7
;
3884 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3886 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3887 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3890 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3891 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3892 IDirectDrawSurface_AddRef(*dst
);
3893 IDirectDrawSurface7_Release(dst7
);
3898 /*****************************************************************************
3899 * IDirect3D7::EnumDevices
3901 * The EnumDevices method for IDirect3D7. It enumerates all supported
3902 * D3D7 devices. Currently the T&L, HAL and RGB devices are enumerated.
3905 * callback: Function to call for each enumerated device
3906 * context: Pointer to pass back to the app
3909 * D3D_OK, or the return value of the GetCaps call
3911 *****************************************************************************/
3912 static HRESULT WINAPI
d3d7_EnumDevices(IDirect3D7
*iface
, LPD3DENUMDEVICESCALLBACK7 callback
, void *context
)
3914 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
3915 D3DDEVICEDESC7 device_desc7
;
3916 D3DDEVICEDESC device_desc1
;
3920 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3923 return DDERR_INVALIDPARAMS
;
3925 wined3d_mutex_lock();
3927 hr
= IDirect3DImpl_GetCaps(ddraw
->wined3d
, &device_desc1
, &device_desc7
);
3930 wined3d_mutex_unlock();
3934 for (i
= 0; i
< sizeof(device_list7
)/sizeof(device_list7
[0]); i
++)
3938 device_desc7
.deviceGUID
= *device_list7
[i
].device_guid
;
3939 ret
= callback(device_list7
[i
].interface_name
, device_list7
[i
].device_name
, &device_desc7
, context
);
3940 if (ret
!= DDENUMRET_OK
)
3942 TRACE("Application cancelled the enumeration.\n");
3943 wined3d_mutex_unlock();
3948 TRACE("End of enumeration.\n");
3950 wined3d_mutex_unlock();
3955 /*****************************************************************************
3956 * IDirect3D3::EnumDevices
3958 * Enumerates all supported Direct3DDevice interfaces. This is the
3959 * implementation for Direct3D 1 to Direc3D 3, Version 7 has its own.
3961 * Version 1, 2 and 3
3964 * callback: Application-provided routine to call for each enumerated device
3965 * Context: Pointer to pass to the callback
3968 * D3D_OK on success,
3969 * The result of IDirect3DImpl_GetCaps if it failed
3971 *****************************************************************************/
3972 static HRESULT WINAPI
d3d3_EnumDevices(IDirect3D3
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3974 static CHAR wined3d_description
[] = "Wine D3DDevice using WineD3D and OpenGL";
3976 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3977 D3DDEVICEDESC device_desc1
, hal_desc
, hel_desc
;
3978 D3DDEVICEDESC7 device_desc7
;
3981 /* Some games (Motoracer 2 demo) have the bad idea to modify the device
3982 * name string. Let's put the string in a sufficiently sized array in
3983 * writable memory. */
3984 char device_name
[50];
3985 strcpy(device_name
,"Direct3D HEL");
3987 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3990 return DDERR_INVALIDPARAMS
;
3992 wined3d_mutex_lock();
3994 hr
= IDirect3DImpl_GetCaps(ddraw
->wined3d
, &device_desc1
, &device_desc7
);
3997 wined3d_mutex_unlock();
4001 /* Do I have to enumerate the reference id? Note from old d3d7:
4002 * "It seems that enumerating the reference IID on Direct3D 1 games
4003 * (AvP / Motoracer2) breaks them". So do not enumerate this iid in V1
4005 * There's a registry key HKLM\Software\Microsoft\Direct3D\Drivers,
4006 * EnumReference which enables / disables enumerating the reference
4007 * rasterizer. It's a DWORD, 0 means disabled, 2 means enabled. The
4008 * enablerefrast.reg and disablerefrast.reg files in the DirectX 7.0 sdk
4009 * demo directory suggest this.
4011 * Some games(GTA 2) seem to use the second enumerated device, so I have
4012 * to enumerate at least 2 devices. So enumerate the reference device to
4015 * Other games (Rollcage) tell emulation and hal device apart by certain
4016 * flags. Rollcage expects D3DPTEXTURECAPS_POW2 to be set (yeah, it is a
4017 * limitation flag), and it refuses all devices that have the perspective
4018 * flag set. This way it refuses the emulation device, and HAL devices
4019 * never have POW2 unset in d3d7 on windows. */
4020 if (ddraw
->d3dversion
!= 1)
4022 static CHAR reference_description
[] = "RGB Direct3D emulation";
4024 TRACE("Enumerating WineD3D D3DDevice interface.\n");
4025 hal_desc
= device_desc1
;
4026 hel_desc
= device_desc1
;
4027 /* The rgb device has the pow2 flag set in the hel caps, but not in the hal caps. */
4028 hal_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
4029 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
4030 hal_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
4031 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
4032 /* RGB, RAMP and MMX devices have a HAL dcmColorModel of 0 */
4033 hal_desc
.dcmColorModel
= 0;
4035 hr
= callback((GUID
*)&IID_IDirect3DRGBDevice
, reference_description
,
4036 device_name
, &hal_desc
, &hel_desc
, context
);
4037 if (hr
!= D3DENUMRET_OK
)
4039 TRACE("Application cancelled the enumeration.\n");
4040 wined3d_mutex_unlock();
4045 strcpy(device_name
,"Direct3D HAL");
4047 TRACE("Enumerating HAL Direct3D device.\n");
4048 hal_desc
= device_desc1
;
4049 hel_desc
= device_desc1
;
4051 /* The hal device does not have the pow2 flag set in hel, but in hal. */
4052 hel_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
4053 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
4054 hel_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
4055 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
4056 /* HAL devices have a HEL dcmColorModel of 0 */
4057 hel_desc
.dcmColorModel
= 0;
4059 hr
= callback((GUID
*)&IID_IDirect3DHALDevice
, wined3d_description
,
4060 device_name
, &hal_desc
, &hel_desc
, context
);
4061 if (hr
!= D3DENUMRET_OK
)
4063 TRACE("Application cancelled the enumeration.\n");
4064 wined3d_mutex_unlock();
4068 TRACE("End of enumeration.\n");
4070 wined3d_mutex_unlock();
4075 static HRESULT WINAPI
d3d2_EnumDevices(IDirect3D2
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
4077 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4079 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
4081 return d3d3_EnumDevices(&ddraw
->IDirect3D3_iface
, callback
, context
);
4084 static HRESULT WINAPI
d3d1_EnumDevices(IDirect3D
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
4086 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4088 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
4090 return d3d3_EnumDevices(&ddraw
->IDirect3D3_iface
, callback
, context
);
4093 /*****************************************************************************
4094 * IDirect3D3::CreateLight
4096 * Creates an IDirect3DLight interface. This interface is used in
4097 * Direct3D3 or earlier for lighting. In Direct3D7 it has been replaced
4098 * by the DIRECT3DLIGHT7 structure. Wine's Direct3DLight implementation
4099 * uses the IDirect3DDevice7 interface with D3D7 lights.
4101 * Version 1, 2 and 3
4104 * light: Address to store the new interface pointer
4105 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
4110 * DDERR_OUTOFMEMORY if memory allocation failed
4111 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
4113 *****************************************************************************/
4114 static HRESULT WINAPI
d3d3_CreateLight(IDirect3D3
*iface
, IDirect3DLight
**light
,
4115 IUnknown
*outer_unknown
)
4117 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4118 struct d3d_light
*object
;
4120 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
4122 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4124 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
4127 ERR("Failed to allocate light memory.\n");
4128 return DDERR_OUTOFMEMORY
;
4131 d3d_light_init(object
, ddraw
);
4133 TRACE("Created light %p.\n", object
);
4134 *light
= &object
->IDirect3DLight_iface
;
4139 static HRESULT WINAPI
d3d2_CreateLight(IDirect3D2
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
4141 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4143 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
4145 return d3d3_CreateLight(&ddraw
->IDirect3D3_iface
, light
, outer_unknown
);
4148 static HRESULT WINAPI
d3d1_CreateLight(IDirect3D
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
4150 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4152 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
4154 return d3d3_CreateLight(&ddraw
->IDirect3D3_iface
, light
, outer_unknown
);
4157 /*****************************************************************************
4158 * IDirect3D3::CreateMaterial
4160 * Creates an IDirect3DMaterial interface. This interface is used by Direct3D3
4161 * and older versions. The IDirect3DMaterial implementation wraps its
4162 * functionality to IDirect3DDevice7::SetMaterial and friends.
4164 * Version 1, 2 and 3
4167 * material: Address to store the new interface's pointer to
4168 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
4173 * DDERR_OUTOFMEMORY if memory allocation failed
4174 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
4176 *****************************************************************************/
4177 static HRESULT WINAPI
d3d3_CreateMaterial(IDirect3D3
*iface
, IDirect3DMaterial3
**material
,
4178 IUnknown
*outer_unknown
)
4180 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4181 struct d3d_material
*object
;
4183 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4185 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4187 object
= d3d_material_create(ddraw
);
4190 ERR("Failed to allocate material memory.\n");
4191 return DDERR_OUTOFMEMORY
;
4194 TRACE("Created material %p.\n", object
);
4195 *material
= &object
->IDirect3DMaterial3_iface
;
4200 static HRESULT WINAPI
d3d2_CreateMaterial(IDirect3D2
*iface
, IDirect3DMaterial2
**material
,
4201 IUnknown
*outer_unknown
)
4203 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4204 struct d3d_material
*object
;
4206 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4208 object
= d3d_material_create(ddraw
);
4211 ERR("Failed to allocate material memory.\n");
4212 return DDERR_OUTOFMEMORY
;
4215 TRACE("Created material %p.\n", object
);
4216 *material
= &object
->IDirect3DMaterial2_iface
;
4221 static HRESULT WINAPI
d3d1_CreateMaterial(IDirect3D
*iface
, IDirect3DMaterial
**material
,
4222 IUnknown
*outer_unknown
)
4224 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4225 struct d3d_material
*object
;
4227 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4229 object
= d3d_material_create(ddraw
);
4232 ERR("Failed to allocate material memory.\n");
4233 return DDERR_OUTOFMEMORY
;
4236 TRACE("Created material %p.\n", object
);
4237 *material
= &object
->IDirect3DMaterial_iface
;
4242 /*****************************************************************************
4243 * IDirect3D3::CreateViewport
4245 * Creates an IDirect3DViewport interface. This interface is used
4246 * by Direct3D and earlier versions for Viewport management. In Direct3D7
4247 * it has been replaced by a viewport structure and
4248 * IDirect3DDevice7::*Viewport. Wine's IDirect3DViewport implementation
4249 * uses the IDirect3DDevice7 methods for its functionality
4252 * Viewport: Address to store the new interface pointer
4253 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
4258 * DDERR_OUTOFMEMORY if memory allocation failed
4259 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
4261 *****************************************************************************/
4262 static HRESULT WINAPI
d3d3_CreateViewport(IDirect3D3
*iface
, IDirect3DViewport3
**viewport
,
4263 IUnknown
*outer_unknown
)
4265 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4266 struct d3d_viewport
*object
;
4268 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4270 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4272 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
4275 ERR("Failed to allocate viewport memory.\n");
4276 return DDERR_OUTOFMEMORY
;
4279 d3d_viewport_init(object
, ddraw
);
4281 TRACE("Created viewport %p.\n", object
);
4282 *viewport
= &object
->IDirect3DViewport3_iface
;
4287 static HRESULT WINAPI
d3d2_CreateViewport(IDirect3D2
*iface
, IDirect3DViewport2
**viewport
, IUnknown
*outer_unknown
)
4289 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4291 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4293 return d3d3_CreateViewport(&ddraw
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
4297 static HRESULT WINAPI
d3d1_CreateViewport(IDirect3D
*iface
, IDirect3DViewport
**viewport
, IUnknown
*outer_unknown
)
4299 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4301 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4303 return d3d3_CreateViewport(&ddraw
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
4307 /*****************************************************************************
4308 * IDirect3D3::FindDevice
4310 * This method finds a device with the requested properties and returns a
4311 * device description
4315 * fds: Describes the requested device characteristics
4316 * fdr: Returns the device description
4320 * DDERR_INVALIDPARAMS if no device was found
4322 *****************************************************************************/
4323 static HRESULT WINAPI
d3d3_FindDevice(IDirect3D3
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4325 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4326 D3DDEVICEDESC7 desc7
;
4327 D3DDEVICEDESC desc1
;
4330 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4332 if (!fds
|| !fdr
) return DDERR_INVALIDPARAMS
;
4334 if (fds
->dwSize
!= sizeof(D3DFINDDEVICESEARCH
)
4335 || fdr
->dwSize
!= sizeof(D3DFINDDEVICERESULT
))
4336 return DDERR_INVALIDPARAMS
;
4338 if ((fds
->dwFlags
& D3DFDS_COLORMODEL
)
4339 && fds
->dcmColorModel
!= D3DCOLOR_RGB
)
4341 WARN("Trying to request a non-RGB D3D color model. Not supported.\n");
4342 return DDERR_INVALIDPARAMS
; /* No real idea what to return here :-) */
4345 if (fds
->dwFlags
& D3DFDS_GUID
)
4347 TRACE("Trying to match guid %s.\n", debugstr_guid(&(fds
->guid
)));
4348 if (!IsEqualGUID(&IID_D3DDEVICE_WineD3D
, &fds
->guid
)
4349 && !IsEqualGUID(&IID_IDirect3DHALDevice
, &fds
->guid
)
4350 && !IsEqualGUID(&IID_IDirect3DRGBDevice
, &fds
->guid
))
4352 WARN("No match for this GUID.\n");
4353 return DDERR_NOTFOUND
;
4358 hr
= IDirect3DImpl_GetCaps(ddraw
->wined3d
, &desc1
, &desc7
);
4359 if (hr
!= D3D_OK
) return hr
;
4361 /* Now return our own GUID */
4362 fdr
->guid
= IID_D3DDEVICE_WineD3D
;
4363 fdr
->ddHwDesc
= desc1
;
4364 fdr
->ddSwDesc
= desc1
;
4366 TRACE("Returning Wine's wined3d device with (undumped) capabilities.\n");
4371 static HRESULT WINAPI
d3d2_FindDevice(IDirect3D2
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4373 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4375 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4377 return d3d3_FindDevice(&ddraw
->IDirect3D3_iface
, fds
, fdr
);
4380 static HRESULT WINAPI
d3d1_FindDevice(IDirect3D
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4382 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4384 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4386 return d3d3_FindDevice(&ddraw
->IDirect3D3_iface
, fds
, fdr
);
4389 /*****************************************************************************
4390 * IDirect3D7::CreateDevice
4392 * Creates an IDirect3DDevice7 interface.
4394 * Version 2, 3 and 7. IDirect3DDevice 1 interfaces are interfaces to
4395 * DirectDraw surfaces and are created with
4396 * IDirectDrawSurface::QueryInterface. This method uses CreateDevice to
4397 * create the device object and QueryInterfaces for IDirect3DDevice
4400 * refiid: IID of the device to create
4401 * Surface: Initial rendertarget
4402 * Device: Address to return the interface pointer
4406 * DDERR_OUTOFMEMORY if memory allocation failed
4407 * DDERR_INVALIDPARAMS if a device exists already
4409 *****************************************************************************/
4410 static HRESULT WINAPI
d3d7_CreateDevice(IDirect3D7
*iface
, REFCLSID riid
,
4411 IDirectDrawSurface7
*surface
, IDirect3DDevice7
**device
)
4413 struct ddraw_surface
*target
= unsafe_impl_from_IDirectDrawSurface7(surface
);
4414 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4415 struct d3d_device
*object
;
4418 TRACE("iface %p, riid %s, surface %p, device %p.\n", iface
, debugstr_guid(riid
), surface
, device
);
4420 wined3d_mutex_lock();
4421 hr
= d3d_device_create(ddraw
, target
, 7, &object
, NULL
);
4423 *device
= &object
->IDirect3DDevice7_iface
;
4426 WARN("Failed to create device, hr %#x.\n", hr
);
4429 wined3d_mutex_unlock();
4434 static HRESULT WINAPI
d3d3_CreateDevice(IDirect3D3
*iface
, REFCLSID riid
,
4435 IDirectDrawSurface4
*surface
, IDirect3DDevice3
**device
, IUnknown
*outer_unknown
)
4437 struct ddraw_surface
*surface_impl
= unsafe_impl_from_IDirectDrawSurface4(surface
);
4438 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4439 struct d3d_device
*device_impl
;
4442 TRACE("iface %p, riid %s, surface %p, device %p, outer_unknown %p.\n",
4443 iface
, debugstr_guid(riid
), surface
, device
, outer_unknown
);
4446 return CLASS_E_NOAGGREGATION
;
4448 wined3d_mutex_lock();
4449 hr
= d3d_device_create(ddraw
, surface_impl
, 3, &device_impl
, NULL
);
4451 *device
= &device_impl
->IDirect3DDevice3_iface
;
4454 WARN("Failed to create device, hr %#x.\n", hr
);
4457 wined3d_mutex_unlock();
4462 static HRESULT WINAPI
d3d2_CreateDevice(IDirect3D2
*iface
, REFCLSID riid
,
4463 IDirectDrawSurface
*surface
, IDirect3DDevice2
**device
)
4465 struct ddraw_surface
*surface_impl
= unsafe_impl_from_IDirectDrawSurface(surface
);
4466 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4467 struct d3d_device
*device_impl
;
4470 TRACE("iface %p, riid %s, surface %p, device %p.\n",
4471 iface
, debugstr_guid(riid
), surface
, device
);
4473 wined3d_mutex_lock();
4474 hr
= d3d_device_create(ddraw
, surface_impl
, 2, &device_impl
, NULL
);
4476 *device
= &device_impl
->IDirect3DDevice2_iface
;
4479 WARN("Failed to create device, hr %#x.\n", hr
);
4482 wined3d_mutex_unlock();
4487 /*****************************************************************************
4488 * IDirect3D7::CreateVertexBuffer
4490 * Creates a new vertex buffer object and returns a IDirect3DVertexBuffer7
4496 * desc: Requested Vertex buffer properties
4497 * vertex_buffer: Address to return the interface pointer at
4498 * flags: Some flags, should be 0
4502 * DDERR_OUTOFMEMORY if memory allocation failed
4503 * The return value of IWineD3DDevice::CreateVertexBuffer if this call fails
4504 * DDERR_INVALIDPARAMS if desc or vertex_buffer are NULL
4506 *****************************************************************************/
4507 static HRESULT WINAPI
d3d7_CreateVertexBuffer(IDirect3D7
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4508 IDirect3DVertexBuffer7
**vertex_buffer
, DWORD flags
)
4510 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4511 struct d3d_vertex_buffer
*object
;
4514 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x.\n",
4515 iface
, desc
, vertex_buffer
, flags
);
4517 if (!vertex_buffer
|| !desc
) return DDERR_INVALIDPARAMS
;
4519 hr
= d3d_vertex_buffer_create(&object
, ddraw
, desc
);
4522 TRACE("Created vertex buffer %p.\n", object
);
4523 *vertex_buffer
= &object
->IDirect3DVertexBuffer7_iface
;
4526 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4531 static HRESULT WINAPI
d3d3_CreateVertexBuffer(IDirect3D3
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4532 IDirect3DVertexBuffer
**vertex_buffer
, DWORD flags
, IUnknown
*outer_unknown
)
4534 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4535 struct d3d_vertex_buffer
*object
;
4538 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x, outer_unknown %p.\n",
4539 iface
, desc
, vertex_buffer
, flags
, outer_unknown
);
4542 return CLASS_E_NOAGGREGATION
;
4543 if (!vertex_buffer
|| !desc
)
4544 return DDERR_INVALIDPARAMS
;
4546 hr
= d3d_vertex_buffer_create(&object
, ddraw
, desc
);
4549 TRACE("Created vertex buffer %p.\n", object
);
4550 *vertex_buffer
= &object
->IDirect3DVertexBuffer_iface
;
4553 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4558 /*****************************************************************************
4559 * IDirect3D7::EnumZBufferFormats
4561 * Enumerates all supported Z buffer pixel formats
4567 * callback: callback to call for each pixel format
4568 * context: Pointer to pass back to the callback
4572 * DDERR_INVALIDPARAMS if callback is NULL
4573 * For details, see IWineD3DDevice::EnumZBufferFormats
4575 *****************************************************************************/
4576 static HRESULT WINAPI
d3d7_EnumZBufferFormats(IDirect3D7
*iface
, REFCLSID device_iid
,
4577 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4579 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4580 struct wined3d_display_mode mode
;
4581 enum wined3d_device_type type
;
4585 /* Order matters. Specifically, BattleZone II (full version) expects the
4586 * 16-bit depth formats to be listed before the 24 and 32 ones. */
4587 static const enum wined3d_format_id formats
[] =
4589 WINED3DFMT_S1_UINT_D15_UNORM
,
4590 WINED3DFMT_D16_UNORM
,
4591 WINED3DFMT_X8D24_UNORM
,
4592 WINED3DFMT_S4X4_UINT_D24_UNORM
,
4593 WINED3DFMT_D24_UNORM_S8_UINT
,
4594 WINED3DFMT_D32_UNORM
,
4597 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4598 iface
, debugstr_guid(device_iid
), callback
, context
);
4600 if (!callback
) return DDERR_INVALIDPARAMS
;
4602 if (IsEqualGUID(device_iid
, &IID_IDirect3DHALDevice
)
4603 || IsEqualGUID(device_iid
, &IID_IDirect3DTnLHalDevice
)
4604 || IsEqualGUID(device_iid
, &IID_D3DDEVICE_WineD3D
))
4606 TRACE("Asked for HAL device.\n");
4607 type
= WINED3D_DEVICE_TYPE_HAL
;
4609 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRGBDevice
)
4610 || IsEqualGUID(device_iid
, &IID_IDirect3DMMXDevice
))
4612 TRACE("Asked for SW device.\n");
4613 type
= WINED3D_DEVICE_TYPE_SW
;
4615 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRefDevice
))
4617 TRACE("Asked for REF device.\n");
4618 type
= WINED3D_DEVICE_TYPE_REF
;
4620 else if (IsEqualGUID(device_iid
, &IID_IDirect3DNullDevice
))
4622 TRACE("Asked for NULLREF device.\n");
4623 type
= WINED3D_DEVICE_TYPE_NULLREF
;
4627 FIXME("Unexpected device GUID %s.\n", debugstr_guid(device_iid
));
4628 type
= WINED3D_DEVICE_TYPE_HAL
;
4631 wined3d_mutex_lock();
4632 /* We need an adapter format from somewhere to please wined3d and WGL.
4633 * Use the current display mode. So far all cards offer the same depth
4634 * stencil format for all modes, but if some do not and applications do
4635 * not like that we'll have to find some workaround, like iterating over
4636 * all imaginable formats and collecting all the depth stencil formats we
4638 hr
= wined3d_device_get_display_mode(ddraw
->wined3d_device
, 0, &mode
);
4640 for (i
= 0; i
< (sizeof(formats
) / sizeof(*formats
)); ++i
)
4642 hr
= wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, type
, mode
.format_id
,
4643 WINED3DUSAGE_DEPTHSTENCIL
, WINED3D_RTYPE_SURFACE
, formats
[i
], WINED3D_SURFACE_TYPE_OPENGL
);
4646 DDPIXELFORMAT pformat
;
4648 memset(&pformat
, 0, sizeof(pformat
));
4649 pformat
.dwSize
= sizeof(pformat
);
4650 PixelFormat_WineD3DtoDD(&pformat
, formats
[i
]);
4652 TRACE("Enumerating wined3d format %#x.\n", formats
[i
]);
4653 hr
= callback(&pformat
, context
);
4654 if (hr
!= DDENUMRET_OK
)
4656 TRACE("Format enumeration cancelled by application.\n");
4657 wined3d_mutex_unlock();
4663 /* Historically some windows drivers used dwZBufferBitDepth=24 for WINED3DFMT_X8D24_UNORM,
4664 * while others used dwZBufferBitDepth=32. In either case the pitch matches a 32 bits per
4665 * pixel format, so we use dwZBufferBitDepth=32. Some games expect 24. Windows Vista and
4666 * newer enumerate both versions, so we do the same(bug 22434) */
4667 hr
= wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, type
, mode
.format_id
,
4668 WINED3DUSAGE_DEPTHSTENCIL
, WINED3D_RTYPE_SURFACE
, WINED3DFMT_X8D24_UNORM
, WINED3D_SURFACE_TYPE_OPENGL
);
4671 DDPIXELFORMAT x8d24
=
4673 sizeof(x8d24
), DDPF_ZBUFFER
, 0,
4674 {24}, {0x00000000}, {0x00ffffff}, {0x00000000}
4676 TRACE("Enumerating WINED3DFMT_X8D24_UNORM, dwZBufferBitDepth=24 version\n");
4677 callback(&x8d24
, context
);
4680 TRACE("End of enumeration.\n");
4682 wined3d_mutex_unlock();
4687 static HRESULT WINAPI
d3d3_EnumZBufferFormats(IDirect3D3
*iface
, REFCLSID device_iid
,
4688 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4690 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4692 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4693 iface
, debugstr_guid(device_iid
), callback
, context
);
4695 return d3d7_EnumZBufferFormats(&ddraw
->IDirect3D7_iface
, device_iid
, callback
, context
);
4698 /*****************************************************************************
4699 * IDirect3D7::EvictManagedTextures
4701 * Removes all managed textures (=surfaces with DDSCAPS2_TEXTUREMANAGE or
4702 * DDSCAPS2_D3DTEXTUREMANAGE caps) to be removed from video memory.
4707 * D3D_OK, because it's a stub
4709 *****************************************************************************/
4710 static HRESULT WINAPI
d3d7_EvictManagedTextures(IDirect3D7
*iface
)
4712 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4714 TRACE("iface %p!\n", iface
);
4716 wined3d_mutex_lock();
4717 if (ddraw
->d3d_initialized
)
4718 wined3d_device_evict_managed_resources(ddraw
->wined3d_device
);
4719 wined3d_mutex_unlock();
4724 static HRESULT WINAPI
d3d3_EvictManagedTextures(IDirect3D3
*iface
)
4726 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4728 TRACE("iface %p.\n", iface
);
4730 return d3d7_EvictManagedTextures(&ddraw
->IDirect3D7_iface
);
4733 /*****************************************************************************
4734 * IDirect3DImpl_GetCaps
4736 * This function retrieves the device caps from wined3d
4737 * and converts it into a D3D7 and D3D - D3D3 structure
4738 * This is a helper function called from various places in ddraw
4741 * wined3d: The interface to get the caps from
4742 * desc1: Old D3D <3 structure to fill (needed)
4743 * desc7: D3D7 device desc structure to fill (needed)
4746 * D3D_OK on success, or the return value of IWineD3D::GetCaps
4748 *****************************************************************************/
4749 HRESULT
IDirect3DImpl_GetCaps(const struct wined3d
*wined3d
, D3DDEVICEDESC
*desc1
, D3DDEVICEDESC7
*desc7
)
4751 WINED3DCAPS wined3d_caps
;
4754 TRACE("wined3d %p, desc1 %p, desc7 %p.\n", wined3d
, desc1
, desc7
);
4756 memset(&wined3d_caps
, 0, sizeof(wined3d_caps
));
4758 wined3d_mutex_lock();
4759 hr
= wined3d_get_device_caps(wined3d
, 0, WINED3D_DEVICE_TYPE_HAL
, &wined3d_caps
);
4760 wined3d_mutex_unlock();
4763 WARN("Failed to get device caps, hr %#x.\n", hr
);
4767 /* Copy the results into the d3d7 and d3d3 structures */
4768 desc7
->dwDevCaps
= wined3d_caps
.DevCaps
;
4769 desc7
->dpcLineCaps
.dwMiscCaps
= wined3d_caps
.PrimitiveMiscCaps
;
4770 desc7
->dpcLineCaps
.dwRasterCaps
= wined3d_caps
.RasterCaps
;
4771 desc7
->dpcLineCaps
.dwZCmpCaps
= wined3d_caps
.ZCmpCaps
;
4772 desc7
->dpcLineCaps
.dwSrcBlendCaps
= wined3d_caps
.SrcBlendCaps
;
4773 desc7
->dpcLineCaps
.dwDestBlendCaps
= wined3d_caps
.DestBlendCaps
;
4774 desc7
->dpcLineCaps
.dwAlphaCmpCaps
= wined3d_caps
.AlphaCmpCaps
;
4775 desc7
->dpcLineCaps
.dwShadeCaps
= wined3d_caps
.ShadeCaps
;
4776 desc7
->dpcLineCaps
.dwTextureCaps
= wined3d_caps
.TextureCaps
;
4777 desc7
->dpcLineCaps
.dwTextureFilterCaps
= wined3d_caps
.TextureFilterCaps
;
4778 desc7
->dpcLineCaps
.dwTextureAddressCaps
= wined3d_caps
.TextureAddressCaps
;
4780 desc7
->dwMaxTextureWidth
= wined3d_caps
.MaxTextureWidth
;
4781 desc7
->dwMaxTextureHeight
= wined3d_caps
.MaxTextureHeight
;
4783 desc7
->dwMaxTextureRepeat
= wined3d_caps
.MaxTextureRepeat
;
4784 desc7
->dwMaxTextureAspectRatio
= wined3d_caps
.MaxTextureAspectRatio
;
4785 desc7
->dwMaxAnisotropy
= wined3d_caps
.MaxAnisotropy
;
4786 desc7
->dvMaxVertexW
= wined3d_caps
.MaxVertexW
;
4788 desc7
->dvGuardBandLeft
= wined3d_caps
.GuardBandLeft
;
4789 desc7
->dvGuardBandTop
= wined3d_caps
.GuardBandTop
;
4790 desc7
->dvGuardBandRight
= wined3d_caps
.GuardBandRight
;
4791 desc7
->dvGuardBandBottom
= wined3d_caps
.GuardBandBottom
;
4793 desc7
->dvExtentsAdjust
= wined3d_caps
.ExtentsAdjust
;
4794 desc7
->dwStencilCaps
= wined3d_caps
.StencilCaps
;
4796 desc7
->dwFVFCaps
= wined3d_caps
.FVFCaps
;
4797 desc7
->dwTextureOpCaps
= wined3d_caps
.TextureOpCaps
;
4799 desc7
->dwVertexProcessingCaps
= wined3d_caps
.VertexProcessingCaps
;
4800 desc7
->dwMaxActiveLights
= wined3d_caps
.MaxActiveLights
;
4802 /* Remove all non-d3d7 caps */
4803 desc7
->dwDevCaps
&= (
4804 D3DDEVCAPS_FLOATTLVERTEX
| D3DDEVCAPS_SORTINCREASINGZ
| D3DDEVCAPS_SORTDECREASINGZ
|
4805 D3DDEVCAPS_SORTEXACT
| D3DDEVCAPS_EXECUTESYSTEMMEMORY
| D3DDEVCAPS_EXECUTEVIDEOMEMORY
|
4806 D3DDEVCAPS_TLVERTEXSYSTEMMEMORY
| D3DDEVCAPS_TLVERTEXVIDEOMEMORY
| D3DDEVCAPS_TEXTURESYSTEMMEMORY
|
4807 D3DDEVCAPS_TEXTUREVIDEOMEMORY
| D3DDEVCAPS_DRAWPRIMTLVERTEX
| D3DDEVCAPS_CANRENDERAFTERFLIP
|
4808 D3DDEVCAPS_TEXTURENONLOCALVIDMEM
| D3DDEVCAPS_DRAWPRIMITIVES2
| D3DDEVCAPS_SEPARATETEXTUREMEMORIES
|
4809 D3DDEVCAPS_DRAWPRIMITIVES2EX
| D3DDEVCAPS_HWTRANSFORMANDLIGHT
| D3DDEVCAPS_CANBLTSYSTONONLOCAL
|
4810 D3DDEVCAPS_HWRASTERIZATION
);
4812 desc7
->dwStencilCaps
&= (
4813 D3DSTENCILCAPS_KEEP
| D3DSTENCILCAPS_ZERO
| D3DSTENCILCAPS_REPLACE
|
4814 D3DSTENCILCAPS_INCRSAT
| D3DSTENCILCAPS_DECRSAT
| D3DSTENCILCAPS_INVERT
|
4815 D3DSTENCILCAPS_INCR
| D3DSTENCILCAPS_DECR
);
4819 desc7
->dwTextureOpCaps
&= (
4820 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
| D3DTEXOPCAPS_SELECTARG2
|
4821 D3DTEXOPCAPS_MODULATE
| D3DTEXOPCAPS_MODULATE2X
| D3DTEXOPCAPS_MODULATE4X
|
4822 D3DTEXOPCAPS_ADD
| D3DTEXOPCAPS_ADDSIGNED
| D3DTEXOPCAPS_ADDSIGNED2X
|
4823 D3DTEXOPCAPS_SUBTRACT
| D3DTEXOPCAPS_ADDSMOOTH
| D3DTEXOPCAPS_BLENDTEXTUREALPHA
|
4824 D3DTEXOPCAPS_BLENDFACTORALPHA
| D3DTEXOPCAPS_BLENDTEXTUREALPHAPM
| D3DTEXOPCAPS_BLENDCURRENTALPHA
|
4825 D3DTEXOPCAPS_PREMODULATE
| D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA
|
4826 D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA
| D3DTEXOPCAPS_BUMPENVMAP
|
4827 D3DTEXOPCAPS_BUMPENVMAPLUMINANCE
| D3DTEXOPCAPS_DOTPRODUCT3
);
4829 desc7
->dwVertexProcessingCaps
&= (
4830 D3DVTXPCAPS_TEXGEN
| D3DVTXPCAPS_MATERIALSOURCE7
| D3DVTXPCAPS_VERTEXFOG
|
4831 D3DVTXPCAPS_DIRECTIONALLIGHTS
| D3DVTXPCAPS_POSITIONALLIGHTS
| D3DVTXPCAPS_LOCALVIEWER
);
4833 desc7
->dpcLineCaps
.dwMiscCaps
&= (
4834 D3DPMISCCAPS_MASKPLANES
| D3DPMISCCAPS_MASKZ
| D3DPMISCCAPS_LINEPATTERNREP
|
4835 D3DPMISCCAPS_CONFORMANT
| D3DPMISCCAPS_CULLNONE
| D3DPMISCCAPS_CULLCW
|
4836 D3DPMISCCAPS_CULLCCW
);
4838 desc7
->dpcLineCaps
.dwRasterCaps
&= (
4839 D3DPRASTERCAPS_DITHER
| D3DPRASTERCAPS_ROP2
| D3DPRASTERCAPS_XOR
|
4840 D3DPRASTERCAPS_PAT
| D3DPRASTERCAPS_ZTEST
| D3DPRASTERCAPS_SUBPIXEL
|
4841 D3DPRASTERCAPS_SUBPIXELX
| D3DPRASTERCAPS_FOGVERTEX
| D3DPRASTERCAPS_FOGTABLE
|
4842 D3DPRASTERCAPS_STIPPLE
| D3DPRASTERCAPS_ANTIALIASSORTDEPENDENT
| D3DPRASTERCAPS_ANTIALIASSORTINDEPENDENT
|
4843 D3DPRASTERCAPS_ANTIALIASEDGES
| D3DPRASTERCAPS_MIPMAPLODBIAS
| D3DPRASTERCAPS_ZBIAS
|
4844 D3DPRASTERCAPS_ZBUFFERLESSHSR
| D3DPRASTERCAPS_FOGRANGE
| D3DPRASTERCAPS_ANISOTROPY
|
4845 D3DPRASTERCAPS_WBUFFER
| D3DPRASTERCAPS_TRANSLUCENTSORTINDEPENDENT
| D3DPRASTERCAPS_WFOG
|
4846 D3DPRASTERCAPS_ZFOG
);
4848 desc7
->dpcLineCaps
.dwZCmpCaps
&= (
4849 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
4850 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
4851 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
4853 desc7
->dpcLineCaps
.dwSrcBlendCaps
&= (
4854 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
4855 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
4856 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
4857 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
4858 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
4860 desc7
->dpcLineCaps
.dwDestBlendCaps
&= (
4861 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
4862 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
4863 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
4864 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
4865 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
4867 desc7
->dpcLineCaps
.dwAlphaCmpCaps
&= (
4868 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
4869 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
4870 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
4872 desc7
->dpcLineCaps
.dwShadeCaps
&= (
4873 D3DPSHADECAPS_COLORFLATMONO
| D3DPSHADECAPS_COLORFLATRGB
| D3DPSHADECAPS_COLORGOURAUDMONO
|
4874 D3DPSHADECAPS_COLORGOURAUDRGB
| D3DPSHADECAPS_COLORPHONGMONO
| D3DPSHADECAPS_COLORPHONGRGB
|
4875 D3DPSHADECAPS_SPECULARFLATMONO
| D3DPSHADECAPS_SPECULARFLATRGB
| D3DPSHADECAPS_SPECULARGOURAUDMONO
|
4876 D3DPSHADECAPS_SPECULARGOURAUDRGB
| D3DPSHADECAPS_SPECULARPHONGMONO
| D3DPSHADECAPS_SPECULARPHONGRGB
|
4877 D3DPSHADECAPS_ALPHAFLATBLEND
| D3DPSHADECAPS_ALPHAFLATSTIPPLED
| D3DPSHADECAPS_ALPHAGOURAUDBLEND
|
4878 D3DPSHADECAPS_ALPHAGOURAUDSTIPPLED
| D3DPSHADECAPS_ALPHAPHONGBLEND
| D3DPSHADECAPS_ALPHAPHONGSTIPPLED
|
4879 D3DPSHADECAPS_FOGFLAT
| D3DPSHADECAPS_FOGGOURAUD
| D3DPSHADECAPS_FOGPHONG
);
4881 desc7
->dpcLineCaps
.dwTextureCaps
&= (
4882 D3DPTEXTURECAPS_PERSPECTIVE
| D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_ALPHA
|
4883 D3DPTEXTURECAPS_TRANSPARENCY
| D3DPTEXTURECAPS_BORDER
| D3DPTEXTURECAPS_SQUAREONLY
|
4884 D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE
| D3DPTEXTURECAPS_ALPHAPALETTE
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
|
4885 D3DPTEXTURECAPS_PROJECTED
| D3DPTEXTURECAPS_CUBEMAP
| D3DPTEXTURECAPS_COLORKEYBLEND
);
4887 desc7
->dpcLineCaps
.dwTextureFilterCaps
&= (
4888 D3DPTFILTERCAPS_NEAREST
| D3DPTFILTERCAPS_LINEAR
| D3DPTFILTERCAPS_MIPNEAREST
|
4889 D3DPTFILTERCAPS_MIPLINEAR
| D3DPTFILTERCAPS_LINEARMIPNEAREST
| D3DPTFILTERCAPS_LINEARMIPLINEAR
|
4890 D3DPTFILTERCAPS_MINFPOINT
| D3DPTFILTERCAPS_MINFLINEAR
| D3DPTFILTERCAPS_MINFANISOTROPIC
|
4891 D3DPTFILTERCAPS_MIPFPOINT
| D3DPTFILTERCAPS_MIPFLINEAR
| D3DPTFILTERCAPS_MAGFPOINT
|
4892 D3DPTFILTERCAPS_MAGFLINEAR
| D3DPTFILTERCAPS_MAGFANISOTROPIC
| D3DPTFILTERCAPS_MAGFAFLATCUBIC
|
4893 D3DPTFILTERCAPS_MAGFGAUSSIANCUBIC
);
4895 desc7
->dpcLineCaps
.dwTextureBlendCaps
&= (
4896 D3DPTBLENDCAPS_DECAL
| D3DPTBLENDCAPS_MODULATE
| D3DPTBLENDCAPS_DECALALPHA
|
4897 D3DPTBLENDCAPS_MODULATEALPHA
| D3DPTBLENDCAPS_DECALMASK
| D3DPTBLENDCAPS_MODULATEMASK
|
4898 D3DPTBLENDCAPS_COPY
| D3DPTBLENDCAPS_ADD
);
4900 desc7
->dpcLineCaps
.dwTextureAddressCaps
&= (
4901 D3DPTADDRESSCAPS_WRAP
| D3DPTADDRESSCAPS_MIRROR
| D3DPTADDRESSCAPS_CLAMP
|
4902 D3DPTADDRESSCAPS_BORDER
| D3DPTADDRESSCAPS_INDEPENDENTUV
);
4904 if (!(desc7
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
))
4906 /* DirectX7 always has the np2 flag set, no matter what the card
4907 * supports. Some old games (Rollcage) check the caps incorrectly.
4908 * If wined3d supports nonpow2 textures it also has np2 conditional
4910 desc7
->dpcLineCaps
.dwTextureCaps
|= D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
;
4913 /* Fill the missing members, and do some fixup */
4914 desc7
->dpcLineCaps
.dwSize
= sizeof(desc7
->dpcLineCaps
);
4915 desc7
->dpcLineCaps
.dwTextureBlendCaps
= D3DPTBLENDCAPS_ADD
| D3DPTBLENDCAPS_MODULATEMASK
|
4916 D3DPTBLENDCAPS_COPY
| D3DPTBLENDCAPS_DECAL
|
4917 D3DPTBLENDCAPS_DECALALPHA
| D3DPTBLENDCAPS_DECALMASK
|
4918 D3DPTBLENDCAPS_MODULATE
| D3DPTBLENDCAPS_MODULATEALPHA
;
4919 desc7
->dpcLineCaps
.dwStippleWidth
= 32;
4920 desc7
->dpcLineCaps
.dwStippleHeight
= 32;
4921 /* Use the same for the TriCaps */
4922 desc7
->dpcTriCaps
= desc7
->dpcLineCaps
;
4924 desc7
->dwDeviceRenderBitDepth
= DDBD_16
| DDBD_24
| DDBD_32
;
4925 desc7
->dwDeviceZBufferBitDepth
= DDBD_16
| DDBD_24
;
4926 desc7
->dwMinTextureWidth
= 1;
4927 desc7
->dwMinTextureHeight
= 1;
4929 /* Convert DWORDs safely to WORDs */
4930 if (wined3d_caps
.MaxTextureBlendStages
> 0xffff) desc7
->wMaxTextureBlendStages
= 0xffff;
4931 else desc7
->wMaxTextureBlendStages
= (WORD
)wined3d_caps
.MaxTextureBlendStages
;
4932 if (wined3d_caps
.MaxSimultaneousTextures
> 0xffff) desc7
->wMaxSimultaneousTextures
= 0xffff;
4933 else desc7
->wMaxSimultaneousTextures
= (WORD
)wined3d_caps
.MaxSimultaneousTextures
;
4935 if (wined3d_caps
.MaxUserClipPlanes
> 0xffff) desc7
->wMaxUserClipPlanes
= 0xffff;
4936 else desc7
->wMaxUserClipPlanes
= (WORD
)wined3d_caps
.MaxUserClipPlanes
;
4937 if (wined3d_caps
.MaxVertexBlendMatrices
> 0xffff) desc7
->wMaxVertexBlendMatrices
= 0xffff;
4938 else desc7
->wMaxVertexBlendMatrices
= (WORD
)wined3d_caps
.MaxVertexBlendMatrices
;
4940 desc7
->deviceGUID
= IID_IDirect3DTnLHalDevice
;
4942 desc7
->dwReserved1
= 0;
4943 desc7
->dwReserved2
= 0;
4944 desc7
->dwReserved3
= 0;
4945 desc7
->dwReserved4
= 0;
4947 /* Fill the old structure */
4948 memset(desc1
, 0, sizeof(*desc1
));
4949 desc1
->dwSize
= sizeof(D3DDEVICEDESC
);
4950 desc1
->dwFlags
= D3DDD_COLORMODEL
4952 | D3DDD_TRANSFORMCAPS
4954 | D3DDD_LIGHTINGCAPS
4957 | D3DDD_DEVICERENDERBITDEPTH
4958 | D3DDD_DEVICEZBUFFERBITDEPTH
4959 | D3DDD_MAXBUFFERSIZE
4960 | D3DDD_MAXVERTEXCOUNT
;
4962 desc1
->dcmColorModel
= D3DCOLOR_RGB
;
4963 desc1
->dwDevCaps
= desc7
->dwDevCaps
;
4964 desc1
->dtcTransformCaps
.dwSize
= sizeof(D3DTRANSFORMCAPS
);
4965 desc1
->dtcTransformCaps
.dwCaps
= D3DTRANSFORMCAPS_CLIP
;
4966 desc1
->bClipping
= TRUE
;
4967 desc1
->dlcLightingCaps
.dwSize
= sizeof(D3DLIGHTINGCAPS
);
4968 desc1
->dlcLightingCaps
.dwCaps
= D3DLIGHTCAPS_DIRECTIONAL
4969 | D3DLIGHTCAPS_PARALLELPOINT
4970 | D3DLIGHTCAPS_POINT
4971 | D3DLIGHTCAPS_SPOT
;
4973 desc1
->dlcLightingCaps
.dwLightingModel
= D3DLIGHTINGMODEL_RGB
;
4974 desc1
->dlcLightingCaps
.dwNumLights
= desc7
->dwMaxActiveLights
;
4976 desc1
->dpcLineCaps
.dwSize
= sizeof(D3DPRIMCAPS
);
4977 desc1
->dpcLineCaps
.dwMiscCaps
= desc7
->dpcLineCaps
.dwMiscCaps
;
4978 desc1
->dpcLineCaps
.dwRasterCaps
= desc7
->dpcLineCaps
.dwRasterCaps
;
4979 desc1
->dpcLineCaps
.dwZCmpCaps
= desc7
->dpcLineCaps
.dwZCmpCaps
;
4980 desc1
->dpcLineCaps
.dwSrcBlendCaps
= desc7
->dpcLineCaps
.dwSrcBlendCaps
;
4981 desc1
->dpcLineCaps
.dwDestBlendCaps
= desc7
->dpcLineCaps
.dwDestBlendCaps
;
4982 desc1
->dpcLineCaps
.dwShadeCaps
= desc7
->dpcLineCaps
.dwShadeCaps
;
4983 desc1
->dpcLineCaps
.dwTextureCaps
= desc7
->dpcLineCaps
.dwTextureCaps
;
4984 desc1
->dpcLineCaps
.dwTextureFilterCaps
= desc7
->dpcLineCaps
.dwTextureFilterCaps
;
4985 desc1
->dpcLineCaps
.dwTextureBlendCaps
= desc7
->dpcLineCaps
.dwTextureBlendCaps
;
4986 desc1
->dpcLineCaps
.dwTextureAddressCaps
= desc7
->dpcLineCaps
.dwTextureAddressCaps
;
4987 desc1
->dpcLineCaps
.dwStippleWidth
= desc7
->dpcLineCaps
.dwStippleWidth
;
4988 desc1
->dpcLineCaps
.dwAlphaCmpCaps
= desc7
->dpcLineCaps
.dwAlphaCmpCaps
;
4990 desc1
->dpcTriCaps
.dwSize
= sizeof(D3DPRIMCAPS
);
4991 desc1
->dpcTriCaps
.dwMiscCaps
= desc7
->dpcTriCaps
.dwMiscCaps
;
4992 desc1
->dpcTriCaps
.dwRasterCaps
= desc7
->dpcTriCaps
.dwRasterCaps
;
4993 desc1
->dpcTriCaps
.dwZCmpCaps
= desc7
->dpcTriCaps
.dwZCmpCaps
;
4994 desc1
->dpcTriCaps
.dwSrcBlendCaps
= desc7
->dpcTriCaps
.dwSrcBlendCaps
;
4995 desc1
->dpcTriCaps
.dwDestBlendCaps
= desc7
->dpcTriCaps
.dwDestBlendCaps
;
4996 desc1
->dpcTriCaps
.dwShadeCaps
= desc7
->dpcTriCaps
.dwShadeCaps
;
4997 desc1
->dpcTriCaps
.dwTextureCaps
= desc7
->dpcTriCaps
.dwTextureCaps
;
4998 desc1
->dpcTriCaps
.dwTextureFilterCaps
= desc7
->dpcTriCaps
.dwTextureFilterCaps
;
4999 desc1
->dpcTriCaps
.dwTextureBlendCaps
= desc7
->dpcTriCaps
.dwTextureBlendCaps
;
5000 desc1
->dpcTriCaps
.dwTextureAddressCaps
= desc7
->dpcTriCaps
.dwTextureAddressCaps
;
5001 desc1
->dpcTriCaps
.dwStippleWidth
= desc7
->dpcTriCaps
.dwStippleWidth
;
5002 desc1
->dpcTriCaps
.dwAlphaCmpCaps
= desc7
->dpcTriCaps
.dwAlphaCmpCaps
;
5004 desc1
->dwDeviceRenderBitDepth
= desc7
->dwDeviceRenderBitDepth
;
5005 desc1
->dwDeviceZBufferBitDepth
= desc7
->dwDeviceZBufferBitDepth
;
5006 desc1
->dwMaxBufferSize
= 0;
5007 desc1
->dwMaxVertexCount
= 65536;
5008 desc1
->dwMinTextureWidth
= desc7
->dwMinTextureWidth
;
5009 desc1
->dwMinTextureHeight
= desc7
->dwMinTextureHeight
;
5010 desc1
->dwMaxTextureWidth
= desc7
->dwMaxTextureWidth
;
5011 desc1
->dwMaxTextureHeight
= desc7
->dwMaxTextureHeight
;
5012 desc1
->dwMinStippleWidth
= 1;
5013 desc1
->dwMinStippleHeight
= 1;
5014 desc1
->dwMaxStippleWidth
= 32;
5015 desc1
->dwMaxStippleHeight
= 32;
5016 desc1
->dwMaxTextureRepeat
= desc7
->dwMaxTextureRepeat
;
5017 desc1
->dwMaxTextureAspectRatio
= desc7
->dwMaxTextureAspectRatio
;
5018 desc1
->dwMaxAnisotropy
= desc7
->dwMaxAnisotropy
;
5019 desc1
->dvGuardBandLeft
= desc7
->dvGuardBandLeft
;
5020 desc1
->dvGuardBandRight
= desc7
->dvGuardBandRight
;
5021 desc1
->dvGuardBandTop
= desc7
->dvGuardBandTop
;
5022 desc1
->dvGuardBandBottom
= desc7
->dvGuardBandBottom
;
5023 desc1
->dvExtentsAdjust
= desc7
->dvExtentsAdjust
;
5024 desc1
->dwStencilCaps
= desc7
->dwStencilCaps
;
5025 desc1
->dwFVFCaps
= desc7
->dwFVFCaps
;
5026 desc1
->dwTextureOpCaps
= desc7
->dwTextureOpCaps
;
5027 desc1
->wMaxTextureBlendStages
= desc7
->wMaxTextureBlendStages
;
5028 desc1
->wMaxSimultaneousTextures
= desc7
->wMaxSimultaneousTextures
;
5033 /*****************************************************************************
5034 * IDirectDraw7 VTable
5035 *****************************************************************************/
5036 static const struct IDirectDraw7Vtbl ddraw7_vtbl
=
5039 ddraw7_QueryInterface
,
5044 ddraw7_CreateClipper
,
5045 ddraw7_CreatePalette
,
5046 ddraw7_CreateSurface
,
5047 ddraw7_DuplicateSurface
,
5048 ddraw7_EnumDisplayModes
,
5049 ddraw7_EnumSurfaces
,
5050 ddraw7_FlipToGDISurface
,
5052 ddraw7_GetDisplayMode
,
5053 ddraw7_GetFourCCCodes
,
5054 ddraw7_GetGDISurface
,
5055 ddraw7_GetMonitorFrequency
,
5057 ddraw7_GetVerticalBlankStatus
,
5059 ddraw7_RestoreDisplayMode
,
5060 ddraw7_SetCooperativeLevel
,
5061 ddraw7_SetDisplayMode
,
5062 ddraw7_WaitForVerticalBlank
,
5064 ddraw7_GetAvailableVidMem
,
5066 ddraw7_GetSurfaceFromDC
,
5068 ddraw7_RestoreAllSurfaces
,
5069 ddraw7_TestCooperativeLevel
,
5070 ddraw7_GetDeviceIdentifier
,
5072 ddraw7_StartModeTest
,
5076 static const struct IDirectDraw4Vtbl ddraw4_vtbl
=
5079 ddraw4_QueryInterface
,
5084 ddraw4_CreateClipper
,
5085 ddraw4_CreatePalette
,
5086 ddraw4_CreateSurface
,
5087 ddraw4_DuplicateSurface
,
5088 ddraw4_EnumDisplayModes
,
5089 ddraw4_EnumSurfaces
,
5090 ddraw4_FlipToGDISurface
,
5092 ddraw4_GetDisplayMode
,
5093 ddraw4_GetFourCCCodes
,
5094 ddraw4_GetGDISurface
,
5095 ddraw4_GetMonitorFrequency
,
5097 ddraw4_GetVerticalBlankStatus
,
5099 ddraw4_RestoreDisplayMode
,
5100 ddraw4_SetCooperativeLevel
,
5101 ddraw4_SetDisplayMode
,
5102 ddraw4_WaitForVerticalBlank
,
5104 ddraw4_GetAvailableVidMem
,
5106 ddraw4_GetSurfaceFromDC
,
5108 ddraw4_RestoreAllSurfaces
,
5109 ddraw4_TestCooperativeLevel
,
5110 ddraw4_GetDeviceIdentifier
,
5113 static const struct IDirectDraw2Vtbl ddraw2_vtbl
=
5116 ddraw2_QueryInterface
,
5121 ddraw2_CreateClipper
,
5122 ddraw2_CreatePalette
,
5123 ddraw2_CreateSurface
,
5124 ddraw2_DuplicateSurface
,
5125 ddraw2_EnumDisplayModes
,
5126 ddraw2_EnumSurfaces
,
5127 ddraw2_FlipToGDISurface
,
5129 ddraw2_GetDisplayMode
,
5130 ddraw2_GetFourCCCodes
,
5131 ddraw2_GetGDISurface
,
5132 ddraw2_GetMonitorFrequency
,
5134 ddraw2_GetVerticalBlankStatus
,
5136 ddraw2_RestoreDisplayMode
,
5137 ddraw2_SetCooperativeLevel
,
5138 ddraw2_SetDisplayMode
,
5139 ddraw2_WaitForVerticalBlank
,
5141 ddraw2_GetAvailableVidMem
,
5144 static const struct IDirectDrawVtbl ddraw1_vtbl
=
5147 ddraw1_QueryInterface
,
5152 ddraw1_CreateClipper
,
5153 ddraw1_CreatePalette
,
5154 ddraw1_CreateSurface
,
5155 ddraw1_DuplicateSurface
,
5156 ddraw1_EnumDisplayModes
,
5157 ddraw1_EnumSurfaces
,
5158 ddraw1_FlipToGDISurface
,
5160 ddraw1_GetDisplayMode
,
5161 ddraw1_GetFourCCCodes
,
5162 ddraw1_GetGDISurface
,
5163 ddraw1_GetMonitorFrequency
,
5165 ddraw1_GetVerticalBlankStatus
,
5167 ddraw1_RestoreDisplayMode
,
5168 ddraw1_SetCooperativeLevel
,
5169 ddraw1_SetDisplayMode
,
5170 ddraw1_WaitForVerticalBlank
,
5173 static const struct IDirect3D7Vtbl d3d7_vtbl
=
5175 /* IUnknown methods */
5176 d3d7_QueryInterface
,
5179 /* IDirect3D7 methods */
5182 d3d7_CreateVertexBuffer
,
5183 d3d7_EnumZBufferFormats
,
5184 d3d7_EvictManagedTextures
5187 static const struct IDirect3D3Vtbl d3d3_vtbl
=
5189 /* IUnknown methods */
5190 d3d3_QueryInterface
,
5193 /* IDirect3D3 methods */
5196 d3d3_CreateMaterial
,
5197 d3d3_CreateViewport
,
5200 d3d3_CreateVertexBuffer
,
5201 d3d3_EnumZBufferFormats
,
5202 d3d3_EvictManagedTextures
5205 static const struct IDirect3D2Vtbl d3d2_vtbl
=
5207 /* IUnknown methods */
5208 d3d2_QueryInterface
,
5211 /* IDirect3D2 methods */
5214 d3d2_CreateMaterial
,
5215 d3d2_CreateViewport
,
5220 static const struct IDirect3DVtbl d3d1_vtbl
=
5222 /* IUnknown methods */
5223 d3d1_QueryInterface
,
5226 /* IDirect3D methods */
5230 d3d1_CreateMaterial
,
5231 d3d1_CreateViewport
,
5235 /*****************************************************************************
5238 * Finds the WineD3D vertex declaration for a specific fvf, and creates one
5239 * if none was found.
5241 * This function is in ddraw.c and the DDraw object space because D3D7
5242 * vertex buffers are created using the IDirect3D interface to the ddraw
5243 * object, so they can be valid across D3D devices(theoretically. The ddraw
5244 * object also owns the wined3d device
5248 * fvf: Fvf to find the decl for
5251 * NULL in case of an error, the vertex declaration for the FVF otherwise.
5253 *****************************************************************************/
5254 struct wined3d_vertex_declaration
*ddraw_find_decl(struct ddraw
*This
, DWORD fvf
)
5256 struct wined3d_vertex_declaration
*pDecl
= NULL
;
5258 int p
, low
, high
; /* deliberately signed */
5259 struct FvfToDecl
*convertedDecls
= This
->decls
;
5261 TRACE("Searching for declaration for fvf %08x... ", fvf
);
5264 high
= This
->numConvertedDecls
- 1;
5265 while(low
<= high
) {
5266 p
= (low
+ high
) >> 1;
5268 if(convertedDecls
[p
].fvf
== fvf
) {
5269 TRACE("found %p\n", convertedDecls
[p
].decl
);
5270 return convertedDecls
[p
].decl
;
5271 } else if(convertedDecls
[p
].fvf
< fvf
) {
5277 TRACE("not found. Creating and inserting at position %d.\n", low
);
5279 hr
= wined3d_vertex_declaration_create_from_fvf(This
->wined3d_device
,
5280 fvf
, This
, &ddraw_null_wined3d_parent_ops
, &pDecl
);
5281 if (hr
!= S_OK
) return NULL
;
5283 if(This
->declArraySize
== This
->numConvertedDecls
) {
5284 int grow
= max(This
->declArraySize
/ 2, 8);
5285 convertedDecls
= HeapReAlloc(GetProcessHeap(), 0, convertedDecls
,
5286 sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
+ grow
));
5287 if (!convertedDecls
)
5289 wined3d_vertex_declaration_decref(pDecl
);
5292 This
->decls
= convertedDecls
;
5293 This
->declArraySize
+= grow
;
5296 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
, sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
- low
));
5297 convertedDecls
[low
].decl
= pDecl
;
5298 convertedDecls
[low
].fvf
= fvf
;
5299 This
->numConvertedDecls
++;
5301 TRACE("Returning %p. %d decls in array\n", pDecl
, This
->numConvertedDecls
);
5305 static inline struct ddraw
*ddraw_from_device_parent(struct wined3d_device_parent
*device_parent
)
5307 return CONTAINING_RECORD(device_parent
, struct ddraw
, device_parent
);
5310 static void CDECL
device_parent_wined3d_device_created(struct wined3d_device_parent
*device_parent
,
5311 struct wined3d_device
*device
)
5313 TRACE("device_parent %p, device %p.\n", device_parent
, device
);
5316 /* This is run from device_process_message() in wined3d, we can't take the
5318 static void CDECL
device_parent_mode_changed(struct wined3d_device_parent
*device_parent
)
5320 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
5321 MONITORINFO monitor_info
;
5326 TRACE("device_parent %p.\n", device_parent
);
5328 if (!(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
) || !ddraw
->swapchain_window
)
5330 TRACE("Nothing to resize.\n");
5334 monitor
= MonitorFromWindow(ddraw
->swapchain_window
, MONITOR_DEFAULTTOPRIMARY
);
5335 monitor_info
.cbSize
= sizeof(monitor_info
);
5336 if (!(ret
= GetMonitorInfoW(monitor
, &monitor_info
)))
5338 ERR("Failed to get monitor info.\n");
5342 r
= &monitor_info
.rcMonitor
;
5343 TRACE("Resizing window %p to %s.\n", ddraw
->swapchain_window
, wine_dbgstr_rect(r
));
5345 if (!(ret
= SetWindowPos(ddraw
->swapchain_window
, HWND_TOP
, r
->left
, r
->top
,
5346 r
->right
- r
->left
, r
->bottom
- r
->top
, SWP_SHOWWINDOW
| SWP_NOACTIVATE
)))
5347 ERR("Failed to resize window.\n");
5350 static HRESULT CDECL
device_parent_create_surface(struct wined3d_device_parent
*device_parent
,
5351 void *container_parent
, UINT width
, UINT height
, enum wined3d_format_id format
, DWORD usage
,
5352 enum wined3d_pool pool
, UINT level
, enum wined3d_cubemap_face face
, struct wined3d_surface
**surface
)
5354 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
5355 struct ddraw_surface
*surf
= NULL
;
5357 DDSCAPS2 searchcaps
= ddraw
->tex_root
->surface_desc
.ddsCaps
;
5359 TRACE("device_parent %p, container_parent %p, width %u, height %u, format %#x, usage %#x,\n"
5360 "\tpool %#x, level %u, face %u, surface %p.\n",
5361 device_parent
, container_parent
, width
, height
, format
, usage
, pool
, level
, face
, surface
);
5363 searchcaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
5366 case WINED3D_CUBEMAP_FACE_POSITIVE_X
:
5367 TRACE("Asked for positive x\n");
5368 if (searchcaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5370 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
5372 surf
= ddraw
->tex_root
; break;
5373 case WINED3D_CUBEMAP_FACE_NEGATIVE_X
:
5374 TRACE("Asked for negative x\n");
5375 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEX
; break;
5376 case WINED3D_CUBEMAP_FACE_POSITIVE_Y
:
5377 TRACE("Asked for positive y\n");
5378 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEY
; break;
5379 case WINED3D_CUBEMAP_FACE_NEGATIVE_Y
:
5380 TRACE("Asked for negative y\n");
5381 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEY
; break;
5382 case WINED3D_CUBEMAP_FACE_POSITIVE_Z
:
5383 TRACE("Asked for positive z\n");
5384 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEZ
; break;
5385 case WINED3D_CUBEMAP_FACE_NEGATIVE_Z
:
5386 TRACE("Asked for negative z\n");
5387 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEZ
; break;
5389 ERR("Unexpected cube face.\n");
5394 IDirectDrawSurface7
*attached
;
5395 IDirectDrawSurface7_GetAttachedSurface(&ddraw
->tex_root
->IDirectDrawSurface7_iface
, &searchcaps
, &attached
);
5396 surf
= unsafe_impl_from_IDirectDrawSurface7(attached
);
5397 IDirectDrawSurface7_Release(attached
);
5399 if (!surf
) ERR("root search surface not found\n");
5401 /* Find the wanted mipmap. There are enough mipmaps in the chain */
5404 IDirectDrawSurface7
*attached
;
5405 IDirectDrawSurface7_GetAttachedSurface(&surf
->IDirectDrawSurface7_iface
, &searchcaps
, &attached
);
5406 if(!attached
) ERR("Surface not found\n");
5407 surf
= impl_from_IDirectDrawSurface7(attached
);
5408 IDirectDrawSurface7_Release(attached
);
5412 /* Return the surface */
5413 *surface
= surf
->wined3d_surface
;
5414 wined3d_surface_incref(*surface
);
5416 TRACE("Returning wineD3DSurface %p, it belongs to surface %p\n", *surface
, surf
);
5421 static void STDMETHODCALLTYPE
ddraw_frontbuffer_destroyed(void *parent
)
5423 struct ddraw
*ddraw
= parent
;
5424 ddraw
->wined3d_frontbuffer
= NULL
;
5427 static const struct wined3d_parent_ops ddraw_frontbuffer_parent_ops
=
5429 ddraw_frontbuffer_destroyed
,
5432 static HRESULT CDECL
device_parent_create_rendertarget(struct wined3d_device_parent
*device_parent
,
5433 void *container_parent
, UINT width
, UINT height
, enum wined3d_format_id format
,
5434 enum wined3d_multisample_type multisample_type
, DWORD multisample_quality
, BOOL lockable
,
5435 struct wined3d_surface
**surface
)
5437 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
5441 TRACE("device_parent %p, container_parent %p, width %u, height %u, format %#x, multisample_type %#x,\n"
5442 "\tmultisample_quality %u, lockable %u, surface %p.\n",
5443 device_parent
, container_parent
, width
, height
, format
, multisample_type
,
5444 multisample_quality
, lockable
, surface
);
5446 if (ddraw
->wined3d_frontbuffer
)
5448 ERR("Frontbuffer already created.\n");
5453 flags
|= WINED3D_SURFACE_MAPPABLE
;
5455 hr
= wined3d_surface_create(ddraw
->wined3d_device
, width
, height
, format
, 0,
5456 WINED3DUSAGE_RENDERTARGET
, WINED3D_POOL_DEFAULT
, multisample_type
, multisample_quality
,
5457 DefaultSurfaceType
, flags
, ddraw
, &ddraw_frontbuffer_parent_ops
, surface
);
5459 ddraw
->wined3d_frontbuffer
= *surface
;
5464 static HRESULT CDECL
device_parent_create_depth_stencil(struct wined3d_device_parent
*device_parent
,
5465 UINT width
, UINT height
, enum wined3d_format_id format
, enum wined3d_multisample_type multisample_type
,
5466 DWORD multisample_quality
, BOOL discard
, struct wined3d_surface
**surface
)
5468 ERR("DirectDraw doesn't have and shouldn't try creating implicit depth buffers.\n");
5472 static HRESULT CDECL
device_parent_create_volume(struct wined3d_device_parent
*device_parent
,
5473 void *container_parent
, UINT width
, UINT height
, UINT depth
, enum wined3d_format_id format
,
5474 enum wined3d_pool pool
, DWORD usage
, struct wined3d_volume
**volume
)
5476 TRACE("device_parent %p, container_parent %p, width %u, height %u, depth %u, "
5477 "format %#x, pool %#x, usage %#x, volume %p.\n",
5478 device_parent
, container_parent
, width
, height
, depth
,
5479 format
, pool
, usage
, volume
);
5481 ERR("Not implemented!\n");
5486 static HRESULT CDECL
device_parent_create_swapchain(struct wined3d_device_parent
*device_parent
,
5487 struct wined3d_swapchain_desc
*desc
, struct wined3d_swapchain
**swapchain
)
5489 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
5492 TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent
, desc
, swapchain
);
5494 if (ddraw
->wined3d_swapchain
)
5496 ERR("Swapchain already created.\n");
5500 hr
= wined3d_swapchain_create(ddraw
->wined3d_device
, desc
,
5501 DefaultSurfaceType
, NULL
, &ddraw_null_wined3d_parent_ops
, swapchain
);
5503 WARN("Failed to create swapchain, hr %#x.\n", hr
);
5508 static const struct wined3d_device_parent_ops ddraw_wined3d_device_parent_ops
=
5510 device_parent_wined3d_device_created
,
5511 device_parent_mode_changed
,
5512 device_parent_create_surface
,
5513 device_parent_create_rendertarget
,
5514 device_parent_create_depth_stencil
,
5515 device_parent_create_volume
,
5516 device_parent_create_swapchain
,
5519 HRESULT
ddraw_init(struct ddraw
*ddraw
, enum wined3d_device_type device_type
)
5524 ddraw
->IDirectDraw7_iface
.lpVtbl
= &ddraw7_vtbl
;
5525 ddraw
->IDirectDraw_iface
.lpVtbl
= &ddraw1_vtbl
;
5526 ddraw
->IDirectDraw2_iface
.lpVtbl
= &ddraw2_vtbl
;
5527 ddraw
->IDirectDraw4_iface
.lpVtbl
= &ddraw4_vtbl
;
5528 ddraw
->IDirect3D_iface
.lpVtbl
= &d3d1_vtbl
;
5529 ddraw
->IDirect3D2_iface
.lpVtbl
= &d3d2_vtbl
;
5530 ddraw
->IDirect3D3_iface
.lpVtbl
= &d3d3_vtbl
;
5531 ddraw
->IDirect3D7_iface
.lpVtbl
= &d3d7_vtbl
;
5532 ddraw
->device_parent
.ops
= &ddraw_wined3d_device_parent_ops
;
5533 ddraw
->numIfaces
= 1;
5536 /* Get the current screen settings. */
5538 ddraw
->orig_bpp
= GetDeviceCaps(hDC
, BITSPIXEL
) * GetDeviceCaps(hDC
, PLANES
);
5540 ddraw
->orig_width
= GetSystemMetrics(SM_CXSCREEN
);
5541 ddraw
->orig_height
= GetSystemMetrics(SM_CYSCREEN
);
5543 ddraw
->wined3d
= wined3d_create(7, WINED3D_LEGACY_DEPTH_BIAS
);
5544 if (!ddraw
->wined3d
)
5546 WARN("Failed to create a wined3d object.\n");
5547 return E_OUTOFMEMORY
;
5550 hr
= wined3d_device_create(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, device_type
,
5551 NULL
, 0, 8, &ddraw
->device_parent
, &ddraw
->wined3d_device
);
5554 WARN("Failed to create a wined3d device, hr %#x.\n", hr
);
5555 wined3d_decref(ddraw
->wined3d
);
5559 list_init(&ddraw
->surface_list
);