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 1b61fd2..ae051d8 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 a4814bd..817f547 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 42ae67a..d6bc7f6 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 6b37552..a39d005 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;