mirror of
https://github.com/reactos/reactos.git
synced 2025-01-07 14:51:00 +00:00
[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
This commit is contained in:
parent
7bd9006bf1
commit
0ed94ccae0
4 changed files with 41 additions and 18 deletions
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue