+ return true;
+
+fail:
+ hud_unset_draw_context(hud);
+ fprintf(stderr, "hud: failed to set a draw context");
+ return false;
+}
+
+struct hud_context *
+hud_create(struct cso_context *cso)
+{
+ struct pipe_screen *screen = cso_get_pipe_context(cso)->screen;
+ struct hud_context *hud;
+ unsigned i;
+ const char *env = debug_get_option("GALLIUM_HUD", NULL);
+#ifdef PIPE_OS_UNIX
+ unsigned signo = debug_get_num_option("GALLIUM_HUD_TOGGLE_SIGNAL", 0);
+ static boolean sig_handled = FALSE;
+ struct sigaction action = {};
+#endif
+ huds_visible = debug_get_bool_option("GALLIUM_HUD_VISIBLE", TRUE);
+
+ if (!env || !*env)
+ return NULL;
+
+ if (strcmp(env, "help") == 0) {
+ print_help(screen);
+ return NULL;
+ }
+
+ hud = CALLOC_STRUCT(hud_context);
+ if (!hud)
+ return NULL;
+
+ /* font (the context is only used for the texture upload) */
+ if (!util_font_create(cso_get_pipe_context(cso),
+ UTIL_FONT_FIXED_8X13, &hud->font)) {
+ 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;
+ hud->alpha_blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ONE;
+
+ /* rasterizer */
+ hud->rasterizer.half_pixel_center = 1;
+ hud->rasterizer.bottom_edge_rule = 1;
+ hud->rasterizer.depth_clip = 1;
+ hud->rasterizer.line_width = 1;
+ hud->rasterizer.line_last_pixel = 1;
+
+ hud->rasterizer_aa_lines = hud->rasterizer;
+ hud->rasterizer_aa_lines.line_smooth = 1;
+