common canvas: revise clear method.
authorHermet Park <chuneon.park@samsung.com>
Thu, 8 Oct 2020 02:55:50 +0000 (11:55 +0900)
committerHermet Park <chuneon.park@samsung.com>
Thu, 8 Oct 2020 03:15:45 +0000 (12:15 +0900)
Canvas::clear() introduces a new argument "free" that deterimes freeing the retained paints.

If free is true, Canvas won't delete the retained paints so that user keep paints valid.

In this scenario, user must have paints pointers, free them manually or push them again to the canvas.

This scenario is useful if user wants to re-organize paints order in the list or reuse them.

Change-Id: Ib8c9125dafed301430eee4cd293434b8d84c0ed7

inc/thorvg.h
src/lib/tvgBezier.cpp
src/lib/tvgCanvas.cpp
src/lib/tvgCanvasImpl.h
src/lib/tvgPaint.h

index e339647..5b42f39 100644 (file)
@@ -148,7 +148,7 @@ public:
 
     Result reserve(uint32_t n) noexcept;
     virtual Result push(std::unique_ptr<Paint> paint) noexcept;
-    virtual Result clear() noexcept;
+    virtual Result clear(bool free = true) noexcept;
     virtual Result update(Paint* paint) noexcept;
     virtual Result draw() noexcept;
     virtual Result sync() noexcept;
index e597159..06f593e 100644 (file)
@@ -147,4 +147,4 @@ void bezSplitAt(const Bezier& cur, float at, Bezier& left, Bezier& right)
     bezSplitLeft(right, t, left);
 }
 
-}
+}
\ No newline at end of file
index eb08768..86b5e16 100644 (file)
@@ -49,9 +49,9 @@ Result Canvas::push(unique_ptr<Paint> paint) noexcept
 }
 
 
-Result Canvas::clear() noexcept
+Result Canvas::clear(bool free) noexcept
 {
-    return pImpl->clear();
+    return pImpl->clear(free);
 }
 
 
index 2aeef06..06a54af 100644 (file)
@@ -40,7 +40,7 @@ struct Canvas::Impl
 
     ~Impl()
     {
-        clear();
+        clear(true);
         delete(renderer);
     }
 
@@ -53,16 +53,19 @@ struct Canvas::Impl
         return update(p);
     }
 
-    Result clear()
+    Result clear(bool free)
     {
         if (!renderer) return Result::InsufficientCondition;
 
         //Clear render target before drawing
         if (!renderer->clear()) return Result::InsufficientCondition;
 
-        for (auto paint : paints) {
-            paint->pImpl->dispose(*renderer);
-            delete(paint);
+        //free paints
+        if (free) {
+            for (auto paint : paints) {
+                paint->pImpl->dispose(*renderer);
+                delete(paint);
+            }
         }
 
         paints.clear();
@@ -79,7 +82,7 @@ struct Canvas::Impl
         //Update single paint node
         if (paint) {
             paint->pImpl->update(*renderer, nullptr, compList, RenderUpdateFlag::None);
-        //Update retained all paint nodes
+        //Update all retained paint nodes
         } else {
             for (auto paint: paints) {
                 paint->pImpl->update(*renderer, nullptr, compList, RenderUpdateFlag::None);
index b84a7e1..2c4a63d 100644 (file)
@@ -123,7 +123,7 @@ namespace tvg
 
         bool dispose(RenderMethod& renderer)
         {
-            if (this->compTarget) this->compTarget->pImpl->dispose(renderer);
+            if (compTarget) compTarget->pImpl->dispose(renderer);
             return smethod->dispose(renderer);
         }