[ros-diffs] [tkreuzer] 56546: [WIN32K] - Alloca to use GDIOBJ_vReferenceObjectByPointer with exclusively locked objects - Make sure the global mono palette actually has 2 entries - Simplify allocation of defau...

tkreuzer at svn.reactos.org tkreuzer at svn.reactos.org
Tue May 8 23:21:10 UTC 2012


Author: tkreuzer
Date: Tue May  8 23:21:09 2012
New Revision: 56546

URL: http://svn.reactos.org/svn/reactos?rev=56546&view=rev
Log:
[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.

Modified:
    trunk/reactos/win32ss/gdi/eng/mouse.c
    trunk/reactos/win32ss/gdi/eng/xlate.c
    trunk/reactos/win32ss/gdi/ntgdi/gdiobj.c
    trunk/reactos/win32ss/gdi/ntgdi/palette.c
    trunk/reactos/win32ss/gdi/ntgdi/palette.h

Modified: trunk/reactos/win32ss/gdi/eng/mouse.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/gdi/eng/mouse.c?rev=56546&r1=56545&r2=56546&view=diff
==============================================================================
--- trunk/reactos/win32ss/gdi/eng/mouse.c [iso-8859-1] (original)
+++ trunk/reactos/win32ss/gdi/eng/mouse.c [iso-8859-1] Tue May  8 23:21:09 2012
@@ -391,7 +391,7 @@
         /* Initialize an EXLATEOBJ */
         ppal = PALETTE_ShareLockPalette(ppdev->devinfo.hpalDefault);
         EXLATEOBJ_vInitialize(&exlo,
-                              &gpalMono,
+                              gppalMono,
                               ppal,
                               0,
                               RGB(0xff,0xff,0xff),

Modified: trunk/reactos/win32ss/gdi/eng/xlate.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/gdi/eng/xlate.c?rev=56546&r1=56545&r2=56546&view=diff
==============================================================================
--- trunk/reactos/win32ss/gdi/eng/xlate.c [iso-8859-1] (original)
+++ trunk/reactos/win32ss/gdi/eng/xlate.c [iso-8859-1] Tue May  8 23:21:09 2012
@@ -591,8 +591,8 @@
 
     /* Normal initialisation. No surface means DEFAULT_BITMAP */
     EXLATEOBJ_vInitialize(pexlo,
-                          psurfSrc ? psurfSrc->ppal : &gpalMono,
-                          psurfDst ? psurfDst->ppal : &gpalMono,
+                          psurfSrc ? psurfSrc->ppal : gppalMono,
+                          psurfDst ? psurfDst->ppal : gppalMono,
                           pdcSrc->pdcattr->crBackgroundClr,
                           pdcDst->pdcattr->crBackgroundClr,
                           pdcDst->pdcattr->crForegroundClr);

Modified: trunk/reactos/win32ss/gdi/ntgdi/gdiobj.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/gdi/ntgdi/gdiobj.c?rev=56546&r1=56545&r2=56546&view=diff
==============================================================================
--- trunk/reactos/win32ss/gdi/ntgdi/gdiobj.c [iso-8859-1] (original)
+++ trunk/reactos/win32ss/gdi/ntgdi/gdiobj.c [iso-8859-1] Tue May  8 23:21:09 2012
@@ -576,9 +576,6 @@
 {
     ULONG cRefs;
 
-    /* Must not be exclusively locked */
-    ASSERT(pobj->cExclusiveLock == 0);
-
     /* Check if the object has a handle */
     if (GDI_HANDLE_GET_INDEX(pobj->hHmgr))
     {

Modified: trunk/reactos/win32ss/gdi/ntgdi/palette.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/gdi/ntgdi/palette.c?rev=56546&r1=56545&r2=56546&view=diff
==============================================================================
--- trunk/reactos/win32ss/gdi/ntgdi/palette.c [iso-8859-1] (original)
+++ trunk/reactos/win32ss/gdi/ntgdi/palette.c [iso-8859-1] Tue May  8 23:21:09 2012
@@ -14,7 +14,7 @@
 
 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];
 
 const PALETTEENTRY g_sysPalTemplate[NB_RESERVED_COLORS] =
@@ -62,30 +62,13 @@
 NTAPI
 InitPaletteImpl()
 {
-    int i;
-    HPALETTE hpalette;
-    PLOGPALETTE palPtr;
-
     // Create default palette (20 system colors)
-    palPtr = ExAllocatePoolWithTag(PagedPool,
-                                   sizeof(LOGPALETTE) +
-                                       (NB_RESERVED_COLORS * sizeof(PALETTEENTRY)),
-                                   TAG_PALETTE);
-    if (!palPtr) return STATUS_NO_MEMORY;
-
-    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);
+    gppalDefault = PALETTE_AllocPalWithHandle(PAL_INDEXED,
+                                              20,
+                                              (PULONG)g_sysPalTemplate,
+                                              0, 0, 0);
+    GDIOBJ_vReferenceObjectByPointer(&gppalDefault->BaseObject);
+    PALETTE_UnlockPalette(gppalDefault);
 
     /*  palette_size = visual->map_entries; */
 
@@ -117,14 +100,12 @@
     gpalRGB565.BaseObject.ulShareCount = 1;
     gpalRGB565.BaseObject.BaseFlags = 0 ;
 
-    memset(&gpalMono, 0, sizeof(PALETTE));
-    gpalMono.flFlags = PAL_MONOCHROME;
-    gpalMono.BaseObject.ulShareCount = 1;
-    gpalMono.BaseObject.BaseFlags = 0 ;
+    gppalMono = PALETTE_AllocPalette(PAL_MONOCHROME|PAL_INDEXED, 2, NULL, 0, 0, 0);
+    PALETTE_vSetRGBColorForIndex(gppalMono, 0, 0x000000);
+    PALETTE_vSetRGBColorForIndex(gppalMono, 1, 0xffffff);
 
     /* Initialize default surface palettes */
-    gppalDefault = PALETTE_ShareLockPalette(hpalette);
-    appalSurfaceDefault[BMF_1BPP] = &gpalMono;
+    appalSurfaceDefault[BMF_1BPP] = gppalMono;
     appalSurfaceDefault[BMF_4BPP] = gppalDefault;
     appalSurfaceDefault[BMF_8BPP] = gppalDefault;
     appalSurfaceDefault[BMF_16BPP] = &gpalRGB565;
@@ -160,7 +141,7 @@
     ULONG fl = 0, cjSize = sizeof(PALETTE);
 
     /* Check if the palette has entries */
-    if (iMode == PAL_INDEXED)
+    if (iMode & PAL_INDEXED)
     {
         /* Check color count */
         if ((cColors == 0) || (cColors > 1024)) return NULL;
@@ -1010,6 +991,82 @@
     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
 LONG
 APIENTRY
@@ -1051,6 +1108,11 @@
 			}
 			_SEH2_END
 		}
+		else
+		{
+		    /* Zero it out, so we don't accidentally leak kernel data */
+		    RtlZeroMemory(pEntries, cEntries * sizeof(PALETTEENTRY));
+		}
 	}
 
 	ret = 0;
@@ -1076,12 +1138,12 @@
 
 		case GdiPalSetColorTable:
 			if (pEntries)
-				ret = IntSetDIBColorTable((HDC)hObj, iStart, cEntries, (RGBQUAD*)pEntries);
+				ret = GreGetSetColorTable((HDC)hObj, iStart, cEntries, (RGBQUAD*)pEntries, TRUE);
 			break;
 
 		case GdiPalGetColorTable:
 			if (pEntries)
-				ret = IntGetDIBColorTable((HDC)hObj, iStart, cEntries, (RGBQUAD*)pEntries);
+				ret = GreGetSetColorTable((HDC)hObj, iStart, cEntries, (RGBQUAD*)pEntries, FALSE);
 			break;
 	}
 

Modified: trunk/reactos/win32ss/gdi/ntgdi/palette.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/gdi/ntgdi/palette.h?rev=56546&r1=56545&r2=56546&view=diff
==============================================================================
--- trunk/reactos/win32ss/gdi/ntgdi/palette.h [iso-8859-1] (original)
+++ trunk/reactos/win32ss/gdi/ntgdi/palette.h [iso-8859-1] Tue May  8 23:21:09 2012
@@ -43,7 +43,7 @@
     PALETTEENTRY apalColors[0];
 } PALETTE;
 
-extern PALETTE gpalRGB, gpalBGR, gpalMono, gpalRGB555, gpalRGB565, *gppalDefault;
+extern PALETTE gpalRGB, gpalBGR, gpalRGB555, gpalRGB565, *gppalMono, *gppalDefault;
 extern PPALETTE appalSurfaceDefault[];
 
 #define  PALETTE_UnlockPalette(pPalette) GDIOBJ_vUnlockObject((POBJ)pPalette)




More information about the Ros-diffs mailing list