From 0ed94ccae0b4aa64ad83897d5d37777c544e2f9b Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Sun, 1 Jul 2012 13:43:33 +0000 Subject: [PATCH] [WIN32K] - Implement SURFACE_vSetPalette and use it everywhere to set the palette for a surface. Make SURFACE::ppal const, so noone accidentally modifies it without properly handling the references. svn path=/trunk/; revision=56816 --- reactos/win32ss/gdi/eng/surface.c | 17 +++++++++++------ reactos/win32ss/gdi/eng/surface.h | 16 +++++++++++++++- reactos/win32ss/gdi/ntgdi/bitmaps.c | 22 +++++++++++++--------- reactos/win32ss/gdi/ntgdi/dibobj.c | 4 ++-- 4 files changed, 41 insertions(+), 18 deletions(-) diff --git a/reactos/win32ss/gdi/eng/surface.c b/reactos/win32ss/gdi/eng/surface.c index de9b79770af..8b54446f93b 100644 --- a/reactos/win32ss/gdi/eng/surface.c +++ b/reactos/win32ss/gdi/eng/surface.c @@ -267,8 +267,7 @@ SURFACE_AllocSurface( } /* Assign a default palette and increment its reference count */ - psurf->ppal = appalSurfaceDefault[iFormat]; - GDIOBJ_vReferenceObjectByPointer(&psurf->ppal->BaseObject); + SURFACE_vSetPalette(psurf, appalSurfaceDefault[iFormat]); return psurf; } @@ -399,6 +398,7 @@ EngAssociateSurface( SURFOBJ *pso; PSURFACE psurf; PDEVOBJ* ppdev; + PPALETTE ppal; ppdev = (PDEVOBJ*)hdev; @@ -418,8 +418,10 @@ EngAssociateSurface( psurf->flags &= ~HOOK_FLAGS; psurf->flags |= (flHooks & HOOK_FLAGS); - /* Get palette */ - psurf->ppal = PALETTE_ShareLockPalette(ppdev->devinfo.hpalDefault); + /* Assign the PDEV's palette */ + ppal = PALETTE_ShareLockPalette(ppdev->devinfo.hpalDefault); + SURFACE_vSetPalette(psurf, ppal); + PALETTE_ShareUnlockPalette(ppal); SURFACE_ShareUnlockSurface(psurf); @@ -441,6 +443,7 @@ EngModifySurface( SURFOBJ *pso; PSURFACE psurf; PDEVOBJ* ppdev; + PPALETTE ppal; psurf = SURFACE_ShareLockSurface(hsurf); if (psurf == NULL) @@ -462,8 +465,10 @@ EngModifySurface( psurf->flags &= ~HOOK_FLAGS; psurf->flags |= (flHooks & HOOK_FLAGS); - /* Get palette */ - psurf->ppal = PALETTE_ShareLockPalette(ppdev->devinfo.hpalDefault); + /* Assign the PDEV's palette */ + ppal = PALETTE_ShareLockPalette(ppdev->devinfo.hpalDefault); + SURFACE_vSetPalette(psurf, ppal); + PALETTE_ShareUnlockPalette(ppal); SURFACE_ShareUnlockSurface(psurf); diff --git a/reactos/win32ss/gdi/eng/surface.h b/reactos/win32ss/gdi/eng/surface.h index 550a6812070..86d054ed789 100644 --- a/reactos/win32ss/gdi/eng/surface.h +++ b/reactos/win32ss/gdi/eng/surface.h @@ -10,7 +10,7 @@ typedef struct _SURFACE SURFOBJ SurfObj; //XDCOBJ * pdcoAA; FLONG flags; - struct _PALETTE *ppal; + struct _PALETTE * const ppal; // Use SURFACE_vSetPalette to assign a palette //UINT unk_050; union @@ -123,3 +123,17 @@ SURFACE_AllocSurface( _In_ ULONG fjBitmap, _In_opt_ ULONG cjWidth, _In_opt_ PVOID pvBits); + +VOID +FORCEINLINE +SURFACE_vSetPalette( + _Inout_ PSURFACE psurf, + _In_ PPALETTE ppal) +{ + if (psurf->ppal) + GDIOBJ_vDereferenceObject((POBJ)psurf->ppal); + if (ppal) + GDIOBJ_vReferenceObjectByPointer((POBJ)ppal); + *(PVOID*)&psurf->ppal = ppal; +} + diff --git a/reactos/win32ss/gdi/ntgdi/bitmaps.c b/reactos/win32ss/gdi/ntgdi/bitmaps.c index 8c2065df14c..ddae4c5e683 100644 --- a/reactos/win32ss/gdi/ntgdi/bitmaps.c +++ b/reactos/win32ss/gdi/ntgdi/bitmaps.c @@ -223,6 +223,7 @@ IntCreateCompatibleBitmap( INT Height) { HBITMAP Bmp = NULL; + PPALETTE ppal; /* MS doc says if width or height is 0, return 1-by-1 pixel, monochrome bitmap */ if (0 == Width || 0 == Height) @@ -241,8 +242,13 @@ IntCreateCompatibleBitmap( NULL); psurf = SURFACE_ShareLockSurface(Bmp); ASSERT(psurf); - /* Set palette */ - psurf->ppal = PALETTE_ShareLockPalette(Dc->ppdev->devinfo.hpalDefault); + + /* Dereference old palette and set new palette */ + ppal = PALETTE_ShareLockPalette(Dc->ppdev->devinfo.hpalDefault); + ASSERT(ppal); + SURFACE_vSetPalette(psurf, ppal); + PALETTE_ShareUnlockPalette(ppal); + /* Set flags */ psurf->flags = API_BITMAP; psurf->hdc = NULL; // FIXME: @@ -266,9 +272,10 @@ IntCreateCompatibleBitmap( NULL); psurfBmp = SURFACE_ShareLockSurface(Bmp); ASSERT(psurfBmp); - /* Assign palette */ - psurfBmp->ppal = psurf->ppal; - GDIOBJ_vReferenceObjectByPointer((POBJ)psurf->ppal); + + /* Dereference old palette and set new palette */ + SURFACE_vSetPalette(psurfBmp, psurf->ppal); + /* Set flags */ psurfBmp->flags = API_BITMAP; psurfBmp->hdc = NULL; // FIXME: @@ -622,12 +629,9 @@ BITMAP_CopyBitmap(HBITMAP hBitmap) psurfSrc->SurfObj.pvBits, psurfNew->SurfObj.cjBits); - /* Dereference the new bitmaps palette, we will use a different */ - GDIOBJ_vDereferenceObject(&psurfNew->ppal->BaseObject); /* Reference the palette of the source bitmap and use it */ - GDIOBJ_vReferenceObjectByPointer(&psurfSrc->ppal->BaseObject); - psurfNew->ppal = psurfSrc->ppal; + SURFACE_vSetPalette(psurfNew, psurfSrc->ppal); /* Unlock the new surface */ SURFACE_ShareUnlockSurface(psurfNew); diff --git a/reactos/win32ss/gdi/ntgdi/dibobj.c b/reactos/win32ss/gdi/ntgdi/dibobj.c index c5a8d6f45c6..694463de204 100644 --- a/reactos/win32ss/gdi/ntgdi/dibobj.c +++ b/reactos/win32ss/gdi/ntgdi/dibobj.c @@ -1599,8 +1599,8 @@ DIB_CreateDIBSection( ppalDIB = CreateDIBPalette(bmi, dc, usage); if (ppalDIB) { - if (bmp->ppal) PALETTE_ShareUnlockPalette(bmp->ppal); - bmp->ppal = ppalDIB; + SURFACE_vSetPalette(bmp, ppalDIB); + PALETTE_ShareUnlockPalette(ppalDIB); } // Clean up in case of errors