[PATCH xserver 1/8] xf86cmap: Factor out private lookup

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


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

diff --git a/hw/xfree86/common/xf86cmap.c b/hw/xfree86/common/xf86cmap.c
index 8588c9fba..e2e9f50a8 100644
--- a/hw/xfree86/common/xf86cmap.c
+++ b/hw/xfree86/common/xf86cmap.c
@@ -60,7 +60,7 @@
 #include "xf86cmap.h"
 
 #define SCREEN_PROLOGUE(pScreen, field) ((pScreen)->field = \
-    ((CMapScreenPtr)dixLookupPrivate(&(pScreen)->devPrivates, CMapScreenKey))->field)
+    getCMapScreenPtr(pScreen)->field)
 #define SCREEN_EPILOGUE(pScreen, field, wrapper)\
     ((pScreen)->field = wrapper)
 
@@ -109,6 +109,18 @@ static DevPrivateKeyRec CMapColormapKeyRec;
 
 #define CMapColormapKey (&CMapColormapKeyRec)
 
+static CMapScreenPtr
+getCMapScreenPtr(ScreenPtr pScreen)
+{
+    return dixLookupPrivate(&pScreen->devPrivates, CMapScreenKey);
+}
+
+static CMapColormapPtr
+getCMapColormapPtr(ColormapPtr pmap)
+{
+    return dixLookupPrivate(&pmap->devPrivates, CMapColormapKey);
+}
+
 static void CMapInstallColormap(ColormapPtr);
 static void CMapStoreColors(ColormapPtr, int, xColorItem *);
 static Bool CMapCloseScreen(ScreenPtr);
