heavy icon drawing sample
authorcompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Wed, 7 Jan 2004 02:34:18 +0000 (02:34 +0000)
committercompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Wed, 7 Jan 2004 02:34:18 +0000 (02:34 +0000)
git-svn-id: http://ltt.polymtl.ca/svn@355 04897980-b3bd-0310-b5e0-8ef037075253

ltt/branches/poly/lttv/modules/guiControlFlow/Draw_Item.c
ltt/branches/poly/lttv/modules/guiControlFlow/Draw_Item.h
ltt/branches/poly/lttv/modules/guiControlFlow/Event_Hooks.c

index c02725be7807ffa01086b95803e85b104ee16ce4..70befcc4005a93308be4a29faefaa5d7cf41a4d3 100644 (file)
@@ -68,7 +68,8 @@
  * We use the lttv global attributes to keep track of the loaded icons.
  * If we need an icon, we look for it in the icons / icon name pathname.
  * If found, we use the pointer to it. If not, we load the pixmap in
- * memory and set the pointer to the GdkPixmap in the attributes.
+ * memory and set the pointer to the GdkPixmap in the attributes. The
+ * structure pointed to contains the pixmap and the mask bitmap.
  * 
  * Author : Mathieu Desnoyers, October 2003
  */
 #include <lttv/hook.h>
 #include <lttv/attribute.h>
 #include <lttv/iattribute.h>
+#include <string.h>
 
 #include <lttv/processTrace.h>
 #include <lttv/state.h>
 
 #include "Draw_Item.h"
