[Mesa-dev] [PATCH 4/6] gallium/hud: draw numbers with 3 decimal places if those aren't 0
Marek Olšák
maraeo at gmail.com
Thu Aug 18 19:56:31 UTC 2016
From: Marek Olšák <marek.olsak at amd.com>
---
src/gallium/auxiliary/hud/hud_context.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/src/gallium/auxiliary/hud/hud_context.c b/src/gallium/auxiliary/hud/hud_context.c
index 8ab998e..f7baccd 100644
--- a/src/gallium/auxiliary/hud/hud_context.c
+++ b/src/gallium/auxiliary/hud/hud_context.c
@@ -289,26 +289,33 @@ number_to_human_readable(uint64_t num, uint64_t max_value,
max_unit = ARRAY_SIZE(metric_units)-1;
units = metric_units;
}
}
while (d > divisor && unit < max_unit) {
d /= divisor;
unit++;
}
- if (d >= 100 || d == (int)d)
+ /* Round to 3 decimal places so as not to print trailing zeros. */
+ if (d*1000 != (int)(d*1000))
+ d = round(d * 1000) / 1000;
+
+ /* Show at least 4 digits with at most 3 decimal places, but not zeros. */
+ if (d >= 1000 || d == (int)d)
sprintf(out, "%.0f%s", d, units[unit]);
- else if (d >= 10 || d*10 == (int)(d*10))
+ else if (d >= 100 || d*10 == (int)(d*10))
sprintf(out, "%.1f%s", d, units[unit]);
- else
+ else if (d >= 10 || d*100 == (int)(d*100))
sprintf(out, "%.2f%s", d, units[unit]);
+ else
+ sprintf(out, "%.3f%s", d, units[unit]);
}
static void
hud_draw_graph_line_strip(struct hud_context *hud, const struct hud_graph *gr,
unsigned xoffset, unsigned yoffset, float yscale)
{
if (gr->num_vertices <= 1)
return;
assert(gr->index <= gr->num_vertices);
@@ -529,21 +536,21 @@ hud_draw(struct hud_context *hud, struct pipe_resource *tex)
cso_set_vertex_elements(cso, 2, hud->velems);
cso_set_render_condition(cso, NULL, FALSE, 0);
cso_set_sampler_views(cso, PIPE_SHADER_FRAGMENT, 1,
&hud->font_sampler_view);
cso_set_samplers(cso, PIPE_SHADER_FRAGMENT, 1, sampler_states);
cso_set_constant_buffer(cso, PIPE_SHADER_VERTEX, 0, &hud->constbuf);
/* prepare vertex buffers */
hud_alloc_vertices(hud, &hud->bg, 4 * 128, 2 * sizeof(float));
hud_alloc_vertices(hud, &hud->whitelines, 4 * 256, 2 * sizeof(float));
- hud_alloc_vertices(hud, &hud->text, 4 * 512, 4 * sizeof(float));
+ hud_alloc_vertices(hud, &hud->text, 4 * 1024, 4 * sizeof(float));
/* prepare all graphs */
hud_batch_query_update(hud->batch_query);
LIST_FOR_EACH_ENTRY(pane, &hud->pane_list, head) {
LIST_FOR_EACH_ENTRY(gr, &pane->graph_list, head) {
gr->query_new_value(gr);
}
hud_pane_accumulate_vertices(hud, pane);
@@ -1019,21 +1026,21 @@ hud_parse_env_var(struct hud_context *hud, const char *env)
if (pane && pane->num_graphs) {
LIST_ADDTAIL(&pane->head, &hud->pane_list);
pane = NULL;
}
break;
case ';':
env++;
y = 10;
- x += column_width + hud->font.glyph_width * 7;
+ x += column_width + hud->font.glyph_width * 9;
height = 100;
if (pane && pane->num_graphs) {
LIST_ADDTAIL(&pane->head, &hud->pane_list);
pane = NULL;
}
/* Starting a new column; reset column width. */
column_width = 251;
break;
--
2.7.4
More information about the mesa-dev
mailing list