• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
36 enum hud_counter {
37    HUD_COUNTER_OFFLOADED,
38    HUD_COUNTER_DIRECT,
39    HUD_COUNTER_SYNCS,
40 };
41 
42 struct hud_context {
43    int refcount;
44 
45    /* Context where queries are executed. */
46    struct pipe_context *record_pipe;
47 
48    /* Context where the HUD is drawn: */
49    struct pipe_context *pipe;
50    struct cso_context *cso;
51 
52    struct hud_batch_query_context *batch_query;
53    struct list_head pane_list;
54 
55    struct util_queue_monitoring *monitored_queue;
56 
57    /* states */
58    struct pipe_blend_state no_blend, alpha_blend;
59    struct pipe_depth_stencil_alpha_state dsa;
60    void *fs_color, *fs_text;
61    struct pipe_rasterizer_state rasterizer, rasterizer_aa_lines;
62    void *vs;
63    struct pipe_vertex_element velems[2];
64 
65    /* font */
66    struct util_font font;
67    struct pipe_sampler_view *font_sampler_view;
68    struct pipe_sampler_state font_sampler_state;
69 
70    /* VS constant buffer */
71    struct {
72       float color[4];
73       float two_div_fb_width;
74       float two_div_fb_height;
75       float translate[2];
76       float scale[2];
77       float padding[2];
78    } constants;
79    struct pipe_constant_buffer constbuf;
80 
81    unsigned fb_width, fb_height;
82 
83    /* vertices for text and background drawing are accumulated here and then
84     * drawn all at once */
85    struct vertex_queue {
86       float *vertices;
87       struct pipe_vertex_buffer vbuf;
88       unsigned max_num_vertices;
89       unsigned num_vertices;
90       unsigned buffer_size;
91    } text, bg, whitelines, color_prims;
92 
93    bool has_srgb;
94 };
95 
96 struct hud_graph {
97    /* initialized by common code */
98    struct list_head head;
99    struct hud_pane *pane;
100    float color[3];
101    float *vertices; /* ring buffer of vertices */
102 
103    /* name and query */
104    char name[128];
105    void *query_data;
106    void (*begin_query)(struct hud_graph *gr, struct pipe_context *pipe);
107    void (*query_new_value)(struct hud_graph *gr, struct pipe_context *pipe);
108    /* use this instead of ordinary free() */
109    void (*free_query_data)(void *ptr, struct pipe_context *pipe);
110 
111    /* mutable variables */
112    unsigned num_vertices;
113    unsigned index; /* vertex index being updated */
114    double current_value;
115    FILE *fd;
116 };
117 
118 struct hud_pane {
119    struct list_head head;
120    struct hud_context *hud;
121    unsigned x1, y1, x2, y2;
122    unsigned inner_x1;
123    unsigned inner_y1;
124    unsigned inner_x2;
125    unsigned inner_y2;
126    unsigned inner_width;
127    unsigned inner_height;
128    float yscale;
129    unsigned max_num_vertices;
130    unsigned last_line; /* index of the last describing line in the graph */
131    uint64_t max_value;
132    uint64_t initial_max_value;
133    uint64_t ceiling;
134    unsigned dyn_ceil_last_ran;
135    boolean dyn_ceiling;
136    boolean sort_items;
137    enum pipe_driver_query_type type;
138    uint64_t period; /* in microseconds */
139 
140    struct list_head graph_list;
141    unsigned num_graphs;
142    unsigned next_color;
143 };
144 
145 
146 /* core */
147 void hud_pane_add_graph(struct hud_pane *pane, struct hud_graph *gr);
148 void hud_pane_set_max_value(struct hud_pane *pane, uint64_t value);
149 void hud_graph_add_value(struct hud_graph *gr, double value);
150 
151 /* graphs/queries */
152 struct hud_batch_query_context;
153 
154 #define ALL_CPUS ~0 /* optionally set as cpu_index */
155 
156 int hud_get_num_cpus(void);
157 
158 void hud_fps_graph_install(struct hud_pane *pane);
159 void hud_cpu_graph_install(struct hud_pane *pane, unsigned cpu_index);
160 void hud_thread_busy_install(struct hud_pane *pane, const char *name, bool main);
161 void hud_thread_counter_install(struct hud_pane *pane, const char *name,
162                                 enum hud_counter counter);
163 void hud_pipe_query_install(struct hud_batch_query_context **pbq,
164                             struct hud_pane *pane,
165                             const char *name,
166                             enum pipe_query_type query_type,
167                             unsigned result_index,
168                             uint64_t max_value,
169                             enum pipe_driver_query_type type,
170                             enum pipe_driver_query_result_type result_type,
171                             unsigned flags);
172 boolean hud_driver_query_install(struct hud_batch_query_context **pbq,
173                                  struct hud_pane *pane,
174                                  struct pipe_screen *screen, const char *name);
175 void hud_batch_query_begin(struct hud_batch_query_context *bq,
176                            struct pipe_context *pipe);
177 void hud_batch_query_update(struct hud_batch_query_context *bq,
178                             struct pipe_context *pipe);
179 void hud_batch_query_cleanup(struct hud_batch_query_context **pbq,
180                              struct pipe_context *pipe);
181 
182 #ifdef HAVE_GALLIUM_EXTRA_HUD
183 int hud_get_num_nics(bool displayhelp);
184 #define NIC_DIRECTION_RX 1
185 #define NIC_DIRECTION_TX 2
186 #define NIC_RSSI_DBM     3
187 void hud_nic_graph_install(struct hud_pane *pane, const char *nic_index,
188                            unsigned int mode);
189 
190 int hud_get_num_disks(bool displayhelp);
191 #define DISKSTAT_RD 1
192 #define DISKSTAT_WR 2
193 void hud_diskstat_graph_install(struct hud_pane *pane, const char *dev_name,
194                                 unsigned int mode);
195 
196 int hud_get_num_cpufreq(bool displayhelp);
197 #define CPUFREQ_MINIMUM     1
198 #define CPUFREQ_CURRENT     2
199 #define CPUFREQ_MAXIMUM     3
200 void hud_cpufreq_graph_install(struct hud_pane *pane, int cpu_index, unsigned int mode);
201 #endif
202 
203 #ifdef HAVE_LIBSENSORS
204 int hud_get_num_sensors(bool displayhelp);
205 #define SENSORS_TEMP_CURRENT     1
206 #define SENSORS_TEMP_CRITICAL    2
207 #define SENSORS_VOLTAGE_CURRENT  3
208 #define SENSORS_CURRENT_CURRENT  4
209 #define SENSORS_POWER_CURRENT    5
210 void hud_sensors_temp_graph_install(struct hud_pane *pane, const char *dev_name,
211                                     unsigned int mode);
212 #endif
213 
214 #endif
215