canvas: add reserve() method. 24/231924/1
authorHermet Park <chuneon.park@samsung.com>
Sun, 26 Apr 2020 16:52:44 +0000 (01:52 +0900)
committerHermet Park <chuneon.park@samsung.com>
Sun, 26 Apr 2020 16:52:44 +0000 (01:52 +0900)
This allocates nodes slots in advance to avoid memory grow & copy.

it will be benefit if you know how many shapes will be used in your canvas.

Change-Id: I7d93d166c9c054078bd86593d3471a2ade3671ee

inc/tizenvg.h
src/lib/tvgCanvas.cpp
test/testMultiShapes.cpp
test/testShape.cpp

index babca5d..1aee6bb 100644 (file)
@@ -90,6 +90,7 @@ public:
     Canvas(RenderMethod*);
     virtual ~Canvas();
 
+    int reserve(size_t n);
     virtual int push(std::unique_ptr<PaintNode> paint) noexcept;
     virtual int clear() noexcept;
     virtual int update() noexcept;
index 3bde24f..96b58e0 100644 (file)
@@ -120,6 +120,14 @@ Canvas::~Canvas()
 }
 
 
+int Canvas::reserve(size_t n)
+{
+    auto impl = pImpl.get();
+    assert(impl);
+    return impl->reserve(n);
+}
+
+
 int Canvas::push(unique_ptr<PaintNode> paint) noexcept
 {
     auto impl = pImpl.get();
index 94d3c31..6fc0469 100644 (file)
@@ -15,7 +15,7 @@ void tvgtest()
 
     //Create a Canvas
     auto canvas = tvg::SwCanvas::gen(buffer, WIDTH, HEIGHT);
-    //canvas->reserve(2);      //reserve 2 shape nodes (optional)
+    canvas->reserve(3);                          //reserve 3 shape nodes (optional)
 
     //Prepare Round Rectangle
     auto shape1 = tvg::ShapeNode::gen();
index c806d99..b7fca2f 100644 (file)
@@ -18,7 +18,7 @@ void tvgtest()
 
     //Prepare a Shape (Rectangle)
     auto shape1 = tvg::ShapeNode::gen();
-    shape1->appendRect(0, 0, 400, 400, 0);      //x, y, w, h, cornerRadius
+    shape1->appendRect(100, 100, 400, 400, 0);  //x, y, w, h, cornerRadius
     shape1->fill(255, 0, 0, 255);               //r, g, b, a
 
     /* Push the shape into the Canvas drawing list