X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-studio%2Ftrunk%2Fsrc%2Fgtkmm%2Fasyncrenderer.cpp;h=72a286c92a56c1dfb5d7009284288a61d6de07d9;hb=9459638ad6797b8139f1e9f0715c96076dbf0890;hp=3651b75f223a96928f1fac84ee7503aa17cd8061;hpb=8e1d10adadf7237f6f2bfedef207add28485e74b;p=synfig.git diff --git a/synfig-studio/trunk/src/gtkmm/asyncrenderer.cpp b/synfig-studio/trunk/src/gtkmm/asyncrenderer.cpp index 3651b75..72a286c 100644 --- a/synfig-studio/trunk/src/gtkmm/asyncrenderer.cpp +++ b/synfig-studio/trunk/src/gtkmm/asyncrenderer.cpp @@ -6,6 +6,7 @@ ** ** \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 @@ -53,6 +54,8 @@ #include #include +#include "general.h" + #endif /* === U S I N G =========================================================== */ @@ -88,9 +91,7 @@ public: } }; std::list tile_queue; -#ifndef SINGLE_THREADED Glib::Mutex mutex; -#endif // SINGLE_THREADED #ifndef GLIB_DISPATCHER_BROKEN Glib::Dispatcher tile_ready_signal; @@ -125,9 +126,7 @@ public: } void set_dead() { -#ifndef SINGLE_THREADED Glib::Mutex::Lock lock(mutex); -#endif // SINGLE_THREADED alive_flag=false; } @@ -163,9 +162,7 @@ public: assert(surface); if(!alive_flag) return false; -#ifndef SINGLE_THREADED Glib::Mutex::Lock lock(mutex); -#endif // SINGLE_THREADED tile_queue.push_back(tile_t(surface,gx,gy)); if(tile_queue.size()==1) { @@ -187,9 +184,7 @@ public: void tile_ready() { -#ifndef SINGLE_THREADED Glib::Mutex::Lock lock(mutex); -#endif // SINGLE_THREADED if(!alive_flag) { tile_queue.clear(); @@ -200,6 +195,13 @@ public: { 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(); @@ -209,20 +211,25 @@ public: virtual void end_frame() { -#ifndef SINGLE_THREADED - 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); -#endif // SINGLE_THREADED if(!alive_flag) return; return warm_target->end_frame(); @@ -239,9 +246,7 @@ public: int scanline_; Surface surface; -#ifndef SINGLE_THREADED Glib::Mutex mutex; -#endif // SINGLE_THREADED #ifndef GLIB_DISPATCHER_BROKEN Glib::Dispatcher frame_ready_signal; @@ -284,9 +289,7 @@ public: void set_dead() { -#ifndef SINGLE_THREADED Glib::Mutex::Lock lock(mutex); -#endif // SINGLE_THREADED alive_flag=false; } @@ -298,9 +301,7 @@ public: virtual void end_frame() { { -#ifndef SINGLE_THREADED Glib::Mutex::Lock lock(mutex); -#endif // SINGLE_THREADED if(!alive_flag) return; @@ -317,24 +318,25 @@ public: #else frame_ready_signal(); #endif - } - -#ifndef SINGLE_THREADED - while(alive_flag && !ready_next) - { - Glib::Mutex::Lock lock(mutex); - if(cond_frame_queue_empty.timed_wait(mutex,Glib::TimeVal(0,BOREDOM_TIMEOUT))) - break; } -#endif // SINGLE_THREADED + +#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) { -#ifndef SINGLE_THREADED Glib::Mutex::Lock lock(mutex); -#endif // SINGLE_THREADED return surface[scanline]; } @@ -346,12 +348,13 @@ public: void frame_ready() { -#ifndef SINGLE_THREADED Glib::Mutex::Lock lock(mutex); -#endif // SINGLE_THREADED 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; } }; @@ -368,7 +371,7 @@ AsyncRenderer::AsyncRenderer(etl::handle target_,synfig::Progres cb(cb) #ifdef SINGLE_THREADED , updating(false) -#endif // SINGLE_THREADED +#endif { render_thread=0; if(etl::handle::cast_dynamic(target_)) @@ -405,19 +408,18 @@ AsyncRenderer::stop() { if(target) { -#ifndef SINGLE_THREADED Glib::Mutex::Lock lock(mutex); -#endif // SINGLE_THREADED done_connection.disconnect(); if(render_thread) { signal_stop_(); -#ifndef SINGLE_THREADED #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 @@ -464,7 +466,7 @@ AsyncRenderer::rendering_progress() while(studio::App::events_pending()) studio::App::iteration(false); updating = false; } -#endif // SINGLE_THREADED +#endif void AsyncRenderer::start_() @@ -477,21 +479,26 @@ AsyncRenderer::start_() #endif #ifdef 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 // SINGLE_THREADED - render_thread=Glib::Thread::create( - sigc::mem_fun(*this,&AsyncRenderer::render_target), + 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); -#endif // SINGLE_THREADED + ); + assert(render_thread); + } } else { @@ -516,9 +523,7 @@ AsyncRenderer::render_target() #endif } -#ifndef SINGLE_THREADED if(mutex.trylock()) -#endif // SINGLE_THREADED { #ifdef GLIB_DISPATCHER_BROKEN done_connection=Glib::signal_timeout().connect( @@ -531,8 +536,6 @@ AsyncRenderer::render_target() #else signal_done_.emit(); #endif -#ifndef SINGLE_THREADED mutex.unlock(); -#endif // SINGLE_THREADED } }