#include <dali/devel-api/adaptor-framework/pixel-buffer.h>
#include <dali/internal/canvas-renderer/common/drawable-group-impl.h>
#include <dali/internal/canvas-renderer/common/drawable-impl.h>
+#include <dali/internal/canvas-renderer/common/gradient-impl.h>
+#include <dali/internal/canvas-renderer/common/shape-impl.h>
#include <dali/internal/imaging/common/pixel-buffer-impl.h>
namespace Dali
mTvgCanvas(nullptr),
mTvgRoot(nullptr),
#endif
- mSize(0, 0),
- mViewBox(0, 0),
+ mSize(Vector2::ZERO),
+ mViewBox(Vector2::ZERO),
mChanged(false)
{
Initialize(viewBox);
bool CanvasRendererTizen::Commit()
{
#ifdef THORVG_SUPPORT
+ Mutex::ScopedLock lock(mMutex);
+
+ if(mSize.width < 1.0f || mSize.height < 1.0f)
+ {
+ DALI_LOG_ERROR("Size is zero [%p]\n", this);
+ return false;
+ }
+
bool changed = false;
for(auto& it : mDrawables)
{
- Internal::Adaptor::Drawable& drawableImpl = GetImplementation(it);
- if(drawableImpl.GetChanged())
+ if(HaveDrawablesChanged(it))
{
+ UpdateDrawablesChanged(it, false);
changed = true;
- drawableImpl.SetChanged(false);
}
}
}
else
{
- if(!mPixelBuffer.GetBuffer())
+ if(!mPixelBuffer || !mPixelBuffer.GetBuffer())
{
MakeTargetBuffer(mSize);
mChanged = false;
}
}
- if(mSize.width < 1.0f || mSize.height < 1.0f)
- {
- DALI_LOG_ERROR("Size is zero [%p]\n", this);
- return false;
- }
-
if(mTvgCanvas->clear() != tvg::Result::Success)
{
DALI_LOG_ERROR("ThorVG canvas clear fail [%p]\n", this);
PushDrawableToGroup(it, mTvgRoot);
}
- if(mTvgCanvas->push(move(scene)) != tvg::Result::Success)
- {
- DALI_LOG_ERROR("ThorVG canvas push fail [%p]\n", this);
- return false;
- }
-
- if(mViewBox != mSize)
+ if(mViewBox != mSize && mViewBox.width > 0 && mViewBox.height > 0)
{
auto scaleX = mSize.width / mViewBox.width;
auto scaleY = mSize.height / mViewBox.height;
mTvgRoot->scale(scaleX < scaleY ? scaleX : scaleY);
}
- mTvgCanvas->update(mTvgRoot);
-
- if(mTvgCanvas->draw() != tvg::Result::Success)
+ if(mTvgCanvas->push(move(scene)) != tvg::Result::Success)
{
- DALI_LOG_ERROR("ThorVG Draw fail [%p]\n", this);
+ DALI_LOG_ERROR("ThorVG canvas push fail [%p]\n", this);
return false;
}
- mTvgCanvas->sync();
-
return true;
#else
return false;
return false;
}
- if(mSize.width < 1.0f || mSize.height < 1.0f)
+ drawableImpl.SetAdded(true);
+ mDrawables.push_back(drawable);
+ mChanged = true;
+
+ return true;
+#else
+ return false;
+#endif
+}
+
+#ifdef THORVG_SUPPORT
+bool CanvasRendererTizen::HaveDrawablesChanged(const Dali::CanvasRenderer::Drawable& drawable) const
+{
+ const Internal::Adaptor::Drawable& drawableImpl = GetImplementation(drawable);
+ if(drawableImpl.GetChanged())
{
- DALI_LOG_ERROR("Size is zero [%p]\n", this);
+ return true;
+ }
+ Dali::CanvasRenderer::Drawable compositeDrawable = drawableImpl.GetCompositionDrawable();
+ if(DALI_UNLIKELY(compositeDrawable))
+ {
+ Internal::Adaptor::Drawable& compositeDrawableImpl = Dali::GetImplementation(compositeDrawable);
+ if(compositeDrawableImpl.GetChanged())
+ {
+ return true;
+ }
+ }
+
+ if(drawableImpl.GetType() == Drawable::Types::DRAWABLE_GROUP)
+ {
+ const Dali::CanvasRenderer::DrawableGroup& group = static_cast<const Dali::CanvasRenderer::DrawableGroup&>(drawable);
+ const Internal::Adaptor::DrawableGroup& drawableGroupImpl = Dali::GetImplementation(group);
+ DrawableGroup::DrawableVector drawables = drawableGroupImpl.GetDrawables();
+ for(auto& it : drawables)
+ {
+ if(HaveDrawablesChanged(it))
+ {
+ return true;
+ }
+ }
+ }
+ else if(drawableImpl.GetType() == Drawable::Types::SHAPE)
+ {
+ const Dali::CanvasRenderer::Shape& shape = static_cast<const Dali::CanvasRenderer::Shape&>(drawable);
+ Dali::CanvasRenderer::Gradient fillGradient = shape.GetFillGradient();
+ if(DALI_UNLIKELY(fillGradient))
+ {
+ Internal::Adaptor::Gradient& fillGradientImpl = Dali::GetImplementation(fillGradient);
+ if(fillGradientImpl.GetChanged())
+ {
+ return true;
+ }
+ }
+
+ Dali::CanvasRenderer::Gradient strokeGradient = shape.GetStrokeGradient();
+ if(DALI_UNLIKELY(strokeGradient))
+ {
+ Internal::Adaptor::Gradient& strokeGradientImpl = Dali::GetImplementation(strokeGradient);
+ if(strokeGradientImpl.GetChanged())
+ {
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
+void CanvasRendererTizen::UpdateDrawablesChanged(Dali::CanvasRenderer::Drawable& drawable, bool changed)
+{
+ Internal::Adaptor::Drawable& drawableImpl = GetImplementation(drawable);
+ drawableImpl.SetChanged(changed);
+
+ Dali::CanvasRenderer::Drawable compositeDrawable = drawableImpl.GetCompositionDrawable();
+ if(DALI_UNLIKELY(compositeDrawable))
+ {
+ Internal::Adaptor::Drawable& compositeDrawableImpl = Dali::GetImplementation(compositeDrawable);
+ compositeDrawableImpl.SetChanged(changed);
+ }
+
+ if(drawableImpl.GetType() == Drawable::Types::DRAWABLE_GROUP)
+ {
+ Dali::CanvasRenderer::DrawableGroup& group = static_cast<Dali::CanvasRenderer::DrawableGroup&>(drawable);
+ Internal::Adaptor::DrawableGroup& drawableGroupImpl = Dali::GetImplementation(group);
+ DrawableGroup::DrawableVector drawables = drawableGroupImpl.GetDrawables();
+ for(auto& it : drawables)
+ {
+ UpdateDrawablesChanged(it, changed);
+ }
+ }
+ else if(drawableImpl.GetType() == Drawable::Types::SHAPE)
+ {
+ Dali::CanvasRenderer::Shape& shape = static_cast<Dali::CanvasRenderer::Shape&>(drawable);
+ Dali::CanvasRenderer::Gradient fillGradient = shape.GetFillGradient();
+ if(DALI_UNLIKELY(fillGradient))
+ {
+ Internal::Adaptor::Gradient& fillGradientImpl = Dali::GetImplementation(fillGradient);
+ fillGradientImpl.SetChanged(changed);
+ }
+
+ Dali::CanvasRenderer::Gradient strokeGradient = shape.GetStrokeGradient();
+ if(DALI_UNLIKELY(strokeGradient))
+ {
+ Internal::Adaptor::Gradient& strokeGradientImpl = Dali::GetImplementation(strokeGradient);
+ strokeGradientImpl.SetChanged(changed);
+ }
+ }
+}
+#endif
+
+bool CanvasRendererTizen::IsCanvasChanged() const
+{
+#ifdef THORVG_SUPPORT
+ if(mChanged)
+ {
+ return true;
+ }
+
+ for(auto& it : mDrawables)
+ {
+ if(HaveDrawablesChanged(it))
+ {
+ return true;
+ }
+ }
+#endif
+ return false;
+}
+
+bool CanvasRendererTizen::Rasterize()
+{
+#ifdef THORVG_SUPPORT
+ Mutex::ScopedLock lock(mMutex);
+
+ if(mTvgCanvas->draw() != tvg::Result::Success)
+ {
+ DALI_LOG_ERROR("ThorVG Draw fail [%p]\n", this);
return false;
}
- drawableImpl.SetAdded(true);
- mDrawables.push_back(drawable);
+ mTvgCanvas->sync();
+
+ return true;
+#else
+ return false;
+#endif
+}
+
+bool CanvasRendererTizen::RemoveDrawable(Dali::CanvasRenderer::Drawable& drawable)
+{
+#ifdef THORVG_SUPPORT
+ DrawableGroup::DrawableVector::iterator it = std::find(mDrawables.begin(), mDrawables.end(), drawable);
+ if(it != mDrawables.end())
+ {
+ Internal::Adaptor::Drawable& drawableImpl = GetImplementation(drawable);
+ drawableImpl.SetAdded(false);
+
+ mDrawables.erase(it);
+ mChanged = true;
+
+ return true;
+ }
+
+#endif
+ return false;
+}
+
+bool CanvasRendererTizen::RemoveAllDrawables()
+{
+#ifdef THORVG_SUPPORT
+ for(auto& it : mDrawables)
+ {
+ Internal::Adaptor::Drawable& drawableImpl = GetImplementation(it);
+ drawableImpl.SetAdded(false);
+ }
+
+ mDrawables.clear();
mChanged = true;
return true;
#endif
}
-bool CanvasRendererTizen::SetSize(const Vector2& size)
+bool CanvasRendererTizen::SetSize(Vector2 size)
{
if(size.width < 1.0f || size.height < 1.0f)
{
if(size != mSize)
{
- mSize = size;
- MakeTargetBuffer(size);
+ mSize = size;
+ mChanged = true;
}
- mChanged = true;
-
return true;
}
-const Vector2& CanvasRendererTizen::GetSize()
+Vector2 CanvasRendererTizen::GetSize() const
{
return mSize;
}
+bool CanvasRendererTizen::SetViewBox(const Vector2& viewBox)
+{
+ if(viewBox.width < 1.0f || viewBox.height < 1.0f)
+ {
+ return false;
+ }
+
+ if(viewBox != mViewBox)
+ {
+ mViewBox = viewBox;
+ mChanged = true;
+ }
+
+ return true;
+}
+
+const Vector2& CanvasRendererTizen::GetViewBox()
+{
+ return mViewBox;
+}
+
void CanvasRendererTizen::MakeTargetBuffer(const Vector2& size)
{
#ifdef THORVG_SUPPORT
PushDrawableToGroup(it, static_cast<tvg::Scene*>(tvgDuplicatedObject));
}
}
+ else if(type == Drawable::Types::SHAPE)
+ {
+ //FillGradient
+ Dali::CanvasRenderer::Shape& shape = static_cast<Dali::CanvasRenderer::Shape&>(drawable);
+ Dali::CanvasRenderer::Gradient fillGradient = shape.GetFillGradient();
+ if(DALI_UNLIKELY(fillGradient))
+ {
+ Internal::Adaptor::Gradient& fillGradientImpl = Dali::GetImplementation(fillGradient);
+ tvg::Fill* tvgDuplicatedFillGradient = static_cast<tvg::Fill*>(fillGradientImpl.GetObject())->duplicate();
+ if(!tvgDuplicatedFillGradient)
+ {
+ DALI_LOG_ERROR("Invalid gradient object [%p]\n", this);
+ return;
+ }
+ if(static_cast<tvg::Shape*>(tvgDuplicatedObject)->fill(std::unique_ptr<tvg::Fill>(tvgDuplicatedFillGradient)) != tvg::Result::Success)
+ {
+ DALI_LOG_ERROR("Tvg gradient set fail [%p]\n", this);
+ return;
+ }
+ }
+
+ //StrokeGradient
+ Dali::CanvasRenderer::Gradient strokeGradient = shape.GetStrokeGradient();
+ if(DALI_UNLIKELY(strokeGradient))
+ {
+ Internal::Adaptor::Gradient& strokeGradientImpl = Dali::GetImplementation(strokeGradient);
+ tvg::Fill* tvgDuplicatedStrokeGradient = static_cast<tvg::Fill*>(strokeGradientImpl.GetObject())->duplicate();
+ if(!tvgDuplicatedStrokeGradient)
+ {
+ DALI_LOG_ERROR("Invalid gradient object [%p]\n", this);
+ return;
+ }
+ if(static_cast<tvg::Shape*>(tvgDuplicatedObject)->stroke(std::unique_ptr<tvg::Fill>(tvgDuplicatedStrokeGradient)) != tvg::Result::Success)
+ {
+ DALI_LOG_ERROR("Tvg gradient set fail [%p]\n", this);
+ return;
+ }
+ }
+ }
Dali::CanvasRenderer::Drawable compositeDrawable = drawableImpl.GetCompositionDrawable();
if(DALI_UNLIKELY(compositeDrawable))