1 /* === S Y N F I G ========================================================= */
2 /*!	\file synfig/rendering/renderer.h
3 **	\brief Renderer Header
4 **
5 **	$Id$
6 **
7 **	\legal
8 **	......... ... 2015 Ivan Mahonin
9 **
10 **	This package is free software; you can redistribute it and/or
11 **	modify it under the terms of the GNU General Public License as
12 **	published by the Free Software Foundation; either version 2 of
13 **	the License, or (at your option) any later version.
14 **
15 **	This package is distributed in the hope that it will be useful,
16 **	but WITHOUT ANY WARRANTY; without even the implied warranty of
17 **	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 **	General Public License for more details.
19 **	\endlegal
20 */
21 /* ========================================================================= */
22 
23 /* === S T A R T =========================================================== */
24 
25 #ifndef __SYNFIG_RENDERING_RENDERER_H
26 #define __SYNFIG_RENDERING_RENDERER_H
27 
28 /* === H E A D E R S ======================================================= */
29 
30 #include <cstdio>
31 
32 #include <map>
33 
34 #include "optimizer.h"
35 
36 /* === M A C R O S ========================================================= */
37 
38 /* === T Y P E D E F S ===================================================== */
39 
40 /* === C L A S S E S & S T R U C T S ======================================= */
41 
42 namespace synfig
43 {
44 namespace rendering
45 {
46 
47 class RenderQueue;
48 
49 class Renderer: public etl::shared_object
50 {
51 public:
52 	typedef etl::handle<Renderer> Handle;
53 
54 	struct DebugOptions {
55 		String task_list_log;
56 		String task_list_optimized_log;
57 		String result_image;
58 	};
59 
60 private:
61 	static Handle blank;
62 	static std::map<String, Handle> *renderers;
63 	static RenderQueue *queue;
64 	static DebugOptions debug_options;
65 	static long long last_registered_optimizer_index;
66 
67 	Optimizer::List optimizers[Optimizer::CATEGORY_ID_COUNT];
68 
69 public:
70 
71 	virtual ~Renderer();
72 
73 	virtual String get_name() const = 0;
74 
get_optimizers(Optimizer::CategoryId category_id)75 	const Optimizer::List& get_optimizers(Optimizer::CategoryId category_id) const { return optimizers[category_id]; }
76 	bool is_optimizer_registered(const Optimizer::Handle &optimizer) const;
77 	void register_optimizer(Real order, const Optimizer::Handle &optimizer);
78 	void register_optimizer(const Optimizer::Handle &optimizer);
79 	void unregister_optimizer(const Optimizer::Handle &optimizer);
80 
81 private:
82 	void optimize_recursive(
83 		const Optimizer::List &optimizers,
84 		const Optimizer::RunParams& params,
85 		int &calls_count,
86 		int &optimizations_count,
87 		int max_level ) const;
88 
89 	void log(
90 		const String &logfile,
91 		const Task::Handle &task,
92 		const Optimizer::RunParams* optimization_stack = NULL,
93 		int level = 0 ) const;
94 	void log(
95 		const String &logfile,
96 		const Task::List &list,
97 		const String &name = String(),
98 		const Optimizer::RunParams* optimization_stack = NULL ) const;
99 
100 	static void initialize_renderers();
101 	static void deinitialize_renderers();
102 
103 	typedef std::pair<Surface::Handle, int>             DepTargetKey;
104 	typedef std::pair<Task::Handle, Task::Set>          DepTargetValue;
105 	typedef std::multimap<DepTargetKey, DepTargetValue> DepTargetMap;
106 	typedef DepTargetMap::value_type                    DepTargetPair;
107 
108 	void find_deps(const Task::List &list) const;
109 
110 public:
111 	int get_max_simultaneous_threads() const;
112 	void optimize(Task::List &list) const;
113 	bool run(const Task::List &list) const;
114 	void enqueue(const Task::List &list, const Task::Handle &finish_signal_task = Task::Handle()) const;
115 
116 	static void initialize();
117 	static void deinitialize();
118 	static void register_renderer(const String &name, const Renderer::Handle &renderer);
119 	static void unregister_renderer(const String &name);
120 	static const Renderer::Handle& get_renderer(const String &name);
121 	static const std::map<String, Handle>& get_renderers();
122 
get_debug_options()123 	static const DebugOptions& get_debug_options()
124 		{ return debug_options; }
125 
subsys_init()126 	static bool subsys_init()
127 	{
128 		initialize();
129 		return true;
130 	}
131 
subsys_stop()132 	static bool subsys_stop()
133 	{
134 		deinitialize();
135 		return false;
136 	}
137 };
138 
139 } /* end namespace rendering */
140 } /* end namespace synfig */
141 
142 /* -- E N D ----------------------------------------------------------------- */
143 
144 #endif
145