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