[Mesa-dev] [PATCH 3/5] gallium/hud: add an option to reset the color counter

Marek Olšák maraeo at gmail.com
Sun Jan 1 00:06:01 UTC 2017


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

---
 src/gallium/auxiliary/hud/hud_context.c | 21 ++++++++++++++++++---
 src/gallium/auxiliary/hud/hud_private.h |  1 +
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/src/gallium/auxiliary/hud/hud_context.c b/src/gallium/auxiliary/hud/hud_context.c
index 9e17d9b..eefbe60 100644
--- a/src/gallium/auxiliary/hud/hud_context.c
+++ b/src/gallium/auxiliary/hud/hud_context.c
@@ -817,31 +817,32 @@ hud_pane_add_graph(struct hud_pane *pane, struct hud_graph *gr)
       {1, 0.5, 0.5},
       {0.5, 1, 1},
       {1, 0.5, 1},
       {1, 1, 0.5},
       {0, 0.5, 0},
       {0.5, 0, 0},
       {0, 0.5, 0.5},
       {0.5, 0, 0.5},
       {0.5, 0.5, 0},
    };
-   unsigned color = pane->num_graphs % ARRAY_SIZE(colors);
+   unsigned color = pane->next_color % ARRAY_SIZE(colors);
 
    strip_hyphens(gr->name);
 
    gr->vertices = MALLOC(pane->max_num_vertices * sizeof(float) * 2);
    gr->color[0] = colors[color][0];
    gr->color[1] = colors[color][1];
    gr->color[2] = colors[color][2];
    gr->pane = pane;
    LIST_ADDTAIL(&gr->head, &pane->graph_list);
    pane->num_graphs++;
