ddraw: Version 1 devices are aggregated by the surface that created them.
[wine/multimedia.git] / dlls / ddraw / surface.c
blob2475522f91aac01d83818b4d1869d5fb81549474
1 /* DirectDraw Surface Implementation
3 * Copyright (c) 1997-2000 Marcus Meissner
4 * Copyright (c) 1998-2000 Lionel Ulmer
5 * Copyright (c) 2000-2001 TransGaming Technologies Inc.
6 * Copyright (c) 2006 Stefan Dösinger
7 * Copyright (c) 2011 Ričardas Barkauskas for CodeWeavers
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "config.h"
25 #include "wine/port.h"
27 #include "ddraw_private.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
31 static struct ddraw_surface *unsafe_impl_from_IDirectDrawSurface2(IDirectDrawSurface2 *iface);
32 static struct ddraw_surface *unsafe_impl_from_IDirectDrawSurface3(IDirectDrawSurface3 *iface);
34 static inline struct ddraw_surface *impl_from_IDirectDrawGammaControl(IDirectDrawGammaControl *iface)
36 return CONTAINING_RECORD(iface, struct ddraw_surface, IDirectDrawGammaControl_iface);
39 /* This is slow, of course. Also, in case of locks, we can't prevent other
40 * applications from drawing to the screen while we've locked the frontbuffer.
41 * We'd like to do this in wined3d instead, but for that to work wined3d needs
42 * to support windowless rendering first. */
43 static HRESULT ddraw_surface_update_frontbuffer(struct ddraw_surface *surface, const RECT *rect, BOOL read)
45 HDC surface_dc, screen_dc;
46 int x, y, w, h;
47 HRESULT hr;
48 BOOL ret;
50 if (!rect)
52 x = 0;
53 y = 0;
54 w = surface->surface_desc.dwWidth;
55 h = surface->surface_desc.dwHeight;
57 else
59 x = rect->left;
60 y = rect->top;
61 w = rect->right - rect->left;
62 h = rect->bottom - rect->top;
65 if (w <= 0 || h <= 0)
66 return DD_OK;
68 if (surface->ddraw->swapchain_window)
70 /* Nothing to do, we control the frontbuffer, or at least the parts we
71 * care about. */
72 if (read)
73 return DD_OK;
75 return wined3d_surface_blt(surface->ddraw->wined3d_frontbuffer, rect,
76 surface->wined3d_surface, rect, 0, NULL, WINED3D_TEXF_POINT);
79 if (FAILED(hr = wined3d_surface_getdc(surface->wined3d_surface, &surface_dc)))
81 ERR("Failed to get surface DC, hr %#x.\n", hr);
82 return hr;
85 if (!(screen_dc = GetDC(NULL)))
87 wined3d_surface_releasedc(surface->wined3d_surface, surface_dc);
88 ERR("Failed to get screen DC.\n");
89 return E_FAIL;
92 if (read)
93 ret = BitBlt(surface_dc, x, y, w, h,
94 screen_dc, x, y, SRCCOPY);
95 else
96 ret = BitBlt(screen_dc, x, y, w, h,
97 surface_dc, x, y, SRCCOPY);
99 ReleaseDC(NULL, screen_dc);
100 wined3d_surface_releasedc(surface->wined3d_surface, surface_dc);
102 if (!ret)
104 ERR("Failed to blit to/from screen.\n");
105 return E_FAIL;
108 return DD_OK;
111 /*****************************************************************************
112 * IUnknown parts follow
113 *****************************************************************************/
115 /*****************************************************************************
116 * IDirectDrawSurface7::QueryInterface
118 * A normal QueryInterface implementation. For QueryInterface rules
119 * see ddraw.c, IDirectDraw7::QueryInterface. This method
120 * can Query IDirectDrawSurface interfaces in all version, IDirect3DTexture
121 * in all versions, the IDirectDrawGammaControl interface and it can
122 * create an IDirect3DDevice. (Uses IDirect3D7::CreateDevice)
124 * Params:
125 * riid: The interface id queried for
126 * obj: Address to write the pointer to
128 * Returns:
129 * S_OK on success
130 * E_NOINTERFACE if the requested interface wasn't found
132 *****************************************************************************/
133 static HRESULT WINAPI ddraw_surface7_QueryInterface(IDirectDrawSurface7 *iface, REFIID riid, void **obj)
135 struct ddraw_surface *This = impl_from_IDirectDrawSurface7(iface);
137 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), obj);
139 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
140 *obj = NULL;
142 if(!riid)
143 return DDERR_INVALIDPARAMS;
145 if (IsEqualGUID(riid, &IID_IDirectDrawSurface7))
147 IDirectDrawSurface7_AddRef(iface);
148 *obj = iface;
149 TRACE("(%p) returning IDirectDrawSurface7 interface at %p\n", This, *obj);
150 return S_OK;
153 if (IsEqualGUID(riid, &IID_IDirectDrawSurface4))
155 IDirectDrawSurface4_AddRef(&This->IDirectDrawSurface4_iface);
156 *obj = &This->IDirectDrawSurface4_iface;
157 TRACE("(%p) returning IDirectDrawSurface4 interface at %p\n", This, *obj);
158 return S_OK;
161 if (IsEqualGUID(riid, &IID_IDirectDrawSurface3))
163 IDirectDrawSurface3_AddRef(&This->IDirectDrawSurface3_iface);
164 *obj = &This->IDirectDrawSurface3_iface;
165 TRACE("(%p) returning IDirectDrawSurface3 interface at %p\n", This, *obj);
166 return S_OK;
169 if (IsEqualGUID(riid, &IID_IDirectDrawSurface2))
171 IDirectDrawSurface2_AddRef(&This->IDirectDrawSurface2_iface);
172 *obj = &This->IDirectDrawSurface2_iface;
173 TRACE("(%p) returning IDirectDrawSurface2 interface at %p\n", This, *obj);
174 return S_OK;
177 if (IsEqualGUID(riid, &IID_IDirectDrawSurface)
178 || IsEqualGUID(riid, &IID_IUnknown))
180 IDirectDrawSurface_AddRef(&This->IDirectDrawSurface_iface);
181 *obj = &This->IDirectDrawSurface_iface;
182 TRACE("(%p) returning IDirectDrawSurface interface at %p\n", This, *obj);
183 return S_OK;
186 if (IsEqualGUID(riid, &IID_IDirectDrawGammaControl))
188 IDirectDrawGammaControl_AddRef(&This->IDirectDrawGammaControl_iface);
189 *obj = &This->IDirectDrawGammaControl_iface;
190 TRACE("(%p) returning IDirectDrawGammaControl interface at %p\n", This, *obj);
191 return S_OK;
194 if (IsEqualGUID(riid, &IID_IDirectDrawColorControl))
196 WARN("Color control not implemented.\n");
197 *obj = NULL;
198 return E_NOINTERFACE;
201 if (This->version != 7)
203 if (IsEqualGUID(riid, &IID_D3DDEVICE_WineD3D)
204 || IsEqualGUID(riid, &IID_IDirect3DHALDevice)
205 || IsEqualGUID(riid, &IID_IDirect3DRGBDevice))
207 wined3d_mutex_lock();
208 if (!This->device1)
210 HRESULT hr = d3d_device_create(This->ddraw, This, 1, &This->device1,
211 (IUnknown *)&This->IDirectDrawSurface_iface);
212 if (FAILED(hr))
214 This->device1 = NULL;
215 wined3d_mutex_unlock();
216 WARN("Failed to create device, hr %#x.\n", hr);
217 return hr;
220 wined3d_mutex_unlock();
222 IDirect3DDevice_AddRef(&This->device1->IDirect3DDevice_iface);
223 *obj = &This->device1->IDirect3DDevice_iface;
224 return S_OK;
227 if (IsEqualGUID(&IID_IDirect3DTexture2, riid))
229 IDirect3DTexture2_AddRef(&This->IDirect3DTexture2_iface);
230 *obj = &This->IDirect3DTexture2_iface;
231 return S_OK;
234 if (IsEqualGUID( &IID_IDirect3DTexture, riid ))
236 IDirect3DTexture2_AddRef(&This->IDirect3DTexture_iface);
237 *obj = &This->IDirect3DTexture_iface;
238 return S_OK;
242 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
244 if (This->version != 7)
245 return E_INVALIDARG;
247 return E_NOINTERFACE;
250 static HRESULT WINAPI ddraw_surface4_QueryInterface(IDirectDrawSurface4 *iface, REFIID riid, void **object)
252 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
254 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
256 return ddraw_surface7_QueryInterface(&surface->IDirectDrawSurface7_iface, riid, object);
259 static HRESULT WINAPI ddraw_surface3_QueryInterface(IDirectDrawSurface3 *iface, REFIID riid, void **object)
261 struct ddraw_surface *surface = impl_from_IDirectDrawSurface3(iface);
263 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
265 return ddraw_surface7_QueryInterface(&surface->IDirectDrawSurface7_iface, riid, object);
268 static HRESULT WINAPI ddraw_surface2_QueryInterface(IDirectDrawSurface2 *iface, REFIID riid, void **object)
270 struct ddraw_surface *surface = impl_from_IDirectDrawSurface2(iface);
272 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
274 return ddraw_surface7_QueryInterface(&surface->IDirectDrawSurface7_iface, riid, object);
277 static HRESULT WINAPI ddraw_surface1_QueryInterface(IDirectDrawSurface *iface, REFIID riid, void **object)
279 struct ddraw_surface *surface = impl_from_IDirectDrawSurface(iface);
281 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
283 return ddraw_surface7_QueryInterface(&surface->IDirectDrawSurface7_iface, riid, object);
286 static HRESULT WINAPI ddraw_gamma_control_QueryInterface(IDirectDrawGammaControl *iface,
287 REFIID riid, void **object)
289 struct ddraw_surface *surface = impl_from_IDirectDrawGammaControl(iface);
291 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
293 return ddraw_surface7_QueryInterface(&surface->IDirectDrawSurface7_iface, riid, object);
296 static HRESULT WINAPI d3d_texture2_QueryInterface(IDirect3DTexture2 *iface, REFIID riid, void **object)
298 struct ddraw_surface *surface = impl_from_IDirect3DTexture2(iface);
300 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
302 return ddraw_surface7_QueryInterface(&surface->IDirectDrawSurface7_iface, riid, object);
305 static HRESULT WINAPI d3d_texture1_QueryInterface(IDirect3DTexture *iface, REFIID riid, void **object)
307 struct ddraw_surface *surface = impl_from_IDirect3DTexture(iface);
309 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
311 return ddraw_surface7_QueryInterface(&surface->IDirectDrawSurface7_iface, riid, object);
314 static void ddraw_surface_add_iface(struct ddraw_surface *This)
316 ULONG iface_count = InterlockedIncrement(&This->iface_count);
317 TRACE("%p increasing iface count to %u.\n", This, iface_count);
319 if (iface_count == 1)
321 wined3d_mutex_lock();
322 if (This->wined3d_surface)
323 wined3d_surface_incref(This->wined3d_surface);
324 if (This->wined3d_texture)
325 wined3d_texture_incref(This->wined3d_texture);
326 wined3d_mutex_unlock();
330 /*****************************************************************************
331 * IDirectDrawSurface7::AddRef
333 * A normal addref implementation
335 * Returns:
336 * The new refcount
338 *****************************************************************************/
339 static ULONG WINAPI ddraw_surface7_AddRef(IDirectDrawSurface7 *iface)
341 struct ddraw_surface *This = impl_from_IDirectDrawSurface7(iface);
342 ULONG refcount = InterlockedIncrement(&This->ref7);
344 TRACE("iface %p increasing refcount to %u.\n", iface, refcount);
346 if (refcount == 1)
348 ddraw_surface_add_iface(This);
351 return refcount;
354 static ULONG WINAPI ddraw_surface4_AddRef(IDirectDrawSurface4 *iface)
356 struct ddraw_surface *This = impl_from_IDirectDrawSurface4(iface);
357 ULONG refcount = InterlockedIncrement(&This->ref4);
359 TRACE("iface %p increasing refcount to %u.\n", iface, refcount);
361 if (refcount == 1)
363 ddraw_surface_add_iface(This);
366 return refcount;
369 static ULONG WINAPI ddraw_surface3_AddRef(IDirectDrawSurface3 *iface)
371 struct ddraw_surface *This = impl_from_IDirectDrawSurface3(iface);
372 ULONG refcount = InterlockedIncrement(&This->ref3);
374 TRACE("iface %p increasing refcount to %u.\n", iface, refcount);
376 if (refcount == 1)
378 ddraw_surface_add_iface(This);
381 return refcount;
384 static ULONG WINAPI ddraw_surface2_AddRef(IDirectDrawSurface2 *iface)
386 struct ddraw_surface *This = impl_from_IDirectDrawSurface2(iface);
387 ULONG refcount = InterlockedIncrement(&This->ref2);
389 TRACE("iface %p increasing refcount to %u.\n", iface, refcount);
391 if (refcount == 1)
393 ddraw_surface_add_iface(This);
396 return refcount;
399 static ULONG WINAPI ddraw_surface1_AddRef(IDirectDrawSurface *iface)
401 struct ddraw_surface *This = impl_from_IDirectDrawSurface(iface);
402 ULONG refcount = InterlockedIncrement(&This->ref1);
404 TRACE("iface %p increasing refcount to %u.\n", iface, refcount);
406 if (refcount == 1)
408 ddraw_surface_add_iface(This);
411 return refcount;
414 static ULONG WINAPI ddraw_gamma_control_AddRef(IDirectDrawGammaControl *iface)
416 struct ddraw_surface *This = impl_from_IDirectDrawGammaControl(iface);
417 ULONG refcount = InterlockedIncrement(&This->gamma_count);
419 TRACE("iface %p increasing refcount to %u.\n", iface, refcount);
421 if (refcount == 1)
423 ddraw_surface_add_iface(This);
426 return refcount;
429 static ULONG WINAPI d3d_texture2_AddRef(IDirect3DTexture2 *iface)
431 struct ddraw_surface *surface = impl_from_IDirect3DTexture2(iface);
433 TRACE("iface %p.\n", iface);
435 return IUnknown_AddRef(surface->texture_outer);
438 static ULONG WINAPI d3d_texture1_AddRef(IDirect3DTexture *iface)
440 struct ddraw_surface *surface = impl_from_IDirect3DTexture(iface);
442 TRACE("iface %p.\n", iface);
444 return IUnknown_AddRef(surface->texture_outer);
447 /*****************************************************************************
448 * ddraw_surface_destroy
450 * A helper function for IDirectDrawSurface7::Release
452 * Frees the surface, regardless of its refcount.
453 * See IDirectDrawSurface7::Release for more information
455 * Params:
456 * This: Surface to free
458 *****************************************************************************/
459 static void ddraw_surface_destroy(struct ddraw_surface *This)
461 TRACE("surface %p.\n", This);
463 /* Check the iface count and give a warning */
464 if(This->iface_count > 1)
466 /* This can happen when a complex surface is destroyed,
467 * because the 2nd surface was addref()ed when the app
468 * called GetAttachedSurface
470 WARN("(%p): Destroying surface with refcounts 7: %d 4: %d 3: %d 2: %d 1: %d\n",
471 This, This->ref7, This->ref4, This->ref3, This->ref2, This->ref1);
474 if (This->wined3d_surface)
475 wined3d_surface_decref(This->wined3d_surface);
478 static void ddraw_surface_cleanup(struct ddraw_surface *surface)
480 struct ddraw_surface *surf;
481 IUnknown *ifaceToRelease;
482 UINT i;
484 TRACE("surface %p.\n", surface);
486 /* The refcount test shows that the palette is detached when the surface
487 * is destroyed. */
488 IDirectDrawSurface7_SetPalette(&surface->IDirectDrawSurface7_iface, NULL);
490 /* Loop through all complex attached surfaces and destroy them.
492 * Yet again, only the root can have more than one complexly attached
493 * surface, all the others have a total of one. */
494 for (i = 0; i < MAX_COMPLEX_ATTACHED; ++i)
496 if (!surface->complex_array[i])
497 break;
499 surf = surface->complex_array[i];
500 surface->complex_array[i] = NULL;
501 while (surf)
503 struct ddraw_surface *destroy = surf;
504 surf = surf->complex_array[0]; /* Iterate through the "tree" */
505 ddraw_surface_destroy(destroy); /* Destroy it */
509 if (surface->device1)
510 IUnknown_Release(&surface->device1->IUnknown_inner);
511 ifaceToRelease = surface->ifaceToRelease;
513 /* Destroy the root surface. */
514 ddraw_surface_destroy(surface);
516 /* Reduce the ddraw refcount */
517 if (ifaceToRelease)
518 IUnknown_Release(ifaceToRelease);
521 ULONG ddraw_surface_release_iface(struct ddraw_surface *This)
523 ULONG iface_count = InterlockedDecrement(&This->iface_count);
524 TRACE("%p decreasing iface count to %u.\n", This, iface_count);
526 if (iface_count == 0)
528 /* Complex attached surfaces are destroyed implicitly when the root is released */
529 wined3d_mutex_lock();
530 if(!This->is_complex_root)
532 WARN("(%p) Attempt to destroy a surface that is not a complex root\n", This);
533 wined3d_mutex_unlock();
534 return iface_count;
536 if (This->wined3d_texture) /* If it's a texture, destroy the wined3d texture. */
537 wined3d_texture_decref(This->wined3d_texture);
538 else
539 ddraw_surface_cleanup(This);
540 wined3d_mutex_unlock();
543 return iface_count;
546 /*****************************************************************************
547 * IDirectDrawSurface7::Release
549 * Reduces the surface's refcount by 1. If the refcount falls to 0, the
550 * surface is destroyed.
552 * Destroying the surface is a bit tricky. For the connection between
553 * WineD3DSurfaces and DirectDrawSurfaces see IDirectDraw7::CreateSurface
554 * It has a nice graph explaining the connection.
556 * What happens here is basically this:
557 * When a surface is destroyed, its WineD3DSurface is released,
558 * and the refcount of the DirectDraw interface is reduced by 1. If it has
559 * complex surfaces attached to it, then these surfaces are destroyed too,
560 * regardless of their refcount. If any surface being destroyed has another
561 * surface attached to it (with a "soft" attachment, not complex), then
562 * this surface is detached with DeleteAttachedSurface.
564 * When the surface is a texture, the WineD3DTexture is released.
565 * If the surface is the Direct3D render target, then the D3D
566 * capabilities of the WineD3DDevice are uninitialized, which causes the
567 * swapchain to be released.
569 * When a complex sublevel falls to ref zero, then this is ignored.
571 * Returns:
572 * The new refcount
574 *****************************************************************************/
575 static ULONG WINAPI ddraw_surface7_Release(IDirectDrawSurface7 *iface)
577 struct ddraw_surface *This = impl_from_IDirectDrawSurface7(iface);
578 ULONG refcount = InterlockedDecrement(&This->ref7);
580 TRACE("iface %p decreasing refcount to %u.\n", iface, refcount);
582 if (refcount == 0)
584 ddraw_surface_release_iface(This);
587 return refcount;
590 static ULONG WINAPI ddraw_surface4_Release(IDirectDrawSurface4 *iface)
592 struct ddraw_surface *This = impl_from_IDirectDrawSurface4(iface);
593 ULONG refcount = InterlockedDecrement(&This->ref4);
595 TRACE("iface %p decreasing refcount to %u.\n", iface, refcount);
597 if (refcount == 0)
599 ddraw_surface_release_iface(This);
602 return refcount;
605 static ULONG WINAPI ddraw_surface3_Release(IDirectDrawSurface3 *iface)
607 struct ddraw_surface *This = impl_from_IDirectDrawSurface3(iface);
608 ULONG refcount = InterlockedDecrement(&This->ref3);
610 TRACE("iface %p decreasing refcount to %u.\n", iface, refcount);
612 if (refcount == 0)
614 ddraw_surface_release_iface(This);
617 return refcount;
620 static ULONG WINAPI ddraw_surface2_Release(IDirectDrawSurface2 *iface)
622 struct ddraw_surface *This = impl_from_IDirectDrawSurface2(iface);
623 ULONG refcount = InterlockedDecrement(&This->ref2);
625 TRACE("iface %p decreasing refcount to %u.\n", iface, refcount);
627 if (refcount == 0)
629 ddraw_surface_release_iface(This);
632 return refcount;
635 static ULONG WINAPI ddraw_surface1_Release(IDirectDrawSurface *iface)
637 struct ddraw_surface *This = impl_from_IDirectDrawSurface(iface);
638 ULONG refcount = InterlockedDecrement(&This->ref1);
640 TRACE("iface %p decreasing refcount to %u.\n", iface, refcount);
642 if (refcount == 0)
644 ddraw_surface_release_iface(This);
647 return refcount;
650 static ULONG WINAPI ddraw_gamma_control_Release(IDirectDrawGammaControl *iface)
652 struct ddraw_surface *This = impl_from_IDirectDrawGammaControl(iface);
653 ULONG refcount = InterlockedDecrement(&This->gamma_count);
655 TRACE("iface %p decreasing refcount to %u.\n", iface, refcount);
657 if (refcount == 0)
659 ddraw_surface_release_iface(This);
662 return refcount;
665 static ULONG WINAPI d3d_texture2_Release(IDirect3DTexture2 *iface)
667 struct ddraw_surface *surface = impl_from_IDirect3DTexture2(iface);
669 TRACE("iface %p.\n", iface);
671 return IUnknown_Release(surface->texture_outer);
674 static ULONG WINAPI d3d_texture1_Release(IDirect3DTexture *iface)
676 struct ddraw_surface *surface = impl_from_IDirect3DTexture(iface);
678 TRACE("iface %p.\n", iface);
680 return IUnknown_Release(surface->texture_outer);
683 /*****************************************************************************
684 * IDirectDrawSurface7::GetAttachedSurface
686 * Returns an attached surface with the requested caps. Surface attachment
687 * and complex surfaces are not clearly described by the MSDN or sdk,
688 * so this method is tricky and likely to contain problems.
689 * This implementation searches the complex list first, then the
690 * attachment chain.
692 * The chains are searched from This down to the last surface in the chain,
693 * not from the first element in the chain. The first surface found is
694 * returned. The MSDN says that this method fails if more than one surface
695 * matches the caps, but it is not sure if that is right. The attachment
696 * structure may not even allow two matching surfaces.
698 * The found surface is AddRef-ed before it is returned.
700 * Params:
701 * Caps: Pointer to a DDCAPS2 structure describing the caps asked for
702 * Surface: Address to store the found surface
704 * Returns:
705 * DD_OK on success
706 * DDERR_INVALIDPARAMS if Caps or Surface is NULL
707 * DDERR_NOTFOUND if no surface was found
709 *****************************************************************************/
710 static HRESULT WINAPI ddraw_surface7_GetAttachedSurface(IDirectDrawSurface7 *iface,
711 DDSCAPS2 *Caps, IDirectDrawSurface7 **Surface)
713 struct ddraw_surface *This = impl_from_IDirectDrawSurface7(iface);
714 struct ddraw_surface *surf;
715 DDSCAPS2 our_caps;
716 int i;
718 TRACE("iface %p, caps %p, attachment %p.\n", iface, Caps, Surface);
720 wined3d_mutex_lock();
722 if(This->version < 7)
724 /* Earlier dx apps put garbage into these members, clear them */
725 our_caps.dwCaps = Caps->dwCaps;
726 our_caps.dwCaps2 = 0;
727 our_caps.dwCaps3 = 0;
728 our_caps.dwCaps4 = 0;
730 else
732 our_caps = *Caps;
735 TRACE("(%p): Looking for caps: %x,%x,%x,%x\n", This, our_caps.dwCaps, our_caps.dwCaps2, our_caps.dwCaps3, our_caps.dwCaps4); /* FIXME: Better debugging */
737 for(i = 0; i < MAX_COMPLEX_ATTACHED; i++)
739 surf = This->complex_array[i];
740 if(!surf) break;
742 if (TRACE_ON(ddraw))
744 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf,
745 surf->surface_desc.ddsCaps.dwCaps,
746 surf->surface_desc.ddsCaps.dwCaps2,
747 surf->surface_desc.ddsCaps.dwCaps3,
748 surf->surface_desc.ddsCaps.dwCaps4);
751 if (((surf->surface_desc.ddsCaps.dwCaps & our_caps.dwCaps) == our_caps.dwCaps) &&
752 ((surf->surface_desc.ddsCaps.dwCaps2 & our_caps.dwCaps2) == our_caps.dwCaps2)) {
754 /* MSDN: "This method fails if more than one surface is attached
755 * that matches the capabilities requested."
757 * Not sure how to test this.
760 TRACE("(%p): Returning surface %p\n", This, surf);
761 TRACE("(%p): mipmapcount=%d\n", This, surf->mipmap_level);
762 *Surface = &surf->IDirectDrawSurface7_iface;
763 ddraw_surface7_AddRef(*Surface);
764 wined3d_mutex_unlock();
766 return DD_OK;
770 /* Next, look at the attachment chain */
771 surf = This;
773 while( (surf = surf->next_attached) )
775 if (TRACE_ON(ddraw))
777 TRACE("Surface: (%p) caps: %x,%x,%x,%x\n", surf,
778 surf->surface_desc.ddsCaps.dwCaps,
779 surf->surface_desc.ddsCaps.dwCaps2,
780 surf->surface_desc.ddsCaps.dwCaps3,
781 surf->surface_desc.ddsCaps.dwCaps4);
784 if (((surf->surface_desc.ddsCaps.dwCaps & our_caps.dwCaps) == our_caps.dwCaps) &&
785 ((surf->surface_desc.ddsCaps.dwCaps2 & our_caps.dwCaps2) == our_caps.dwCaps2)) {
787 TRACE("(%p): Returning surface %p\n", This, surf);
788 *Surface = &surf->IDirectDrawSurface7_iface;
789 ddraw_surface7_AddRef(*Surface);
790 wined3d_mutex_unlock();
791 return DD_OK;
795 TRACE("(%p) Didn't find a valid surface\n", This);
797 wined3d_mutex_unlock();
799 *Surface = NULL;
800 return DDERR_NOTFOUND;
803 static HRESULT WINAPI ddraw_surface4_GetAttachedSurface(IDirectDrawSurface4 *iface,
804 DDSCAPS2 *caps, IDirectDrawSurface4 **attachment)
806 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
807 struct ddraw_surface *attachment_impl;
808 IDirectDrawSurface7 *attachment7;
809 HRESULT hr;
811 TRACE("iface %p, caps %p, attachment %p.\n", iface, caps, attachment);
813 hr = ddraw_surface7_GetAttachedSurface(&surface->IDirectDrawSurface7_iface,
814 caps, &attachment7);
815 if (FAILED(hr))
817 *attachment = NULL;
818 return hr;
820 attachment_impl = impl_from_IDirectDrawSurface7(attachment7);
821 *attachment = &attachment_impl->IDirectDrawSurface4_iface;
822 ddraw_surface4_AddRef(*attachment);
823 ddraw_surface7_Release(attachment7);
825 return hr;
828 static HRESULT WINAPI ddraw_surface3_GetAttachedSurface(IDirectDrawSurface3 *iface,
829 DDSCAPS *caps, IDirectDrawSurface3 **attachment)
831 struct ddraw_surface *surface = impl_from_IDirectDrawSurface3(iface);
832 struct ddraw_surface *attachment_impl;
833 IDirectDrawSurface7 *attachment7;
834 DDSCAPS2 caps2;
835 HRESULT hr;
837 TRACE("iface %p, caps %p, attachment %p.\n", iface, caps, attachment);
839 caps2.dwCaps = caps->dwCaps;
840 caps2.dwCaps2 = 0;
841 caps2.dwCaps3 = 0;
842 caps2.dwCaps4 = 0;
844 hr = ddraw_surface7_GetAttachedSurface(&surface->IDirectDrawSurface7_iface,
845 &caps2, &attachment7);
846 if (FAILED(hr))
848 *attachment = NULL;
849 return hr;
851 attachment_impl = impl_from_IDirectDrawSurface7(attachment7);
852 *attachment = &attachment_impl->IDirectDrawSurface3_iface;
853 ddraw_surface3_AddRef(*attachment);
854 ddraw_surface7_Release(attachment7);
856 return hr;
859 static HRESULT WINAPI ddraw_surface2_GetAttachedSurface(IDirectDrawSurface2 *iface,
860 DDSCAPS *caps, IDirectDrawSurface2 **attachment)
862 struct ddraw_surface *surface = impl_from_IDirectDrawSurface2(iface);
863 struct ddraw_surface *attachment_impl;
864 IDirectDrawSurface7 *attachment7;
865 DDSCAPS2 caps2;
866 HRESULT hr;
868 TRACE("iface %p, caps %p, attachment %p.\n", iface, caps, attachment);
870 caps2.dwCaps = caps->dwCaps;
871 caps2.dwCaps2 = 0;
872 caps2.dwCaps3 = 0;
873 caps2.dwCaps4 = 0;
875 hr = ddraw_surface7_GetAttachedSurface(&surface->IDirectDrawSurface7_iface,
876 &caps2, &attachment7);
877 if (FAILED(hr))
879 *attachment = NULL;
880 return hr;
882 attachment_impl = impl_from_IDirectDrawSurface7(attachment7);
883 *attachment = &attachment_impl->IDirectDrawSurface2_iface;
884 ddraw_surface2_AddRef(*attachment);
885 ddraw_surface7_Release(attachment7);
887 return hr;
890 static HRESULT WINAPI ddraw_surface1_GetAttachedSurface(IDirectDrawSurface *iface,
891 DDSCAPS *caps, IDirectDrawSurface **attachment)
893 struct ddraw_surface *surface = impl_from_IDirectDrawSurface(iface);
894 struct ddraw_surface *attachment_impl;
895 IDirectDrawSurface7 *attachment7;
896 DDSCAPS2 caps2;
897 HRESULT hr;
899 TRACE("iface %p, caps %p, attachment %p.\n", iface, caps, attachment);
901 caps2.dwCaps = caps->dwCaps;
902 caps2.dwCaps2 = 0;
903 caps2.dwCaps3 = 0;
904 caps2.dwCaps4 = 0;
906 hr = ddraw_surface7_GetAttachedSurface(&surface->IDirectDrawSurface7_iface,
907 &caps2, &attachment7);
908 if (FAILED(hr))
910 *attachment = NULL;
911 return hr;
913 attachment_impl = impl_from_IDirectDrawSurface7(attachment7);
914 *attachment = &attachment_impl->IDirectDrawSurface_iface;
915 ddraw_surface1_AddRef(*attachment);
916 ddraw_surface7_Release(attachment7);
918 return hr;
921 /*****************************************************************************
922 * IDirectDrawSurface7::Lock
924 * Locks the surface and returns a pointer to the surface's memory
926 * Params:
927 * Rect: Rectangle to lock. If NULL, the whole surface is locked
928 * DDSD: Pointer to a DDSURFACEDESC2 which shall receive the surface's desc.
929 * Flags: Locking flags, e.g Read only or write only
930 * h: An event handle that's not used and must be NULL
932 * Returns:
933 * DD_OK on success
934 * DDERR_INVALIDPARAMS if DDSD is NULL
935 * For more details, see IWineD3DSurface::LockRect
937 *****************************************************************************/
938 static HRESULT surface_lock(struct ddraw_surface *This,
939 RECT *Rect, DDSURFACEDESC2 *DDSD, DWORD Flags, HANDLE h)
941 struct wined3d_mapped_rect mapped_rect;
942 HRESULT hr = DD_OK;
944 TRACE("This %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
945 This, wine_dbgstr_rect(Rect), DDSD, Flags, h);
947 /* This->surface_desc.dwWidth and dwHeight are changeable, thus lock */
948 wined3d_mutex_lock();
950 /* Should I check for the handle to be NULL?
952 * The DDLOCK flags and the D3DLOCK flags are equal
953 * for the supported values. The others are ignored by WineD3D
956 /* Windows zeroes this if the rect is invalid */
957 DDSD->lpSurface = 0;
959 if (Rect)
961 if ((Rect->left < 0)
962 || (Rect->top < 0)
963 || (Rect->left > Rect->right)
964 || (Rect->top > Rect->bottom)
965 || (Rect->right > This->surface_desc.dwWidth)
966 || (Rect->bottom > This->surface_desc.dwHeight))
968 WARN("Trying to lock an invalid rectangle, returning DDERR_INVALIDPARAMS\n");
969 wined3d_mutex_unlock();
970 return DDERR_INVALIDPARAMS;
974 if (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER)
975 hr = ddraw_surface_update_frontbuffer(This, Rect, TRUE);
976 if (SUCCEEDED(hr))
977 hr = wined3d_surface_map(This->wined3d_surface, &mapped_rect, Rect, Flags);
978 if (FAILED(hr))
980 wined3d_mutex_unlock();
981 switch(hr)
983 /* D3D8 and D3D9 return the general D3DERR_INVALIDCALL error, but ddraw has a more
984 * specific error. But since IWineD3DSurface::LockRect returns that error in this
985 * only occasion, keep d3d8 and d3d9 free from the return value override. There are
986 * many different places where d3d8/9 would have to catch the DDERR_SURFACEBUSY, it
987 * is much easier to do it in one place in ddraw
989 case WINED3DERR_INVALIDCALL: return DDERR_SURFACEBUSY;
990 default: return hr;
994 if (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER)
996 if (Flags & DDLOCK_READONLY)
997 memset(&This->ddraw->primary_lock, 0, sizeof(This->ddraw->primary_lock));
998 else if (Rect)
999 This->ddraw->primary_lock = *Rect;
1000 else
1001 SetRect(&This->ddraw->primary_lock, 0, 0, This->surface_desc.dwWidth, This->surface_desc.dwHeight);
1004 /* Override the memory area. The pitch should be set already. Strangely windows
1005 * does not set the LPSURFACE flag on locked surfaces !?!.
1006 * DDSD->dwFlags |= DDSD_LPSURFACE;
1008 This->surface_desc.lpSurface = mapped_rect.data;
1009 DD_STRUCT_COPY_BYSIZE(DDSD,&(This->surface_desc));
1011 TRACE("locked surface returning description :\n");
1012 if (TRACE_ON(ddraw)) DDRAW_dump_surface_desc(DDSD);
1014 wined3d_mutex_unlock();
1016 return DD_OK;
1019 static HRESULT WINAPI ddraw_surface7_Lock(IDirectDrawSurface7 *iface,
1020 RECT *rect, DDSURFACEDESC2 *surface_desc, DWORD flags, HANDLE h)
1022 struct ddraw_surface *surface = impl_from_IDirectDrawSurface7(iface);
1024 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1025 iface, wine_dbgstr_rect(rect), surface_desc, flags, h);
1027 if (!surface_desc) return DDERR_INVALIDPARAMS;
1028 if (surface_desc->dwSize != sizeof(DDSURFACEDESC) &&
1029 surface_desc->dwSize != sizeof(DDSURFACEDESC2))
1031 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc->dwSize);
1032 return DDERR_INVALIDPARAMS;
1034 return surface_lock(surface, rect, surface_desc, flags, h);
1037 static HRESULT WINAPI ddraw_surface4_Lock(IDirectDrawSurface4 *iface, RECT *rect,
1038 DDSURFACEDESC2 *surface_desc, DWORD flags, HANDLE h)
1040 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
1042 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1043 iface, wine_dbgstr_rect(rect), surface_desc, flags, h);
1045 if (!surface_desc) return DDERR_INVALIDPARAMS;
1046 if (surface_desc->dwSize != sizeof(DDSURFACEDESC) &&
1047 surface_desc->dwSize != sizeof(DDSURFACEDESC2))
1049 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc->dwSize);
1050 return DDERR_INVALIDPARAMS;
1052 return surface_lock(surface, rect, surface_desc, flags, h);
1055 static HRESULT WINAPI ddraw_surface3_Lock(IDirectDrawSurface3 *iface, RECT *rect,
1056 DDSURFACEDESC *surface_desc, DWORD flags, HANDLE h)
1058 struct ddraw_surface *surface = impl_from_IDirectDrawSurface3(iface);
1059 DDSURFACEDESC2 surface_desc2;
1060 HRESULT hr;
1062 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1063 iface, wine_dbgstr_rect(rect), surface_desc, flags, h);
1065 if (!surface_desc) return DDERR_INVALIDPARAMS;
1066 if (surface_desc->dwSize != sizeof(DDSURFACEDESC) &&
1067 surface_desc->dwSize != sizeof(DDSURFACEDESC2))
1069 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc->dwSize);
1070 return DDERR_INVALIDPARAMS;
1073 surface_desc2.dwSize = surface_desc->dwSize;
1074 surface_desc2.dwFlags = 0;
1075 hr = surface_lock(surface, rect, &surface_desc2, flags, h);
1076 DDSD2_to_DDSD(&surface_desc2, surface_desc);
1077 surface_desc->dwSize = surface_desc2.dwSize;
1078 return hr;
1081 static HRESULT WINAPI ddraw_surface2_Lock(IDirectDrawSurface2 *iface, RECT *rect,
1082 DDSURFACEDESC *surface_desc, DWORD flags, HANDLE h)
1084 struct ddraw_surface *surface = impl_from_IDirectDrawSurface2(iface);
1085 DDSURFACEDESC2 surface_desc2;
1086 HRESULT hr;
1088 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1089 iface, wine_dbgstr_rect(rect), surface_desc, flags, h);
1091 if (!surface_desc) return DDERR_INVALIDPARAMS;
1092 if (surface_desc->dwSize != sizeof(DDSURFACEDESC) &&
1093 surface_desc->dwSize != sizeof(DDSURFACEDESC2))
1095 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc->dwSize);
1096 return DDERR_INVALIDPARAMS;
1099 surface_desc2.dwSize = surface_desc->dwSize;
1100 surface_desc2.dwFlags = 0;
1101 hr = surface_lock(surface, rect, &surface_desc2, flags, h);
1102 DDSD2_to_DDSD(&surface_desc2, surface_desc);
1103 surface_desc->dwSize = surface_desc2.dwSize;
1104 return hr;
1107 static HRESULT WINAPI ddraw_surface1_Lock(IDirectDrawSurface *iface, RECT *rect,
1108 DDSURFACEDESC *surface_desc, DWORD flags, HANDLE h)
1110 struct ddraw_surface *surface = impl_from_IDirectDrawSurface(iface);
1111 DDSURFACEDESC2 surface_desc2;
1112 HRESULT hr;
1113 TRACE("iface %p, rect %s, surface_desc %p, flags %#x, h %p.\n",
1114 iface, wine_dbgstr_rect(rect), surface_desc, flags, h);
1116 if (!surface_desc) return DDERR_INVALIDPARAMS;
1117 if (surface_desc->dwSize != sizeof(DDSURFACEDESC) &&
1118 surface_desc->dwSize != sizeof(DDSURFACEDESC2))
1120 WARN("Invalid structure size %d, returning DDERR_INVALIDPARAMS\n", surface_desc->dwSize);
1121 return DDERR_INVALIDPARAMS;
1124 surface_desc2.dwSize = surface_desc->dwSize;
1125 surface_desc2.dwFlags = 0;
1126 hr = surface_lock(surface, rect, &surface_desc2, flags, h);
1127 DDSD2_to_DDSD(&surface_desc2, surface_desc);
1128 surface_desc->dwSize = surface_desc2.dwSize;
1129 return hr;
1132 /*****************************************************************************
1133 * IDirectDrawSurface7::Unlock
1135 * Unlocks an locked surface
1137 * Params:
1138 * Rect: Not used by this implementation
1140 * Returns:
1141 * D3D_OK on success
1142 * For more details, see IWineD3DSurface::UnlockRect
1144 *****************************************************************************/
1145 static HRESULT WINAPI ddraw_surface7_Unlock(IDirectDrawSurface7 *iface, RECT *pRect)
1147 struct ddraw_surface *surface = impl_from_IDirectDrawSurface7(iface);
1148 HRESULT hr;
1150 TRACE("iface %p, rect %s.\n", iface, wine_dbgstr_rect(pRect));
1152 wined3d_mutex_lock();
1153 hr = wined3d_surface_unmap(surface->wined3d_surface);
1154 if (SUCCEEDED(hr))
1156 if (surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER)
1157 hr = ddraw_surface_update_frontbuffer(surface, &surface->ddraw->primary_lock, FALSE);
1158 surface->surface_desc.lpSurface = NULL;
1160 wined3d_mutex_unlock();
1162 return hr;
1165 static HRESULT WINAPI ddraw_surface4_Unlock(IDirectDrawSurface4 *iface, RECT *pRect)
1167 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
1169 TRACE("iface %p, rect %p.\n", iface, pRect);
1171 return ddraw_surface7_Unlock(&surface->IDirectDrawSurface7_iface, pRect);
1174 static HRESULT WINAPI ddraw_surface3_Unlock(IDirectDrawSurface3 *iface, void *data)
1176 struct ddraw_surface *surface = impl_from_IDirectDrawSurface3(iface);
1178 TRACE("iface %p, data %p.\n", iface, data);
1180 /* data might not be the LPRECT of later versions, so drop it. */
1181 return ddraw_surface7_Unlock(&surface->IDirectDrawSurface7_iface, NULL);
1184 static HRESULT WINAPI ddraw_surface2_Unlock(IDirectDrawSurface2 *iface, void *data)
1186 struct ddraw_surface *surface = impl_from_IDirectDrawSurface2(iface);
1188 TRACE("iface %p, data %p.\n", iface, data);
1190 /* data might not be the LPRECT of later versions, so drop it. */
1191 return ddraw_surface7_Unlock(&surface->IDirectDrawSurface7_iface, NULL);
1194 static HRESULT WINAPI ddraw_surface1_Unlock(IDirectDrawSurface *iface, void *data)
1196 struct ddraw_surface *surface = impl_from_IDirectDrawSurface(iface);
1198 TRACE("iface %p, data %p.\n", iface, data);
1200 /* data might not be the LPRECT of later versions, so drop it. */
1201 return ddraw_surface7_Unlock(&surface->IDirectDrawSurface7_iface, NULL);
1204 /*****************************************************************************
1205 * IDirectDrawSurface7::Flip
1207 * Flips a surface with the DDSCAPS_FLIP flag. The flip is relayed to
1208 * IWineD3DSurface::Flip. Because WineD3D doesn't handle attached surfaces,
1209 * the flip target is passed to WineD3D, even if the app didn't specify one
1211 * Params:
1212 * DestOverride: Specifies the surface that will become the new front
1213 * buffer. If NULL, the current back buffer is used
1214 * Flags: some DirectDraw flags, see include/ddraw.h
1216 * Returns:
1217 * DD_OK on success
1218 * DDERR_NOTFLIPPABLE if no flip target could be found
1219 * DDERR_INVALIDOBJECT if the surface isn't a front buffer
1220 * For more details, see IWineD3DSurface::Flip
1222 *****************************************************************************/
1223 static HRESULT WINAPI ddraw_surface7_Flip(IDirectDrawSurface7 *iface, IDirectDrawSurface7 *DestOverride, DWORD Flags)
1225 struct ddraw_surface *surface = impl_from_IDirectDrawSurface7(iface);
1226 struct ddraw_surface *Override = unsafe_impl_from_IDirectDrawSurface7(DestOverride);
1227 IDirectDrawSurface7 *Override7;
1228 HRESULT hr;
1230 TRACE("iface %p, dst %p, flags %#x.\n", iface, DestOverride, Flags);
1232 /* Flip has to be called from a front buffer
1233 * What about overlay surfaces, AFAIK they can flip too? */
1234 if (!(surface->surface_desc.ddsCaps.dwCaps & (DDSCAPS_FRONTBUFFER | DDSCAPS_OVERLAY)))
1235 return DDERR_INVALIDOBJECT; /* Unchecked */
1237 wined3d_mutex_lock();
1239 /* WineD3D doesn't keep track of attached surface, so find the target */
1240 if(!Override)
1242 DDSCAPS2 Caps;
1244 memset(&Caps, 0, sizeof(Caps));
1245 Caps.dwCaps |= DDSCAPS_BACKBUFFER;
1246 hr = ddraw_surface7_GetAttachedSurface(iface, &Caps, &Override7);
1247 if(hr != DD_OK)
1249 ERR("Can't find a flip target\n");
1250 wined3d_mutex_unlock();
1251 return DDERR_NOTFLIPPABLE; /* Unchecked */
1253 Override = impl_from_IDirectDrawSurface7(Override7);
1255 /* For the GetAttachedSurface */
1256 ddraw_surface7_Release(Override7);
1259 hr = wined3d_surface_flip(surface->wined3d_surface, Override->wined3d_surface, Flags);
1260 if (SUCCEEDED(hr) && surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER)
1261 hr = ddraw_surface_update_frontbuffer(surface, NULL, FALSE);
1263 wined3d_mutex_unlock();
1265 return hr;
1268 static HRESULT WINAPI ddraw_surface4_Flip(IDirectDrawSurface4 *iface, IDirectDrawSurface4 *dst, DWORD flags)
1270 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
1271 struct ddraw_surface *dst_impl = unsafe_impl_from_IDirectDrawSurface4(dst);
1273 TRACE("iface %p, dst %p, flags %#x.\n", iface, dst, flags);
1275 return ddraw_surface7_Flip(&surface->IDirectDrawSurface7_iface,
1276 dst_impl ? &dst_impl->IDirectDrawSurface7_iface : NULL, flags);
1279 static HRESULT WINAPI ddraw_surface3_Flip(IDirectDrawSurface3 *iface, IDirectDrawSurface3 *dst, DWORD flags)
1281 struct ddraw_surface *surface = impl_from_IDirectDrawSurface3(iface);
1282 struct ddraw_surface *dst_impl = unsafe_impl_from_IDirectDrawSurface3(dst);
1284 TRACE("iface %p, dst %p, flags %#x.\n", iface, dst, flags);
1286 return ddraw_surface7_Flip(&surface->IDirectDrawSurface7_iface,
1287 dst_impl ? &dst_impl->IDirectDrawSurface7_iface : NULL, flags);
1290 static HRESULT WINAPI ddraw_surface2_Flip(IDirectDrawSurface2 *iface, IDirectDrawSurface2 *dst, DWORD flags)
1292 struct ddraw_surface *surface = impl_from_IDirectDrawSurface2(iface);
1293 struct ddraw_surface *dst_impl = unsafe_impl_from_IDirectDrawSurface2(dst);
1295 TRACE("iface %p, dst %p, flags %#x.\n", iface, dst, flags);
1297 return ddraw_surface7_Flip(&surface->IDirectDrawSurface7_iface,
1298 dst_impl ? &dst_impl->IDirectDrawSurface7_iface : NULL, flags);
1301 static HRESULT WINAPI ddraw_surface1_Flip(IDirectDrawSurface *iface, IDirectDrawSurface *dst, DWORD flags)
1303 struct ddraw_surface *surface = impl_from_IDirectDrawSurface(iface);
1304 struct ddraw_surface *dst_impl = unsafe_impl_from_IDirectDrawSurface(dst);
1306 TRACE("iface %p, dst %p, flags %#x.\n", iface, dst, flags);
1308 return ddraw_surface7_Flip(&surface->IDirectDrawSurface7_iface,
1309 dst_impl ? &dst_impl->IDirectDrawSurface7_iface : NULL, flags);
1312 static HRESULT ddraw_surface_blt_clipped(struct ddraw_surface *dst_surface, const RECT *dst_rect_in,
1313 struct ddraw_surface *src_surface, const RECT *src_rect_in, DWORD flags,
1314 const WINEDDBLTFX *fx, enum wined3d_texture_filter_type filter)
1316 struct wined3d_surface *wined3d_src_surface = src_surface ? src_surface->wined3d_surface : NULL;
1317 RECT src_rect, dst_rect;
1318 float scale_x, scale_y;
1319 const RECT *clip_rect;
1320 UINT clip_list_size;
1321 RGNDATA *clip_list;
1322 HRESULT hr = DD_OK;
1323 UINT i;
1325 if (!dst_surface->clipper)
1327 if (src_surface && src_surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER)
1328 hr = ddraw_surface_update_frontbuffer(src_surface, src_rect_in, TRUE);
1329 if (SUCCEEDED(hr))
1330 hr = wined3d_surface_blt(dst_surface->wined3d_surface, dst_rect_in,
1331 wined3d_src_surface, src_rect_in, flags, fx, filter);
1332 if (SUCCEEDED(hr) && (dst_surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER))
1333 hr = ddraw_surface_update_frontbuffer(dst_surface, dst_rect_in, FALSE);
1335 return hr;
1338 if (!dst_rect_in)
1340 dst_rect.left = 0;
1341 dst_rect.top = 0;
1342 dst_rect.right = dst_surface->surface_desc.dwWidth;
1343 dst_rect.bottom = dst_surface->surface_desc.dwHeight;
1345 else
1347 dst_rect = *dst_rect_in;
1350 if (IsRectEmpty(&dst_rect))
1351 return DDERR_INVALIDRECT;
1353 if (src_surface)
1355 if (!src_rect_in)
1357 src_rect.left = 0;
1358 src_rect.top = 0;
1359 src_rect.right = src_surface->surface_desc.dwWidth;
1360 src_rect.bottom = src_surface->surface_desc.dwHeight;
1362 else
1364 src_rect = *src_rect_in;
1367 if (IsRectEmpty(&src_rect))
1368 return DDERR_INVALIDRECT;
1370 else
1372 SetRect(&src_rect, 0, 0, 0, 0);
1375 scale_x = (float)(src_rect.right - src_rect.left) / (float)(dst_rect.right - dst_rect.left);
1376 scale_y = (float)(src_rect.bottom - src_rect.top) / (float)(dst_rect.bottom - dst_rect.top);
1378 if (FAILED(hr = IDirectDrawClipper_GetClipList(&dst_surface->clipper->IDirectDrawClipper_iface,
1379 &dst_rect, NULL, &clip_list_size)))
1381 WARN("Failed to get clip list size, hr %#x.\n", hr);
1382 return hr;
1385 if (!(clip_list = HeapAlloc(GetProcessHeap(), 0, clip_list_size)))
1387 WARN("Failed to allocate clip list.\n");
1388 return E_OUTOFMEMORY;
1391 if (FAILED(hr = IDirectDrawClipper_GetClipList(&dst_surface->clipper->IDirectDrawClipper_iface,
1392 &dst_rect, clip_list, &clip_list_size)))
1394 WARN("Failed to get clip list, hr %#x.\n", hr);
1395 HeapFree(GetProcessHeap(), 0, clip_list);
1396 return hr;
1399 clip_rect = (RECT *)clip_list->Buffer;
1400 for (i = 0; i < clip_list->rdh.nCount; ++i)
1402 RECT src_rect_clipped = src_rect;
1404 if (src_surface)
1406 src_rect_clipped.left += (LONG)((clip_rect[i].left - dst_rect.left) * scale_x);
1407 src_rect_clipped.top += (LONG)((clip_rect[i].top - dst_rect.top) * scale_y);
1408 src_rect_clipped.right -= (LONG)((dst_rect.right - clip_rect[i].right) * scale_x);
1409 src_rect_clipped.bottom -= (LONG)((dst_rect.bottom - clip_rect[i].bottom) * scale_y);
1411 if (src_surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER)
1413 if (FAILED(hr = ddraw_surface_update_frontbuffer(src_surface, &src_rect_clipped, TRUE)))
1414 break;
1418 if (FAILED(hr = wined3d_surface_blt(dst_surface->wined3d_surface, &clip_rect[i],
1419 wined3d_src_surface, &src_rect_clipped, flags, fx, filter)))
1420 break;
1422 if (dst_surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER)
1424 if (FAILED(hr = ddraw_surface_update_frontbuffer(dst_surface, &clip_rect[i], FALSE)))
1425 break;
1429 HeapFree(GetProcessHeap(), 0, clip_list);
1430 return hr;
1433 /*****************************************************************************
1434 * IDirectDrawSurface7::Blt
1436 * Performs a blit on the surface
1438 * Params:
1439 * DestRect: Destination rectangle, can be NULL
1440 * SrcSurface: Source surface, can be NULL
1441 * SrcRect: Source rectangle, can be NULL
1442 * Flags: Blt flags
1443 * DDBltFx: Some extended blt parameters, connected to the flags
1445 * Returns:
1446 * D3D_OK on success
1447 * See IWineD3DSurface::Blt for more details
1449 *****************************************************************************/
1450 static HRESULT WINAPI ddraw_surface7_Blt(IDirectDrawSurface7 *iface, RECT *DestRect,
1451 IDirectDrawSurface7 *SrcSurface, RECT *SrcRect, DWORD Flags, DDBLTFX *DDBltFx)
1453 struct ddraw_surface *dst_surface = impl_from_IDirectDrawSurface7(iface);
1454 struct ddraw_surface *src_surface = unsafe_impl_from_IDirectDrawSurface7(SrcSurface);
1455 HRESULT hr = DD_OK;
1457 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1458 iface, wine_dbgstr_rect(DestRect), SrcSurface, wine_dbgstr_rect(SrcRect), Flags, DDBltFx);
1460 /* Check for validity of the flags here. WineD3D Has the software-opengl selection path and would have
1461 * to check at 2 places, and sometimes do double checks. This also saves the call to wined3d :-)
1463 if((Flags & DDBLT_KEYSRCOVERRIDE) && (!DDBltFx || Flags & DDBLT_KEYSRC)) {
1464 WARN("Invalid source color key parameters, returning DDERR_INVALIDPARAMS\n");
1465 return DDERR_INVALIDPARAMS;
1468 if((Flags & DDBLT_KEYDESTOVERRIDE) && (!DDBltFx || Flags & DDBLT_KEYDEST)) {
1469 WARN("Invalid destination color key parameters, returning DDERR_INVALIDPARAMS\n");
1470 return DDERR_INVALIDPARAMS;
1473 wined3d_mutex_lock();
1475 if (Flags & DDBLT_KEYSRC && (!src_surface || !(src_surface->surface_desc.dwFlags & DDSD_CKSRCBLT)))
1477 WARN("DDBLT_KEYDEST blit without color key in surface, returning DDERR_INVALIDPARAMS\n");
1478 wined3d_mutex_unlock();
1479 return DDERR_INVALIDPARAMS;
1482 /* TODO: Check if the DDBltFx contains any ddraw surface pointers. If it
1483 * does, copy the struct, and replace the ddraw surfaces with the wined3d
1484 * surfaces. So far no blitting operations using surfaces in the bltfx
1485 * struct are supported anyway. */
1486 hr = ddraw_surface_blt_clipped(dst_surface, DestRect, src_surface, SrcRect,
1487 Flags, (WINEDDBLTFX *)DDBltFx, WINED3D_TEXF_LINEAR);
1489 wined3d_mutex_unlock();
1490 switch(hr)
1492 case WINED3DERR_NOTAVAILABLE: return DDERR_UNSUPPORTED;
1493 case WINED3DERR_WRONGTEXTUREFORMAT: return DDERR_INVALIDPIXELFORMAT;
1494 default: return hr;
1498 static HRESULT WINAPI ddraw_surface4_Blt(IDirectDrawSurface4 *iface, RECT *dst_rect,
1499 IDirectDrawSurface4 *src_surface, RECT *src_rect, DWORD flags, DDBLTFX *fx)
1501 struct ddraw_surface *dst = impl_from_IDirectDrawSurface4(iface);
1502 struct ddraw_surface *src = unsafe_impl_from_IDirectDrawSurface4(src_surface);
1504 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1505 iface, wine_dbgstr_rect(dst_rect), src_surface, wine_dbgstr_rect(src_rect), flags, fx);
1507 return ddraw_surface7_Blt(&dst->IDirectDrawSurface7_iface, dst_rect,
1508 src ? &src->IDirectDrawSurface7_iface : NULL, src_rect, flags, fx);
1511 static HRESULT WINAPI ddraw_surface3_Blt(IDirectDrawSurface3 *iface, RECT *dst_rect,
1512 IDirectDrawSurface3 *src_surface, RECT *src_rect, DWORD flags, DDBLTFX *fx)
1514 struct ddraw_surface *dst = impl_from_IDirectDrawSurface3(iface);
1515 struct ddraw_surface *src_impl = unsafe_impl_from_IDirectDrawSurface3(src_surface);
1517 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1518 iface, wine_dbgstr_rect(dst_rect), src_surface, wine_dbgstr_rect(src_rect), flags, fx);
1520 return ddraw_surface7_Blt(&dst->IDirectDrawSurface7_iface, dst_rect,
1521 src_impl ? &src_impl->IDirectDrawSurface7_iface : NULL, src_rect, flags, fx);
1524 static HRESULT WINAPI ddraw_surface2_Blt(IDirectDrawSurface2 *iface, RECT *dst_rect,
1525 IDirectDrawSurface2 *src_surface, RECT *src_rect, DWORD flags, DDBLTFX *fx)
1527 struct ddraw_surface *dst = impl_from_IDirectDrawSurface2(iface);
1528 struct ddraw_surface *src_impl = unsafe_impl_from_IDirectDrawSurface2(src_surface);
1530 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1531 iface, wine_dbgstr_rect(dst_rect), src_surface, wine_dbgstr_rect(src_rect), flags, fx);
1533 return ddraw_surface7_Blt(&dst->IDirectDrawSurface7_iface, dst_rect,
1534 src_impl ? &src_impl->IDirectDrawSurface7_iface : NULL, src_rect, flags, fx);
1537 static HRESULT WINAPI ddraw_surface1_Blt(IDirectDrawSurface *iface, RECT *dst_rect,
1538 IDirectDrawSurface *src_surface, RECT *src_rect, DWORD flags, DDBLTFX *fx)
1540 struct ddraw_surface *dst = impl_from_IDirectDrawSurface(iface);
1541 struct ddraw_surface *src_impl = unsafe_impl_from_IDirectDrawSurface(src_surface);
1543 TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n",
1544 iface, wine_dbgstr_rect(dst_rect), src_surface, wine_dbgstr_rect(src_rect), flags, fx);
1546 return ddraw_surface7_Blt(&dst->IDirectDrawSurface7_iface, dst_rect,
1547 src_impl ? &src_impl->IDirectDrawSurface7_iface : NULL, src_rect, flags, fx);
1550 /*****************************************************************************
1551 * IDirectDrawSurface7::AddAttachedSurface
1553 * Attaches a surface to another surface. How the surface attachments work
1554 * is not totally understood yet, and this method is prone to problems.
1555 * The surface that is attached is AddRef-ed.
1557 * Tests with complex surfaces suggest that the surface attachments form a
1558 * tree, but no method to test this has been found yet.
1560 * The attachment list consists of a first surface (first_attached) and
1561 * for each surface a pointer to the next attached surface (next_attached).
1562 * For the first surface, and a surface that has no attachments
1563 * first_attached points to the surface itself. A surface that has
1564 * no successors in the chain has next_attached set to NULL.
1566 * Newly attached surfaces are attached right after the root surface.
1567 * If a surface is attached to a complex surface compound, it's attached to
1568 * the surface that the app requested, not the complex root. See
1569 * GetAttachedSurface for a description how surfaces are found.
1571 * This is how the current implementation works, and it was coded by looking
1572 * at the needs of the applications.
1574 * So far only Z-Buffer attachments are tested, and they are activated in
1575 * WineD3D. Mipmaps could be tricky to activate in WineD3D.
1576 * Back buffers should work in 2D mode, but they are not tested(They can be
1577 * attached in older iface versions). Rendering to the front buffer and
1578 * switching between that and double buffering is not yet implemented in
1579 * WineD3D, so for 3D it might have unexpected results.
1581 * ddraw_surface_attach_surface is the real thing,
1582 * ddraw_surface7_AddAttachedSurface is a wrapper around it that
1583 * performs additional checks. Version 7 of this interface is much more restrictive
1584 * than its predecessors.
1586 * Params:
1587 * Attach: Surface to attach to iface
1589 * Returns:
1590 * DD_OK on success
1591 * DDERR_CANNOTATTACHSURFACE if the surface can't be attached for some reason
1593 *****************************************************************************/
1594 static HRESULT ddraw_surface_attach_surface(struct ddraw_surface *This, struct ddraw_surface *Surf)
1596 TRACE("surface %p, attachment %p.\n", This, Surf);
1598 if(Surf == This)
1599 return DDERR_CANNOTATTACHSURFACE; /* unchecked */
1601 wined3d_mutex_lock();
1603 /* Check if the surface is already attached somewhere */
1604 if (Surf->next_attached || Surf->first_attached != Surf)
1606 /* TODO: Test for the structure of the manual attachment. Is it a
1607 * chain or a list? What happens if one surface is attached to 2
1608 * different surfaces? */
1609 WARN("Surface %p is already attached somewhere. next_attached %p, first_attached %p.\n",
1610 Surf, Surf->next_attached, Surf->first_attached);
1612 wined3d_mutex_unlock();
1613 return DDERR_SURFACEALREADYATTACHED;
1616 /* This inserts the new surface at the 2nd position in the chain, right after the root surface */
1617 Surf->next_attached = This->next_attached;
1618 Surf->first_attached = This->first_attached;
1619 This->next_attached = Surf;
1621 /* Check if the WineD3D depth stencil needs updating */
1622 if(This->ddraw->d3ddevice)
1624 IDirect3DDeviceImpl_UpdateDepthStencil(This->ddraw->d3ddevice);
1627 wined3d_mutex_unlock();
1629 return DD_OK;
1632 static HRESULT WINAPI ddraw_surface7_AddAttachedSurface(IDirectDrawSurface7 *iface, IDirectDrawSurface7 *attachment)
1634 struct ddraw_surface *This = impl_from_IDirectDrawSurface7(iface);
1635 struct ddraw_surface *attachment_impl = unsafe_impl_from_IDirectDrawSurface7(attachment);
1636 HRESULT hr;
1638 TRACE("iface %p, attachment %p.\n", iface, attachment);
1640 /* Version 7 of this interface seems to refuse everything except z buffers, as per msdn */
1641 if(!(attachment_impl->surface_desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER))
1644 WARN("Application tries to attach a non Z buffer surface. caps %08x\n",
1645 attachment_impl->surface_desc.ddsCaps.dwCaps);
1646 return DDERR_CANNOTATTACHSURFACE;
1649 hr = ddraw_surface_attach_surface(This, attachment_impl);
1650 if (FAILED(hr))
1652 return hr;
1654 attachment_impl->attached_iface = (IUnknown *)attachment;
1655 IUnknown_AddRef(attachment_impl->attached_iface);
1656 return hr;
1659 static HRESULT WINAPI ddraw_surface4_AddAttachedSurface(IDirectDrawSurface4 *iface, IDirectDrawSurface4 *attachment)
1661 struct ddraw_surface *This = impl_from_IDirectDrawSurface4(iface);
1662 struct ddraw_surface *attachment_impl = unsafe_impl_from_IDirectDrawSurface4(attachment);
1663 HRESULT hr;
1665 TRACE("iface %p, attachment %p.\n", iface, attachment);
1667 hr = ddraw_surface7_AddAttachedSurface(&This->IDirectDrawSurface7_iface,
1668 attachment_impl ? &attachment_impl->IDirectDrawSurface7_iface : NULL);
1669 if (FAILED(hr))
1671 return hr;
1673 attachment_impl->attached_iface = (IUnknown *)attachment;
1674 IUnknown_AddRef(attachment_impl->attached_iface);
1675 ddraw_surface7_Release(&attachment_impl->IDirectDrawSurface7_iface);
1676 return hr;
1678 static HRESULT WINAPI ddraw_surface3_AddAttachedSurface(IDirectDrawSurface3 *iface, IDirectDrawSurface3 *attachment)
1680 struct ddraw_surface *This = impl_from_IDirectDrawSurface3(iface);
1681 struct ddraw_surface *attachment_impl = unsafe_impl_from_IDirectDrawSurface3(attachment);
1682 HRESULT hr;
1684 TRACE("iface %p, attachment %p.\n", iface, attachment);
1686 /* Tests suggest that
1687 * -> offscreen plain surfaces can be attached to other offscreen plain surfaces
1688 * -> offscreen plain surfaces can be attached to primaries
1689 * -> primaries can be attached to offscreen plain surfaces
1690 * -> z buffers can be attached to primaries */
1691 if (This->surface_desc.ddsCaps.dwCaps & (DDSCAPS_PRIMARYSURFACE | DDSCAPS_OFFSCREENPLAIN)
1692 && attachment_impl->surface_desc.ddsCaps.dwCaps & (DDSCAPS_PRIMARYSURFACE | DDSCAPS_OFFSCREENPLAIN))
1694 /* Sizes have to match */
1695 if (attachment_impl->surface_desc.dwWidth != This->surface_desc.dwWidth
1696 || attachment_impl->surface_desc.dwHeight != This->surface_desc.dwHeight)
1698 WARN("Surface sizes do not match.\n");
1699 return DDERR_CANNOTATTACHSURFACE;
1701 /* OK */
1703 else if (This->surface_desc.ddsCaps.dwCaps & (DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE)
1704 && attachment_impl->surface_desc.ddsCaps.dwCaps & (DDSCAPS_ZBUFFER))
1706 /* OK */
1708 else
1710 WARN("Invalid attachment combination.\n");
1711 return DDERR_CANNOTATTACHSURFACE;
1714 hr = ddraw_surface_attach_surface(This, attachment_impl);
1715 if (FAILED(hr))
1717 return hr;
1719 attachment_impl->attached_iface = (IUnknown *)attachment;
1720 IUnknown_AddRef(attachment_impl->attached_iface);
1721 return hr;
1724 static HRESULT WINAPI ddraw_surface2_AddAttachedSurface(IDirectDrawSurface2 *iface, IDirectDrawSurface2 *attachment)
1726 struct ddraw_surface *This = impl_from_IDirectDrawSurface2(iface);
1727 struct ddraw_surface *attachment_impl = unsafe_impl_from_IDirectDrawSurface2(attachment);
1728 HRESULT hr;
1730 TRACE("iface %p, attachment %p.\n", iface, attachment);
1732 hr = ddraw_surface3_AddAttachedSurface(&This->IDirectDrawSurface3_iface,
1733 attachment_impl ? &attachment_impl->IDirectDrawSurface3_iface : NULL);
1734 if (FAILED(hr))
1736 return hr;
1738 attachment_impl->attached_iface = (IUnknown *)attachment;
1739 IUnknown_AddRef(attachment_impl->attached_iface);
1740 ddraw_surface3_Release(&attachment_impl->IDirectDrawSurface3_iface);
1741 return hr;
1744 static HRESULT WINAPI ddraw_surface1_AddAttachedSurface(IDirectDrawSurface *iface, IDirectDrawSurface *attachment)
1746 struct ddraw_surface *This = impl_from_IDirectDrawSurface(iface);
1747 struct ddraw_surface *attachment_impl = unsafe_impl_from_IDirectDrawSurface(attachment);
1748 HRESULT hr;
1750 TRACE("iface %p, attachment %p.\n", iface, attachment);
1752 hr = ddraw_surface3_AddAttachedSurface(&This->IDirectDrawSurface3_iface,
1753 attachment_impl ? &attachment_impl->IDirectDrawSurface3_iface : NULL);
1754 if (FAILED(hr))
1756 return hr;
1758 attachment_impl->attached_iface = (IUnknown *)attachment;
1759 IUnknown_AddRef(attachment_impl->attached_iface);
1760 ddraw_surface3_Release(&attachment_impl->IDirectDrawSurface3_iface);
1761 return hr;
1764 /*****************************************************************************
1765 * IDirectDrawSurface7::DeleteAttachedSurface
1767 * Removes a surface from the attachment chain. The surface's refcount
1768 * is decreased by one after it has been removed
1770 * Params:
1771 * Flags: Some flags, not used by this implementation
1772 * Attach: Surface to detach
1774 * Returns:
1775 * DD_OK on success
1776 * DDERR_SURFACENOTATTACHED if the surface isn't attached to
1778 *****************************************************************************/
1779 static HRESULT ddraw_surface_delete_attached_surface(struct ddraw_surface *surface,
1780 struct ddraw_surface *attachment, IUnknown *detach_iface)
1782 struct ddraw_surface *prev = surface;
1784 TRACE("surface %p, attachment %p, detach_iface %p.\n", surface, attachment, detach_iface);
1786 wined3d_mutex_lock();
1787 if (!attachment || (attachment->first_attached != surface) || (attachment == surface) )
1789 wined3d_mutex_unlock();
1790 return DDERR_CANNOTDETACHSURFACE;
1793 if (attachment->attached_iface != detach_iface)
1795 WARN("attachment->attach_iface %p != detach_iface %p.\n", attachment->attached_iface, detach_iface);
1796 wined3d_mutex_unlock();
1797 return DDERR_SURFACENOTATTACHED;
1800 /* Remove MIPMAPSUBLEVEL if this seemed to be one */
1801 if (surface->surface_desc.ddsCaps.dwCaps & attachment->surface_desc.ddsCaps.dwCaps & DDSCAPS_MIPMAP)
1803 attachment->surface_desc.ddsCaps.dwCaps2 &= ~DDSCAPS2_MIPMAPSUBLEVEL;
1804 /* FIXME: we should probably also subtract from dwMipMapCount of this
1805 * and all parent surfaces */
1808 /* Find the predecessor of the detached surface */
1809 while (prev)
1811 if (prev->next_attached == attachment)
1812 break;
1813 prev = prev->next_attached;
1816 /* There must be a surface, otherwise there's a bug */
1817 assert(prev);
1819 /* Unchain the surface */
1820 prev->next_attached = attachment->next_attached;
1821 attachment->next_attached = NULL;
1822 attachment->first_attached = attachment;
1824 /* Check if the wined3d depth stencil needs updating. */
1825 if (surface->ddraw->d3ddevice)
1826 IDirect3DDeviceImpl_UpdateDepthStencil(surface->ddraw->d3ddevice);
1827 wined3d_mutex_unlock();
1829 /* Set attached_iface to NULL before releasing it, the surface may go
1830 * away. */
1831 attachment->attached_iface = NULL;
1832 IUnknown_Release(detach_iface);
1834 return DD_OK;
1837 static HRESULT WINAPI ddraw_surface7_DeleteAttachedSurface(IDirectDrawSurface7 *iface,
1838 DWORD flags, IDirectDrawSurface7 *attachment)
1840 struct ddraw_surface *surface = impl_from_IDirectDrawSurface7(iface);
1841 struct ddraw_surface *attachment_impl = unsafe_impl_from_IDirectDrawSurface7(attachment);
1843 TRACE("iface %p, flags %#x, attachment %p.\n", iface, flags, attachment);
1845 return ddraw_surface_delete_attached_surface(surface, attachment_impl, (IUnknown *)attachment);
1848 static HRESULT WINAPI ddraw_surface4_DeleteAttachedSurface(IDirectDrawSurface4 *iface,
1849 DWORD flags, IDirectDrawSurface4 *attachment)
1851 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
1852 struct ddraw_surface *attachment_impl = unsafe_impl_from_IDirectDrawSurface4(attachment);
1854 TRACE("iface %p, flags %#x, attachment %p.\n", iface, flags, attachment);
1856 return ddraw_surface_delete_attached_surface(surface, attachment_impl, (IUnknown *)attachment);
1859 static HRESULT WINAPI ddraw_surface3_DeleteAttachedSurface(IDirectDrawSurface3 *iface,
1860 DWORD flags, IDirectDrawSurface3 *attachment)
1862 struct ddraw_surface *surface = impl_from_IDirectDrawSurface3(iface);
1863 struct ddraw_surface *attachment_impl = unsafe_impl_from_IDirectDrawSurface3(attachment);
1865 TRACE("iface %p, flags %#x, attachment %p.\n", iface, flags, attachment);
1867 return ddraw_surface_delete_attached_surface(surface, attachment_impl, (IUnknown *)attachment);
1870 static HRESULT WINAPI ddraw_surface2_DeleteAttachedSurface(IDirectDrawSurface2 *iface,
1871 DWORD flags, IDirectDrawSurface2 *attachment)
1873 struct ddraw_surface *surface = impl_from_IDirectDrawSurface2(iface);
1874 struct ddraw_surface *attachment_impl = unsafe_impl_from_IDirectDrawSurface2(attachment);
1876 TRACE("iface %p, flags %#x, attachment %p.\n", iface, flags, attachment);
1878 return ddraw_surface_delete_attached_surface(surface, attachment_impl, (IUnknown *)attachment);
1881 static HRESULT WINAPI ddraw_surface1_DeleteAttachedSurface(IDirectDrawSurface *iface,
1882 DWORD flags, IDirectDrawSurface *attachment)
1884 struct ddraw_surface *surface = impl_from_IDirectDrawSurface(iface);
1885 struct ddraw_surface *attachment_impl = unsafe_impl_from_IDirectDrawSurface(attachment);
1887 TRACE("iface %p, flags %#x, attachment %p.\n", iface, flags, attachment);
1889 return ddraw_surface_delete_attached_surface(surface, attachment_impl, (IUnknown *)attachment);
1892 /*****************************************************************************
1893 * IDirectDrawSurface7::AddOverlayDirtyRect
1895 * "This method is not currently implemented"
1897 * Params:
1898 * Rect: ?
1900 * Returns:
1901 * DDERR_UNSUPPORTED
1903 *****************************************************************************/
1904 static HRESULT WINAPI ddraw_surface7_AddOverlayDirtyRect(IDirectDrawSurface7 *iface, RECT *Rect)
1906 TRACE("iface %p, rect %s.\n", iface, wine_dbgstr_rect(Rect));
1908 return DDERR_UNSUPPORTED; /* unchecked */
1911 static HRESULT WINAPI ddraw_surface4_AddOverlayDirtyRect(IDirectDrawSurface4 *iface, RECT *rect)
1913 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
1915 TRACE("iface %p, rect %s.\n", iface, wine_dbgstr_rect(rect));
1917 return ddraw_surface7_AddOverlayDirtyRect(&surface->IDirectDrawSurface7_iface, rect);
1920 static HRESULT WINAPI ddraw_surface3_AddOverlayDirtyRect(IDirectDrawSurface3 *iface, RECT *rect)
1922 struct ddraw_surface *surface = impl_from_IDirectDrawSurface3(iface);
1924 TRACE("iface %p, rect %s.\n", iface, wine_dbgstr_rect(rect));
1926 return ddraw_surface7_AddOverlayDirtyRect(&surface->IDirectDrawSurface7_iface, rect);
1929 static HRESULT WINAPI ddraw_surface2_AddOverlayDirtyRect(IDirectDrawSurface2 *iface, RECT *rect)
1931 struct ddraw_surface *surface = impl_from_IDirectDrawSurface2(iface);
1933 TRACE("iface %p, rect %s.\n", iface, wine_dbgstr_rect(rect));
1935 return ddraw_surface7_AddOverlayDirtyRect(&surface->IDirectDrawSurface7_iface, rect);
1938 static HRESULT WINAPI ddraw_surface1_AddOverlayDirtyRect(IDirectDrawSurface *iface, RECT *rect)
1940 struct ddraw_surface *surface = impl_from_IDirectDrawSurface(iface);
1942 TRACE("iface %p, rect %s.\n", iface, wine_dbgstr_rect(rect));
1944 return ddraw_surface7_AddOverlayDirtyRect(&surface->IDirectDrawSurface7_iface, rect);
1947 /*****************************************************************************
1948 * IDirectDrawSurface7::GetDC
1950 * Returns a GDI device context for the surface
1952 * Params:
1953 * hdc: Address of a HDC variable to store the dc to
1955 * Returns:
1956 * DD_OK on success
1957 * DDERR_INVALIDPARAMS if hdc is NULL
1958 * For details, see IWineD3DSurface::GetDC
1960 *****************************************************************************/
1961 static HRESULT WINAPI ddraw_surface7_GetDC(IDirectDrawSurface7 *iface, HDC *hdc)
1963 struct ddraw_surface *surface = impl_from_IDirectDrawSurface7(iface);
1964 HRESULT hr = DD_OK;
1966 TRACE("iface %p, dc %p.\n", iface, hdc);
1968 if(!hdc)
1969 return DDERR_INVALIDPARAMS;
1971 wined3d_mutex_lock();
1972 if (surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER)
1973 hr = ddraw_surface_update_frontbuffer(surface, NULL, TRUE);
1974 if (SUCCEEDED(hr))
1975 hr = wined3d_surface_getdc(surface->wined3d_surface, hdc);
1976 wined3d_mutex_unlock();
1977 switch(hr)
1979 /* Some, but not all errors set *hdc to NULL. E.g. DCALREADYCREATED does not
1980 * touch *hdc
1982 case WINED3DERR_INVALIDCALL:
1983 if(hdc) *hdc = NULL;
1984 return DDERR_INVALIDPARAMS;
1986 default: return hr;
1990 static HRESULT WINAPI ddraw_surface4_GetDC(IDirectDrawSurface4 *iface, HDC *dc)
1992 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
1994 TRACE("iface %p, dc %p.\n", iface, dc);
1996 return ddraw_surface7_GetDC(&surface->IDirectDrawSurface7_iface, dc);
1999 static HRESULT WINAPI ddraw_surface3_GetDC(IDirectDrawSurface3 *iface, HDC *dc)
2001 struct ddraw_surface *surface = impl_from_IDirectDrawSurface3(iface);
2003 TRACE("iface %p, dc %p.\n", iface, dc);
2005 return ddraw_surface7_GetDC(&surface->IDirectDrawSurface7_iface, dc);
2008 static HRESULT WINAPI ddraw_surface2_GetDC(IDirectDrawSurface2 *iface, HDC *dc)
2010 struct ddraw_surface *surface = impl_from_IDirectDrawSurface2(iface);
2012 TRACE("iface %p, dc %p.\n", iface, dc);
2014 return ddraw_surface7_GetDC(&surface->IDirectDrawSurface7_iface, dc);
2017 static HRESULT WINAPI ddraw_surface1_GetDC(IDirectDrawSurface *iface, HDC *dc)
2019 struct ddraw_surface *surface = impl_from_IDirectDrawSurface(iface);
2021 TRACE("iface %p, dc %p.\n", iface, dc);
2023 return ddraw_surface7_GetDC(&surface->IDirectDrawSurface7_iface, dc);
2026 /*****************************************************************************
2027 * IDirectDrawSurface7::ReleaseDC
2029 * Releases the DC that was constructed with GetDC
2031 * Params:
2032 * hdc: HDC to release
2034 * Returns:
2035 * DD_OK on success
2036 * For more details, see IWineD3DSurface::ReleaseDC
2038 *****************************************************************************/
2039 static HRESULT WINAPI ddraw_surface7_ReleaseDC(IDirectDrawSurface7 *iface, HDC hdc)
2041 struct ddraw_surface *surface = impl_from_IDirectDrawSurface7(iface);
2042 HRESULT hr;
2044 TRACE("iface %p, dc %p.\n", iface, hdc);
2046 wined3d_mutex_lock();
2047 hr = wined3d_surface_releasedc(surface->wined3d_surface, hdc);
2048 if (SUCCEEDED(hr) && (surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER))
2049 hr = ddraw_surface_update_frontbuffer(surface, NULL, FALSE);
2050 wined3d_mutex_unlock();
2052 return hr;
2055 static HRESULT WINAPI ddraw_surface4_ReleaseDC(IDirectDrawSurface4 *iface, HDC dc)
2057 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
2059 TRACE("iface %p, dc %p.\n", iface, dc);
2061 return ddraw_surface7_ReleaseDC(&surface->IDirectDrawSurface7_iface, dc);
2064 static HRESULT WINAPI ddraw_surface3_ReleaseDC(IDirectDrawSurface3 *iface, HDC dc)
2066 struct ddraw_surface *surface = impl_from_IDirectDrawSurface3(iface);
2068 TRACE("iface %p, dc %p.\n", iface, dc);
2070 return ddraw_surface7_ReleaseDC(&surface->IDirectDrawSurface7_iface, dc);
2073 static HRESULT WINAPI ddraw_surface2_ReleaseDC(IDirectDrawSurface2 *iface, HDC dc)
2075 struct ddraw_surface *surface = impl_from_IDirectDrawSurface2(iface);
2077 TRACE("iface %p, dc %p.\n", iface, dc);
2079 return ddraw_surface7_ReleaseDC(&surface->IDirectDrawSurface7_iface, dc);
2082 static HRESULT WINAPI ddraw_surface1_ReleaseDC(IDirectDrawSurface *iface, HDC dc)
2084 struct ddraw_surface *surface = impl_from_IDirectDrawSurface(iface);
2086 TRACE("iface %p, dc %p.\n", iface, dc);
2088 return ddraw_surface7_ReleaseDC(&surface->IDirectDrawSurface7_iface, dc);
2091 /*****************************************************************************
2092 * IDirectDrawSurface7::GetCaps
2094 * Returns the surface's caps
2096 * Params:
2097 * Caps: Address to write the caps to
2099 * Returns:
2100 * DD_OK on success
2101 * DDERR_INVALIDPARAMS if Caps is NULL
2103 *****************************************************************************/
2104 static HRESULT WINAPI ddraw_surface7_GetCaps(IDirectDrawSurface7 *iface, DDSCAPS2 *Caps)
2106 struct ddraw_surface *surface = impl_from_IDirectDrawSurface7(iface);
2108 TRACE("iface %p, caps %p.\n", iface, Caps);
2110 if(!Caps)
2111 return DDERR_INVALIDPARAMS;
2113 *Caps = surface->surface_desc.ddsCaps;
2115 return DD_OK;
2118 static HRESULT WINAPI ddraw_surface4_GetCaps(IDirectDrawSurface4 *iface, DDSCAPS2 *caps)
2120 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
2122 TRACE("iface %p, caps %p.\n", iface, caps);
2124 return ddraw_surface7_GetCaps(&surface->IDirectDrawSurface7_iface, caps);
2127 static HRESULT WINAPI ddraw_surface3_GetCaps(IDirectDrawSurface3 *iface, DDSCAPS *caps)
2129 struct ddraw_surface *surface = impl_from_IDirectDrawSurface3(iface);
2130 DDSCAPS2 caps2;
2131 HRESULT hr;
2133 TRACE("iface %p, caps %p.\n", iface, caps);
2135 hr = ddraw_surface7_GetCaps(&surface->IDirectDrawSurface7_iface, &caps2);
2136 if (FAILED(hr)) return hr;
2138 caps->dwCaps = caps2.dwCaps;
2139 return hr;
2142 static HRESULT WINAPI ddraw_surface2_GetCaps(IDirectDrawSurface2 *iface, DDSCAPS *caps)
2144 struct ddraw_surface *surface = impl_from_IDirectDrawSurface2(iface);
2145 DDSCAPS2 caps2;
2146 HRESULT hr;
2148 TRACE("iface %p, caps %p.\n", iface, caps);
2150 hr = ddraw_surface7_GetCaps(&surface->IDirectDrawSurface7_iface, &caps2);
2151 if (FAILED(hr)) return hr;
2153 caps->dwCaps = caps2.dwCaps;
2154 return hr;
2157 static HRESULT WINAPI ddraw_surface1_GetCaps(IDirectDrawSurface *iface, DDSCAPS *caps)
2159 struct ddraw_surface *surface = impl_from_IDirectDrawSurface(iface);
2160 DDSCAPS2 caps2;
2161 HRESULT hr;
2163 TRACE("iface %p, caps %p.\n", iface, caps);
2165 hr = ddraw_surface7_GetCaps(&surface->IDirectDrawSurface7_iface, &caps2);
2166 if (FAILED(hr)) return hr;
2168 caps->dwCaps = caps2.dwCaps;
2169 return hr;
2172 /*****************************************************************************
2173 * IDirectDrawSurface7::SetPriority
2175 * Sets a texture priority for managed textures.
2177 * Params:
2178 * Priority: The new priority
2180 * Returns:
2181 * DD_OK on success
2182 * For more details, see IWineD3DSurface::SetPriority
2184 *****************************************************************************/
2185 static HRESULT WINAPI ddraw_surface7_SetPriority(IDirectDrawSurface7 *iface, DWORD Priority)
2187 struct ddraw_surface *surface = impl_from_IDirectDrawSurface7(iface);
2188 HRESULT hr;
2190 TRACE("iface %p, priority %u.\n", iface, Priority);
2192 wined3d_mutex_lock();
2193 hr = wined3d_surface_set_priority(surface->wined3d_surface, Priority);
2194 wined3d_mutex_unlock();
2196 return hr;
2199 /*****************************************************************************
2200 * IDirectDrawSurface7::GetPriority
2202 * Returns the surface's priority
2204 * Params:
2205 * Priority: Address of a variable to write the priority to
2207 * Returns:
2208 * D3D_OK on success
2209 * DDERR_INVALIDPARAMS if Priority == NULL
2210 * For more details, see IWineD3DSurface::GetPriority
2212 *****************************************************************************/
2213 static HRESULT WINAPI ddraw_surface7_GetPriority(IDirectDrawSurface7 *iface, DWORD *Priority)
2215 struct ddraw_surface *surface = impl_from_IDirectDrawSurface7(iface);
2217 TRACE("iface %p, priority %p.\n", iface, Priority);
2219 if(!Priority)
2221 return DDERR_INVALIDPARAMS;
2224 wined3d_mutex_lock();
2225 *Priority = wined3d_surface_get_priority(surface->wined3d_surface);
2226 wined3d_mutex_unlock();
2228 return DD_OK;
2231 /*****************************************************************************
2232 * IDirectDrawSurface7::SetPrivateData
2234 * Stores some data in the surface that is intended for the application's
2235 * use.
2237 * Params:
2238 * tag: GUID that identifies the data
2239 * Data: Pointer to the private data
2240 * Size: Size of the private data
2241 * Flags: Some flags
2243 * Returns:
2244 * D3D_OK on success
2245 * For more details, see IWineD3DSurface::SetPrivateData
2247 *****************************************************************************/
2248 static HRESULT WINAPI ddraw_surface7_SetPrivateData(IDirectDrawSurface7 *iface,
2249 REFGUID tag, void *Data, DWORD Size, DWORD Flags)
2251 struct ddraw_surface *surface = impl_from_IDirectDrawSurface7(iface);
2252 struct wined3d_resource *resource;
2253 HRESULT hr;
2255 TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n",
2256 iface, debugstr_guid(tag), Data, Size, Flags);
2258 wined3d_mutex_lock();
2259 resource = wined3d_surface_get_resource(surface->wined3d_surface);
2260 hr = wined3d_resource_set_private_data(resource, tag, Data, Size, Flags);
2261 wined3d_mutex_unlock();
2263 switch(hr)
2265 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
2266 default: return hr;
2270 static HRESULT WINAPI ddraw_surface4_SetPrivateData(IDirectDrawSurface4 *iface,
2271 REFGUID tag, void *data, DWORD size, DWORD flags)
2273 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
2275 TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n",
2276 iface, debugstr_guid(tag), data, size, flags);
2278 return ddraw_surface7_SetPrivateData(&surface->IDirectDrawSurface7_iface, tag, data, size, flags);
2281 /*****************************************************************************
2282 * IDirectDrawSurface7::GetPrivateData
2284 * Returns the private data set with IDirectDrawSurface7::SetPrivateData
2286 * Params:
2287 * tag: GUID of the data to return
2288 * Data: Address where to write the data to
2289 * Size: Size of the buffer at Data
2291 * Returns:
2292 * DD_OK on success
2293 * DDERR_INVALIDPARAMS if Data is NULL
2294 * For more details, see IWineD3DSurface::GetPrivateData
2296 *****************************************************************************/
2297 static HRESULT WINAPI ddraw_surface7_GetPrivateData(IDirectDrawSurface7 *iface, REFGUID tag, void *Data, DWORD *Size)
2299 struct ddraw_surface *surface = impl_from_IDirectDrawSurface7(iface);
2300 struct wined3d_resource *resource;
2301 HRESULT hr;
2303 TRACE("iface %p, tag %s, data %p, data_size %p.\n",
2304 iface, debugstr_guid(tag), Data, Size);
2306 if(!Data)
2307 return DDERR_INVALIDPARAMS;
2309 wined3d_mutex_lock();
2310 resource = wined3d_surface_get_resource(surface->wined3d_surface);
2311 hr = wined3d_resource_get_private_data(resource, tag, Data, Size);
2312 wined3d_mutex_unlock();
2314 return hr;
2317 static HRESULT WINAPI ddraw_surface4_GetPrivateData(IDirectDrawSurface4 *iface, REFGUID tag, void *data, DWORD *size)
2319 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
2321 TRACE("iface %p, tag %s, data %p, data_size %p.\n",
2322 iface, debugstr_guid(tag), data, size);
2324 return ddraw_surface7_GetPrivateData(&surface->IDirectDrawSurface7_iface, tag, data, size);
2327 /*****************************************************************************
2328 * IDirectDrawSurface7::FreePrivateData
2330 * Frees private data stored in the surface
2332 * Params:
2333 * tag: Tag of the data to free
2335 * Returns:
2336 * D3D_OK on success
2337 * For more details, see IWineD3DSurface::FreePrivateData
2339 *****************************************************************************/
2340 static HRESULT WINAPI ddraw_surface7_FreePrivateData(IDirectDrawSurface7 *iface, REFGUID tag)
2342 struct ddraw_surface *surface = impl_from_IDirectDrawSurface7(iface);
2343 struct wined3d_resource *resource;
2344 HRESULT hr;
2346 TRACE("iface %p, tag %s.\n", iface, debugstr_guid(tag));
2348 wined3d_mutex_lock();
2349 resource = wined3d_surface_get_resource(surface->wined3d_surface);
2350 hr = wined3d_resource_free_private_data(resource, tag);
2351 wined3d_mutex_unlock();
2353 return hr;
2356 static HRESULT WINAPI ddraw_surface4_FreePrivateData(IDirectDrawSurface4 *iface, REFGUID tag)
2358 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
2360 TRACE("iface %p, tag %s.\n", iface, debugstr_guid(tag));
2362 return ddraw_surface7_FreePrivateData(&surface->IDirectDrawSurface7_iface, tag);
2365 /*****************************************************************************
2366 * IDirectDrawSurface7::PageLock
2368 * Prevents a sysmem surface from being paged out
2370 * Params:
2371 * Flags: Not used, must be 0(unchecked)
2373 * Returns:
2374 * DD_OK, because it's a stub
2376 *****************************************************************************/
2377 static HRESULT WINAPI ddraw_surface7_PageLock(IDirectDrawSurface7 *iface, DWORD Flags)
2379 TRACE("iface %p, flags %#x.\n", iface, Flags);
2381 /* This is Windows memory management related - we don't need this */
2382 return DD_OK;
2385 static HRESULT WINAPI ddraw_surface4_PageLock(IDirectDrawSurface4 *iface, DWORD flags)
2387 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
2389 TRACE("iface %p, flags %#x.\n", iface, flags);
2391 return ddraw_surface7_PageLock(&surface->IDirectDrawSurface7_iface, flags);
2394 static HRESULT WINAPI ddraw_surface3_PageLock(IDirectDrawSurface3 *iface, DWORD flags)
2396 struct ddraw_surface *surface = impl_from_IDirectDrawSurface3(iface);
2398 TRACE("iface %p, flags %#x.\n", iface, flags);
2400 return ddraw_surface7_PageLock(&surface->IDirectDrawSurface7_iface, flags);
2403 static HRESULT WINAPI ddraw_surface2_PageLock(IDirectDrawSurface2 *iface, DWORD flags)
2405 struct ddraw_surface *surface = impl_from_IDirectDrawSurface2(iface);
2407 TRACE("iface %p, flags %#x.\n", iface, flags);
2409 return ddraw_surface7_PageLock(&surface->IDirectDrawSurface7_iface, flags);
2412 /*****************************************************************************
2413 * IDirectDrawSurface7::PageUnlock
2415 * Allows a sysmem surface to be paged out
2417 * Params:
2418 * Flags: Not used, must be 0(unchecked)
2420 * Returns:
2421 * DD_OK, because it's a stub
2423 *****************************************************************************/
2424 static HRESULT WINAPI ddraw_surface7_PageUnlock(IDirectDrawSurface7 *iface, DWORD Flags)
2426 TRACE("iface %p, flags %#x.\n", iface, Flags);
2428 return DD_OK;
2431 static HRESULT WINAPI ddraw_surface4_PageUnlock(IDirectDrawSurface4 *iface, DWORD flags)
2433 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
2435 TRACE("iface %p, flags %#x.\n", iface, flags);
2437 return ddraw_surface7_PageUnlock(&surface->IDirectDrawSurface7_iface, flags);
2440 static HRESULT WINAPI ddraw_surface3_PageUnlock(IDirectDrawSurface3 *iface, DWORD flags)
2442 struct ddraw_surface *surface = impl_from_IDirectDrawSurface3(iface);
2444 TRACE("iface %p, flags %#x.\n", iface, flags);
2446 return ddraw_surface7_PageUnlock(&surface->IDirectDrawSurface7_iface, flags);
2449 static HRESULT WINAPI ddraw_surface2_PageUnlock(IDirectDrawSurface2 *iface, DWORD flags)
2451 struct ddraw_surface *surface = impl_from_IDirectDrawSurface2(iface);
2453 TRACE("iface %p, flags %#x.\n", iface, flags);
2455 return ddraw_surface7_PageUnlock(&surface->IDirectDrawSurface7_iface, flags);
2458 /*****************************************************************************
2459 * IDirectDrawSurface7::BltBatch
2461 * An unimplemented function
2463 * Params:
2466 * Returns:
2467 * DDERR_UNSUPPORTED
2469 *****************************************************************************/
2470 static HRESULT WINAPI ddraw_surface7_BltBatch(IDirectDrawSurface7 *iface, DDBLTBATCH *Batch, DWORD Count, DWORD Flags)
2472 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface, Batch, Count, Flags);
2474 /* MSDN: "not currently implemented" */
2475 return DDERR_UNSUPPORTED;
2478 static HRESULT WINAPI ddraw_surface4_BltBatch(IDirectDrawSurface4 *iface, DDBLTBATCH *batch, DWORD count, DWORD flags)
2480 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
2482 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface, batch, count, flags);
2484 return ddraw_surface7_BltBatch(&surface->IDirectDrawSurface7_iface, batch, count, flags);
2487 static HRESULT WINAPI ddraw_surface3_BltBatch(IDirectDrawSurface3 *iface, DDBLTBATCH *batch, DWORD count, DWORD flags)
2489 struct ddraw_surface *surface = impl_from_IDirectDrawSurface3(iface);
2491 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface, batch, count, flags);
2493 return ddraw_surface7_BltBatch(&surface->IDirectDrawSurface7_iface, batch, count, flags);
2496 static HRESULT WINAPI ddraw_surface2_BltBatch(IDirectDrawSurface2 *iface, DDBLTBATCH *batch, DWORD count, DWORD flags)
2498 struct ddraw_surface *surface = impl_from_IDirectDrawSurface2(iface);
2500 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface, batch, count, flags);
2502 return ddraw_surface7_BltBatch(&surface->IDirectDrawSurface7_iface, batch, count, flags);
2505 static HRESULT WINAPI ddraw_surface1_BltBatch(IDirectDrawSurface *iface, DDBLTBATCH *batch, DWORD count, DWORD flags)
2507 struct ddraw_surface *surface = impl_from_IDirectDrawSurface(iface);
2509 TRACE("iface %p, batch %p, count %u, flags %#x.\n", iface, batch, count, flags);
2511 return ddraw_surface7_BltBatch(&surface->IDirectDrawSurface7_iface, batch, count, flags);
2514 /*****************************************************************************
2515 * IDirectDrawSurface7::EnumAttachedSurfaces
2517 * Enumerates all surfaces attached to this surface
2519 * Params:
2520 * context: Pointer to pass unmodified to the callback
2521 * cb: Callback function to call for each surface
2523 * Returns:
2524 * DD_OK on success
2525 * DDERR_INVALIDPARAMS if cb is NULL
2527 *****************************************************************************/
2528 static HRESULT WINAPI ddraw_surface7_EnumAttachedSurfaces(IDirectDrawSurface7 *iface,
2529 void *context, LPDDENUMSURFACESCALLBACK7 cb)
2531 struct ddraw_surface *surface = impl_from_IDirectDrawSurface7(iface);
2532 struct ddraw_surface *surf;
2533 DDSURFACEDESC2 desc;
2534 int i;
2536 /* Attached surfaces aren't handled in WineD3D */
2537 TRACE("iface %p, context %p, callback %p.\n", iface, context, cb);
2539 if(!cb)
2540 return DDERR_INVALIDPARAMS;
2542 wined3d_mutex_lock();
2544 for(i = 0; i < MAX_COMPLEX_ATTACHED; i++)
2546 surf = surface->complex_array[i];
2547 if(!surf) break;
2549 ddraw_surface7_AddRef(&surf->IDirectDrawSurface7_iface);
2550 desc = surf->surface_desc;
2551 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
2552 if (cb(&surf->IDirectDrawSurface7_iface, &desc, context) == DDENUMRET_CANCEL)
2554 wined3d_mutex_unlock();
2555 return DD_OK;
2559 for (surf = surface->next_attached; surf != NULL; surf = surf->next_attached)
2561 ddraw_surface7_AddRef(&surf->IDirectDrawSurface7_iface);
2562 desc = surf->surface_desc;
2563 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
2564 if (cb(&surf->IDirectDrawSurface7_iface, &desc, context) == DDENUMRET_CANCEL)
2566 wined3d_mutex_unlock();
2567 return DD_OK;
2571 TRACE(" end of enumeration.\n");
2573 wined3d_mutex_unlock();
2575 return DD_OK;
2578 struct callback_info2
2580 LPDDENUMSURFACESCALLBACK2 callback;
2581 void *context;
2584 struct callback_info
2586 LPDDENUMSURFACESCALLBACK callback;
2587 void *context;
2590 static HRESULT CALLBACK EnumCallback2(IDirectDrawSurface7 *surface, DDSURFACEDESC2 *surface_desc, void *context)
2592 struct ddraw_surface *surface_impl = impl_from_IDirectDrawSurface7(surface);
2593 const struct callback_info2 *info = context;
2595 ddraw_surface4_AddRef(&surface_impl->IDirectDrawSurface4_iface);
2596 ddraw_surface7_Release(surface);
2598 return info->callback(&surface_impl->IDirectDrawSurface4_iface, surface_desc, info->context);
2601 static HRESULT CALLBACK EnumCallback(IDirectDrawSurface7 *surface, DDSURFACEDESC2 *surface_desc, void *context)
2603 struct ddraw_surface *surface_impl = impl_from_IDirectDrawSurface7(surface);
2604 const struct callback_info *info = context;
2606 ddraw_surface1_AddRef(&surface_impl->IDirectDrawSurface_iface);
2607 ddraw_surface7_Release(surface);
2609 /* FIXME: Check surface_test.dwSize */
2610 return info->callback(&surface_impl->IDirectDrawSurface_iface,
2611 (DDSURFACEDESC *)surface_desc, info->context);
2614 static HRESULT WINAPI ddraw_surface4_EnumAttachedSurfaces(IDirectDrawSurface4 *iface,
2615 void *context, LPDDENUMSURFACESCALLBACK2 callback)
2617 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
2618 struct callback_info2 info;
2620 TRACE("iface %p, context %p, callback %p.\n", iface, context, callback);
2622 info.callback = callback;
2623 info.context = context;
2625 return ddraw_surface7_EnumAttachedSurfaces(&surface->IDirectDrawSurface7_iface,
2626 &info, EnumCallback2);
2629 static HRESULT WINAPI ddraw_surface3_EnumAttachedSurfaces(IDirectDrawSurface3 *iface,
2630 void *context, LPDDENUMSURFACESCALLBACK callback)
2632 struct ddraw_surface *surface = impl_from_IDirectDrawSurface3(iface);
2633 struct callback_info info;
2635 TRACE("iface %p, context %p, callback %p.\n", iface, context, callback);
2637 info.callback = callback;
2638 info.context = context;
2640 return ddraw_surface7_EnumAttachedSurfaces(&surface->IDirectDrawSurface7_iface,
2641 &info, EnumCallback);
2644 static HRESULT WINAPI ddraw_surface2_EnumAttachedSurfaces(IDirectDrawSurface2 *iface,
2645 void *context, LPDDENUMSURFACESCALLBACK callback)
2647 struct ddraw_surface *surface = impl_from_IDirectDrawSurface2(iface);
2648 struct callback_info info;
2650 TRACE("iface %p, context %p, callback %p.\n", iface, context, callback);
2652 info.callback = callback;
2653 info.context = context;
2655 return ddraw_surface7_EnumAttachedSurfaces(&surface->IDirectDrawSurface7_iface,
2656 &info, EnumCallback);
2659 static HRESULT WINAPI ddraw_surface1_EnumAttachedSurfaces(IDirectDrawSurface *iface,
2660 void *context, LPDDENUMSURFACESCALLBACK callback)
2662 struct ddraw_surface *surface = impl_from_IDirectDrawSurface(iface);
2663 struct callback_info info;
2665 TRACE("iface %p, context %p, callback %p.\n", iface, context, callback);
2667 info.callback = callback;
2668 info.context = context;
2670 return ddraw_surface7_EnumAttachedSurfaces(&surface->IDirectDrawSurface7_iface,
2671 &info, EnumCallback);
2674 /*****************************************************************************
2675 * IDirectDrawSurface7::EnumOverlayZOrders
2677 * "Enumerates the overlay surfaces on the specified destination"
2679 * Params:
2680 * Flags: DDENUMOVERLAYZ_BACKTOFRONT or DDENUMOVERLAYZ_FRONTTOBACK
2681 * context: context to pass back to the callback
2682 * cb: callback function to call for each enumerated surface
2684 * Returns:
2685 * DD_OK, because it's a stub
2687 *****************************************************************************/
2688 static HRESULT WINAPI ddraw_surface7_EnumOverlayZOrders(IDirectDrawSurface7 *iface,
2689 DWORD Flags, void *context, LPDDENUMSURFACESCALLBACK7 cb)
2691 FIXME("iface %p, flags %#x, context %p, callback %p stub!\n", iface, Flags, context, cb);
2693 return DD_OK;
2696 static HRESULT WINAPI ddraw_surface4_EnumOverlayZOrders(IDirectDrawSurface4 *iface,
2697 DWORD flags, void *context, LPDDENUMSURFACESCALLBACK2 callback)
2699 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
2700 struct callback_info2 info;
2702 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface, flags, context, callback);
2704 info.callback = callback;
2705 info.context = context;
2707 return ddraw_surface7_EnumOverlayZOrders(&surface->IDirectDrawSurface7_iface,
2708 flags, &info, EnumCallback2);
2711 static HRESULT WINAPI ddraw_surface3_EnumOverlayZOrders(IDirectDrawSurface3 *iface,
2712 DWORD flags, void *context, LPDDENUMSURFACESCALLBACK callback)
2714 struct ddraw_surface *surface = impl_from_IDirectDrawSurface3(iface);
2715 struct callback_info info;
2717 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface, flags, context, callback);
2719 info.callback = callback;
2720 info.context = context;
2722 return ddraw_surface7_EnumOverlayZOrders(&surface->IDirectDrawSurface7_iface,
2723 flags, &info, EnumCallback);
2726 static HRESULT WINAPI ddraw_surface2_EnumOverlayZOrders(IDirectDrawSurface2 *iface,
2727 DWORD flags, void *context, LPDDENUMSURFACESCALLBACK callback)
2729 struct ddraw_surface *surface = impl_from_IDirectDrawSurface2(iface);
2730 struct callback_info info;
2732 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface, flags, context, callback);
2734 info.callback = callback;
2735 info.context = context;
2737 return ddraw_surface7_EnumOverlayZOrders(&surface->IDirectDrawSurface7_iface,
2738 flags, &info, EnumCallback);
2741 static HRESULT WINAPI ddraw_surface1_EnumOverlayZOrders(IDirectDrawSurface *iface,
2742 DWORD flags, void *context, LPDDENUMSURFACESCALLBACK callback)
2744 struct ddraw_surface *surface = impl_from_IDirectDrawSurface(iface);
2745 struct callback_info info;
2747 TRACE("iface %p, flags %#x, context %p, callback %p.\n", iface, flags, context, callback);
2749 info.callback = callback;
2750 info.context = context;
2752 return ddraw_surface7_EnumOverlayZOrders(&surface->IDirectDrawSurface7_iface,
2753 flags, &info, EnumCallback);
2756 /*****************************************************************************
2757 * IDirectDrawSurface7::GetBltStatus
2759 * Returns the blitting status
2761 * Params:
2762 * Flags: DDGBS_CANBLT or DDGBS_ISBLTDONE
2764 * Returns:
2765 * See IWineD3DSurface::Blt
2767 *****************************************************************************/
2768 static HRESULT WINAPI ddraw_surface7_GetBltStatus(IDirectDrawSurface7 *iface, DWORD Flags)
2770 struct ddraw_surface *surface = impl_from_IDirectDrawSurface7(iface);
2771 HRESULT hr;
2773 TRACE("iface %p, flags %#x.\n", iface, Flags);
2775 wined3d_mutex_lock();
2776 hr = wined3d_surface_get_blt_status(surface->wined3d_surface, Flags);
2777 wined3d_mutex_unlock();
2778 switch(hr)
2780 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
2781 default: return hr;
2785 static HRESULT WINAPI ddraw_surface4_GetBltStatus(IDirectDrawSurface4 *iface, DWORD flags)
2787 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
2789 TRACE("iface %p, flags %#x.\n", iface, flags);
2791 return ddraw_surface7_GetBltStatus(&surface->IDirectDrawSurface7_iface, flags);
2794 static HRESULT WINAPI ddraw_surface3_GetBltStatus(IDirectDrawSurface3 *iface, DWORD flags)
2796 struct ddraw_surface *surface = impl_from_IDirectDrawSurface3(iface);
2798 TRACE("iface %p, flags %#x.\n", iface, flags);
2800 return ddraw_surface7_GetBltStatus(&surface->IDirectDrawSurface7_iface, flags);
2803 static HRESULT WINAPI ddraw_surface2_GetBltStatus(IDirectDrawSurface2 *iface, DWORD flags)
2805 struct ddraw_surface *surface = impl_from_IDirectDrawSurface2(iface);
2807 TRACE("iface %p, flags %#x.\n", iface, flags);
2809 return ddraw_surface7_GetBltStatus(&surface->IDirectDrawSurface7_iface, flags);
2812 static HRESULT WINAPI ddraw_surface1_GetBltStatus(IDirectDrawSurface *iface, DWORD flags)
2814 struct ddraw_surface *surface = impl_from_IDirectDrawSurface(iface);
2816 TRACE("iface %p, flags %#x.\n", iface, flags);
2818 return ddraw_surface7_GetBltStatus(&surface->IDirectDrawSurface7_iface, flags);
2821 /*****************************************************************************
2822 * IDirectDrawSurface7::GetColorKey
2824 * Returns the color key assigned to the surface
2826 * Params:
2827 * Flags: Some flags
2828 * CKey: Address to store the key to
2830 * Returns:
2831 * DD_OK on success
2832 * DDERR_INVALIDPARAMS if CKey is NULL
2834 *****************************************************************************/
2835 static HRESULT WINAPI ddraw_surface7_GetColorKey(IDirectDrawSurface7 *iface, DWORD Flags, DDCOLORKEY *CKey)
2837 struct ddraw_surface *This = impl_from_IDirectDrawSurface7(iface);
2839 TRACE("iface %p, flags %#x, color_key %p.\n", iface, Flags, CKey);
2841 if(!CKey)
2842 return DDERR_INVALIDPARAMS;
2844 wined3d_mutex_lock();
2846 switch (Flags)
2848 case DDCKEY_DESTBLT:
2849 if (!(This->surface_desc.dwFlags & DDSD_CKDESTBLT))
2851 wined3d_mutex_unlock();
2852 return DDERR_NOCOLORKEY;
2854 *CKey = This->surface_desc.ddckCKDestBlt;
2855 break;
2857 case DDCKEY_DESTOVERLAY:
2858 if (!(This->surface_desc.dwFlags & DDSD_CKDESTOVERLAY))
2860 wined3d_mutex_unlock();
2861 return DDERR_NOCOLORKEY;
2863 *CKey = This->surface_desc.u3.ddckCKDestOverlay;
2864 break;
2866 case DDCKEY_SRCBLT:
2867 if (!(This->surface_desc.dwFlags & DDSD_CKSRCBLT))
2869 wined3d_mutex_unlock();
2870 return DDERR_NOCOLORKEY;
2872 *CKey = This->surface_desc.ddckCKSrcBlt;
2873 break;
2875 case DDCKEY_SRCOVERLAY:
2876 if (!(This->surface_desc.dwFlags & DDSD_CKSRCOVERLAY))
2878 wined3d_mutex_unlock();
2879 return DDERR_NOCOLORKEY;
2881 *CKey = This->surface_desc.ddckCKSrcOverlay;
2882 break;
2884 default:
2885 wined3d_mutex_unlock();
2886 return DDERR_INVALIDPARAMS;
2889 wined3d_mutex_unlock();
2891 return DD_OK;
2894 static HRESULT WINAPI ddraw_surface4_GetColorKey(IDirectDrawSurface4 *iface, DWORD flags, DDCOLORKEY *color_key)
2896 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
2898 TRACE("iface %p, flags %#x, color_key %p.\n", iface, flags, color_key);
2900 return ddraw_surface7_GetColorKey(&surface->IDirectDrawSurface7_iface, flags, color_key);
2903 static HRESULT WINAPI ddraw_surface3_GetColorKey(IDirectDrawSurface3 *iface, DWORD flags, DDCOLORKEY *color_key)
2905 struct ddraw_surface *surface = impl_from_IDirectDrawSurface3(iface);
2907 TRACE("iface %p, flags %#x, color_key %p.\n", iface, flags, color_key);
2909 return ddraw_surface7_GetColorKey(&surface->IDirectDrawSurface7_iface, flags, color_key);
2912 static HRESULT WINAPI ddraw_surface2_GetColorKey(IDirectDrawSurface2 *iface, DWORD flags, DDCOLORKEY *color_key)
2914 struct ddraw_surface *surface = impl_from_IDirectDrawSurface2(iface);
2916 TRACE("iface %p, flags %#x, color_key %p.\n", iface, flags, color_key);
2918 return ddraw_surface7_GetColorKey(&surface->IDirectDrawSurface7_iface, flags, color_key);
2921 static HRESULT WINAPI ddraw_surface1_GetColorKey(IDirectDrawSurface *iface, DWORD flags, DDCOLORKEY *color_key)
2923 struct ddraw_surface *surface = impl_from_IDirectDrawSurface(iface);
2925 TRACE("iface %p, flags %#x, color_key %p.\n", iface, flags, color_key);
2927 return ddraw_surface7_GetColorKey(&surface->IDirectDrawSurface7_iface, flags, color_key);
2930 /*****************************************************************************
2931 * IDirectDrawSurface7::GetFlipStatus
2933 * Returns the flipping status of the surface
2935 * Params:
2936 * Flags: DDGFS_CANFLIP of DDGFS_ISFLIPDONE
2938 * Returns:
2939 * See IWineD3DSurface::GetFlipStatus
2941 *****************************************************************************/
2942 static HRESULT WINAPI ddraw_surface7_GetFlipStatus(IDirectDrawSurface7 *iface, DWORD Flags)
2944 struct ddraw_surface *surface = impl_from_IDirectDrawSurface7(iface);
2945 HRESULT hr;
2947 TRACE("iface %p, flags %#x.\n", iface, Flags);
2949 wined3d_mutex_lock();
2950 hr = wined3d_surface_get_flip_status(surface->wined3d_surface, Flags);
2951 wined3d_mutex_unlock();
2953 switch(hr)
2955 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
2956 default: return hr;
2960 static HRESULT WINAPI ddraw_surface4_GetFlipStatus(IDirectDrawSurface4 *iface, DWORD flags)
2962 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
2964 TRACE("iface %p, flags %#x.\n", iface, flags);
2966 return ddraw_surface7_GetFlipStatus(&surface->IDirectDrawSurface7_iface, flags);
2969 static HRESULT WINAPI ddraw_surface3_GetFlipStatus(IDirectDrawSurface3 *iface, DWORD flags)
2971 struct ddraw_surface *surface = impl_from_IDirectDrawSurface3(iface);
2973 TRACE("iface %p, flags %#x.\n", iface, flags);
2975 return ddraw_surface7_GetFlipStatus(&surface->IDirectDrawSurface7_iface, flags);
2978 static HRESULT WINAPI ddraw_surface2_GetFlipStatus(IDirectDrawSurface2 *iface, DWORD flags)
2980 struct ddraw_surface *surface = impl_from_IDirectDrawSurface2(iface);
2982 TRACE("iface %p, flags %#x.\n", iface, flags);
2984 return ddraw_surface7_GetFlipStatus(&surface->IDirectDrawSurface7_iface, flags);
2987 static HRESULT WINAPI ddraw_surface1_GetFlipStatus(IDirectDrawSurface *iface, DWORD flags)
2989 struct ddraw_surface *surface = impl_from_IDirectDrawSurface(iface);
2991 TRACE("iface %p, flags %#x.\n", iface, flags);
2993 return ddraw_surface7_GetFlipStatus(&surface->IDirectDrawSurface7_iface, flags);
2996 /*****************************************************************************
2997 * IDirectDrawSurface7::GetOverlayPosition
2999 * Returns the display coordinates of a visible and active overlay surface
3001 * Params:
3005 * Returns:
3006 * DDERR_NOTAOVERLAYSURFACE, because it's a stub
3007 *****************************************************************************/
3008 static HRESULT WINAPI ddraw_surface7_GetOverlayPosition(IDirectDrawSurface7 *iface, LONG *X, LONG *Y)
3010 struct ddraw_surface *surface = impl_from_IDirectDrawSurface7(iface);
3011 HRESULT hr;
3013 TRACE("iface %p, x %p, y %p.\n", iface, X, Y);
3015 wined3d_mutex_lock();
3016 hr = wined3d_surface_get_overlay_position(surface->wined3d_surface, X, Y);
3017 wined3d_mutex_unlock();
3019 return hr;
3022 static HRESULT WINAPI ddraw_surface4_GetOverlayPosition(IDirectDrawSurface4 *iface, LONG *x, LONG *y)
3024 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
3026 TRACE("iface %p, x %p, y %p.\n", iface, x, y);
3028 return ddraw_surface7_GetOverlayPosition(&surface->IDirectDrawSurface7_iface, x, y);
3031 static HRESULT WINAPI ddraw_surface3_GetOverlayPosition(IDirectDrawSurface3 *iface, LONG *x, LONG *y)
3033 struct ddraw_surface *surface = impl_from_IDirectDrawSurface3(iface);
3035 TRACE("iface %p, x %p, y %p.\n", iface, x, y);
3037 return ddraw_surface7_GetOverlayPosition(&surface->IDirectDrawSurface7_iface, x, y);
3040 static HRESULT WINAPI ddraw_surface2_GetOverlayPosition(IDirectDrawSurface2 *iface, LONG *x, LONG *y)
3042 struct ddraw_surface *surface = impl_from_IDirectDrawSurface2(iface);
3044 TRACE("iface %p, x %p, y %p.\n", iface, x, y);
3046 return ddraw_surface7_GetOverlayPosition(&surface->IDirectDrawSurface7_iface, x, y);
3049 static HRESULT WINAPI ddraw_surface1_GetOverlayPosition(IDirectDrawSurface *iface, LONG *x, LONG *y)
3051 struct ddraw_surface *surface = impl_from_IDirectDrawSurface(iface);
3053 TRACE("iface %p, x %p, y %p.\n", iface, x, y);
3055 return ddraw_surface7_GetOverlayPosition(&surface->IDirectDrawSurface7_iface, x, y);
3058 /*****************************************************************************
3059 * IDirectDrawSurface7::GetPixelFormat
3061 * Returns the pixel format of the Surface
3063 * Params:
3064 * PixelFormat: Pointer to a DDPIXELFORMAT structure to which the pixel
3065 * format should be written
3067 * Returns:
3068 * DD_OK on success
3069 * DDERR_INVALIDPARAMS if PixelFormat is NULL
3071 *****************************************************************************/
3072 static HRESULT WINAPI ddraw_surface7_GetPixelFormat(IDirectDrawSurface7 *iface, DDPIXELFORMAT *PixelFormat)
3074 /* What is DDERR_INVALIDSURFACETYPE for here? */
3075 struct ddraw_surface *surface = impl_from_IDirectDrawSurface7(iface);
3077 TRACE("iface %p, pixel_format %p.\n", iface, PixelFormat);
3079 if(!PixelFormat)
3080 return DDERR_INVALIDPARAMS;
3082 wined3d_mutex_lock();
3083 DD_STRUCT_COPY_BYSIZE(PixelFormat, &surface->surface_desc.u4.ddpfPixelFormat);
3084 wined3d_mutex_unlock();
3086 return DD_OK;
3089 static HRESULT WINAPI ddraw_surface4_GetPixelFormat(IDirectDrawSurface4 *iface, DDPIXELFORMAT *pixel_format)
3091 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
3093 TRACE("iface %p, pixel_format %p.\n", iface, pixel_format);
3095 return ddraw_surface7_GetPixelFormat(&surface->IDirectDrawSurface7_iface, pixel_format);
3098 static HRESULT WINAPI ddraw_surface3_GetPixelFormat(IDirectDrawSurface3 *iface, DDPIXELFORMAT *pixel_format)
3100 struct ddraw_surface *surface = impl_from_IDirectDrawSurface3(iface);
3102 TRACE("iface %p, pixel_format %p.\n", iface, pixel_format);
3104 return ddraw_surface7_GetPixelFormat(&surface->IDirectDrawSurface7_iface, pixel_format);
3107 static HRESULT WINAPI ddraw_surface2_GetPixelFormat(IDirectDrawSurface2 *iface, DDPIXELFORMAT *pixel_format)
3109 struct ddraw_surface *surface = impl_from_IDirectDrawSurface2(iface);
3111 TRACE("iface %p, pixel_format %p.\n", iface, pixel_format);
3113 return ddraw_surface7_GetPixelFormat(&surface->IDirectDrawSurface7_iface, pixel_format);
3116 static HRESULT WINAPI ddraw_surface1_GetPixelFormat(IDirectDrawSurface *iface, DDPIXELFORMAT *pixel_format)
3118 struct ddraw_surface *surface = impl_from_IDirectDrawSurface(iface);
3120 TRACE("iface %p, pixel_format %p.\n", iface, pixel_format);
3122 return ddraw_surface7_GetPixelFormat(&surface->IDirectDrawSurface7_iface, pixel_format);
3125 /*****************************************************************************
3126 * IDirectDrawSurface7::GetSurfaceDesc
3128 * Returns the description of this surface
3130 * Params:
3131 * DDSD: Address of a DDSURFACEDESC2 structure that is to be filled with the
3132 * surface desc
3134 * Returns:
3135 * DD_OK on success
3136 * DDERR_INVALIDPARAMS if DDSD is NULL
3138 *****************************************************************************/
3139 static HRESULT WINAPI ddraw_surface7_GetSurfaceDesc(IDirectDrawSurface7 *iface, DDSURFACEDESC2 *DDSD)
3141 struct ddraw_surface *surface = impl_from_IDirectDrawSurface7(iface);
3143 TRACE("iface %p, surface_desc %p.\n", iface, DDSD);
3145 if(!DDSD)
3146 return DDERR_INVALIDPARAMS;
3148 if (DDSD->dwSize != sizeof(DDSURFACEDESC2))
3150 WARN("Incorrect struct size %d, returning DDERR_INVALIDPARAMS\n",DDSD->dwSize);
3151 return DDERR_INVALIDPARAMS;
3154 wined3d_mutex_lock();
3155 DD_STRUCT_COPY_BYSIZE(DDSD, &surface->surface_desc);
3156 TRACE("Returning surface desc:\n");
3157 if (TRACE_ON(ddraw)) DDRAW_dump_surface_desc(DDSD);
3158 wined3d_mutex_unlock();
3160 return DD_OK;
3163 static HRESULT WINAPI ddraw_surface4_GetSurfaceDesc(IDirectDrawSurface4 *iface, DDSURFACEDESC2 *DDSD)
3165 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
3167 TRACE("iface %p, surface_desc %p.\n", iface, DDSD);
3169 return ddraw_surface7_GetSurfaceDesc(&surface->IDirectDrawSurface7_iface, DDSD);
3172 static HRESULT WINAPI ddraw_surface3_GetSurfaceDesc(IDirectDrawSurface3 *iface, DDSURFACEDESC *surface_desc)
3174 struct ddraw_surface *surface = impl_from_IDirectDrawSurface3(iface);
3176 TRACE("iface %p, surface_desc %p.\n", iface, surface_desc);
3178 if (!surface_desc) return DDERR_INVALIDPARAMS;
3180 if (surface_desc->dwSize != sizeof(DDSURFACEDESC))
3182 WARN("Incorrect structure size %u, returning DDERR_INVALIDPARAMS.\n", surface_desc->dwSize);
3183 return DDERR_INVALIDPARAMS;
3186 wined3d_mutex_lock();
3187 DDSD2_to_DDSD(&surface->surface_desc, surface_desc);
3188 TRACE("Returning surface desc:\n");
3189 if (TRACE_ON(ddraw))
3191 /* DDRAW_dump_surface_desc handles the smaller size */
3192 DDRAW_dump_surface_desc((DDSURFACEDESC2 *)surface_desc);
3194 wined3d_mutex_unlock();
3196 return DD_OK;
3199 static HRESULT WINAPI ddraw_surface2_GetSurfaceDesc(IDirectDrawSurface2 *iface, DDSURFACEDESC *DDSD)
3201 struct ddraw_surface *surface = impl_from_IDirectDrawSurface2(iface);
3203 TRACE("iface %p, surface_desc %p.\n", iface, DDSD);
3205 return ddraw_surface3_GetSurfaceDesc(&surface->IDirectDrawSurface3_iface, DDSD);
3208 static HRESULT WINAPI ddraw_surface1_GetSurfaceDesc(IDirectDrawSurface *iface, DDSURFACEDESC *DDSD)
3210 struct ddraw_surface *surface = impl_from_IDirectDrawSurface(iface);
3212 TRACE("iface %p, surface_desc %p.\n", iface, DDSD);
3214 return ddraw_surface3_GetSurfaceDesc(&surface->IDirectDrawSurface3_iface, DDSD);
3217 /*****************************************************************************
3218 * IDirectDrawSurface7::Initialize
3220 * Initializes the surface. This is a no-op in Wine
3222 * Params:
3223 * DD: Pointer to an DirectDraw interface
3224 * DDSD: Surface description for initialization
3226 * Returns:
3227 * DDERR_ALREADYINITIALIZED
3229 *****************************************************************************/
3230 static HRESULT WINAPI ddraw_surface7_Initialize(IDirectDrawSurface7 *iface,
3231 IDirectDraw *ddraw, DDSURFACEDESC2 *surface_desc)
3233 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface, ddraw, surface_desc);
3235 return DDERR_ALREADYINITIALIZED;
3238 static HRESULT WINAPI ddraw_surface4_Initialize(IDirectDrawSurface4 *iface,
3239 IDirectDraw *ddraw, DDSURFACEDESC2 *surface_desc)
3241 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
3243 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface, ddraw, surface_desc);
3245 return ddraw_surface7_Initialize(&surface->IDirectDrawSurface7_iface,
3246 ddraw, surface_desc);
3249 static HRESULT WINAPI ddraw_surface3_Initialize(IDirectDrawSurface3 *iface,
3250 IDirectDraw *ddraw, DDSURFACEDESC *surface_desc)
3252 struct ddraw_surface *surface = impl_from_IDirectDrawSurface3(iface);
3253 DDSURFACEDESC2 surface_desc2;
3255 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface, ddraw, surface_desc);
3257 if (surface_desc) DDSD_to_DDSD2(surface_desc, &surface_desc2);
3258 return ddraw_surface7_Initialize(&surface->IDirectDrawSurface7_iface,
3259 ddraw, surface_desc ? &surface_desc2 : NULL);
3262 static HRESULT WINAPI ddraw_surface2_Initialize(IDirectDrawSurface2 *iface,
3263 IDirectDraw *ddraw, DDSURFACEDESC *surface_desc)
3265 struct ddraw_surface *surface = impl_from_IDirectDrawSurface2(iface);
3266 DDSURFACEDESC2 surface_desc2;
3268 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface, ddraw, surface_desc);
3270 if (surface_desc) DDSD_to_DDSD2(surface_desc, &surface_desc2);
3271 return ddraw_surface7_Initialize(&surface->IDirectDrawSurface7_iface,
3272 ddraw, surface_desc ? &surface_desc2 : NULL);
3275 static HRESULT WINAPI ddraw_surface1_Initialize(IDirectDrawSurface *iface,
3276 IDirectDraw *ddraw, DDSURFACEDESC *surface_desc)
3278 struct ddraw_surface *surface = impl_from_IDirectDrawSurface(iface);
3279 DDSURFACEDESC2 surface_desc2;
3281 TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface, ddraw, surface_desc);
3283 if (surface_desc) DDSD_to_DDSD2(surface_desc, &surface_desc2);
3284 return ddraw_surface7_Initialize(&surface->IDirectDrawSurface7_iface,
3285 ddraw, surface_desc ? &surface_desc2 : NULL);
3288 /*****************************************************************************
3289 * IDirect3DTexture1::Initialize
3291 * The sdk says it's not implemented
3293 * Params:
3296 * Returns
3297 * DDERR_UNSUPPORTED
3299 *****************************************************************************/
3300 static HRESULT WINAPI d3d_texture1_Initialize(IDirect3DTexture *iface,
3301 IDirect3DDevice *device, IDirectDrawSurface *surface)
3303 TRACE("iface %p, device %p, surface %p.\n", iface, device, surface);
3305 return DDERR_UNSUPPORTED; /* Unchecked */
3308 /*****************************************************************************
3309 * IDirectDrawSurface7::IsLost
3311 * Checks if the surface is lost
3313 * Returns:
3314 * DD_OK, if the surface is usable
3315 * DDERR_ISLOST if the surface is lost
3316 * See IWineD3DSurface::IsLost for more details
3318 *****************************************************************************/
3319 static HRESULT WINAPI ddraw_surface7_IsLost(IDirectDrawSurface7 *iface)
3321 struct ddraw_surface *surface = impl_from_IDirectDrawSurface7(iface);
3322 HRESULT hr;
3324 TRACE("iface %p.\n", iface);
3326 wined3d_mutex_lock();
3327 hr = wined3d_surface_is_lost(surface->wined3d_surface);
3328 wined3d_mutex_unlock();
3330 switch(hr)
3332 /* D3D8 and 9 loose full devices, thus there's only a DEVICELOST error.
3333 * WineD3D uses the same error for surfaces
3335 case WINED3DERR_DEVICELOST: return DDERR_SURFACELOST;
3336 default: return hr;
3340 static HRESULT WINAPI ddraw_surface4_IsLost(IDirectDrawSurface4 *iface)
3342 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
3344 TRACE("iface %p.\n", iface);
3346 return ddraw_surface7_IsLost(&surface->IDirectDrawSurface7_iface);
3349 static HRESULT WINAPI ddraw_surface3_IsLost(IDirectDrawSurface3 *iface)
3351 struct ddraw_surface *surface = impl_from_IDirectDrawSurface3(iface);
3353 TRACE("iface %p.\n", iface);
3355 return ddraw_surface7_IsLost(&surface->IDirectDrawSurface7_iface);
3358 static HRESULT WINAPI ddraw_surface2_IsLost(IDirectDrawSurface2 *iface)
3360 struct ddraw_surface *surface = impl_from_IDirectDrawSurface2(iface);
3362 TRACE("iface %p.\n", iface);
3364 return ddraw_surface7_IsLost(&surface->IDirectDrawSurface7_iface);
3367 static HRESULT WINAPI ddraw_surface1_IsLost(IDirectDrawSurface *iface)
3369 struct ddraw_surface *surface = impl_from_IDirectDrawSurface(iface);
3371 TRACE("iface %p.\n", iface);
3373 return ddraw_surface7_IsLost(&surface->IDirectDrawSurface7_iface);
3376 /*****************************************************************************
3377 * IDirectDrawSurface7::Restore
3379 * Restores a lost surface. This makes the surface usable again, but
3380 * doesn't reload its old contents
3382 * Returns:
3383 * DD_OK on success
3384 * See IWineD3DSurface::Restore for more details
3386 *****************************************************************************/
3387 static HRESULT WINAPI ddraw_surface7_Restore(IDirectDrawSurface7 *iface)
3389 struct ddraw_surface *surface = impl_from_IDirectDrawSurface7(iface);
3390 HRESULT hr;
3392 TRACE("iface %p.\n", iface);
3394 wined3d_mutex_lock();
3395 hr = wined3d_surface_restore(surface->wined3d_surface);
3396 wined3d_mutex_unlock();
3398 return hr;
3401 static HRESULT WINAPI ddraw_surface4_Restore(IDirectDrawSurface4 *iface)
3403 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
3405 TRACE("iface %p.\n", iface);
3407 return ddraw_surface7_Restore(&surface->IDirectDrawSurface7_iface);
3410 static HRESULT WINAPI ddraw_surface3_Restore(IDirectDrawSurface3 *iface)
3412 struct ddraw_surface *surface = impl_from_IDirectDrawSurface3(iface);
3414 TRACE("iface %p.\n", iface);
3416 return ddraw_surface7_Restore(&surface->IDirectDrawSurface7_iface);
3419 static HRESULT WINAPI ddraw_surface2_Restore(IDirectDrawSurface2 *iface)
3421 struct ddraw_surface *surface = impl_from_IDirectDrawSurface2(iface);
3423 TRACE("iface %p.\n", iface);
3425 return ddraw_surface7_Restore(&surface->IDirectDrawSurface7_iface);
3428 static HRESULT WINAPI ddraw_surface1_Restore(IDirectDrawSurface *iface)
3430 struct ddraw_surface *surface = impl_from_IDirectDrawSurface(iface);
3432 TRACE("iface %p.\n", iface);
3434 return ddraw_surface7_Restore(&surface->IDirectDrawSurface7_iface);
3437 /*****************************************************************************
3438 * IDirectDrawSurface7::SetOverlayPosition
3440 * Changes the display coordinates of an overlay surface
3442 * Params:
3443 * X:
3444 * Y:
3446 * Returns:
3447 * DDERR_NOTAOVERLAYSURFACE, because we don't support overlays right now
3448 *****************************************************************************/
3449 static HRESULT WINAPI ddraw_surface7_SetOverlayPosition(IDirectDrawSurface7 *iface, LONG X, LONG Y)
3451 struct ddraw_surface *surface = impl_from_IDirectDrawSurface7(iface);
3452 HRESULT hr;
3454 TRACE("iface %p, x %d, y %d.\n", iface, X, Y);
3456 wined3d_mutex_lock();
3457 hr = wined3d_surface_set_overlay_position(surface->wined3d_surface, X, Y);
3458 wined3d_mutex_unlock();
3460 return hr;
3463 static HRESULT WINAPI ddraw_surface4_SetOverlayPosition(IDirectDrawSurface4 *iface, LONG x, LONG y)
3465 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
3467 TRACE("iface %p, x %d, y %d.\n", iface, x, y);
3469 return ddraw_surface7_SetOverlayPosition(&surface->IDirectDrawSurface7_iface, x, y);
3472 static HRESULT WINAPI ddraw_surface3_SetOverlayPosition(IDirectDrawSurface3 *iface, LONG x, LONG y)
3474 struct ddraw_surface *surface = impl_from_IDirectDrawSurface3(iface);
3476 TRACE("iface %p, x %d, y %d.\n", iface, x, y);
3478 return ddraw_surface7_SetOverlayPosition(&surface->IDirectDrawSurface7_iface, x, y);
3481 static HRESULT WINAPI ddraw_surface2_SetOverlayPosition(IDirectDrawSurface2 *iface, LONG x, LONG y)
3483 struct ddraw_surface *surface = impl_from_IDirectDrawSurface2(iface);
3485 TRACE("iface %p, x %d, y %d.\n", iface, x, y);
3487 return ddraw_surface7_SetOverlayPosition(&surface->IDirectDrawSurface7_iface, x, y);
3490 static HRESULT WINAPI ddraw_surface1_SetOverlayPosition(IDirectDrawSurface *iface, LONG x, LONG y)
3492 struct ddraw_surface *surface = impl_from_IDirectDrawSurface(iface);
3494 TRACE("iface %p, x %d, y %d.\n", iface, x, y);
3496 return ddraw_surface7_SetOverlayPosition(&surface->IDirectDrawSurface7_iface, x, y);
3499 /*****************************************************************************
3500 * IDirectDrawSurface7::UpdateOverlay
3502 * Modifies the attributes of an overlay surface.
3504 * Params:
3505 * SrcRect: The section of the source being used for the overlay
3506 * DstSurface: Address of the surface that is overlaid
3507 * DstRect: Place of the overlay
3508 * Flags: some DDOVER_* flags
3510 * Returns:
3511 * DDERR_UNSUPPORTED, because we don't support overlays
3513 *****************************************************************************/
3514 static HRESULT WINAPI ddraw_surface7_UpdateOverlay(IDirectDrawSurface7 *iface, RECT *SrcRect,
3515 IDirectDrawSurface7 *DstSurface, RECT *DstRect, DWORD Flags, DDOVERLAYFX *FX)
3517 struct ddraw_surface *src_impl = impl_from_IDirectDrawSurface7(iface);
3518 struct ddraw_surface *dst_impl = unsafe_impl_from_IDirectDrawSurface7(DstSurface);
3519 HRESULT hr;
3521 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3522 iface, wine_dbgstr_rect(SrcRect), DstSurface, wine_dbgstr_rect(DstRect), Flags, FX);
3524 wined3d_mutex_lock();
3525 hr = wined3d_surface_update_overlay(src_impl->wined3d_surface, SrcRect,
3526 dst_impl ? dst_impl->wined3d_surface : NULL, DstRect, Flags, (WINEDDOVERLAYFX *)FX);
3527 wined3d_mutex_unlock();
3529 switch(hr) {
3530 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
3531 case WINEDDERR_NOTAOVERLAYSURFACE: return DDERR_NOTAOVERLAYSURFACE;
3532 case WINEDDERR_OVERLAYNOTVISIBLE: return DDERR_OVERLAYNOTVISIBLE;
3533 default:
3534 return hr;
3538 static HRESULT WINAPI ddraw_surface4_UpdateOverlay(IDirectDrawSurface4 *iface, RECT *src_rect,
3539 IDirectDrawSurface4 *dst_surface, RECT *dst_rect, DWORD flags, DDOVERLAYFX *fx)
3541 struct ddraw_surface *src_impl = impl_from_IDirectDrawSurface4(iface);
3542 struct ddraw_surface *dst_impl = unsafe_impl_from_IDirectDrawSurface4(dst_surface);
3544 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3545 iface, wine_dbgstr_rect(src_rect), dst_surface, wine_dbgstr_rect(dst_rect), flags, fx);
3547 return ddraw_surface7_UpdateOverlay(&src_impl->IDirectDrawSurface7_iface, src_rect,
3548 dst_impl ? &dst_impl->IDirectDrawSurface7_iface : NULL, dst_rect, flags, fx);
3551 static HRESULT WINAPI ddraw_surface3_UpdateOverlay(IDirectDrawSurface3 *iface, RECT *src_rect,
3552 IDirectDrawSurface3 *dst_surface, RECT *dst_rect, DWORD flags, DDOVERLAYFX *fx)
3554 struct ddraw_surface *src_impl = impl_from_IDirectDrawSurface3(iface);
3555 struct ddraw_surface *dst_impl = unsafe_impl_from_IDirectDrawSurface3(dst_surface);
3557 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3558 iface, wine_dbgstr_rect(src_rect), dst_surface, wine_dbgstr_rect(dst_rect), flags, fx);
3560 return ddraw_surface7_UpdateOverlay(&src_impl->IDirectDrawSurface7_iface, src_rect,
3561 dst_impl ? &dst_impl->IDirectDrawSurface7_iface : NULL, dst_rect, flags, fx);
3564 static HRESULT WINAPI ddraw_surface2_UpdateOverlay(IDirectDrawSurface2 *iface, RECT *src_rect,
3565 IDirectDrawSurface2 *dst_surface, RECT *dst_rect, DWORD flags, DDOVERLAYFX *fx)
3567 struct ddraw_surface *src_impl = impl_from_IDirectDrawSurface2(iface);
3568 struct ddraw_surface *dst_impl = unsafe_impl_from_IDirectDrawSurface2(dst_surface);
3570 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3571 iface, wine_dbgstr_rect(src_rect), dst_surface, wine_dbgstr_rect(dst_rect), flags, fx);
3573 return ddraw_surface7_UpdateOverlay(&src_impl->IDirectDrawSurface7_iface, src_rect,
3574 dst_impl ? &dst_impl->IDirectDrawSurface7_iface : NULL, dst_rect, flags, fx);
3577 static HRESULT WINAPI ddraw_surface1_UpdateOverlay(IDirectDrawSurface *iface, RECT *src_rect,
3578 IDirectDrawSurface *dst_surface, RECT *dst_rect, DWORD flags, DDOVERLAYFX *fx)
3580 struct ddraw_surface *src_impl = impl_from_IDirectDrawSurface(iface);
3581 struct ddraw_surface *dst_impl = unsafe_impl_from_IDirectDrawSurface(dst_surface);
3583 TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
3584 iface, wine_dbgstr_rect(src_rect), dst_surface, wine_dbgstr_rect(dst_rect), flags, fx);
3586 return ddraw_surface7_UpdateOverlay(&src_impl->IDirectDrawSurface7_iface, src_rect,
3587 dst_impl ? &dst_impl->IDirectDrawSurface7_iface : NULL, dst_rect, flags, fx);
3590 /*****************************************************************************
3591 * IDirectDrawSurface7::UpdateOverlayDisplay
3593 * The DX7 sdk says that it's not implemented
3595 * Params:
3596 * Flags: ?
3598 * Returns: DDERR_UNSUPPORTED, because we don't support overlays
3600 *****************************************************************************/
3601 static HRESULT WINAPI ddraw_surface7_UpdateOverlayDisplay(IDirectDrawSurface7 *iface, DWORD Flags)
3603 TRACE("iface %p, flags %#x.\n", iface, Flags);
3605 return DDERR_UNSUPPORTED;
3608 static HRESULT WINAPI ddraw_surface4_UpdateOverlayDisplay(IDirectDrawSurface4 *iface, DWORD flags)
3610 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
3612 TRACE("iface %p, flags %#x.\n", iface, flags);
3614 return ddraw_surface7_UpdateOverlayDisplay(&surface->IDirectDrawSurface7_iface, flags);
3617 static HRESULT WINAPI ddraw_surface3_UpdateOverlayDisplay(IDirectDrawSurface3 *iface, DWORD flags)
3619 struct ddraw_surface *surface = impl_from_IDirectDrawSurface3(iface);
3621 TRACE("iface %p, flags %#x.\n", iface, flags);
3623 return ddraw_surface7_UpdateOverlayDisplay(&surface->IDirectDrawSurface7_iface, flags);
3626 static HRESULT WINAPI ddraw_surface2_UpdateOverlayDisplay(IDirectDrawSurface2 *iface, DWORD flags)
3628 struct ddraw_surface *surface = impl_from_IDirectDrawSurface2(iface);
3630 TRACE("iface %p, flags %#x.\n", iface, flags);
3632 return ddraw_surface7_UpdateOverlayDisplay(&surface->IDirectDrawSurface7_iface, flags);
3635 static HRESULT WINAPI ddraw_surface1_UpdateOverlayDisplay(IDirectDrawSurface *iface, DWORD flags)
3637 struct ddraw_surface *surface = impl_from_IDirectDrawSurface(iface);
3639 TRACE("iface %p, flags %#x.\n", iface, flags);
3641 return ddraw_surface7_UpdateOverlayDisplay(&surface->IDirectDrawSurface7_iface, flags);
3644 /*****************************************************************************
3645 * IDirectDrawSurface7::UpdateOverlayZOrder
3647 * Sets an overlay's Z order
3649 * Params:
3650 * Flags: DDOVERZ_* flags
3651 * DDSRef: Defines the relative position in the overlay chain
3653 * Returns:
3654 * DDERR_NOTOVERLAYSURFACE, because we don't support overlays
3656 *****************************************************************************/
3657 static HRESULT WINAPI ddraw_surface7_UpdateOverlayZOrder(IDirectDrawSurface7 *iface,
3658 DWORD Flags, IDirectDrawSurface7 *DDSRef)
3660 struct ddraw_surface *surface = impl_from_IDirectDrawSurface7(iface);
3661 struct ddraw_surface *reference_impl = unsafe_impl_from_IDirectDrawSurface7(DDSRef);
3662 HRESULT hr;
3664 TRACE("iface %p, flags %#x, reference %p.\n", iface, Flags, DDSRef);
3666 wined3d_mutex_lock();
3667 hr = wined3d_surface_update_overlay_z_order(surface->wined3d_surface,
3668 Flags, reference_impl ? reference_impl->wined3d_surface : NULL);
3669 wined3d_mutex_unlock();
3671 return hr;
3674 static HRESULT WINAPI ddraw_surface4_UpdateOverlayZOrder(IDirectDrawSurface4 *iface,
3675 DWORD flags, IDirectDrawSurface4 *reference)
3677 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
3678 struct ddraw_surface *reference_impl = unsafe_impl_from_IDirectDrawSurface4(reference);
3680 TRACE("iface %p, flags %#x, reference %p.\n", iface, flags, reference);
3682 return ddraw_surface7_UpdateOverlayZOrder(&surface->IDirectDrawSurface7_iface, flags,
3683 reference_impl ? &reference_impl->IDirectDrawSurface7_iface : NULL);
3686 static HRESULT WINAPI ddraw_surface3_UpdateOverlayZOrder(IDirectDrawSurface3 *iface,
3687 DWORD flags, IDirectDrawSurface3 *reference)
3689 struct ddraw_surface *surface = impl_from_IDirectDrawSurface3(iface);
3690 struct ddraw_surface *reference_impl = unsafe_impl_from_IDirectDrawSurface3(reference);
3692 TRACE("iface %p, flags %#x, reference %p.\n", iface, flags, reference);
3694 return ddraw_surface7_UpdateOverlayZOrder(&surface->IDirectDrawSurface7_iface, flags,
3695 reference_impl ? &reference_impl->IDirectDrawSurface7_iface : NULL);
3698 static HRESULT WINAPI ddraw_surface2_UpdateOverlayZOrder(IDirectDrawSurface2 *iface,
3699 DWORD flags, IDirectDrawSurface2 *reference)
3701 struct ddraw_surface *surface = impl_from_IDirectDrawSurface2(iface);
3702 struct ddraw_surface *reference_impl = unsafe_impl_from_IDirectDrawSurface2(reference);
3704 TRACE("iface %p, flags %#x, reference %p.\n", iface, flags, reference);
3706 return ddraw_surface7_UpdateOverlayZOrder(&surface->IDirectDrawSurface7_iface, flags,
3707 reference_impl ? &reference_impl->IDirectDrawSurface7_iface : NULL);
3710 static HRESULT WINAPI ddraw_surface1_UpdateOverlayZOrder(IDirectDrawSurface *iface,
3711 DWORD flags, IDirectDrawSurface *reference)
3713 struct ddraw_surface *surface = impl_from_IDirectDrawSurface(iface);
3714 struct ddraw_surface *reference_impl = unsafe_impl_from_IDirectDrawSurface(reference);
3716 TRACE("iface %p, flags %#x, reference %p.\n", iface, flags, reference);
3718 return ddraw_surface7_UpdateOverlayZOrder(&surface->IDirectDrawSurface7_iface, flags,
3719 reference_impl ? &reference_impl->IDirectDrawSurface7_iface : NULL);
3722 /*****************************************************************************
3723 * IDirectDrawSurface7::GetDDInterface
3725 * Returns the IDirectDraw7 interface pointer of the DirectDraw object this
3726 * surface belongs to
3728 * Params:
3729 * DD: Address to write the interface pointer to
3731 * Returns:
3732 * DD_OK on success
3733 * DDERR_INVALIDPARAMS if DD is NULL
3735 *****************************************************************************/
3736 static HRESULT WINAPI ddraw_surface7_GetDDInterface(IDirectDrawSurface7 *iface, void **DD)
3738 struct ddraw_surface *This = impl_from_IDirectDrawSurface7(iface);
3740 TRACE("iface %p, ddraw %p.\n", iface, DD);
3742 if(!DD)
3743 return DDERR_INVALIDPARAMS;
3745 switch(This->version)
3747 case 7:
3748 *DD = &This->ddraw->IDirectDraw7_iface;
3749 break;
3751 case 4:
3752 *DD = &This->ddraw->IDirectDraw4_iface;
3753 break;
3755 case 2:
3756 *DD = &This->ddraw->IDirectDraw2_iface;
3757 break;
3759 case 1:
3760 *DD = &This->ddraw->IDirectDraw_iface;
3761 break;
3764 IUnknown_AddRef((IUnknown *)*DD);
3766 return DD_OK;
3769 static HRESULT WINAPI ddraw_surface4_GetDDInterface(IDirectDrawSurface4 *iface, void **ddraw)
3771 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
3773 TRACE("iface %p, ddraw %p.\n", iface, ddraw);
3775 return ddraw_surface7_GetDDInterface(&surface->IDirectDrawSurface7_iface, ddraw);
3778 static HRESULT WINAPI ddraw_surface3_GetDDInterface(IDirectDrawSurface3 *iface, void **ddraw)
3780 struct ddraw_surface *surface = impl_from_IDirectDrawSurface3(iface);
3782 TRACE("iface %p, ddraw %p.\n", iface, ddraw);
3784 return ddraw_surface7_GetDDInterface(&surface->IDirectDrawSurface7_iface, ddraw);
3787 static HRESULT WINAPI ddraw_surface2_GetDDInterface(IDirectDrawSurface2 *iface, void **ddraw)
3789 struct ddraw_surface *surface = impl_from_IDirectDrawSurface2(iface);
3791 TRACE("iface %p, ddraw %p.\n", iface, ddraw);
3793 return ddraw_surface7_GetDDInterface(&surface->IDirectDrawSurface7_iface, ddraw);
3796 /* This seems also windows implementation specific - I don't think WineD3D needs this */
3797 static HRESULT WINAPI ddraw_surface7_ChangeUniquenessValue(IDirectDrawSurface7 *iface)
3799 struct ddraw_surface *This = impl_from_IDirectDrawSurface7(iface);
3800 volatile struct ddraw_surface* vThis = This;
3802 TRACE("iface %p.\n", iface);
3804 wined3d_mutex_lock();
3805 /* A uniqueness value of 0 is apparently special.
3806 * This needs to be checked.
3807 * TODO: Write tests for this code and check if the volatile, interlocked stuff is really needed
3809 while (1) {
3810 DWORD old_uniqueness_value = vThis->uniqueness_value;
3811 DWORD new_uniqueness_value = old_uniqueness_value+1;
3813 if (old_uniqueness_value == 0) break;
3814 if (new_uniqueness_value == 0) new_uniqueness_value = 1;
3816 if (InterlockedCompareExchange((LONG*)&vThis->uniqueness_value,
3817 old_uniqueness_value,
3818 new_uniqueness_value)
3819 == old_uniqueness_value)
3820 break;
3823 wined3d_mutex_unlock();
3825 return DD_OK;
3828 static HRESULT WINAPI ddraw_surface4_ChangeUniquenessValue(IDirectDrawSurface4 *iface)
3830 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
3832 TRACE("iface %p.\n", iface);
3834 return ddraw_surface7_ChangeUniquenessValue(&surface->IDirectDrawSurface7_iface);
3837 static HRESULT WINAPI ddraw_surface7_GetUniquenessValue(IDirectDrawSurface7 *iface, DWORD *pValue)
3839 struct ddraw_surface *surface = impl_from_IDirectDrawSurface7(iface);
3841 TRACE("iface %p, value %p.\n", iface, pValue);
3843 wined3d_mutex_lock();
3844 *pValue = surface->uniqueness_value;
3845 wined3d_mutex_unlock();
3847 return DD_OK;
3850 static HRESULT WINAPI ddraw_surface4_GetUniquenessValue(IDirectDrawSurface4 *iface, DWORD *pValue)
3852 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
3854 TRACE("iface %p, value %p.\n", iface, pValue);
3856 return ddraw_surface7_GetUniquenessValue(&surface->IDirectDrawSurface7_iface, pValue);
3859 /*****************************************************************************
3860 * IDirectDrawSurface7::SetLOD
3862 * Sets the level of detail of a texture
3864 * Params:
3865 * MaxLOD: LOD to set
3867 * Returns:
3868 * DD_OK on success
3869 * DDERR_INVALIDOBJECT if the surface is invalid for this method
3871 *****************************************************************************/
3872 static HRESULT WINAPI ddraw_surface7_SetLOD(IDirectDrawSurface7 *iface, DWORD MaxLOD)
3874 struct ddraw_surface *surface = impl_from_IDirectDrawSurface7(iface);
3875 HRESULT hr;
3877 TRACE("iface %p, lod %u.\n", iface, MaxLOD);
3879 wined3d_mutex_lock();
3880 if (!(surface->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_TEXTUREMANAGE))
3882 wined3d_mutex_unlock();
3883 return DDERR_INVALIDOBJECT;
3886 if (!surface->wined3d_texture)
3888 ERR("The ddraw surface has no wined3d texture.\n");
3889 wined3d_mutex_unlock();
3890 return DDERR_INVALIDOBJECT;
3893 hr = wined3d_texture_set_lod(surface->wined3d_texture, MaxLOD);
3894 wined3d_mutex_unlock();
3896 return hr;
3899 /*****************************************************************************
3900 * IDirectDrawSurface7::GetLOD
3902 * Returns the level of detail of a Direct3D texture
3904 * Params:
3905 * MaxLOD: Address to write the LOD to
3907 * Returns:
3908 * DD_OK on success
3909 * DDERR_INVALIDPARAMS if MaxLOD is NULL
3910 * DDERR_INVALIDOBJECT if the surface is invalid for this method
3912 *****************************************************************************/
3913 static HRESULT WINAPI ddraw_surface7_GetLOD(IDirectDrawSurface7 *iface, DWORD *MaxLOD)
3915 struct ddraw_surface *surface = impl_from_IDirectDrawSurface7(iface);
3917 TRACE("iface %p, lod %p.\n", iface, MaxLOD);
3919 if(!MaxLOD)
3920 return DDERR_INVALIDPARAMS;
3922 wined3d_mutex_lock();
3923 if (!(surface->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_TEXTUREMANAGE))
3925 wined3d_mutex_unlock();
3926 return DDERR_INVALIDOBJECT;
3929 *MaxLOD = wined3d_texture_get_lod(surface->wined3d_texture);
3930 wined3d_mutex_unlock();
3932 return DD_OK;
3935 /*****************************************************************************
3936 * IDirectDrawSurface7::BltFast
3938 * Performs a fast Blit.
3940 * Params:
3941 * dstx: The x coordinate to blit to on the destination
3942 * dsty: The y coordinate to blit to on the destination
3943 * Source: The source surface
3944 * rsrc: The source rectangle
3945 * trans: Type of transfer. Some DDBLTFAST_* flags
3947 * Returns:
3948 * DD_OK on success
3949 * For more details, see IWineD3DSurface::BltFast
3951 *****************************************************************************/
3952 static HRESULT WINAPI ddraw_surface7_BltFast(IDirectDrawSurface7 *iface, DWORD dstx, DWORD dsty,
3953 IDirectDrawSurface7 *Source, RECT *rsrc, DWORD trans)
3955 struct ddraw_surface *This = impl_from_IDirectDrawSurface7(iface);
3956 struct ddraw_surface *src = unsafe_impl_from_IDirectDrawSurface7(Source);
3957 DWORD src_w, src_h, dst_w, dst_h;
3958 HRESULT hr = DD_OK;
3959 DWORD flags = 0;
3960 RECT dst_rect;
3962 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
3963 iface, dstx, dsty, Source, wine_dbgstr_rect(rsrc), trans);
3965 dst_w = This->surface_desc.dwWidth;
3966 dst_h = This->surface_desc.dwHeight;
3968 /* Source must be != NULL, This is not checked by windows. Windows happily throws a 0xc0000005
3969 * in that case
3971 if(rsrc)
3973 src_w = rsrc->right - rsrc->left;
3974 src_h = rsrc->bottom - rsrc->top;
3976 else
3978 src_w = src->surface_desc.dwWidth;
3979 src_h = src->surface_desc.dwHeight;
3982 if (src_w > dst_w || dstx > dst_w - src_w
3983 || src_h > dst_h || dsty > dst_h - src_h)
3985 WARN("Destination area out of bounds, returning DDERR_INVALIDRECT.\n");
3986 return DDERR_INVALIDRECT;
3989 SetRect(&dst_rect, dstx, dsty, dstx + src_w, dsty + src_h);
3990 if (trans & DDBLTFAST_SRCCOLORKEY)
3991 flags |= WINEDDBLT_KEYSRC;
3992 if (trans & DDBLTFAST_DESTCOLORKEY)
3993 flags |= WINEDDBLT_KEYDEST;
3994 if (trans & DDBLTFAST_WAIT)
3995 flags |= WINEDDBLT_WAIT;
3996 if (trans & DDBLTFAST_DONOTWAIT)
3997 flags |= WINEDDBLT_DONOTWAIT;
3999 wined3d_mutex_lock();
4000 if (This->clipper)
4002 wined3d_mutex_unlock();
4003 WARN("Destination surface has a clipper set, returning DDERR_BLTFASTCANTCLIP.\n");
4004 return DDERR_BLTFASTCANTCLIP;
4007 if (src->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER)
4008 hr = ddraw_surface_update_frontbuffer(src, rsrc, TRUE);
4009 if (SUCCEEDED(hr))
4010 hr = wined3d_surface_blt(This->wined3d_surface, &dst_rect,
4011 src->wined3d_surface, rsrc, flags, NULL, WINED3D_TEXF_POINT);
4012 if (SUCCEEDED(hr) && (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER))
4013 hr = ddraw_surface_update_frontbuffer(This, &dst_rect, FALSE);
4014 wined3d_mutex_unlock();
4016 switch(hr)
4018 case WINED3DERR_NOTAVAILABLE: return DDERR_UNSUPPORTED;
4019 case WINED3DERR_WRONGTEXTUREFORMAT: return DDERR_INVALIDPIXELFORMAT;
4020 default: return hr;
4024 static HRESULT WINAPI ddraw_surface4_BltFast(IDirectDrawSurface4 *iface, DWORD dst_x, DWORD dst_y,
4025 IDirectDrawSurface4 *src_surface, RECT *src_rect, DWORD flags)
4027 struct ddraw_surface *dst_impl = impl_from_IDirectDrawSurface4(iface);
4028 struct ddraw_surface *src_impl = unsafe_impl_from_IDirectDrawSurface4(src_surface);
4030 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4031 iface, dst_x, dst_y, src_surface, wine_dbgstr_rect(src_rect), flags);
4033 return ddraw_surface7_BltFast(&dst_impl->IDirectDrawSurface7_iface, dst_x, dst_y,
4034 src_impl ? &src_impl->IDirectDrawSurface7_iface : NULL, src_rect, flags);
4037 static HRESULT WINAPI ddraw_surface3_BltFast(IDirectDrawSurface3 *iface, DWORD dst_x, DWORD dst_y,
4038 IDirectDrawSurface3 *src_surface, RECT *src_rect, DWORD flags)
4040 struct ddraw_surface *dst_impl = impl_from_IDirectDrawSurface3(iface);
4041 struct ddraw_surface *src_impl = unsafe_impl_from_IDirectDrawSurface3(src_surface);
4043 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4044 iface, dst_x, dst_y, src_surface, wine_dbgstr_rect(src_rect), flags);
4046 return ddraw_surface7_BltFast(&dst_impl->IDirectDrawSurface7_iface, dst_x, dst_y,
4047 src_impl ? &src_impl->IDirectDrawSurface7_iface : NULL, src_rect, flags);
4050 static HRESULT WINAPI ddraw_surface2_BltFast(IDirectDrawSurface2 *iface, DWORD dst_x, DWORD dst_y,
4051 IDirectDrawSurface2 *src_surface, RECT *src_rect, DWORD flags)
4053 struct ddraw_surface *dst_impl = impl_from_IDirectDrawSurface2(iface);
4054 struct ddraw_surface *src_impl = unsafe_impl_from_IDirectDrawSurface2(src_surface);
4056 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4057 iface, dst_x, dst_y, src_surface, wine_dbgstr_rect(src_rect), flags);
4059 return ddraw_surface7_BltFast(&dst_impl->IDirectDrawSurface7_iface, dst_x, dst_y,
4060 src_impl ? &src_impl->IDirectDrawSurface7_iface : NULL, src_rect, flags);
4063 static HRESULT WINAPI ddraw_surface1_BltFast(IDirectDrawSurface *iface, DWORD dst_x, DWORD dst_y,
4064 IDirectDrawSurface *src_surface, RECT *src_rect, DWORD flags)
4066 struct ddraw_surface *dst_impl = impl_from_IDirectDrawSurface(iface);
4067 struct ddraw_surface *src_impl = unsafe_impl_from_IDirectDrawSurface(src_surface);
4069 TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n",
4070 iface, dst_x, dst_y, src_surface, wine_dbgstr_rect(src_rect), flags);
4072 return ddraw_surface7_BltFast(&dst_impl->IDirectDrawSurface7_iface, dst_x, dst_y,
4073 src_impl ? &src_impl->IDirectDrawSurface7_iface : NULL, src_rect, flags);
4076 /*****************************************************************************
4077 * IDirectDrawSurface7::GetClipper
4079 * Returns the IDirectDrawClipper interface of the clipper assigned to this
4080 * surface
4082 * Params:
4083 * Clipper: Address to store the interface pointer at
4085 * Returns:
4086 * DD_OK on success
4087 * DDERR_INVALIDPARAMS if Clipper is NULL
4088 * DDERR_NOCLIPPERATTACHED if there's no clipper attached
4090 *****************************************************************************/
4091 static HRESULT WINAPI ddraw_surface7_GetClipper(IDirectDrawSurface7 *iface, IDirectDrawClipper **Clipper)
4093 struct ddraw_surface *surface = impl_from_IDirectDrawSurface7(iface);
4095 TRACE("iface %p, clipper %p.\n", iface, Clipper);
4097 if (!Clipper)
4098 return DDERR_INVALIDPARAMS;
4100 wined3d_mutex_lock();
4101 if (!surface->clipper)
4103 wined3d_mutex_unlock();
4104 return DDERR_NOCLIPPERATTACHED;
4107 *Clipper = (IDirectDrawClipper *)surface->clipper;
4108 IDirectDrawClipper_AddRef(*Clipper);
4109 wined3d_mutex_unlock();
4111 return DD_OK;
4114 static HRESULT WINAPI ddraw_surface4_GetClipper(IDirectDrawSurface4 *iface, IDirectDrawClipper **clipper)
4116 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
4118 TRACE("iface %p, clipper %p.\n", iface, clipper);
4120 return ddraw_surface7_GetClipper(&surface->IDirectDrawSurface7_iface, clipper);
4123 static HRESULT WINAPI ddraw_surface3_GetClipper(IDirectDrawSurface3 *iface, IDirectDrawClipper **clipper)
4125 struct ddraw_surface *surface = impl_from_IDirectDrawSurface3(iface);
4127 TRACE("iface %p, clipper %p.\n", iface, clipper);
4129 return ddraw_surface7_GetClipper(&surface->IDirectDrawSurface7_iface, clipper);
4132 static HRESULT WINAPI ddraw_surface2_GetClipper(IDirectDrawSurface2 *iface, IDirectDrawClipper **clipper)
4134 struct ddraw_surface *surface = impl_from_IDirectDrawSurface2(iface);
4136 TRACE("iface %p, clipper %p.\n", iface, clipper);
4138 return ddraw_surface7_GetClipper(&surface->IDirectDrawSurface7_iface, clipper);
4141 static HRESULT WINAPI ddraw_surface1_GetClipper(IDirectDrawSurface *iface, IDirectDrawClipper **clipper)
4143 struct ddraw_surface *surface = impl_from_IDirectDrawSurface(iface);
4145 TRACE("iface %p, clipper %p.\n", iface, clipper);
4147 return ddraw_surface7_GetClipper(&surface->IDirectDrawSurface7_iface, clipper);
4150 /*****************************************************************************
4151 * IDirectDrawSurface7::SetClipper
4153 * Sets a clipper for the surface
4155 * Params:
4156 * Clipper: IDirectDrawClipper interface of the clipper to set
4158 * Returns:
4159 * DD_OK on success
4161 *****************************************************************************/
4162 static HRESULT WINAPI ddraw_surface7_SetClipper(IDirectDrawSurface7 *iface,
4163 IDirectDrawClipper *iclipper)
4165 struct ddraw_surface *This = impl_from_IDirectDrawSurface7(iface);
4166 struct ddraw_clipper *clipper = unsafe_impl_from_IDirectDrawClipper(iclipper);
4167 struct ddraw_clipper *old_clipper = This->clipper;
4168 HWND clipWindow;
4170 TRACE("iface %p, clipper %p.\n", iface, iclipper);
4172 wined3d_mutex_lock();
4173 if (clipper == This->clipper)
4175 wined3d_mutex_unlock();
4176 return DD_OK;
4179 This->clipper = clipper;
4181 if (clipper != NULL)
4182 IDirectDrawClipper_AddRef(iclipper);
4183 if (old_clipper)
4184 IDirectDrawClipper_Release(&old_clipper->IDirectDrawClipper_iface);
4186 if ((This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) && This->ddraw->wined3d_swapchain)
4188 clipWindow = NULL;
4189 if(clipper) {
4190 IDirectDrawClipper_GetHWnd(iclipper, &clipWindow);
4193 if (clipWindow)
4195 wined3d_swapchain_set_window(This->ddraw->wined3d_swapchain, clipWindow);
4196 ddraw_set_swapchain_window(This->ddraw, clipWindow);
4198 else
4200 wined3d_swapchain_set_window(This->ddraw->wined3d_swapchain, This->ddraw->d3d_window);
4201 ddraw_set_swapchain_window(This->ddraw, This->ddraw->dest_window);
4205 wined3d_mutex_unlock();
4207 return DD_OK;
4210 static HRESULT WINAPI ddraw_surface4_SetClipper(IDirectDrawSurface4 *iface, IDirectDrawClipper *clipper)
4212 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
4214 TRACE("iface %p, clipper %p.\n", iface, clipper);
4216 return ddraw_surface7_SetClipper(&surface->IDirectDrawSurface7_iface, clipper);
4219 static HRESULT WINAPI ddraw_surface3_SetClipper(IDirectDrawSurface3 *iface, IDirectDrawClipper *clipper)
4221 struct ddraw_surface *surface = impl_from_IDirectDrawSurface3(iface);
4223 TRACE("iface %p, clipper %p.\n", iface, clipper);
4225 return ddraw_surface7_SetClipper(&surface->IDirectDrawSurface7_iface, clipper);
4228 static HRESULT WINAPI ddraw_surface2_SetClipper(IDirectDrawSurface2 *iface, IDirectDrawClipper *clipper)
4230 struct ddraw_surface *surface = impl_from_IDirectDrawSurface2(iface);
4232 TRACE("iface %p, clipper %p.\n", iface, clipper);
4234 return ddraw_surface7_SetClipper(&surface->IDirectDrawSurface7_iface, clipper);
4237 static HRESULT WINAPI ddraw_surface1_SetClipper(IDirectDrawSurface *iface, IDirectDrawClipper *clipper)
4239 struct ddraw_surface *surface = impl_from_IDirectDrawSurface(iface);
4241 TRACE("iface %p, clipper %p.\n", iface, clipper);
4243 return ddraw_surface7_SetClipper(&surface->IDirectDrawSurface7_iface, clipper);
4246 /*****************************************************************************
4247 * IDirectDrawSurface7::SetSurfaceDesc
4249 * Sets the surface description. It can override the pixel format, the surface
4250 * memory, ...
4251 * It's not really tested.
4253 * Params:
4254 * DDSD: Pointer to the new surface description to set
4255 * Flags: Some flags
4257 * Returns:
4258 * DD_OK on success
4259 * DDERR_INVALIDPARAMS if DDSD is NULL
4261 *****************************************************************************/
4262 static HRESULT WINAPI ddraw_surface7_SetSurfaceDesc(IDirectDrawSurface7 *iface, DDSURFACEDESC2 *DDSD, DWORD Flags)
4264 struct ddraw_surface *This = impl_from_IDirectDrawSurface7(iface);
4265 HRESULT hr;
4266 const DWORD allowed_flags = DDSD_LPSURFACE | DDSD_PIXELFORMAT | DDSD_WIDTH
4267 | DDSD_HEIGHT | DDSD_PITCH | DDSD_CAPS;
4268 enum wined3d_format_id format_id;
4269 BOOL update_wined3d = FALSE;
4270 UINT width, height;
4272 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface, DDSD, Flags);
4274 if (!DDSD)
4276 WARN("DDSD is NULL, returning DDERR_INVALIDPARAMS\n");
4277 return DDERR_INVALIDPARAMS;
4279 if (Flags)
4281 WARN("Flags is %x, returning DDERR_INVALIDPARAMS\n", Flags);
4282 return DDERR_INVALIDPARAMS;
4284 if (!(This->surface_desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY))
4286 WARN("Surface is not in system memory, returning DDERR_INVALIDSURFACETYPE.\n");
4287 return DDERR_INVALIDSURFACETYPE;
4290 /* Tests show that only LPSURFACE and PIXELFORMAT can be set, and LPSURFACE is required
4291 * for PIXELFORMAT to work */
4292 if (DDSD->dwFlags & ~allowed_flags)
4294 WARN("Invalid flags (0x%08x) set, returning DDERR_INVALIDPARAMS\n", DDSD->dwFlags);
4295 return DDERR_INVALIDPARAMS;
4297 if (!(DDSD->dwFlags & DDSD_LPSURFACE))
4299 WARN("DDSD_LPSURFACE is not set, returning DDERR_INVALIDPARAMS\n");
4300 return DDERR_INVALIDPARAMS;
4302 if (DDSD->dwFlags & DDSD_CAPS)
4304 WARN("DDSD_CAPS is set, returning DDERR_INVALIDCAPS.\n");
4305 return DDERR_INVALIDCAPS;
4307 if (DDSD->dwFlags & DDSD_WIDTH)
4309 if (!(DDSD->dwFlags & DDSD_PITCH))
4311 WARN("DDSD_WIDTH is set, but DDSD_PITCH is not, returning DDERR_INVALIDPARAMS.\n");
4312 return DDERR_INVALIDPARAMS;
4314 if (!DDSD->dwWidth || DDSD->u1.lPitch <= 0 || DDSD->u1.lPitch & 0x3)
4316 WARN("Pitch is %d, width is %u, returning DDERR_INVALIDPARAMS.\n",
4317 DDSD->u1.lPitch, DDSD->dwWidth);
4318 return DDERR_INVALIDPARAMS;
4320 if (DDSD->dwWidth != This->surface_desc.dwWidth)
4322 TRACE("Surface width changed from %u to %u.\n", This->surface_desc.dwWidth, DDSD->dwWidth);
4323 update_wined3d = TRUE;
4325 if (DDSD->u1.lPitch != This->surface_desc.u1.lPitch)
4327 TRACE("Surface pitch changed from %u to %u.\n", This->surface_desc.u1.lPitch, DDSD->u1.lPitch);
4328 update_wined3d = TRUE;
4330 width = DDSD->dwWidth;
4332 else if (DDSD->dwFlags & DDSD_PITCH)
4334 WARN("DDSD_PITCH is set, but DDSD_WIDTH is not, returning DDERR_INVALIDPARAMS.\n");
4335 return DDERR_INVALIDPARAMS;
4337 else
4339 width = This->surface_desc.dwWidth;
4342 if (DDSD->dwFlags & DDSD_HEIGHT)
4344 if (!DDSD->dwHeight)
4346 WARN("Height is 0, returning DDERR_INVALIDPARAMS.\n");
4347 return DDERR_INVALIDPARAMS;
4349 if (DDSD->dwHeight != This->surface_desc.dwHeight)
4351 TRACE("Surface height changed from %u to %u.\n", This->surface_desc.dwHeight, DDSD->dwHeight);
4352 update_wined3d = TRUE;
4354 height = DDSD->dwHeight;
4356 else
4358 height = This->surface_desc.dwHeight;
4361 wined3d_mutex_lock();
4362 if (DDSD->dwFlags & DDSD_PIXELFORMAT)
4364 enum wined3d_format_id current_format_id;
4365 format_id = PixelFormat_DD2WineD3D(&DDSD->u4.ddpfPixelFormat);
4367 if (format_id == WINED3DFMT_UNKNOWN)
4369 ERR("Requested to set an unknown pixelformat\n");
4370 wined3d_mutex_unlock();
4371 return DDERR_INVALIDPARAMS;
4373 current_format_id = PixelFormat_DD2WineD3D(&This->surface_desc.u4.ddpfPixelFormat);
4374 if (format_id != current_format_id)
4376 TRACE("Surface format changed from %#x to %#x.\n", current_format_id, format_id);
4377 update_wined3d = TRUE;
4380 else
4382 format_id = PixelFormat_DD2WineD3D(&This->surface_desc.u4.ddpfPixelFormat);
4385 if (update_wined3d)
4387 if (FAILED(hr = wined3d_surface_update_desc(This->wined3d_surface, width, height,
4388 format_id, WINED3D_MULTISAMPLE_NONE, 0)))
4390 WARN("Failed to update surface desc, hr %#x.\n", hr);
4391 wined3d_mutex_unlock();
4392 return hr;
4395 if (DDSD->dwFlags & DDSD_WIDTH)
4396 This->surface_desc.dwWidth = width;
4397 if (DDSD->dwFlags & DDSD_PITCH)
4398 This->surface_desc.u1.lPitch = DDSD->u1.lPitch;
4399 if (DDSD->dwFlags & DDSD_HEIGHT)
4400 This->surface_desc.dwHeight = height;
4401 if (DDSD->dwFlags & DDSD_PIXELFORMAT)
4402 This->surface_desc.u4.ddpfPixelFormat = DDSD->u4.ddpfPixelFormat;
4405 if (DDSD->dwFlags & DDSD_LPSURFACE && DDSD->lpSurface)
4407 hr = wined3d_surface_set_mem(This->wined3d_surface, DDSD->lpSurface);
4408 if (FAILED(hr))
4410 /* No need for a trace here, wined3d does that for us */
4411 switch(hr)
4413 case WINED3DERR_INVALIDCALL:
4414 wined3d_mutex_unlock();
4415 return DDERR_INVALIDPARAMS;
4416 default:
4417 break; /* Go on */
4420 /* DDSD->lpSurface is set by Lock() */
4423 wined3d_mutex_unlock();
4425 return DD_OK;
4428 static HRESULT WINAPI ddraw_surface4_SetSurfaceDesc(IDirectDrawSurface4 *iface,
4429 DDSURFACEDESC2 *surface_desc, DWORD flags)
4431 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
4433 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface, surface_desc, flags);
4435 return ddraw_surface7_SetSurfaceDesc(&surface->IDirectDrawSurface7_iface,
4436 surface_desc, flags);
4439 static HRESULT WINAPI ddraw_surface3_SetSurfaceDesc(IDirectDrawSurface3 *iface,
4440 DDSURFACEDESC *surface_desc, DWORD flags)
4442 struct ddraw_surface *surface = impl_from_IDirectDrawSurface3(iface);
4443 DDSURFACEDESC2 surface_desc2;
4445 TRACE("iface %p, surface_desc %p, flags %#x.\n", iface, surface_desc, flags);
4447 if (surface_desc) DDSD_to_DDSD2(surface_desc, &surface_desc2);
4448 return ddraw_surface7_SetSurfaceDesc(&surface->IDirectDrawSurface7_iface,
4449 surface_desc ? &surface_desc2 : NULL, flags);
4452 /*****************************************************************************
4453 * IDirectDrawSurface7::GetPalette
4455 * Returns the IDirectDrawPalette interface of the palette currently assigned
4456 * to the surface
4458 * Params:
4459 * Pal: Address to write the interface pointer to
4461 * Returns:
4462 * DD_OK on success
4463 * DDERR_INVALIDPARAMS if Pal is NULL
4465 *****************************************************************************/
4466 static HRESULT WINAPI ddraw_surface7_GetPalette(IDirectDrawSurface7 *iface, IDirectDrawPalette **Pal)
4468 struct ddraw_surface *surface = impl_from_IDirectDrawSurface7(iface);
4469 struct wined3d_palette *wined3d_palette;
4470 HRESULT hr = DD_OK;
4472 TRACE("iface %p, palette %p.\n", iface, Pal);
4474 if(!Pal)
4475 return DDERR_INVALIDPARAMS;
4477 wined3d_mutex_lock();
4478 wined3d_palette = wined3d_surface_get_palette(surface->wined3d_surface);
4479 if (wined3d_palette)
4481 *Pal = wined3d_palette_get_parent(wined3d_palette);
4482 IDirectDrawPalette_AddRef(*Pal);
4484 else
4486 *Pal = NULL;
4487 hr = DDERR_NOPALETTEATTACHED;
4490 wined3d_mutex_unlock();
4492 return hr;
4495 static HRESULT WINAPI ddraw_surface4_GetPalette(IDirectDrawSurface4 *iface, IDirectDrawPalette **palette)
4497 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
4499 TRACE("iface %p, palette %p.\n", iface, palette);
4501 return ddraw_surface7_GetPalette(&surface->IDirectDrawSurface7_iface, palette);
4504 static HRESULT WINAPI ddraw_surface3_GetPalette(IDirectDrawSurface3 *iface, IDirectDrawPalette **palette)
4506 struct ddraw_surface *surface = impl_from_IDirectDrawSurface3(iface);
4508 TRACE("iface %p, palette %p.\n", iface, palette);
4510 return ddraw_surface7_GetPalette(&surface->IDirectDrawSurface7_iface, palette);
4513 static HRESULT WINAPI ddraw_surface2_GetPalette(IDirectDrawSurface2 *iface, IDirectDrawPalette **palette)
4515 struct ddraw_surface *surface = impl_from_IDirectDrawSurface2(iface);
4517 TRACE("iface %p, palette %p.\n", iface, palette);
4519 return ddraw_surface7_GetPalette(&surface->IDirectDrawSurface7_iface, palette);
4522 static HRESULT WINAPI ddraw_surface1_GetPalette(IDirectDrawSurface *iface, IDirectDrawPalette **palette)
4524 struct ddraw_surface *surface = impl_from_IDirectDrawSurface(iface);
4526 TRACE("iface %p, palette %p.\n", iface, palette);
4528 return ddraw_surface7_GetPalette(&surface->IDirectDrawSurface7_iface, palette);
4531 /*****************************************************************************
4532 * SetColorKeyEnum
4534 * EnumAttachedSurface callback for SetColorKey. Used to set color keys
4535 * recursively in the surface tree
4537 *****************************************************************************/
4538 struct SCKContext
4540 HRESULT ret;
4541 struct wined3d_color_key *color_key;
4542 DWORD Flags;
4545 static HRESULT WINAPI SetColorKeyEnum(IDirectDrawSurface7 *surface, DDSURFACEDESC2 *desc, void *context)
4547 struct ddraw_surface *surface_impl = impl_from_IDirectDrawSurface7(surface);
4548 struct SCKContext *ctx = context;
4549 HRESULT hr;
4551 hr = wined3d_surface_set_color_key(surface_impl->wined3d_surface, ctx->Flags, ctx->color_key);
4552 if (FAILED(hr))
4554 WARN("IWineD3DSurface_SetColorKey failed, hr = %08x\n", hr);
4555 ctx->ret = hr;
4558 ddraw_surface7_EnumAttachedSurfaces(surface, context, SetColorKeyEnum);
4559 ddraw_surface7_Release(surface);
4561 return DDENUMRET_OK;
4564 /*****************************************************************************
4565 * IDirectDrawSurface7::SetColorKey
4567 * Sets the color keying options for the surface. Observations showed that
4568 * in case of complex surfaces the color key has to be assigned to all
4569 * sublevels.
4571 * Params:
4572 * Flags: DDCKEY_*
4573 * CKey: The new color key
4575 * Returns:
4576 * DD_OK on success
4577 * See IWineD3DSurface::SetColorKey for details
4579 *****************************************************************************/
4580 static HRESULT WINAPI ddraw_surface7_SetColorKey(IDirectDrawSurface7 *iface, DWORD Flags, DDCOLORKEY *CKey)
4582 struct ddraw_surface *This = impl_from_IDirectDrawSurface7(iface);
4583 DDCOLORKEY FixedCKey;
4584 struct SCKContext ctx = { DD_OK, (struct wined3d_color_key *)(CKey ? &FixedCKey : NULL), Flags };
4586 TRACE("iface %p, flags %#x, color_key %p.\n", iface, Flags, CKey);
4588 wined3d_mutex_lock();
4589 if (CKey)
4591 FixedCKey = *CKey;
4592 /* Handle case where dwColorSpaceHighValue < dwColorSpaceLowValue */
4593 if (FixedCKey.dwColorSpaceHighValue < FixedCKey.dwColorSpaceLowValue)
4594 FixedCKey.dwColorSpaceHighValue = FixedCKey.dwColorSpaceLowValue;
4596 switch (Flags & ~DDCKEY_COLORSPACE)
4598 case DDCKEY_DESTBLT:
4599 This->surface_desc.ddckCKDestBlt = FixedCKey;
4600 This->surface_desc.dwFlags |= DDSD_CKDESTBLT;
4601 break;
4603 case DDCKEY_DESTOVERLAY:
4604 This->surface_desc.u3.ddckCKDestOverlay = FixedCKey;
4605 This->surface_desc.dwFlags |= DDSD_CKDESTOVERLAY;
4606 break;
4608 case DDCKEY_SRCOVERLAY:
4609 This->surface_desc.ddckCKSrcOverlay = FixedCKey;
4610 This->surface_desc.dwFlags |= DDSD_CKSRCOVERLAY;
4611 break;
4613 case DDCKEY_SRCBLT:
4614 This->surface_desc.ddckCKSrcBlt = FixedCKey;
4615 This->surface_desc.dwFlags |= DDSD_CKSRCBLT;
4616 break;
4618 default:
4619 wined3d_mutex_unlock();
4620 return DDERR_INVALIDPARAMS;
4623 else
4625 switch (Flags & ~DDCKEY_COLORSPACE)
4627 case DDCKEY_DESTBLT:
4628 This->surface_desc.dwFlags &= ~DDSD_CKDESTBLT;
4629 break;
4631 case DDCKEY_DESTOVERLAY:
4632 This->surface_desc.dwFlags &= ~DDSD_CKDESTOVERLAY;
4633 break;
4635 case DDCKEY_SRCOVERLAY:
4636 This->surface_desc.dwFlags &= ~DDSD_CKSRCOVERLAY;
4637 break;
4639 case DDCKEY_SRCBLT:
4640 This->surface_desc.dwFlags &= ~DDSD_CKSRCBLT;
4641 break;
4643 default:
4644 wined3d_mutex_unlock();
4645 return DDERR_INVALIDPARAMS;
4648 ctx.ret = wined3d_surface_set_color_key(This->wined3d_surface, Flags, ctx.color_key);
4649 ddraw_surface7_EnumAttachedSurfaces(iface, &ctx, SetColorKeyEnum);
4650 wined3d_mutex_unlock();
4652 switch(ctx.ret)
4654 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
4655 default: return ctx.ret;
4659 static HRESULT WINAPI ddraw_surface4_SetColorKey(IDirectDrawSurface4 *iface, DWORD flags, DDCOLORKEY *color_key)
4661 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
4663 TRACE("iface %p, flags %#x, color_key %p.\n", iface, flags, color_key);
4665 return ddraw_surface7_SetColorKey(&surface->IDirectDrawSurface7_iface, flags, color_key);
4668 static HRESULT WINAPI ddraw_surface3_SetColorKey(IDirectDrawSurface3 *iface, DWORD flags, DDCOLORKEY *color_key)
4670 struct ddraw_surface *surface = impl_from_IDirectDrawSurface3(iface);
4672 TRACE("iface %p, flags %#x, color_key %p.\n", iface, flags, color_key);
4674 return ddraw_surface7_SetColorKey(&surface->IDirectDrawSurface7_iface, flags, color_key);
4677 static HRESULT WINAPI ddraw_surface2_SetColorKey(IDirectDrawSurface2 *iface, DWORD flags, DDCOLORKEY *color_key)
4679 struct ddraw_surface *surface = impl_from_IDirectDrawSurface2(iface);
4681 TRACE("iface %p, flags %#x, color_key %p.\n", iface, flags, color_key);
4683 return ddraw_surface7_SetColorKey(&surface->IDirectDrawSurface7_iface, flags, color_key);
4686 static HRESULT WINAPI ddraw_surface1_SetColorKey(IDirectDrawSurface *iface, DWORD flags, DDCOLORKEY *color_key)
4688 struct ddraw_surface *surface = impl_from_IDirectDrawSurface(iface);
4690 TRACE("iface %p, flags %#x, color_key %p.\n", iface, flags, color_key);
4692 return ddraw_surface7_SetColorKey(&surface->IDirectDrawSurface7_iface, flags, color_key);
4695 /*****************************************************************************
4696 * IDirectDrawSurface7::SetPalette
4698 * Assigns a DirectDrawPalette object to the surface
4700 * Params:
4701 * Pal: Interface to the palette to set
4703 * Returns:
4704 * DD_OK on success
4706 *****************************************************************************/
4707 static HRESULT WINAPI ddraw_surface7_SetPalette(IDirectDrawSurface7 *iface, IDirectDrawPalette *Pal)
4709 struct ddraw_surface *This = impl_from_IDirectDrawSurface7(iface);
4710 struct ddraw_palette *palette_impl = unsafe_impl_from_IDirectDrawPalette(Pal);
4711 IDirectDrawPalette *oldPal;
4712 struct ddraw_surface *surf;
4713 HRESULT hr;
4715 TRACE("iface %p, palette %p.\n", iface, Pal);
4717 if (!(This->surface_desc.u4.ddpfPixelFormat.dwFlags & (DDPF_PALETTEINDEXED1 | DDPF_PALETTEINDEXED2 |
4718 DDPF_PALETTEINDEXED4 | DDPF_PALETTEINDEXED8 | DDPF_PALETTEINDEXEDTO8))) {
4719 return DDERR_INVALIDPIXELFORMAT;
4722 if (This->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_MIPMAPSUBLEVEL)
4724 return DDERR_NOTONMIPMAPSUBLEVEL;
4727 /* Find the old palette */
4728 wined3d_mutex_lock();
4729 hr = IDirectDrawSurface_GetPalette(iface, &oldPal);
4730 if(hr != DD_OK && hr != DDERR_NOPALETTEATTACHED)
4732 wined3d_mutex_unlock();
4733 return hr;
4735 if(oldPal) IDirectDrawPalette_Release(oldPal); /* For the GetPalette */
4737 /* Set the new Palette */
4738 wined3d_surface_set_palette(This->wined3d_surface, palette_impl ? palette_impl->wineD3DPalette : NULL);
4739 /* AddRef the Palette */
4740 if(Pal) IDirectDrawPalette_AddRef(Pal);
4742 /* Release the old palette */
4743 if(oldPal) IDirectDrawPalette_Release(oldPal);
4745 /* Update the wined3d frontbuffer if this is the frontbuffer. */
4746 if ((This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER) && This->ddraw->wined3d_frontbuffer)
4748 hr = wined3d_surface_set_palette(This->ddraw->wined3d_frontbuffer, palette_impl ? palette_impl->wineD3DPalette : NULL);
4749 if (FAILED(hr))
4750 ERR("Failed to set frontbuffer palette, hr %#x.\n", hr);
4753 /* If this is a front buffer, also update the back buffers
4754 * TODO: How do things work for palettized cube textures?
4756 if(This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER)
4758 /* For primary surfaces the tree is just a list, so the simpler scheme fits too */
4759 DDSCAPS2 caps2 = { DDSCAPS_PRIMARYSURFACE, 0, 0, 0 };
4761 surf = This;
4762 while(1)
4764 IDirectDrawSurface7 *attach;
4765 HRESULT hr;
4766 hr = ddraw_surface7_GetAttachedSurface(&surf->IDirectDrawSurface7_iface, &caps2, &attach);
4767 if(hr != DD_OK)
4769 break;
4772 TRACE("Setting palette on %p\n", attach);
4773 ddraw_surface7_SetPalette(attach, Pal);
4774 surf = impl_from_IDirectDrawSurface7(attach);
4775 ddraw_surface7_Release(attach);
4779 wined3d_mutex_unlock();
4781 return DD_OK;
4784 static HRESULT WINAPI ddraw_surface4_SetPalette(IDirectDrawSurface4 *iface, IDirectDrawPalette *palette)
4786 struct ddraw_surface *surface = impl_from_IDirectDrawSurface4(iface);
4788 TRACE("iface %p, palette %p.\n", iface, palette);
4790 return ddraw_surface7_SetPalette(&surface->IDirectDrawSurface7_iface, palette);
4793 static HRESULT WINAPI ddraw_surface3_SetPalette(IDirectDrawSurface3 *iface, IDirectDrawPalette *palette)
4795 struct ddraw_surface *surface = impl_from_IDirectDrawSurface3(iface);
4797 TRACE("iface %p, palette %p.\n", iface, palette);
4799 return ddraw_surface7_SetPalette(&surface->IDirectDrawSurface7_iface, palette);
4802 static HRESULT WINAPI ddraw_surface2_SetPalette(IDirectDrawSurface2 *iface, IDirectDrawPalette *palette)
4804 struct ddraw_surface *surface = impl_from_IDirectDrawSurface2(iface);
4806 TRACE("iface %p, palette %p.\n", iface, palette);
4808 return ddraw_surface7_SetPalette(&surface->IDirectDrawSurface7_iface, palette);
4811 static HRESULT WINAPI ddraw_surface1_SetPalette(IDirectDrawSurface *iface, IDirectDrawPalette *palette)
4813 struct ddraw_surface *surface = impl_from_IDirectDrawSurface(iface);
4815 TRACE("iface %p, palette %p.\n", iface, palette);
4817 return ddraw_surface7_SetPalette(&surface->IDirectDrawSurface7_iface, palette);
4820 /**********************************************************
4821 * IDirectDrawGammaControl::GetGammaRamp
4823 * Returns the current gamma ramp for a surface
4825 * Params:
4826 * flags: Ignored
4827 * gamma_ramp: Address to write the ramp to
4829 * Returns:
4830 * DD_OK on success
4831 * DDERR_INVALIDPARAMS if gamma_ramp is NULL
4833 **********************************************************/
4834 static HRESULT WINAPI ddraw_gamma_control_GetGammaRamp(IDirectDrawGammaControl *iface,
4835 DWORD flags, DDGAMMARAMP *gamma_ramp)
4837 struct ddraw_surface *surface = impl_from_IDirectDrawGammaControl(iface);
4839 TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface, flags, gamma_ramp);
4841 if (!gamma_ramp)
4843 WARN("Invalid gamma_ramp passed.\n");
4844 return DDERR_INVALIDPARAMS;
4847 wined3d_mutex_lock();
4848 if (surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
4850 /* Note: DDGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
4851 wined3d_device_get_gamma_ramp(surface->ddraw->wined3d_device, 0, (struct wined3d_gamma_ramp *)gamma_ramp);
4853 else
4855 ERR("Not implemented for non-primary surfaces.\n");
4857 wined3d_mutex_unlock();
4859 return DD_OK;
4862 /**********************************************************
4863 * IDirectDrawGammaControl::SetGammaRamp
4865 * Sets the red, green and blue gamma ramps for
4867 * Params:
4868 * flags: Can be DDSGR_CALIBRATE to request calibration
4869 * gamma_ramp: Structure containing the new gamma ramp
4871 * Returns:
4872 * DD_OK on success
4873 * DDERR_INVALIDPARAMS if gamma_ramp is NULL
4875 **********************************************************/
4876 static HRESULT WINAPI ddraw_gamma_control_SetGammaRamp(IDirectDrawGammaControl *iface,
4877 DWORD flags, DDGAMMARAMP *gamma_ramp)
4879 struct ddraw_surface *surface = impl_from_IDirectDrawGammaControl(iface);
4881 TRACE("iface %p, flags %#x, gamma_ramp %p.\n", iface, flags, gamma_ramp);
4883 if (!gamma_ramp)
4885 WARN("Invalid gamma_ramp passed.\n");
4886 return DDERR_INVALIDPARAMS;
4889 wined3d_mutex_lock();
4890 if (surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
4892 /* Note: DDGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
4893 wined3d_device_set_gamma_ramp(surface->ddraw->wined3d_device,
4894 0, flags, (struct wined3d_gamma_ramp *)gamma_ramp);
4896 else
4898 ERR("Not implemented for non-primary surfaces.\n");
4900 wined3d_mutex_unlock();
4902 return DD_OK;
4905 /*****************************************************************************
4906 * IDirect3DTexture2::PaletteChanged
4908 * Informs the texture about a palette change
4910 * Params:
4911 * start: Start index of the change
4912 * count: The number of changed entries
4914 * Returns
4915 * D3D_OK, because it's a stub
4917 *****************************************************************************/
4918 static HRESULT WINAPI d3d_texture2_PaletteChanged(IDirect3DTexture2 *iface, DWORD start, DWORD count)
4920 FIXME("iface %p, start %u, count %u stub!\n", iface, start, count);
4922 return D3D_OK;
4925 static HRESULT WINAPI d3d_texture1_PaletteChanged(IDirect3DTexture *iface, DWORD start, DWORD count)
4927 struct ddraw_surface *surface = impl_from_IDirect3DTexture(iface);
4929 TRACE("iface %p, start %u, count %u.\n", iface, start, count);
4931 return d3d_texture2_PaletteChanged(&surface->IDirect3DTexture2_iface, start, count);
4934 /*****************************************************************************
4935 * IDirect3DTexture::Unload
4937 * DX5 SDK: "The IDirect3DTexture2::Unload method is not implemented
4940 * Returns:
4941 * DDERR_UNSUPPORTED
4943 *****************************************************************************/
4944 static HRESULT WINAPI d3d_texture1_Unload(IDirect3DTexture *iface)
4946 WARN("iface %p. Not implemented.\n", iface);
4948 return DDERR_UNSUPPORTED;
4951 /*****************************************************************************
4952 * IDirect3DTexture2::GetHandle
4954 * Returns handle for the texture. At the moment, the interface
4955 * to the IWineD3DTexture is used.
4957 * Params:
4958 * device: Device this handle is assigned to
4959 * handle: Address to store the handle at.
4961 * Returns:
4962 * D3D_OK
4964 *****************************************************************************/
4965 static HRESULT WINAPI d3d_texture2_GetHandle(IDirect3DTexture2 *iface,
4966 IDirect3DDevice2 *device, D3DTEXTUREHANDLE *handle)
4968 struct ddraw_surface *surface = impl_from_IDirect3DTexture2(iface);
4969 IDirect3DDeviceImpl *device_impl = unsafe_impl_from_IDirect3DDevice2(device);
4971 TRACE("iface %p, device %p, handle %p.\n", iface, device, handle);
4973 wined3d_mutex_lock();
4975 if (!surface->Handle)
4977 DWORD h = ddraw_allocate_handle(&device_impl->handle_table, surface, DDRAW_HANDLE_SURFACE);
4978 if (h == DDRAW_INVALID_HANDLE)
4980 ERR("Failed to allocate a texture handle.\n");
4981 wined3d_mutex_unlock();
4982 return DDERR_OUTOFMEMORY;
4985 surface->Handle = h + 1;
4988 TRACE("Returning handle %08x.\n", surface->Handle);
4989 *handle = surface->Handle;
4991 wined3d_mutex_unlock();
4993 return D3D_OK;
4996 static HRESULT WINAPI d3d_texture1_GetHandle(IDirect3DTexture *iface,
4997 IDirect3DDevice *device, D3DTEXTUREHANDLE *handle)
4999 struct ddraw_surface *surface = impl_from_IDirect3DTexture(iface);
5000 IDirect3DDeviceImpl *device_impl = unsafe_impl_from_IDirect3DDevice(device);
5002 TRACE("iface %p, device %p, handle %p.\n", iface, device, handle);
5004 return d3d_texture2_GetHandle(&surface->IDirect3DTexture2_iface,
5005 device_impl ? &device_impl->IDirect3DDevice2_iface : NULL, handle);
5008 /*****************************************************************************
5009 * get_sub_mimaplevel
5011 * Helper function that returns the next mipmap level
5013 * tex_ptr: Surface of which to return the next level
5015 *****************************************************************************/
5016 static struct ddraw_surface *get_sub_mimaplevel(struct ddraw_surface *surface)
5018 /* Now go down the mipmap chain to the next surface */
5019 static DDSCAPS2 mipmap_caps = { DDSCAPS_MIPMAP | DDSCAPS_TEXTURE, 0, 0, 0 };
5020 IDirectDrawSurface7 *next_level;
5021 HRESULT hr;
5023 hr = ddraw_surface7_GetAttachedSurface(&surface->IDirectDrawSurface7_iface, &mipmap_caps, &next_level);
5024 if (FAILED(hr)) return NULL;
5026 ddraw_surface7_Release(next_level);
5028 return impl_from_IDirectDrawSurface7(next_level);
5031 /*****************************************************************************
5032 * IDirect3DTexture2::Load
5034 * Loads a texture created with the DDSCAPS_ALLOCONLOAD
5036 * This function isn't relayed to WineD3D because the whole interface is
5037 * implemented in DDraw only. For speed improvements a implementation which
5038 * takes OpenGL more into account could be placed into WineD3D.
5040 * Params:
5041 * src_texture: Address of the texture to load
5043 * Returns:
5044 * D3D_OK on success
5045 * D3DERR_TEXTURE_LOAD_FAILED.
5047 *****************************************************************************/
5048 static HRESULT WINAPI d3d_texture2_Load(IDirect3DTexture2 *iface, IDirect3DTexture2 *src_texture)
5050 struct ddraw_surface *dst_surface = impl_from_IDirect3DTexture2(iface);
5051 struct ddraw_surface *src_surface = unsafe_impl_from_IDirect3DTexture2(src_texture);
5052 HRESULT hr;
5054 TRACE("iface %p, src_texture %p.\n", iface, src_texture);
5056 if (src_surface == dst_surface)
5058 TRACE("copying surface %p to surface %p, why?\n", src_surface, dst_surface);
5059 return D3D_OK;
5062 wined3d_mutex_lock();
5064 if (((src_surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_MIPMAP)
5065 != (dst_surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_MIPMAP))
5066 || (src_surface->surface_desc.u2.dwMipMapCount != dst_surface->surface_desc.u2.dwMipMapCount))
5068 ERR("Trying to load surfaces with different mip-map counts.\n");
5071 for (;;)
5073 struct wined3d_palette *wined3d_dst_pal, *wined3d_src_pal;
5074 IDirectDrawPalette *dst_pal = NULL, *src_pal = NULL;
5075 DDSURFACEDESC *src_desc, *dst_desc;
5077 TRACE("Copying surface %p to surface %p (mipmap level %d).\n",
5078 src_surface, dst_surface, src_surface->mipmap_level);
5080 /* Suppress the ALLOCONLOAD flag */
5081 dst_surface->surface_desc.ddsCaps.dwCaps &= ~DDSCAPS_ALLOCONLOAD;
5083 /* Get the palettes */
5084 wined3d_dst_pal = wined3d_surface_get_palette(dst_surface->wined3d_surface);
5085 if (wined3d_dst_pal)
5086 dst_pal = wined3d_palette_get_parent(wined3d_dst_pal);
5088 wined3d_src_pal = wined3d_surface_get_palette(src_surface->wined3d_surface);
5089 if (wined3d_src_pal)
5090 src_pal = wined3d_palette_get_parent(wined3d_src_pal);
5092 if (src_pal)
5094 PALETTEENTRY palent[256];
5096 if (!dst_pal)
5098 wined3d_mutex_unlock();
5099 return DDERR_NOPALETTEATTACHED;
5101 IDirectDrawPalette_GetEntries(src_pal, 0, 0, 256, palent);
5102 IDirectDrawPalette_SetEntries(dst_pal, 0, 0, 256, palent);
5105 /* Copy one surface on the other */
5106 dst_desc = (DDSURFACEDESC *)&(dst_surface->surface_desc);
5107 src_desc = (DDSURFACEDESC *)&(src_surface->surface_desc);
5109 if ((src_desc->dwWidth != dst_desc->dwWidth) || (src_desc->dwHeight != dst_desc->dwHeight))
5111 /* Should also check for same pixel format, u1.lPitch, ... */
5112 ERR("Error in surface sizes.\n");
5113 wined3d_mutex_unlock();
5114 return D3DERR_TEXTURE_LOAD_FAILED;
5116 else
5118 struct wined3d_mapped_rect src_rect, dst_rect;
5120 /* Copy the src blit color key if the source has one, don't erase
5121 * the destination's ckey if the source has none */
5122 if (src_desc->dwFlags & DDSD_CKSRCBLT)
5124 IDirectDrawSurface7_SetColorKey(&dst_surface->IDirectDrawSurface7_iface,
5125 DDCKEY_SRCBLT, &src_desc->ddckCKSrcBlt);
5128 /* Copy the main memory texture into the surface that corresponds
5129 * to the OpenGL texture object. */
5131 hr = wined3d_surface_map(src_surface->wined3d_surface, &src_rect, NULL, 0);
5132 if (FAILED(hr))
5134 ERR("Failed to lock source surface, hr %#x.\n", hr);
5135 wined3d_mutex_unlock();
5136 return D3DERR_TEXTURE_LOAD_FAILED;
5139 hr = wined3d_surface_map(dst_surface->wined3d_surface, &dst_rect, NULL, 0);
5140 if (FAILED(hr))
5142 ERR("Failed to lock destination surface, hr %#x.\n", hr);
5143 wined3d_surface_unmap(src_surface->wined3d_surface);
5144 wined3d_mutex_unlock();
5145 return D3DERR_TEXTURE_LOAD_FAILED;
5148 if (dst_surface->surface_desc.u4.ddpfPixelFormat.dwFlags & DDPF_FOURCC)
5149 memcpy(dst_rect.data, src_rect.data, src_surface->surface_desc.u1.dwLinearSize);
5150 else
5151 memcpy(dst_rect.data, src_rect.data, src_rect.row_pitch * src_desc->dwHeight);
5153 wined3d_surface_unmap(src_surface->wined3d_surface);
5154 wined3d_surface_unmap(dst_surface->wined3d_surface);
5157 if (src_surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_MIPMAP)
5158 src_surface = get_sub_mimaplevel(src_surface);
5159 else
5160 src_surface = NULL;
5162 if (dst_surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_MIPMAP)
5163 dst_surface = get_sub_mimaplevel(dst_surface);
5164 else
5165 dst_surface = NULL;
5167 if (!src_surface || !dst_surface)
5169 if (src_surface != dst_surface)
5170 ERR("Loading surface with different mipmap structure.\n");
5171 break;
5175 wined3d_mutex_unlock();
5177 return hr;
5180 static HRESULT WINAPI d3d_texture1_Load(IDirect3DTexture *iface, IDirect3DTexture *src_texture)
5182 struct ddraw_surface *dst_surface = impl_from_IDirect3DTexture(iface);
5183 struct ddraw_surface *src_surface = unsafe_impl_from_IDirect3DTexture(src_texture);
5185 TRACE("iface %p, src_texture %p.\n", iface, src_texture);
5187 return d3d_texture2_Load(&dst_surface->IDirect3DTexture2_iface,
5188 src_surface ? &src_surface->IDirect3DTexture2_iface : NULL);
5191 /*****************************************************************************
5192 * The VTable
5193 *****************************************************************************/
5195 static const struct IDirectDrawSurface7Vtbl ddraw_surface7_vtbl =
5197 /* IUnknown */
5198 ddraw_surface7_QueryInterface,
5199 ddraw_surface7_AddRef,
5200 ddraw_surface7_Release,
5201 /* IDirectDrawSurface */
5202 ddraw_surface7_AddAttachedSurface,
5203 ddraw_surface7_AddOverlayDirtyRect,
5204 ddraw_surface7_Blt,
5205 ddraw_surface7_BltBatch,
5206 ddraw_surface7_BltFast,
5207 ddraw_surface7_DeleteAttachedSurface,
5208 ddraw_surface7_EnumAttachedSurfaces,
5209 ddraw_surface7_EnumOverlayZOrders,
5210 ddraw_surface7_Flip,
5211 ddraw_surface7_GetAttachedSurface,
5212 ddraw_surface7_GetBltStatus,
5213 ddraw_surface7_GetCaps,
5214 ddraw_surface7_GetClipper,
5215 ddraw_surface7_GetColorKey,
5216 ddraw_surface7_GetDC,
5217 ddraw_surface7_GetFlipStatus,
5218 ddraw_surface7_GetOverlayPosition,
5219 ddraw_surface7_GetPalette,
5220 ddraw_surface7_GetPixelFormat,
5221 ddraw_surface7_GetSurfaceDesc,
5222 ddraw_surface7_Initialize,
5223 ddraw_surface7_IsLost,
5224 ddraw_surface7_Lock,
5225 ddraw_surface7_ReleaseDC,
5226 ddraw_surface7_Restore,
5227 ddraw_surface7_SetClipper,
5228 ddraw_surface7_SetColorKey,
5229 ddraw_surface7_SetOverlayPosition,
5230 ddraw_surface7_SetPalette,
5231 ddraw_surface7_Unlock,
5232 ddraw_surface7_UpdateOverlay,
5233 ddraw_surface7_UpdateOverlayDisplay,
5234 ddraw_surface7_UpdateOverlayZOrder,
5235 /* IDirectDrawSurface2 */
5236 ddraw_surface7_GetDDInterface,
5237 ddraw_surface7_PageLock,
5238 ddraw_surface7_PageUnlock,
5239 /* IDirectDrawSurface3 */
5240 ddraw_surface7_SetSurfaceDesc,
5241 /* IDirectDrawSurface4 */
5242 ddraw_surface7_SetPrivateData,
5243 ddraw_surface7_GetPrivateData,
5244 ddraw_surface7_FreePrivateData,
5245 ddraw_surface7_GetUniquenessValue,
5246 ddraw_surface7_ChangeUniquenessValue,
5247 /* IDirectDrawSurface7 */
5248 ddraw_surface7_SetPriority,
5249 ddraw_surface7_GetPriority,
5250 ddraw_surface7_SetLOD,
5251 ddraw_surface7_GetLOD,
5254 static const struct IDirectDrawSurface4Vtbl ddraw_surface4_vtbl =
5256 /* IUnknown */
5257 ddraw_surface4_QueryInterface,
5258 ddraw_surface4_AddRef,
5259 ddraw_surface4_Release,
5260 /* IDirectDrawSurface */
5261 ddraw_surface4_AddAttachedSurface,
5262 ddraw_surface4_AddOverlayDirtyRect,
5263 ddraw_surface4_Blt,
5264 ddraw_surface4_BltBatch,
5265 ddraw_surface4_BltFast,
5266 ddraw_surface4_DeleteAttachedSurface,
5267 ddraw_surface4_EnumAttachedSurfaces,
5268 ddraw_surface4_EnumOverlayZOrders,
5269 ddraw_surface4_Flip,
5270 ddraw_surface4_GetAttachedSurface,
5271 ddraw_surface4_GetBltStatus,
5272 ddraw_surface4_GetCaps,
5273 ddraw_surface4_GetClipper,
5274 ddraw_surface4_GetColorKey,
5275 ddraw_surface4_GetDC,
5276 ddraw_surface4_GetFlipStatus,
5277 ddraw_surface4_GetOverlayPosition,
5278 ddraw_surface4_GetPalette,
5279 ddraw_surface4_GetPixelFormat,
5280 ddraw_surface4_GetSurfaceDesc,
5281 ddraw_surface4_Initialize,
5282 ddraw_surface4_IsLost,
5283 ddraw_surface4_Lock,
5284 ddraw_surface4_ReleaseDC,
5285 ddraw_surface4_Restore,
5286 ddraw_surface4_SetClipper,
5287 ddraw_surface4_SetColorKey,
5288 ddraw_surface4_SetOverlayPosition,
5289 ddraw_surface4_SetPalette,
5290 ddraw_surface4_Unlock,
5291 ddraw_surface4_UpdateOverlay,
5292 ddraw_surface4_UpdateOverlayDisplay,
5293 ddraw_surface4_UpdateOverlayZOrder,
5294 /* IDirectDrawSurface2 */
5295 ddraw_surface4_GetDDInterface,
5296 ddraw_surface4_PageLock,
5297 ddraw_surface4_PageUnlock,
5298 /* IDirectDrawSurface3 */
5299 ddraw_surface4_SetSurfaceDesc,
5300 /* IDirectDrawSurface4 */
5301 ddraw_surface4_SetPrivateData,
5302 ddraw_surface4_GetPrivateData,
5303 ddraw_surface4_FreePrivateData,
5304 ddraw_surface4_GetUniquenessValue,
5305 ddraw_surface4_ChangeUniquenessValue,
5308 static const struct IDirectDrawSurface3Vtbl ddraw_surface3_vtbl =
5310 /* IUnknown */
5311 ddraw_surface3_QueryInterface,
5312 ddraw_surface3_AddRef,
5313 ddraw_surface3_Release,
5314 /* IDirectDrawSurface */
5315 ddraw_surface3_AddAttachedSurface,
5316 ddraw_surface3_AddOverlayDirtyRect,
5317 ddraw_surface3_Blt,
5318 ddraw_surface3_BltBatch,
5319 ddraw_surface3_BltFast,
5320 ddraw_surface3_DeleteAttachedSurface,
5321 ddraw_surface3_EnumAttachedSurfaces,
5322 ddraw_surface3_EnumOverlayZOrders,
5323 ddraw_surface3_Flip,
5324 ddraw_surface3_GetAttachedSurface,
5325 ddraw_surface3_GetBltStatus,
5326 ddraw_surface3_GetCaps,
5327 ddraw_surface3_GetClipper,
5328 ddraw_surface3_GetColorKey,
5329 ddraw_surface3_GetDC,
5330 ddraw_surface3_GetFlipStatus,
5331 ddraw_surface3_GetOverlayPosition,
5332 ddraw_surface3_GetPalette,
5333 ddraw_surface3_GetPixelFormat,
5334 ddraw_surface3_GetSurfaceDesc,
5335 ddraw_surface3_Initialize,
5336 ddraw_surface3_IsLost,
5337 ddraw_surface3_Lock,
5338 ddraw_surface3_ReleaseDC,
5339 ddraw_surface3_Restore,
5340 ddraw_surface3_SetClipper,
5341 ddraw_surface3_SetColorKey,
5342 ddraw_surface3_SetOverlayPosition,
5343 ddraw_surface3_SetPalette,
5344 ddraw_surface3_Unlock,
5345 ddraw_surface3_UpdateOverlay,
5346 ddraw_surface3_UpdateOverlayDisplay,
5347 ddraw_surface3_UpdateOverlayZOrder,
5348 /* IDirectDrawSurface2 */
5349 ddraw_surface3_GetDDInterface,
5350 ddraw_surface3_PageLock,
5351 ddraw_surface3_PageUnlock,
5352 /* IDirectDrawSurface3 */
5353 ddraw_surface3_SetSurfaceDesc,
5356 static const struct IDirectDrawSurface2Vtbl ddraw_surface2_vtbl =
5358 /* IUnknown */
5359 ddraw_surface2_QueryInterface,
5360 ddraw_surface2_AddRef,
5361 ddraw_surface2_Release,
5362 /* IDirectDrawSurface */
5363 ddraw_surface2_AddAttachedSurface,
5364 ddraw_surface2_AddOverlayDirtyRect,
5365 ddraw_surface2_Blt,
5366 ddraw_surface2_BltBatch,
5367 ddraw_surface2_BltFast,
5368 ddraw_surface2_DeleteAttachedSurface,
5369 ddraw_surface2_EnumAttachedSurfaces,
5370 ddraw_surface2_EnumOverlayZOrders,
5371 ddraw_surface2_Flip,
5372 ddraw_surface2_GetAttachedSurface,
5373 ddraw_surface2_GetBltStatus,
5374 ddraw_surface2_GetCaps,
5375 ddraw_surface2_GetClipper,
5376 ddraw_surface2_GetColorKey,
5377 ddraw_surface2_GetDC,
5378 ddraw_surface2_GetFlipStatus,
5379 ddraw_surface2_GetOverlayPosition,
5380 ddraw_surface2_GetPalette,
5381 ddraw_surface2_GetPixelFormat,
5382 ddraw_surface2_GetSurfaceDesc,
5383 ddraw_surface2_Initialize,
5384 ddraw_surface2_IsLost,
5385 ddraw_surface2_Lock,
5386 ddraw_surface2_ReleaseDC,
5387 ddraw_surface2_Restore,
5388 ddraw_surface2_SetClipper,
5389 ddraw_surface2_SetColorKey,
5390 ddraw_surface2_SetOverlayPosition,
5391 ddraw_surface2_SetPalette,
5392 ddraw_surface2_Unlock,
5393 ddraw_surface2_UpdateOverlay,
5394 ddraw_surface2_UpdateOverlayDisplay,
5395 ddraw_surface2_UpdateOverlayZOrder,
5396 /* IDirectDrawSurface2 */
5397 ddraw_surface2_GetDDInterface,
5398 ddraw_surface2_PageLock,
5399 ddraw_surface2_PageUnlock,
5402 static const struct IDirectDrawSurfaceVtbl ddraw_surface1_vtbl =
5404 /* IUnknown */
5405 ddraw_surface1_QueryInterface,
5406 ddraw_surface1_AddRef,
5407 ddraw_surface1_Release,
5408 /* IDirectDrawSurface */
5409 ddraw_surface1_AddAttachedSurface,
5410 ddraw_surface1_AddOverlayDirtyRect,
5411 ddraw_surface1_Blt,
5412 ddraw_surface1_BltBatch,
5413 ddraw_surface1_BltFast,
5414 ddraw_surface1_DeleteAttachedSurface,
5415 ddraw_surface1_EnumAttachedSurfaces,
5416 ddraw_surface1_EnumOverlayZOrders,
5417 ddraw_surface1_Flip,
5418 ddraw_surface1_GetAttachedSurface,
5419 ddraw_surface1_GetBltStatus,
5420 ddraw_surface1_GetCaps,
5421 ddraw_surface1_GetClipper,
5422 ddraw_surface1_GetColorKey,
5423 ddraw_surface1_GetDC,
5424 ddraw_surface1_GetFlipStatus,
5425 ddraw_surface1_GetOverlayPosition,
5426 ddraw_surface1_GetPalette,
5427 ddraw_surface1_GetPixelFormat,
5428 ddraw_surface1_GetSurfaceDesc,
5429 ddraw_surface1_Initialize,
5430 ddraw_surface1_IsLost,
5431 ddraw_surface1_Lock,
5432 ddraw_surface1_ReleaseDC,
5433 ddraw_surface1_Restore,
5434 ddraw_surface1_SetClipper,
5435 ddraw_surface1_SetColorKey,
5436 ddraw_surface1_SetOverlayPosition,
5437 ddraw_surface1_SetPalette,
5438 ddraw_surface1_Unlock,
5439 ddraw_surface1_UpdateOverlay,
5440 ddraw_surface1_UpdateOverlayDisplay,
5441 ddraw_surface1_UpdateOverlayZOrder,
5444 static const struct IDirectDrawGammaControlVtbl ddraw_gamma_control_vtbl =
5446 ddraw_gamma_control_QueryInterface,
5447 ddraw_gamma_control_AddRef,
5448 ddraw_gamma_control_Release,
5449 ddraw_gamma_control_GetGammaRamp,
5450 ddraw_gamma_control_SetGammaRamp,
5453 static const struct IDirect3DTexture2Vtbl d3d_texture2_vtbl =
5455 d3d_texture2_QueryInterface,
5456 d3d_texture2_AddRef,
5457 d3d_texture2_Release,
5458 d3d_texture2_GetHandle,
5459 d3d_texture2_PaletteChanged,
5460 d3d_texture2_Load,
5463 static const struct IDirect3DTextureVtbl d3d_texture1_vtbl =
5465 d3d_texture1_QueryInterface,
5466 d3d_texture1_AddRef,
5467 d3d_texture1_Release,
5468 d3d_texture1_Initialize,
5469 d3d_texture1_GetHandle,
5470 d3d_texture1_PaletteChanged,
5471 d3d_texture1_Load,
5472 d3d_texture1_Unload,
5475 /* Some games (e.g. Tomb Raider 3) pass the wrong version of the
5476 * IDirectDrawSurface interface to ddraw methods. */
5477 struct ddraw_surface *unsafe_impl_from_IDirectDrawSurface7(IDirectDrawSurface7 *iface)
5479 if (!iface) return NULL;
5480 if (iface->lpVtbl != &ddraw_surface7_vtbl)
5482 HRESULT hr = IUnknown_QueryInterface(iface, &IID_IDirectDrawSurface7, (void **)&iface);
5483 if (FAILED(hr))
5485 WARN("Object %p doesn't expose interface IDirectDrawSurface7.\n", iface);
5486 return NULL;
5488 IUnknown_Release(iface);
5490 return CONTAINING_RECORD(iface, struct ddraw_surface, IDirectDrawSurface7_iface);
5493 struct ddraw_surface *unsafe_impl_from_IDirectDrawSurface4(IDirectDrawSurface4 *iface)
5495 if (!iface) return NULL;
5496 if (iface->lpVtbl != &ddraw_surface4_vtbl)
5498 HRESULT hr = IUnknown_QueryInterface(iface, &IID_IDirectDrawSurface4, (void **)&iface);
5499 if (FAILED(hr))
5501 WARN("Object %p doesn't expose interface IDirectDrawSurface4.\n", iface);
5502 return NULL;
5504 IUnknown_Release(iface);
5506 return CONTAINING_RECORD(iface, struct ddraw_surface, IDirectDrawSurface4_iface);
5509 static struct ddraw_surface *unsafe_impl_from_IDirectDrawSurface3(IDirectDrawSurface3 *iface)
5511 if (!iface) return NULL;
5512 if (iface->lpVtbl != &ddraw_surface3_vtbl)
5514 HRESULT hr = IUnknown_QueryInterface(iface, &IID_IDirectDrawSurface3, (void **)&iface);
5515 if (FAILED(hr))
5517 WARN("Object %p doesn't expose interface IDirectDrawSurface3.\n", iface);
5518 return NULL;
5520 IUnknown_Release(iface);
5522 return CONTAINING_RECORD(iface, struct ddraw_surface, IDirectDrawSurface3_iface);
5525 static struct ddraw_surface *unsafe_impl_from_IDirectDrawSurface2(IDirectDrawSurface2 *iface)
5527 if (!iface) return NULL;
5528 if (iface->lpVtbl != &ddraw_surface2_vtbl)
5530 HRESULT hr = IUnknown_QueryInterface(iface, &IID_IDirectDrawSurface2, (void **)&iface);
5531 if (FAILED(hr))
5533 WARN("Object %p doesn't expose interface IDirectDrawSurface2.\n", iface);
5534 return NULL;
5536 IUnknown_Release(iface);
5538 return CONTAINING_RECORD(iface, struct ddraw_surface, IDirectDrawSurface2_iface);
5541 struct ddraw_surface *unsafe_impl_from_IDirectDrawSurface(IDirectDrawSurface *iface)
5543 if (!iface) return NULL;
5544 if (iface->lpVtbl != &ddraw_surface1_vtbl)
5546 HRESULT hr = IUnknown_QueryInterface(iface, &IID_IDirectDrawSurface, (void **)&iface);
5547 if (FAILED(hr))
5549 WARN("Object %p doesn't expose interface IDirectDrawSurface.\n", iface);
5550 return NULL;
5552 IUnknown_Release(iface);
5554 return CONTAINING_RECORD(iface, struct ddraw_surface, IDirectDrawSurface_iface);
5557 struct ddraw_surface *unsafe_impl_from_IDirect3DTexture2(IDirect3DTexture2 *iface)
5559 if (!iface) return NULL;
5560 assert(iface->lpVtbl == &d3d_texture2_vtbl);
5561 return CONTAINING_RECORD(iface, struct ddraw_surface, IDirect3DTexture2_iface);
5564 struct ddraw_surface *unsafe_impl_from_IDirect3DTexture(IDirect3DTexture *iface)
5566 if (!iface) return NULL;
5567 assert(iface->lpVtbl == &d3d_texture1_vtbl);
5568 return CONTAINING_RECORD(iface, struct ddraw_surface, IDirect3DTexture_iface);
5571 static void STDMETHODCALLTYPE ddraw_surface_wined3d_object_destroyed(void *parent)
5573 struct ddraw_surface *surface = parent;
5575 TRACE("surface %p.\n", surface);
5577 /* Check for attached surfaces and detach them. */
5578 if (surface->first_attached != surface)
5580 /* Well, this shouldn't happen: The surface being attached is
5581 * referenced in AddAttachedSurface(), so it shouldn't be released
5582 * until DeleteAttachedSurface() is called, because the refcount is
5583 * held. It looks like the application released it often enough to
5584 * force this. */
5585 WARN("Surface is still attached to surface %p.\n", surface->first_attached);
5587 /* The refcount will drop to -1 here */
5588 if (FAILED(ddraw_surface_delete_attached_surface(surface->first_attached, surface, surface->attached_iface)))
5589 ERR("DeleteAttachedSurface failed.\n");
5592 while (surface->next_attached)
5593 if (FAILED(ddraw_surface_delete_attached_surface(surface,
5594 surface->next_attached, surface->next_attached->attached_iface)))
5595 ERR("DeleteAttachedSurface failed.\n");
5597 /* Having a texture handle set implies that the device still exists. */
5598 if (surface->Handle)
5599 ddraw_free_handle(&surface->ddraw->d3ddevice->handle_table, surface->Handle - 1, DDRAW_HANDLE_SURFACE);
5601 /* Reduce the ddraw surface count. */
5602 list_remove(&surface->surface_list_entry);
5604 if (surface == surface->ddraw->primary)
5605 surface->ddraw->primary = NULL;
5607 HeapFree(GetProcessHeap(), 0, surface);
5610 static const struct wined3d_parent_ops ddraw_surface_wined3d_parent_ops =
5612 ddraw_surface_wined3d_object_destroyed,
5615 static void STDMETHODCALLTYPE ddraw_texture_wined3d_object_destroyed(void *parent)
5617 struct ddraw_surface *surface = parent;
5619 TRACE("surface %p.\n", surface);
5621 ddraw_surface_cleanup(surface);
5624 static const struct wined3d_parent_ops ddraw_texture_wined3d_parent_ops =
5626 ddraw_texture_wined3d_object_destroyed,
5629 HRESULT ddraw_surface_create_texture(struct ddraw_surface *surface)
5631 const DDSURFACEDESC2 *desc = &surface->surface_desc;
5632 enum wined3d_format_id format;
5633 enum wined3d_pool pool;
5634 UINT levels;
5636 if (desc->ddsCaps.dwCaps & DDSCAPS_MIPMAP)
5637 levels = desc->u2.dwMipMapCount;
5638 else
5639 levels = 1;
5641 /* DDSCAPS_SYSTEMMEMORY textures are in WINED3D_POOL_SYSTEM_MEM.
5642 * Should I forward the MANAGED cap to the managed pool? */
5643 if (desc->ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY)
5644 pool = WINED3D_POOL_SYSTEM_MEM;
5645 else
5646 pool = WINED3D_POOL_DEFAULT;
5648 format = PixelFormat_DD2WineD3D(&surface->surface_desc.u4.ddpfPixelFormat);
5649 if (desc->ddsCaps.dwCaps2 & DDSCAPS2_CUBEMAP)
5650 return wined3d_texture_create_cube(surface->ddraw->wined3d_device, desc->dwWidth,
5651 levels, 0, format, pool, surface, &ddraw_texture_wined3d_parent_ops, &surface->wined3d_texture);
5652 else
5653 return wined3d_texture_create_2d(surface->ddraw->wined3d_device, desc->dwWidth, desc->dwHeight,
5654 levels, 0, format, pool, surface, &ddraw_texture_wined3d_parent_ops, &surface->wined3d_texture);
5657 HRESULT ddraw_surface_init(struct ddraw_surface *surface, struct ddraw *ddraw,
5658 DDSURFACEDESC2 *desc, UINT mip_level, UINT version)
5660 enum wined3d_pool pool = WINED3D_POOL_DEFAULT;
5661 DWORD flags = WINED3D_SURFACE_MAPPABLE;
5662 enum wined3d_format_id format;
5663 DWORD usage = 0;
5664 HRESULT hr;
5666 if (!(desc->ddsCaps.dwCaps & (DDSCAPS_VIDEOMEMORY | DDSCAPS_SYSTEMMEMORY))
5667 && !((desc->ddsCaps.dwCaps & DDSCAPS_TEXTURE)
5668 && (desc->ddsCaps.dwCaps2 & DDSCAPS2_TEXTUREMANAGE)))
5670 /* Tests show surfaces without memory flags get these flags added
5671 * right after creation. */
5672 desc->ddsCaps.dwCaps |= DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY;
5675 /* Some applications assume surfaces will always be mapped at the same
5676 * address. Some of those also assume that this address is valid even when
5677 * the surface isn't mapped, and that updates done this way will be
5678 * visible on the screen. The game Nox is such an application,
5679 * Commandos: Behind Enemy Lines is another. */
5680 flags |= WINED3D_SURFACE_PIN_SYSMEM;
5682 if (desc->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
5684 usage |= WINED3DUSAGE_RENDERTARGET;
5685 desc->ddsCaps.dwCaps |= DDSCAPS_VISIBLE;
5688 if ((desc->ddsCaps.dwCaps & DDSCAPS_3DDEVICE) && !(desc->ddsCaps.dwCaps & DDSCAPS_ZBUFFER))
5690 usage |= WINED3DUSAGE_RENDERTARGET;
5693 if (desc->ddsCaps.dwCaps & (DDSCAPS_OVERLAY))
5695 usage |= WINED3DUSAGE_OVERLAY;
5698 if (desc->ddsCaps.dwCaps & DDSCAPS_ZBUFFER)
5699 usage |= WINED3DUSAGE_DEPTHSTENCIL;
5701 if (desc->ddsCaps.dwCaps & DDSCAPS_OWNDC)
5702 usage |= WINED3DUSAGE_OWNDC;
5704 if (desc->ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY)
5706 pool = WINED3D_POOL_SYSTEM_MEM;
5708 else if (desc->ddsCaps.dwCaps2 & DDSCAPS2_TEXTUREMANAGE)
5710 pool = WINED3D_POOL_MANAGED;
5711 /* Managed textures have the system memory flag set. */
5712 desc->ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY;
5714 else if (desc->ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY)
5716 /* Videomemory adds localvidmem. This is mutually exclusive with
5717 * systemmemory and texturemanage. */
5718 desc->ddsCaps.dwCaps |= DDSCAPS_LOCALVIDMEM;
5721 format = PixelFormat_DD2WineD3D(&desc->u4.ddpfPixelFormat);
5722 if (format == WINED3DFMT_UNKNOWN)
5724 WARN("Unsupported / unknown pixelformat.\n");
5725 return DDERR_INVALIDPIXELFORMAT;
5728 surface->IDirectDrawSurface7_iface.lpVtbl = &ddraw_surface7_vtbl;
5729 surface->IDirectDrawSurface4_iface.lpVtbl = &ddraw_surface4_vtbl;
5730 surface->IDirectDrawSurface3_iface.lpVtbl = &ddraw_surface3_vtbl;
5731 surface->IDirectDrawSurface2_iface.lpVtbl = &ddraw_surface2_vtbl;
5732 surface->IDirectDrawSurface_iface.lpVtbl = &ddraw_surface1_vtbl;
5733 surface->IDirectDrawGammaControl_iface.lpVtbl = &ddraw_gamma_control_vtbl;
5734 surface->IDirect3DTexture2_iface.lpVtbl = &d3d_texture2_vtbl;
5735 surface->IDirect3DTexture_iface.lpVtbl = &d3d_texture1_vtbl;
5736 surface->iface_count = 1;
5737 surface->version = version;
5738 surface->ddraw = ddraw;
5740 if (version == 7)
5742 surface->ref7 = 1;
5743 surface->texture_outer = (IUnknown *)&surface->IDirectDrawSurface7_iface;
5745 else if (version == 4)
5747 surface->ref4 = 1;
5748 surface->texture_outer = (IUnknown *)&surface->IDirectDrawSurface4_iface;
5750 else
5752 surface->ref1 = 1;
5753 surface->texture_outer = (IUnknown *)&surface->IDirectDrawSurface_iface;
5756 copy_to_surfacedesc2(&surface->surface_desc, desc);
5758 surface->first_attached = surface;
5760 hr = wined3d_surface_create(ddraw->wined3d_device, desc->dwWidth, desc->dwHeight, format, mip_level,
5761 usage, pool, WINED3D_MULTISAMPLE_NONE, 0, DefaultSurfaceType, flags,
5762 surface, &ddraw_surface_wined3d_parent_ops, &surface->wined3d_surface);
5763 if (FAILED(hr))
5765 WARN("Failed to create wined3d surface, hr %#x.\n", hr);
5766 return hr;
5769 /* Anno 1602 stores the pitch right after surface creation, so make sure
5770 * it's there. TODO: Test other fourcc formats. */
5771 if (format == WINED3DFMT_DXT1 || format == WINED3DFMT_DXT2 || format == WINED3DFMT_DXT3
5772 || format == WINED3DFMT_DXT4 || format == WINED3DFMT_DXT5)
5774 surface->surface_desc.dwFlags |= DDSD_LINEARSIZE;
5775 if (format == WINED3DFMT_DXT1)
5777 surface->surface_desc.u1.dwLinearSize = max(4, desc->dwWidth) * max(4, desc->dwHeight) / 2;
5779 else
5781 surface->surface_desc.u1.dwLinearSize = max(4, desc->dwWidth) * max(4, desc->dwHeight);
5784 else
5786 surface->surface_desc.dwFlags |= DDSD_PITCH;
5787 surface->surface_desc.u1.lPitch = wined3d_surface_get_pitch(surface->wined3d_surface);
5790 if (desc->dwFlags & DDSD_CKDESTOVERLAY)
5792 wined3d_surface_set_color_key(surface->wined3d_surface, DDCKEY_DESTOVERLAY,
5793 (struct wined3d_color_key *)&desc->u3.ddckCKDestOverlay);
5795 if (desc->dwFlags & DDSD_CKDESTBLT)
5797 wined3d_surface_set_color_key(surface->wined3d_surface, DDCKEY_DESTBLT,
5798 (struct wined3d_color_key *)&desc->ddckCKDestBlt);
5800 if (desc->dwFlags & DDSD_CKSRCOVERLAY)
5802 wined3d_surface_set_color_key(surface->wined3d_surface, DDCKEY_SRCOVERLAY,
5803 (struct wined3d_color_key *)&desc->ddckCKSrcOverlay);
5805 if (desc->dwFlags & DDSD_CKSRCBLT)
5807 wined3d_surface_set_color_key(surface->wined3d_surface, DDCKEY_SRCBLT,
5808 (struct wined3d_color_key *)&desc->ddckCKSrcBlt);
5810 if (desc->dwFlags & DDSD_LPSURFACE)
5812 hr = wined3d_surface_set_mem(surface->wined3d_surface, desc->lpSurface);
5813 if (FAILED(hr))
5815 ERR("Failed to set surface memory, hr %#x.\n", hr);
5816 wined3d_surface_decref(surface->wined3d_surface);
5817 return hr;
5821 return DD_OK;