1 /* DirectDrawSurface base implementation
3 * Copyright 1997-2000 Marcus Meissner
4 * Copyright 1998-2000 Lionel Ulmer (most of Direct3D stuff)
5 * Copyright 2000-2001 TransGaming Technologies Inc.
13 #include "debugtools.h"
14 #include "ddraw_private.h"
15 #include "dsurface/main.h"
16 #include "ddraw/main.h"
17 #include "dsurface/thunks.h"
19 DEFAULT_DEBUG_CHANNEL(ddraw);
21 /** Creation/Destruction functions */
24 Main_DirectDrawSurface_Construct(IDirectDrawSurfaceImpl *This,
26 const DDSURFACEDESC2 *pDDSD)
28 if (pDDSD != &This->surface_desc) {
29 This->surface_desc.dwSize = sizeof(This->surface_desc);
30 DD_STRUCT_COPY_BYSIZE(&(This->surface_desc),pDDSD);
32 This->uniqueness_value = 1; /* unchecked */
35 This->local.lpSurfMore = &This->more;
36 This->local.lpGbl = &This->global;
37 This->local.dwProcessId = GetCurrentProcessId();
38 This->local.dwFlags = 0; /* FIXME */
39 This->local.ddsCaps.dwCaps = This->surface_desc.ddsCaps.dwCaps;
40 /* FIXME: more local stuff */
41 This->more.lpDD_lcl = &pDD->local;
42 This->more.ddsCapsEx.dwCaps2 = This->surface_desc.ddsCaps.dwCaps2;
43 This->more.ddsCapsEx.dwCaps3 = This->surface_desc.ddsCaps.dwCaps3;
44 This->more.ddsCapsEx.dwCaps4 = This->surface_desc.ddsCaps.dwCaps4;
45 /* FIXME: more more stuff */
46 This->gmore = &This->global_more;
47 This->global.u3.lpDD = pDD->local.lpGbl;
48 /* FIXME: more global stuff */
50 This->final_release = Main_DirectDrawSurface_final_release;
51 This->late_allocate = Main_DirectDrawSurface_late_allocate;
52 This->attach = Main_DirectDrawSurface_attach;
53 This->detach = Main_DirectDrawSurface_detach;
54 This->lock_update = Main_DirectDrawSurface_lock_update;
55 This->unlock_update = Main_DirectDrawSurface_unlock_update;
56 This->lose_surface = Main_DirectDrawSurface_lose_surface;
57 This->set_palette = Main_DirectDrawSurface_set_palette;
58 This->update_palette = Main_DirectDrawSurface_update_palette;
59 This->get_display_window = Main_DirectDrawSurface_get_display_window;
60 This->get_gamma_ramp = Main_DirectDrawSurface_get_gamma_ramp;
61 This->set_gamma_ramp = Main_DirectDrawSurface_set_gamma_ramp;
63 ICOM_INIT_INTERFACE(This, IDirectDrawSurface3,
64 DDRAW_IDDS3_Thunk_VTable);
65 ICOM_INIT_INTERFACE(This, IDirectDrawGammaControl,
67 /* There is no generic implementation of IDDS7 */
69 Main_DirectDraw_AddSurface(pDD, This);
73 void Main_DirectDrawSurface_final_release(IDirectDrawSurfaceImpl* This)
75 Main_DirectDraw_RemoveSurface(This->ddraw_owner, This);
78 HRESULT Main_DirectDrawSurface_late_allocate(IDirectDrawSurfaceImpl* This)
83 static void Main_DirectDrawSurface_Destroy(IDirectDrawSurfaceImpl* This)
85 This->final_release(This);
86 if (This->private != This+1) HeapFree(GetProcessHeap(), 0, This->private);
87 HeapFree(GetProcessHeap(), 0, This);
90 void Main_DirectDrawSurface_ForceDestroy(IDirectDrawSurfaceImpl* This)
92 WARN("destroying surface %p with refcnt %lu\n", This, This->ref);
93 Main_DirectDrawSurface_Destroy(This);
96 ULONG WINAPI Main_DirectDrawSurface_Release(LPDIRECTDRAWSURFACE7 iface)
98 ICOM_THIS(IDirectDrawSurfaceImpl, iface);
100 if (--This->ref == 0)
102 if (This->aux_release)
103 This->aux_release(This->aux_ctx, This->aux_data);
104 Main_DirectDrawSurface_Destroy(This);
111 ULONG WINAPI Main_DirectDrawSurface_AddRef(LPDIRECTDRAWSURFACE7 iface)
113 ICOM_THIS(IDirectDrawSurfaceImpl, iface);
119 Main_DirectDrawSurface_QueryInterface(LPDIRECTDRAWSURFACE7 iface, REFIID riid,
122 ICOM_THIS(IDirectDrawSurfaceImpl, iface);
123 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(riid), ppObj);
125 if (IsEqualGUID(&IID_IUnknown, riid)
126 || IsEqualGUID(&IID_IDirectDrawSurface7, riid)
127 || IsEqualGUID(&IID_IDirectDrawSurface4, riid))
130 *ppObj = ICOM_INTERFACE(This, IDirectDrawSurface7);
133 else if (IsEqualGUID(&IID_IDirectDrawSurface, riid)
134 || IsEqualGUID(&IID_IDirectDrawSurface2, riid)
135 || IsEqualGUID(&IID_IDirectDrawSurface3, riid))
138 *ppObj = ICOM_INTERFACE(This, IDirectDrawSurface3);
141 else if (IsEqualGUID(&IID_IDirectDrawGammaControl, riid))
144 *ppObj = ICOM_INTERFACE(This, IDirectDrawGammaControl);
148 return E_NOINTERFACE;
154 Main_DirectDrawSurface_attach(IDirectDrawSurfaceImpl *This,
155 IDirectDrawSurfaceImpl *to)
160 BOOL Main_DirectDrawSurface_detach(IDirectDrawSurfaceImpl *This)
166 Main_DirectDrawSurface_lock_update(IDirectDrawSurfaceImpl* This, LPCRECT pRect)
171 Main_DirectDrawSurface_unlock_update(IDirectDrawSurfaceImpl* This,
177 Main_DirectDrawSurface_lose_surface(IDirectDrawSurfaceImpl* This)
182 Main_DirectDrawSurface_set_palette(IDirectDrawSurfaceImpl* This,
183 IDirectDrawPaletteImpl* pal)
188 Main_DirectDrawSurface_update_palette(IDirectDrawSurfaceImpl* This,
189 IDirectDrawPaletteImpl* pal,
190 DWORD dwStart, DWORD dwCount,
191 LPPALETTEENTRY palent)
196 Main_DirectDrawSurface_get_display_window(IDirectDrawSurfaceImpl* This)
202 Main_DirectDrawSurface_get_gamma_ramp(IDirectDrawSurfaceImpl* This,
204 LPDDGAMMARAMP lpGammaRamp)
208 hr = This->get_dc(This, &hDC);
209 if (FAILED(hr)) return hr;
210 hr = GetDeviceGammaRamp(hDC, lpGammaRamp) ? DD_OK : DDERR_UNSUPPORTED;
211 This->release_dc(This, hDC);
216 Main_DirectDrawSurface_set_gamma_ramp(IDirectDrawSurfaceImpl* This,
218 LPDDGAMMARAMP lpGammaRamp)
222 hr = This->get_dc(This, &hDC);
223 if (FAILED(hr)) return hr;
224 hr = SetDeviceGammaRamp(hDC, lpGammaRamp) ? DD_OK : DDERR_UNSUPPORTED;
225 This->release_dc(This, hDC);
230 /*** Interface functions */
233 Main_DirectDrawSurface_AddAttachedSurface(LPDIRECTDRAWSURFACE7 iface,
234 LPDIRECTDRAWSURFACE7 pAttach)
236 ICOM_THIS(IDirectDrawSurfaceImpl, iface);
237 IDirectDrawSurfaceImpl* surf = ICOM_OBJECT(IDirectDrawSurfaceImpl,
238 IDirectDrawSurface7, pAttach);
240 TRACE("(%p)->(%p)\n",This,pAttach);
242 /* Does windows check this? */
244 return DDERR_CANNOTATTACHSURFACE; /* unchecked */
246 /* Does windows check this? */
247 if (surf->ddraw_owner != This->ddraw_owner)
248 return DDERR_CANNOTATTACHSURFACE; /* unchecked */
250 if (surf->surface_owner != NULL)
251 return DDERR_SURFACEALREADYATTACHED; /* unchecked */
253 /* TODO MSDN: "You can attach only z-buffer surfaces with this method."
254 * But apparently backbuffers and mipmaps can be attached too. */
256 /* Set MIPMAPSUBLEVEL if this seems to be one */
257 if (This->surface_desc.ddsCaps.dwCaps &
258 surf->surface_desc.ddsCaps.dwCaps & DDSCAPS_MIPMAP) {
259 surf->surface_desc.ddsCaps.dwCaps2 |= DDSCAPS2_MIPMAPSUBLEVEL;
260 /* FIXME: we should probably also add to dwMipMapCount of this
261 * and all parent surfaces (update create_texture if you do) */
264 /* Callback to allow the surface to do something special now that it is
265 * attached. (e.g. maybe the Z-buffer tells the renderer to use it.) */
266 if (!surf->attach(surf, This))
267 return DDERR_CANNOTATTACHSURFACE;
269 /* check: Where should it go in the chain? This puts it on the head. */
271 This->attached->prev_attached = surf;
272 surf->next_attached = This->attached;
273 surf->prev_attached = NULL;
274 This->attached = surf;
275 surf->surface_owner = This;
277 IDirectDrawSurface7_AddRef(pAttach);
282 /* MSDN: "not currently implemented." */
284 Main_DirectDrawSurface_AddOverlayDirtyRect(LPDIRECTDRAWSURFACE7 iface,
287 TRACE("(%p)->(%p)\n",iface,pRect);
288 return DDERR_UNSUPPORTED; /* unchecked */
291 /* MSDN: "not currently implemented." */
293 Main_DirectDrawSurface_BltBatch(LPDIRECTDRAWSURFACE7 iface,
294 LPDDBLTBATCH pBatch, DWORD dwCount,
297 TRACE("(%p)->(%p,%ld,%08lx)\n",iface,pBatch,dwCount,dwFlags);
298 return DDERR_UNSUPPORTED; /* unchecked */
302 Main_DirectDrawSurface_ChangeUniquenessValue(LPDIRECTDRAWSURFACE7 iface)
304 ICOM_THIS(IDirectDrawSurfaceImpl, iface);
305 volatile IDirectDrawSurfaceImpl* vThis = This;
307 TRACE("(%p)\n",This);
308 /* A uniquness value of 0 is apparently special.
309 * This needs to be checked. */
312 DWORD old_uniqueness_value = vThis->uniqueness_value;
313 DWORD new_uniqueness_value = old_uniqueness_value+1;
315 if (old_uniqueness_value == 0) break;
316 if (new_uniqueness_value == 0) new_uniqueness_value = 1;
318 if (InterlockedCompareExchange((LONG*)&vThis->uniqueness_value,
319 old_uniqueness_value,
320 new_uniqueness_value)
321 == old_uniqueness_value)
329 Main_DirectDrawSurface_DeleteAttachedSurface(LPDIRECTDRAWSURFACE7 iface,
331 LPDIRECTDRAWSURFACE7 pAttach)
333 ICOM_THIS(IDirectDrawSurfaceImpl, iface);
334 IDirectDrawSurfaceImpl* surf = ICOM_OBJECT(IDirectDrawSurfaceImpl,
335 IDirectDrawSurface7, pAttach);
337 TRACE("(%p)->(%08lx,%p)\n",This,dwFlags,pAttach);
339 if (!surf || (surf->surface_owner != This))
340 return DDERR_SURFACENOTATTACHED; /* unchecked */
344 /* Remove MIPMAPSUBLEVEL if this seemed to be one */
345 if (This->surface_desc.ddsCaps.dwCaps &
346 surf->surface_desc.ddsCaps.dwCaps & DDSCAPS_MIPMAP) {
347 surf->surface_desc.ddsCaps.dwCaps2 &= ~DDSCAPS2_MIPMAPSUBLEVEL;
348 /* FIXME: we should probably also subtract from dwMipMapCount of this
349 * and all parent surfaces */
352 if (surf->next_attached)
353 surf->next_attached->prev_attached = surf->prev_attached;
354 if (surf->prev_attached)
355 surf->prev_attached->next_attached = surf->next_attached;
356 if (This->attached == surf)
357 This->attached = surf->next_attached;
359 IDirectDrawSurface7_Release(pAttach);
365 Main_DirectDrawSurface_EnumAttachedSurfaces(LPDIRECTDRAWSURFACE7 iface,
367 LPDDENUMSURFACESCALLBACK7 cb)
369 ICOM_THIS(IDirectDrawSurfaceImpl, iface);
370 IDirectDrawSurfaceImpl* surf;
372 TRACE("(%p)->(%p,%p)\n",This,context,cb);
374 for (surf = This->attached; surf != NULL; surf = surf->next_attached)
376 /* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
377 if (cb(ICOM_INTERFACE(surf, IDirectDrawSurface7), &surf->surface_desc,
378 context) == DDENUMRET_CANCEL)
386 Main_DirectDrawSurface_EnumOverlayZOrders(LPDIRECTDRAWSURFACE7 iface,
387 DWORD dwFlags, LPVOID context,
388 LPDDENUMSURFACESCALLBACK7 cb)
390 TRACE("(%p)->(%08lx,%p,%p)\n",iface,dwFlags,context,cb);
394 BOOL Main_DirectDrawSurface_flip_data(IDirectDrawSurfaceImpl* front,
395 IDirectDrawSurfaceImpl* back,
398 /* uniqueness_value? */
399 /* This is necessary. But is it safe? */
401 HDC tmp = front->hDC;
402 front->hDC = back->hDC;
407 BOOL tmp = front->dc_in_use;
408 front->dc_in_use = back->dc_in_use;
409 back->dc_in_use = tmp;
413 FLATPTR tmp = front->global.fpVidMem;
414 front->global.fpVidMem = back->global.fpVidMem;
415 back->global.fpVidMem = tmp;
419 ULONG_PTR tmp = front->global_more.hKernelSurface;
420 front->global_more.hKernelSurface = back->global_more.hKernelSurface;
421 back->global_more.hKernelSurface = tmp;
428 Main_DirectDrawSurface_Flip(LPDIRECTDRAWSURFACE7 iface,
429 LPDIRECTDRAWSURFACE7 override, DWORD dwFlags)
431 ICOM_THIS(IDirectDrawSurfaceImpl, iface);
432 IDirectDrawSurfaceImpl* target;
435 TRACE("(%p)->(%p,%08lx)\n",This,override,dwFlags);
437 /* MSDN: "This method can be called only for a surface that has the
438 * DDSCAPS_FLIP and DDSCAPS_FRONTBUFFER capabilities." */
439 if ((This->surface_desc.ddsCaps.dwCaps&(DDSCAPS_FLIP|DDSCAPS_FRONTBUFFER))
440 != (DDSCAPS_FLIP|DDSCAPS_FRONTBUFFER))
441 return DDERR_NOTFLIPPABLE;
444 if (This->aux_flip(This->aux_ctx, This->aux_data))
447 /* 1. find the flip target */
448 /* XXX I don't think this algorithm works for more than 1 backbuffer. */
449 if (override == NULL)
451 static DDSCAPS2 back_caps = { DDSCAPS_BACKBUFFER };
452 LPDIRECTDRAWSURFACE7 tgt;
454 hr = IDirectDrawSurface7_GetAttachedSurface(iface, &back_caps, &tgt);
455 if (FAILED(hr)) return DDERR_NOTFLIPPABLE; /* unchecked */
457 target = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7,
459 IDirectDrawSurface7_Release(tgt);
463 BOOL on_chain = FALSE;
464 IDirectDrawSurfaceImpl* surf;
466 /* MSDN: "The method fails if the specified [override] surface is not
467 * a member of the flipping chain." */
469 /* Verify that override is on this flip chain. We assume that
470 * surf is the head of the flipping chain, because it's the front
472 target = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7,
475 /* Either target is (indirectly) attached to This or This is
476 * (indirectly) attached to target. */
477 for (surf = target; surf != NULL; surf = surf->surface_owner)
487 return DDERR_INVALIDPARAMS; /* unchecked */
490 TRACE("flip to backbuffer: %p\n",target);
491 if (This->flip_data(This, target, dwFlags))
492 This->flip_update(This, dwFlags);
497 static PrivateData* find_private_data(IDirectDrawSurfaceImpl *This,
501 for (data = This->private_data; data != NULL; data = data->next)
503 if (IsEqualGUID(&data->tag, tag)) break;
510 Main_DirectDrawSurface_FreePrivateData(LPDIRECTDRAWSURFACE7 iface, REFGUID tag)
512 ICOM_THIS(IDirectDrawSurfaceImpl, iface);
515 data = find_private_data(This, tag);
516 if (data == NULL) return DDERR_NOTFOUND;
519 data->prev->next = data->next;
521 data->next->prev = data->prev;
523 if (data->flags & DDSPD_IUNKNOWNPTR)
525 if (data->ptr.object != NULL)
526 IUnknown_Release(data->ptr.object);
529 HeapFree(GetProcessHeap(), 0, data->ptr.data);
531 HeapFree(GetProcessHeap(), 0, data);
537 Main_DirectDrawSurface_GetAttachedSurface(LPDIRECTDRAWSURFACE7 iface,
539 LPDIRECTDRAWSURFACE7* ppSurface)
541 ICOM_THIS(IDirectDrawSurfaceImpl, iface);
542 IDirectDrawSurfaceImpl* surf;
543 IDirectDrawSurfaceImpl* found = NULL;
545 TRACE("(%p)->Looking for caps: %lx,%lx,%lx,%lx output: %p\n",This,pCaps->dwCaps, pCaps->dwCaps2,
546 pCaps->dwCaps3, pCaps->dwCaps4, ppSurface);
548 for (surf = This->attached; surf != NULL; surf = surf->next_attached)
550 TRACE("Surface: (%p) caps: %lx,%lx,%lx,%lx \n",surf ,
551 surf->surface_desc.ddsCaps.dwCaps,
552 surf->surface_desc.ddsCaps.dwCaps2,
553 surf->surface_desc.ddsCaps.dwCaps3,
554 surf->surface_desc.ddsCaps.dwCaps4);
555 if (((surf->surface_desc.ddsCaps.dwCaps & pCaps->dwCaps) == pCaps->dwCaps)
556 && ((surf->surface_desc.ddsCaps.dwCaps2 & pCaps->dwCaps2) == pCaps->dwCaps2))
558 /* MSDN: "This method fails if more than one surface is attached
559 * that matches the capabilities requested." */
562 FIXME("More than one attached surface matches requested caps. What should we do here?\n");
563 /* Previous code returned 'DDERR_NOTFOUND'. That appears not
564 to be correct, given what 3DMark expects from MipMapped surfaces.
565 We shall just continue instead. */
573 return DDERR_NOTFOUND;
575 *ppSurface = ICOM_INTERFACE(found, IDirectDrawSurface7);
577 /* XXX d3dframe.cpp sometimes AddRefs things that it gets from us. */
578 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(found, IDirectDrawSurface7));
583 Main_DirectDrawSurface_GetBltStatus(LPDIRECTDRAWSURFACE7 iface, DWORD dwFlags)
585 TRACE("(%p)->(%08lx)\n",iface,dwFlags);
590 case DDGBS_ISBLTDONE:
594 return DDERR_INVALIDPARAMS;
599 Main_DirectDrawSurface_GetCaps(LPDIRECTDRAWSURFACE7 iface, LPDDSCAPS2 pCaps)
601 ICOM_THIS(IDirectDrawSurfaceImpl, iface);
603 TRACE("(%p)->(%p)\n",This,pCaps);
604 *pCaps = This->surface_desc.ddsCaps;
609 Main_DirectDrawSurface_GetClipper(LPDIRECTDRAWSURFACE7 iface,
610 LPDIRECTDRAWCLIPPER* ppClipper)
612 ICOM_THIS(IDirectDrawSurfaceImpl, iface);
614 TRACE("(%p)->(%p)\n",This,ppClipper);
615 if (This->clipper == NULL)
616 return DDERR_NOCLIPPERATTACHED;
618 *ppClipper = ICOM_INTERFACE(This->clipper, IDirectDrawClipper);
619 IDirectDrawClipper_AddRef(ICOM_INTERFACE(This->clipper,
620 IDirectDrawClipper));
625 Main_DirectDrawSurface_GetColorKey(LPDIRECTDRAWSURFACE7 iface, DWORD dwFlags,
628 /* There is a DDERR_NOCOLORKEY error, but how do we know if a color key
629 * isn't there? That's like saying that an int isn't there. (Which MS
630 * has done in other docs.) */
632 ICOM_THIS(IDirectDrawSurfaceImpl, iface);
634 TRACE("(%p)->(%08lx,%p)\n",This,dwFlags,pCKey);
638 *pCKey = This->surface_desc.ddckCKDestBlt;
641 case DDCKEY_DESTOVERLAY:
642 *pCKey = This->surface_desc.u3.ddckCKDestOverlay;
646 *pCKey = This->surface_desc.ddckCKSrcBlt;
649 case DDCKEY_SRCOVERLAY:
650 *pCKey = This->surface_desc.ddckCKSrcOverlay;
654 return DDERR_INVALIDPARAMS;
660 /* XXX We need to do something with the DC if the surface gets lost. */
662 Main_DirectDrawSurface_GetDC(LPDIRECTDRAWSURFACE7 iface, HDC *phDC)
666 ICOM_THIS(IDirectDrawSurfaceImpl, iface);
668 TRACE("(%p)->(%p)\n",This,phDC);
676 return DDERR_DCALREADYCREATED;
680 * Strange: Lock lists DDERR_SURFACEBUSY as an error, meaning that another
681 * thread has it locked, but GetDC does not. */
682 ddsd.dwSize = sizeof(ddsd);
683 hr = IDirectDrawSurface7_Lock(iface, NULL, &ddsd, 0, 0);
690 hr = This->get_dc(This, &This->hDC);
693 TRACE("returning %08x\n",This->hDC);
696 This->dc_in_use = TRUE;
698 else WARN("No DC! Prepare for trouble\n");
705 Main_DirectDrawSurface_GetDDInterface(LPDIRECTDRAWSURFACE7 iface, LPVOID* pDD)
707 ICOM_THIS(IDirectDrawSurfaceImpl, iface);
709 TRACE("(%p)->(%p)\n",This,pDD);
710 *pDD = ICOM_INTERFACE(This->ddraw_owner, IDirectDraw7);
711 IDirectDraw7_AddRef(ICOM_INTERFACE(This->ddraw_owner, IDirectDraw7));
716 Main_DirectDrawSurface_GetFlipStatus(LPDIRECTDRAWSURFACE7 iface, DWORD dwFlags)
718 /* XXX: DDERR_INVALIDSURFACETYPE */
720 TRACE("(%p)->(%08lx)\n",iface,dwFlags);
724 case DDGFS_ISFLIPDONE:
728 return DDERR_INVALIDPARAMS;
733 Main_DirectDrawSurface_GetLOD(LPDIRECTDRAWSURFACE7 iface, LPDWORD pdwMaxLOD)
735 ICOM_THIS(IDirectDrawSurfaceImpl, iface);
737 TRACE("(%p)->(%p)\n",This,pdwMaxLOD);
740 *pdwMaxLOD = This->max_lod;
745 Main_DirectDrawSurface_GetOverlayPosition(LPDIRECTDRAWSURFACE7 iface,
746 LPLONG pX, LPLONG pY)
748 return DDERR_NOTAOVERLAYSURFACE;
752 Main_DirectDrawSurface_GetPalette(LPDIRECTDRAWSURFACE7 iface,
753 LPDIRECTDRAWPALETTE* ppPalette)
755 ICOM_THIS(IDirectDrawSurfaceImpl, iface);
757 TRACE("(%p)->(%p)\n",This,ppPalette);
758 if (This->palette == NULL)
759 return DDERR_NOPALETTEATTACHED;
761 *ppPalette = ICOM_INTERFACE(This->palette, IDirectDrawPalette);
762 IDirectDrawPalette_AddRef(ICOM_INTERFACE(This->palette,
763 IDirectDrawPalette));
768 Main_DirectDrawSurface_GetPixelFormat(LPDIRECTDRAWSURFACE7 iface,
769 LPDDPIXELFORMAT pDDPixelFormat)
771 /* What is DDERR_INVALIDSURFACETYPE for here? */
772 ICOM_THIS(IDirectDrawSurfaceImpl, iface);
774 TRACE("(%p)->(%p)\n",This,pDDPixelFormat);
775 DD_STRUCT_COPY_BYSIZE(pDDPixelFormat,&This->surface_desc.u4.ddpfPixelFormat);
780 Main_DirectDrawSurface_GetPriority(LPDIRECTDRAWSURFACE7 iface,
783 ICOM_THIS(IDirectDrawSurfaceImpl, iface);
785 TRACE("(%p)->(%p)\n",This,pdwPriority);
788 *pdwPriority = This->priority;
793 Main_DirectDrawSurface_GetPrivateData(LPDIRECTDRAWSURFACE7 iface,
794 REFGUID tag, LPVOID pBuffer,
795 LPDWORD pcbBufferSize)
797 ICOM_THIS(IDirectDrawSurfaceImpl, iface);
800 data = find_private_data(This, tag);
801 if (data == NULL) return DDERR_NOTFOUND;
803 /* This may not be right. */
804 if ((data->flags & DDSPD_VOLATILE)
805 && data->uniqueness_value != This->uniqueness_value)
806 return DDERR_EXPIRED;
808 if (*pcbBufferSize < data->size)
810 *pcbBufferSize = data->size;
811 return DDERR_MOREDATA;
814 if (data->flags & DDSPD_IUNKNOWNPTR)
816 *(LPUNKNOWN *)pBuffer = data->ptr.object;
817 IUnknown_AddRef(data->ptr.object);
821 memcpy(pBuffer, data->ptr.data, data->size);
828 Main_DirectDrawSurface_GetSurfaceDesc(LPDIRECTDRAWSURFACE7 iface,
829 LPDDSURFACEDESC2 pDDSD)
831 ICOM_THIS(IDirectDrawSurfaceImpl, iface);
833 TRACE("(%p)->(%p)\n",This,pDDSD);
834 if ((pDDSD->dwSize < sizeof(DDSURFACEDESC)) ||
835 (pDDSD->dwSize > sizeof(DDSURFACEDESC2))) {
836 ERR("Impossible/Strange struct size %ld.\n",pDDSD->dwSize);
837 return DDERR_GENERIC;
840 DD_STRUCT_COPY_BYSIZE(pDDSD,&This->surface_desc);
845 Main_DirectDrawSurface_GetUniquenessValue(LPDIRECTDRAWSURFACE7 iface,
848 ICOM_THIS(IDirectDrawSurfaceImpl, iface);
850 TRACE("(%p)->(%p)\n",This,pValue);
851 *pValue = This->uniqueness_value;
856 Main_DirectDrawSurface_Initialize(LPDIRECTDRAWSURFACE7 iface,
857 LPDIRECTDRAW pDD, LPDDSURFACEDESC2 pDDSD)
859 TRACE("(%p)->(%p,%p)\n",iface,pDD,pDDSD);
860 return DDERR_ALREADYINITIALIZED;
864 Main_DirectDrawSurface_IsLost(LPDIRECTDRAWSURFACE7 iface)
866 ICOM_THIS(IDirectDrawSurfaceImpl, iface);
868 TRACE("(%p) is%s lost\n",This, (This->lost ? "" : " not"));
869 return This->lost ? DDERR_SURFACELOST : DD_OK;
873 /* XXX This doesn't actually do any locking or keep track of the locked
874 * rectangles. The behaviour is poorly documented. */
876 Main_DirectDrawSurface_Lock(LPDIRECTDRAWSURFACE7 iface, LPRECT prect,
877 LPDDSURFACEDESC2 pDDSD, DWORD flags, HANDLE h)
879 ICOM_THIS(IDirectDrawSurfaceImpl, iface);
881 TRACE("(%p)->Lock(%p,%p,%08lx,%08lx)\n",This,prect,pDDSD,flags,(DWORD)h);
883 if (flags & ~(DDLOCK_WAIT|DDLOCK_READONLY|DDLOCK_WRITEONLY))
884 WARN("(%p)->Lock(%p,%p,%08lx,%08lx)\n",
885 This,prect,pDDSD,flags,(DWORD)h);
887 /* First, copy the Surface description */
888 DD_STRUCT_COPY_BYSIZE(pDDSD,&(This->surface_desc));
890 TRACE("locked surface: height=%ld, width=%ld, pitch=%ld\n",
891 pDDSD->dwHeight,pDDSD->dwWidth,pDDSD->u1.lPitch);
893 /* If asked only for a part, change the surface pointer.
894 * (Not documented.) */
896 TRACE(" lprect: %dx%d-%dx%d\n",
897 prect->top,prect->left,prect->bottom,prect->right
899 if ((prect->top < 0) ||
901 (prect->bottom < 0) ||
902 (prect->right < 0)) {
903 ERR(" Negative values in LPRECT !!!\n");
904 return DDERR_INVALIDPARAMS;
907 This->lock_update(This, prect);
909 pDDSD->lpSurface = (char *)This->surface_desc.lpSurface
910 + prect->top * This->surface_desc.u1.lPitch
911 + prect->left * GET_BPP(This->surface_desc);
918 Main_DirectDrawSurface_PageLock(LPDIRECTDRAWSURFACE7 iface, DWORD dwFlags)
920 /* Some surface types should return DDERR_CANTPAGELOCK. */
925 Main_DirectDrawSurface_PageUnlock(LPDIRECTDRAWSURFACE7 iface, DWORD dwFlags)
927 /* Some surface types should return DDERR_CANTPAGEUNLOCK, and we should
928 * keep track so we can return DDERR_NOTPAGELOCKED as appropriate. */
933 Main_DirectDrawSurface_ReleaseDC(LPDIRECTDRAWSURFACE7 iface, HDC hDC)
936 ICOM_THIS(IDirectDrawSurfaceImpl, iface);
938 TRACE("(%p)->(%08x)\n",This,hDC);
940 if (!This->dc_in_use || This->hDC != hDC)
941 return DDERR_INVALIDPARAMS;
943 This->release_dc(This, hDC);
945 hr = IDirectDrawSurface7_Unlock(iface, NULL);
946 if (FAILED(hr)) return hr;
948 This->dc_in_use = FALSE;
957 Main_DirectDrawSurface_SetClipper(LPDIRECTDRAWSURFACE7 iface,
958 LPDIRECTDRAWCLIPPER pDDClipper)
960 ICOM_THIS(IDirectDrawSurfaceImpl, iface);
962 TRACE("(%p)->(%p)\n",This,pDDClipper);
963 if (pDDClipper == ICOM_INTERFACE(This->clipper, IDirectDrawClipper))
966 if (This->clipper != NULL)
967 IDirectDrawClipper_Release(ICOM_INTERFACE(This->clipper,
968 IDirectDrawClipper));
970 This->clipper = ICOM_OBJECT(IDirectDrawClipperImpl, IDirectDrawClipper,
972 if (pDDClipper != NULL)
973 IDirectDrawClipper_AddRef(pDDClipper);
979 Main_DirectDrawSurface_SetColorKey(LPDIRECTDRAWSURFACE7 iface,
980 DWORD dwFlags, LPDDCOLORKEY pCKey)
982 ICOM_THIS(IDirectDrawSurfaceImpl, iface);
984 TRACE("(%p)->(%08lx,%p)\n",This,dwFlags,pCKey);
987 FIXME("supposedly removing color key %lu\n",
988 dwFlags & ~DDCKEY_COLORSPACE);
992 switch (dwFlags & ~DDCKEY_COLORSPACE)
995 This->surface_desc.ddckCKDestBlt = *pCKey;
998 case DDCKEY_DESTOVERLAY:
999 This->surface_desc.u3.ddckCKDestOverlay = *pCKey;
1002 case DDCKEY_SRCOVERLAY:
1003 This->surface_desc.ddckCKSrcOverlay = *pCKey;
1007 This->surface_desc.ddckCKSrcBlt = *pCKey;
1011 return DDERR_INVALIDPARAMS;
1018 Main_DirectDrawSurface_SetLOD(LPDIRECTDRAWSURFACE7 iface, DWORD dwMaxLOD)
1020 ICOM_THIS(IDirectDrawSurfaceImpl, iface);
1022 TRACE("(%p)->(%08lx)\n",This,dwMaxLOD);
1023 CHECK_TEXTURE(This);
1025 This->max_lod = dwMaxLOD;
1030 Main_DirectDrawSurface_SetOverlayPosition(LPDIRECTDRAWSURFACE7 iface,
1033 return DDERR_NOTAOVERLAYSURFACE;
1037 Main_DirectDrawSurface_SetPalette(LPDIRECTDRAWSURFACE7 iface,
1038 LPDIRECTDRAWPALETTE pPalette)
1040 ICOM_THIS(IDirectDrawSurfaceImpl, iface);
1042 TRACE("(%p)->(%p)\n",This,pPalette);
1043 if (pPalette == ICOM_INTERFACE(This->palette, IDirectDrawPalette))
1046 if (This->palette != NULL) {
1047 if (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
1048 This->palette->flags &= ~DDPCAPS_PRIMARYSURFACE;
1049 IDirectDrawPalette_Release(ICOM_INTERFACE(This->palette,
1050 IDirectDrawPalette));
1053 This->palette = ICOM_OBJECT(IDirectDrawPaletteImpl, IDirectDrawPalette,
1055 if (pPalette != NULL) {
1056 IDirectDrawPalette_AddRef(pPalette);
1057 if (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
1058 This->palette->flags |= DDPCAPS_PRIMARYSURFACE;
1061 This->set_palette(This, This->palette);
1067 Main_DirectDrawSurface_SetPriority(LPDIRECTDRAWSURFACE7 iface,
1070 ICOM_THIS(IDirectDrawSurfaceImpl, iface);
1072 TRACE("(%p)->(%08lx)\n",This,dwPriority);
1073 CHECK_TEXTURE(This);
1075 This->priority = dwPriority;
1079 /* Be careful when locking this: it is risky to call the object's AddRef
1080 * or Release holding a lock. */
1082 Main_DirectDrawSurface_SetPrivateData(LPDIRECTDRAWSURFACE7 iface,
1083 REFGUID tag, LPVOID pData,
1084 DWORD cbSize, DWORD dwFlags)
1087 ICOM_THIS(IDirectDrawSurfaceImpl, iface);
1089 data = find_private_data(This, tag);
1092 data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data));
1093 if (data == NULL) return DDERR_OUTOFMEMORY;
1096 data->flags = dwFlags;
1097 data->uniqueness_value = This->uniqueness_value;
1099 if (dwFlags & DDSPD_IUNKNOWNPTR)
1101 data->ptr.object = (LPUNKNOWN)pData;
1102 data->size = sizeof(LPUNKNOWN);
1103 IUnknown_AddRef(data->ptr.object);
1107 data->ptr.data = HeapAlloc(GetProcessHeap(), 0, cbSize);
1108 if (data->ptr.data == NULL)
1110 HeapFree(GetProcessHeap(), 0, data);
1111 return DDERR_OUTOFMEMORY;
1116 data->next = This->private_data;
1118 if (This->private_data)
1119 This->private_data->prev = data;
1120 This->private_data = data;
1126 /* I don't actually know how windows handles this case. The only
1127 * reason I don't just call FreePrivateData is because I want to
1128 * guarantee SetPrivateData working when using LPUNKNOWN or data
1129 * that is no larger than the old data. */
1135 /* SetSurfaceDesc */
1138 Main_DirectDrawSurface_Unlock(LPDIRECTDRAWSURFACE7 iface, LPRECT pRect)
1140 ICOM_THIS(IDirectDrawSurfaceImpl,iface);
1142 TRACE("(%p)->Unlock(%p)\n",This,pRect);
1144 This->unlock_update(This, pRect);
1145 if (This->aux_unlock)
1146 This->aux_unlock(This->aux_ctx, This->aux_data, pRect);
1152 Main_DirectDrawSurface_UpdateOverlay(LPDIRECTDRAWSURFACE7 iface,
1154 LPDIRECTDRAWSURFACE7 pDstSurface,
1155 LPRECT pDstRect, DWORD dwFlags,
1158 return DDERR_UNSUPPORTED;
1161 /* MSDN: "not currently implemented." */
1163 Main_DirectDrawSurface_UpdateOverlayDisplay(LPDIRECTDRAWSURFACE7 iface,
1166 return DDERR_UNSUPPORTED;
1170 Main_DirectDrawSurface_UpdateOverlayZOrder(LPDIRECTDRAWSURFACE7 iface,
1172 LPDIRECTDRAWSURFACE7 pDDSRef)
1174 return DDERR_NOTAOVERLAYSURFACE;