+   pane->next_color++;
 }
 
 void
 hud_graph_add_value(struct hud_graph *gr, uint64_t value)
 {
    gr->current_value = value;
    value = value > gr->pane->ceiling ? gr->pane->ceiling : value;
 
    if (gr->fd)
       fprintf(gr->fd, "%" PRIu64 "\n", value);
@@ -916,21 +917,22 @@ parse_string(const char *s, char *out)
               "parsing a string\n", *s, *s);
       fflush(stderr);
    }
 
    return i;
 }
 
 static char *
 read_pane_settings(char *str, unsigned * const x, unsigned * const y,
                unsigned * const width, unsigned * const height,
-               uint64_t * const ceiling, boolean * const dyn_ceiling)
+               uint64_t * const ceiling, boolean * const dyn_ceiling,
+               boolean *reset_colors)
 {
    char *ret = str;
    unsigned tmp;
 
    while (*str == '.') {
       ++str;
       switch (*str) {
       case 'x':
          ++str;
          *x = strtoul(str, &ret, 10);
@@ -967,20 +969,26 @@ read_pane_settings(char *str, unsigned * const x, unsigned * const y,
          *ceiling = tmp > 10 ? tmp : 10;
          str = ret;
          break;
 
       case 'd':
          ++str;
          ret = str;
          *dyn_ceiling = true;
          break;
 
+      case 'r':
+         ++str;
+         ret = str;
+         *reset_colors = true;
+         break;
+
       default:
          fprintf(stderr, "gallium_hud: syntax error: unexpected '%c'\n", *str);
          fflush(stderr);
       }
 
    }
 
    return ret;
 }
 
@@ -1008,56 +1016,62 @@ hud_parse_env_var(struct hud_context *hud, const char *env)
    unsigned num, i;
    char name_a[256], s[256];
    char *name;
    struct hud_pane *pane = NULL;
    unsigned x = 10, y = 10;
    unsigned width = 251, height = 100;
    unsigned period = 500 * 1000;  /* default period (1/2 second) */
    uint64_t ceiling = UINT64_MAX;
    unsigned column_width = 251;
    boolean dyn_ceiling = false;
+   boolean reset_colors = false;
    const char *period_env;
 
    /*
     * The GALLIUM_HUD_PERIOD env var sets the graph update rate.
     * The env var is in seconds (a float).
     * Zero means update after every frame.
     */
    period_env = getenv("GALLIUM_HUD_PERIOD");
    if (period_env) {
       float p = (float) atof(period_env);
       if (p >= 0.0f) {
          period = (unsigned) (p * 1000 * 1000);
       }
    }
 
    while ((num = parse_string(env, name_a)) != 0) {
       env += num;
 
       /* check for explicit location, size and etc. settings */
       name = read_pane_settings(name_a, &x, &y, &width, &height, &ceiling,
-                         &dyn_ceiling);
+                         &dyn_ceiling, &reset_colors);
 
      /*
       * Keep track of overall column width to avoid pane overlapping in case
       * later we create a new column while the bottom pane in the current
       * column is less wide than the rest of the panes in it.
       */
      column_width = width > column_width ? width : column_width;
 
       if (!pane) {
          pane = hud_pane_create(x, y, x + width, y + height, period, 10,
                          ceiling, dyn_ceiling);
          if (!pane)
             return;
       }
 
+      if (reset_colors) {
+         pane->next_color = 0;
+         reset_colors = false;
+      }
+
       /* Add a graph. */
 #if HAVE_GALLIUM_EXTRA_HUD || HAVE_LIBSENSORS
       char arg_name[64];
 #endif
       /* IF YOU CHANGE THIS, UPDATE print_help! */
       if (strcmp(name, "fps") == 0) {
          hud_fps_graph_install(pane);
       }
       else if (strcmp(name, "cpu") == 0) {
          hud_cpu_graph_install(pane, ALL_CPUS);
@@ -1306,20 +1320,21 @@ print_help(struct pipe_screen *screen)
    puts("             to the upper-left corner of the viewport, in pixels.");
    puts("  'y[value]' sets the location of the pane on the y axis relative");
    puts("             to the upper-left corner of the viewport, in pixels.");
    puts("  'w[value]' sets width of the graph pixels.");
    puts("  'h[value]' sets height of the graph in pixels.");
    puts("  'c[value]' sets the ceiling of the value of the Y axis.");
    puts("             If the graph needs to draw values higher than");
    puts("             the ceiling allows, the value is clamped.");
    puts("  'd' activates dynamic Y axis readjustment to set the value of");
    puts("      the Y axis to match the highest value still visible in the graph.");
+   puts("  'r' resets the color counter (the next color will be green)");
    puts("");
    puts("  If 'c' and 'd' modifiers are used simultaneously, both are in effect:");
    puts("  the Y axis does not go above the restriction imposed by 'c' while");
    puts("  still adjusting the value of the Y axis down when appropriate.");
    puts("");
    puts("  Example: GALLIUM_HUD=\".w256.h64.x1600.y520.d.c1000fps+cpu,.datom-count\"");
    puts("");
    puts("  Available names:");
    puts("    fps");
    puts("    cpu");
diff --git a/src/gallium/auxiliary/hud/hud_private.h b/src/gallium/auxiliary/hud/hud_private.h
index 5132b3d..479ece5 100644
--- a/src/gallium/auxiliary/hud/hud_private.h
+++ b/src/gallium/auxiliary/hud/hud_private.h
@@ -66,20 +66,21 @@ struct hud_pane {
    uint64_t max_value;
    uint64_t initial_max_value;
    uint64_t ceiling;
    unsigned dyn_ceil_last_ran;
    boolean dyn_ceiling;
    enum pipe_driver_query_type type;
    uint64_t period; /* in microseconds */
 
    struct list_head graph_list;
    unsigned num_graphs;
+   unsigned next_color;
 };
 
 
 /* core */
 void hud_pane_add_graph(struct hud_pane *pane, struct hud_graph *gr);
 void hud_pane_set_max_value(struct hud_pane *pane, uint64_t value);
 void hud_graph_add_value(struct hud_graph *gr, uint64_t value);
 
 /* graphs/queries */
 struct hud_batch_query_context;
-- 
2.7.4



More information about the mesa-dev mailing list