Blame synfig-core/src/synfig/target_cairo_tile.h

Carlos Lopez 940dd2
/* === S Y N F I G ========================================================= */
Carlos Lopez 940dd2
/*!	\file target_cairo_tile.h
Carlos Lopez 940dd2
**	\brief Template Header for the Target Cairo class tile mode
Carlos Lopez 940dd2
**
Carlos Lopez 940dd2
**	$Id$
Carlos Lopez 940dd2
**
Carlos Lopez 940dd2
**	\legal
Carlos Lopez 940dd2
**	Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
Carlos Lopez e83454
**	Copyright (c) 2013-2013 Carlos Lรณpez
Carlos Lopez 940dd2
**
Carlos Lopez 940dd2
**	This package is free software; you can redistribute it and/or
Carlos Lopez 940dd2
**	modify it under the terms of the GNU General Public License as
Carlos Lopez 940dd2
**	published by the Free Software Foundation; either version 2 of
Carlos Lopez 940dd2
**	the License, or (at your option) any later version.
Carlos Lopez 940dd2
**
Carlos Lopez 940dd2
**	This package is distributed in the hope that it will be useful,
Carlos Lopez 940dd2
**	but WITHOUT ANY WARRANTY; without even the implied warranty of
Carlos Lopez 940dd2
**	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Carlos Lopez 940dd2
**	General Public License for more details.
Carlos Lopez 940dd2
**	\endlegal
Carlos Lopez 940dd2
*/
Carlos Lopez 940dd2
/* ========================================================================= */
Carlos Lopez 940dd2
Carlos Lopez 940dd2
/* === S T A R T =========================================================== */
Carlos Lopez 940dd2
Carlos Lopez 940dd2
#ifndef __SYNFIG_TARGET_CAIRO_TILE_H
Carlos Lopez 940dd2
#define __SYNFIG_TARGET_CAIRO_TILE_H
Carlos Lopez 940dd2
Carlos Lopez 940dd2
/* === H E A D E R S ======================================================= */
Carlos Lopez 940dd2
Carlos Lopez 940dd2
#include "target.h"
Carlos Lopez 940dd2
#include "cairo.h"
Carlos Lopez 940dd2
Carlos Lopez 940dd2
Carlos Lopez 940dd2
/* === M A C R O S ========================================================= */
Carlos Lopez 940dd2
4590f7
#define TILE_SIZE 64
Carlos Lopez 940dd2
Carlos Lopez 940dd2
/* === T Y P E D E F S ===================================================== */
Carlos Lopez 940dd2
Carlos Lopez 940dd2
/* === C L A S S E S & S T R U C T S ======================================= */
Carlos Lopez 940dd2
Carlos Lopez 940dd2
namespace synfig {
Carlos Lopez 940dd2
Carlos Lopez 940dd2
class CairoSurface;
Carlos Lopez 940dd2
Carlos Lopez 940dd2
/*!	\class Target_Cairo_Tile
luz.paz 99f3ef
**	\brief This is a Target class that implements the render function
Carlos Lopez 940dd2
* for a CairoSurface using tile mode
Carlos Lopez 940dd2
*/
Carlos Lopez 940dd2
class Target_Cairo_Tile : public Target
Carlos Lopez 940dd2
{
Carlos Lopez 940dd2
	//! Number of threads to use
Carlos Lopez 940dd2
	int threads_;
Carlos Lopez 940dd2
	//! Tile width in pixels
Carlos Lopez 940dd2
	int tile_w_;
Carlos Lopez 940dd2
	//! Tile height in pixles
Carlos Lopez 940dd2
	int tile_h_;
Carlos Lopez 940dd2
	//! The current tile being rendered
Carlos Lopez 940dd2
	int curr_tile_;
Carlos Lopez 940dd2
	//! Determines if the tiles should be clipped to the render description
Carlos Lopez 940dd2
	//! or not
Carlos Lopez 940dd2
	bool clipping_;
Carlos Lopez 940dd2
Carlos Lopez 940dd2
public:
Carlos Lopez 940dd2
	typedef etl::handle<target_cairo_tile> Handle;</target_cairo_tile>
Carlos Lopez 940dd2
	typedef etl::loose_handle<target_cairo_tile> LooseHandle;</target_cairo_tile>
Carlos Lopez 940dd2
	typedef etl::handle<const target_cairo_tile=""> ConstHandle;</const>
Carlos Lopez 940dd2
	//! Default constructor (current frame = 0)
Carlos Lopez 940dd2
	Target_Cairo_Tile();
Carlos Lopez 940dd2
Carlos Lopez 940dd2
	//! Renders the canvas to the target
Carlos Lopez 940dd2
	virtual bool render(ProgressCallback *cb=NULL);
Carlos Lopez 940dd2
Carlos Lopez 940dd2
	//! Determines which tile needs to be rendered next.
Carlos Lopez 940dd2
	/*!	Most cases will not have to redefine this function.
Carlos Lopez 940dd2
	 **	The default should be adequate in nearly all situations.
Carlos Lopez 940dd2
	 **	\returns The number of tiles left to go plus one.
Carlos Lopez 940dd2
	 **		This means that whenever this function returns zero,
Carlos Lopez 940dd2
	 **		there are no more tiles to render and that any value
Carlos Lopez 940dd2
	 **		in \a x or \a y should be disregarded. */
Carlos Lopez 940dd2
	virtual int next_tile(int& x, int& y);
Carlos Lopez 940dd2
	
Carlos Lopez 940dd2
	//! Returns the number of peniding frames to render. If it is zero it
Carlos Lopez 940dd2
	//! stops rendering frames.
Carlos Lopez 940dd2
	virtual int next_frame(Time& time);
Carlos Lopez 940dd2
	
Carlos Lopez 940dd2
	//! Adds the tile at \a x , \a y contained in \a surface
Carlos Lopez 66f437
	virtual bool add_tile(cairo_surface_t* surface, int x, int y)=0;
Carlos Lopez 940dd2
	//! Returns the total tiles of the imaged rounded to integer number of tiles
Carlos Lopez 940dd2
	virtual int total_tiles()const
Carlos Lopez 940dd2
	{
Carlos Lopez 940dd2
		// Width of the image(in tiles)
Carlos Lopez 940dd2
		const int tw(rend_desc().get_w()/tile_w_+(rend_desc().get_w()%tile_w_?1:0));
Carlos Lopez 940dd2
		const int th(rend_desc().get_h()/tile_h_+(rend_desc().get_h()%tile_h_?1:0));
Carlos Lopez 940dd2
		
Carlos Lopez 940dd2
		return tw*th;
Carlos Lopez 940dd2
	}
Carlos Lopez 940dd2
	//!Sets the number of threads
Carlos Lopez 940dd2
	void set_threads(int x) { threads_=x; }
Carlos Lopez 940dd2
	//!Gets the number of threads
Carlos Lopez 940dd2
	int get_threads()const { return threads_; }
luz.paz 99f3ef
	//!Sets the tile width
Carlos Lopez 940dd2
	void set_tile_w(int w) { tile_w_=w; }
luz.paz 99f3ef
	//!Gets the tile width
Carlos Lopez 940dd2
	int get_tile_w()const { return tile_w_; }
Carlos Lopez 940dd2
	//!Sets the tile height
Carlos Lopez 940dd2
	void set_tile_h(int h) { tile_h_=h; }
Carlos Lopez 940dd2
	//!Gets the tile height
Carlos Lopez 940dd2
	int get_tile_h()const { return tile_h_; }
Carlos Lopez 940dd2
	//! Gets clipping
Carlos Lopez 940dd2
	bool get_clipping()const { return clipping_; }
Carlos Lopez 940dd2
	//! Sets clipping
Carlos Lopez 940dd2
	void set_clipping(bool x) { clipping_=x; }
Carlos Lopez 940dd2
	
Carlos Lopez 940dd2
	
Carlos Lopez 3025c9
	//! Marks the start of a frame
Carlos Lopez 3025c9
	/*! \return \c true on success, \c false upon an error.
Carlos Lopez 3025c9
	 **	\see end_frame()*/
Carlos Lopez 3025c9
	virtual bool start_frame(ProgressCallback *cb=NULL)=0;
Carlos Lopez 3025c9
	
Carlos Lopez 3025c9
	//! Marks the end of a frame
Carlos Lopez 3025c9
	/*! \see start_frame() */
Carlos Lopez 3025c9
	virtual void end_frame()=0;
Carlos Lopez 940dd2
	
a4bbdd
	//! Filters the cairo surface based on gamma
e198f4
	static void gamma_filter(cairo_surface_t* surface, const synfig::Gamma &gamma);
Carlos Lopez 940dd2
Carlos Lopez 940dd2
private:
Carlos Lopez 940dd2
	//! Renders the context to the surface
Carlos Lopez 940dd2
	bool render_frame_(Context context,ProgressCallback *cb=0);
Carlos Lopez 940dd2
Carlos Lopez 940dd2
}; // END of class Target_Cairo_Tile
Carlos Lopez 940dd2
Carlos Lopez 940dd2
}; // END of namespace synfig
Carlos Lopez 940dd2
Carlos Lopez 940dd2
/* === E N D =============================================================== */
Carlos Lopez 940dd2
Carlos Lopez 940dd2
#endif