Code

Simple first pass for rough timing
authorJon A. Cruz <jon@joncruz.org>
Fri, 17 Dec 2010 04:12:30 +0000 (20:12 -0800)
committerJon A. Cruz <jon@joncruz.org>
Fri, 17 Dec 2010 04:12:30 +0000 (20:12 -0800)
src/verbs.cpp
src/widgets/desktop-widget.cpp
src/widgets/icon.cpp

index a218e85dbf7d5359083ebcbbf56e717898bf93ca..c1726ecd412b5bbc46f9b78a0272a85262cefab4 100644 (file)
@@ -2314,7 +2314,7 @@ Verb *Verb::_base_verbs[] = {
     new EditVerb(SP_VERB_EDIT_CLEAR_ALL, "EditClearAll", N_("Clea_r All"),
                  N_("Delete all objects from document"), NULL),
     new EditVerb(SP_VERB_EDIT_SELECT_ALL, "EditSelectAll", N_("Select Al_l"),
-                 N_("Select all objects or all nodes"), GTK_STOCK_SELECT_ALL),
+                 N_("Select all objects or all nodes"), "fooble"),//GTK_STOCK_SELECT_ALL),
     new EditVerb(SP_VERB_EDIT_SELECT_ALL_IN_ALL_LAYERS, "EditSelectAllInAllLayers", N_("Select All in All La_yers"),
                  N_("Select all objects in all visible and unlocked layers"), INKSCAPE_ICON_EDIT_SELECT_ALL_LAYERS),
     new EditVerb(SP_VERB_EDIT_INVERT, "EditInvert", N_("In_vert Selection"),
index 7a3e337ded52557484b94d5f626b51bbe21ae2f3..57e58cd5e4d4795f98c8eb8c9bd3017b7b7353aa 100644 (file)
@@ -121,6 +121,30 @@ static void sp_dtw_sticky_zoom_toggled (GtkMenuItem *item, gpointer data);
 
 SPViewWidgetClass *dtw_parent_class;
 
+static GTimer *baseTimer = 0;
+static bool timeReported = false;
+
+static void timeGoing(gchar const* id)
+{
+    if ( !baseTimer ) {
+        g_message("Starting time at point [%s]", id);
+        baseTimer = g_timer_new();
+    }
+}
+
+static void checkTime(gchar const* msg)
+{
+    if ( baseTimer && !timeReported ) {
+        timeReported = true;
+        g_timer_stop(baseTimer);
+        gulong msCount = 0;
+        gdouble secs = g_timer_elapsed( baseTimer, &msCount );
+        g_message("Time ended at %2.3f with [%s]", secs, msg);
+    }
+}
+
+
+
 class CMSPrefWatcher {
 public:
     CMSPrefWatcher() :
@@ -250,6 +274,7 @@ GType SPDesktopWidget::getType(void)
 {
     static GtkType type = 0;
     if (!type) {
+        timeGoing("SPDesktopWidget::getType");
         GTypeInfo info = {
             sizeof(SPDesktopWidgetClass),
             0, // base_init
@@ -273,6 +298,7 @@ GType SPDesktopWidget::getType(void)
 static void
 sp_desktop_widget_class_init (SPDesktopWidgetClass *klass)
 {
+    timeGoing("sp_desktop_widget_class_init");
     dtw_parent_class = (SPViewWidgetClass*)gtk_type_class (SP_TYPE_VIEW_WIDGET);
 
     GtkObjectClass *object_class = (GtkObjectClass *) klass;
@@ -289,6 +315,7 @@ sp_desktop_widget_class_init (SPDesktopWidgetClass *klass)
  */
 void SPDesktopWidget::init( SPDesktopWidget *dtw )
 {
+    timeGoing("SPDesktopWidget::init");
     GtkWidget *widget;
     GtkWidget *tbl;
     GtkWidget *canvas_tbl;
@@ -564,6 +591,28 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw )
     gtk_widget_show_all (dtw->vbox);
 
     gtk_widget_grab_focus (GTK_WIDGET(dtw->canvas));
+
+    {
+        g_message("FIRE UP");
+
+        gtk_widget_add_events( eventbox, GDK_STRUCTURE_MASK );
+
+        gboolean fooMap(GtkWidget *widget, GdkEvent *event, gpointer userData);
+        g_signal_connect( G_OBJECT(eventbox), "map-event", G_CALLBACK(fooMap), dtw );
+
+        void fooReal(GtkWidget *widget, gpointer userData);
+        g_signal_connect( G_OBJECT(eventbox), "map-event", G_CALLBACK(fooReal), dtw );
+    }
+}
+
+gboolean fooMap(GtkWidget *widget, GdkEvent *event, gpointer userData) {
+    checkTime( "MAP");
+    return FALSE;
+}
+
+void fooReal(GtkWidget *widget, gpointer userData)
+{
+    checkTime("REALIZE");
 }
 
 /**
index 15900d340c1e27969a35cb6d1dba2f2abc78710e..d8d68461440cdd645711b0c514bbe62c62fa1476 100644 (file)
@@ -20,6 +20,7 @@
 #include <glib/gmem.h>
 #include <gtk/gtk.h>
 #include <gtkmm.h>
+#include <gdkmm/pixbuf.h>
 
 #include "path-prefix.h"
 #include "preferences.h"
@@ -542,8 +543,7 @@ static void setupLegacyNaming() {
     legacyNames["zoom"] ="sticky_zoom";
 }
 
-static GtkWidget *
-sp_icon_new_full( Inkscape::IconSize lsize, gchar const *name )
+static GtkWidget *sp_icon_new_full( Inkscape::IconSize lsize, gchar const *name )
 {
     static bool dump = Inkscape::Preferences::get()->getBool("/debug/icons/dumpGtk");
 
@@ -1203,6 +1203,7 @@ bool prerender_icon(gchar const *name, GtkIconSize lsize, unsigned psize)
 {
     bool loadNeeded = false;
     static bool dump = Inkscape::Preferences::get()->getBool("/debug/icons/dumpGtk");
+    static bool useCache = Inkscape::Preferences::get()->getBool("/debug/icons/useCache");
 
     Glib::ustring key = icon_cache_key(name, psize);
     if ( !get_cached_pixbuf(key) ) {
@@ -1211,28 +1212,62 @@ bool prerender_icon(gchar const *name, GtkIconSize lsize, unsigned psize)
             if (dump) {
                 g_message("prerender_icon  [%s] %d:%d", name, lsize, psize);
             }
-            guchar* px = load_svg_pixels(name, lsize, psize);
-            if ( !px ) {
-                // check for a fallback name
-                if ( legacyNames.find(name) != legacyNames.end() ) {
-                    if ( dump ) {
-                        g_message("load_svg_pixels([%s]=%s, %d, %d)", name, legacyNames[name].c_str(), lsize, psize);
+            // In file encoding:
+            std::string iconCacheDir = Glib::build_filename(Glib::build_filename(Glib::get_user_cache_dir(), "inkscape"), "icons");
+            std::string potentialFile = Glib::build_filename( iconCacheDir, name );
+            potentialFile += ".png";
+            
+            bool dataLoaded = false;
+            if ( useCache && Glib::file_test(potentialFile, Glib::FILE_TEST_EXISTS) && Glib::file_test(potentialFile, Glib::FILE_TEST_IS_REGULAR) ) {
+                Glib::RefPtr<Gdk::Pixbuf> pb = Gdk::Pixbuf::create_from_file(potentialFile);
+                if (pb) {
+                    dataLoaded = true;
+                    GdkPixbuf *obj = pb->gobj();
+                    g_object_ref(obj);
+                    pb_cache[key] = obj;
+                    addToIconSet(obj, name, lsize, psize);
+                    loadNeeded = true;
+                    if (internalNames.find(name) == internalNames.end()) {
+                        internalNames.insert(name);
                     }
-                    px = load_svg_pixels(legacyNames[name].c_str(), lsize, psize);
                 }
             }
-            if (px) {
-                GdkPixbuf* pb = gdk_pixbuf_new_from_data( px, GDK_COLORSPACE_RGB, TRUE, 8,
-                                                          psize, psize, psize * 4,
-                                                          reinterpret_cast<GdkPixbufDestroyNotify>(g_free), NULL );
-                pb_cache[key] = pb;
-                addToIconSet(pb, name, lsize, psize);
-                loadNeeded = true;
-                if (internalNames.find(name) == internalNames.end()) {
-                    internalNames.insert(name);
+
+            if (!dataLoaded) {
+                guchar* px = load_svg_pixels(name, lsize, psize);
+                if ( !px ) {
+                    // check for a fallback name
+                    if ( legacyNames.find(name) != legacyNames.end() ) {
+                        if ( dump ) {
+                            g_message("load_svg_pixels([%s]=%s, %d, %d)", name, legacyNames[name].c_str(), lsize, psize);
+                        }
+                        px = load_svg_pixels(legacyNames[name].c_str(), lsize, psize);
+                    }
+                }
+                if (px) {
+                    GdkPixbuf* pb = gdk_pixbuf_new_from_data( px, GDK_COLORSPACE_RGB, TRUE, 8,
+                                                              psize, psize, psize * 4,
+                                                              reinterpret_cast<GdkPixbufDestroyNotify>(g_free), NULL );
+                    pb_cache[key] = pb;
+                    addToIconSet(pb, name, lsize, psize);
+                    loadNeeded = true;
+                    if (internalNames.find(name) == internalNames.end()) {
+                        internalNames.insert(name);
+                    }
+                    if (useCache) {
+                        g_object_ref(pb);
+                        Glib::RefPtr<Gdk::Pixbuf> ppp = Glib::wrap(pb);
+                        try {
+                            ppp->save( potentialFile, "png" );
+                        } catch ( Glib::FileError &ex ) {
+                            g_warning("FileError    [%s]", ex.what().c_str());
+                        } catch ( Gdk::PixbufError &ex ) {
+                            g_warning("PixbufError  [%s]", ex.what().c_str());
+                        }
+                    }
+                } else if (dump) {
+                    g_message("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX  error!!! pixels not found for '%s'", name);
                 }
-            } else if (dump) {
-                g_message("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX  error!!! pixels not found for '%s'", name);
             }
         }
         else if (dump) {
@@ -1249,6 +1284,7 @@ static GdkPixbuf *sp_icon_image_load_svg(gchar const *name, GtkIconSize lsize, u
     // did we already load this icon at this scale/size?
     GdkPixbuf* pb = get_cached_pixbuf(key);
     if (!pb) {
+        g_message("YYYYYYYYYYYYY YYYYYYYYYYYYYYY two load_svg_pixels(%s, %d, %d)", name, lsize, psize);
         guchar *px = load_svg_pixels(name, lsize, psize);
         if (px) {
             pb = gdk_pixbuf_new_from_data(px, GDK_COLORSPACE_RGB, TRUE, 8,