[Mesa-dev] [PATCH 3/6] gallium/hud: use sRGB for nicer AA lines

Marek Olšák maraeo at gmail.com
Thu Aug 18 19:56:30 UTC 2016


From: Marek Olšák <marek.olsak at amd.com>

---
 src/gallium/auxiliary/hud/hud_context.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/src/gallium/auxiliary/hud/hud_context.c b/src/gallium/auxiliary/hud/hud_context.c
index fb9c8c6..8ab998e 100644
--- a/src/gallium/auxiliary/hud/hud_context.c
+++ b/src/gallium/auxiliary/hud/hud_context.c
@@ -35,20 +35,21 @@
 
 #include <signal.h>
 #include <stdio.h>
 
 #include "hud/hud_context.h"
 #include "hud/hud_private.h"
 #include "hud/font.h"
 
 #include "cso_cache/cso_context.h"
 #include "util/u_draw_quad.h"
+#include "util/u_format.h"
 #include "util/u_inlines.h"
 #include "util/u_memory.h"
 #include "util/u_math.h"
 #include "util/u_sampler.h"
 #include "util/u_simple_shaders.h"
 #include "util/u_string.h"
 #include "util/u_upload_mgr.h"
 #include "tgsi/tgsi_text.h"
 #include "tgsi/tgsi_dump.h"
 
@@ -90,20 +91,22 @@ struct hud_context {
    unsigned fb_width, fb_height;
 
    /* vertices for text and background drawing are accumulated here and then
     * drawn all at once */
    struct vertex_queue {
       float *vertices;
       struct pipe_vertex_buffer vbuf;
       unsigned max_num_vertices;
       unsigned num_vertices;
    } text, bg, whitelines;
+
+   bool has_srgb;
 };
 
 #ifdef PIPE_OS_UNIX
 static void
 signal_visible_handler(int sig, siginfo_t *siginfo, void *context)
 {
    huds_visible = !huds_visible;
 }
 #endif
 
@@ -477,20 +480,32 @@ hud_draw(struct hud_context *hud, struct pipe_resource *tex)
                         CSO_BIT_VERTEX_SHADER |
                         CSO_BIT_VERTEX_ELEMENTS |
                         CSO_BIT_AUX_VERTEX_BUFFER_SLOT |
                         CSO_BIT_PAUSE_QUERIES |
                         CSO_BIT_RENDER_CONDITION));
    cso_save_constant_buffer_slot0(cso, PIPE_SHADER_VERTEX);
 
    /* set states */
    memset(&surf_templ, 0, sizeof(surf_templ));
    surf_templ.format = tex->format;
+
+   /* Without this, AA lines look thinner if they are between 2 pixels
+    * because the alpha is 0.5 on both pixels. (it's ugly)
+    *
+    * sRGB makes the width of all AA lines look the same.
+    */
+   if (hud->has_srgb) {
+      enum pipe_format srgb_format = util_format_srgb(tex->format);
+
+      if (srgb_format != PIPE_FORMAT_NONE)
+         surf_templ.format = srgb_format;
+   }
    surf = pipe->create_surface(pipe, tex, &surf_templ);
 
    memset(&fb, 0, sizeof(fb));
    fb.nr_cbufs = 1;
    fb.cbufs[0] = surf;
    fb.zsbuf = NULL;
    fb.width = hud->fb_width;
    fb.height = hud->fb_height;
 
    viewport.scale[0] = 0.5f * hud->fb_width;
@@ -1131,20 +1146,21 @@ print_help(struct pipe_screen *screen)
       }
    }
 
    puts("");
    fflush(stdout);
 }
 
 struct hud_context *
 hud_create(struct pipe_context *pipe, struct cso_context *cso)
 {
+   struct pipe_screen *screen = pipe->screen;
    struct hud_context *hud;
    struct pipe_sampler_view view_templ;
    unsigned i;
    const char *env = debug_get_option("GALLIUM_HUD", NULL);
    unsigned signo = debug_get_num_option("GALLIUM_HUD_TOGGLE_SIGNAL", 0);
 #ifdef PIPE_OS_UNIX
    static boolean sig_handled = FALSE;
    struct sigaction action = {};
 #endif
    huds_visible = debug_get_bool_option("GALLIUM_HUD_VISIBLE", TRUE);
@@ -1166,20 +1182,25 @@ hud_create(struct pipe_context *pipe, struct cso_context *cso)
    hud->uploader = u_upload_create(pipe, 256 * 1024,
                                    PIPE_BIND_VERTEX_BUFFER, PIPE_USAGE_STREAM);
 
    /* font */
    if (!util_font_create(pipe, UTIL_FONT_FIXED_8X13, &hud->font)) {
       u_upload_destroy(hud->uploader);
       FREE(hud);
       return NULL;
    }
 
+   hud->has_srgb = screen->is_format_supported(screen,
+                                               PIPE_FORMAT_B8G8R8A8_SRGB,
+                                               PIPE_TEXTURE_2D, 0,
+                                               PIPE_BIND_RENDER_TARGET) != 0;
+
    /* blend state */
    hud->no_blend.rt[0].colormask = PIPE_MASK_RGBA;
 
    hud->alpha_blend.rt[0].colormask = PIPE_MASK_RGBA;
    hud->alpha_blend.rt[0].blend_enable = 1;
    hud->alpha_blend.rt[0].rgb_func = PIPE_BLEND_ADD;
    hud->alpha_blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_SRC_ALPHA;
    hud->alpha_blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_INV_SRC_ALPHA;
    hud->alpha_blend.rt[0].alpha_func = PIPE_BLEND_ADD;
    hud->alpha_blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ZERO;
-- 
2.7.4



More information about the mesa-dev mailing list