From 9bb1a9c46064f252f98f7232c5d66c0c539d6968 Mon Sep 17 00:00:00 2001 From: dooglus Date: Fri, 12 Oct 2007 14:43:52 +0000 Subject: [PATCH] Improve single-threaded operation. It's now safe(r?) to close a canvas while it's rendering. git-svn-id: http://svn.voria.com/code@913 1f10aa63-cdf2-0310-b900-c93c546f37ac --- synfig-studio/trunk/src/gtkmm/canvasview.cpp | 22 ++++++++++++++++++++-- synfig-studio/trunk/src/gtkmm/canvasview.h | 1 + synfig-studio/trunk/src/gtkmm/workarea.cpp | 17 +++++++++++++++-- synfig-studio/trunk/src/gtkmm/workarea.h | 2 ++ 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/synfig-studio/trunk/src/gtkmm/canvasview.cpp b/synfig-studio/trunk/src/gtkmm/canvasview.cpp index 9f4860e..14419be 100644 --- a/synfig-studio/trunk/src/gtkmm/canvasview.cpp +++ b/synfig-studio/trunk/src/gtkmm/canvasview.cpp @@ -3526,10 +3526,12 @@ static bool _close_instance(etl::handle instance) } bool -CanvasView::on_delete_event(GdkEventAny* event) +CanvasView::close_instance_when_safe() { + if (get_work_area()->get_updating()) + return true; + if(get_instance()->get_visible_canvases()==1) - { // Schedule a close to occur in a few moments Glib::signal_timeout().connect( sigc::bind( @@ -3538,8 +3540,24 @@ CanvasView::on_delete_event(GdkEventAny* event) ) ,250 ); + + return false; +} + +bool +CanvasView::on_delete_event(GdkEventAny* event) +{ + if (get_work_area()->get_updating()) + { + get_work_area()->stop_updating(true); // stop and mark as cancelled + + // give the workarea chances to stop updating + Glib::signal_timeout().connect(sigc::mem_fun(*this, &CanvasView::close_instance_when_safe) ,250); + return true; } + close_instance_when_safe(); + //! \todo This causes the window to be deleted straight away - but what if we prompt 'save?' and the user cancels? // Is there ever any need to pass on the delete event to the window here? // if(event) return Gtk::Window::on_delete_event(event); diff --git a/synfig-studio/trunk/src/gtkmm/canvasview.h b/synfig-studio/trunk/src/gtkmm/canvasview.h index b934fd4..f1c1d78 100644 --- a/synfig-studio/trunk/src/gtkmm/canvasview.h +++ b/synfig-studio/trunk/src/gtkmm/canvasview.h @@ -678,6 +678,7 @@ private: bool on_audio_scrub(); protected: + bool close_instance_when_safe(); bool on_delete_event(GdkEventAny* event); /* diff --git a/synfig-studio/trunk/src/gtkmm/workarea.cpp b/synfig-studio/trunk/src/gtkmm/workarea.cpp index 54216f3..abdf30c 100644 --- a/synfig-studio/trunk/src/gtkmm/workarea.cpp +++ b/synfig-studio/trunk/src/gtkmm/workarea.cpp @@ -810,6 +810,19 @@ WorkArea::~WorkArea() render_idle_func_id=0; } +bool +WorkArea::get_updating()const +{ + return App::single_threaded && async_renderer && async_renderer->updating == true; +} + +void +WorkArea::stop_updating(bool cancel) +{ + async_renderer->stop(); + if (cancel) canceled_=true; +} + void WorkArea::save_meta_data() { @@ -2174,9 +2187,9 @@ public: bool studio::WorkArea::async_update_preview() { - if (single_threaded() && async_renderer && async_renderer->updating == true) + if (get_updating()) { - async_renderer->stop(); + stop_updating(); return false; } diff --git a/synfig-studio/trunk/src/gtkmm/workarea.h b/synfig-studio/trunk/src/gtkmm/workarea.h index 3b6ecae..8769789 100644 --- a/synfig-studio/trunk/src/gtkmm/workarea.h +++ b/synfig-studio/trunk/src/gtkmm/workarea.h @@ -258,6 +258,8 @@ public: bool get_canceled()const { return canceled_; } bool get_queued()const { return queued; } bool get_rendering()const { return rendering; } + bool get_updating()const; + void stop_updating(bool cancel = false); bool get_full_frame()const { return full_frame; } //int get_w()const { return w; } //int get_h()const { return h; } -- 2.7.4