CanvasRenderer: Add Drawable::SetClipPath() Api
[platform/core/uifw/dali-adaptor.git] / dali / internal / canvas-renderer / ubuntu / drawable-impl-ubuntu.cpp
index 4c8a411..f4cb431 100644 (file)
@@ -48,7 +48,10 @@ DrawableUbuntu* DrawableUbuntu::New()
 
 DrawableUbuntu::DrawableUbuntu()
 : mAdded(false),
-  mChanged(false)
+  mChanged(false),
+  mType(Drawable::Types::NONE),
+  mCompositionType(Drawable::CompositionType::NONE),
+  mCompositionDrawable()
 #ifdef THORVG_SUPPORT
   ,
   mTvgPaint(nullptr)
@@ -59,7 +62,7 @@ DrawableUbuntu::DrawableUbuntu()
 DrawableUbuntu::~DrawableUbuntu()
 {
 #ifdef THORVG_SUPPORT
-  if(mTvgPaint && !mAdded)
+  if(mTvgPaint)
   {
     delete mTvgPaint;
   }
@@ -209,11 +212,53 @@ Rect<float> DrawableUbuntu::GetBoundingBox() const
 #endif
 }
 
-void DrawableUbuntu::SetDrawableAdded(bool added)
+bool DrawableUbuntu::SetClipPath(Dali::CanvasRenderer::Drawable& clip)
+{
+#ifdef THORVG_SUPPORT
+  if(!mTvgPaint)
+  {
+    DALI_LOG_ERROR("Drawable is null\n");
+    return false;
+  }
+
+  Internal::Adaptor::Drawable& drawableImpl = Dali::GetImplementation(clip);
+  if(drawableImpl.IsAdded())
+  {
+    DALI_LOG_ERROR("Already used [%p][%p]\n", this, &clip);
+    return false;
+  }
+
+  drawableImpl.SetAdded(true);
+  mCompositionDrawable = clip;
+  mCompositionType     = Drawable::CompositionType::CLIP_PATH;
+  Drawable::SetChanged(true);
+
+  return true;
+#else
+  return false;
+#endif
+}
+
+Dali::CanvasRenderer::Drawable DrawableUbuntu::GetCompositionDrawable() const
+{
+  return mCompositionDrawable;
+}
+
+Drawable::CompositionType DrawableUbuntu::GetCompositionType() const
+{
+  return mCompositionType;
+}
+
+void DrawableUbuntu::SetAdded(bool added)
 {
   mAdded = !!added;
 }
 
+bool DrawableUbuntu::IsAdded() const
+{
+  return mAdded;
+}
+
 void* DrawableUbuntu::GetObject() const
 {
 #ifdef THORVG_SUPPORT
@@ -230,17 +275,6 @@ void DrawableUbuntu::SetObject(const void* object)
   {
     mTvgPaint = static_cast<tvg::Paint*>((void*)object);
   }
-  else
-  {
-    if(mAdded)
-    {
-      mTvgPaint = nullptr;
-    }
-    if(mTvgPaint)
-    {
-      delete mTvgPaint;
-    }
-  }
 #endif
 }
 
@@ -254,6 +288,16 @@ bool DrawableUbuntu::GetChanged() const
 {
   return mChanged;
 }
+
+void DrawableUbuntu::SetType(Drawable::Types type)
+{
+  mType = type;
+}
+
+Drawable::Types DrawableUbuntu::GetType() const
+{
+  return mType;
+}
 } // namespace Adaptor
 
 } // namespace Internal