Shinya Kitaoka 810553
#pragma once
Shinya Kitaoka 810553
Toshihiro Shimizu 890ddd
#ifndef TOONZ_STDFX_PLUGIN_HOST_H__
Toshihiro Shimizu 890ddd
#define TOONZ_STDFX_PLUGIN_HOST_H__
Toshihiro Shimizu 890ddd
#include <qthread></qthread>
Toshihiro Shimizu 890ddd
#include <string></string>
Toshihiro Shimizu 890ddd
#include <memory></memory>
Toshihiro Shimizu 890ddd
#include "tzeraryfx.h"
Toshihiro Shimizu 890ddd
#if defined(_WIN32) || defined(_CYGWIN_)
Toshihiro Shimizu 890ddd
#include <windows.h></windows.h>
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
#include "toonz_plugin.h"
Toshihiro Shimizu 890ddd
#include "toonz_hostif.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*
Toshihiro Shimizu 890ddd
namespace toonz {
Shinya Kitaoka 120a6e
        struct nodal_rasterfx_handler_t;
Shinya Kitaoka 120a6e
        struct host_interface_t;
Shinya Kitaoka 120a6e
        struct plugin_probe_t;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/* probe で得られる静的な plugin 情報 */
Shinya Kitaoka 120a6e
class PluginDescription {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  std::string name_;
Shinya Kitaoka 120a6e
  std::string vendor_;
Shinya Kitaoka 120a6e
  std::string id_;
Shinya Kitaoka 120a6e
  std::string note_;
Shinya Kitaoka 120a6e
  std::string url_;
Shinya Kitaoka 120a6e
  std::string fullname_;
Shinya Kitaoka 120a6e
  int clss_;
Shinya Kitaoka 120a6e
  toonz_plugin_version_t plugin_ver_;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  PluginDescription(const toonz::plugin_probe_t *const probe);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  /* 'geometric' is known as 'Zerary' on toonz. we avoid using the word because
Shinya Kitaoka 120a6e
   * nobody did not understand a meaning of the word */
Shinya Kitaoka 120a6e
  bool is_geometric() const {
Shinya Kitaoka 120a6e
    return clss_ & TOONZ_PLUGIN_CLASS_MODIFIER_GEOMETRIC;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class PluginInformation;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/* エフェクトのインスタンスを構築するためのクラス */
Shinya Kitaoka d1f6c4
struct PluginDeclaration final : public TFxDeclaration {
Shinya Kitaoka 120a6e
  PluginDeclaration(PluginInformation *pi);
Shinya Kitaoka 120a6e
  TPersist *create() const final override;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  PluginInformation *pi_;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class UIPage;
Toshihiro Shimizu 890ddd
class Param;
Toshihiro Shimizu 890ddd
class ParamView;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class ParamsPageSet;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
struct port_description_t {
Shinya Kitaoka 120a6e
  bool input_;
Shinya Kitaoka 120a6e
  std::string name_;
Shinya Kitaoka 120a6e
  int type_;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  port_description_t(bool input, const char *nm, int type)
Shinya Kitaoka 120a6e
      : input_(input), name_(nm), type_(type) {}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#if defined(_WIN32) || defined(_CYGWIN_)
Toshihiro Shimizu 890ddd
typedef std::shared_ptr<std::remove_pointer<hmodule>::type> library_t;</std::remove_pointer<hmodule>
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
typedef std::shared_ptr<void> library_t;</void>
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class PluginInformation {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  PluginDeclaration *decl_;
Shinya Kitaoka 120a6e
  PluginDescription *desc_;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  library_t library_;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  toonz::nodal_rasterfx_handler_t *handler_;
Shinya Kitaoka 120a6e
  toonz::host_interface_t *host_;
Shinya Kitaoka 120a6e
  int (*ini_)(toonz::host_interface_t *);
Shinya Kitaoka 120a6e
  void (*fin_)(void);
Shinya Kitaoka 120a6e
  int ref_count_;
Shinya Kitaoka 120a6e
  int param_page_num_;
Shinya Kitaoka 120a6e
  std::unique_ptr<toonz_param_page_t[]> param_pages_;</toonz_param_page_t[]>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  std::vector<uipage *=""> ui_pages_;</uipage>
Shinya Kitaoka 120a6e
  std::vector<paramview *=""> param_views_;</paramview>
Shinya Kitaoka 120a6e
  std::map<std::string, port_description_t=""> port_mapper_;</std::string,>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  std::vector<std::shared_ptr<void>></std::shared_ptr<void>
Shinya Kitaoka 120a6e
      param_resources_; /* deep-copy に使う scratch area */
Shinya Kitaoka 120a6e
  std::vector<std::shared_ptr<std::string>></std::shared_ptr<std::string>
Shinya Kitaoka 120a6e
      param_string_tbl_; /* shared_ptr< void > では non-virtual destructor
Shinya Kitaoka 120a6e
                            が呼ばれないので  */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  PluginInformation()
Shinya Kitaoka 120a6e
      : desc_(NULL)
Shinya Kitaoka 120a6e
      , library_(NULL)
Shinya Kitaoka 120a6e
      , handler_(NULL)
Shinya Kitaoka 120a6e
      , host_(NULL)
Shinya Kitaoka 120a6e
      , ini_(NULL)
Shinya Kitaoka 120a6e
      , fin_(NULL)
Shinya Kitaoka 120a6e
      , ref_count_(1)
Shinya Kitaoka 120a6e
      , param_page_num_(0) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  ~PluginInformation();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void add_ref();
Shinya Kitaoka 120a6e
  void release();
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class Loader final : public QObject {
Shinya Kitaoka 120a6e
  Q_OBJECT;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  Loader();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 120a6e
  void doLoad(const QString &file);
Shinya Kitaoka 120a6e
  void walkDirectory_(const QString &file);
Toshihiro Shimizu 890ddd
public slots:
Shinya Kitaoka 120a6e
  void walkDirectory(const QString &file);
Shinya Kitaoka 120a6e
  void walkDictionary(const QString &file);
Toshihiro Shimizu 890ddd
signals:
Shinya Kitaoka 120a6e
  void load_finished(PluginInformation *pi);
Shinya Kitaoka 120a6e
  void fixup();
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class PluginLoadController final : public QObject {
Shinya Kitaoka 120a6e
  Q_OBJECT;
Shinya Kitaoka 120a6e
  QThread work_entity;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  PluginLoadController(const std::string &basedir, QObject *listener);
Shinya Kitaoka 120a6e
  bool wait(int timeout_in_ms) { return work_entity.wait(timeout_in_ms); };
Toshihiro Shimizu 890ddd
public slots:
Shinya Kitaoka 120a6e
  void result(PluginInformation *pi);
Shinya Kitaoka 120a6e
  void finished();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
signals:
Shinya Kitaoka 120a6e
  void start(const QString &filepath);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class RasterFxPluginHost final : public TZeraryFx, public TPluginInterface {
Shinya Kitaoka 120a6e
  PluginInformation *pi_;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  std::vector<std::shared_ptr<tfxport>> inputs_;</std::shared_ptr<tfxport>
Shinya Kitaoka 120a6e
  std::vector<std::shared_ptr<param>> params_;</std::shared_ptr<param>
Shinya Kitaoka 120a6e
  void *user_data_;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  static bool validateKeyName(const char *name);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 120a6e
  virtual RasterFxPluginHost *newInstance(PluginInformation *pi) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  RasterFxPluginHost(PluginInformation *pinfo);
Shinya Kitaoka 120a6e
  ~RasterFxPluginHost();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void notify();
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  const TPersistDeclaration *getDeclaration() const override;
Shinya Kitaoka 473e70
  std::string getPluginId() const override;
Shinya Kitaoka 120a6e
Shinya Kitaoka 38fd86
  bool doGetBBox(double frame, TRectD &bbox,
Shinya Kitaoka 38fd86
                 const TRenderSettings &info) override;
Shinya Kitaoka 38fd86
  void doCompute(TTile &tile, double frame,
Shinya Kitaoka 38fd86
                 const TRenderSettings &info) override;
Shinya Kitaoka 120a6e
  int getMemoryRequirement(const TRectD &rect, double frame,
Shinya Kitaoka 473e70
                           const TRenderSettings &info) override;
Shinya Kitaoka 473e70
  bool canHandle(const TRenderSettings &info, double frame) override;
Shinya Kitaoka 120a6e
  bool addInputPort(const std::string &nm, std::shared_ptr<tfxport> port);</tfxport>
Shinya Kitaoka 120a6e
  bool addOutputPort(const std::string &nm, TRasterFxPort *port);
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  TFx *clone(bool recursive) const override;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // UIPage
Shinya Kitaoka 120a6e
  UIPage *createUIPage(const char *name);
Shinya Kitaoka 120a6e
  void build(ParamsPageSet *);
Shinya Kitaoka 120a6e
  std::string getUrl() const;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // setup
Shinya Kitaoka 120a6e
  bool setParamStructure(int n, toonz_param_page_t *descs, int &err,
Shinya Kitaoka 120a6e
                         void *&pos);
Shinya Kitaoka 120a6e
  bool addPortDesc(port_description_t &&);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  Param *createParam(const toonz_param_desc_t *);
Shinya Kitaoka 120a6e
  Param *createParam(const char *name, toonz_param_type_enum e);
Shinya Kitaoka 120a6e
  Param *getParam(const char *name) const;
Shinya Kitaoka 120a6e
  ParamView *createParamView();
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  bool isPlugin() const override { return true; }
Shinya Kitaoka 473e70
  bool isPluginZerary() const override { return pi_->desc_->is_geometric(); }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  bool isZerary() const override { return isPluginZerary(); };
Shinya Kitaoka 473e70
  void callStartRenderHandler() override;
Shinya Kitaoka 473e70
  void callEndRenderHandler() override;
Shinya Kitaoka 38fd86
  void callStartRenderFrameHandler(const TRenderSettings *rs,
Shinya Kitaoka 38fd86
                                   double frame) override;
Shinya Kitaoka 38fd86
  void callEndRenderFrameHandler(const TRenderSettings *rs,
Shinya Kitaoka 38fd86
                                 double frame) override;
Shinya Kitaoka 120a6e
  void *getUserData();
Shinya Kitaoka 120a6e
  void setUserData(void *user_data);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void createParamsByDesc();
Shinya Kitaoka 120a6e
  void createPortsByDesc();
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif