Skip to contentSkip to conversation

xf86-video-modesetting generic colormap handling

PATCH New James Simmons 1 participant 1 message Mar 6, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xf86-video-modesetting generic colormap handling

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.

src/driver.c +63 -1
index 87431ff..a825f35 100644
@@ -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);
 
src/drmmode_display.c +0 -83

89 lines not on this page · raw message

src/drmmode_display.h +0 -1
index e83167b..3b6cfff 100644
@@ -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 {