[PATCH] xf86-video-modesetting generic colormap handling

James Simmons jsimmons at infradead.org
Tue Mar 6 06:09:09 PST 2012


This patch replaces drmmode_load_palette with a very generic function
that removes the need of drmmode_crtc_private_rec to carry around 
color indexes. Also have the xorg driver actually call 
the xf86HandleColormaps function.

Signed-off-by: James Simmons <jsimmons at infradead.org>

diff --git a/src/driver.c b/src/driver.c
index 87431ff..a825f35 100644
--- a/src/driver.c
+++ b/src/driver.c
@@ -42,6 +42,7 @@
 #include "xf86Pci.h"
 #include "mipointer.h"
 #include "micmap.h"
+#include "xf86cmap.h"
 #include <X11/extensions/randr.h>
 #include "fb.h"
 #include "edid.h"
@@ -540,6 +541,62 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     return FALSE;
 }
 
+static void
+LoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
+                LOCO * colors, VisualPtr pVisual)
+{
+    xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+    CARD16 lut_r[256], lut_g[256], lut_b[256];
+    int i, j, k, index;
+
+    for (k = 0; k < xf86_config->num_crtc; k++) {
+        xf86CrtcPtr crtc = xf86_config->crtc[k];
+
+        switch (pScrn->depth) {
+        case 15:
+            for (i = 0; i < numColors; i++) {
+                index = indices[i];
+                for (j = 0; j < 8; j++) {
+                    lut_r[index * 8 + j] = colors[index].red << 8;
+                    lut_g[index * 8 + j] = colors[index].green << 8;
+                    lut_b[index * 8 + j] = colors[index].blue << 8;
+                }
+            }
+            break;
+        case 16:
+            for (i = 0; i < numColors; i++) {
+                index = indices[i];
+
+                if (index <= 31) {
+                    for (j = 0; j < 8; j++) {
+                        lut_r[index * 8 + j] = colors[index].red << 8;
+                        lut_b[index * 8 + j] = colors[index].blue << 8;
+                    }
+                }
+
+                for (j = 0; j < 4; j++)
+                    lut_g[index * 4 + j] = colors[index].green << 8;
+            }
+            break;
+        default:
+            for (i = 0; i < numColors; i++) {
+                index = indices[i];
+                lut_r[index] = colors[index].red << 8;
+                lut_g[index] = colors[index].green << 8;
+                lut_b[index] = colors[index].blue << 8;
+            }
+            break;
+        }
+
+        /* Make the change through RandR */
+#ifdef RANDR_12_INTERFACE
+        RRCrtcGammaSet(crtc->randr_crtc, lut_r, lut_g, lut_b);
+#else /*RANDR_12_INTERFACE*/
+        crtc->funcs->gamma_set(crtc, lut_r, lut_g, lut_b, 256);
+#endif
+    }
+}
+
 static void *
 msShadowWindow(ScreenPtr screen, CARD32 row, CARD32 offset, int mode,
 	       CARD32 *size, void *closure)
@@ -716,7 +773,12 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 	return FALSE;
 
     if (!miCreateDefColormap(pScreen))
-	return FALSE;
+        return FALSE;
+
+    if (!xf86HandleColormaps(pScreen, 256, 8, LoadPalette, NULL,
+                             CMAP_RELOAD_ON_MODE_SWITCH
+                             | CMAP_PALETTED_TRUECOLOR))
+        return FALSE;
 
     xf86DPMSInit(pScreen, xf86DPMSSet, 0);
 
diff --git a/src/drmmode_display.c b/src/drmmode_display.c
index 7fa933a..d1da19a 100644
--- a/src/drmmode_display.c
+++ b/src/drmmode_display.c
@@ -1134,89 +1132,6 @@ Bool drmmode_set_desired_modes(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
 	return TRUE;
 }
 
-static void drmmode_load_palette(ScrnInfoPtr pScrn, int numColors,
-                                 int *indices, LOCO *colors, VisualPtr pVisual)
-{
-    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
-    uint16_t       lut_r[256], lut_g[256], lut_b[256];
-    int index, j, i;
-    int c;
-
-    for (c = 0; c < xf86_config->num_crtc; c++) {
-        xf86CrtcPtr crtc = xf86_config->crtc[c];
-	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
-
-        for (i = 0 ; i < 256; i++) {
-            lut_r[i] = drmmode_crtc->lut_r[i] << 6;
-            lut_g[i] = drmmode_crtc->lut_g[i] << 6;
-            lut_b[i] = drmmode_crtc->lut_b[i] << 6;
-        }
-
-        switch(pScrn->depth) {
-        case 15:
-            for (i = 0; i < numColors; i++) {
-                index = indices[i];
-                for (j = 0; j < 8; j++) {
-                    lut_r[index * 8 + j] = colors[index].red << 6;
-                    lut_g[index * 8 + j] = colors[index].green << 6;
-                    lut_b[index * 8 + j] = colors[index].blue << 6;
-                }
-            }
-         break;
-         case 16:
-             for (i = 0; i < numColors; i++) {
-                 index = indices[i];
-
-                  if (i <= 31) {
-                      for (j = 0; j < 8; j++) {
-                          lut_r[index * 8 + j] = colors[index].red << 6;
-                          lut_b[index * 8 + j] = colors[index].blue << 6;
-                      }
-                  }
-
-                  for (j = 0; j < 4; j++) {
-                      lut_g[index * 4 + j] = colors[index].green << 6;
-                  }
-              }
-	  break;
-          default:
-              for (i = 0; i < numColors; i++) {
-                  index = indices[i];
-                  lut_r[index] = colors[index].red << 6;
-                  lut_g[index] = colors[index].green << 6;
-                  lut_b[index] = colors[index].blue << 6;
-              }
-              break;
-          }
-
-    /* Make the change through RandR */
-#ifdef RANDR_12_INTERFACE
-        if (crtc->randr_crtc)
-            RRCrtcGammaSet(crtc->randr_crtc, lut_r, lut_g, lut_b);
-        else
-#endif
-            crtc->funcs->gamma_set(crtc, lut_r, lut_g, lut_b, 256);
-     }
-}
-
-Bool drmmode_setup_colormap(ScreenPtr pScreen, ScrnInfoPtr pScrn)
-{
-    xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 0,
-                  "Initializing kms color map\n");
-    if (!miCreateDefColormap(pScreen))
-        return FALSE;
-    /* all radeons support 10 bit CLUTs */
-    if (!xf86HandleColormaps(pScreen, 256, 10,
-                             drmmode_load_palette, NULL,
-                             CMAP_PALETTED_TRUECOLOR
-#if 0 /* This option messes up text mode! (eich at suse.de) */
-                             | CMAP_LOAD_EVEN_IF_OFFSCREEN
-#endif
-                             | CMAP_RELOAD_ON_MODE_SWITCH))
-         return FALSE;
-    return TRUE;
-}
-
 #ifdef HAVE_UDEV
 static void
 drmmode_handle_uevents(int fd, void *closure)
diff --git a/src/drmmode_display.h b/src/drmmode_display.h
index e83167b..3b6cfff 100644
--- a/src/drmmode_display.h
+++ b/src/drmmode_display.h
@@ -66,7 +66,6 @@ typedef struct {
     int hw_id;
     struct dumb_bo *cursor_bo;
     unsigned rotate_fb_id;
-    uint16_t lut_r[256], lut_g[256], lut_b[256];
 } drmmode_crtc_private_rec, *drmmode_crtc_private_ptr;
 
 typedef struct {


More information about the dri-devel mailing list