1 /* === S Y N F I G ========================================================= */
2 /*!	\file target_tile.h
3 **	\brief Template Header
4 **
5 **	$Id$
6 **
7 **	\legal
8 **	Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **	Copyright (c) 2008 Chris Moore
10 **	Copyright (c) 2012-2013 Carlos López
11 **
12 **	This package is free software; you can redistribute it and/or
13 **	modify it under the terms of the GNU General Public License as
14 **	published by the Free Software Foundation; either version 2 of
15 **	the License, or (at your option) any later version.
16 **
17 **	This package is distributed in the hope that it will be useful,
18 **	but WITHOUT ANY WARRANTY; without even the implied warranty of
19 **	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 **	General Public License for more details.
21 **	\endlegal
22 */
23 /* ========================================================================= */
24 
25 /* === S T A R T =========================================================== */
26 
27 #ifndef __SYNFIG_TARGET_TILE_H
28 #define __SYNFIG_TARGET_TILE_H
29 
30 /* === H E A D E R S ======================================================= */
31 
32 #include "target.h"
33 
34 /* === M A C R O S ========================================================= */
35 
36 #define TILE_SIZE 64
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 { class SurfaceSW; }
45 
46 /*!	\class Target_Tile
47 **	\brief Render-target
48 **	\todo writeme
49 */
50 class Target_Tile : public Target
51 {
52 	//! Number of threads
53 	int threads_;
54 	//! Tile width in pixels
55 	int tile_w_;
56 	//! Tile height in pixles
57 	int tile_h_;
58 	//! The current tile being rendered
59 	int curr_tile_;
60 	//! Determines if the tiles should be clipped to the redener description
61 	//! or not
62 	bool clipping_;
63 
64 	bool allow_multithreading_;
65 
66 	String engine_;
67 
68 	struct TileGroup;
69 
70 	bool call_renderer(Context &context, const etl::handle<rendering::SurfaceSW> &surfacesw, int quality, const RendDesc &renddesc, ProgressCallback *cb);
71 
72 public:
73 	typedef etl::handle<Target_Tile> Handle;
74 	typedef etl::loose_handle<Target_Tile> LooseHandle;
75 	typedef etl::handle<const Target_Tile> ConstHandle;
76 
77 	Target_Tile();
78 
79 	//! Renders the canvas to the target
80 	virtual bool render(ProgressCallback *cb=NULL);
81 
82 	virtual bool async_render_tile(RectInt rect, Context context, RendDesc tile_desc, ProgressCallback *cb=NULL);
83 	virtual bool wait_render_tiles(ProgressCallback *cb=NULL);
84 
85 	//! Determines which tile needs to be rendered next.
86 	/*!	Most cases will not have to redefine this function.
87 	**	The default should be adequate in nearly all situations.
88 	**	\returns The number of tiles left to go <i>plus one</i>.
89 	**		This means that whenever this function returns zero,
90 	**		there are no more tiles to render and that any value
91 	**		in \a rect should be disregarded. */
92 	virtual int next_tile(RectInt& rect);
93 
94 	//! Returns the number of peniding frames to render. If it is zero it
95 	//! stops rendering frames.
96 	virtual int next_frame(Time& time);
97 
98 	//! Adds the tile at \a x , \a y contained in \a surface
99 	virtual bool add_tile(const synfig::Surface &surface, int x, int y)=0;
100 
101 	//! Marks the start of a frame
102 	/*! \return \c true on success, \c false upon an error.
103 	**	\see end_frame(), start_scanline()
104 	*/
105 	virtual bool start_frame(ProgressCallback *cb=NULL)=0;
106 
107 	//! Marks the end of a frame
108 	/*! \see start_frame() */
109 	virtual void end_frame()=0;
110 	//!Sets the number of threads
set_threads(int x)111 	void set_threads(int x) { threads_=x; }
112 	//!Gets the number of threads
get_threads()113 	int get_threads()const { return threads_; }
114 	//!Sets the tile widht
set_tile_w(int w)115 	void set_tile_w(int w) { tile_w_=w; }
116 	//!Gets the tile widht
get_tile_w()117 	int get_tile_w()const { return tile_w_; }
118 	//!Sets the tile height
set_tile_h(int h)119 	void set_tile_h(int h) { tile_h_=h; }
120 	//!Gets the tile height
get_tile_h()121 	int get_tile_h()const { return tile_h_; }
122 	//! Gets clipping
get_clipping()123 	bool get_clipping()const { return clipping_; }
124 	//! Sets clipping
set_clipping(bool x)125 	void set_clipping(bool x) { clipping_=x; }
126 	//! Gets clipping
get_allow_multithreading()127 	bool get_allow_multithreading()const { return allow_multithreading_; }
128 	//! Sets clipping
set_allow_multithreading(bool x)129 	void set_allow_multithreading(bool x) { allow_multithreading_=x; }
130 	//! Gets engine
get_engine()131 	const String& get_engine()const { return engine_; }
132 	//! Sets engine
set_engine(const String & x)133 	void set_engine(const String &x) { engine_=x; }
134 
135 private:
136 	//! Renders the context to the surface
137 	bool render_frame_(Context context,ProgressCallback *cb=0);
138 
139 }; // END of class Target_Tile
140 
141 }; // END of namespace synfig
142 
143 /* === E N D =============================================================== */
144 
145 #endif
146