Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef TRENDERER_INCLUDED
Toshihiro Shimizu 890ddd
#define TRENDERER_INCLUDED
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "trasterfx.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#undef DVAPI
Toshihiro Shimizu 890ddd
#undef DVVAR
Toshihiro Shimizu 890ddd
#ifdef TFX_EXPORTS
Toshihiro Shimizu 890ddd
#define DVAPI DV_EXPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_EXPORT_VAR
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define DVAPI DV_IMPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_IMPORT_VAR
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=========================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//  Forward declarations
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TRenderer;
Toshihiro Shimizu 890ddd
class TRendererImp;
Toshihiro Shimizu 890ddd
class TException;
Toshihiro Shimizu 890ddd
class TRenderSettings;
Toshihiro Shimizu 890ddd
class TRasterFxP;
Toshihiro Shimizu 890ddd
class TFxCacheManager;
Toshihiro Shimizu 890ddd
class TRenderResourceManager;
Toshihiro Shimizu 890ddd
class TRenderResourceManagerGenerator;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TFxPair
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	TRasterFxP m_frameA, m_frameB;
Toshihiro Shimizu 890ddd
	TFxPair() : m_frameA(), m_frameB() {}
Toshihiro Shimizu 890ddd
	TFxPair(const TRasterFxP &frameA, TRasterFxP &frameB)
Toshihiro Shimizu 890ddd
		: m_frameA(frameA), m_frameB(frameB) {}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//typedef std::pair<trasterfxp, trasterfxp=""> TFxPair;</trasterfxp,>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=========================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//====================
Toshihiro Shimizu 890ddd
//    TRenderPort
Toshihiro Shimizu 890ddd
//--------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//! The TRenderPort class acts as a spatially-declared listener to a TRenderer instance.
Toshihiro Shimizu 890ddd
//! TRenderPorts are the formally supported receivers of TRenderer's activity notifications;
Toshihiro Shimizu 890ddd
//! they provide some basic pure virtual members that are appropriately invoked by the TRenderer
Toshihiro Shimizu 890ddd
//! when an associated interesting render event takes place.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI TRenderPort
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TRectD m_renderArea;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	struct RenderData;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRenderPort();
Toshihiro Shimizu 890ddd
	virtual ~TRenderPort();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setRenderArea(const TRectD &area);
Toshihiro Shimizu 890ddd
	TRectD &getRenderArea();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual void onRenderRasterStarted(const RenderData &renderData) {}
Toshihiro Shimizu 890ddd
	virtual void onRenderRasterCompleted(const RenderData &renderData) {}
Toshihiro Shimizu 890ddd
	virtual void onRenderFailure(const RenderData &renderData, TException &e) {}
Toshihiro Shimizu 890ddd
	virtual void onRenderFinished(bool isCanceled = false) {}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=========================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//================================
