cf6cb7e0 |
1 | /****************************************************************************** |
2 | * Draw_Item.c |
3 | * |
4 | * This file contains methods responsible for drawing a generic type of data |
5 | * in a drawable. Doing this generically will permit user defined drawing |
6 | * behavior in a later time. |
7 | * |
b782dd11 |
8 | * This file provides an API which is meant to be reusable for all viewers that |
9 | * need to show information in line, icon, text, background or point form in |
10 | * a drawable area having time for x axis. The y axis, in the control flow |
11 | * viewer case, is corresponding to the different processes, but it can be |
12 | * reused integrally for cpu, and eventually locks, buffers, network |
13 | * interfaces... What will differ between the viewers is the precise |
14 | * information which interests us. We may think that the most useful |
15 | * information for control flow are some specific events, like schedule |
16 | * change, and processes'states. It may differ for a cpu viewer : the |
17 | * interesting information could be more the execution mode of each cpu. |
18 | * This API in meant to make viewer's writers life easier : it will become |
19 | * a simple choice of icons and line types for the precise information |
20 | * the viewer has to provide (agremented with keeping supplementary records |
21 | * and modifying slightly the DrawContext to suit the needs.) |
22 | * |
f0728492 |
23 | * We keep each data type in attributes, keys to specific information |
24 | * being formed from the GQuark corresponding to the information received. |
25 | * (facilities / facility_name / events / eventname.) |
26 | * (cpus/cpu_name, process_states/ps_name, |
27 | * execution_modes/em_name, execution_submodes/es_name). |
cf6cb7e0 |
28 | * The goal is then to provide a generic way to print information on the |
29 | * screen for all this different information. |
30 | * |
31 | * Information can be printed as |
32 | * |
33 | * - text (text + color + size + position (over or under line) |
34 | * - icon (icon filename, corresponding to a loaded icon, accessible through |
35 | * a GQuark. Icons are loaded statically at the guiControlFlow level during |
36 | * module initialization and can be added on the fly if not present in the |
37 | * GQuark.) The habitual place for xpm icons is in |
38 | * ${prefix}/share/LinuxTraceToolkit.) + position (over or under line) |
39 | * - line (color, width, style) |
189a5d08 |
40 | * - Arc (big points) (color, size) |
cf6cb7e0 |
41 | * - background color (color) |
42 | * |
189a5d08 |
43 | * An item is a leaf of the attributes tree. It is, in that case, including |
44 | * all kind of events categories we can have. It then associates each category |
45 | * with one or more actions (drawing something) or nothing. |
46 | * |
7d5ffafa |
47 | * Each item has an array of hooks (hook list). Each hook represents an |
48 | * operation to perform. We seek the array each time we want to |
a2e850ff |
49 | * draw an item. We execute each operation in order. An operation type |
50 | * is associated with each hook to permit user listing and modification |
51 | * of these operations. The operation type is also used to find the |
52 | * corresponding priority for the sorting. Operation type and priorities |
53 | * are enum and a static int table. |
cf6cb7e0 |
54 | * |
55 | * The array has to be sorted by priority each time we add a task in it. |
a2e850ff |
56 | * A priority is associated with each operation type. It permits |
cf6cb7e0 |
57 | * to perform background color selection before line or text drawing. We also |
58 | * draw lines before text, so the text appears over the lines. |
59 | * |
60 | * Executing all the arrays of operations for a specific event (which |
61 | * implies information for state, event, cpu, execution mode and submode) |
62 | * has to be done in a same DrawContext. The goal there is to keep the offset |
63 | * of the text and icons over and under the middle line, so a specific |
64 | * event could be printed as ( R Si 0 for running, scheduled in, cpu 0 ), |
7d5ffafa |
65 | * text being easy to replace with icons. The DrawContext is passed as |
66 | * call_data for the operation hooks. |
cf6cb7e0 |
67 | * |
b782dd11 |
68 | * We use the lttv global attributes to keep track of the loaded icons. |
69 | * If we need an icon, we look for it in the icons / icon name pathname. |
70 | * If found, we use the pointer to it. If not, we load the pixmap in |
1a31868c |
71 | * memory and set the pointer to the GdkPixmap in the attributes. The |
72 | * structure pointed to contains the pixmap and the mask bitmap. |
b782dd11 |
73 | * |
cf6cb7e0 |
74 | * Author : Mathieu Desnoyers, October 2003 |
75 | */ |
7d5ffafa |
76 | |
77 | #include <glib.h> |
09e2606f |
78 | #include <gtk/gtk.h> |
79 | #include <gdk/gdk.h> |
7d5ffafa |
80 | #include <lttv/hook.h> |
f0728492 |
81 | #include <lttv/attribute.h> |
82 | #include <lttv/iattribute.h> |
1a31868c |
83 | #include <string.h> |
7d5ffafa |
84 | |
b782dd11 |
85 | #include <lttv/processTrace.h> |
86 | #include <lttv/state.h> |
87 | |
09e2606f |
88 | #include "Draw_Item.h" |
1a31868c |
89 | |
90 | |
91 | #define MAX_PATH_LEN 256 |
92 | |
501d5405 |
93 | /* drawing hook functions */ |
4c69e0cc |
94 | gboolean draw_text( void *hook_data, void *call_data) |
b782dd11 |
95 | { |
a56a1ba4 |
96 | PropertiesText *Properties = (PropertiesText*)hook_data; |
97 | DrawContext *Draw_Context = (DrawContext*)call_data; |
98 | |
99 | PangoContext *context; |
100 | PangoLayout *layout; |
101 | PangoAttribute *attribute; |
102 | PangoFontDescription *FontDesc;// = pango_font_description_new(); |
103 | gint Font_Size; |
104 | PangoRectangle ink_rect; |
105 | |
106 | layout = Draw_Context->pango_layout; |
107 | |
108 | context = pango_layout_get_context(layout); |
109 | FontDesc = pango_context_get_font_description(context); |
110 | |
111 | pango_font_description_set_size(FontDesc, Properties->size*PANGO_SCALE); |
112 | pango_layout_context_changed(layout); |
113 | |
68997a22 |
114 | pango_layout_set_text(layout, Properties->text, -1); |
a56a1ba4 |
115 | pango_layout_get_pixel_extents(layout, &ink_rect, NULL); |
116 | switch(Properties->position) { |
117 | case OVER: |
118 | gdk_draw_layout_with_colors(Draw_Context->drawable, |
119 | Draw_Context->gc, |
68997a22 |
120 | Draw_Context->current->modify_over->x, |
121 | Draw_Context->current->modify_over->y, |
a56a1ba4 |
122 | layout, Properties->foreground, Properties->background); |
68997a22 |
123 | Draw_Context->current->modify_over->x += ink_rect.width; |
a56a1ba4 |
124 | |
125 | break; |
126 | case MIDDLE: |
127 | gdk_draw_layout_with_colors(Draw_Context->drawable, |
128 | Draw_Context->gc, |
68997a22 |
129 | Draw_Context->current->modify_middle->x, |
130 | Draw_Context->current->modify_middle->y, |
a56a1ba4 |
131 | layout, Properties->foreground, Properties->background); |
68997a22 |
132 | Draw_Context->current->modify_middle->x += ink_rect.width; |
a56a1ba4 |
133 | break; |
134 | case UNDER: |
135 | gdk_draw_layout_with_colors(Draw_Context->drawable, |
136 | Draw_Context->gc, |
68997a22 |
137 | Draw_Context->current->modify_under->x, |
138 | Draw_Context->current->modify_under->y, |
a56a1ba4 |
139 | layout, Properties->foreground, Properties->background); |
68997a22 |
140 | Draw_Context->current->modify_under->x += ink_rect.width; |
a56a1ba4 |
141 | break; |
142 | } |
143 | |
144 | return 0; |
b782dd11 |
145 | } |
146 | |
1a31868c |
147 | |
148 | /* To speed up the process, search in already loaded icons list first. Only |
149 | * load it if not present. |
150 | */ |
4c69e0cc |
151 | gboolean draw_icon( void *hook_data, void *call_data) |
b782dd11 |
152 | { |
a56a1ba4 |
153 | PropertiesIcon *Properties = (PropertiesIcon*)hook_data; |
154 | DrawContext *Draw_Context = (DrawContext*)call_data; |
b782dd11 |
155 | |
1a31868c |
156 | LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); |
a56a1ba4 |
157 | LttvAttributeValue value; |
158 | gchar icon_name[MAX_PATH_LEN] = "icons/"; |
159 | IconStruct *icon_info; |
8d088fb2 |
160 | |
a56a1ba4 |
161 | strcat(icon_name, Properties->icon_name); |
162 | |
1a31868c |
163 | g_assert(lttv_iattribute_find_by_path(attributes, icon_name, |
164 | LTTV_POINTER, &value)); |
a56a1ba4 |
165 | if(*(value.v_pointer) == NULL) |
166 | { |
167 | *(value.v_pointer) = icon_info = g_new(IconStruct,1); |
168 | |
169 | icon_info->pixmap = gdk_pixmap_create_from_xpm(Draw_Context->drawable, |
170 | &icon_info->mask, NULL, Properties->icon_name); |
171 | } |
172 | else |
173 | { |
174 | icon_info = *(value.v_pointer); |
175 | } |
176 | |
177 | gdk_gc_set_clip_mask(Draw_Context->gc, icon_info->mask); |
178 | |
179 | switch(Properties->position) { |
180 | case OVER: |
181 | gdk_gc_set_clip_origin( |
182 | Draw_Context->gc, |
68997a22 |
183 | Draw_Context->current->modify_over->x, |
184 | Draw_Context->current->modify_over->y); |
a56a1ba4 |
185 | gdk_draw_drawable(Draw_Context->drawable, |
186 | Draw_Context->gc, |
187 | icon_info->pixmap, |
188 | 0, 0, |
68997a22 |
189 | Draw_Context->current->modify_over->x, |
190 | Draw_Context->current->modify_over->y, |
a56a1ba4 |
191 | Properties->width, Properties->height); |
192 | |
68997a22 |
193 | Draw_Context->current->modify_over->x += Properties->width; |
a56a1ba4 |
194 | |
195 | break; |
196 | case MIDDLE: |
197 | gdk_gc_set_clip_origin( |
198 | Draw_Context->gc, |
68997a22 |
199 | Draw_Context->current->modify_middle->x, |
200 | Draw_Context->current->modify_middle->y); |
a56a1ba4 |
201 | gdk_draw_drawable(Draw_Context->drawable, |
202 | Draw_Context->gc, |
203 | icon_info->pixmap, |
204 | 0, 0, |
68997a22 |
205 | Draw_Context->current->modify_middle->x, |
206 | Draw_Context->current->modify_middle->y, |
a56a1ba4 |
207 | Properties->width, Properties->height); |
208 | |
68997a22 |
209 | Draw_Context->current->modify_middle->x += Properties->width; |
a56a1ba4 |
210 | break; |
211 | case UNDER: |
212 | gdk_gc_set_clip_origin( |
213 | Draw_Context->gc, |
68997a22 |
214 | Draw_Context->current->modify_under->x, |
215 | Draw_Context->current->modify_under->y); |
a56a1ba4 |
216 | gdk_draw_drawable(Draw_Context->drawable, |
217 | Draw_Context->gc, |
218 | icon_info->pixmap, |
219 | 0, 0, |
68997a22 |
220 | Draw_Context->current->modify_under->x, |
221 | Draw_Context->current->modify_under->y, |
a56a1ba4 |
222 | Properties->width, Properties->height); |
223 | |
68997a22 |
224 | Draw_Context->current->modify_under->x += Properties->width; |
a56a1ba4 |
225 | break; |
226 | } |
227 | |
228 | gdk_gc_set_clip_origin(Draw_Context->gc, 0, 0); |
229 | gdk_gc_set_clip_mask(Draw_Context->gc, NULL); |
230 | |
231 | return 0; |
b782dd11 |
232 | } |
233 | |
4c69e0cc |
234 | gboolean draw_line( void *hook_data, void *call_data) |
b782dd11 |
235 | { |
a56a1ba4 |
236 | PropertiesLine *Properties = (PropertiesLine*)hook_data; |
237 | DrawContext *Draw_Context = (DrawContext*)call_data; |
238 | //GdkGC *gc = gdk_gc_new(Draw_Context->drawable); |
239 | |
240 | //gdk_gc_set_foreground(Draw_Context->gc, Properties->color); |
241 | gdk_gc_set_rgb_fg_color(Draw_Context->gc, Properties->color); |
242 | //gdk_gc_set_foreground(gc, Properties->color); |
243 | gdk_gc_set_line_attributes( Draw_Context->gc, |
244 | Properties->line_width, |
245 | Properties->style, |
246 | GDK_CAP_BUTT, |
247 | GDK_JOIN_MITER); |
248 | |
249 | switch(Properties->position) { |
250 | case OVER: |
251 | drawing_draw_line( |
252 | NULL, Draw_Context->drawable, |
68997a22 |
253 | Draw_Context->previous->over->x, |
254 | Draw_Context->previous->over->y, |
255 | Draw_Context->current->over->x, |
256 | Draw_Context->current->over->y, |
a56a1ba4 |
257 | Draw_Context->gc); |
258 | break; |
259 | case MIDDLE: |
260 | drawing_draw_line( |
261 | NULL, Draw_Context->drawable, |
68997a22 |
262 | Draw_Context->previous->middle->x, |
263 | Draw_Context->previous->middle->y, |
264 | Draw_Context->current->middle->x, |
265 | Draw_Context->current->middle->y, |
a56a1ba4 |
266 | Draw_Context->gc); |
267 | break; |
268 | case UNDER: |
269 | drawing_draw_line( |
270 | NULL, Draw_Context->drawable, |
68997a22 |
271 | Draw_Context->previous->under->x, |
272 | Draw_Context->previous->under->y, |
273 | Draw_Context->current->under->x, |
274 | Draw_Context->current->under->y, |
a56a1ba4 |
275 | Draw_Context->gc); |
276 | |
277 | break; |
278 | } |
279 | |
280 | //gdk_gc_unref(gc); |
281 | |
282 | return 0; |
b782dd11 |
283 | } |
284 | |
4c69e0cc |
285 | gboolean draw_arc( void *hook_data, void *call_data) |
b782dd11 |
286 | { |
a56a1ba4 |
287 | PropertiesArc *Properties = (PropertiesArc*)hook_data; |
288 | DrawContext *Draw_Context = (DrawContext*)call_data; |
289 | |
290 | //gdk_gc_set_foreground(Draw_Context->gc, Properties->color); |
291 | gdk_gc_set_rgb_fg_color(Draw_Context->gc, Properties->color); |
292 | |
293 | switch(Properties->position) { |
294 | case OVER: |
295 | gdk_draw_arc(Draw_Context->drawable, Draw_Context->gc, |
296 | Properties->filled, |
68997a22 |
297 | Draw_Context->current->modify_over->x, |
298 | Draw_Context->current->modify_over->y, |
a56a1ba4 |
299 | Properties->size, Properties->size, 0, 360*64); |
68997a22 |
300 | Draw_Context->current->modify_over->x += Properties->size; |
a56a1ba4 |
301 | break; |
302 | case MIDDLE: |
303 | gdk_draw_arc(Draw_Context->drawable, Draw_Context->gc, |
304 | Properties->filled, |
68997a22 |
305 | Draw_Context->current->modify_middle->x, |
306 | Draw_Context->current->modify_middle->y, |
a56a1ba4 |
307 | Properties->size, Properties->size, 0, 360*64); |
68997a22 |
308 | Draw_Context->current->modify_middle->x += Properties->size; |
a56a1ba4 |
309 | |
310 | break; |
311 | case UNDER: |
312 | gdk_draw_arc(Draw_Context->drawable, Draw_Context->gc, |
313 | Properties->filled, |
68997a22 |
314 | Draw_Context->current->modify_under->x, |
315 | Draw_Context->current->modify_under->y, |
a56a1ba4 |
316 | Properties->size, Properties->size, 0, 360*64); |
68997a22 |
317 | Draw_Context->current->modify_under->x += Properties->size; |
a56a1ba4 |
318 | |
319 | break; |
320 | } |
321 | |
322 | |
323 | return 0; |
b782dd11 |
324 | } |
325 | |
4c69e0cc |
326 | gboolean draw_bg( void *hook_data, void *call_data) |
b782dd11 |
327 | { |
a56a1ba4 |
328 | PropertiesBG *Properties = (PropertiesBG*)hook_data; |
329 | DrawContext *Draw_Context = (DrawContext*)call_data; |
b782dd11 |
330 | |
a56a1ba4 |
331 | //gdk_gc_set_foreground(Draw_Context->gc, Properties->color); |
332 | gdk_gc_set_rgb_fg_color(Draw_Context->gc, Properties->color); |
09e2606f |
333 | |
334 | |
a56a1ba4 |
335 | gdk_draw_rectangle(Draw_Context->drawable, Draw_Context->gc, |
336 | TRUE, |
68997a22 |
337 | Draw_Context->previous->over->x, |
338 | Draw_Context->previous->over->y, |
339 | Draw_Context->current->over->x - Draw_Context->previous->over->x, |
340 | Draw_Context->previous->under->y); |
09e2606f |
341 | |
a56a1ba4 |
342 | return 0; |
b782dd11 |
343 | } |
344 | |
345 | |