Finish TODO 8,9
This commit is contained in:
@@ -32,6 +32,9 @@
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#ifdef OFX_SUPPORTS_OPENGLRENDER
|
||||
#include <QOpenGLFunctions>
|
||||
#endif
|
||||
|
||||
extern "C" {
|
||||
#include <libswscale/swscale.h>
|
||||
@@ -203,12 +206,15 @@ void olive::plugin::OliveClipInstance::setInputTexture(TexturePtr texture, OfxTi
|
||||
if (!texture) {
|
||||
return;
|
||||
}
|
||||
this->params_ = texture->params();
|
||||
#ifdef OFX_SUPPORTS_OPENGLRENDER
|
||||
input_textures_.insert(time, texture);
|
||||
#endif
|
||||
|
||||
AVFramePtr frame = texture->frame();
|
||||
if (!frame || !frame->data[0]) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->params_=texture->params();
|
||||
AVPixelFormat expected_fmt =
|
||||
FFmpegUtils::GetFFmpegPixelFormat(params_.format(),
|
||||
params_.channel_count());
|
||||
@@ -282,3 +288,70 @@ void olive::plugin::OliveClipInstance::setInputTexture(TexturePtr texture, OfxTi
|
||||
copy_bytes);
|
||||
}
|
||||
}
|
||||
|
||||
void olive::plugin::OliveClipInstance::setOutputTexture(Texture *texture,
|
||||
OfxTime time)
|
||||
{
|
||||
#ifdef OFX_SUPPORTS_OPENGLRENDER
|
||||
if (!texture) {
|
||||
return;
|
||||
}
|
||||
output_textures_.insert(time, texture);
|
||||
#else
|
||||
(void)texture;
|
||||
(void)time;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef OFX_SUPPORTS_OPENGLRENDER
|
||||
OFX::Host::ImageEffect::Texture *
|
||||
olive::plugin::OliveClipInstance::loadTexture(OfxTime time, const char *format,
|
||||
const OfxRectD *optionalBounds)
|
||||
{
|
||||
(void)format;
|
||||
|
||||
Texture *gl_texture = nullptr;
|
||||
if (isOutput()) {
|
||||
gl_texture = output_textures_.value(time, nullptr);
|
||||
} else {
|
||||
TexturePtr input = input_textures_.value(time);
|
||||
gl_texture = input ? input.get() : nullptr;
|
||||
}
|
||||
|
||||
if (!gl_texture || gl_texture->IsDummy() || !gl_texture->id().isValid()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
OfxRectD rod_d = getRegionOfDefinition(time);
|
||||
OfxRectI rod = { static_cast<int>(std::floor(rod_d.x1)),
|
||||
static_cast<int>(std::floor(rod_d.y1)),
|
||||
static_cast<int>(std::ceil(rod_d.x2)),
|
||||
static_cast<int>(std::ceil(rod_d.y2)) };
|
||||
OfxRectI bounds = rod;
|
||||
if (optionalBounds) {
|
||||
bounds.x1 = static_cast<int>(std::floor(optionalBounds->x1));
|
||||
bounds.y1 = static_cast<int>(std::floor(optionalBounds->y1));
|
||||
bounds.x2 = static_cast<int>(std::ceil(optionalBounds->x2));
|
||||
bounds.y2 = static_cast<int>(std::ceil(optionalBounds->y2));
|
||||
}
|
||||
bounds.x1 = std::max(bounds.x1, rod.x1);
|
||||
bounds.y1 = std::max(bounds.y1, rod.y1);
|
||||
bounds.x2 = std::min(bounds.x2, rod.x2);
|
||||
bounds.y2 = std::min(bounds.y2, rod.y2);
|
||||
|
||||
const int bytes_per_row =
|
||||
params_.width() * params_.channel_count() * params_.format().byte_count();
|
||||
const std::string &field = getFieldOrder();
|
||||
const std::string unique_id = std::to_string(
|
||||
reinterpret_cast<uintptr_t>(gl_texture)) + "_" +
|
||||
std::to_string(static_cast<long long>(time));
|
||||
|
||||
const int texture_id = gl_texture->id().value<GLuint>();
|
||||
OFX::Host::ImageEffect::Texture *texture =
|
||||
new OFX::Host::ImageEffect::Texture(
|
||||
*this, 1.0, 1.0, texture_id, GL_TEXTURE_2D, bounds, rod,
|
||||
bytes_per_row, field, unique_id);
|
||||
texture->addReference();
|
||||
return texture;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -70,10 +70,13 @@ public:
|
||||
params_ = params;
|
||||
}
|
||||
# ifdef OFX_SUPPORTS_OPENGLRENDER
|
||||
OFX::Host::ImageEffect::Texture* loadTexture(OfxTime time, const char *format, const OfxRectD *optionalBounds) { return NULL; };
|
||||
OFX::Host::ImageEffect::Texture* loadTexture(OfxTime time,
|
||||
const char *format,
|
||||
const OfxRectD *optionalBounds) override;
|
||||
# endif
|
||||
|
||||
void setInputTexture(TexturePtr texture, OfxTime time);
|
||||
void setOutputTexture(Texture *texture, OfxTime time);
|
||||
|
||||
private:
|
||||
VideoParams params_;
|
||||
@@ -84,6 +87,10 @@ private:
|
||||
|
||||
std::string name_;
|
||||
QMap<OfxTime,std::shared_ptr<Image>> images_;
|
||||
#ifdef OFX_SUPPORTS_OPENGLRENDER
|
||||
QMap<OfxTime, TexturePtr> input_textures_;
|
||||
QMap<OfxTime, Texture *> output_textures_;
|
||||
#endif
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,6 +77,10 @@ ImageEffect::Descriptor *
|
||||
OliveHost::makeDescriptor(ImageEffect::ImageEffectPlugin* plugin)
|
||||
{
|
||||
ImageEffect::Descriptor* desc = new ImageEffect::Descriptor(plugin);
|
||||
#ifdef OFX_SUPPORTS_OPENGLRENDER
|
||||
desc->getProps().setStringProperty(kOfxImageEffectPropOpenGLRenderSupported,
|
||||
"true");
|
||||
#endif
|
||||
descriptors_.append(desc);
|
||||
return desc;
|
||||
}
|
||||
@@ -85,6 +89,10 @@ OliveHost::makeDescriptor(const ImageEffect::Descriptor &rootContext,
|
||||
ImageEffect::ImageEffectPlugin *plugin)
|
||||
{
|
||||
ImageEffect::Descriptor* desc = new ImageEffect::Descriptor(rootContext,plugin);
|
||||
#ifdef OFX_SUPPORTS_OPENGLRENDER
|
||||
desc->getProps().setStringProperty(kOfxImageEffectPropOpenGLRenderSupported,
|
||||
"true");
|
||||
#endif
|
||||
descriptors_.append(desc);
|
||||
return desc;
|
||||
}
|
||||
@@ -93,6 +101,10 @@ OliveHost::makeDescriptor(const std::string &bundlePath,
|
||||
ImageEffect::ImageEffectPlugin *plugin)
|
||||
{
|
||||
ImageEffect::Descriptor* desc = new ImageEffect::Descriptor(bundlePath, plugin);
|
||||
#ifdef OFX_SUPPORTS_OPENGLRENDER
|
||||
desc->getProps().setStringProperty(kOfxImageEffectPropOpenGLRenderSupported,
|
||||
"true");
|
||||
#endif
|
||||
descriptors_.append(desc);
|
||||
return desc;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "OlivePluginInstance.h"
|
||||
|
||||
#include "OliveClip.h"
|
||||
#include "ofxGPURender.h"
|
||||
#include "ofxCore.h"
|
||||
#include "ofxMessage.h"
|
||||
#include "common/Current.h"
|
||||
@@ -42,6 +43,19 @@ namespace olive
|
||||
namespace plugin
|
||||
{
|
||||
namespace {
|
||||
const std::string &FieldOrderForParams(const VideoParams ¶ms)
|
||||
{
|
||||
switch (params.interlacing()) {
|
||||
case VideoParams::kInterlaceNone:
|
||||
return kOfxImageFieldNone;
|
||||
case VideoParams::kInterlacedTopFirst:
|
||||
return kOfxImageFieldUpper;
|
||||
case VideoParams::kInterlacedBottomFirst:
|
||||
return kOfxImageFieldLower;
|
||||
}
|
||||
return kOfxImageFieldNone;
|
||||
}
|
||||
|
||||
class DeferredRedoCommand : public UndoCommand {
|
||||
public:
|
||||
explicit DeferredRedoCommand(UndoCommand *inner)
|
||||
@@ -107,6 +121,11 @@ ViewerOutput *GetActiveViewerOutput()
|
||||
}
|
||||
} // namespace
|
||||
|
||||
const std::string &OlivePluginInstance::getDefaultOutputFielding() const
|
||||
{
|
||||
return FieldOrderForParams(params_);
|
||||
}
|
||||
|
||||
OfxStatus OlivePluginInstance::vmessage(const char *type, const char *id,
|
||||
const char *format, va_list args)
|
||||
{
|
||||
@@ -196,7 +215,6 @@ void OlivePluginInstance::getProjectExtent(double &xSize, double &ySize) const
|
||||
{
|
||||
xSize =params_.width();
|
||||
ySize =params_.height();
|
||||
// TODO: Ensure this project does not support this.
|
||||
}
|
||||
double OlivePluginInstance::getProjectPixelAspectRatio() const
|
||||
{
|
||||
@@ -392,6 +410,22 @@ bool OlivePluginInstance::progressUpdate(double t)
|
||||
return !progress_cancelled_;
|
||||
}
|
||||
|
||||
OfxStatus OlivePluginInstance::contextAttachedAction()
|
||||
{
|
||||
if (!open_gl_enabled_) {
|
||||
return kOfxStatReplyDefault;
|
||||
}
|
||||
return kOfxStatOK;
|
||||
}
|
||||
|
||||
OfxStatus OlivePluginInstance::contextDetachedAction()
|
||||
{
|
||||
if (!open_gl_enabled_) {
|
||||
return kOfxStatReplyDefault;
|
||||
}
|
||||
return kOfxStatOK;
|
||||
}
|
||||
|
||||
double OlivePluginInstance::timeLineGetTime()
|
||||
{
|
||||
if (ViewerOutput *viewer = GetActiveViewerOutput()) {
|
||||
@@ -420,6 +454,17 @@ void OlivePluginInstance::timeLineGetBounds(double &t1, double &t2)
|
||||
t2 = 0.0;
|
||||
}
|
||||
|
||||
void OlivePluginInstance::setCustomInArgs(const std::string &action,
|
||||
OFX::Host::Property::Set &inArgs)
|
||||
{
|
||||
if (action == kOfxImageEffectActionRender ||
|
||||
action == kOfxImageEffectActionBeginSequenceRender ||
|
||||
action == kOfxImageEffectActionEndSequenceRender) {
|
||||
inArgs.setIntProperty(kOfxImageEffectPropOpenGLEnabled,
|
||||
open_gl_enabled_ ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
OFX::Host::ImageEffect::ClipInstance *OlivePluginInstance::newClipInstance(
|
||||
OFX::Host::ImageEffect::Instance *plugin,
|
||||
OFX::Host::ImageEffect::ClipDescriptor *descriptor,
|
||||
|
||||
@@ -67,9 +67,7 @@ public:
|
||||
}
|
||||
explicit OlivePluginInstance(Instance & instance):Instance(instance){};
|
||||
~OlivePluginInstance() override = default;
|
||||
const std::string &getDefaultOutputFielding() const{
|
||||
return kOfxImageFieldNone;
|
||||
};
|
||||
const std::string &getDefaultOutputFielding() const override;
|
||||
|
||||
void setVideoParam(VideoParams params)
|
||||
{
|
||||
@@ -79,6 +77,10 @@ public:
|
||||
{
|
||||
node_ = node;
|
||||
}
|
||||
void setOpenGLEnabled(bool enabled)
|
||||
{
|
||||
open_gl_enabled_ = enabled;
|
||||
}
|
||||
OFX::Host::ImageEffect::ClipInstance *newClipInstance(
|
||||
OFX::Host::ImageEffect::Instance *plugin,
|
||||
OFX::Host::ImageEffect::ClipDescriptor *descriptor,
|
||||
@@ -165,6 +167,11 @@ public:
|
||||
/// false if you should abandon processing, true to continue
|
||||
virtual bool progressUpdate(double t) override;
|
||||
|
||||
#ifdef OFX_SUPPORTS_OPENGLRENDER
|
||||
virtual OfxStatus contextAttachedAction() override;
|
||||
virtual OfxStatus contextDetachedAction() override;
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -182,6 +189,9 @@ public:
|
||||
/// get the first and last times available on the effect's timeline
|
||||
virtual void timeLineGetBounds(double &t1, double &t2);
|
||||
|
||||
void setCustomInArgs(const std::string &action,
|
||||
OFX::Host::Property::Set &inArgs) override;
|
||||
|
||||
|
||||
private:
|
||||
QList<PersistentErrors> persistentErrors_;
|
||||
@@ -195,6 +205,7 @@ private:
|
||||
QPointer<ProgressDialog> progress_dialog_;
|
||||
bool progress_cancelled_ = false;
|
||||
bool progress_active_ = false;
|
||||
bool open_gl_enabled_ = false;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user