X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-studio%2Ftrunk%2Fsrc%2Fgtkmm%2Fasyncrenderer.cpp;h=72a286c92a56c1dfb5d7009284288a61d6de07d9;hb=9459638ad6797b8139f1e9f0715c96076dbf0890;hp=b2de0872913c5546cc561ef07892b8ef7a2ad4f8;hpb=ce408de81ca266b1f334ee9bc6c8fb7ba1492ed4;p=synfig.git diff --git a/synfig-studio/trunk/src/gtkmm/asyncrenderer.cpp b/synfig-studio/trunk/src/gtkmm/asyncrenderer.cpp index b2de087..72a286c 100644 --- a/synfig-studio/trunk/src/gtkmm/asyncrenderer.cpp +++ b/synfig-studio/trunk/src/gtkmm/asyncrenderer.cpp @@ -2,10 +2,11 @@ /*! \file asyncrenderer.cpp ** \brief Template File ** -** $Id: asyncrenderer.cpp,v 1.5 2005/01/12 07:03:42 darco Exp $ +** $Id$ ** ** \legal ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** Copyright (c) 2007 Chris Moore ** ** This package is free software; you can redistribute it and/or ** modify it under the terms of the GNU General Public License as @@ -30,6 +31,7 @@ #endif #include "asyncrenderer.h" +#include "app.h" #include #include @@ -52,6 +54,8 @@ #include #include +#include "general.h" + #endif /* === U S I N G =========================================================== */ @@ -75,7 +79,7 @@ class AsyncTarget_Tile : public synfig::Target_Tile { public: etl::handle warm_target; - + struct tile_t { Surface surface; @@ -88,15 +92,15 @@ public: }; std::list tile_queue; Glib::Mutex mutex; - + #ifndef GLIB_DISPATCHER_BROKEN Glib::Dispatcher tile_ready_signal; #endif Glib::Cond cond_tile_queue_empty; bool alive_flag; - + sigc::connection ready_connection; - + public: AsyncTarget_Tile(etl::handle warm_target): warm_target(warm_target) @@ -115,7 +119,7 @@ public: ready_connection=tile_ready_signal.connect(sigc::mem_fun(*this,&AsyncTarget_Tile::tile_ready)); #endif } - + ~AsyncTarget_Tile() { ready_connection.disconnect(); @@ -125,17 +129,17 @@ public: Glib::Mutex::Lock lock(mutex); alive_flag=false; } - + virtual int total_tiles()const { return warm_target->total_tiles(); } - + virtual int next_tile(int& x, int& y) { if(!alive_flag) return 0; - + return warm_target->next_tile(x,y); } @@ -145,14 +149,14 @@ public: return 0; return warm_target->next_frame(time); } - + virtual bool start_frame(synfig::ProgressCallback *cb=0) { if(!alive_flag) return false; return warm_target->start_frame(cb); } - + virtual bool add_tile(const synfig::Surface &surface, int gx, int gy) { assert(surface); @@ -174,7 +178,7 @@ public: tile_ready_signal(); #endif } - + return alive_flag; } @@ -190,9 +194,16 @@ public: while(!tile_queue.empty() && alive_flag) { tile_t& tile(tile_queue.front()); - + + if (getenv("SYNFIG_SHOW_TILE_OUTLINES")) + { + Color red(1,0,0); + tile.surface.fill(red, 0, 0, 1, tile.surface.get_h()); + tile.surface.fill(red, 0, 0, tile.surface.get_w(), 1); + } + alive_flag=warm_target->add_tile(tile.surface,tile.x,tile.y); - + tile_queue.pop_front(); } cond_tile_queue_empty.signal(); @@ -200,17 +211,24 @@ public: virtual void end_frame() { - while(alive_flag) +#ifdef SINGLE_THREADED + if (!single_threaded()) { - Glib::Mutex::Lock lock(mutex); - if(!tile_queue.empty() && alive_flag) +#endif + while(alive_flag) { - if(cond_tile_queue_empty.timed_wait(mutex,Glib::TimeVal(0,BOREDOM_TIMEOUT))) + Glib::Mutex::Lock lock(mutex); + if(!tile_queue.empty() && alive_flag) + { + if(cond_tile_queue_empty.timed_wait(mutex,Glib::TimeVal(0,BOREDOM_TIMEOUT))) + break; + } + else break; } - else - break; +#ifdef SINGLE_THREADED } +#endif Glib::Mutex::Lock lock(mutex); if(!alive_flag) return; @@ -224,12 +242,12 @@ class AsyncTarget_Scanline : public synfig::Target_Scanline { public: etl::handle warm_target; - + int scanline_; Surface surface; Glib::Mutex mutex; - + #ifndef GLIB_DISPATCHER_BROKEN Glib::Dispatcher frame_ready_signal; #endif @@ -255,7 +273,7 @@ public: #endif surface.set_wh(warm_target->rend_desc().get_w(),warm_target->rend_desc().get_h()); } - + ~AsyncTarget_Scanline() { ready_connection.disconnect(); @@ -274,12 +292,12 @@ public: Glib::Mutex::Lock lock(mutex); alive_flag=false; } - - virtual bool start_frame(synfig::ProgressCallback *cb=0) - { + + virtual bool start_frame(synfig::ProgressCallback */*cb*/=0) + { return alive_flag; } - + virtual void end_frame() { { @@ -300,24 +318,29 @@ public: #else frame_ready_signal(); #endif - } - - while(alive_flag && !ready_next) - { - Glib::Mutex::Lock lock(mutex); - if(cond_frame_queue_empty.timed_wait(mutex,Glib::TimeVal(0,BOREDOM_TIMEOUT))) - break; } + +#ifdef SINGLE_THREADED + if (single_threaded()) + signal_progress()(); + else +#endif + while(alive_flag && !ready_next) + { + Glib::Mutex::Lock lock(mutex); + if(cond_frame_queue_empty.timed_wait(mutex,Glib::TimeVal(0,BOREDOM_TIMEOUT))) + break; + } } - + virtual Color * start_scanline(int scanline) { Glib::Mutex::Lock lock(mutex); return surface[scanline]; } - + virtual bool end_scanline() { return alive_flag; @@ -328,7 +351,10 @@ public: Glib::Mutex::Lock lock(mutex); if(alive_flag) alive_flag=warm_target->add_frame(&surface); - cond_frame_queue_empty.signal(); +#ifdef SINGLE_THREADED + if (!single_threaded()) +#endif + cond_frame_queue_empty.signal(); ready_next=true; } }; @@ -343,6 +369,9 @@ AsyncRenderer::AsyncRenderer(etl::handle target_,synfig::Progres error(false), success(false), cb(cb) +#ifdef SINGLE_THREADED + , updating(false) +#endif { render_thread=0; if(etl::handle::cast_dynamic(target_)) @@ -350,9 +379,9 @@ AsyncRenderer::AsyncRenderer(etl::handle target_,synfig::Progres etl::handle wrap_target( new AsyncTarget_Tile(etl::handle::cast_dynamic(target_)) ); - + signal_stop_.connect(sigc::mem_fun(*wrap_target,&AsyncTarget_Tile::set_dead)); - + target=wrap_target; } else if(etl::handle::cast_dynamic(target_)) @@ -362,9 +391,9 @@ AsyncRenderer::AsyncRenderer(etl::handle target_,synfig::Progres etl::handle::cast_dynamic(target_) ) ); - + signal_stop_.connect(sigc::mem_fun(*wrap_target,&AsyncTarget_Scanline::set_dead)); - + target=wrap_target; } } @@ -381,23 +410,26 @@ AsyncRenderer::stop() { Glib::Mutex::Lock lock(mutex); done_connection.disconnect(); - + if(render_thread) { signal_stop_(); - + #if REJOIN_ON_STOP - render_thread->join(); +#ifdef SINGLE_THREADED + if (!single_threaded()) #endif - + render_thread->join(); +#endif + // Make sure all the dispatch crap is cleared out //Glib::MainContext::get_default()->iteration(false); - + if(success) signal_success_(); - + signal_finished_(); - + target=0; render_thread=0; } @@ -426,6 +458,16 @@ AsyncRenderer::start() ); } +#ifdef SINGLE_THREADED +void +AsyncRenderer::rendering_progress() +{ + updating = true; + while(studio::App::events_pending()) studio::App::iteration(false); + updating = false; +} +#endif + void AsyncRenderer::start_() { @@ -435,16 +477,28 @@ AsyncRenderer::start_() #ifndef GLIB_DISPATCHER_BROKEN done_connection=signal_done_.connect(mem_fun(*this,&AsyncRenderer::stop)); #endif - - render_thread=Glib::Thread::create( - sigc::mem_fun(*this,&AsyncRenderer::render_target), + +#ifdef SINGLE_THREADED + if (single_threaded()) + { + synfig::info("%s:%d rendering in the same thread", __FILE__, __LINE__); + target->signal_progress().connect(sigc::mem_fun(this,&AsyncRenderer::rendering_progress)); + render_thread = (Glib::Thread*)1; + render_target(); + } + else +#endif + { + render_thread=Glib::Thread::create( + sigc::mem_fun(*this,&AsyncRenderer::render_target), #if REJOIN_ON_STOP - true + true #else - false + false #endif - ); - assert(render_thread); + ); + assert(render_thread); + } } else { @@ -456,7 +510,7 @@ void AsyncRenderer::render_target() { etl::handle target(AsyncRenderer::target); - + if(target && target->render()) { success=true;