@@ -261,9 +273,7 @@ CMapColormapUseMax(VisualPtr pVisual, CMapScreenPtr pScreenPriv)
 static Bool
 CMapAllocateColormapPrivate(ColormapPtr pmap)
 {
-    CMapScreenPtr pScreenPriv =
-        (CMapScreenPtr) dixLookupPrivate(&pmap->pScreen->devPrivates,
-                                         CMapScreenKey);
+    CMapScreenPtr pScreenPriv = getCMapScreenPtr(pmap->pScreen);
     CMapColormapPtr pColPriv;
     CMapLinkPtr pLink;
     int numColors;
@@ -304,8 +314,7 @@ static Bool
 CMapCreateColormap(ColormapPtr pmap)
 {
     ScreenPtr pScreen = pmap->pScreen;
-    CMapScreenPtr pScreenPriv =
-        (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, CMapScreenKey);
+    CMapScreenPtr pScreenPriv = getCMapScreenPtr(pScreen);
     Bool ret = FALSE;
 
     pScreen->CreateColormap = pScreenPriv->CreateColormap;
@@ -322,10 +331,8 @@ static void
 CMapDestroyColormap(ColormapPtr cmap)
 {
     ScreenPtr pScreen = cmap->pScreen;
-    CMapScreenPtr pScreenPriv =
-        (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, CMapScreenKey);
-    CMapColormapPtr pColPriv =
-        (CMapColormapPtr) dixLookupPrivate(&cmap->devPrivates, CMapColormapKey);
+    CMapScreenPtr pScreenPriv = getCMapScreenPtr(pScreen);
+    CMapColormapPtr pColPriv = getCMapColormapPtr(cmap);
     CMapLinkPtr prevLink = NULL, pLink = pScreenPriv->maps;
 
     if (pColPriv) {
@@ -359,8 +366,7 @@ CMapStoreColors(ColormapPtr pmap, int ndef, xColorItem * pdefs)
 {
     ScreenPtr pScreen = pmap->pScreen;
     VisualPtr pVisual = pmap->pVisual;
-    CMapScreenPtr pScreenPriv =
-        (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, CMapScreenKey);
+    CMapScreenPtr pScreenPriv = getCMapScreenPtr(pScreen);
     int *indices = pScreenPriv->PreAllocIndices;
     int num = ndef;
 
@@ -375,9 +381,7 @@ CMapStoreColors(ColormapPtr pmap, int ndef, xColorItem * pdefs)
         return;
 
     if (pVisual->class == DirectColor) {
-        CMapColormapPtr pColPriv =
-            (CMapColormapPtr) dixLookupPrivate(&pmap->devPrivates,
-                                               CMapColormapKey);
+        CMapColormapPtr pColPriv = getCMapColormapPtr(pmap);
         int i;
 
         if (CMapColormapUseMax(pVisual, pScreenPriv)) {
@@ -437,8 +441,7 @@ static void
 CMapInstallColormap(ColormapPtr pmap)
 {
     ScreenPtr pScreen = pmap->pScreen;
-    CMapScreenPtr pScreenPriv =
-        (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, CMapScreenKey);
+    CMapScreenPtr pScreenPriv = getCMapScreenPtr(pScreen);
 
     if (pmap == GetInstalledmiColormap(pmap->pScreen))
         return;
@@ -468,8 +471,7 @@ CMapEnterVT(ScrnInfoPtr pScrn)
 {
     ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
     Bool ret;
-    CMapScreenPtr pScreenPriv =
-        (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, CMapScreenKey);
+    CMapScreenPtr pScreenPriv = getCMapScreenPtr(pScreen);
 
     pScrn->EnterVT = pScreenPriv->EnterVT;
     ret = (*pScreenPriv->EnterVT) (pScrn);
@@ -487,8 +489,7 @@ static Bool
 CMapSwitchMode(ScrnInfoPtr pScrn, DisplayModePtr mode)
 {
     ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
-    CMapScreenPtr pScreenPriv =
-        (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, CMapScreenKey);
+    CMapScreenPtr pScreenPriv = getCMapScreenPtr(pScreen);
 
     if ((*pScreenPriv->SwitchMode) (pScrn, mode)) {
         if (GetInstalledmiColormap(pScreen))
@@ -503,8 +504,7 @@ static int
 CMapSetDGAMode(ScrnInfoPtr pScrn, int num, DGADevicePtr dev)
 {
     ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
-    CMapScreenPtr pScreenPriv =
-        (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, CMapScreenKey);
+    CMapScreenPtr pScreenPriv = getCMapScreenPtr(pScreen);
     int ret;
 
     ret = (*pScreenPriv->SetDGAMode) (pScrn, num, dev);
@@ -524,11 +524,8 @@ CMapSetDGAMode(ScrnInfoPtr pScrn, int num, DGADevicePtr dev)
 static void
 CMapReinstallMap(ColormapPtr pmap)
 {
-    CMapScreenPtr pScreenPriv =
-        (CMapScreenPtr) dixLookupPrivate(&pmap->pScreen->devPrivates,
-                                         CMapScreenKey);
-    CMapColormapPtr cmapPriv =
-        (CMapColormapPtr) dixLookupPrivate(&pmap->devPrivates, CMapColormapKey);
+    CMapScreenPtr pScreenPriv = getCMapScreenPtr(pmap->pScreen);
+    CMapColormapPtr cmapPriv = getCMapColormapPtr(pmap);
     ScrnInfoPtr pScrn = xf86ScreenToScrn(pmap->pScreen);
     int i = cmapPriv->numColors;
     int *indices = pScreenPriv->PreAllocIndices;
@@ -555,11 +552,8 @@ CMapReinstallMap(ColormapPtr pmap)
 static void
 CMapRefreshColors(ColormapPtr pmap, int defs, int *indices)
 {
-    CMapScreenPtr pScreenPriv =
-        (CMapScreenPtr) dixLookupPrivate(&pmap->pScreen->devPrivates,
-                                         CMapScreenKey);
-    CMapColormapPtr pColPriv =
-        (CMapColormapPtr) dixLookupPrivate(&pmap->devPrivates, CMapColormapKey);
+    CMapScreenPtr pScreenPriv = getCMapScreenPtr(pmap->pScreen);
+    CMapColormapPtr pColPriv = getCMapColormapPtr(pmap);
     VisualPtr pVisual = pmap->pVisual;
     ScrnInfoPtr pScrn = xf86ScreenToScrn(pmap->pScreen);
     int numColors, i;
@@ -687,11 +681,8 @@ CMapCompareColors(LOCO * color1, LOCO * color2)
 static void
 CMapSetOverscan(ColormapPtr pmap, int defs, int *indices)
 {
-    CMapScreenPtr pScreenPriv =
-        (CMapScreenPtr) dixLookupPrivate(&pmap->pScreen->devPrivates,
-                                         CMapScreenKey);
-    CMapColormapPtr pColPriv =
-        (CMapColormapPtr) dixLookupPrivate(&pmap->devPrivates, CMapColormapKey);
+    CMapScreenPtr pScreenPriv = getCMapScreenPtr(pmap->pScreen);
+    CMapColormapPtr pColPriv = getCMapColormapPtr(pmap);
     ScrnInfoPtr pScrn = xf86ScreenToScrn(pmap->pScreen);
     VisualPtr pVisual = pmap->pVisual;
     int i;
@@ -831,8 +822,7 @@ CMapSetOverscan(ColormapPtr pmap, int defs, int *indices)
 static void
 CMapUnwrapScreen(ScreenPtr pScreen)
 {
-    CMapScreenPtr pScreenPriv =
-        (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, CMapScreenKey);
+    CMapScreenPtr pScreenPriv = getCMapScreenPtr(pScreen);
     ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
 
     pScreen->CloseScreen = pScreenPriv->CloseScreen;
@@ -917,9 +907,7 @@ CMapChangeGamma(ScrnInfoPtr pScrn, Gamma gamma)
     if (!CMapScreenKeyRegistered)
         return BadImplementation;
 
-    pScreenPriv = (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates,
-                                                   CMapScreenKey);
-    if (!pScreenPriv)
+    if (!(pScreenPriv = getCMapScreenPtr(pScreen)))
         return BadImplementation;
 
     if (gamma.red < GAMMA_MIN || gamma.red > GAMMA_MAX ||
@@ -936,8 +924,7 @@ CMapChangeGamma(ScrnInfoPtr pScrn, Gamma gamma)
     /* mark all colormaps on this screen */
     pLink = pScreenPriv->maps;
     while (pLink) {
-        pColPriv = (CMapColormapPtr) dixLookupPrivate(&pLink->cmap->devPrivates,
-                                                      CMapColormapKey);
+        pColPriv = getCMapColormapPtr(pLink->cmap);
         pColPriv->recalculate = TRUE;
         pLink = pLink->next;
     }
@@ -1012,9 +999,7 @@ xf86ChangeGammaRamp(ScreenPtr pScreen,
     if (!CMapScreenKeyRegistered)
         return BadImplementation;
 
-    pScreenPriv = (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates,
-                                                   CMapScreenKey);
-    if (!pScreenPriv)
+    if (!(pScreenPriv = getCMapScreenPtr(pScreen)))
         return BadImplementation;
 
     if (pScreenPriv->gammaElements != size)
@@ -1025,8 +1010,7 @@ xf86ChangeGammaRamp(ScreenPtr pScreen,
     /* mark all colormaps on this screen */
     pLink = pScreenPriv->maps;
     while (pLink) {
-        pColPriv = (CMapColormapPtr) dixLookupPrivate(&pLink->cmap->devPrivates,
-                                                      CMapColormapKey);
+        pColPriv = getCMapColormapPtr(pLink->cmap);
         pColPriv->recalculate = TRUE;
         pLink = pLink->next;
     }
@@ -1073,9 +1057,7 @@ xf86GetGammaRampSize(ScreenPtr pScreen)
     if (!CMapScreenKeyRegistered)
         return 0;
 
-    pScreenPriv = (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates,
-                                                   CMapScreenKey);
-    if (!pScreenPriv)
+    if (!(pScreenPriv = getCMapScreenPtr(pScreen)))
         return 0;
 
     return pScreenPriv->gammaElements;
@@ -1094,9 +1076,7 @@ xf86GetGammaRamp(ScreenPtr pScreen,
     if (!CMapScreenKeyRegistered)
         return BadImplementation;
 
-    pScreenPriv = (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates,
-                                                   CMapScreenKey);
-    if (!pScreenPriv)
+    if (!(pScreenPriv = getCMapScreenPtr(pScreen)))
         return BadImplementation;
 
     if (size > pScreenPriv->gammaElements)
-- 
2.14.3



More information about the xorg-devel mailing list