mirror of
https://github.com/reactos/reactos.git
synced 2025-04-20 12:29:56 +00:00
[WIN32K]
- Alloca to use GDIOBJ_vReferenceObjectByPointer with exclusively locked objects - Make sure the global mono palette actually has 2 entries - Simplify allocation of default palette - Implement GreGetSetColorTable, replacing IntSetDIBColorTable / IntGetDIBColorTable - Make sure that memory possibly copied to user mode is zeroed. svn path=/trunk/; revision=56546
This commit is contained in:
parent
2e19d5b6f6
commit
505334785a
5 changed files with 99 additions and 40 deletions
|
@ -391,7 +391,7 @@ EngSetPointerShape(
|
||||||
/* Initialize an EXLATEOBJ */
|
/* Initialize an EXLATEOBJ */
|
||||||
ppal = PALETTE_ShareLockPalette(ppdev->devinfo.hpalDefault);
|
ppal = PALETTE_ShareLockPalette(ppdev->devinfo.hpalDefault);
|
||||||
EXLATEOBJ_vInitialize(&exlo,
|
EXLATEOBJ_vInitialize(&exlo,
|
||||||
&gpalMono,
|
gppalMono,
|
||||||
ppal,
|
ppal,
|
||||||
0,
|
0,
|
||||||
RGB(0xff,0xff,0xff),
|
RGB(0xff,0xff,0xff),
|
||||||
|
|
|
@ -591,8 +591,8 @@ EXLATEOBJ_vInitXlateFromDCs(
|
||||||
|
|
||||||
/* Normal initialisation. No surface means DEFAULT_BITMAP */
|
/* Normal initialisation. No surface means DEFAULT_BITMAP */
|
||||||
EXLATEOBJ_vInitialize(pexlo,
|
EXLATEOBJ_vInitialize(pexlo,
|
||||||
psurfSrc ? psurfSrc->ppal : &gpalMono,
|
psurfSrc ? psurfSrc->ppal : gppalMono,
|
||||||
psurfDst ? psurfDst->ppal : &gpalMono,
|
psurfDst ? psurfDst->ppal : gppalMono,
|
||||||
pdcSrc->pdcattr->crBackgroundClr,
|
pdcSrc->pdcattr->crBackgroundClr,
|
||||||
pdcDst->pdcattr->crBackgroundClr,
|
pdcDst->pdcattr->crBackgroundClr,
|
||||||
pdcDst->pdcattr->crForegroundClr);
|
pdcDst->pdcattr->crForegroundClr);
|
||||||
|
|
|
@ -576,9 +576,6 @@ GDIOBJ_vReferenceObjectByPointer(POBJ pobj)
|
||||||
{
|
{
|
||||||
ULONG cRefs;
|
ULONG cRefs;
|
||||||
|
|
||||||
/* Must not be exclusively locked */
|
|
||||||
ASSERT(pobj->cExclusiveLock == 0);
|
|
||||||
|
|
||||||
/* Check if the object has a handle */
|
/* Check if the object has a handle */
|
||||||
if (GDI_HANDLE_GET_INDEX(pobj->hHmgr))
|
if (GDI_HANDLE_GET_INDEX(pobj->hHmgr))
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
static UINT SystemPaletteUse = SYSPAL_NOSTATIC; /* The program need save the pallete and restore it */
|
static UINT SystemPaletteUse = SYSPAL_NOSTATIC; /* The program need save the pallete and restore it */
|
||||||
|
|
||||||
PALETTE gpalRGB, gpalBGR, gpalMono, gpalRGB555, gpalRGB565, *gppalDefault;
|
PALETTE gpalRGB, gpalBGR, gpalRGB555, gpalRGB565, *gppalMono, *gppalDefault;
|
||||||
PPALETTE appalSurfaceDefault[11];
|
PPALETTE appalSurfaceDefault[11];
|
||||||
|
|
||||||
const PALETTEENTRY g_sysPalTemplate[NB_RESERVED_COLORS] =
|
const PALETTEENTRY g_sysPalTemplate[NB_RESERVED_COLORS] =
|
||||||
|
@ -62,30 +62,13 @@ NTSTATUS
|
||||||
NTAPI
|
NTAPI
|
||||||
InitPaletteImpl()
|
InitPaletteImpl()
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
HPALETTE hpalette;
|
|
||||||
PLOGPALETTE palPtr;
|
|
||||||
|
|
||||||
// Create default palette (20 system colors)
|
// Create default palette (20 system colors)
|
||||||
palPtr = ExAllocatePoolWithTag(PagedPool,
|
gppalDefault = PALETTE_AllocPalWithHandle(PAL_INDEXED,
|
||||||
sizeof(LOGPALETTE) +
|
20,
|
||||||
(NB_RESERVED_COLORS * sizeof(PALETTEENTRY)),
|
(PULONG)g_sysPalTemplate,
|
||||||
TAG_PALETTE);
|
0, 0, 0);
|
||||||
if (!palPtr) return STATUS_NO_MEMORY;
|
GDIOBJ_vReferenceObjectByPointer(&gppalDefault->BaseObject);
|
||||||
|
PALETTE_UnlockPalette(gppalDefault);
|
||||||
palPtr->palVersion = 0x300;
|
|
||||||
palPtr->palNumEntries = NB_RESERVED_COLORS;
|
|
||||||
for (i=0; i<NB_RESERVED_COLORS; i++)
|
|
||||||
{
|
|
||||||
palPtr->palPalEntry[i].peRed = g_sysPalTemplate[i].peRed;
|
|
||||||
palPtr->palPalEntry[i].peGreen = g_sysPalTemplate[i].peGreen;
|
|
||||||
palPtr->palPalEntry[i].peBlue = g_sysPalTemplate[i].peBlue;
|
|
||||||
palPtr->palPalEntry[i].peFlags = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
hpalette = GreCreatePaletteInternal(palPtr,NB_RESERVED_COLORS);
|
|
||||||
ASSERT(hpalette);
|
|
||||||
ExFreePoolWithTag(palPtr, TAG_PALETTE);
|
|
||||||
|
|
||||||
/* palette_size = visual->map_entries; */
|
/* palette_size = visual->map_entries; */
|
||||||
|
|
||||||
|
@ -117,14 +100,12 @@ InitPaletteImpl()
|
||||||
gpalRGB565.BaseObject.ulShareCount = 1;
|
gpalRGB565.BaseObject.ulShareCount = 1;
|
||||||
gpalRGB565.BaseObject.BaseFlags = 0 ;
|
gpalRGB565.BaseObject.BaseFlags = 0 ;
|
||||||
|
|
||||||
memset(&gpalMono, 0, sizeof(PALETTE));
|
gppalMono = PALETTE_AllocPalette(PAL_MONOCHROME|PAL_INDEXED, 2, NULL, 0, 0, 0);
|
||||||
gpalMono.flFlags = PAL_MONOCHROME;
|
PALETTE_vSetRGBColorForIndex(gppalMono, 0, 0x000000);
|
||||||
gpalMono.BaseObject.ulShareCount = 1;
|
PALETTE_vSetRGBColorForIndex(gppalMono, 1, 0xffffff);
|
||||||
gpalMono.BaseObject.BaseFlags = 0 ;
|
|
||||||
|
|
||||||
/* Initialize default surface palettes */
|
/* Initialize default surface palettes */
|
||||||
gppalDefault = PALETTE_ShareLockPalette(hpalette);
|
appalSurfaceDefault[BMF_1BPP] = gppalMono;
|
||||||
appalSurfaceDefault[BMF_1BPP] = &gpalMono;
|
|
||||||
appalSurfaceDefault[BMF_4BPP] = gppalDefault;
|
appalSurfaceDefault[BMF_4BPP] = gppalDefault;
|
||||||
appalSurfaceDefault[BMF_8BPP] = gppalDefault;
|
appalSurfaceDefault[BMF_8BPP] = gppalDefault;
|
||||||
appalSurfaceDefault[BMF_16BPP] = &gpalRGB565;
|
appalSurfaceDefault[BMF_16BPP] = &gpalRGB565;
|
||||||
|
@ -160,7 +141,7 @@ PALETTE_AllocPalette(
|
||||||
ULONG fl = 0, cjSize = sizeof(PALETTE);
|
ULONG fl = 0, cjSize = sizeof(PALETTE);
|
||||||
|
|
||||||
/* Check if the palette has entries */
|
/* Check if the palette has entries */
|
||||||
if (iMode == PAL_INDEXED)
|
if (iMode & PAL_INDEXED)
|
||||||
{
|
{
|
||||||
/* Check color count */
|
/* Check color count */
|
||||||
if ((cColors == 0) || (cColors > 1024)) return NULL;
|
if ((cColors == 0) || (cColors > 1024)) return NULL;
|
||||||
|
@ -1010,6 +991,82 @@ IntSetPaletteEntries(
|
||||||
return Entries;
|
return Entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ULONG
|
||||||
|
APIENTRY
|
||||||
|
GreGetSetColorTable(
|
||||||
|
HDC hdc,
|
||||||
|
ULONG iStartIndex,
|
||||||
|
ULONG cEntries,
|
||||||
|
RGBQUAD *prgbColors,
|
||||||
|
BOOL bSet)
|
||||||
|
{
|
||||||
|
PDC pdc;
|
||||||
|
PSURFACE psurf;
|
||||||
|
PPALETTE ppal = NULL;
|
||||||
|
ULONG i, iEndIndex, iResult = 0;
|
||||||
|
|
||||||
|
/* Lock the DC */
|
||||||
|
pdc = DC_LockDc(hdc);
|
||||||
|
if (!pdc)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get the surace from the DC */
|
||||||
|
psurf = pdc->dclevel.pSurface;
|
||||||
|
|
||||||
|
/* Check if we have the default surface */
|
||||||
|
if ((psurf == NULL) && !bSet)
|
||||||
|
{
|
||||||
|
/* Use a mono palette */
|
||||||
|
ppal = gppalMono;
|
||||||
|
}
|
||||||
|
else if (psurf->SurfObj.iType == STYPE_BITMAP)
|
||||||
|
{
|
||||||
|
/* Get the palette of the surface */
|
||||||
|
ppal = psurf->ppal;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check if this is an indexed palette and the range is ok */
|
||||||
|
if (ppal && (ppal->flFlags & PAL_INDEXED) &&
|
||||||
|
(iStartIndex < ppal->NumColors))
|
||||||
|
{
|
||||||
|
/* Calculate the end of the operation */
|
||||||
|
iEndIndex = min(iStartIndex + cEntries, ppal->NumColors);
|
||||||
|
|
||||||
|
/* Check what operation to perform */
|
||||||
|
if (bSet)
|
||||||
|
{
|
||||||
|
/* Loop all colors and set the palette entries */
|
||||||
|
for (i = iStartIndex; i < iEndIndex; i++, prgbColors++)
|
||||||
|
{
|
||||||
|
ppal->IndexedColors[i].peRed = prgbColors->rgbRed;
|
||||||
|
ppal->IndexedColors[i].peGreen = prgbColors->rgbGreen;
|
||||||
|
ppal->IndexedColors[i].peBlue = prgbColors->rgbBlue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Loop all colors and get the palette entries */
|
||||||
|
for (i = iStartIndex; i < iEndIndex; i++, prgbColors++)
|
||||||
|
{
|
||||||
|
prgbColors->rgbRed = ppal->IndexedColors[i].peRed;
|
||||||
|
prgbColors->rgbGreen = ppal->IndexedColors[i].peGreen;
|
||||||
|
prgbColors->rgbBlue = ppal->IndexedColors[i].peBlue;
|
||||||
|
prgbColors->rgbReserved = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Calculate how many entries were modified */
|
||||||
|
iResult = iEndIndex - iStartIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Unlock the DC */
|
||||||
|
DC_UnlockDc(pdc);
|
||||||
|
|
||||||
|
return iResult;
|
||||||
|
}
|
||||||
|
|
||||||
W32KAPI
|
W32KAPI
|
||||||
LONG
|
LONG
|
||||||
APIENTRY
|
APIENTRY
|
||||||
|
@ -1051,6 +1108,11 @@ NtGdiDoPalette(
|
||||||
}
|
}
|
||||||
_SEH2_END
|
_SEH2_END
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Zero it out, so we don't accidentally leak kernel data */
|
||||||
|
RtlZeroMemory(pEntries, cEntries * sizeof(PALETTEENTRY));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
@ -1076,12 +1138,12 @@ NtGdiDoPalette(
|
||||||
|
|
||||||
case GdiPalSetColorTable:
|
case GdiPalSetColorTable:
|
||||||
if (pEntries)
|
if (pEntries)
|
||||||
ret = IntSetDIBColorTable((HDC)hObj, iStart, cEntries, (RGBQUAD*)pEntries);
|
ret = GreGetSetColorTable((HDC)hObj, iStart, cEntries, (RGBQUAD*)pEntries, TRUE);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GdiPalGetColorTable:
|
case GdiPalGetColorTable:
|
||||||
if (pEntries)
|
if (pEntries)
|
||||||
ret = IntGetDIBColorTable((HDC)hObj, iStart, cEntries, (RGBQUAD*)pEntries);
|
ret = GreGetSetColorTable((HDC)hObj, iStart, cEntries, (RGBQUAD*)pEntries, FALSE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ typedef struct _PALETTE
|
||||||
PALETTEENTRY apalColors[0];
|
PALETTEENTRY apalColors[0];
|
||||||
} PALETTE;
|
} PALETTE;
|
||||||
|
|
||||||
extern PALETTE gpalRGB, gpalBGR, gpalMono, gpalRGB555, gpalRGB565, *gppalDefault;
|
extern PALETTE gpalRGB, gpalBGR, gpalRGB555, gpalRGB565, *gppalMono, *gppalDefault;
|
||||||
extern PPALETTE appalSurfaceDefault[];
|
extern PPALETTE appalSurfaceDefault[];
|
||||||
|
|
||||||
#define PALETTE_UnlockPalette(pPalette) GDIOBJ_vUnlockObject((POBJ)pPalette)
|
#define PALETTE_UnlockPalette(pPalette) GDIOBJ_vUnlockObject((POBJ)pPalette)
|
||||||
|
|
Loading…
Reference in a new issue