sw_engine rle: performance optimization.
authorHermet Park <chuneon.park@samsung.com>
Thu, 5 Nov 2020 07:34:14 +0000 (16:34 +0900)
committerHermet Park <chuneon.park@samsung.com>
Fri, 6 Nov 2020 02:28:06 +0000 (11:28 +0900)
Tis is a subsequential trial of 1b8188ee676eae5c690b1b88bb823b6ad126bb78
for opimizing memory alloc count.

In this time, it concentrates on rle span.

@Issues: 75

Change-Id: Ie7a0324c33856b2ac938f4300a280b5fb6d3b39f

src/lib/sw_engine/tvgSwCommon.h
src/lib/sw_engine/tvgSwRle.cpp
src/lib/sw_engine/tvgSwShape.cpp
src/lib/sw_engine/tvgSwStroke.cpp

index c5c0822..6e26224 100644 (file)
@@ -290,8 +290,9 @@ void fillFree(SwFill* fill);
 void fillFetchLinear(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, uint32_t offset, uint32_t len);
 void fillFetchRadial(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, uint32_t len);
 
-SwRleData* rleRender(const SwOutline* outline, const SwBBox& bbox, const SwSize& clip, bool antiAlias);
+SwRleData* rleRender(SwRleData* rle, const SwOutline* outline, const SwBBox& bbox, const SwSize& clip, bool antiAlias);
 void rleFree(SwRleData* rle);
+void rleReset(SwRleData* rle);
 void rleClipPath(SwRleData *rle, const SwRleData *clip);
 void rleClipRect(SwRleData *rle, const SwBBox* clip);
 
index 7c99c30..2afcc87 100644 (file)
@@ -707,7 +707,7 @@ SwSpan* _intersectSpansRect(const SwBBox *bbox, const SwRleData *targetRle, SwSp
 /* External Class Implementation                                        */
 /************************************************************************/
 
-SwRleData* rleRender(const SwOutline* outline, const SwBBox& bbox, const SwSize& clip, bool antiAlias)
+SwRleData* rleRender(SwRleData* rle, const SwOutline* outline, const SwBBox& bbox, const SwSize& clip, bool antiAlias)
 {
     constexpr auto RENDER_POOL_SIZE = 16384L;
     constexpr auto BAND_SIZE = 40;
@@ -736,7 +736,9 @@ SwRleData* rleRender(const SwOutline* outline, const SwBBox& bbox, const SwSize&
     rw.bandShoot = 0;
     rw.clip = clip;
     rw.antiAlias = antiAlias;
-    rw.rle = reinterpret_cast<SwRleData*>(calloc(1, sizeof(SwRleData)));
+
+    if (!rle) rw.rle = reinterpret_cast<SwRleData*>(calloc(1, sizeof(SwRleData)));
+    else rw.rle = rle;
 
     //Generate RLE
     Band bands[BAND_SIZE];
@@ -830,6 +832,13 @@ error:
 }
 
 
+void rleReset(SwRleData* rle)
+{
+    if (!rle) return;
+    rle->size = 0;
+}
+
+
 void rleFree(SwRleData* rle)
 {
     if (!rle) return;
index ed769a2..637663a 100644 (file)
@@ -459,7 +459,7 @@ bool shapeGenRle(SwShape* shape, TVG_UNUSED const Shape* sdata, const SwSize& cl
     //Case A: Fast Track Rectangle Drawing
     if (!hasComposite && (shape->rect = _fastTrack(shape->outline))) return true;
     //Case B: Normale Shape RLE Drawing
-    if ((shape->rle = rleRender(shape->outline, shape->bbox, clip, antiAlias))) return true;
+    if ((shape->rle = rleRender(shape->rle, shape->outline, shape->bbox, clip, antiAlias))) return true;
 
     return false;
 }
@@ -474,8 +474,7 @@ void shapeDelOutline(SwShape* shape, uint32_t tid)
 
 void shapeReset(SwShape* shape)
 {
-    rleFree(shape->rle);
-    shape->rle = nullptr;
+    rleReset(shape->rle);
     shape->rect = false;
     _initBBox(shape->bbox);
 }
@@ -597,9 +596,7 @@ void shapeResetStroke(SwShape* shape, const Shape* sdata, const Matrix* transfor
     if (!stroke) return;
 
     strokeReset(stroke, sdata, transform);
-
-    rleFree(shape->strokeRle);
-    shape->strokeRle = nullptr;
+    rleReset(shape->strokeRle);
 }
 
 
@@ -642,7 +639,7 @@ bool shapeGenStrokeRle(SwShape* shape, const Shape* sdata, unsigned tid, const M
         goto fail;
     }
 
-    shape->strokeRle = rleRender(strokeOutline, bbox, clip, true);
+    shape->strokeRle = rleRender(shape->strokeRle, strokeOutline, bbox, clip, true);
 
 fail:
     if (freeOutline) {
index db4b5e5..96c8b95 100644 (file)
@@ -920,12 +920,10 @@ SwOutline* strokeExportOutline(SwStroke* stroke, unsigned tid)
         outline->pts = static_cast<SwPoint*>(realloc(outline->pts, sizeof(SwPoint) * ptsCnt));
         outline->types = static_cast<uint8_t*>(realloc(outline->types, sizeof(uint8_t) * ptsCnt));
         outline->reservedPtsCnt = ptsCnt;
-        printf("pts(%d)\n", sizeof(SwPoint) * ptsCnt);
     }
     if (outline->reservedCntrsCnt < cntrsCnt) {
         outline->cntrs = static_cast<uint32_t*>(realloc(outline->cntrs, sizeof(uint32_t) * cntrsCnt));
         outline->reservedCntrsCnt = cntrsCnt;
-        printf("cntrs(%d)\n", sizeof(SwPoint) * ptsCnt);
     }
 
     _exportBorderOutline(*stroke, outline, 0);  //left