Toshihiro Shimizu 890ddd
//    TRenderPort::RenderData
Toshihiro Shimizu 890ddd
//--------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//! This storage struct contains the elementary data necessary to identify a cluster of identical
Toshihiro Shimizu 890ddd
//! rendered frames from TRenderer. In order to avoid recalculation of identical frames during a
Toshihiro Shimizu 890ddd
//! render process, they are merged in one 'equivalence cluster' of which only one representant is
Toshihiro Shimizu 890ddd
//! rendered; the m_frames member stores each frame of such cluster. The associated raster is stored
Toshihiro Shimizu 890ddd
//! in the m_ras member. Additional returned infos include the TRenderSettings under which the frames
Toshihiro Shimizu 890ddd
//! were rendered, and unique identification vars.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
struct TRenderPort::RenderData {
Toshihiro Shimizu 890ddd
	std::vector<double> m_frames; //!< Frames this output represents</double>
Toshihiro Shimizu 890ddd
	TRenderSettings m_info;		  //!< Output settings description
Toshihiro Shimizu 890ddd
	TRasterP m_rasA, m_rasB;	  //!< The output images; m_rasB is not empty only for interlacacing and stereoscopic.
Toshihiro Shimizu 890ddd
	unsigned long m_renderId;	 //!< Identifier of the rendering session this output belongs to
Toshihiro Shimizu 890ddd
	unsigned long m_taskId;		  //!< Task identifier in the rendering session. Starts at 0, preserves
Toshihiro Shimizu 890ddd
								  //!< the original submission order except for cluster equivalence.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	RenderData() : m_renderId((unsigned long)-1), m_taskId((unsigned long)-1) {}
Toshihiro Shimizu 890ddd
	RenderData(const std::vector<double> &frames,</double>
Toshihiro Shimizu 890ddd
			   const TRenderSettings &info, const TRasterP &rasA, const TRasterP &rasB,
Toshihiro Shimizu 890ddd
			   unsigned long renderId, unsigned long taskId)
Toshihiro Shimizu 890ddd
		: m_frames(frames), m_info(info), m_rasA(rasA), m_rasB(rasB), m_renderId(renderId), m_taskId(taskId) {}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=================================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=========================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//    TRenderer
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//! The TRenderer class provides the core operative interface to the Toonz
Toshihiro Shimizu 890ddd
//! rendering library.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//! The TRenderer's main purpose is that of invoking a render process on a group
Toshihiro Shimizu 890ddd
//! of separate threads through the \b startRendering() methods. After this is done,
Toshihiro Shimizu 890ddd
//! the activated process communicates with any TRenderPort previously set through
Toshihiro Shimizu 890ddd
//! the \b addPort() method in order to notify the render status.
Toshihiro Shimizu 890ddd
//! The rendering process can be interrupted with the stopRendering() method, which
Toshihiro Shimizu 890ddd
//! makes all rendering threads quit safely at the most appropriate time; the more
Toshihiro Shimizu 890ddd
//! specific abortRendering() method may be used to terminate a render process id in case
Toshihiro Shimizu 890ddd
//! more than one process is running.
Toshihiro Shimizu 890ddd
//! \n \n
Toshihiro Shimizu 890ddd
//! Technically, this class is an \a interface to the actual rendering class,
Toshihiro Shimizu 890ddd
//! which remains in background. This means that users have no necessity of maintaining the
Toshihiro Shimizu 890ddd
//! TRenderer instance alive as a render process is running. We may, for example,
Toshihiro Shimizu 890ddd
//! create a TRenderer, set its properties, launch the render, and release the TRenderer
Toshihiro Shimizu 890ddd
//! instance immediately after as the internal rendering class will continue working on.
Toshihiro Shimizu 890ddd
//! TRenderers may therefore be copied and assigned freely to refer an already existing
Toshihiro Shimizu 890ddd
//! internal rendering instance. These are created anew only using the default
Toshihiro Shimizu 890ddd
//! TRenderer(int) constructor.
Toshihiro Shimizu 890ddd
//! \n \n
Toshihiro Shimizu 890ddd
//! On the other hand, TRenderer's lifespan may last longer than that of a single rendering
Toshihiro Shimizu 890ddd
//! process. This is especially useful when it is known that multiple rendering processes share
Toshihiro Shimizu 890ddd
//! some common resources (likewise, intermediate cache results), which can be maintained
Toshihiro Shimizu 890ddd
//! in the same internal TRenderer representation for later use.
Toshihiro Shimizu 890ddd
//! \n \n
Toshihiro Shimizu 890ddd
//! Some final notes about methods dealing with Toonz's lower-level API. Direct invocation
Toshihiro Shimizu 890ddd
//! of rendering functions, such as the TRasterFx::compute() method, is discouraged. Further
Toshihiro Shimizu 890ddd
//! improvements of the TRenderer's API will eventually make the need for these calls obsolete. However,
Toshihiro Shimizu 890ddd
//! we've implemented the possibilty to rely on TRenderer's management support even in those cases -
Toshihiro Shimizu 890ddd
//! it can be done by declaring the render process' interesting events through the apposite  declare..() <\a>
Toshihiro Shimizu 890ddd
//! methods and invoking install() and uninstall() on each rendering thread you'll raise
Toshihiro Shimizu 890ddd
//! for the process.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI TRenderer
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TRendererImp *m_imp;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	friend class TRenderResourceManagerGenerator;
Toshihiro Shimizu 890ddd
	TRenderResourceManager *getManager(unsigned int id) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	//! The RenderData struct contains the frame specifics to supply for a
Toshihiro Shimizu 890ddd
	//! TRenderer::startRendering() call.
Toshihiro Shimizu 890ddd
	struct RenderData {
Toshihiro Shimizu 890ddd
		double m_frame;
Toshihiro Shimizu 890ddd
		TRenderSettings m_info;
Toshihiro Shimizu 890ddd
		TFxPair m_fxRoot; //The second of pair is used for field interlacing or stereoscopic render.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		RenderData(double frame, const TRenderSettings &info, const TFxPair &fxRoot)
Toshihiro Shimizu 890ddd
			: m_frame(frame), m_info(info), m_fxRoot(fxRoot) {}
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	TRenderer(int nThread = 1);
Toshihiro Shimizu 890ddd
	TRenderer(TRendererImp *);
Toshihiro Shimizu 890ddd
	~TRenderer();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRenderer(const TRenderer &);
Toshihiro Shimizu 890ddd
	void operator=(const TRenderer &);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	operator bool() const { return m_imp; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void addPort(TRenderPort *port);
Toshihiro Shimizu 890ddd
	void removePort(TRenderPort *port);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	unsigned long startRendering(const std::vector<trenderer::renderdata> *renderDatas);</trenderer::renderdata>
Toshihiro Shimizu 890ddd
	unsigned long startRendering(double f, const TRenderSettings &info, const TFxPair &actualRoot);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void abortRendering(unsigned long renderId);
Toshihiro Shimizu 890ddd
	void stopRendering(bool waitForCompleteStop = false);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void enablePrecomputing(bool on);
Toshihiro Shimizu 890ddd
	bool isPrecomputingEnabled() const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setThreadsCount(int nThreads);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	static TRenderer instance();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	unsigned long rendererId();
Toshihiro Shimizu 890ddd
	static unsigned long renderId();
Toshihiro Shimizu 890ddd
	static unsigned long nextRenderId();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//-----------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//Render instance properties
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	enum RenderStatus { IDLE = 0x0,
Toshihiro Shimizu 890ddd
						FIRSTRUN = 0x1,
Toshihiro Shimizu 890ddd
						TESTRUN = 0x2,
Toshihiro Shimizu 890ddd
						COMPUTING = 0x4 };
Toshihiro Shimizu 890ddd
	int getRenderStatus(unsigned long renderId) const;
Toshihiro Shimizu 890ddd
	bool isAborted(unsigned long renderId) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//-----------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//  To install the TRenderer on lower-level rendering invocations
Toshihiro Shimizu 890ddd
	static unsigned long buildRenderId();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void declareRenderStart(unsigned long renderId);
Toshihiro Shimizu 890ddd
	void declareRenderEnd(unsigned long renderId);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void declareFrameStart(double frame);
Toshihiro Shimizu 890ddd
	void declareFrameEnd(double frame);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void install(unsigned long renderId);
Toshihiro Shimizu 890ddd
	void uninstall();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// Be sure that this method is called at least once before a rendering driven by a working thread
Toshihiro Shimizu 890ddd
	// (the TRendererStartInvoker singleton must be referred first by a thread that survives, e.g. the main thread)
Toshihiro Shimizu 890ddd
	static void initialize();
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
typedef std::vector<trenderer::renderdata> RenderDataVector;</trenderer::renderdata>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif