synfig-studio  1.0.3
asyncrenderer.h
Go to the documentation of this file.
1 /* === S Y N F I G ========================================================= */
22 /* ========================================================================= */
23 
24 /* === S T A R T =========================================================== */
25 
26 #ifndef __SYNFIG_ASYNCRENDERER_H
27 #define __SYNFIG_ASYNCRENDERER_H
28 
29 /* === H E A D E R S ======================================================= */
30 
31 #include <ETL/handle>
32 #include <sigc++/signal.h>
33 #include <sigc++/trackable.h>
34 #include <sigc++/connection.h>
35 
36 #include <synfig/target_scanline.h>
37 #include <synfig/target_tile.h>
38 #include <synfig/target_cairo.h>
39 #include <synfig/target_cairo_tile.h>
40 #include <synfig/surface.h>
41 #include <glibmm/main.h>
42 #include <ETL/ref_count>
43 #include <glibmm/thread.h>
44 #include <glibmm/dispatcher.h>
45 
46 #include "app.h"
47 
48 /* === M A C R O S ========================================================= */
49 
50 // uncomment define SINGLE_THREADED to use a single thread, and hopefully get more stability (dooglus)
51 // changed to be default if using windows (Nov 2009 pixelgeek) - see app.h
52 #ifdef SINGLE_THREADED
53 # define single_threaded() App::single_threaded
54 #endif
55 
56 /* === T Y P E D E F S ===================================================== */
57 
58 /* === C L A S S E S & S T R U C T S ======================================= */
59 
60 namespace studio {
61 
62 class AsyncRenderer : public etl::shared_object, public sigc::trackable
63 {
65  sigc::signal<void> signal_finished_;
67  sigc::signal<void> signal_success_;
68 
70  std::list<sigc::connection> activity_connection_list;
71 
73  etl::handle<synfig::Target> target;
74 
76  bool error;
78  bool success;
79 
80  synfig::ProgressCallback *cb;
82  sigc::signal<void> signal_stop_;
83 
84  Glib::Thread* render_thread;
85  Glib::Dispatcher signal_done_;
86  Glib::Mutex mutex;
87  sigc::connection done_connection;
88 
89  Glib::TimeVal start_time;
90  Glib::TimeVal finish_time;
91 
92  /*
93  -- ** -- P A R E N T M E M B E R S -----------------------------------------
94  */
95 public:
96 
97  AsyncRenderer(etl::handle<synfig::Target> target,synfig::ProgressCallback *cb=0);
98  virtual ~AsyncRenderer();
99 
100  void start();
101  void stop();
102  void pause();
103  void resume();
104 #ifdef SINGLE_THREADED
105  void rendering_progress();
106  bool updating;
107 #endif
108 
109  bool has_error()const { return error; }
110  bool has_success()const { return success; }
111  synfig::Real get_execution_time() const { return (finish_time - start_time).as_double(); }
112 
113  sigc::signal<void>& signal_finished() { return signal_finished_; }
114  sigc::signal<void>& signal_success() { return signal_success_; }
115 
116 private:
117 
118  void render_target();
119  void start_();
120 
121  /*
122  -- ** -- C H I L D M E M B E R S -------------------------------------------
123  */
124 
125 protected:
126 
127 };
128 
129 }; // END of namespace studio
130 
131 /* === E N D =============================================================== */
132 
133 #endif