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 | |
b782dd11 |
93 | /* Drawing hook functions */ |
4c69e0cc |
94 | gboolean draw_text( void *hook_data, void *call_data) |
b782dd11 |
95 | { |
96 | PropertiesText *Properties = (PropertiesText*)hook_data; |
97 | DrawContext *Draw_Context = (DrawContext*)call_data; |
09e2606f |
98 | |
99 | PangoContext *context; |
100 | PangoLayout *layout; |
50439712 |
101 | PangoAttribute *attribute; |
102 | PangoAttrList* attrib_list;// = pango_attr_list_new(); |
09e2606f |
103 | PangoFontDescription *FontDesc;// = pango_font_description_new(); |
104 | gint Font_Size; |
105 | PangoRectangle ink_rect; |
106 | |
50439712 |
107 | //gdk_gc_set_foreground(Draw_Context->gc, Properties->foreground); |
108 | //gdk_gc_set_background(Draw_Context->gc, Properties->background); |
09e2606f |
109 | |
34b04882 |
110 | layout = Draw_Context->pango_layout; |
09e2606f |
111 | context = pango_layout_get_context(layout); |
112 | FontDesc = pango_context_get_font_description(context); |
50439712 |
113 | attrib_list = pango_layout_get_attributes(layout); |
114 | if(attrib_list == NULL) |
115 | { |
116 | attrib_list = pango_attr_list_new(); |
117 | } |
09e2606f |
118 | pango_font_description_set_size(FontDesc, Properties->size*PANGO_SCALE); |
50439712 |
119 | pango_layout_context_changed(layout); |
120 | |
121 | attribute = pango_attr_foreground_new(Properties->foreground->red, |
122 | Properties->foreground->green, |
123 | Properties->foreground->blue); |
124 | //pango_attr_list_change(attrib_list, attribute); |
125 | pango_attr_list_change(attrib_list, attribute); |
126 | //pango_attribute_destroy(attribute); |
127 | attribute = pango_attr_background_new(Properties->background->red, |
128 | Properties->background->green, |
129 | Properties->background->blue); |
130 | pango_attr_list_change(attrib_list, attribute); |
131 | pango_layout_set_attributes(layout, attrib_list); |
132 | |
133 | //pango_attr_list_unref(attrib_list); |
134 | |
09e2606f |
135 | pango_layout_set_text(layout, Properties->Text, -1); |
136 | pango_layout_get_pixel_extents(layout, &ink_rect, NULL); |
50439712 |
137 | pango_layout_context_changed(layout); |
09e2606f |
138 | switch(Properties->position) { |
139 | case OVER: |
140 | gdk_draw_layout(Draw_Context->drawable, Draw_Context->gc, |
141 | Draw_Context->Current->modify_over->x, |
142 | Draw_Context->Current->modify_over->y, |
143 | layout); |
144 | Draw_Context->Current->modify_over->x += ink_rect.width; |
145 | |
146 | break; |
147 | case MIDDLE: |
148 | gdk_draw_layout(Draw_Context->drawable, Draw_Context->gc, |
149 | Draw_Context->Current->modify_middle->x, |
150 | Draw_Context->Current->modify_middle->y, |
151 | layout); |
152 | Draw_Context->Current->modify_middle->x += ink_rect.width; |
153 | break; |
154 | case UNDER: |
155 | gdk_draw_layout(Draw_Context->drawable, Draw_Context->gc, |
156 | Draw_Context->Current->modify_under->x, |
157 | Draw_Context->Current->modify_under->y, |
158 | layout); |
159 | Draw_Context->Current->modify_under->x += ink_rect.width; |
160 | break; |
161 | } |
162 | |
09e2606f |
163 | return 0; |
b782dd11 |
164 | } |
165 | |
1a31868c |
166 | |
167 | /* To speed up the process, search in already loaded icons list first. Only |
168 | * load it if not present. |
169 | */ |
4c69e0cc |
170 | gboolean draw_icon( void *hook_data, void *call_data) |
b782dd11 |
171 | { |
172 | PropertiesIcon *Properties = (PropertiesIcon*)hook_data; |
173 | DrawContext *Draw_Context = (DrawContext*)call_data; |
174 | |
1a31868c |
175 | LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); |
176 | LttvAttributeValue value; |
177 | gchar icon_name[MAX_PATH_LEN] = "icons/"; |
178 | IconStruct *icon_info; |
8d088fb2 |
179 | |
1a31868c |
180 | strcat(icon_name, Properties->icon_name); |
181 | |
182 | g_assert(lttv_iattribute_find_by_path(attributes, icon_name, |
183 | LTTV_POINTER, &value)); |
184 | if(*(value.v_pointer) == NULL) |
185 | { |
186 | *(value.v_pointer) = icon_info = g_new(IconStruct,1); |
187 | |
188 | icon_info->pixmap = gdk_pixmap_create_from_xpm(Draw_Context->drawable, |
189 | &icon_info->mask, NULL, Properties->icon_name); |
190 | } |
191 | else |
192 | { |
193 | icon_info = *(value.v_pointer); |
194 | } |
195 | |
196 | gdk_gc_set_clip_mask(Draw_Context->gc, icon_info->mask); |
197 | |
09e2606f |
198 | switch(Properties->position) { |
199 | case OVER: |
1a31868c |
200 | gdk_gc_set_clip_origin( |
201 | Draw_Context->gc, |
202 | Draw_Context->Current->modify_over->x, |
203 | Draw_Context->Current->modify_over->y); |
09e2606f |
204 | gdk_draw_drawable(Draw_Context->drawable, |
1a31868c |
205 | Draw_Context->gc, |
206 | icon_info->pixmap, |
09e2606f |
207 | 0, 0, |
208 | Draw_Context->Current->modify_over->x, |
209 | Draw_Context->Current->modify_over->y, |
210 | Properties->width, Properties->height); |
211 | |
212 | Draw_Context->Current->modify_over->x += Properties->width; |
213 | |
214 | break; |
215 | case MIDDLE: |
1a31868c |
216 | gdk_gc_set_clip_origin( |
217 | Draw_Context->gc, |
218 | Draw_Context->Current->modify_middle->x, |
219 | Draw_Context->Current->modify_middle->y); |
09e2606f |
220 | gdk_draw_drawable(Draw_Context->drawable, |
1a31868c |
221 | Draw_Context->gc, |
222 | icon_info->pixmap, |
09e2606f |
223 | 0, 0, |
224 | Draw_Context->Current->modify_middle->x, |
225 | Draw_Context->Current->modify_middle->y, |
226 | Properties->width, Properties->height); |
227 | |
09e2606f |
228 | Draw_Context->Current->modify_middle->x += Properties->width; |
229 | break; |
230 | case UNDER: |
1a31868c |
231 | gdk_gc_set_clip_origin( |
232 | Draw_Context->gc, |
233 | Draw_Context->Current->modify_under->x, |
234 | Draw_Context->Current->modify_under->y); |
09e2606f |
235 | gdk_draw_drawable(Draw_Context->drawable, |
1a31868c |
236 | Draw_Context->gc, |
237 | icon_info->pixmap, |
09e2606f |
238 | 0, 0, |
239 | Draw_Context->Current->modify_under->x, |
240 | Draw_Context->Current->modify_under->y, |
241 | Properties->width, Properties->height); |
242 | |
243 | Draw_Context->Current->modify_under->x += Properties->width; |
244 | break; |
245 | } |
246 | |
1a31868c |
247 | gdk_gc_set_clip_origin(Draw_Context->gc, 0, 0); |
248 | gdk_gc_set_clip_mask(Draw_Context->gc, NULL); |
09e2606f |
249 | |
250 | return 0; |
b782dd11 |
251 | } |
252 | |
4c69e0cc |
253 | gboolean draw_line( void *hook_data, void *call_data) |
b782dd11 |
254 | { |
255 | PropertiesLine *Properties = (PropertiesLine*)hook_data; |
256 | DrawContext *Draw_Context = (DrawContext*)call_data; |
257 | |
09e2606f |
258 | gdk_gc_set_foreground(Draw_Context->gc, Properties->color); |
259 | gdk_gc_set_line_attributes( Draw_Context->gc, |
260 | Properties->line_width, |
261 | Properties->style, |
262 | GDK_CAP_BUTT, |
263 | GDK_JOIN_MITER); |
264 | |
265 | switch(Properties->position) { |
266 | case OVER: |
267 | drawing_draw_line( |
268 | NULL, Draw_Context->drawable, |
269 | Draw_Context->Previous->over->x, |
270 | Draw_Context->Previous->over->y, |
271 | Draw_Context->Current->over->x, |
272 | Draw_Context->Current->over->y, |
273 | Draw_Context->gc); |
274 | break; |
275 | case MIDDLE: |
276 | drawing_draw_line( |
277 | NULL, Draw_Context->drawable, |
278 | Draw_Context->Previous->middle->x, |
279 | Draw_Context->Previous->middle->y, |
280 | Draw_Context->Current->middle->x, |
281 | Draw_Context->Current->middle->y, |
282 | Draw_Context->gc); |
283 | break; |
284 | case UNDER: |
285 | drawing_draw_line( |
286 | NULL, Draw_Context->drawable, |
287 | Draw_Context->Previous->under->x, |
288 | Draw_Context->Previous->under->y, |
289 | Draw_Context->Current->under->x, |
290 | Draw_Context->Current->under->y, |
291 | Draw_Context->gc); |
292 | |
293 | break; |
294 | } |
295 | |
296 | return 0; |
b782dd11 |
297 | } |
298 | |
4c69e0cc |
299 | gboolean draw_arc( void *hook_data, void *call_data) |
b782dd11 |
300 | { |
301 | PropertiesArc *Properties = (PropertiesArc*)hook_data; |
302 | DrawContext *Draw_Context = (DrawContext*)call_data; |
303 | |
09e2606f |
304 | gdk_gc_set_foreground(Draw_Context->gc, Properties->color); |
305 | |
306 | switch(Properties->position) { |
307 | case OVER: |
308 | gdk_draw_arc(Draw_Context->drawable, Draw_Context->gc, |
309 | Properties->filled, |
310 | Draw_Context->Current->modify_over->x, |
311 | Draw_Context->Current->modify_over->y, |
312 | Properties->size, Properties->size, 0, 360*64); |
313 | Draw_Context->Current->modify_over->x += Properties->size; |
09e2606f |
314 | break; |
315 | case MIDDLE: |
316 | gdk_draw_arc(Draw_Context->drawable, Draw_Context->gc, |
317 | Properties->filled, |
318 | Draw_Context->Current->modify_middle->x, |
319 | Draw_Context->Current->modify_middle->y, |
320 | Properties->size, Properties->size, 0, 360*64); |
321 | Draw_Context->Current->modify_middle->x += Properties->size; |
322 | |
323 | break; |
324 | case UNDER: |
325 | gdk_draw_arc(Draw_Context->drawable, Draw_Context->gc, |
326 | Properties->filled, |
327 | Draw_Context->Current->modify_under->x, |
328 | Draw_Context->Current->modify_under->y, |
329 | Properties->size, Properties->size, 0, 360*64); |
330 | Draw_Context->Current->modify_under->x += Properties->size; |
331 | |
332 | break; |
333 | } |
334 | |
335 | |
336 | return 0; |
b782dd11 |
337 | } |
338 | |
4c69e0cc |
339 | gboolean draw_bg( void *hook_data, void *call_data) |
b782dd11 |
340 | { |
341 | PropertiesBG *Properties = (PropertiesBG*)hook_data; |
342 | DrawContext *Draw_Context = (DrawContext*)call_data; |
343 | |
09e2606f |
344 | gdk_gc_set_foreground(Draw_Context->gc, Properties->color); |
345 | |
346 | |
347 | gdk_draw_rectangle(Draw_Context->drawable, Draw_Context->gc, |
348 | TRUE, |
349 | Draw_Context->Previous->over->x, |
350 | Draw_Context->Previous->over->y, |
351 | Draw_Context->Current->over->x - Draw_Context->Previous->over->x, |
352 | Draw_Context->Previous->under->y); |
353 | |
354 | return 0; |
b782dd11 |
355 | } |
356 | |
357 | |