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
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
31 #define NONAMELESSUNION
37 #include "wine/exception.h"
42 #include "ddraw_private.h"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(ddraw
);
47 static BOOL
IDirectDrawImpl_DDSD_Match(const DDSURFACEDESC2
* requested
, const DDSURFACEDESC2
* provided
);
48 static HRESULT WINAPI
IDirectDrawImpl_AttachD3DDevice(IDirectDrawImpl
*This
, IDirectDrawSurfaceImpl
*primary
);
49 static HRESULT WINAPI
IDirectDrawImpl_CreateNewSurface(IDirectDrawImpl
*This
, DDSURFACEDESC2
*pDDSD
, IDirectDrawSurfaceImpl
**ppSurf
, UINT level
);
51 /* Device identifier. Don't relay it to WineD3D */
52 static const DDDEVICEIDENTIFIER2 deviceidentifier
=
56 { { 0x00010001, 0x00010001 } },
58 /* a8373c10-7ac4-4deb-849a-009844d08b2d */
59 {0xa8373c10,0x7ac4,0x4deb, {0x84,0x9a,0x00,0x98,0x44,0xd0,0x8b,0x2d}},
63 /*****************************************************************************
65 *****************************************************************************/
67 /*****************************************************************************
68 * IDirectDraw7::QueryInterface
70 * Queries different interfaces of the DirectDraw object. It can return
71 * IDirectDraw interfaces in version 1, 2, 4 and 7, and IDirect3D interfaces
72 * in version 1, 2, 3 and 7. An IDirect3DDevice can be created with this
74 * The returned interface is AddRef()-ed before it's returned
76 * Rules for QueryInterface:
77 * http://msdn.microsoft.com/library/default.asp? \
78 * url=/library/en-us/com/html/6db17ed8-06e4-4bae-bc26-113176cc7e0e.asp
80 * Used for version 1, 2, 4 and 7
83 * refiid: Interface ID asked for
84 * obj: Used to return the interface pointer
87 * S_OK if an interface was found
88 * E_NOINTERFACE if the requested interface wasn't found
90 *****************************************************************************/
92 IDirectDrawImpl_QueryInterface(IDirectDraw7
*iface
,
96 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
98 TRACE("(%p)->(%s,%p)\n", This
, debugstr_guid(refiid
), obj
);
100 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
104 return DDERR_INVALIDPARAMS
;
106 /* Check DirectDraw Interfaces */
107 if ( IsEqualGUID( &IID_IUnknown
, refiid
) ||
108 IsEqualGUID( &IID_IDirectDraw7
, refiid
) )
110 *obj
= ICOM_INTERFACE(This
, IDirectDraw7
);
111 TRACE("(%p) Returning IDirectDraw7 interface at %p\n", This
, *obj
);
113 else if ( IsEqualGUID( &IID_IDirectDraw4
, refiid
) )
115 *obj
= ICOM_INTERFACE(This
, IDirectDraw4
);
116 TRACE("(%p) Returning IDirectDraw4 interface at %p\n", This
, *obj
);
118 else if ( IsEqualGUID( &IID_IDirectDraw3
, refiid
) )
120 *obj
= ICOM_INTERFACE(This
, IDirectDraw3
);
121 TRACE("(%p) Returning IDirectDraw3 interface at %p\n", This
, *obj
);
123 else if ( IsEqualGUID( &IID_IDirectDraw2
, refiid
) )
125 *obj
= ICOM_INTERFACE(This
, IDirectDraw2
);
126 TRACE("(%p) Returning IDirectDraw2 interface at %p\n", This
, *obj
);
128 else if ( IsEqualGUID( &IID_IDirectDraw
, refiid
) )
130 *obj
= ICOM_INTERFACE(This
, IDirectDraw
);
131 TRACE("(%p) Returning IDirectDraw interface at %p\n", This
, *obj
);
135 * The refcount unit test revealed that an IDirect3D7 interface can only be queried
136 * from a DirectDraw object that was created as an IDirectDraw7 interface. No idea
137 * who had this idea and why. The older interfaces can query and IDirect3D version
138 * because they are all created as IDirectDraw(1). This isn't really crucial behavior,
139 * and messy to implement with the common creation function, so it has been left out here.
141 else if ( IsEqualGUID( &IID_IDirect3D
, refiid
) ||
142 IsEqualGUID( &IID_IDirect3D2
, refiid
) ||
143 IsEqualGUID( &IID_IDirect3D3
, refiid
) ||
144 IsEqualGUID( &IID_IDirect3D7
, refiid
) )
146 /* Check the surface implementation */
147 if(This
->ImplType
== SURFACE_UNKNOWN
)
149 /* Apps may create the IDirect3D Interface before the primary surface.
150 * set the surface implementation */
151 This
->ImplType
= SURFACE_OPENGL
;
152 TRACE("(%p) Choosing OpenGL surfaces because a Direct3D interface was requested\n", This
);
154 else if(This
->ImplType
!= SURFACE_OPENGL
&& DefaultSurfaceType
== SURFACE_UNKNOWN
)
156 ERR("(%p) The App is requesting a D3D device, but a non-OpenGL surface type was choosen. Prepare for trouble!\n", This
);
157 ERR(" (%p) You may want to contact wine-devel for help\n", This
);
158 /* Should I assert(0) here??? */
160 else if(This
->ImplType
!= SURFACE_OPENGL
)
162 WARN("The app requests a Direct3D interface, but non-opengl surfaces where set in winecfg\n");
163 /* Do not abort here, only reject 3D Device creation */
166 if ( IsEqualGUID( &IID_IDirect3D
, refiid
) )
168 This
->d3dversion
= 1;
169 *obj
= ICOM_INTERFACE(This
, IDirect3D
);
170 TRACE(" returning Direct3D interface at %p.\n", *obj
);
172 else if ( IsEqualGUID( &IID_IDirect3D2
, refiid
) )
174 This
->d3dversion
= 2;
175 *obj
= ICOM_INTERFACE(This
, IDirect3D2
);
176 TRACE(" returning Direct3D2 interface at %p.\n", *obj
);
178 else if ( IsEqualGUID( &IID_IDirect3D3
, refiid
) )
180 This
->d3dversion
= 3;
181 *obj
= ICOM_INTERFACE(This
, IDirect3D3
);
182 TRACE(" returning Direct3D3 interface at %p.\n", *obj
);
184 else if(IsEqualGUID( &IID_IDirect3D7
, refiid
))
186 This
->d3dversion
= 7;
187 *obj
= ICOM_INTERFACE(This
, IDirect3D7
);
188 TRACE(" returning Direct3D7 interface at %p.\n", *obj
);
192 /* Unknown interface */
195 ERR("(%p)->(%s, %p): No interface found\n", This
, debugstr_guid(refiid
), obj
);
196 return E_NOINTERFACE
;
199 IUnknown_AddRef( (IUnknown
*) *obj
);
203 /*****************************************************************************
204 * IDirectDraw7::AddRef
206 * Increases the interfaces refcount, basically
208 * DDraw refcounting is a bit tricky. The different DirectDraw interface
209 * versions have individual refcounts, but the IDirect3D interfaces do not.
210 * All interfaces are from one object, that means calling QueryInterface on an
211 * IDirectDraw7 interface for an IDirectDraw4 interface does not create a new
212 * IDirectDrawImpl object.
214 * That means all AddRef and Release implementations of IDirectDrawX work
215 * with their own counter, and IDirect3DX::AddRef thunk to IDirectDraw (1),
216 * except of IDirect3D7 which thunks to IDirectDraw7
218 * Returns: The new refcount
220 *****************************************************************************/
222 IDirectDrawImpl_AddRef(IDirectDraw7
*iface
)
224 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
225 ULONG ref
= InterlockedIncrement(&This
->ref7
);
227 TRACE("(%p) : incrementing IDirectDraw7 refcount from %u.\n", This
, ref
-1);
229 if(ref
== 1) InterlockedIncrement(&This
->numIfaces
);
234 /*****************************************************************************
235 * IDirectDrawImpl_Destroy
237 * Destroys a ddraw object if all refcounts are 0. This is to share code
238 * between the IDirectDrawX::Release functions
241 * This: DirectDraw object to destroy
243 *****************************************************************************/
245 IDirectDrawImpl_Destroy(IDirectDrawImpl
*This
)
249 for(i
= 0; i
< This
->numConvertedDecls
; i
++)
251 IWineD3DVertexDeclaration_Release(This
->decls
[i
].decl
);
253 HeapFree(GetProcessHeap(), 0, This
->decls
);
255 /* Clear the cooplevel to restore window and display mode */
256 IDirectDraw7_SetCooperativeLevel(ICOM_INTERFACE(This
, IDirectDraw7
),
260 /* Destroy the device window if we created one */
261 if(This
->devicewindow
!= 0)
263 TRACE(" (%p) Destroying the device window %p\n", This
, This
->devicewindow
);
264 DestroyWindow(This
->devicewindow
);
265 This
->devicewindow
= 0;
268 /* Unregister the window class */
269 UnregisterClassA(This
->classname
, 0);
271 remove_ddraw_object(This
);
273 /* Release the attached WineD3D stuff */
274 IWineD3DDevice_Release(This
->wineD3DDevice
);
275 IWineD3D_Release(This
->wineD3D
);
277 /* Now free the object */
278 HeapFree(GetProcessHeap(), 0, This
);
281 /*****************************************************************************
282 * IDirectDraw7::Release
284 * Decreases the refcount. If the refcount falls to 0, the object is destroyed
286 * Returns: The new refcount
287 *****************************************************************************/
289 IDirectDrawImpl_Release(IDirectDraw7
*iface
)
291 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
292 ULONG ref
= InterlockedDecrement(&This
->ref7
);
294 TRACE("(%p)->() decrementing IDirectDraw7 refcount from %u.\n", This
, ref
+1);
298 ULONG ifacecount
= InterlockedDecrement(&This
->numIfaces
);
299 if(ifacecount
== 0) IDirectDrawImpl_Destroy(This
);
305 /*****************************************************************************
306 * IDirectDraw methods
307 *****************************************************************************/
309 /*****************************************************************************
310 * IDirectDraw7::SetCooperativeLevel
312 * Sets the cooperative level for the DirectDraw object, and the window
313 * assigned to it. The cooperative level determines the general behavior
314 * of the DirectDraw application
316 * Warning: This is quite tricky, as it's not really documented which
317 * cooperative levels can be combined with each other. If a game fails
318 * after this function, try to check the cooperative levels passed on
319 * Windows, and if it returns something different.
321 * If you think that this function caused the failure because it writes a
322 * fixme, be sure to run again with a +ddraw trace.
324 * What is known about cooperative levels (See the ddraw modes test):
325 * DDSCL_EXCLUSIVE and DDSCL_FULLSCREEN must be used with each other
326 * DDSCL_NORMAL is not compatible with DDSCL_EXCLUSIVE or DDSCL_FULLSCREEN
327 * DDSCL_SETFOCUSWINDOW can be passed only in DDSCL_NORMAL mode, but after that
328 * DDSCL_FULLSCREEN can be activated
329 * DDSCL_SETFOCUSWINDOW may only be used with DDSCL_NOWINDOWCHANGES
331 * Handled flags: DDSCL_NORMAL, DDSCL_FULLSCREEN, DDSCL_EXCLUSIVE,
332 * DDSCL_SETFOCUSWINDOW (partially),
333 * DDSCL_MULTITHREADED (work in progress)
335 * Unhandled flags, which should be implemented
336 * DDSCL_SETDEVICEWINDOW: Sets a window specially used for rendering (I don't
337 * expect any difference to a normal window for wine)
338 * DDSCL_CREATEDEVICEWINDOW: Tells ddraw to create its own window for
339 * rendering (Possible test case: Half-life)
341 * Unsure about these: DDSCL_FPUSETUP DDSCL_FPURESERVE
343 * These seem not really imporant for wine
344 * DDSCL_ALLOWREBOOT, DDSCL_NOWINDOWCHANGES, DDSCL_ALLOWMODEX
347 * DD_OK if the cooperative level was set successfully
348 * DDERR_INVALIDPARAMS if the passed cooperative level combination is invalid
349 * DDERR_HWNDALREADYSET if DDSCL_SETFOCUSWINDOW is passed in exclusive mode
350 * (Probably others too, have to investigate)
352 *****************************************************************************/
353 static HRESULT WINAPI
354 IDirectDrawImpl_SetCooperativeLevel(IDirectDraw7
*iface
,
358 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
362 FIXME("(%p)->(%p,%08x)\n",This
,hwnd
,cooplevel
);
363 DDRAW_dump_cooperativelevel(cooplevel
);
365 /* Get the old window */
366 hr
= IWineD3DDevice_GetHWND(This
->wineD3DDevice
, &window
);
369 ERR("IWineD3DDevice::GetHWND failed, hr = %08x\n", hr
);
373 /* Tests suggest that we need one of them: */
374 if(!(cooplevel
& (DDSCL_SETFOCUSWINDOW
|
378 TRACE("Incorrect cooplevel flags, returning DDERR_INVALIDPARAMS\n");
379 return DDERR_INVALIDPARAMS
;
382 /* Handle those levels first which set various hwnds */
383 if(cooplevel
& DDSCL_SETFOCUSWINDOW
)
385 /* This isn't compatible with a lot of flags */
386 if(cooplevel
& ( DDSCL_MULTITHREADED
|
391 DDSCL_SETDEVICEWINDOW
|
396 TRACE("Called with incompatible flags, returning DDERR_INVALIDPARAMS\n");
397 return DDERR_INVALIDPARAMS
;
399 else if( (This
->cooperative_level
& DDSCL_FULLSCREEN
) && window
)
401 TRACE("Setting DDSCL_SETFOCUSWINDOW with an already set window, returning DDERR_HWNDALREADYSET\n");
402 return DDERR_HWNDALREADYSET
;
405 This
->focuswindow
= hwnd
;
406 /* Won't use the hwnd param for anything else */
409 /* Use the focus window for drawing too */
410 IWineD3DDevice_SetHWND(This
->wineD3DDevice
, This
->focuswindow
);
412 /* Destroy the device window, if we have one */
413 if(This
->devicewindow
)
415 DestroyWindow(This
->devicewindow
);
416 This
->devicewindow
= NULL
;
419 /* DDSCL_NORMAL or DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE */
420 if(cooplevel
& DDSCL_NORMAL
)
422 /* Can't coexist with fullscreen or exclusive */
423 if(cooplevel
& (DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
) )
425 TRACE("(%p) DDSCL_NORMAL is not compative with DDSCL_FULLSCREEN or DDSCL_EXCLUSIVE\n", This
);
426 return DDERR_INVALIDPARAMS
;
429 /* Switching from fullscreen? */
430 if(This
->cooperative_level
& DDSCL_FULLSCREEN
)
432 /* Restore the display mode */
433 IDirectDraw7_RestoreDisplayMode(iface
);
435 This
->cooperative_level
&= ~DDSCL_FULLSCREEN
;
436 This
->cooperative_level
&= ~DDSCL_EXCLUSIVE
;
437 This
->cooperative_level
&= ~DDSCL_ALLOWMODEX
;
440 /* Don't override focus windows or private device windows */
442 !(This
->focuswindow
) &&
443 !(This
->devicewindow
) &&
446 IWineD3DDevice_SetHWND(This
->wineD3DDevice
, hwnd
);
449 IWineD3DDevice_SetFullscreen(This
->wineD3DDevice
,
452 else if(cooplevel
& DDSCL_FULLSCREEN
)
454 /* Needs DDSCL_EXCLUSIVE */
455 if(!(cooplevel
& DDSCL_EXCLUSIVE
) )
457 TRACE("(%p) DDSCL_FULLSCREEN needs DDSCL_EXCLUSIVE\n", This
);
458 return DDERR_INVALIDPARAMS
;
463 TRACE("(%p) DDSCL_FULLSCREEN needs a HWND\n", This);
464 return DDERR_INVALIDPARAMS;
468 /* Switch from normal to full screen mode? */
469 if(This
->cooperative_level
& DDSCL_NORMAL
)
471 This
->cooperative_level
&= ~DDSCL_NORMAL
;
472 IWineD3DDevice_SetFullscreen(This
->wineD3DDevice
,
476 /* Don't override focus windows or private device windows */
478 !(This
->focuswindow
) &&
479 !(This
->devicewindow
) &&
482 IWineD3DDevice_SetHWND(This
->wineD3DDevice
, hwnd
);
485 else if(cooplevel
& DDSCL_EXCLUSIVE
)
487 TRACE("(%p) DDSCL_EXCLUSIVE needs DDSCL_FULLSCREEN\n", This
);
488 return DDERR_INVALIDPARAMS
;
491 if(cooplevel
& DDSCL_CREATEDEVICEWINDOW
)
493 /* Don't create a device window if a focus window is set */
494 if( !(This
->focuswindow
) )
496 HWND devicewindow
= CreateWindowExA(0, This
->classname
, "DDraw device window",
498 GetSystemMetrics(SM_CXSCREEN
),
499 GetSystemMetrics(SM_CYSCREEN
),
500 NULL
, NULL
, GetModuleHandleA(0), NULL
);
502 ShowWindow(devicewindow
, SW_SHOW
); /* Just to be sure */
503 TRACE("(%p) Created a DDraw device window. HWND=%p\n", This
, devicewindow
);
505 IWineD3DDevice_SetHWND(This
->wineD3DDevice
, devicewindow
);
506 This
->devicewindow
= devicewindow
;
510 if(cooplevel
& DDSCL_MULTITHREADED
&& !(This
->cooperative_level
& DDSCL_MULTITHREADED
))
512 FIXME("DirectDraw is not thread safe yet\n");
514 /* Enable thread safety in wined3d */
515 IWineD3DDevice_SetMultithreaded(This
->wineD3DDevice
);
518 /* Unhandled flags */
519 if(cooplevel
& DDSCL_ALLOWREBOOT
)
520 WARN("(%p) Unhandled flag DDSCL_ALLOWREBOOT, harmless\n", This
);
521 if(cooplevel
& DDSCL_ALLOWMODEX
)
522 WARN("(%p) Unhandled flag DDSCL_ALLOWMODEX, harmless\n", This
);
523 if(cooplevel
& DDSCL_FPUSETUP
)
524 WARN("(%p) Unhandled flag DDSCL_FPUSETUP, harmless\n", This
);
525 if(cooplevel
& DDSCL_FPUPRESERVE
)
526 WARN("(%p) Unhandled flag DDSCL_FPUPRESERVE, harmless\n", This
);
528 /* Store the cooperative_level */
529 This
->cooperative_level
|= cooplevel
;
530 TRACE("SetCooperativeLevel retuning DD_OK\n");
534 /*****************************************************************************
535 * IDirectDraw7::SetDisplayMode
537 * Sets the display screen resolution, color depth and refresh frequency
538 * when in fullscreen mode (in theory).
539 * Possible return values listed in the SDK suggest that this method fails
540 * when not in fullscreen mode, but this is wrong. Windows 2000 happily sets
541 * the display mode in DDSCL_NORMAL mode without an hwnd specified.
542 * It seems to be valid to pass 0 for With and Height, this has to be tested
543 * It could mean that the current video mode should be left as-is. (But why
547 * Height, Width: Screen dimension
548 * BPP: Color depth in Bits per pixel
549 * Refreshrate: Screen refresh rate
555 *****************************************************************************/
556 static HRESULT WINAPI
557 IDirectDrawImpl_SetDisplayMode(IDirectDraw7
*iface
,
564 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
565 WINED3DDISPLAYMODE Mode
;
567 TRACE("(%p)->(%d,%d,%d,%d,%x: Relay!\n", This
, Width
, Height
, BPP
, RefreshRate
, Flags
);
569 if( !Width
|| !Height
)
571 ERR("Width=%d, Height=%d, what to do?\n", Width
, Height
);
572 /* It looks like Need for Speed Porsche Unleashed expects DD_OK here */
576 /* Check the exclusive mode
577 if(!(This->cooperative_level & DDSCL_EXCLUSIVE))
578 return DDERR_NOEXCLUSIVEMODE;
579 * This is WRONG. Don't know if the SDK is completely
580 * wrong and if there are any conditions when DDERR_NOEXCLUSIVE
581 * is returned, but Half-Life 1.1.1.1 (Steam version)
586 Mode
.Height
= Height
;
587 Mode
.RefreshRate
= RefreshRate
;
590 case 8: Mode
.Format
= WINED3DFMT_P8
; break;
591 case 15: Mode
.Format
= WINED3DFMT_X1R5G5B5
; break;
592 case 16: Mode
.Format
= WINED3DFMT_R5G6B5
; break;
593 case 24: Mode
.Format
= WINED3DFMT_R8G8B8
; break;
594 case 32: Mode
.Format
= WINED3DFMT_A8R8G8B8
; break;
597 /* TODO: The possible return values from msdn suggest that
598 * the screen mode can't be changed if a surface is locked
599 * or some drawing is in progress
602 /* TODO: Lose the primary surface */
603 hr
= IWineD3DDevice_SetDisplayMode(This
->wineD3DDevice
,
604 0, /* First swapchain */
608 case WINED3DERR_NOTAVAILABLE
: return DDERR_INVALIDMODE
;
613 /*****************************************************************************
614 * IDirectDraw7::RestoreDisplayMode
616 * Restores the display mode to what it was at creation time. Basically.
618 * A problem arises when there are 2 DirectDraw objects using the same hwnd:
619 * -> DD_1 finds the screen at 1400x1050x32 when created, sets it to 640x480x16
620 * -> DD_2 is created, finds the screen at 640x480x16, sets it to 1024x768x32
621 * -> DD_1 is released. The screen should be left at 1024x768x32.
622 * -> DD_2 is released. The screen should be set to 1400x1050x32
623 * This case is unhandled right now, but Empire Earth does it this way.
624 * (But perhaps there is something in SetCooperativeLevel to prevent this)
626 * The msdn says that this method resets the display mode to what it was before
627 * SetDisplayMode was called. What if SetDisplayModes is called 2 times??
631 * DDERR_NOEXCLUSIVE mode if the device isn't in fullscreen mode
633 *****************************************************************************/
634 static HRESULT WINAPI
635 IDirectDrawImpl_RestoreDisplayMode(IDirectDraw7
*iface
)
637 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
638 TRACE("(%p)\n", This
);
640 return IDirectDraw7_SetDisplayMode(ICOM_INTERFACE(This
, IDirectDraw7
),
648 /*****************************************************************************
649 * IDirectDraw7::GetCaps
651 * Returns the drives capabilities
653 * Used for version 1, 2, 4 and 7
656 * DriverCaps: Structure to write the Hardware accelerated caps to
657 * HelCaps: Structure to write the emulation caps to
660 * This implementation returns DD_OK only
662 *****************************************************************************/
663 static HRESULT WINAPI
664 IDirectDrawImpl_GetCaps(IDirectDraw7
*iface
,
668 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
669 TRACE("(%p)->(%p,%p)\n", This
, DriverCaps
, HELCaps
);
671 /* One structure must be != NULL */
672 if( (!DriverCaps
) && (!HELCaps
) )
674 ERR("(%p) Invalid params to IDirectDrawImpl_GetCaps\n", This
);
675 return DDERR_INVALIDPARAMS
;
680 DD_STRUCT_COPY_BYSIZE(DriverCaps
, &This
->caps
);
683 TRACE("Driver Caps :\n");
684 DDRAW_dump_DDCAPS(DriverCaps
);
690 DD_STRUCT_COPY_BYSIZE(HELCaps
, &This
->caps
);
693 TRACE("HEL Caps :\n");
694 DDRAW_dump_DDCAPS(HELCaps
);
701 /*****************************************************************************
702 * IDirectDraw7::Compact
704 * No idea what it does, MSDN says it's not implemented.
707 * DD_OK, but this is unchecked
709 *****************************************************************************/
710 static HRESULT WINAPI
711 IDirectDrawImpl_Compact(IDirectDraw7
*iface
)
713 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
714 TRACE("(%p)\n", This
);
719 /*****************************************************************************
720 * IDirectDraw7::GetDisplayMode
722 * Returns information about the current display mode
724 * Exists in Version 1, 2, 4 and 7
727 * DDSD: Address of a surface description structure to write the info to
732 *****************************************************************************/
733 static HRESULT WINAPI
734 IDirectDrawImpl_GetDisplayMode(IDirectDraw7
*iface
,
735 DDSURFACEDESC2
*DDSD
)
737 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
739 WINED3DDISPLAYMODE Mode
;
741 TRACE("(%p)->(%p): Relay\n", This
, DDSD
);
743 /* This seems sane */
746 return DDERR_INVALIDPARAMS
;
749 /* The necessary members of LPDDSURFACEDESC and LPDDSURFACEDESC2 are equal,
750 * so one method can be used for all versions (Hopefully)
752 hr
= IWineD3DDevice_GetDisplayMode(This
->wineD3DDevice
,
757 ERR(" (%p) IWineD3DDevice::GetDisplayMode returned %08x\n", This
, hr
);
762 memset(DDSD
, 0, Size
);
765 DDSD
->dwFlags
|= DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
| DDSD_PITCH
| DDSD_REFRESHRATE
;
766 DDSD
->dwWidth
= Mode
.Width
;
767 DDSD
->dwHeight
= Mode
.Height
;
768 DDSD
->u2
.dwRefreshRate
= 60;
769 DDSD
->ddsCaps
.dwCaps
= 0;
770 DDSD
->u4
.ddpfPixelFormat
.dwSize
= sizeof(DDSD
->u4
.ddpfPixelFormat
);
771 PixelFormat_WineD3DtoDD(&DDSD
->u4
.ddpfPixelFormat
, Mode
.Format
);
772 DDSD
->u1
.lPitch
= Mode
.Width
* DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8;
776 TRACE("Returning surface desc :\n");
777 DDRAW_dump_surface_desc(DDSD
);
783 /*****************************************************************************
784 * IDirectDraw7::GetFourCCCodes
786 * Returns an array of supported FourCC codes.
788 * Exists in Version 1, 2, 4 and 7
791 * NumCodes: Contains the number of Codes that Codes can carry. Returns the number
792 * of enumerated codes
793 * Codes: Pointer to an array of DWORDs where the supported codes are written
797 * Always returns DD_OK, as it's a stub for now
799 *****************************************************************************/
800 static HRESULT WINAPI
801 IDirectDrawImpl_GetFourCCCodes(IDirectDraw7
*iface
,
802 DWORD
*NumCodes
, DWORD
*Codes
)
804 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
805 FIXME("(%p)->(%p, %p): Stub!\n", This
, NumCodes
, Codes
);
807 if(NumCodes
) *NumCodes
= 0;
812 /*****************************************************************************
813 * IDirectDraw7::GetMonitorFrequency
815 * Returns the monitor's frequency
817 * Exists in Version 1, 2, 4 and 7
820 * Freq: Pointer to a DWORD to write the frequency to
823 * Always returns DD_OK
825 *****************************************************************************/
826 static HRESULT WINAPI
827 IDirectDrawImpl_GetMonitorFrequency(IDirectDraw7
*iface
,
830 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
831 TRACE("(%p)->(%p)\n", This
, Freq
);
833 /* Ideally this should be in WineD3D, as it concerns the screen setup,
834 * but for now this should make the games happy
840 /*****************************************************************************
841 * IDirectDraw7::GetVerticalBlankStatus
843 * Returns the Vertical blank status of the monitor. This should be in WineD3D
844 * too basically, but as it's a semi stub, I didn't create a function there
847 * status: Pointer to a BOOL to be filled with the vertical blank status
851 * DDERR_INVALIDPARAMS if status is NULL
853 *****************************************************************************/
854 static HRESULT WINAPI
855 IDirectDrawImpl_GetVerticalBlankStatus(IDirectDraw7
*iface
,
858 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
859 TRACE("(%p)->(%p)\n", This
, status
);
861 /* This looks sane, the MSDN suggests it too */
862 if(!status
) return DDERR_INVALIDPARAMS
;
864 *status
= This
->fake_vblank
;
865 This
->fake_vblank
= !This
->fake_vblank
;
869 /*****************************************************************************
870 * IDirectDraw7::GetAvailableVidMem
872 * Returns the total and free video memory
875 * Caps: Specifies the memory type asked for
876 * total: Pointer to a DWORD to be filled with the total memory
877 * free: Pointer to a DWORD to be filled with the free memory
881 * DDERR_INVALIDPARAMS of free and total are NULL
883 *****************************************************************************/
884 static HRESULT WINAPI
885 IDirectDrawImpl_GetAvailableVidMem(IDirectDraw7
*iface
, DDSCAPS2
*Caps
, DWORD
*total
, DWORD
*free
)
887 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
888 TRACE("(%p)->(%p, %p, %p)\n", This
, Caps
, total
, free
);
892 TRACE("(%p) Asked for memory with description: ", This
);
893 DDRAW_dump_DDSCAPS2(Caps
);
897 /* Todo: System memory vs local video memory vs non-local video memory
898 * The MSDN also mentions differences between texture memory and other
899 * resources, but that's not important
902 if( (!total
) && (!free
) ) return DDERR_INVALIDPARAMS
;
904 if(total
) *total
= This
->total_vidmem
;
905 if(free
) *free
= IWineD3DDevice_GetAvailableTextureMem(This
->wineD3DDevice
);
910 /*****************************************************************************
911 * IDirectDraw7::Initialize
913 * Initializes a DirectDraw interface.
916 * GUID: Interface identifier. Well, don't know what this is really good
920 * Returns DD_OK on the first call,
921 * DDERR_ALREADYINITIALIZED on repeated calls
923 *****************************************************************************/
924 static HRESULT WINAPI
925 IDirectDrawImpl_Initialize(IDirectDraw7
*iface
,
928 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
929 TRACE("(%p)->(%s): No-op\n", This
, debugstr_guid(Guid
));
931 if(This
->initialized
)
933 return DDERR_ALREADYINITIALIZED
;
941 /*****************************************************************************
942 * IDirectDraw7::FlipToGDISurface
944 * "Makes the surface that the GDI writes to the primary surface"
945 * Looks like some windows specific thing we don't have to care about.
946 * According to MSDN it permits GDI dialog boxes in FULLSCREEN mode. Good to
947 * show error boxes ;)
948 * Well, just return DD_OK.
951 * Always returns DD_OK
953 *****************************************************************************/
954 static HRESULT WINAPI
955 IDirectDrawImpl_FlipToGDISurface(IDirectDraw7
*iface
)
957 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
958 TRACE("(%p)\n", This
);
963 /*****************************************************************************
964 * IDirectDraw7::WaitForVerticalBlank
966 * This method allows applications to get in sync with the vertical blank
968 * The wormhole demo in the DirectX 7 sdk uses this call, and it doesn't
969 * redraw the screen, most likely because of this stub
972 * Flags: one of DDWAITVB_BLOCKBEGIN, DDWAITVB_BLOCKBEGINEVENT
973 * or DDWAITVB_BLOCKEND
974 * h: Not used, according to MSDN
977 * Always returns DD_OK
979 *****************************************************************************/
980 static HRESULT WINAPI
981 IDirectDrawImpl_WaitForVerticalBlank(IDirectDraw7
*iface
,
985 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
986 FIXME("(%p)->(%x,%p): Stub\n", This
, Flags
, h
);
988 /* MSDN says DDWAITVB_BLOCKBEGINEVENT is not supported */
989 if(Flags
& DDWAITVB_BLOCKBEGINEVENT
)
990 return DDERR_UNSUPPORTED
; /* unchecked */
995 /*****************************************************************************
996 * IDirectDraw7::GetScanLine
998 * Returns the scan line that is being drawn on the monitor
1001 * Scanline: Address to write the scan line value to
1004 * Always returns DD_OK
1006 *****************************************************************************/
1007 static HRESULT WINAPI
IDirectDrawImpl_GetScanLine(IDirectDraw7
*iface
, DWORD
*Scanline
)
1009 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1010 static BOOL hide
= FALSE
;
1011 WINED3DDISPLAYMODE Mode
;
1013 /* This function is called often, so print the fixme only once */
1016 FIXME("(%p)->(%p): Semi-Stub\n", This
, Scanline
);
1020 IWineD3DDevice_GetDisplayMode(This
->wineD3DDevice
,
1024 /* Fake the line sweeping of the monitor */
1025 /* FIXME: We should synchronize with a source to keep the refresh rate */
1026 *Scanline
= This
->cur_scanline
++;
1027 /* Assume 20 scan lines in the vertical blank */
1028 if (This
->cur_scanline
>= Mode
.Height
+ 20)
1029 This
->cur_scanline
= 0;
1034 /*****************************************************************************
1035 * IDirectDraw7::TestCooperativeLevel
1037 * Informs the application about the state of the video adapter, depending
1038 * on the cooperative level
1041 * DD_OK if the device is in a sane state
1042 * DDERR_NOEXCLUSIVEMODE or DDERR_EXCLUSIVEMODEALREADYSET
1043 * if the state is not correct(See below)
1045 *****************************************************************************/
1046 static HRESULT WINAPI
1047 IDirectDrawImpl_TestCooperativeLevel(IDirectDraw7
*iface
)
1049 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1051 TRACE("(%p)\n", This
);
1053 /* Description from MSDN:
1054 * For fullscreen apps return DDERR_NOEXCLUSIVEMODE if the user switched
1055 * away from the app with e.g. alt-tab. Windowed apps receive
1056 * DDERR_EXCLUSIVEMODEALREADYSET if another application created a
1057 * DirectDraw object in exclusive mode. DDERR_WRONGMODE is returned,
1058 * when the video mode has changed
1061 hr
= IWineD3DDevice_TestCooperativeLevel(This
->wineD3DDevice
);
1063 /* Fix the result value. These values are mapped from their
1068 case WINED3DERR_DEVICELOST
:
1069 if(This
->cooperative_level
& DDSCL_EXCLUSIVE
)
1071 return DDERR_NOEXCLUSIVEMODE
;
1075 return DDERR_EXCLUSIVEMODEALREADYSET
;
1078 case WINED3DERR_DEVICENOTRESET
:
1084 case WINED3DERR_DRIVERINTERNALERROR
:
1086 ERR("(%p) Unexpected return value %08x from wineD3D, "
1087 " returning DD_OK\n", This
, hr
);
1093 /*****************************************************************************
1094 * IDirectDraw7::GetGDISurface
1096 * Returns the surface that GDI is treating as the primary surface.
1097 * For Wine this is the front buffer
1100 * GDISurface: Address to write the surface pointer to
1103 * DD_OK if the surface was found
1104 * DDERR_NOTFOUND if the GDI surface wasn't found
1106 *****************************************************************************/
1107 static HRESULT WINAPI
1108 IDirectDrawImpl_GetGDISurface(IDirectDraw7
*iface
,
1109 IDirectDrawSurface7
**GDISurface
)
1111 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1112 IWineD3DSurface
*Surf
;
1113 IDirectDrawSurface7
*ddsurf
;
1116 TRACE("(%p)->(%p)\n", This
, GDISurface
);
1118 /* Get the back buffer from the wineD3DDevice and search its
1119 * attached surfaces for the front buffer
1121 hr
= IWineD3DDevice_GetBackBuffer(This
->wineD3DDevice
,
1123 0, /* first back buffer*/
1124 WINED3DBACKBUFFER_TYPE_MONO
,
1127 if( (hr
!= D3D_OK
) ||
1130 ERR("IWineD3DDevice::GetBackBuffer failed\n");
1131 return DDERR_NOTFOUND
;
1134 /* GetBackBuffer AddRef()ed the surface, release it */
1135 IWineD3DSurface_Release(Surf
);
1137 IWineD3DSurface_GetParent(Surf
,
1138 (IUnknown
**) &ddsurf
);
1139 IDirectDrawSurface7_Release(ddsurf
); /* For the GetParent */
1141 /* Find the front buffer */
1142 ddsCaps
.dwCaps
= DDSCAPS_FRONTBUFFER
;
1143 hr
= IDirectDrawSurface7_GetAttachedSurface(ddsurf
,
1148 ERR("IDirectDrawSurface7::GetAttachedSurface failed, hr = %x\n", hr
);
1151 /* The AddRef is OK this time */
1155 /*****************************************************************************
1156 * IDirectDraw7::EnumDisplayModes
1158 * Enumerates the supported Display modes. The modes can be filtered with
1159 * the DDSD parameter.
1162 * Flags: can be DDEDM_REFRESHRATES and DDEDM_STANDARDVGAMODES
1163 * DDSD: Surface description to filter the modes
1164 * Context: Pointer passed back to the callback function
1165 * cb: Application-provided callback function
1169 * DDERR_INVALIDPARAMS if the callback wasn't set
1171 *****************************************************************************/
1172 static HRESULT WINAPI
1173 IDirectDrawImpl_EnumDisplayModes(IDirectDraw7
*iface
,
1175 DDSURFACEDESC2
*DDSD
,
1177 LPDDENUMMODESCALLBACK2 cb
)
1179 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1180 unsigned int modenum
, fmt
;
1181 WINED3DFORMAT pixelformat
= WINED3DFMT_UNKNOWN
;
1182 WINED3DDISPLAYMODE mode
;
1183 DDSURFACEDESC2 callback_sd
;
1185 WINED3DFORMAT checkFormatList
[] =
1188 WINED3DFMT_A8R8G8B8
,
1189 WINED3DFMT_X8R8G8B8
,
1191 WINED3DFMT_X1R5G5B5
,
1192 WINED3DFMT_A1R5G5B5
,
1193 WINED3DFMT_A4R4G4B4
,
1195 WINED3DFMT_A8R3G3B2
,
1196 WINED3DFMT_X4R4G4B4
,
1197 WINED3DFMT_A2B10G10R10
,
1198 WINED3DFMT_A8B8G8R8
,
1199 WINED3DFMT_X8B8G8R8
,
1200 WINED3DFMT_A2R10G10B10
,
1205 TRACE("(%p)->(%p,%p,%p): Relay\n", This
, DDSD
, Context
, cb
);
1207 /* This looks sane */
1208 if(!cb
) return DDERR_INVALIDPARAMS
;
1212 if ((DDSD
->dwFlags
& DDSD_PIXELFORMAT
) && (DDSD
->u4
.ddpfPixelFormat
.dwFlags
& DDPF_RGB
) )
1213 pixelformat
= PixelFormat_DD2WineD3D(&DDSD
->u4
.ddpfPixelFormat
);
1216 for(fmt
= 0; fmt
< (sizeof(checkFormatList
) / sizeof(checkFormatList
[0])); fmt
++)
1218 if(pixelformat
!= WINED3DFMT_UNKNOWN
&& checkFormatList
[fmt
] != pixelformat
)
1224 while(IWineD3D_EnumAdapterModes(This
->wineD3D
,
1225 WINED3DADAPTER_DEFAULT
,
1226 checkFormatList
[fmt
],
1228 &mode
) == WINED3D_OK
)
1232 if(DDSD
->dwFlags
& DDSD_WIDTH
&& mode
.Width
!= DDSD
->dwWidth
) continue;
1233 if(DDSD
->dwFlags
& DDSD_HEIGHT
&& mode
.Height
!= DDSD
->dwHeight
) continue;
1236 memset(&callback_sd
, 0, sizeof(callback_sd
));
1237 callback_sd
.dwSize
= sizeof(callback_sd
);
1238 callback_sd
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
1240 callback_sd
.dwFlags
= DDSD_HEIGHT
|DDSD_WIDTH
|DDSD_PIXELFORMAT
|DDSD_PITCH
;
1241 if(Flags
& DDEDM_REFRESHRATES
)
1243 callback_sd
.dwFlags
|= DDSD_REFRESHRATE
;
1244 callback_sd
.u2
.dwRefreshRate
= mode
.RefreshRate
;
1247 callback_sd
.dwWidth
= mode
.Width
;
1248 callback_sd
.dwHeight
= mode
.Height
;
1250 PixelFormat_WineD3DtoDD(&callback_sd
.u4
.ddpfPixelFormat
, mode
.Format
);
1252 TRACE("Enumerating %dx%d@%d\n", callback_sd
.dwWidth
, callback_sd
.dwHeight
, callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
);
1254 if(cb(&callback_sd
, Context
) == DDENUMRET_CANCEL
)
1256 TRACE("Application asked to terminate the enumeration\n");
1262 TRACE("End of enumeration\n");
1266 /*****************************************************************************
1267 * IDirectDraw7::EvaluateMode
1269 * Used with IDirectDraw7::StartModeTest to test video modes.
1270 * EvaluateMode is used to pass or fail a mode, and continue with the next
1274 * Flags: DDEM_MODEPASSED or DDEM_MODEFAILED
1275 * Timeout: Returns the amount of seconds left before the mode would have
1276 * been failed automatically
1279 * This implementation always DD_OK, because it's a stub
1281 *****************************************************************************/
1282 static HRESULT WINAPI
1283 IDirectDrawImpl_EvaluateMode(IDirectDraw7
*iface
,
1287 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1288 FIXME("(%p)->(%d,%p): Stub!\n", This
, Flags
, Timeout
);
1290 /* When implementing this, implement it in WineD3D */
1295 /*****************************************************************************
1296 * IDirectDraw7::GetDeviceIdentifier
1298 * Returns the device identifier, which gives information about the driver
1299 * Our device identifier is defined at the beginning of this file.
1302 * DDDI: Address for the returned structure
1303 * Flags: Can be DDGDI_GETHOSTIDENTIFIER
1306 * On success it returns DD_OK
1307 * DDERR_INVALIDPARAMS if DDDI is NULL
1309 *****************************************************************************/
1310 static HRESULT WINAPI
1311 IDirectDrawImpl_GetDeviceIdentifier(IDirectDraw7
*iface
,
1312 DDDEVICEIDENTIFIER2
*DDDI
,
1315 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1316 TRACE("(%p)->(%p,%08x)\n", This
, DDDI
, Flags
);
1319 return DDERR_INVALIDPARAMS
;
1321 /* The DDGDI_GETHOSTIDENTIFIER returns the information about the 2D
1322 * host adapter, if there's a secondary 3D adapter. This doesn't apply
1323 * to any modern hardware, nor is it interesting for Wine, so ignore it
1326 *DDDI
= deviceidentifier
;
1330 /*****************************************************************************
1331 * IDirectDraw7::GetSurfaceFromDC
1333 * Returns the Surface for a GDI device context handle.
1334 * Is this related to IDirectDrawSurface::GetDC ???
1337 * hdc: hdc to return the surface for
1338 * Surface: Address to write the surface pointer to
1341 * Always returns DD_OK because it's a stub
1343 *****************************************************************************/
1344 static HRESULT WINAPI
1345 IDirectDrawImpl_GetSurfaceFromDC(IDirectDraw7
*iface
,
1347 IDirectDrawSurface7
**Surface
)
1349 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1350 FIXME("(%p)->(%p,%p): Stub!\n", This
, hdc
, Surface
);
1352 /* Implementation idea if needed: Loop through all surfaces and compare
1353 * their hdc with hdc. Implement it in WineD3D! */
1354 return DDERR_NOTFOUND
;
1357 /*****************************************************************************
1358 * IDirectDraw7::RestoreAllSurfaces
1360 * Calls the restore method of all surfaces
1365 * Always returns DD_OK because it's a stub
1367 *****************************************************************************/
1368 static HRESULT WINAPI
1369 IDirectDrawImpl_RestoreAllSurfaces(IDirectDraw7
*iface
)
1371 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1372 FIXME("(%p): Stub\n", This
);
1374 /* This isn't hard to implement: Enumerate all WineD3D surfaces,
1375 * get their parent and call their restore method. Do not implement
1376 * it in WineD3D, as restoring a surface means re-creating the
1382 /*****************************************************************************
1383 * IDirectDraw7::StartModeTest
1385 * Tests the specified video modes to update the system registry with
1386 * refresh rate information. StartModeTest starts the mode test,
1387 * EvaluateMode is used to fail or pass a mode. If EvaluateMode
1388 * isn't called within 15 seconds, the mode is failed automatically
1390 * As refresh rates are handled by the X server, I don't think this
1391 * Method is important
1394 * Modes: An array of mode specifications
1395 * NumModes: The number of modes in Modes
1396 * Flags: Some flags...
1399 * Returns DDERR_TESTFINISHED if flags contains DDSMT_ISTESTREQUIRED,
1400 * if no modes are passed, DDERR_INVALIDPARAMS is returned,
1403 *****************************************************************************/
1404 static HRESULT WINAPI
1405 IDirectDrawImpl_StartModeTest(IDirectDraw7
*iface
,
1410 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1411 WARN("(%p)->(%p, %d, %x): Semi-Stub, most likely harmless\n", This
, Modes
, NumModes
, Flags
);
1413 /* This looks sane */
1414 if( (!Modes
) || (NumModes
== 0) ) return DDERR_INVALIDPARAMS
;
1416 /* DDSMT_ISTESTREQUIRED asks if a mode test is necessary.
1417 * As it is not, DDERR_TESTFINISHED is returned
1418 * (hopefully that's correct
1420 if(Flags & DDSMT_ISTESTREQUIRED) return DDERR_TESTFINISHED;
1421 * well, that value doesn't (yet) exist in the wine headers, so ignore it
1427 /*****************************************************************************
1428 * IDirectDrawImpl_RecreateSurfacesCallback
1430 * Enumeration callback for IDirectDrawImpl_RecreateAllSurfaces.
1431 * It re-recreates the WineD3DSurface. It's pretty straightforward
1433 *****************************************************************************/
1435 IDirectDrawImpl_RecreateSurfacesCallback(IDirectDrawSurface7
*surf
,
1436 DDSURFACEDESC2
*desc
,
1439 IDirectDrawSurfaceImpl
*surfImpl
= ICOM_OBJECT(IDirectDrawSurfaceImpl
,
1440 IDirectDrawSurface7
,
1442 IDirectDrawImpl
*This
= surfImpl
->ddraw
;
1444 IParentImpl
*parImpl
= NULL
;
1445 IWineD3DSurface
*wineD3DSurface
;
1448 IWineD3DClipper
*clipper
= NULL
;
1450 WINED3DSURFACE_DESC Desc
;
1451 WINED3DFORMAT Format
;
1452 WINED3DRESOURCETYPE Type
;
1457 WINED3DMULTISAMPLE_TYPE MultiSampleType
;
1458 DWORD MultiSampleQuality
;
1462 TRACE("(%p): Enumerated Surface %p\n", This
, surfImpl
);
1464 /* For the enumeration */
1465 IDirectDrawSurface7_Release(surf
);
1467 if(surfImpl
->ImplType
== This
->ImplType
) return DDENUMRET_OK
; /* Continue */
1469 /* Get the objects */
1470 wineD3DSurface
= surfImpl
->WineD3DSurface
;
1471 IWineD3DSurface_GetParent(wineD3DSurface
, &Parent
);
1472 IUnknown_Release(Parent
); /* For the getParent */
1474 /* Is the parent an IParent interface? */
1475 if(IUnknown_QueryInterface(Parent
, &IID_IParent
, &tmp
) == S_OK
)
1477 /* It is a IParent interface! */
1478 IUnknown_Release(Parent
); /* For the QueryInterface */
1479 parImpl
= ICOM_OBJECT(IParentImpl
, IParent
, Parent
);
1480 /* Release the reference the parent interface is holding */
1481 IWineD3DSurface_Release(wineD3DSurface
);
1484 /* get the clipper */
1485 IWineD3DSurface_GetClipper(wineD3DSurface
, &clipper
);
1487 /* Get the surface properties */
1488 Desc
.Format
= &Format
;
1490 Desc
.Usage
= &Usage
;
1493 Desc
.MultiSampleType
= &MultiSampleType
;
1494 Desc
.MultiSampleQuality
= &MultiSampleQuality
;
1495 Desc
.Width
= &Width
;
1496 Desc
.Height
= &Height
;
1498 hr
= IWineD3DSurface_GetDesc(wineD3DSurface
, &Desc
);
1499 if(hr
!= D3D_OK
) return hr
;
1501 /* Create the new surface */
1502 hr
= IWineD3DDevice_CreateSurface(This
->wineD3DDevice
,
1503 Width
, Height
, Format
,
1504 TRUE
/* Lockable */,
1505 FALSE
/* Discard */,
1506 surfImpl
->mipmap_level
,
1507 &surfImpl
->WineD3DSurface
,
1513 0 /* SharedHandle */,
1520 IWineD3DSurface_SetClipper(surfImpl
->WineD3DSurface
, clipper
);
1522 /* Update the IParent if it exists */
1525 parImpl
->child
= (IUnknown
*) surfImpl
->WineD3DSurface
;
1526 /* Add a reference for the IParent */
1527 IWineD3DSurface_AddRef(surfImpl
->WineD3DSurface
);
1529 /* TODO: Copy the surface content, except for render targets */
1531 if(IWineD3DSurface_Release(wineD3DSurface
) == 0)
1532 TRACE("Surface released successful, next surface\n");
1534 ERR("Something's still holding the old WineD3DSurface\n");
1536 surfImpl
->ImplType
= This
->ImplType
;
1540 IWineD3DClipper_Release(clipper
);
1542 return DDENUMRET_OK
;
1545 /*****************************************************************************
1546 * IDirectDrawImpl_RecreateAllSurfaces
1548 * A function, that converts all wineD3DSurfaces to the new implementation type
1549 * It enumerates all surfaces with IWineD3DDevice::EnumSurfaces, creates a
1550 * new WineD3DSurface, copies the content and releases the old surface
1552 *****************************************************************************/
1554 IDirectDrawImpl_RecreateAllSurfaces(IDirectDrawImpl
*This
)
1556 DDSURFACEDESC2 desc
;
1557 TRACE("(%p): Switch to implementation %d\n", This
, This
->ImplType
);
1559 if(This
->ImplType
!= SURFACE_OPENGL
&& This
->d3d_initialized
)
1561 /* Should happen almost never */
1562 FIXME("(%p) Switching to non-opengl surfaces with d3d started. Is this a bug?\n", This
);
1564 IWineD3DDevice_Uninit3D(This
->wineD3DDevice
, D3D7CB_DestroyDepthStencilSurface
, D3D7CB_DestroySwapChain
);
1566 /* Contrary: D3D starting is handled by the caller, because it knows the render target */
1568 memset(&desc
, 0, sizeof(desc
));
1569 desc
.dwSize
= sizeof(desc
);
1571 return IDirectDraw7_EnumSurfaces(ICOM_INTERFACE(This
, IDirectDraw7
),
1575 IDirectDrawImpl_RecreateSurfacesCallback
);
1578 /*****************************************************************************
1579 * D3D7CB_CreateSurface
1581 * Callback function for IDirect3DDevice_CreateTexture. It searches for the
1582 * correct mipmap sublevel, and returns it to WineD3D.
1583 * The surfaces are created already by IDirectDraw7::CreateSurface
1586 * With, Height: With and height of the surface
1587 * Format: The requested format
1588 * Usage, Pool: D3DUSAGE and D3DPOOL of the surface
1589 * level: The mipmap level
1590 * Face: The cube map face type
1591 * Surface: Pointer to pass the created surface back at
1592 * SharedHandle: NULL
1597 *****************************************************************************/
1598 static HRESULT WINAPI
1599 D3D7CB_CreateSurface(IUnknown
*device
,
1600 IUnknown
*pSuperior
,
1601 UINT Width
, UINT Height
,
1602 WINED3DFORMAT Format
,
1603 DWORD Usage
, WINED3DPOOL Pool
, UINT level
,
1604 WINED3DCUBEMAP_FACES Face
,
1605 IWineD3DSurface
**Surface
,
1606 HANDLE
*SharedHandle
)
1608 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, device
);
1609 IDirectDrawSurfaceImpl
*surf
= NULL
;
1611 DDSCAPS2 searchcaps
= This
->tex_root
->surface_desc
.ddsCaps
;
1612 TRACE("(%p) call back. surf=%p. Face %d level %d\n", device
, This
->tex_root
, Face
, level
);
1614 searchcaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
1617 case WINED3DCUBEMAP_FACE_POSITIVE_X
:
1618 TRACE("Asked for positive x\n");
1619 if(searchcaps
.dwCaps2
& DDSCAPS2_CUBEMAP
) {
1620 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
1622 surf
= This
->tex_root
; break;
1623 case WINED3DCUBEMAP_FACE_NEGATIVE_X
:
1624 TRACE("Asked for negative x\n");
1625 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEX
; break;
1626 case WINED3DCUBEMAP_FACE_POSITIVE_Y
:
1627 TRACE("Asked for positive y\n");
1628 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEY
; break;
1629 case WINED3DCUBEMAP_FACE_NEGATIVE_Y
:
1630 TRACE("Asked for negative y\n");
1631 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEY
; break;
1632 case WINED3DCUBEMAP_FACE_POSITIVE_Z
:
1633 TRACE("Asked for positive z\n");
1634 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEZ
; break;
1635 case WINED3DCUBEMAP_FACE_NEGATIVE_Z
:
1636 TRACE("Asked for negative z\n");
1637 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEZ
; break;
1638 default: {ERR("Unexpected cube face\n");} /* Stupid compiler */
1643 IDirectDrawSurface7
*attached
;
1644 IDirectDrawSurface7_GetAttachedSurface(ICOM_INTERFACE(This
->tex_root
, IDirectDrawSurface7
),
1647 surf
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, attached
);
1648 IDirectDrawSurface7_Release(attached
);
1650 if(!surf
) ERR("root search surface not found\n");
1652 /* Find the wanted mipmap. There are enough mipmaps in the chain */
1655 IDirectDrawSurface7
*attached
;
1656 IDirectDrawSurface7_GetAttachedSurface(ICOM_INTERFACE(surf
, IDirectDrawSurface7
),
1659 if(!attached
) ERR("Surface not found\n");
1660 surf
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, attached
);
1661 IDirectDrawSurface7_Release(attached
);
1665 /* Return the surface */
1666 *Surface
= surf
->WineD3DSurface
;
1668 TRACE("Returning wineD3DSurface %p, it belongs to surface %p\n", *Surface
, surf
);
1672 ULONG WINAPI
D3D7CB_DestroySwapChain(IWineD3DSwapChain
*pSwapChain
) {
1673 IUnknown
* swapChainParent
;
1674 TRACE("(%p) call back\n", pSwapChain
);
1676 IWineD3DSwapChain_GetParent(pSwapChain
, &swapChainParent
);
1677 IUnknown_Release(swapChainParent
);
1678 return IUnknown_Release(swapChainParent
);
1681 ULONG WINAPI
D3D7CB_DestroyDepthStencilSurface(IWineD3DSurface
*pSurface
) {
1682 IUnknown
* surfaceParent
;
1683 TRACE("(%p) call back\n", pSurface
);
1685 IWineD3DSurface_GetParent(pSurface
, (IUnknown
**) &surfaceParent
);
1686 IUnknown_Release(surfaceParent
);
1687 return IUnknown_Release(surfaceParent
);
1690 /*****************************************************************************
1691 * IDirectDrawImpl_CreateNewSurface
1693 * A helper function for IDirectDraw7::CreateSurface. It creates a new surface
1694 * with the passed parameters.
1697 * DDSD: Description of the surface to create
1698 * Surf: Address to store the interface pointer at
1703 *****************************************************************************/
1704 static HRESULT WINAPI
1705 IDirectDrawImpl_CreateNewSurface(IDirectDrawImpl
*This
,
1706 DDSURFACEDESC2
*pDDSD
,
1707 IDirectDrawSurfaceImpl
**ppSurf
,
1711 UINT Width
= 0, Height
= 0;
1712 WINED3DFORMAT Format
= WINED3DFMT_UNKNOWN
;
1713 WINED3DRESOURCETYPE ResType
= WINED3DRTYPE_SURFACE
;
1715 WINED3DSURFTYPE ImplType
= This
->ImplType
;
1716 WINED3DSURFACE_DESC Desc
;
1718 IParentImpl
*parImpl
= NULL
;
1719 WINED3DPOOL Pool
= WINED3DPOOL_DEFAULT
;
1721 /* Dummies for GetDesc */
1722 WINED3DPOOL dummy_d3dpool
;
1723 WINED3DMULTISAMPLE_TYPE dummy_mst
;
1727 if (TRACE_ON(ddraw
))
1729 TRACE(" (%p) Requesting surface desc :\n", This
);
1730 DDRAW_dump_surface_desc(pDDSD
);
1733 /* Select the surface type, if it wasn't choosen yet */
1734 if(ImplType
== SURFACE_UNKNOWN
)
1736 /* Use GL Surfaces if a D3DDEVICE Surface is requested */
1737 if(pDDSD
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
1739 TRACE("(%p) Choosing GL surfaces because a 3DDEVICE Surface was requested\n", This
);
1740 ImplType
= SURFACE_OPENGL
;
1743 /* Otherwise use GDI surfaces for now */
1746 TRACE("(%p) Choosing GDI surfaces for 2D rendering\n", This
);
1747 ImplType
= SURFACE_GDI
;
1750 /* Policy if all surface implementations are available:
1751 * First, check if a default type was set with winecfg. If not,
1752 * try Xrender surfaces, and use them if they work. Next, check if
1753 * accelerated OpenGL is available, and use GL surfaces in this
1754 * case. If all else fails, use GDI surfaces. If a 3DDEVICE surface
1755 * was created, always use OpenGL surfaces.
1757 * (Note: Xrender surfaces are not implemented for now, the
1758 * unaccelerated implementation uses GDI to render in Software)
1761 /* Store the type. If it needs to be changed, all WineD3DSurfaces have to
1762 * be re-created. This could be done with IDirectDrawSurface7::Restore
1764 This
->ImplType
= ImplType
;
1768 if((pDDSD
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
) &&
1769 (This
->ImplType
!= SURFACE_OPENGL
) && DefaultSurfaceType
== SURFACE_UNKNOWN
)
1771 /* We have to change to OpenGL,
1772 * and re-create all WineD3DSurfaces
1774 ImplType
= SURFACE_OPENGL
;
1775 This
->ImplType
= ImplType
;
1776 TRACE("(%p) Re-creating all surfaces\n", This
);
1777 IDirectDrawImpl_RecreateAllSurfaces(This
);
1778 TRACE("(%p) Done recreating all surfaces\n", This
);
1780 else if(This
->ImplType
!= SURFACE_OPENGL
&& pDDSD
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
1782 WARN("The application requests a 3D capable surface, but a non-opengl surface was set in the registry\n");
1783 /* Do not fail surface creation, only fail 3D device creation */
1787 /* Get the correct wined3d usage */
1788 if (pDDSD
->ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
|
1789 DDSCAPS_BACKBUFFER
|
1790 DDSCAPS_3DDEVICE
) )
1792 Usage
|= WINED3DUSAGE_RENDERTARGET
;
1794 pDDSD
->ddsCaps
.dwCaps
|= DDSCAPS_VIDEOMEMORY
|
1797 if (pDDSD
->ddsCaps
.dwCaps
& (DDSCAPS_OVERLAY
))
1799 Usage
|= WINED3DUSAGE_OVERLAY
;
1801 if(This
->depthstencil
|| (pDDSD
->ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
) )
1803 /* The depth stencil creation callback sets this flag.
1804 * Set the WineD3D usage to let it know that it's a depth
1807 Usage
|= WINED3DUSAGE_DEPTHSTENCIL
;
1809 if(pDDSD
->ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
1811 Pool
= WINED3DPOOL_SYSTEMMEM
;
1813 else if(pDDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
)
1815 Pool
= WINED3DPOOL_MANAGED
;
1816 /* Managed textures have the system memory flag set */
1817 pDDSD
->ddsCaps
.dwCaps
|= DDSCAPS_SYSTEMMEMORY
;
1819 else if(pDDSD
->ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
)
1821 /* Videomemory adds localvidmem, this is mutually exclusive with systemmemory
1824 pDDSD
->ddsCaps
.dwCaps
|= DDSCAPS_LOCALVIDMEM
;
1827 Format
= PixelFormat_DD2WineD3D(&pDDSD
->u4
.ddpfPixelFormat
);
1828 if(Format
== WINED3DFMT_UNKNOWN
)
1830 ERR("Unsupported / Unknown pixelformat\n");
1831 return DDERR_INVALIDPIXELFORMAT
;
1834 /* Create the Surface object */
1835 *ppSurf
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectDrawSurfaceImpl
));
1838 ERR("(%p) Error allocating memory for a surface\n", This
);
1839 return DDERR_OUTOFVIDEOMEMORY
;
1841 ICOM_INIT_INTERFACE(*ppSurf
, IDirectDrawSurface7
, IDirectDrawSurface7_Vtbl
);
1842 ICOM_INIT_INTERFACE(*ppSurf
, IDirectDrawSurface3
, IDirectDrawSurface3_Vtbl
);
1843 ICOM_INIT_INTERFACE(*ppSurf
, IDirectDrawGammaControl
, IDirectDrawGammaControl_Vtbl
);
1844 ICOM_INIT_INTERFACE(*ppSurf
, IDirect3DTexture2
, IDirect3DTexture2_Vtbl
);
1845 ICOM_INIT_INTERFACE(*ppSurf
, IDirect3DTexture
, IDirect3DTexture1_Vtbl
);
1847 (*ppSurf
)->version
= 7;
1848 (*ppSurf
)->ddraw
= This
;
1849 (*ppSurf
)->surface_desc
.dwSize
= sizeof(DDSURFACEDESC2
);
1850 (*ppSurf
)->surface_desc
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
1851 DD_STRUCT_COPY_BYSIZE(&(*ppSurf
)->surface_desc
, pDDSD
);
1853 /* Surface attachments */
1854 (*ppSurf
)->next_attached
= NULL
;
1855 (*ppSurf
)->first_attached
= *ppSurf
;
1857 /* Needed to re-create the surface on an implementation change */
1858 (*ppSurf
)->ImplType
= ImplType
;
1860 /* For D3DDevice creation */
1861 (*ppSurf
)->isRenderTarget
= FALSE
;
1863 /* A trace message for debugging */
1864 TRACE("(%p) Created IDirectDrawSurface implementation structure at %p\n", This
, *ppSurf
);
1866 if(pDDSD
->ddsCaps
.dwCaps
& ( DDSCAPS_PRIMARYSURFACE
| DDSCAPS_TEXTURE
| DDSCAPS_3DDEVICE
) )
1868 /* Render targets and textures need a IParent interface,
1869 * because WineD3D will destroy them when the swapchain
1872 parImpl
= HeapAlloc(GetProcessHeap(), 0, sizeof(IParentImpl
));
1875 ERR("Out of memory when allocating memory for a IParent implementation\n");
1876 return DDERR_OUTOFMEMORY
;
1879 ICOM_INIT_INTERFACE(parImpl
, IParent
, IParent_Vtbl
);
1880 Parent
= (IUnknown
*) ICOM_INTERFACE(parImpl
, IParent
);
1881 TRACE("Using IParent interface %p as parent\n", parImpl
);
1885 /* Use the surface as parent */
1886 Parent
= (IUnknown
*) ICOM_INTERFACE(*ppSurf
, IDirectDrawSurface7
);
1887 TRACE("Using Surface interface %p as parent\n", *ppSurf
);
1890 /* Now create the WineD3D Surface */
1891 hr
= IWineD3DDevice_CreateSurface(This
->wineD3DDevice
,
1895 TRUE
/* Lockable */,
1896 FALSE
/* Discard */,
1898 &(*ppSurf
)->WineD3DSurface
,
1901 WINED3DMULTISAMPLE_NONE
,
1902 0 /* MultiSampleQuality */,
1903 0 /* SharedHandle */,
1909 ERR("IWineD3DDevice::CreateSurface failed. hr = %08x\n", hr
);
1913 /* Set the child of the parent implementation if it exists */
1916 parImpl
->child
= (IUnknown
*) (*ppSurf
)->WineD3DSurface
;
1917 /* The IParent releases the WineD3DSurface, and
1918 * the ddraw surface does that too. Hold a reference
1920 IWineD3DSurface_AddRef((*ppSurf
)->WineD3DSurface
);
1923 /* Increase the surface counter, and attach the surface */
1924 InterlockedIncrement(&This
->surfaces
);
1925 list_add_head(&This
->surface_list
, &(*ppSurf
)->surface_list_entry
);
1927 /* Here we could store all created surfaces in the DirectDrawImpl structure,
1928 * But this could also be delegated to WineDDraw, as it keeps track of all its
1929 * resources. Not implemented for now, as there are more important things ;)
1932 /* Get the pixel format of the WineD3DSurface and store it.
1933 * Don't use the Format choosen above, WineD3D might have
1936 Desc
.Format
= &Format
;
1937 Desc
.Type
= &ResType
;
1938 Desc
.Usage
= &Usage
;
1939 Desc
.Pool
= &dummy_d3dpool
;
1940 Desc
.Size
= &dummy_uint
;
1941 Desc
.MultiSampleType
= &dummy_mst
;
1942 Desc
.MultiSampleQuality
= &dummy_dword
;
1943 Desc
.Width
= &Width
;
1944 Desc
.Height
= &Height
;
1946 (*ppSurf
)->surface_desc
.dwFlags
|= DDSD_PIXELFORMAT
;
1947 hr
= IWineD3DSurface_GetDesc((*ppSurf
)->WineD3DSurface
, &Desc
);
1950 ERR("IWineD3DSurface::GetDesc failed\n");
1951 IDirectDrawSurface7_Release( (IDirectDrawSurface7
*) *ppSurf
);
1955 if(Format
== WINED3DFMT_UNKNOWN
)
1957 FIXME("IWineD3DSurface::GetDesc returned WINED3DFMT_UNKNOWN\n");
1959 PixelFormat_WineD3DtoDD( &(*ppSurf
)->surface_desc
.u4
.ddpfPixelFormat
, Format
);
1961 /* Anno 1602 stores the pitch right after surface creation, so make sure it's there.
1962 * I can't LockRect() the surface here because if OpenGL surfaces are in use, the
1963 * WineD3DDevice might not be useable for 3D yet, so an extra method was created.
1964 * TODO: Test other fourcc formats
1966 if(Format
== WINED3DFMT_DXT1
|| Format
== WINED3DFMT_DXT2
|| Format
== WINED3DFMT_DXT3
||
1967 Format
== WINED3DFMT_DXT4
|| Format
== WINED3DFMT_DXT5
)
1969 (*ppSurf
)->surface_desc
.dwFlags
|= DDSD_LINEARSIZE
;
1970 if(Format
== WINED3DFMT_DXT1
)
1972 (*ppSurf
)->surface_desc
.u1
.dwLinearSize
= max(4, Width
) * max(4, Height
) / 2;
1976 (*ppSurf
)->surface_desc
.u1
.dwLinearSize
= max(4, Width
) * max(4, Height
);
1981 (*ppSurf
)->surface_desc
.dwFlags
|= DDSD_PITCH
;
1982 (*ppSurf
)->surface_desc
.u1
.lPitch
= IWineD3DSurface_GetPitch((*ppSurf
)->WineD3DSurface
);
1985 /* Application passed a color key? Set it! */
1986 if(pDDSD
->dwFlags
& DDSD_CKDESTOVERLAY
)
1988 IWineD3DSurface_SetColorKey((*ppSurf
)->WineD3DSurface
,
1990 (WINEDDCOLORKEY
*) &pDDSD
->u3
.ddckCKDestOverlay
);
1992 if(pDDSD
->dwFlags
& DDSD_CKDESTBLT
)
1994 IWineD3DSurface_SetColorKey((*ppSurf
)->WineD3DSurface
,
1996 (WINEDDCOLORKEY
*) &pDDSD
->ddckCKDestBlt
);
1998 if(pDDSD
->dwFlags
& DDSD_CKSRCOVERLAY
)
2000 IWineD3DSurface_SetColorKey((*ppSurf
)->WineD3DSurface
,
2002 (WINEDDCOLORKEY
*) &pDDSD
->ddckCKSrcOverlay
);
2004 if(pDDSD
->dwFlags
& DDSD_CKSRCBLT
)
2006 IWineD3DSurface_SetColorKey((*ppSurf
)->WineD3DSurface
,
2008 (WINEDDCOLORKEY
*) &pDDSD
->ddckCKSrcBlt
);
2010 if ( pDDSD
->dwFlags
& DDSD_LPSURFACE
)
2012 hr
= IWineD3DSurface_SetMem((*ppSurf
)->WineD3DSurface
, pDDSD
->lpSurface
);
2013 if(hr
!= WINED3D_OK
)
2015 /* No need for a trace here, wined3d does that for us */
2016 IDirectDrawSurface7_Release(ICOM_INTERFACE((*ppSurf
), IDirectDrawSurface7
));
2023 /*****************************************************************************
2024 * CreateAdditionalSurfaces
2026 * Creates a new mipmap chain.
2029 * root: Root surface to attach the newly created chain to
2030 * count: number of surfaces to create
2031 * DDSD: Description of the surface. Intentionally not a pointer to avoid side
2032 * effects on the caller
2033 * CubeFaceRoot: Wether the new surface is a root of a cube map face. This
2034 * creates an additional surface without the mipmapping flags
2036 *****************************************************************************/
2038 CreateAdditionalSurfaces(IDirectDrawImpl
*This
,
2039 IDirectDrawSurfaceImpl
*root
,
2041 DDSURFACEDESC2 DDSD
,
2044 UINT i
, j
, level
= 0;
2046 IDirectDrawSurfaceImpl
*last
= root
;
2048 for(i
= 0; i
< count
; i
++)
2050 IDirectDrawSurfaceImpl
*object2
= NULL
;
2052 /* increase the mipmap level, but only if a mipmap is created
2053 * In this case, also halve the size
2055 if(DDSD
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
&& !CubeFaceRoot
)
2058 if(DDSD
.dwWidth
> 1) DDSD
.dwWidth
/= 2;
2059 if(DDSD
.dwHeight
> 1) DDSD
.dwHeight
/= 2;
2060 /* Set the mipmap sublevel flag according to msdn */
2061 DDSD
.ddsCaps
.dwCaps2
|= DDSCAPS2_MIPMAPSUBLEVEL
;
2065 DDSD
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
2067 CubeFaceRoot
= FALSE
;
2069 hr
= IDirectDrawImpl_CreateNewSurface(This
,
2078 /* Add the new surface to the complex attachment array */
2079 for(j
= 0; j
< MAX_COMPLEX_ATTACHED
; j
++)
2081 if(last
->complex_array
[j
]) continue;
2082 last
->complex_array
[j
] = object2
;
2087 /* Remove the (possible) back buffer cap from the new surface description,
2088 * because only one surface in the flipping chain is a back buffer, one
2089 * is a front buffer, the others are just primary surfaces.
2091 DDSD
.ddsCaps
.dwCaps
&= ~DDSCAPS_BACKBUFFER
;
2096 /*****************************************************************************
2097 * IDirectDraw7::CreateSurface
2099 * Creates a new IDirectDrawSurface object and returns its interface.
2101 * The surface connections with wined3d are a bit tricky. Basically it works
2104 * |------------------------| |-----------------|
2105 * | DDraw surface | | WineD3DSurface |
2107 * | WineD3DSurface |-------------->| |
2108 * | Child |<------------->| Parent |
2109 * |------------------------| |-----------------|
2111 * The DDraw surface is the parent of the wined3d surface, and it releases
2112 * the WineD3DSurface when the ddraw surface is destroyed.
2114 * However, for all surfaces which can be in a container in WineD3D,
2115 * we have to do this. These surfaces are ususally complex surfaces,
2116 * so this concerns primary surfaces with a front and a back buffer,
2119 * |------------------------| |-----------------|
2120 * | DDraw surface | | Containter |
2122 * | Child |<------------->| Parent |
2123 * | Texture |<------------->| |
2124 * | WineD3DSurface |<----| | Levels |<--|
2125 * | Complex connection | | | | |
2126 * |------------------------| | |-----------------| |
2130 * | |------------------| | |-----------------| |
2131 * | | IParent | |-------->| WineD3DSurface | |
2133 * | | Child |<------------->| Parent | |
2134 * | | | | Container |<--|
2135 * | |------------------| |-----------------| |
2137 * | |----------------------| |
2138 * | | DDraw surface 2 | |
2140 * |<->| Complex root Child | |
2142 * | | WineD3DSurface |<----| |
2143 * | |----------------------| | |
2145 * | |---------------------| | |-----------------| |
2146 * | | IParent | |----->| WineD3DSurface | |
2148 * | | Child |<---------->| Parent | |
2149 * | |---------------------| | Container |<--|
2150 * | |-----------------| |
2152 * | ---More surfaces can follow--- |
2154 * The reason is that the IWineD3DSwapchain(render target container)
2155 * and the IWineD3DTexure(Texture container) release the parents
2156 * of their surface's children, but by releasing the complex root
2157 * the surfaces which are complexly attached to it are destroyed
2158 * too. See IDirectDrawSurface::Release for a more detailed
2162 * DDSD: Description of the surface to create
2163 * Surf: Address to store the interface pointer at
2164 * UnkOuter: Basically for aggregation support, but ddraw doesn't support
2165 * aggregation, so it has to be NULL
2169 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
2170 * DDERR_* if an error occurs
2172 *****************************************************************************/
2173 static HRESULT WINAPI
2174 IDirectDrawImpl_CreateSurface(IDirectDraw7
*iface
,
2175 DDSURFACEDESC2
*DDSD
,
2176 IDirectDrawSurface7
**Surf
,
2179 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
2180 IDirectDrawSurfaceImpl
*object
= NULL
;
2182 LONG extra_surfaces
= 0;
2183 DDSURFACEDESC2 desc2
;
2184 WINED3DDISPLAYMODE Mode
;
2186 TRACE("(%p)->(%p,%p,%p)\n", This
, DDSD
, Surf
, UnkOuter
);
2188 /* Some checks before we start */
2189 if (TRACE_ON(ddraw
))
2191 TRACE(" (%p) Requesting surface desc :\n", This
);
2192 DDRAW_dump_surface_desc(DDSD
);
2195 if (UnkOuter
!= NULL
)
2197 FIXME("(%p) : outer != NULL?\n", This
);
2198 return CLASS_E_NOAGGREGATION
; /* unchecked */
2203 FIXME("(%p) You want to get back a surface? Don't give NULL ptrs!\n", This
);
2204 return E_POINTER
; /* unchecked */
2207 if (!(DDSD
->dwFlags
& DDSD_CAPS
))
2209 /* DVIDEO.DLL does forget the DDSD_CAPS flag ... *sigh* */
2210 DDSD
->dwFlags
|= DDSD_CAPS
;
2212 if (DDSD
->ddsCaps
.dwCaps
== 0)
2214 /* This has been checked on real Windows */
2215 DDSD
->ddsCaps
.dwCaps
= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
;
2218 if (DDSD
->ddsCaps
.dwCaps
& DDSCAPS_ALLOCONLOAD
)
2220 /* If the surface is of the 'alloconload' type, ignore the LPSURFACE field */
2221 DDSD
->dwFlags
&= ~DDSD_LPSURFACE
;
2224 if ((DDSD
->dwFlags
& DDSD_LPSURFACE
) && (DDSD
->lpSurface
== NULL
))
2226 /* Frank Herbert's Dune specifies a null pointer for the surface, ignore the LPSURFACE field */
2227 WARN("(%p) Null surface pointer specified, ignore it!\n", This
);
2228 DDSD
->dwFlags
&= ~DDSD_LPSURFACE
;
2231 if((DDSD
->ddsCaps
.dwCaps
& (DDSCAPS_FLIP
| DDSCAPS_PRIMARYSURFACE
)) == (DDSCAPS_FLIP
| DDSCAPS_PRIMARYSURFACE
) &&
2232 !(This
->cooperative_level
& DDSCL_EXCLUSIVE
))
2234 TRACE("(%p): Attempt to create a flipable primary surface without DDSCL_EXCLUSIVE set\n", This
);
2236 return DDERR_NOEXCLUSIVEMODE
;
2239 if(DDSD
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
)) {
2240 WARN("Application tried to create an explicit front or back buffer\n");
2241 return DDERR_INVALIDCAPS
;
2243 /* Check cube maps but only if the size includes them */
2244 if (DDSD
->dwSize
>= sizeof(DDSURFACEDESC2
))
2246 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
&&
2247 !(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
))
2249 WARN("Cube map faces requested without cube map flag\n");
2250 return DDERR_INVALIDCAPS
;
2252 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
&&
2253 (DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
) == 0)
2255 WARN("Cube map without faces requested\n");
2256 return DDERR_INVALIDPARAMS
;
2259 /* Quick tests confirm those can be created, but we don't do that yet */
2260 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
&&
2261 (DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
) != DDSCAPS2_CUBEMAP_ALLFACES
)
2263 FIXME("Partial cube maps not supported yet\n");
2267 /* According to the msdn this flag is ignored by CreateSurface */
2268 if (DDSD
->dwSize
>= sizeof(DDSURFACEDESC2
))
2269 DDSD
->ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
2271 /* Modify some flags */
2272 memset(&desc2
, 0, sizeof(desc2
));
2273 desc2
.dwSize
= sizeof(desc2
); /* For the struct copy */
2274 DD_STRUCT_COPY_BYSIZE(&desc2
, DDSD
);
2275 desc2
.dwSize
= sizeof(desc2
); /* To override a possibly smaller size */
2276 desc2
.u4
.ddpfPixelFormat
.dwSize
=sizeof(DDPIXELFORMAT
); /* Just to be sure */
2278 /* Get the video mode from WineD3D - we will need it */
2279 hr
= IWineD3DDevice_GetDisplayMode(This
->wineD3DDevice
,
2280 0, /* Swapchain 0 */
2284 ERR("Failed to read display mode from wined3d\n");
2285 switch(This
->orig_bpp
)
2288 Mode
.Format
= WINED3DFMT_P8
;
2292 Mode
.Format
= WINED3DFMT_X1R5G5B5
;
2296 Mode
.Format
= WINED3DFMT_R5G6B5
;
2300 Mode
.Format
= WINED3DFMT_R8G8B8
;
2304 Mode
.Format
= WINED3DFMT_X8R8G8B8
;
2307 Mode
.Width
= This
->orig_width
;
2308 Mode
.Height
= This
->orig_height
;
2311 /* No pixelformat given? Use the current screen format */
2312 if(!(desc2
.dwFlags
& DDSD_PIXELFORMAT
))
2314 desc2
.dwFlags
|= DDSD_PIXELFORMAT
;
2315 desc2
.u4
.ddpfPixelFormat
.dwSize
=sizeof(DDPIXELFORMAT
);
2317 /* Wait: It could be a Z buffer */
2318 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
2320 switch(desc2
.u2
.dwMipMapCount
) /* Who had this glorious idea? */
2323 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, WINED3DFMT_D15S1
);
2326 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, WINED3DFMT_D16
);
2329 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, WINED3DFMT_D24X8
);
2332 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, WINED3DFMT_D32
);
2335 ERR("Unknown Z buffer bit depth\n");
2340 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, Mode
.Format
);
2344 /* No Width or no Height? Use the original screen size
2346 if(!(desc2
.dwFlags
& DDSD_WIDTH
) ||
2347 !(desc2
.dwFlags
& DDSD_HEIGHT
) )
2349 /* Invalid for non-render targets */
2350 if(!(desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
2352 WARN("Creating a non-Primary surface without Width or Height info, returning DDERR_INVALIDPARAMS\n");
2354 return DDERR_INVALIDPARAMS
;
2357 desc2
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
2358 desc2
.dwWidth
= Mode
.Width
;
2359 desc2
.dwHeight
= Mode
.Height
;
2362 /* Mipmap count fixes */
2363 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
2365 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_COMPLEX
)
2367 if(desc2
.dwFlags
& DDSD_MIPMAPCOUNT
)
2369 /* Mipmap count is given, nothing to do */
2373 /* Undocumented feature: Create sublevels until
2374 * either the width or the height is 1
2376 DWORD min
= desc2
.dwWidth
< desc2
.dwHeight
?
2377 desc2
.dwWidth
: desc2
.dwHeight
;
2378 desc2
.u2
.dwMipMapCount
= 0;
2381 desc2
.u2
.dwMipMapCount
+= 1;
2388 /* Not-complex mipmap -> Mipmapcount = 1 */
2389 desc2
.u2
.dwMipMapCount
= 1;
2391 extra_surfaces
= desc2
.u2
.dwMipMapCount
- 1;
2393 /* There's a mipmap count in the created surface in any case */
2394 desc2
.dwFlags
|= DDSD_MIPMAPCOUNT
;
2396 /* If no mipmap is given, the texture has only one level */
2398 /* The first surface is a front buffer, the back buffer is created afterwards */
2399 if( (desc2
.dwFlags
& DDSD_CAPS
) && (desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) )
2401 desc2
.ddsCaps
.dwCaps
|= DDSCAPS_FRONTBUFFER
;
2404 /* The root surface in a cube map is positive x */
2405 if(desc2
.ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
2407 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
2408 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
2411 /* Create the first surface */
2412 hr
= IDirectDrawImpl_CreateNewSurface(This
, &desc2
, &object
, 0);
2415 ERR("IDirectDrawImpl_CreateNewSurface failed with %08x\n", hr
);
2418 object
->is_complex_root
= TRUE
;
2420 *Surf
= ICOM_INTERFACE(object
, IDirectDrawSurface7
);
2422 /* Create Additional surfaces if necessary
2423 * This applies to Primary surfaces which have a back buffer count
2424 * set, but not to mipmap textures. In case of Mipmap textures,
2425 * wineD3D takes care of the creation of additional surfaces
2427 if(DDSD
->dwFlags
& DDSD_BACKBUFFERCOUNT
)
2429 extra_surfaces
= DDSD
->dwBackBufferCount
;
2430 desc2
.ddsCaps
.dwCaps
&= ~DDSCAPS_FRONTBUFFER
; /* It's not a front buffer */
2431 desc2
.ddsCaps
.dwCaps
|= DDSCAPS_BACKBUFFER
;
2435 if(desc2
.ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
2437 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
2438 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEZ
;
2439 hr
|= CreateAdditionalSurfaces(This
, object
, extra_surfaces
+ 1, desc2
, TRUE
);
2440 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_NEGATIVEZ
;
2441 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEZ
;
2442 hr
|= CreateAdditionalSurfaces(This
, object
, extra_surfaces
+ 1, desc2
, TRUE
);
2443 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_POSITIVEZ
;
2444 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEY
;
2445 hr
|= CreateAdditionalSurfaces(This
, object
, extra_surfaces
+ 1, desc2
, TRUE
);
2446 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_NEGATIVEY
;
2447 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEY
;
2448 hr
|= CreateAdditionalSurfaces(This
, object
, extra_surfaces
+ 1, desc2
, TRUE
);
2449 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_POSITIVEY
;
2450 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEX
;
2451 hr
|= CreateAdditionalSurfaces(This
, object
, extra_surfaces
+ 1, desc2
, TRUE
);
2452 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_NEGATIVEX
;
2453 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
2456 hr
|= CreateAdditionalSurfaces(This
, object
, extra_surfaces
, desc2
, FALSE
);
2459 /* This destroys and possibly created surfaces too */
2460 IDirectDrawSurface_Release( ICOM_INTERFACE(object
, IDirectDrawSurface7
) );
2464 /* Addref the ddraw interface to keep an reference for each surface */
2465 IDirectDraw7_AddRef(iface
);
2466 object
->ifaceToRelease
= (IUnknown
*) iface
;
2468 /* If the implementation is OpenGL and there's no d3ddevice, attach a d3ddevice
2469 * But attach the d3ddevice only if the currently created surface was
2470 * a primary surface (2D app in 3D mode) or a 3DDEVICE surface (3D app)
2471 * The only case I can think of where this doesn't apply is when a
2472 * 2D app was configured by the user to run with OpenGL and it didn't create
2473 * the render target as first surface. In this case the render target creation
2474 * will cause the 3D init.
2476 if( (This
->ImplType
== SURFACE_OPENGL
) && !(This
->d3d_initialized
) &&
2477 desc2
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_3DDEVICE
) )
2479 IDirectDrawSurfaceImpl
*target
= object
, *surface
;
2482 /* Search for the primary to use as render target */
2483 LIST_FOR_EACH(entry
, &This
->surface_list
)
2485 surface
= LIST_ENTRY(entry
, IDirectDrawSurfaceImpl
, surface_list_entry
);
2486 if((surface
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
)) ==
2487 (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
))
2491 TRACE("Using primary %p as render target\n", target
);
2496 TRACE("(%p) Attaching a D3DDevice, rendertarget = %p\n", This
, target
);
2497 hr
= IDirectDrawImpl_AttachD3DDevice(This
, target
);
2500 ERR("IDirectDrawImpl_AttachD3DDevice failed, hr = %x\n", hr
);
2504 /* Create a WineD3DTexture if a texture was requested */
2505 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
2508 WINED3DFORMAT Format
;
2509 WINED3DPOOL Pool
= WINED3DPOOL_DEFAULT
;
2511 This
->tex_root
= object
;
2513 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
2515 /* a mipmap is created, create enough levels */
2516 levels
= desc2
.u2
.dwMipMapCount
;
2520 /* No mipmap is created, create one level */
2524 /* DDSCAPS_SYSTEMMEMORY textures are in WINED3DPOOL_SYSTEMMEM */
2525 if(DDSD
->ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
2527 Pool
= WINED3DPOOL_SYSTEMMEM
;
2529 /* Should I forward the MANEGED cap to the managed pool ? */
2531 /* Get the format. It's set already by CreateNewSurface */
2532 Format
= PixelFormat_DD2WineD3D(&object
->surface_desc
.u4
.ddpfPixelFormat
);
2534 /* The surfaces are already created, the callback only
2535 * passes the IWineD3DSurface to WineD3D
2537 if(desc2
.ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
2539 hr
= IWineD3DDevice_CreateCubeTexture(This
->wineD3DDevice
,
2540 DDSD
->dwWidth
, /* Edgelength */
2545 (IWineD3DCubeTexture
**) &object
->wineD3DTexture
,
2546 0, /* SharedHandle */
2547 (IUnknown
*) ICOM_INTERFACE(object
, IDirectDrawSurface7
),
2548 D3D7CB_CreateSurface
);
2552 hr
= IWineD3DDevice_CreateTexture(This
->wineD3DDevice
,
2553 DDSD
->dwWidth
, DDSD
->dwHeight
,
2554 levels
, /* MipMapCount = Levels */
2558 (IWineD3DTexture
**) &object
->wineD3DTexture
,
2559 0, /* SharedHandle */
2560 (IUnknown
*) ICOM_INTERFACE(object
, IDirectDrawSurface7
),
2561 D3D7CB_CreateSurface
);
2563 This
->tex_root
= NULL
;
2569 #define DDENUMSURFACES_SEARCHTYPE (DDENUMSURFACES_CANBECREATED|DDENUMSURFACES_DOESEXIST)
2570 #define DDENUMSURFACES_MATCHTYPE (DDENUMSURFACES_ALL|DDENUMSURFACES_MATCH|DDENUMSURFACES_NOMATCH)
2573 Main_DirectDraw_DDPIXELFORMAT_Match(const DDPIXELFORMAT
*requested
,
2574 const DDPIXELFORMAT
*provided
)
2576 /* Some flags must be present in both or neither for a match. */
2577 static const DWORD must_match
= DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
2578 | DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_FOURCC
2579 | DDPF_ZBUFFER
| DDPF_STENCILBUFFER
;
2581 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
2584 if ((requested
->dwFlags
& must_match
) != (provided
->dwFlags
& must_match
))
2587 if (requested
->dwFlags
& DDPF_FOURCC
)
2588 if (requested
->dwFourCC
!= provided
->dwFourCC
)
2591 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_ALPHA
2592 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
2593 if (requested
->u1
.dwRGBBitCount
!= provided
->u1
.dwRGBBitCount
)
2596 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
2597 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
2598 if (requested
->u2
.dwRBitMask
!= provided
->u2
.dwRBitMask
)
2601 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_BUMPDUDV
))
2602 if (requested
->u3
.dwGBitMask
!= provided
->u3
.dwGBitMask
)
2605 /* I could be wrong about the bumpmapping. MSDN docs are vague. */
2606 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
2608 if (requested
->u4
.dwBBitMask
!= provided
->u4
.dwBBitMask
)
2611 if (requested
->dwFlags
& (DDPF_ALPHAPIXELS
|DDPF_ZPIXELS
))
2612 if (requested
->u5
.dwRGBAlphaBitMask
!= provided
->u5
.dwRGBAlphaBitMask
)
2619 IDirectDrawImpl_DDSD_Match(const DDSURFACEDESC2
* requested
,
2620 const DDSURFACEDESC2
* provided
)
2629 #define CMP(FLAG, FIELD) \
2630 { DDSD_##FLAG, offsetof(DDSURFACEDESC2, FIELD), \
2631 sizeof(((DDSURFACEDESC2 *)(NULL))->FIELD) }
2633 static const struct compare_info compare
[] =
2635 CMP(ALPHABITDEPTH
, dwAlphaBitDepth
),
2636 CMP(BACKBUFFERCOUNT
, dwBackBufferCount
),
2638 CMP(CKDESTBLT
, ddckCKDestBlt
),
2639 CMP(CKDESTOVERLAY
, u3
/* ddckCKDestOverlay */),
2640 CMP(CKSRCBLT
, ddckCKSrcBlt
),
2641 CMP(CKSRCOVERLAY
, ddckCKSrcOverlay
),
2642 CMP(HEIGHT
, dwHeight
),
2643 CMP(LINEARSIZE
, u1
/* dwLinearSize */),
2644 CMP(LPSURFACE
, lpSurface
),
2645 CMP(MIPMAPCOUNT
, u2
/* dwMipMapCount */),
2646 CMP(PITCH
, u1
/* lPitch */),
2647 /* PIXELFORMAT: manual */
2648 CMP(REFRESHRATE
, u2
/* dwRefreshRate */),
2649 CMP(TEXTURESTAGE
, dwTextureStage
),
2650 CMP(WIDTH
, dwWidth
),
2651 /* ZBUFFERBITDEPTH: "obsolete" */
2658 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
2661 for (i
=0; i
< sizeof(compare
)/sizeof(compare
[0]); i
++)
2663 if (requested
->dwFlags
& compare
[i
].flag
2664 && memcmp((const char *)provided
+ compare
[i
].offset
,
2665 (const char *)requested
+ compare
[i
].offset
,
2666 compare
[i
].size
) != 0)
2670 if (requested
->dwFlags
& DDSD_PIXELFORMAT
)
2672 if (!Main_DirectDraw_DDPIXELFORMAT_Match(&requested
->u4
.ddpfPixelFormat
,
2673 &provided
->u4
.ddpfPixelFormat
))
2680 #undef DDENUMSURFACES_SEARCHTYPE
2681 #undef DDENUMSURFACES_MATCHTYPE
2683 /*****************************************************************************
2684 * IDirectDraw7::EnumSurfaces
2686 * Loops through all surfaces attached to this device and calls the
2687 * application callback. This can't be relayed to WineD3DDevice,
2688 * because some WineD3DSurfaces' parents are IParent objects
2691 * Flags: Some filtering flags. See IDirectDrawImpl_EnumSurfacesCallback
2692 * DDSD: Description to filter for
2693 * Context: Application-provided pointer, it's passed unmodified to the
2695 * Callback: Address to call for each surface
2698 * DDERR_INVALIDPARAMS if the callback is NULL
2701 *****************************************************************************/
2702 static HRESULT WINAPI
2703 IDirectDrawImpl_EnumSurfaces(IDirectDraw7
*iface
,
2705 DDSURFACEDESC2
*DDSD
,
2707 LPDDENUMSURFACESCALLBACK7 Callback
)
2709 /* The surface enumeration is handled by WineDDraw,
2710 * because it keeps track of all surfaces attached to
2711 * it. The filtering is done by our callback function,
2712 * because WineDDraw doesn't handle ddraw-like surface
2715 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
2716 IDirectDrawSurfaceImpl
*surf
;
2718 DDSURFACEDESC2 desc
;
2719 struct list
*entry
, *entry2
;
2721 all
= Flags
& DDENUMSURFACES_ALL
;
2722 nomatch
= Flags
& DDENUMSURFACES_NOMATCH
;
2724 TRACE("(%p)->(%x,%p,%p,%p)\n", This
, Flags
, DDSD
, Context
, Callback
);
2727 return DDERR_INVALIDPARAMS
;
2729 /* Use the _SAFE enumeration, the app may destroy enumerated surfaces */
2730 LIST_FOR_EACH_SAFE(entry
, entry2
, &This
->surface_list
)
2732 surf
= LIST_ENTRY(entry
, IDirectDrawSurfaceImpl
, surface_list_entry
);
2733 if (all
|| (nomatch
!= IDirectDrawImpl_DDSD_Match(DDSD
, &surf
->surface_desc
)))
2735 desc
= surf
->surface_desc
;
2736 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(surf
, IDirectDrawSurface7
));
2737 if(Callback( ICOM_INTERFACE(surf
, IDirectDrawSurface7
), &desc
, Context
) != DDENUMRET_OK
)
2744 static HRESULT WINAPI
2745 findRenderTarget(IDirectDrawSurface7
*surface
,
2746 DDSURFACEDESC2
*desc
,
2749 IDirectDrawSurfaceImpl
*surf
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, surface
);
2750 IDirectDrawSurfaceImpl
**target
= (IDirectDrawSurfaceImpl
**) ctx
;
2752 if(!surf
->isRenderTarget
) {
2754 IDirectDrawSurface7_Release(surface
);
2755 return DDENUMRET_CANCEL
;
2758 /* Recurse into the surface tree */
2759 IDirectDrawSurface7_EnumAttachedSurfaces(surface
, ctx
, findRenderTarget
);
2761 IDirectDrawSurface7_Release(surface
);
2762 if(*target
) return DDENUMRET_CANCEL
;
2763 else return DDENUMRET_OK
; /* Continue with the next neighbor surface */
2766 /*****************************************************************************
2767 * D3D7CB_CreateRenderTarget
2769 * Callback called by WineD3D to create Surfaces for render target usage
2770 * This function takes the D3D target from the IDirectDrawImpl structure,
2771 * and returns the WineD3DSurface. To avoid double usage, the surface
2772 * is marked as render target afterwards
2775 * device: The WineD3DDevice's parent
2776 * Width, Height, Format: Dimensions and pixelformat of the render target
2777 * Ignored, because the surface already exists
2778 * MultiSample, MultisampleQuality, Lockable: Ignored for the same reason
2780 * ppSurface: Address to pass the surface pointer back at
2781 * pSharedHandle: Ignored
2784 * Always returns D3D_OK
2786 *****************************************************************************/
2787 static HRESULT WINAPI
2788 D3D7CB_CreateRenderTarget(IUnknown
*device
, IUnknown
*pSuperior
,
2789 UINT Width
, UINT Height
,
2790 WINED3DFORMAT Format
,
2791 WINED3DMULTISAMPLE_TYPE MultiSample
,
2792 DWORD MultisampleQuality
,
2794 IWineD3DSurface
** ppSurface
,
2795 HANDLE
* pSharedHandle
)
2797 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, device
);
2798 IDirectDrawSurfaceImpl
*d3dSurface
= This
->d3d_target
, *target
= NULL
;
2799 TRACE("(%p) call back\n", device
);
2801 if(d3dSurface
->isRenderTarget
)
2803 IDirectDrawSurface7_EnumAttachedSurfaces(ICOM_INTERFACE(d3dSurface
, IDirectDrawSurface7
),
2804 &target
, findRenderTarget
);
2808 target
= d3dSurface
;
2813 target
= This
->d3d_target
;
2814 ERR(" (%p) : No DirectDrawSurface found to create the back buffer. Using the front buffer as back buffer. Uncertain consequences\n", This
);
2817 /* TODO: Return failure if the dimensions do not match, but this shouldn't happen */
2819 *ppSurface
= target
->WineD3DSurface
;
2820 target
->isRenderTarget
= TRUE
;
2821 TRACE("Returning wineD3DSurface %p, it belongs to surface %p\n", *ppSurface
, d3dSurface
);
2825 static HRESULT WINAPI
2826 D3D7CB_CreateDepthStencilSurface(IUnknown
*device
,
2827 IUnknown
*pSuperior
,
2830 WINED3DFORMAT Format
,
2831 WINED3DMULTISAMPLE_TYPE MultiSample
,
2832 DWORD MultisampleQuality
,
2834 IWineD3DSurface
** ppSurface
,
2835 HANDLE
* pSharedHandle
)
2837 /* Create a Depth Stencil surface to make WineD3D happy */
2838 HRESULT hr
= D3D_OK
;
2839 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, device
);
2840 DDSURFACEDESC2 ddsd
;
2842 TRACE("(%p) call back\n", device
);
2846 /* Create a DirectDraw surface */
2847 memset(&ddsd
, 0, sizeof(ddsd
));
2848 ddsd
.dwSize
= sizeof(ddsd
);
2849 ddsd
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
2850 ddsd
.dwFlags
= DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
2851 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
2852 ddsd
.dwHeight
= Height
;
2853 ddsd
.dwWidth
= Width
;
2856 PixelFormat_WineD3DtoDD(&ddsd
.u4
.ddpfPixelFormat
, Format
);
2860 ddsd
.dwFlags
^= DDSD_PIXELFORMAT
;
2863 This
->depthstencil
= TRUE
;
2864 hr
= IDirectDraw7_CreateSurface((IDirectDraw7
*) This
,
2866 (IDirectDrawSurface7
**) &This
->DepthStencilBuffer
,
2868 This
->depthstencil
= FALSE
;
2871 ERR(" (%p) Creating a DepthStencil Surface failed, result = %x\n", This
, hr
);
2874 *ppSurface
= This
->DepthStencilBuffer
->WineD3DSurface
;
2878 /*****************************************************************************
2879 * D3D7CB_CreateAdditionalSwapChain
2881 * Callback function for WineD3D which creates a new WineD3DSwapchain
2882 * interface. It also creates an IParent interface to store that pointer,
2883 * so the WineD3DSwapchain has a parent and can be released when the D3D
2884 * device is destroyed
2885 *****************************************************************************/
2886 static HRESULT WINAPI
2887 D3D7CB_CreateAdditionalSwapChain(IUnknown
*device
,
2888 WINED3DPRESENT_PARAMETERS
* pPresentationParameters
,
2889 IWineD3DSwapChain
** ppSwapChain
)
2891 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, device
);
2892 IParentImpl
*object
= NULL
;
2893 HRESULT res
= D3D_OK
;
2894 IWineD3DSwapChain
*swapchain
;
2895 TRACE("(%p) call back\n", device
);
2897 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IParentImpl
));
2900 FIXME("Allocation of memory failed\n");
2901 *ppSwapChain
= NULL
;
2902 return DDERR_OUTOFVIDEOMEMORY
;
2905 ICOM_INIT_INTERFACE(object
, IParent
, IParent_Vtbl
);
2908 res
= IWineD3DDevice_CreateAdditionalSwapChain(This
->wineD3DDevice
,
2909 pPresentationParameters
,
2911 (IUnknown
*) ICOM_INTERFACE(object
, IParent
),
2912 D3D7CB_CreateRenderTarget
,
2913 D3D7CB_CreateDepthStencilSurface
);
2916 FIXME("(%p) call to IWineD3DDevice_CreateAdditionalSwapChain failed\n", This
);
2917 HeapFree(GetProcessHeap(), 0 , object
);
2918 *ppSwapChain
= NULL
;
2922 *ppSwapChain
= swapchain
;
2923 object
->child
= (IUnknown
*) swapchain
;
2929 /*****************************************************************************
2930 * IDirectDrawImpl_AttachD3DDevice
2932 * Initializes the D3D capabilities of WineD3D
2935 * primary: The primary surface for D3D
2941 *****************************************************************************/
2942 static HRESULT WINAPI
2943 IDirectDrawImpl_AttachD3DDevice(IDirectDrawImpl
*This
,
2944 IDirectDrawSurfaceImpl
*primary
)
2949 WINED3DPRESENT_PARAMETERS localParameters
;
2951 TRACE("(%p)->(%p)\n", This
, primary
);
2953 /* Get the window */
2954 hr
= IWineD3DDevice_GetHWND(This
->wineD3DDevice
,
2958 ERR("IWineD3DDevice::GetHWND failed\n");
2962 /* If there's no window, create a hidden window. WineD3D needs it */
2965 window
= CreateWindowExA(0, This
->classname
, "Hidden D3D Window",
2967 GetSystemMetrics(SM_CXSCREEN
),
2968 GetSystemMetrics(SM_CYSCREEN
),
2969 NULL
, NULL
, GetModuleHandleA(0), NULL
);
2971 ShowWindow(window
, SW_HIDE
); /* Just to be sure */
2972 WARN("(%p) No window for the Direct3DDevice, created a hidden window. HWND=%p\n", This
, window
);
2973 This
->d3d_window
= window
;
2977 TRACE("(%p) Using existing window %p for Direct3D rendering\n", This
, window
);
2980 /* Store the future Render Target surface */
2981 This
->d3d_target
= primary
;
2983 /* Use the surface description for the device parameters, not the
2984 * Device settings. The app might render to an offscreen surface
2986 localParameters
.BackBufferWidth
= primary
->surface_desc
.dwWidth
;
2987 localParameters
.BackBufferHeight
= primary
->surface_desc
.dwHeight
;
2988 localParameters
.BackBufferFormat
= PixelFormat_DD2WineD3D(&primary
->surface_desc
.u4
.ddpfPixelFormat
);
2989 localParameters
.BackBufferCount
= (primary
->surface_desc
.dwFlags
& DDSD_BACKBUFFERCOUNT
) ? primary
->surface_desc
.dwBackBufferCount
: 0;
2990 localParameters
.MultiSampleType
= WINED3DMULTISAMPLE_NONE
;
2991 localParameters
.MultiSampleQuality
= 0;
2992 localParameters
.SwapEffect
= WINED3DSWAPEFFECT_COPY
;
2993 localParameters
.hDeviceWindow
= window
;
2994 localParameters
.Windowed
= !(This
->cooperative_level
& DDSCL_FULLSCREEN
);
2995 localParameters
.EnableAutoDepthStencil
= FALSE
;
2996 localParameters
.AutoDepthStencilFormat
= WINED3DFMT_D16
;
2997 localParameters
.Flags
= 0;
2998 localParameters
.FullScreen_RefreshRateInHz
= WINED3DPRESENT_RATE_DEFAULT
; /* Default rate: It's already set */
2999 localParameters
.PresentationInterval
= WINED3DPRESENT_INTERVAL_DEFAULT
;
3001 TRACE("Passing mode %d\n", localParameters
.BackBufferFormat
);
3003 /* Set this NOW, otherwise creating the depth stencil surface will cause a
3004 * recursive loop until ram or emulated video memory is full
3006 This
->d3d_initialized
= TRUE
;
3008 hr
= IWineD3DDevice_Init3D(This
->wineD3DDevice
,
3010 D3D7CB_CreateAdditionalSwapChain
);
3013 This
->wineD3DDevice
= NULL
;
3017 /* Create an Index Buffer parent */
3018 TRACE("(%p) Successfully initialized 3D\n", This
);
3022 /*****************************************************************************
3023 * DirectDrawCreateClipper (DDRAW.@)
3025 * Creates a new IDirectDrawClipper object.
3028 * Clipper: Address to write the interface pointer to
3029 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3033 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3034 * E_OUTOFMEMORY if allocating the object failed
3036 *****************************************************************************/
3038 DirectDrawCreateClipper(DWORD Flags
,
3039 IDirectDrawClipper
**Clipper
,
3042 IDirectDrawClipperImpl
* object
;
3043 TRACE("(%08x,%p,%p)\n", Flags
, Clipper
, UnkOuter
);
3045 if (UnkOuter
!= NULL
) return CLASS_E_NOAGGREGATION
;
3047 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
3048 sizeof(IDirectDrawClipperImpl
));
3049 if (object
== NULL
) return E_OUTOFMEMORY
;
3051 ICOM_INIT_INTERFACE(object
, IDirectDrawClipper
, IDirectDrawClipper_Vtbl
);
3053 object
->wineD3DClipper
= pWineDirect3DCreateClipper((IUnknown
*) object
);
3054 if(!object
->wineD3DClipper
)
3056 HeapFree(GetProcessHeap(), 0, object
);
3057 return E_OUTOFMEMORY
;
3060 *Clipper
= (IDirectDrawClipper
*) object
;
3064 /*****************************************************************************
3065 * IDirectDraw7::CreateClipper
3067 * Creates a DDraw clipper. See DirectDrawCreateClipper for details
3069 *****************************************************************************/
3070 static HRESULT WINAPI
3071 IDirectDrawImpl_CreateClipper(IDirectDraw7
*iface
,
3073 IDirectDrawClipper
**Clipper
,
3076 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
3077 TRACE("(%p)->(%x,%p,%p)\n", This
, Flags
, Clipper
, UnkOuter
);
3078 return DirectDrawCreateClipper(Flags
, Clipper
, UnkOuter
);
3081 /*****************************************************************************
3082 * IDirectDraw7::CreatePalette
3084 * Creates a new IDirectDrawPalette object
3087 * Flags: The flags for the new clipper
3088 * ColorTable: Color table to assign to the new clipper
3089 * Palette: Address to write the interface pointer to
3090 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3094 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3095 * E_OUTOFMEMORY if allocating the object failed
3097 *****************************************************************************/
3098 static HRESULT WINAPI
3099 IDirectDrawImpl_CreatePalette(IDirectDraw7
*iface
,
3101 PALETTEENTRY
*ColorTable
,
3102 IDirectDrawPalette
**Palette
,
3103 IUnknown
*pUnkOuter
)
3105 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
3106 IDirectDrawPaletteImpl
*object
;
3107 HRESULT hr
= DDERR_GENERIC
;
3108 TRACE("(%p)->(%x,%p,%p,%p)\n", This
, Flags
, ColorTable
, Palette
, pUnkOuter
);
3110 if(pUnkOuter
!= NULL
)
3112 WARN("pUnkOuter is %p, returning CLASS_E_NOAGGREGATION\n", pUnkOuter
);
3113 return CLASS_E_NOAGGREGATION
;
3116 /* The refcount test shows that a cooplevel is required for this */
3117 if(!This
->cooperative_level
)
3119 WARN("No cooperative level set, returning DDERR_NOCOOPERATIVELEVELSET\n");
3120 return DDERR_NOCOOPERATIVELEVELSET
;
3123 object
= HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawPaletteImpl
));
3126 ERR("Out of memory when allocating memory for a palette implementation\n");
3127 return E_OUTOFMEMORY
;
3130 ICOM_INIT_INTERFACE(object
, IDirectDrawPalette
, IDirectDrawPalette_Vtbl
);
3132 object
->ddraw_owner
= This
;
3134 hr
= IWineD3DDevice_CreatePalette(This
->wineD3DDevice
, Flags
, ColorTable
, &object
->wineD3DPalette
, (IUnknown
*) ICOM_INTERFACE(object
, IDirectDrawPalette
) );
3137 HeapFree(GetProcessHeap(), 0, object
);
3141 IDirectDraw7_AddRef(iface
);
3142 object
->ifaceToRelease
= (IUnknown
*) iface
;
3143 *Palette
= ICOM_INTERFACE(object
, IDirectDrawPalette
);
3147 /*****************************************************************************
3148 * IDirectDraw7::DuplicateSurface
3150 * Duplicates a surface. The surface memory points to the same memory as
3151 * the original surface, and it's released when the last surface referencing
3152 * it is released. I guess that's beyond Wine's surface management right now
3153 * (Idea: create a new DDraw surface with the same WineD3DSurface. I need a
3154 * test application to implement this)
3157 * Src: Address of the source surface
3158 * Dest: Address to write the new surface pointer to
3161 * See IDirectDraw7::CreateSurface
3163 *****************************************************************************/
3164 static HRESULT WINAPI
3165 IDirectDrawImpl_DuplicateSurface(IDirectDraw7
*iface
,
3166 IDirectDrawSurface7
*Src
,
3167 IDirectDrawSurface7
**Dest
)
3169 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
3170 IDirectDrawSurfaceImpl
*Surf
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, Src
);
3172 FIXME("(%p)->(%p,%p)\n", This
, Surf
, Dest
);
3174 /* For now, simply create a new, independent surface */
3175 return IDirectDraw7_CreateSurface(iface
,
3176 &Surf
->surface_desc
,
3181 /*****************************************************************************
3182 * IDirectDraw7 VTable
3183 *****************************************************************************/
3184 const IDirectDraw7Vtbl IDirectDraw7_Vtbl
=
3187 IDirectDrawImpl_QueryInterface
,
3188 IDirectDrawImpl_AddRef
,
3189 IDirectDrawImpl_Release
,
3190 /*** IDirectDraw ***/
3191 IDirectDrawImpl_Compact
,
3192 IDirectDrawImpl_CreateClipper
,
3193 IDirectDrawImpl_CreatePalette
,
3194 IDirectDrawImpl_CreateSurface
,
3195 IDirectDrawImpl_DuplicateSurface
,
3196 IDirectDrawImpl_EnumDisplayModes
,
3197 IDirectDrawImpl_EnumSurfaces
,
3198 IDirectDrawImpl_FlipToGDISurface
,
3199 IDirectDrawImpl_GetCaps
,
3200 IDirectDrawImpl_GetDisplayMode
,
3201 IDirectDrawImpl_GetFourCCCodes
,
3202 IDirectDrawImpl_GetGDISurface
,
3203 IDirectDrawImpl_GetMonitorFrequency
,
3204 IDirectDrawImpl_GetScanLine
,
3205 IDirectDrawImpl_GetVerticalBlankStatus
,
3206 IDirectDrawImpl_Initialize
,
3207 IDirectDrawImpl_RestoreDisplayMode
,
3208 IDirectDrawImpl_SetCooperativeLevel
,
3209 IDirectDrawImpl_SetDisplayMode
,
3210 IDirectDrawImpl_WaitForVerticalBlank
,
3211 /*** IDirectDraw2 ***/
3212 IDirectDrawImpl_GetAvailableVidMem
,
3213 /*** IDirectDraw7 ***/
3214 IDirectDrawImpl_GetSurfaceFromDC
,
3215 IDirectDrawImpl_RestoreAllSurfaces
,
3216 IDirectDrawImpl_TestCooperativeLevel
,
3217 IDirectDrawImpl_GetDeviceIdentifier
,
3218 /*** IDirectDraw7 ***/
3219 IDirectDrawImpl_StartModeTest
,
3220 IDirectDrawImpl_EvaluateMode
3223 /*****************************************************************************
3224 * IDirectDrawImpl_FindDecl
3226 * Finds the WineD3D vertex declaration for a specific fvf, and creates one
3227 * if none was found.
3229 * This function is in ddraw.c and the DDraw object space because D3D7
3230 * vertex buffers are created using the IDirect3D interface to the ddraw
3231 * object, so they can be valid across D3D devices(theoretically. The ddraw
3232 * object also owns the wined3d device
3236 * fvf: Fvf to find the decl for
3239 * NULL in case of an error, the IWineD3DVertexDeclaration interface for the
3242 *****************************************************************************/
3243 IWineD3DVertexDeclaration
*
3244 IDirectDrawImpl_FindDecl(IDirectDrawImpl
*This
,
3248 IWineD3DVertexDeclaration
* pDecl
= NULL
;
3249 int p
, low
, high
; /* deliberately signed */
3250 struct FvfToDecl
*convertedDecls
= This
->decls
;
3252 TRACE("Searching for declaration for fvf %08x... ", fvf
);
3255 high
= This
->numConvertedDecls
- 1;
3256 while(low
<= high
) {
3257 p
= (low
+ high
) >> 1;
3259 if(convertedDecls
[p
].fvf
== fvf
) {
3260 TRACE("found %p\n", convertedDecls
[p
].decl
);
3261 return convertedDecls
[p
].decl
;
3262 } else if(convertedDecls
[p
].fvf
< fvf
) {
3268 TRACE("not found. Creating and inserting at position %d.\n", low
);
3270 hr
= IWineD3DDevice_CreateVertexDeclarationFromFVF(This
->wineD3DDevice
,
3272 (IUnknown
*) ICOM_INTERFACE(This
, IDirectDraw7
),
3274 if (hr
!= S_OK
) return NULL
;
3276 if(This
->declArraySize
== This
->numConvertedDecls
) {
3277 int grow
= max(This
->declArraySize
/ 2, 8);
3278 convertedDecls
= HeapReAlloc(GetProcessHeap(), 0, convertedDecls
,
3279 sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
+ grow
));
3280 if(!convertedDecls
) {
3281 /* This will destroy it */
3282 IWineD3DVertexDeclaration_Release(pDecl
);
3285 This
->decls
= convertedDecls
;
3286 This
->declArraySize
+= grow
;
3289 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
, sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
- low
));
3290 convertedDecls
[low
].decl
= pDecl
;
3291 convertedDecls
[low
].fvf
= fvf
;
3292 This
->numConvertedDecls
++;
3294 TRACE("Returning %p. %d decls in array\n", pDecl
, This
->numConvertedDecls
);