CanvasRenderer: Refactoring tvgObject management
[platform/core/uifw/dali-adaptor.git] / dali / internal / canvas-renderer / ubuntu / drawable-impl-ubuntu.cpp
index cc3de91..36a84aa 100644 (file)
@@ -48,7 +48,8 @@ DrawableUbuntu* DrawableUbuntu::New()
 
 DrawableUbuntu::DrawableUbuntu()
 : mAdded(false),
-  mChanged(false)
+  mChanged(false),
+  mType(Drawable::Types::NONE)
 #ifdef THORVG_SUPPORT
   ,
   mTvgPaint(nullptr)
@@ -59,7 +60,7 @@ DrawableUbuntu::DrawableUbuntu()
 DrawableUbuntu::~DrawableUbuntu()
 {
 #ifdef THORVG_SUPPORT
-  if(mTvgPaint && !mAdded)
+  if(mTvgPaint)
   {
     delete mTvgPaint;
   }
@@ -186,11 +187,39 @@ bool DrawableUbuntu::Transform(const Dali::Matrix3& matrix)
 #endif
 }
 
-void DrawableUbuntu::SetDrawableAdded(bool added)
+Rect<float> DrawableUbuntu::GetBoundingBox() const
+{
+#ifdef THORVG_SUPPORT
+  if(!mTvgPaint)
+  {
+    DALI_LOG_ERROR("Drawable is null\n");
+    return Rect<float>(0, 0, 0, 0);
+  }
+
+  float x, y, width, height;
+  x = y = width = height = 0;
+
+  if(mTvgPaint->bounds(&x, &y, &width, &height) != tvg::Result::Success)
+  {
+    DALI_LOG_ERROR("Get bounds fail.\n");
+    return Rect<float>(0, 0, 0, 0);
+  }
+  return Rect<float>(x, y, width, height);
+#else
+  return Rect<float>(0, 0, 0, 0);
+#endif
+}
+
+void DrawableUbuntu::SetAdded(bool added)
 {
   mAdded = !!added;
 }
 
+bool DrawableUbuntu::IsAdded() const
+{
+  return mAdded;
+}
+
 void* DrawableUbuntu::GetObject() const
 {
 #ifdef THORVG_SUPPORT
@@ -207,17 +236,6 @@ void DrawableUbuntu::SetObject(const void* object)
   {
     mTvgPaint = static_cast<tvg::Paint*>((void*)object);
   }
-  else
-  {
-    if(mAdded)
-    {
-      mTvgPaint = nullptr;
-    }
-    if(mTvgPaint)
-    {
-      delete mTvgPaint;
-    }
-  }
 #endif
 }
 
@@ -231,6 +249,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