[PATCH xserver] render: Store and use all 16bpc of precision for solid pixels (v2)

Adam Jackson ajax at redhat.com
Mon Feb 26 15:33:50 UTC 2018


This plumbs the full width color for solid pictures through to fb, exa,
and glamor. External drivers and acceleration code may wish to make a
similar change for sufficiently new servers.

v2: Don't break ABI (Michel Dänzer)

Signed-off-by: Adam Jackson <ajax at redhat.com>
Reviewed-by: Keith Packard <keithp at keithp.com>
---
 exa/exa_render.c        |  4 +++-
 fb/fbpict.c             | 16 +++-------------
 glamor/glamor_program.c |  7 ++++---
 glamor/glamor_render.c  | 20 ++++++++------------
 glamor/glamor_utils.h   |  9 +++++++++
 render/picture.c        |  1 +
 render/picturestr.h     |  1 +
 7 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/exa/exa_render.c b/exa/exa_render.c
index b24bec0524..50a9a659ed 100644
--- a/exa/exa_render.c
+++ b/exa/exa_render.c
@@ -291,7 +291,9 @@ exaTryDriverSolidFill(PicturePtr pSrc,
         pixel = exaGetPixmapFirstPixel(pSrcPix);
     }
     else
-        pixel = pSrc->pSourcePict->solidFill.color;
+        miRenderColorToPixel(pSrc->pFormat,
+                             &pSrc->pSourcePict->solidFill.fullcolor,
+                             &pixel);
 
     if (!exaGetRGBAFromPixel(pixel, &red, &green, &blue, &alpha,
                              pSrc->pFormat, pSrc->format) ||
diff --git a/fb/fbpict.c b/fb/fbpict.c
index 7ea0b668f8..759f0d5db7 100644
--- a/fb/fbpict.c
+++ b/fb/fbpict.c
@@ -220,20 +220,10 @@ static pixman_image_t *
 create_solid_fill_image(PicturePtr pict)
 {
     PictSolidFill *solid = &pict->pSourcePict->solidFill;
-    pixman_color_t color;
-    CARD32 a, r, g, b;
+    /* pixman_color_t and xRenderColor have the same layout */
+    pixman_color_t *color = (pixman_color_t *)&solid->color;
 
-    a = (solid->color & 0xff000000) >> 24;
-    r = (solid->color & 0x00ff0000) >> 16;
-    g = (solid->color & 0x0000ff00) >> 8;
-    b = (solid->color & 0x000000ff) >> 0;
-
-    color.alpha = (a << 8) | a;
-    color.red = (r << 8) | r;
-    color.green = (g << 8) | g;
-    color.blue = (b << 8) | b;
-
-    return pixman_image_create_solid_fill(&color);
+    return pixman_image_create_solid_fill(color);
 }
 
 static pixman_image_t *
diff --git a/glamor/glamor_program.c b/glamor/glamor_program.c
index 23c102bc30..830deb38b3 100644
--- a/glamor/glamor_program.c
+++ b/glamor/glamor_program.c
@@ -508,12 +508,13 @@ glamor_set_blend(CARD8 op, glamor_program_alpha alpha, PicturePtr dst)
 static Bool
 use_source_solid(CARD8 op, PicturePtr src, PicturePtr dst, glamor_program *prog)
 {
+    PictSolidFill *solid = &src->pSourcePict->solidFill;
+    float color[4];
 
+    glamor_get_rgba_from_color(&solid->fullcolor, color);
     glamor_set_blend(op, prog->alpha, dst);
+    glUniform4fv(prog->fg_uniform, 1, color);
 
-    glamor_set_color_depth(dst->pDrawable->pScreen, 32,
-                           src->pSourcePict->solidFill.color,
-                           prog->fg_uniform);
     return TRUE;
 }
 
diff --git a/glamor/glamor_render.c b/glamor/glamor_render.c
index 7a96c82dd0..d8d1a335b8 100644
--- a/glamor/glamor_render.c
+++ b/glamor/glamor_render.c
@@ -828,13 +828,11 @@ glamor_composite_choose_shader(CARD8 op,
         source_solid_color[3] = 0.0;
     }
     else if (!source->pDrawable) {
-        if (source->pSourcePict->type == SourcePictTypeSolidFill) {
+        SourcePictPtr sp = source->pSourcePict;
+        if (sp->type == SourcePictTypeSolidFill) {
             key.source = SHADER_SOURCE_SOLID;
-            glamor_get_rgba_from_pixel(source->pSourcePict->solidFill.color,
-                                       &source_solid_color[0],
-                                       &source_solid_color[1],
-                                       &source_solid_color[2],
-                                       &source_solid_color[3], PICT_a8r8g8b8);
+            glamor_get_rgba_from_color(&sp->solidFill.fullcolor,
+                                       source_solid_color);
         }
         else
             goto fail;
@@ -848,13 +846,11 @@ glamor_composite_choose_shader(CARD8 op,
 
     if (mask) {
         if (!mask->pDrawable) {
-            if (mask->pSourcePict->type == SourcePictTypeSolidFill) {
+            SourcePictPtr sp = mask->pSourcePict;
+            if (sp->type == SourcePictTypeSolidFill) {
                 key.mask = SHADER_MASK_SOLID;
-                glamor_get_rgba_from_pixel
-                    (mask->pSourcePict->solidFill.color,
-                     &mask_solid_color[0],
-                     &mask_solid_color[1],
-                     &mask_solid_color[2], &mask_solid_color[3], PICT_a8r8g8b8);
+                glamor_get_rgba_from_color(&sp->solidFill.fullcolor,
+                                           mask_solid_color);
             }
             else
                 goto fail;
diff --git a/glamor/glamor_utils.h b/glamor/glamor_utils.h
index 7597b92dcb..d4f995ab9e 100644
--- a/glamor/glamor_utils.h
+++ b/glamor/glamor_utils.h
@@ -710,6 +710,15 @@ glamor_get_rgba_from_pixel(CARD32 pixel,
     return TRUE;
 }
 
+static inline void
+glamor_get_rgba_from_color(const xRenderColor *color, float rgba[4])
+{
+    rgba[0] = color->red   / (float)UINT16_MAX;
+    rgba[1] = color->green / (float)UINT16_MAX;
+    rgba[2] = color->blue  / (float)UINT16_MAX;
+    rgba[3] = color->alpha / (float)UINT16_MAX;
+}
+
 inline static Bool
 glamor_is_large_pixmap(PixmapPtr pixmap)
 {
diff --git a/render/picture.c b/render/picture.c
index f0638a39f1..a53f3b560f 100644
--- a/render/picture.c
+++ b/render/picture.c
@@ -875,6 +875,7 @@ CreateSolidPicture(Picture pid, xRenderColor * color, int *error)
     }
     pPicture->pSourcePict->type = SourcePictTypeSolidFill;
     pPicture->pSourcePict->solidFill.color = xRenderColorToCard32(*color);
+    memcpy(&pPicture->pSourcePict->solidFill.fullcolor, color, sizeof(*color));
     return pPicture;
 }
 
diff --git a/render/picturestr.h b/render/picturestr.h
index 33baef9bf1..dd25a272d1 100644
--- a/render/picturestr.h
+++ b/render/picturestr.h
@@ -68,6 +68,7 @@ typedef struct pixman_transform PictTransform, *PictTransformPtr;
 typedef struct _PictSolidFill {
     unsigned int type;
     CARD32 color;
+    xRenderColor fullcolor;
 } PictSolidFill, *PictSolidFillPtr;
 
 typedef struct _PictGradientStop {
-- 
2.14.3



More information about the xorg-devel mailing list