summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1c944f1)
raw | patch | inline | side by side (parent: 1c944f1)
author | Jon A. Cruz <jon@joncruz.org> | |
Sun, 25 Jul 2010 23:55:49 +0000 (16:55 -0700) | ||
committer | Jon A. Cruz <jon@joncruz.org> | |
Sun, 25 Jul 2010 23:55:49 +0000 (16:55 -0700) |
Throttle down icon preview rendering based on observed duration.
src/ui/dialog/icon-preview.cpp | patch | blob | history | |
src/ui/dialog/icon-preview.h | patch | blob | history |
index 0eddfa285d9268949aa0a9ff1249f05336e6797d..c8f5d2c2e43fcbb96dd596bdd66aca3ecd8662b3 100644 (file)
const gchar *name, unsigned int psize );
}
+#define noICON_VERBOSE 1
+
namespace Inkscape {
namespace UI {
namespace Dialog {
desktop(0),
document(0),
timer(0),
+ renderTimer(0),
pending(false),
+ minDelay(0.1),
targetId(),
hot(1),
selectionButton(0),
delete timer;
timer = 0;
}
+ if ( renderTimer ) {
+ renderTimer->stop();
+ delete renderTimer;
+ renderTimer = 0;
+ }
selChangedConn.disconnect();
docModConn.disconnect();
//#########################################################################
+#if ICON_VERBOSE
+static Glib::ustring getTimestr()
+{
+ Glib::ustring str;
+ GTimeVal now = {0, 0};
+ g_get_current_time(&now);
+ glong secs = now.tv_sec % 60;
+ glong mins = (now.tv_sec / 60) % 60;
+ gchar *ptr = g_strdup_printf(":%02ld:%02ld.%06ld", mins, secs, now.tv_usec);
+ str = ptr;
+ g_free(ptr);
+ ptr = 0;
+ return str;
+}
+#endif // ICON_VERBOSE
+
void IconPreviewPanel::setDesktop( SPDesktop* desktop )
{
Panel::setDesktop(desktop);
if (!timer) {
timer = new Glib::Timer();
}
- if (timer->elapsed() < 0.1) {
+ if (timer->elapsed() < minDelay) {
+#if ICON_VERBOSE
+ g_message( "%s Deferring refresh as too soon. calling queueRefresh()", getTimestr().c_str() );
+#endif //ICON_VERBOSE
// Do not refresh too quickly
queueRefresh();
} else if ( desktop ) {
+#if ICON_VERBOSE
+ g_message( "%s Refreshing preview.", getTimestr().c_str() );
+#endif // ICON_VERBOSE
bool hold = Inkscape::Preferences::get()->getBool("/iconpreview/selectionHold", true);
+ SPObject *target = 0;
if ( selectionButton && selectionButton->get_active() )
{
- SPObject *target = (hold && !targetId.empty()) ? desktop->doc()->getObjectById( targetId.c_str() ) : 0;
+ target = (hold && !targetId.empty()) ? desktop->doc()->getObjectById( targetId.c_str() ) : 0;
if ( !target ) {
targetId.clear();
Inkscape::Selection * sel = sp_desktop_selection(desktop);
}
}
}
- if ( target ) {
- renderPreview(target);
- }
} else {
- SPObject *target = desktop->currentRoot();
- if ( target ) {
- renderPreview(target);
- }
+ target = desktop->currentRoot();
}
+ if ( target ) {
+ renderPreview(target);
+ }
+#if ICON_VERBOSE
+ g_message( "%s resetting timer", getTimestr().c_str() );
+#endif // ICON_VERBOSE
timer->reset();
}
}
if (!timer) {
timer = new Glib::Timer();
}
- if ( timer->elapsed() > 0.1 ) {
+ if ( timer->elapsed() > minDelay ) {
+#if ICON_VERBOSE
+ g_message( "%s refreshCB() timer has progressed", getTimestr().c_str() );
+#endif // ICON_VERBOSE
callAgain = false;
refreshPreview();
+#if ICON_VERBOSE
+ g_message( "%s refreshCB() setting pending false", getTimestr().c_str() );
+#endif // ICON_VERBOSE
pending = false;
}
return callAgain;
{
if (!pending) {
pending = true;
+#if ICON_VERBOSE
+ g_message( "%s queueRefresh() Setting pending true", getTimestr().c_str() );
+#endif // ICON_VERBOSE
if (!timer) {
timer = new Glib::Timer();
}
{
SPDocument * doc = SP_OBJECT_DOCUMENT(obj);
gchar const * id = obj->getId();
+ if ( !renderTimer ) {
+ renderTimer = new Glib::Timer();
+ }
+ renderTimer->reset();
-// g_message(" setting up to render '%s' as the icon", id );
+#if ICON_VERBOSE
+ g_message("%s setting up to render '%s' as the icon", getTimestr().c_str(), id );
+#endif // ICON_VERBOSE
NRArenaItem *root = NULL;
sp_item_invoke_hide(SP_ITEM(sp_document_root(doc)), visionkey);
nr_object_unref((NRObject *) arena);
+ renderTimer->stop();
+ minDelay = std::max( 0.1, renderTimer->elapsed() * 3.0 );
+#if ICON_VERBOSE
+ g_message(" render took %f seconds.", renderTimer->elapsed());
+#endif // ICON_VERBOSE
}
void IconPreviewPanel::updateMagnify()
index 0842c3c5eb226de114b9f990b0dc4a6028540382..f8957086aaf4305bfb9a4ddfc2ec74fb752098a9 100644 (file)
SPDesktop *desktop;
SPDocument *document;
Glib::Timer *timer;
+ Glib::Timer *renderTimer;
bool pending;
+ gdouble minDelay;
Gtk::Tooltips tips;