1/************************************************************************** 2 * 3 * Copyright 2013 Marek Olšák <maraeo@gmail.com> 4 * All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the 8 * "Software"), to deal in the Software without restriction, including 9 * without limitation the rights to use, copy, modify, merge, publish, 10 * distribute, sub license, and/or sell copies of the Software, and to 11 * permit persons to whom the Software is furnished to do so, subject to 12 * the following conditions: 13 * 14 * The above copyright notice and this permission notice (including the 15 * next paragraph) shall be included in all copies or substantial portions 16 * of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21 * IN NO EVENT SHALL THE AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR 22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 * 26 **************************************************************************/ 27 28#ifndef HUD_PRIVATE_H 29#define HUD_PRIVATE_H 30 31#include "pipe/p_context.h" 32#include "pipe/p_state.h" 33#include "util/list.h" 34#include "hud/font.h" 35 36enum hud_counter { 37 HUD_COUNTER_OFFLOADED, 38 HUD_COUNTER_DIRECT, 39 HUD_COUNTER_SYNCS, 40}; 41 42struct hud_context { 43 int refcount; 44 bool simple; 45 46 /* Context where queries are executed. */ 47 struct pipe_context *record_pipe; 48 49 /* Context where the HUD is drawn: */ 50 struct pipe_context *pipe; 51 struct cso_context *cso; 52 53 struct hud_batch_query_context *batch_query; 54 struct list_head pane_list; 55 56 struct util_queue_monitoring *monitored_queue; 57 58 /* states */ 59 struct pipe_blend_state no_blend, alpha_blend; 60 struct pipe_depth_stencil_alpha_state dsa; 61 void *fs_color, *fs_text; 62 struct pipe_rasterizer_state rasterizer, rasterizer_aa_lines; 63 void *vs; 64 struct pipe_vertex_element velems[2]; 65 66 /* font */ 67 struct util_font font; 68 struct pipe_sampler_view *font_sampler_view; 69 struct pipe_sampler_state font_sampler_state; 70 71 /* VS constant buffer */ 72 struct { 73 float color[4]; 74 float two_div_fb_width; 75 float two_div_fb_height; 76 float translate[2]; 77 float scale[2]; 78 float padding[2]; 79 } constants; 80 struct pipe_constant_buffer constbuf; 81 82 unsigned fb_width, fb_height; 83 84 /* vertices for text and background drawing are accumulated here and then 85 * drawn all at once */ 86 struct vertex_queue { 87 float *vertices; 88 struct pipe_vertex_buffer vbuf; 89 unsigned max_num_vertices; 90 unsigned num_vertices; 91 unsigned buffer_size; 92 } text, bg, whitelines, color_prims; 93 94 bool has_srgb; 95}; 96 97struct hud_graph { 98 /* initialized by common code */ 99 struct list_head head; 100 struct hud_pane *pane; 101 float color[3]; 102 float *vertices; /* ring buffer of vertices */ 103 104 /* name and query */ 105 char name[128]; 106 void *query_data; 107 void (*begin_query)(struct hud_graph *gr, struct pipe_context *pipe); 108 void (*query_new_value)(struct hud_graph *gr, struct pipe_context *pipe); 109 /* use this instead of ordinary free() */ 110 void (*free_query_data)(void *ptr, struct pipe_context *pipe); 111 112 /* mutable variables */ 113 unsigned num_vertices; 114 unsigned index; /* vertex index being updated */ 115 double current_value; 116 FILE *fd; 117}; 118 119struct hud_pane { 120 struct list_head head; 121 struct hud_context *hud; 122 unsigned x1, y1, x2, y2, y_simple; 123 unsigned inner_x1; 124 unsigned inner_y1; 125 unsigned inner_x2; 126 unsigned inner_y2; 127 unsigned inner_width; 128 unsigned inner_height; 129 float yscale; 130 unsigned max_num_vertices; 131 unsigned last_line; /* index of the last describing line in the graph */ 132 uint64_t max_value; 133 uint64_t initial_max_value; 134 uint64_t ceiling; 135 unsigned dyn_ceil_last_ran; 136 boolean dyn_ceiling; 137 boolean sort_items; 138 enum pipe_driver_query_type type; 139 uint64_t period; /* in microseconds */ 140 141 struct list_head graph_list; 142 unsigned num_graphs; 143 unsigned next_color; 144}; 145 146 147/* core */ 148void hud_pane_add_graph(struct hud_pane *pane, struct hud_graph *gr); 149void hud_pane_set_max_value(struct hud_pane *pane, uint64_t value); 150void hud_graph_add_value(struct hud_graph *gr, double value); 151 152/* graphs/queries */ 153struct hud_batch_query_context; 154 155#define ALL_CPUS ~0 /* optionally set as cpu_index */ 156 157int hud_get_num_cpus(void); 158 159void hud_fps_graph_install(struct hud_pane *pane); 160void hud_frametime_graph_install(struct hud_pane *pane); 161void hud_cpu_graph_install(struct hud_pane *pane, unsigned cpu_index); 162void hud_thread_busy_install(struct hud_pane *pane, const char *name, bool main); 163void hud_thread_counter_install(struct hud_pane *pane, const char *name, 164 enum hud_counter counter); 165void hud_pipe_query_install(struct hud_batch_query_context **pbq, 166 struct hud_pane *pane, 167 const char *name, 168 enum pipe_query_type query_type, 169 unsigned result_index, 170 uint64_t max_value, 171 enum pipe_driver_query_type type, 172 enum pipe_driver_query_result_type result_type, 173 unsigned flags); 174boolean hud_driver_query_install(struct hud_batch_query_context **pbq, 175 struct hud_pane *pane, 176 struct pipe_screen *screen, const char *name); 177void hud_batch_query_begin(struct hud_batch_query_context *bq, 178 struct pipe_context *pipe); 179void hud_batch_query_update(struct hud_batch_query_context *bq, 180 struct pipe_context *pipe); 181void hud_batch_query_cleanup(struct hud_batch_query_context **pbq, 182 struct pipe_context *pipe); 183 184#ifdef HAVE_GALLIUM_EXTRA_HUD 185int hud_get_num_nics(bool displayhelp); 186#define NIC_DIRECTION_RX 1 187#define NIC_DIRECTION_TX 2 188#define NIC_RSSI_DBM 3 189void hud_nic_graph_install(struct hud_pane *pane, const char *nic_index, 190 unsigned int mode); 191 192int hud_get_num_disks(bool displayhelp); 193#define DISKSTAT_RD 1 194#define DISKSTAT_WR 2 195void hud_diskstat_graph_install(struct hud_pane *pane, const char *dev_name, 196 unsigned int mode); 197 198int hud_get_num_cpufreq(bool displayhelp); 199#define CPUFREQ_MINIMUM 1 200#define CPUFREQ_CURRENT 2 201#define CPUFREQ_MAXIMUM 3 202void hud_cpufreq_graph_install(struct hud_pane *pane, int cpu_index, unsigned int mode); 203#endif 204 205#ifdef HAVE_LIBSENSORS 206int hud_get_num_sensors(bool displayhelp); 207#define SENSORS_TEMP_CURRENT 1 208#define SENSORS_TEMP_CRITICAL 2 209#define SENSORS_VOLTAGE_CURRENT 3 210#define SENSORS_CURRENT_CURRENT 4 211#define SENSORS_POWER_CURRENT 5 212void hud_sensors_temp_graph_install(struct hud_pane *pane, const char *dev_name, 213 unsigned int mode); 214#endif 215 216#endif 217