Author: tkreuzer
Date: Sun Jul 1 13:43:33 2012
New Revision: 56816
URL:
http://svn.reactos.org/svn/reactos?rev=56816&view=rev
Log:
[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.
Modified:
trunk/reactos/win32ss/gdi/eng/surface.c
trunk/reactos/win32ss/gdi/eng/surface.h
trunk/reactos/win32ss/gdi/ntgdi/bitmaps.c
trunk/reactos/win32ss/gdi/ntgdi/dibobj.c
Modified: trunk/reactos/win32ss/gdi/eng/surface.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/gdi/eng/surface.c?…
==============================================================================
--- trunk/reactos/win32ss/gdi/eng/surface.c [iso-8859-1] (original)
+++ trunk/reactos/win32ss/gdi/eng/surface.c [iso-8859-1] Sun Jul 1 13:43:33 2012
@@ -267,8 +267,7 @@
}
/* 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 @@
SURFOBJ *pso;
PSURFACE psurf;
PDEVOBJ* ppdev;
+ PPALETTE ppal;
ppdev = (PDEVOBJ*)hdev;
@@ -418,8 +418,10 @@
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 @@
SURFOBJ *pso;
PSURFACE psurf;
PDEVOBJ* ppdev;
+ PPALETTE ppal;
psurf = SURFACE_ShareLockSurface(hsurf);
if (psurf == NULL)
@@ -462,8 +465,10 @@
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);
Modified: trunk/reactos/win32ss/gdi/eng/surface.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/gdi/eng/surface.h?…
==============================================================================
--- trunk/reactos/win32ss/gdi/eng/surface.h [iso-8859-1] (original)
+++ trunk/reactos/win32ss/gdi/eng/surface.h [iso-8859-1] Sun Jul 1 13:43:33 2012
@@ -10,7 +10,7 @@
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 @@
_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;
+}
+
Modified: trunk/reactos/win32ss/gdi/ntgdi/bitmaps.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/gdi/ntgdi/bitmaps.…
==============================================================================
--- trunk/reactos/win32ss/gdi/ntgdi/bitmaps.c [iso-8859-1] (original)
+++ trunk/reactos/win32ss/gdi/ntgdi/bitmaps.c [iso-8859-1] Sun Jul 1 13:43:33 2012
@@ -223,6 +223,7 @@
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 @@
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 @@
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 @@
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);
Modified: trunk/reactos/win32ss/gdi/ntgdi/dibobj.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/gdi/ntgdi/dibobj.c…
==============================================================================
--- trunk/reactos/win32ss/gdi/ntgdi/dibobj.c [iso-8859-1] (original)
+++ trunk/reactos/win32ss/gdi/ntgdi/dibobj.c [iso-8859-1] Sun Jul 1 13:43:33 2012
@@ -1599,8 +1599,8 @@
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