sw_engine: flush memory pool after drawing.
authorHermet Park <chuneon.park@samsung.com>
Wed, 28 Jul 2021 08:14:34 +0000 (17:14 +0900)
committerJunsuChoi <jsuya.choi@samsung.com>
Thu, 29 Jul 2021 01:14:54 +0000 (10:14 +0900)
if many canvas instances own private memory pool,
the memory usage can be increased linearly.

To prevent memory usage, flush out memory pool from the clear()
if the canvas uses private memory pool.

src/lib/sw_engine/tvgSwMemPool.cpp
src/lib/sw_engine/tvgSwRenderer.cpp
src/lib/sw_engine/tvgSwRle.cpp
src/lib/sw_engine/tvgSwStroke.cpp

index 1b61fd291424cbb233282ad71dc7454eb08cb428..ae051d81060ae12341eacf6538eb4c70cf0c9e1b 100644 (file)
@@ -95,37 +95,33 @@ bool mpoolClear(SwMpool* mpool)
 
     for (unsigned i = 0; i < mpool->allocSize; ++i) {
 
+        //Outline
         p = &mpool->outline[i];
 
-        if (p->cntrs) {
-            free(p->cntrs);
-            p->cntrs = nullptr;
-        }
-        if (p->pts) {
-            free(p->pts);
-            p->pts = nullptr;
-        }
-        if (p->types) {
-            free(p->types);
-            p->types = nullptr;
-        }
+        free(p->cntrs);
+        p->cntrs = nullptr;
+
+        free(p->pts);
+        p->pts = nullptr;
+
+        free(p->types);
+        p->types = nullptr;
+
         p->cntrsCnt = p->reservedCntrsCnt = 0;
         p->ptsCnt = p->reservedPtsCnt = 0;
 
+        //StrokeOutline
         p = &mpool->strokeOutline[i];
 
-        if (p->cntrs) {
-            free(p->cntrs);
-            p->cntrs = nullptr;
-        }
-        if (p->pts) {
-            free(p->pts);
-            p->pts = nullptr;
-        }
-        if (p->types) {
-            free(p->types);
-            p->types = nullptr;
-        }
+        free(p->cntrs);
+        p->cntrs = nullptr;
+
+        free(p->pts);
+        p->pts = nullptr;
+
+        free(p->types);
+        p->types = nullptr;
+
         p->cntrsCnt = p->reservedCntrsCnt = 0;
         p->ptsCnt = p->reservedPtsCnt = 0;
     }
index a4814bd47cafeeb7defce4f98d9e4c919b635571..817f54728171e25bb6f91c01770ac9a414dfbb2b 100644 (file)
@@ -223,7 +223,6 @@ static void _termEngine()
 
 SwRenderer::~SwRenderer()
 {
-    clear();
     clearCompositors();
 
     if (surface) delete(surface);
@@ -241,6 +240,8 @@ bool SwRenderer::clear()
     for (auto task = tasks.data; task < (tasks.data + tasks.count); ++task) (*task)->done();
     tasks.clear();
 
+    if (!sharedMpool) mpoolClear(mpool);
+
     if (surface) {
         vport.x = vport.y = 0;
         vport.w = surface->w;
index 42ae67aa308631d8ebced0fd1a0f91e101a59379..d6bc7f6e76e31732e6a023d82a1b9d04b78548ec 100644 (file)
@@ -141,6 +141,7 @@ static void _genSpan(SwRleData* rle, const SwSpan* spans, uint32_t count)
     /* when the rle needs to be regenerated because of attribute change. */
     if (rle->alloc < newSize) {
         rle->alloc = (newSize * 2);
+        //OPTIMIZE: use mempool!
         rle->spans = static_cast<SwSpan*>(realloc(rle->spans, rle->alloc * sizeof(SwSpan)));
     }
 
@@ -162,7 +163,7 @@ static void _horizLine(RleWorker& rw, SwCoord x, SwCoord y, SwCoord area, SwCoor
 
     /* compute the coverage line's coverage, depending on the outline fill rule */
     /* the coverage percentage is area/(PIXEL_BITS*PIXEL_BITS*2) */
-    auto coverage = static_cast<int>(area >> (PIXEL_BITS * 2 + 1 - 8));    //range 0 - 256
+    auto coverage = static_cast<int>(area >> (PIXEL_BITS * 2 + 1 - 8));    //range 0 - 255
 
     if (coverage < 0) coverage = -coverage;
 
@@ -247,12 +248,10 @@ static void _sweep(RleWorker& rw)
         auto cell = rw.yCells[y];
 
         while (cell) {
-
             if (cell->x > x && cover != 0) _horizLine(rw, x, y, cover * (ONE_PIXEL * 2), cell->x - x);
             cover += cell->cover;
             auto area = cover * (ONE_PIXEL * 2) - cell->area;
             if (area != 0 && cell->x >= 0) _horizLine(rw, cell->x, y, area, 1);
-
             x = cell->x + 1;
             cell = cell->next;
         }
index 6b375529f00e6c6de65c7d10b4d6d904970359a3..a39d0053c2079e3d92723ba7831c016942cbc97f 100644 (file)
@@ -56,7 +56,7 @@ static void _growBorder(SwStrokeBorder* border, uint32_t newPts)
 
     while (maxCur < maxNew)
         maxCur += (maxCur >> 1) + 16;
-
+    //OPTIMIZE: use mempool!
     border->pts = static_cast<SwPoint*>(realloc(border->pts, maxCur * sizeof(SwPoint)));
     border->tags = static_cast<uint8_t*>(realloc(border->tags, maxCur * sizeof(uint8_t)));
     border->maxPts = maxCur;