return GetImplementation(*this).AddDrawable(drawable);
}
+bool CanvasRenderer::IsCanvasChanged() const
+{
+ return GetImplementation(*this).IsCanvasChanged();
+}
+
+bool CanvasRenderer::Rasterize()
+{
+ return GetImplementation(*this).Rasterize();
+}
+
bool CanvasRenderer::SetSize(const Vector2& size)
{
return GetImplementation(*this).SetSize(size);
public:
/**
- * @brief Draw inner canvas the contexts added to the CanvasRenderer.
+ * @brief Prepare for drawing drawables added to CanvasRenderer on inner canvas.
+ * @return Returns True when it's successful. False otherwise.
*/
bool Commit();
Devel::PixelBuffer GetPixelBuffer();
/**
+ * @brief Draw drawables added to CanvasRenderer to inner buffer.
+ * @return Returns True when it's successful. False otherwise.
+ */
+ bool Rasterize();
+
+ /**
+ * @brief Returns whether the drawables added to the Canvas are changed.
+ * @return Returns True when drawables added to the Canvas are changed, False otherwise.
+ */
+ bool IsCanvasChanged() const;
+
+ /**
* @brief This is the size of the buffer in the Canvas.
* @param[in] size The size of canvas buffer.
* @return Returns True when it's successful. False otherwise.
return false;
}
+bool CanvasRenderer::IsCanvasChanged() const
+{
+ return false;
+}
+
+bool CanvasRenderer::Rasterize()
+{
+ return false;
+}
+
bool CanvasRenderer::SetSize(const Vector2& size)
{
return false;
virtual bool AddDrawable(Dali::CanvasRenderer::Drawable& drawable);
/**
+ * @copydoc Dali::CanvasRenderer::IsCanvasChanged()
+ */
+ virtual bool IsCanvasChanged() const;
+
+ /**
+ * @copydoc Dali::CanvasRenderer::Rasterize()
+ */
+ virtual bool Rasterize();
+
+ /**
* @copydoc Dali::CanvasRenderer::SetSize()
*/
virtual bool SetSize(const Vector2& size);
return false;
}
+bool CanvasRendererGeneric::IsCanvasChanged() const
+{
+ return false;
+}
+
+bool CanvasRendererGeneric::Rasterize()
+{
+ return false;
+}
+
bool CanvasRendererGeneric::SetSize(const Vector2& size)
{
return false;
bool AddDrawable(Dali::CanvasRenderer::Drawable& drawable) override;
/**
+ * @copydoc Dali::CanvasRenderer::IsCanvasChanged()
+ */
+ virtual bool IsCanvasChanged() const;
+
+ /**
+ * @copydoc Dali::CanvasRenderer::Rasterize()
+ */
+ virtual bool Rasterize();
+
+ /**
* @copydoc Dali::CanvasRenderer::SetSize()
*/
bool SetSize(const Vector2& size) override;
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;
+ }
+
+ 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;
+ }
+ }
+ }
+
+ return false;
+}
+
+void CanvasRendererTizen::UpdateDrawablesChanged(Dali::CanvasRenderer::Drawable& drawable, bool changed)
+{
+ Internal::Adaptor::Drawable& drawableImpl = GetImplementation(drawable);
+ drawableImpl.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);
+ }
+ }
+}
+#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);
- mChanged = true;
+ mTvgCanvas->sync();
return true;
#else
if(size != mSize)
{
- mSize = size;
- MakeTargetBuffer(size);
+ mSize = size;
+ mChanged = true;
}
- mChanged = true;
-
return true;
}
#ifdef THORVG_SUPPORT
#include <thorvg.h>
#endif
+#include <dali/devel-api/threading/mutex.h>
#include <dali/public-api/object/weak-handle.h>
// INTERNAL INCLUDES
#include <dali/devel-api/adaptor-framework/canvas-renderer-drawable.h>
#include <dali/devel-api/adaptor-framework/canvas-renderer.h>
#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/canvas-renderer-impl.h>
+#include <dali/internal/canvas-renderer/common/drawable-group-impl.h>
namespace Dali
{
bool AddDrawable(Dali::CanvasRenderer::Drawable& drawable) override;
/**
+ * @copydoc Dali::CanvasRenderer::IsCanvasChanged()
+ */
+ bool IsCanvasChanged() const override;
+
+ /**
+ * @copydoc Dali::CanvasRenderer::Rasterize()
+ */
+ bool Rasterize() override;
+
+ /**
* @copydoc Dali::CanvasRenderer::SetSize()
*/
bool SetSize(const Vector2& size) override;
#ifdef THORVG_SUPPORT
/**
+ * @brief Get drawables changed status.
+ * If drawable is a type that can have child drawables, it is called recursively.
+ * @param[in] drawable The drawable object.
+ * @return Returns whether drawables have changed.
+ */
+ bool HaveDrawablesChanged(const Dali::CanvasRenderer::Drawable& drawable) const;
+
+ /**
+ * @brief Update drawables changed status.
+ * If drawable is a type that can have child drawables, it is called recursively.
+ * @param[in] drawable The drawable object.
+ * @param[in] changed The state of changed.
+ */
+ void UpdateDrawablesChanged(Dali::CanvasRenderer::Drawable& drawable, bool changed);
+
+ /**
* @brief Push drawable object to parent.
* If drawable is a type that can have child drawables, it is called recursively.
* @param[in] drawable The drawable object.
private:
Devel::PixelBuffer mPixelBuffer;
+ Dali::Mutex mMutex;
#ifdef THORVG_SUPPORT
std::unique_ptr<tvg::SwCanvas> mTvgCanvas;
bool CanvasRendererUbuntu::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 CanvasRendererUbuntu::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;
+ }
+
+ 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;
+ }
+ }
+ }
+
+ return false;
+}
+
+void CanvasRendererUbuntu::UpdateDrawablesChanged(Dali::CanvasRenderer::Drawable& drawable, bool changed)
+{
+ Internal::Adaptor::Drawable& drawableImpl = GetImplementation(drawable);
+ drawableImpl.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);
+ }
+ }
+}
+#endif
+
+bool CanvasRendererUbuntu::IsCanvasChanged() const
+{
+#ifdef THORVG_SUPPORT
+ if(mChanged)
+ {
+ return true;
+ }
+
+ for(auto& it : mDrawables)
+ {
+ if(HaveDrawablesChanged(it))
+ {
+ return true;
+ }
+ }
+#endif
+ return false;
+}
+
+bool CanvasRendererUbuntu::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);
- mChanged = true;
+ mTvgCanvas->sync();
return true;
#else
if(size != mSize)
{
- mSize = size;
- MakeTargetBuffer(size);
+ mSize = size;
+ mChanged = true;
}
- mChanged = true;
-
return true;
}
#ifdef THORVG_SUPPORT
#include <thorvg.h>
#endif
+#include <dali/devel-api/threading/mutex.h>
#include <dali/public-api/object/weak-handle.h>
// INTERNAL INCLUDES
#include <dali/devel-api/adaptor-framework/canvas-renderer-drawable.h>
#include <dali/devel-api/adaptor-framework/canvas-renderer.h>
#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/canvas-renderer-impl.h>
+#include <dali/internal/canvas-renderer/common/drawable-group-impl.h>
namespace Dali
{
bool AddDrawable(Dali::CanvasRenderer::Drawable& drawable) override;
/**
+ * @copydoc Dali::CanvasRenderer::IsCanvasChanged()
+ */
+ bool IsCanvasChanged() const override;
+
+ /**
+ * @copydoc Dali::CanvasRenderer::Rasterize()
+ */
+ bool Rasterize() override;
+
+ /**
* @copydoc Dali::CanvasRenderer::SetSize()
*/
bool SetSize(const Vector2& size) override;
#ifdef THORVG_SUPPORT
/**
+ * @brief Get drawables changed status.
+ * If drawable is a type that can have child drawables, it is called recursively.
+ * @param[in] drawable The drawable object.
+ * @return Returns whether drawables have changed.
+ */
+ bool HaveDrawablesChanged(const Dali::CanvasRenderer::Drawable& drawable) const;
+
+ /**
+ * @brief Update drawables changed status.
+ * If drawable is a type that can have child drawables, it is called recursively.
+ * @param[in] drawable The drawable object.
+ * @param[in] changed The state of changed.
+ */
+ void UpdateDrawablesChanged(Dali::CanvasRenderer::Drawable& drawable, bool changed);
+
+ /**
* @brief Push drawable object to parent.
* If drawable is a type that can have child drawables, it is called recursively.
* @param[in] drawable The drawable object.
private:
Devel::PixelBuffer mPixelBuffer;
+ Dali::Mutex mMutex;
#ifdef THORVG_SUPPORT
std::unique_ptr<tvg::SwCanvas> mTvgCanvas;