[PATCH xserver 2/8] xf86cmap: Remove numColors from the colormap private

Adam Jackson ajax at redhat.com
Wed Jan 31 15:53:58 UTC 2018


We can compute this as needed instead.

Signed-off-by: Adam Jackson <ajax at redhat.com>
---
 hw/xfree86/common/xf86cmap.c | 43 ++++++++++++++++++++++---------------------
 1 file changed, 22 insertions(+), 21 deletions(-)

diff --git a/hw/xfree86/common/xf86cmap.c b/hw/xfree86/common/xf86cmap.c
index e2e9f50a8..7c9e063ba 100644
--- a/hw/xfree86/common/xf86cmap.c
+++ b/hw/xfree86/common/xf86cmap.c
@@ -95,7 +95,6 @@ typedef struct {
 } CMapScreenRec, *CMapScreenPtr;
 
 typedef struct {
-    int numColors;
     LOCO *colors;
     Bool recalculate;
     int overscan;
@@ -270,21 +269,24 @@ CMapColormapUseMax(VisualPtr pVisual, CMapScreenPtr pScreenPriv)
     return ((1 << pVisual->nplanes) > pScreenPriv->maxColors);
 }
 
-static Bool
-CMapAllocateColormapPrivate(ColormapPtr pmap)
+static int
+CMapNumColors(ColormapPtr pmap, CMapScreenPtr pScreenPriv)
 {
-    CMapScreenPtr pScreenPriv = getCMapScreenPtr(pmap->pScreen);
-    CMapColormapPtr pColPriv;
-    CMapLinkPtr pLink;
-    int numColors;
-    LOCO *colors;
-
     if (CMapColormapUseMax(pmap->pVisual, pScreenPriv))
-        numColors = pmap->pVisual->ColormapEntries;
+        return pmap->pVisual->ColormapEntries;
     else
-        numColors = 1 << pmap->pVisual->nplanes;
+        return 1 << pmap->pVisual->nplanes;
+}
 
-    if (!(colors = xallocarray(numColors, sizeof(LOCO))))
+static Bool
+CMapAllocateColormapPrivate(ColormapPtr pmap)
+{
+    CMapScreenPtr pScreenPriv = getCMapScreenPtr(pmap->pScreen);
+    CMapColormapPtr pColPriv;
+    CMapLinkPtr pLink;
+    LOCO *colors;
+
+    if (!(colors = xallocarray(CMapNumColors(pmap, pScreenPriv), sizeof(LOCO))))
         return FALSE;
 
     if (!(pColPriv = malloc(sizeof(CMapColormapRec)))) {
@@ -294,7 +296,6 @@ CMapAllocateColormapPrivate(ColormapPtr pmap)
 
     dixSetPrivate(&pmap->devPrivates, CMapColormapKey, pColPriv);
 
-    pColPriv->numColors = numColors;
     pColPriv->colors = colors;
     pColPriv->recalculate = TRUE;
     pColPriv->overscan = -1;
@@ -381,7 +382,6 @@ CMapStoreColors(ColormapPtr pmap, int ndef, xColorItem * pdefs)
         return;
 
     if (pVisual->class == DirectColor) {
-        CMapColormapPtr pColPriv = getCMapColormapPtr(pmap);
         int i;
 
         if (CMapColormapUseMax(pVisual, pScreenPriv)) {
@@ -424,8 +424,8 @@ CMapStoreColors(ColormapPtr pmap, int ndef, xColorItem * pdefs)
         }
         else {
             /* not really as overkill as it seems */
-            num = pColPriv->numColors;
-            for (i = 0; i < pColPriv->numColors; i++)
+            num = CMapNumColors(pmap, pScreenPriv);
+            for (i = 0; i < num; i++)
                 indices[i] = i;
         }
     }
@@ -527,17 +527,18 @@ CMapReinstallMap(ColormapPtr pmap)
     CMapScreenPtr pScreenPriv = getCMapScreenPtr(pmap->pScreen);
     CMapColormapPtr cmapPriv = getCMapColormapPtr(pmap);
     ScrnInfoPtr pScrn = xf86ScreenToScrn(pmap->pScreen);
-    int i = cmapPriv->numColors;
+    int i, n;
     int *indices = pScreenPriv->PreAllocIndices;
 
+    i = n = CMapNumColors(pmap, pScreenPriv);
+
     while (i--)
         indices[i] = i;
 
     if (cmapPriv->recalculate)
-        CMapRefreshColors(pmap, cmapPriv->numColors, indices);
+        CMapRefreshColors(pmap, n, indices);
     else {
-        (*pScrn->LoadPalette) (pScrn, cmapPriv->numColors,
-                               indices, cmapPriv->colors, pmap->pVisual);
+        pScrn->LoadPalette(pScrn, n, indices, cmapPriv->colors, pmap->pVisual);
         if (pScrn->SetOverscan) {
 #ifdef DEBUGOVERSCAN
             ErrorF("SetOverscan() called from CMapReinstallMap\n");
@@ -561,7 +562,7 @@ CMapRefreshColors(ColormapPtr pmap, int defs, int *indices)
     EntryPtr entry;
     int reds, greens, blues, maxValue, index, shift;
 
-    numColors = pColPriv->numColors;
+    numColors = CMapNumColors(pmap, pScreenPriv);
     shift = 16 - pScreenPriv->sigRGBbits;
     maxValue = (1 << pScreenPriv->sigRGBbits) - 1;
     gamma = pScreenPriv->gamma;
-- 
2.14.3



More information about the xorg-devel mailing list