#include <rive/shapes/paint/fill.hpp>
#include <rive/shapes/paint/solid_color.hpp>
#include <rive/shapes/paint/stroke.hpp>
-#include <rive/tvg_renderer.hpp>
// INTERNAL INCLUDES
#include <dali-extension/internal/rive-animation-view/animation-renderer/rive-animation-renderer-manager.h>
mTargetSurface(),
mUploadCompletedSignal(),
mTbmQueue(NULL),
- mSwCanvas(nullptr),
- mFile(nullptr),
mArtboard(nullptr),
mAnimation(nullptr),
mStartFrameNumber(0),
mFrameRate(60.0f),
mResourceReady(false),
mShaderChanged(false),
- mResourceReadyTriggered(false)
+ mResourceReadyTriggered(false),
+ mRiveTizenAdapter(nullptr)
{
- tvg::Initializer::init(tvg::CanvasEngine::Sw, 0);
+ mRiveTizenAdapter = new RiveTizen();
}
RiveAnimationRenderer::~RiveAnimationRenderer()
{
Dali::Mutex::ScopedLock lock(mMutex);
-
ClearRiveAnimations();
- if(mFile)
+ if (mRiveTizenAdapter)
{
- delete mFile;
+ delete mRiveTizenAdapter;
}
- mSwCanvas->clear();
- tvg::Initializer::term(tvg::CanvasEngine::Sw);
+ mRiveTizenAdapter = nullptr;
DALI_LOG_INFO(gRiveAnimationLogFilter, Debug::Verbose, "RiveAnimationRenderer::~RiveAnimationRenderer: this = %p\n", this);
}
return;
}
- auto reader = rive::BinaryReader(&bytes[0], bytes.Size());
-
- if(mFile)
- {
- delete mFile;
- }
-
- auto result = rive::File::import(reader, &mFile);
- if(result != rive::ImportResult::success)
- {
- DALI_LOG_ERROR("Failed to import %s", filename.c_str());
- return;
- }
-
- mArtboard = mFile->artboard();
- mArtboard->advance(0.0f);
-
ClearRiveAnimations();
+ mRiveTizenAdapter->loadRiveResource(&bytes[0], bytes.Size());
+ mArtboard = mRiveTizenAdapter->getArtboard();
for(unsigned int i = 0; i < mArtboard->animationCount(); i++)
{
auto animation = mArtboard->animation(i);
const std::string& name = animation->name();
- mAnimations.emplace_back(Animation(new rive::LinearAnimationInstance(animation), name, false));
+ mAnimations.emplace_back(Animation(mRiveTizenAdapter->createLinearAnimationInstance(i), name, false));
}
mAnimation = mArtboard->firstAnimation();
bool RiveAnimationRenderer::Render(double elapsed)
{
Dali::Mutex::ScopedLock lock(mMutex);
- if(!mTbmQueue || !mTargetSurface || !mArtboard || mAnimations.empty())
+ if(!mTbmQueue || !mTargetSurface || mAnimations.empty())
{
return false;
}
tbm_surface_internal_ref(tbmSurface);
- if(!mSwCanvas)
- {
- mSwCanvas = tvg::SwCanvas::gen();
- mSwCanvas->mempool(tvg::SwCanvas::MempoolPolicy::Individual);
- }
- mSwCanvas->clear();
- mSwCanvas->target((uint32_t*)buffer, info.planes[0].stride / 4, info.width, info.height, tvg::SwCanvas::ARGB8888);
+ mRiveTizenAdapter->createCanvas(buffer, info.width, info.height, info.planes[0].stride / 4);
// Render Rive animation by elapsed time
for(auto& animation : mAnimations)
{
if(animation.enable)
{
- animation.instance->advance(elapsed);
- animation.instance->apply(mArtboard);
+ mRiveTizenAdapter->animationAdvanceApply(animation.instance.get(), elapsed);
}
else if(animation.elapsed >= 0.0f)
{
- animation.instance->time(animation.elapsed);
- animation.instance->apply(mArtboard);
+ mRiveTizenAdapter->animationApply(animation.instance.get(), elapsed);
}
}
}
- mArtboard->advance(elapsed);
-
- rive::TvgRenderer renderer(mSwCanvas.get());
- renderer.save();
- renderer.align(rive::Fit::contain,
- rive::Alignment::center,
- rive::AABB(0, 0, info.width, info.height),
- mArtboard->bounds());
- mArtboard->draw(&renderer);
- renderer.restore();
-
- if(mSwCanvas->draw() == tvg::Result::Success)
- {
- mSwCanvas->sync();
- }
- else
+
+ if (!mRiveTizenAdapter->render(elapsed, info.width, info.height))
{
tbm_surface_unmap(tbmSurface);
tbm_surface_queue_cancel_dequeue(mTbmQueue, tbmSurface);
{
if(mAnimations[i].instance)
{
- auto animation = mArtboard->animation(i);
- mAnimations[i].instance.reset(new rive::LinearAnimationInstance(animation));
+ mAnimations[i].instance.reset(mRiveTizenAdapter->createLinearAnimationInstance(i));
}
mAnimations[i].enable = enable;
return;
#include <tbm_surface.h>
#include <tbm_surface_queue.h>
-// RIVE - THORVG INCLUDES
-#include <thorvg.h>
+// RIVE - INCLUDES
+#include <rive_tizen.hpp>
#include <rive/animation/linear_animation_instance.hpp>
#include <rive/artboard.hpp>
-//
// INTERNAL INCLUDES
#include <dali-extension/internal/rive-animation-view/animation-renderer/rive-animation-renderer-event-handler.h>
NativeImageSourceQueuePtr mTargetSurface; ///< The target surface
UploadCompletedSignalType mUploadCompletedSignal; ///< Upload completed signal
tbm_surface_queue_h mTbmQueue; ///< Tbm surface queue handle
- std::unique_ptr<tvg::SwCanvas> mSwCanvas; ///< ThorVG SW canvas handle
- rive::File *mFile; ///< Rive file handle
rive::Artboard *mArtboard; ///< Rive artboard handle
std::vector<Animation> mAnimations; ///< Rive animations
rive::LinearAnimation *mAnimation; ///< Rive animation handle
bool mResourceReady; ///< Whether the resource is ready
bool mShaderChanged; ///< Whether the shader is changed to support native image
bool mResourceReadyTriggered;///< Whether the resource ready is triggered
+ RiveTizen *mRiveTizenAdapter; ///< Rive Tizen Adapter
};
} // namespace Internal