From 809dfd8644c4b41a0958a212f24d2daa180bd51c Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Mon, 27 Apr 2020 01:52:44 +0900 Subject: [PATCH] canvas: add reserve() method. 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 | 1 + src/lib/tvgCanvas.cpp | 8 ++++++++ test/testMultiShapes.cpp | 2 +- test/testShape.cpp | 2 +- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/inc/tizenvg.h b/inc/tizenvg.h index babca5d4..1aee6bb8 100644 --- a/inc/tizenvg.h +++ b/inc/tizenvg.h @@ -90,6 +90,7 @@ public: Canvas(RenderMethod*); virtual ~Canvas(); + int reserve(size_t n); virtual int push(std::unique_ptr paint) noexcept; virtual int clear() noexcept; virtual int update() noexcept; diff --git a/src/lib/tvgCanvas.cpp b/src/lib/tvgCanvas.cpp index 3bde24f6..96b58e0c 100644 --- a/src/lib/tvgCanvas.cpp +++ b/src/lib/tvgCanvas.cpp @@ -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 paint) noexcept { auto impl = pImpl.get(); diff --git a/test/testMultiShapes.cpp b/test/testMultiShapes.cpp index 94d3c31f..6fc0469f 100644 --- a/test/testMultiShapes.cpp +++ b/test/testMultiShapes.cpp @@ -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(); diff --git a/test/testShape.cpp b/test/testShape.cpp index c806d990..b7fca2f9 100644 --- a/test/testShape.cpp +++ b/test/testShape.cpp @@ -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