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