Mesa (master): gallium/hud: add an option to sort items below graphs

Marek Olšák mareko at kemper.freedesktop.org
Thu Jan 5 17:30:23 UTC 2017


Module: Mesa
Branch: master
Commit: 6d54cd75a893ff643745e711e0c5ba14a465f505
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=6d54cd75a893ff643745e711e0c5ba14a465f505

Author: Marek Olšák <marek.olsak at amd.com>
Date:   Sun Dec 25 21:03:25 2016 +0100

gallium/hud: add an option to sort items below graphs

Reviewed-by: Nicolai Hähnle <nicolai.haehnle at amd.com>

---

 src/gallium/auxiliary/hud/hud_context.c | 37 ++++++++++++++++++++++++++++-----
 src/gallium/auxiliary/hud/hud_private.h |  1 +
 2 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/src/gallium/auxiliary/hud/hud_context.c b/src/gallium/auxiliary/hud/hud_context.c
index 4e2c789..805e1a7 100644
--- a/src/gallium/auxiliary/hud/hud_context.c
+++ b/src/gallium/auxiliary/hud/hud_context.c
@@ -483,7 +483,7 @@ hud_draw(struct hud_context *hud, struct pipe_resource *tex)
    const struct pipe_sampler_state *sampler_states[] =
          { &hud->font_sampler_state };
    struct hud_pane *pane;
-   struct hud_graph *gr;
+   struct hud_graph *gr, *next;
 
    if (!huds_visible)
       return;
@@ -576,6 +576,23 @@ hud_draw(struct hud_context *hud, struct pipe_resource *tex)
          gr->query_new_value(gr);
       }
 
+      if (pane->sort_items) {
+         LIST_FOR_EACH_ENTRY_SAFE(gr, next, &pane->graph_list, head) {
+            /* ignore the last one */
+            if (&gr->head == pane->graph_list.prev)
+               continue;
+
+            /* This is an incremental bubble sort, because we only do one pass
+             * per frame. It will eventually reach an equilibrium.
+             */
+            if (gr->current_value <
+                LIST_ENTRY(struct hud_graph, next, head)->current_value) {
+               LIST_DEL(&gr->head);
+               LIST_ADD(&gr->head, &next->head);
+            }
+         }
+      }
+
       hud_pane_accumulate_vertices(hud, pane);
    }
 
@@ -761,7 +778,7 @@ hud_pane_update_dyn_ceiling(struct hud_graph *gr, struct hud_pane *pane)
 static struct hud_pane *
 hud_pane_create(unsigned x1, unsigned y1, unsigned x2, unsigned y2,
                 unsigned period, uint64_t max_value, uint64_t ceiling,
-                boolean dyn_ceiling)
+                boolean dyn_ceiling, boolean sort_items)
 {
    struct hud_pane *pane = CALLOC_STRUCT(hud_pane);
 
@@ -783,6 +800,7 @@ hud_pane_create(unsigned x1, unsigned y1, unsigned x2, unsigned y2,
    pane->ceiling = ceiling;
    pane->dyn_ceiling = dyn_ceiling;
    pane->dyn_ceil_last_ran = 0;
+   pane->sort_items = sort_items;
    pane->initial_max_value = max_value;
    hud_pane_set_max_value(pane, max_value);
    LIST_INITHEAD(&pane->graph_list);
@@ -928,7 +946,7 @@ 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,
-               boolean *reset_colors)
+               boolean *reset_colors, boolean *sort_items)
 {
    char *ret = str;
    unsigned tmp;
@@ -985,6 +1003,12 @@ read_pane_settings(char *str, unsigned * const x, unsigned * const y,
          *reset_colors = true;
          break;
 
+      case 's':
+         ++str;
+         ret = str;
+         *sort_items = true;
+         break;
+
       default:
          fprintf(stderr, "gallium_hud: syntax error: unexpected '%c'\n", *str);
          fflush(stderr);
@@ -1027,6 +1051,7 @@ hud_parse_env_var(struct hud_context *hud, const char *env)
    unsigned column_width = 251;
    boolean dyn_ceiling = false;
    boolean reset_colors = false;
+   boolean sort_items = false;
    const char *period_env;
 
    /*
@@ -1047,7 +1072,7 @@ hud_parse_env_var(struct hud_context *hud, const char *env)
 
       /* check for explicit location, size and etc. settings */
       name = read_pane_settings(name_a, &x, &y, &width, &height, &ceiling,
-                         &dyn_ceiling, &reset_colors);
+                                &dyn_ceiling, &reset_colors, &sort_items);
 
      /*
       * Keep track of overall column width to avoid pane overlapping in case
@@ -1058,7 +1083,7 @@ hud_parse_env_var(struct hud_context *hud, const char *env)
 
       if (!pane) {
          pane = hud_pane_create(x, y, x + width, y + height, period, 10,
-                         ceiling, dyn_ceiling);
+                         ceiling, dyn_ceiling, sort_items);
          if (!pane)
             return;
       }
@@ -1292,6 +1317,7 @@ hud_parse_env_var(struct hud_context *hud, const char *env)
       width = 251;
       ceiling = UINT64_MAX;
       dyn_ceiling = false;
+      sort_items = false;
 
    }
 
@@ -1344,6 +1370,7 @@ print_help(struct pipe_screen *screen)
    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("  's' sort items below graphs in descending order");
    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");
diff --git a/src/gallium/auxiliary/hud/hud_private.h b/src/gallium/auxiliary/hud/hud_private.h
index 479ece5..d719e5f 100644
--- a/src/gallium/auxiliary/hud/hud_private.h
+++ b/src/gallium/auxiliary/hud/hud_private.h
@@ -68,6 +68,7 @@ struct hud_pane {
    uint64_t ceiling;
    unsigned dyn_ceil_last_ran;
    boolean dyn_ceiling;
+   boolean sort_items;
    enum pipe_driver_query_type type;
    uint64_t period; /* in microseconds */
 




More information about the mesa-commit mailing list