+
+
+#define MAX_PATH_LEN 256
+
 /* The DrawContext keeps information about the current drawing position and
  * the previous one, so we can use both to draw lines.
  *
  * the modify_* are used to take into account that we should go forward
  * when we draw a text, an arc or an icon, while it's unneeded when we
  * draw a line or background.
+ *
  */
 struct _DrawContext {
        GdkDrawable     *drawable;
        GdkGC           *gc;
+       
 
        DrawInfo        *Current;
        DrawInfo        *Previous;
@@ -137,6 +144,14 @@ struct _ItemInfo {
        LttvTracefileState      *tfs;
 };
 
+/*
+ * Structure used to keep information about icons.
+ */
+struct _IconStruct {
+       GdkPixmap *pixmap;
+       GdkBitmap *mask;
+};
+
 
 /*
  * The Item element is only used so the DrawOperation is modifiable by users.
@@ -263,26 +278,47 @@ gboolean draw_text( void *hook_data, void *call_data)
        return 0;
 }
 
+
+/* To speed up the process, search in already loaded icons list first. Only
+ * load it if not present.
+ */
 gboolean draw_icon( void *hook_data, void *call_data)
 {
        PropertiesIcon *Properties = (PropertiesIcon*)hook_data;
        DrawContext *Draw_Context = (DrawContext*)call_data;
 
-       GdkBitmap *mask = g_new(GdkBitmap, 1);
-       GdkPixmap *icon_pixmap = g_new(GdkPixmap, 1);
-       GdkGC *gc = gdk_gc_new(Draw_Context->drawable);
-       gdk_gc_copy(gc, Draw_Context->gc);
-
-       icon_pixmap = gdk_pixmap_create_from_xpm(Draw_Context->drawable, &mask, NULL,
-                                                                                                                                                                               Properties->icon_name);
-
-       gdk_gc_set_clip_mask(gc, mask);
-
+  LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
+       LttvAttributeValue value;
+       gchar icon_name[MAX_PATH_LEN] = "icons/";
+       IconStruct *icon_info;
+       
+       strcat(icon_name, Properties->icon_name);
+       
+  g_assert(lttv_iattribute_find_by_path(attributes, icon_name,
+      LTTV_POINTER, &value));
+       if(*(value.v_pointer) == NULL)
+       {
+       *(value.v_pointer) = icon_info = g_new(IconStruct,1);
+               
+               icon_info->pixmap = gdk_pixmap_create_from_xpm(Draw_Context->drawable,
+                                                                                                       &icon_info->mask, NULL, Properties->icon_name);
+       }
+       else
+       {
+               icon_info = *(value.v_pointer);
+       }
+       
+       gdk_gc_set_clip_mask(Draw_Context->gc, icon_info->mask);
+       
        switch(Properties->position) {
                case OVER:
+                                                       gdk_gc_set_clip_origin(
+                                                                       Draw_Context->gc,
+                                                                       Draw_Context->Current->modify_over->x,
+                                                                       Draw_Context->Current->modify_over->y);
                                                        gdk_draw_drawable(Draw_Context->drawable, 
-                                                                       gc,
-                                                                       icon_pixmap,
+                                                                       Draw_Context->gc,
+                                                                       icon_info->pixmap,
                                                                        0, 0,
                                                                        Draw_Context->Current->modify_over->x,
                                                                        Draw_Context->Current->modify_over->y,
@@ -292,21 +328,28 @@ gboolean draw_icon( void *hook_data, void *call_data)
 
                        break;
                case MIDDLE:
+                                                       gdk_gc_set_clip_origin(
+                                                                       Draw_Context->gc,
+                                                                       Draw_Context->Current->modify_middle->x,
+                                                                       Draw_Context->Current->modify_middle->y);
                                                        gdk_draw_drawable(Draw_Context->drawable, 
-                                                                       gc,
-                                                                       icon_pixmap,
+                                                                       Draw_Context->gc,
+                                                                       icon_info->pixmap,
                                                                        0, 0,
                                                                        Draw_Context->Current->modify_middle->x,
                                                                        Draw_Context->Current->modify_middle->y,
                                                                        Properties->width, Properties->height);
 
-
                                                        Draw_Context->Current->modify_middle->x += Properties->width;
                        break;
                case UNDER:
+                                                       gdk_gc_set_clip_origin(
+                                                                       Draw_Context->gc,
+                                                                       Draw_Context->Current->modify_under->x,
+                                                                       Draw_Context->Current->modify_under->y);
                                                        gdk_draw_drawable(Draw_Context->drawable, 
-                                                                       gc,
-                                                                       icon_pixmap,
+                                                                       Draw_Context->gc,
+                                                                       icon_info->pixmap,
                                                                        0, 0,
                                                                        Draw_Context->Current->modify_under->x,
                                                                        Draw_Context->Current->modify_under->y,
@@ -316,7 +359,8 @@ gboolean draw_icon( void *hook_data, void *call_data)
                        break;
        }
 
-       g_free(gc);
+       gdk_gc_set_clip_origin(Draw_Context->gc, 0, 0);
+       gdk_gc_set_clip_mask(Draw_Context->gc, NULL);
        
        return 0;
 }
index 5e6311fbe512e23fadce6d990f465dbf75ddc4f5..6e5f5eb5cd2bfcdacc07531c941d4293757b3393 100644 (file)
@@ -5,6 +5,8 @@ typedef struct _DrawContext DrawContext;
 typedef struct _DrawInfo DrawInfo;
 typedef struct _ItemInfo ItemInfo;
 
+typedef struct _IconStruct IconStruct;
+
 typedef struct _DrawOperation DrawOperation;
 
 
index a268bf2284a1f306aaa28367a4add63b2e820f62..e04a72b05aff075733728482819b0e64ba5ec96f 100644 (file)
 #include "Drawing.h"
 #include "CFV-private.h"
 
+#define MAX_PATH_LEN 256
+
+//FIXME : remove this include when tests finished.
+#include "Draw_Item.h"
+#include <string.h>
+
+struct _DrawContext {
+       GdkDrawable     *drawable;
+       GdkGC           *gc;
+       
+
+       DrawInfo        *Current;
+       DrawInfo        *Previous;
+};
+
+struct _DrawInfo {
+       ItemInfo        *over;
+       ItemInfo        *middle;
+       ItemInfo        *under;
+       
+       ItemInfo        *modify_over;
+       ItemInfo        *modify_middle;
+       ItemInfo        *modify_under;
+};
+
+/* LttvExecutionState is accessible through the LttvTracefileState. Is has
+ * a pointer to the LttvProcessState which points to the top of stack
+ * execution state : LttvExecutionState *state.
+ *
+ * LttvExecutionState contains (useful here):
+ * LttvExecutionMode t,
+ * LttvExecutionSubmode n,
+ * LttvProcessStatus s
+ * 
+ *
+ * LttvTraceState will be used in the case we need the string of the
+ * different processes, eventtype_names, syscall_names, trap_names, irq_names.
+ *
+ * LttvTracefileState also gives the cpu_name and, as it herits from
+ * LttvTracefileContext, it gives the LttEvent structure, which is needed
+ * to get facility name and event name.
+ */
+struct _ItemInfo {
+       gint    x, y;
+       LttvTraceState          *ts;
+       LttvTracefileState      *tfs;
+};
+
+
+
+struct _PropertiesIcon {
+       gchar           *icon_name;
+       gint            width;
+       gint            height;
+       RelPos          position;
+};
+
+
+
+void test_draw_item(Drawing_t *Drawing,
+                       GdkPixmap *Pixmap) 
+{
+       PropertiesIcon properties_icon;
+       DrawContext draw_context;
+       
+       DrawInfo current, previous;
+       ItemInfo over, middle, under, modify_over, modify_middle, modify_under;
+
+       int i,j;
+       
+       for(i=0; i<1024;i=i+15)
+       {
+               for(j=0;j<768;j=j+15)
+               {
+                       over.x = i;
+                       over.y = j;
+                       over.ts =  NULL;
+                       over.tfs = NULL;
+
+                       current.modify_over = &over;
+       
+                       draw_context.drawable = Pixmap;
+                       draw_context.gc = Drawing->Drawing_Area_V->style->black_gc;
+
+                       draw_context.Current = &current;
+                       draw_context.Previous = NULL;
+       
+                       properties_icon.icon_name = g_new(char, MAX_PATH_LEN);
+                       strncpy(properties_icon.icon_name, 
+                               "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/mini-display.xpm",
+                               MAX_PATH_LEN);
+                       properties_icon.width = -1;
+                       properties_icon.height = -1;
+                       properties_icon.position = OVER;
+       
+                       draw_icon(&properties_icon, &draw_context);
+               }
+       }
+
+}
 
 /* NOTE : no drawing data should be sent there, since the drawing widget
  * has not been initialized */
@@ -32,7 +132,7 @@ void send_test_drawing(ProcessList *Process_List,
                        gint width,
                        gint height) // height won't be used here ?
 {
-       int i;
+       int i,j;
        ProcessInfo Process_Info = {10000, 12000, 55600};
        //ProcessInfo Process_Info = {156, 14000, 55500};
        GtkTreeRowReference *got_RowRef;
@@ -95,21 +195,6 @@ void send_test_drawing(ProcessList *Process_List,
                y+(height/2), x + width, y+(height/2),
                Drawing->Drawing_Area_V->style->black_gc);
 
-
-       /* Draw icon */
-       icon_pixmap = gdk_pixmap_create_from_xpm(Pixmap, &mask, NULL,
-//                             "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/move_message.xpm");
-                               "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/mini-display.xpm");
-       gdk_gc_copy(gc, Drawing->Drawing_Area_V->style->black_gc);
-       gdk_gc_set_clip_mask(gc, mask);
-       gdk_draw_drawable(Pixmap, 
-                       gc,
-                       icon_pixmap,
-                       0, 0, 0, 0, -1, -1);
-       
-       g_free(icon_pixmap);
-       g_free(mask);
-
        g_info("y : %u, height : %u", y, height);
 
        
@@ -179,6 +264,42 @@ void send_test_drawing(ProcessList *Process_List,
                Drawing->Drawing_Area_V->style->black_gc);
 
        g_info("y : %u, height : %u", y, height);
+       
+
+       /* IMPORTANT : This action uses the cpu heavily! */
+       //icon_pixmap = gdk_pixmap_create_from_xpm(Pixmap, &mask, NULL,
+//                             "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/move_message.xpm");
+       //                              "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/mini-display.xpm");
+
+       //              gdk_gc_set_clip_mask(Drawing->Drawing_Area_V->style->black_gc, mask);
+
+//     for(i=x;i<x+width;i=i+15)
+//     {
+//             for(j=0;j<height*20;j=j+15)
+//             {
+                       
+                       /* Draw icon */
+                       //gdk_gc_copy(gc, Drawing->Drawing_Area_V->style->black_gc);
+//                     gdk_gc_set_clip_origin(Drawing->Drawing_Area_V->style->black_gc, i, j);
+//                     gdk_draw_drawable(Pixmap, 
+//                                     Drawing->Drawing_Area_V->style->black_gc,
+//                                     icon_pixmap,
+//                                     0, 0, i, j, -1, -1);
+
+//             }
+//     }
+       
+       test_draw_item(Drawing,Pixmap);
+       
+       //gdk_gc_set_clip_origin(Drawing->Drawing_Area_V->style->black_gc, 0, 0);
+       //gdk_gc_set_clip_mask(Drawing->Drawing_Area_V->style->black_gc, NULL);
+
+       //g_free(icon_pixmap);
+       //g_free(mask);
+
+
+
+
 
 
        pango_font_description_set_size(FontDesc, Font_Size);
This page took 0.029266 seconds and 4 git commands to generate.