From a58e4fe22b08a924099c428a0e9d257fbdb22300 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Thu, 5 Nov 2020 16:34:14 +0900 Subject: [PATCH] sw_engine rle: performance optimization. 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 | 3 ++- src/lib/sw_engine/tvgSwRle.cpp | 13 +++++++++++-- src/lib/sw_engine/tvgSwShape.cpp | 11 ++++------- src/lib/sw_engine/tvgSwStroke.cpp | 2 -- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/lib/sw_engine/tvgSwCommon.h b/src/lib/sw_engine/tvgSwCommon.h index c5c0822..6e26224 100644 --- a/src/lib/sw_engine/tvgSwCommon.h +++ b/src/lib/sw_engine/tvgSwCommon.h @@ -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); diff --git a/src/lib/sw_engine/tvgSwRle.cpp b/src/lib/sw_engine/tvgSwRle.cpp index 7c99c30..2afcc87 100644 --- a/src/lib/sw_engine/tvgSwRle.cpp +++ b/src/lib/sw_engine/tvgSwRle.cpp @@ -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(calloc(1, sizeof(SwRleData))); + + if (!rle) rw.rle = reinterpret_cast(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; diff --git a/src/lib/sw_engine/tvgSwShape.cpp b/src/lib/sw_engine/tvgSwShape.cpp index ed769a2..637663a 100644 --- a/src/lib/sw_engine/tvgSwShape.cpp +++ b/src/lib/sw_engine/tvgSwShape.cpp @@ -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) { diff --git a/src/lib/sw_engine/tvgSwStroke.cpp b/src/lib/sw_engine/tvgSwStroke.cpp index db4b5e5..96c8b95 100644 --- a/src/lib/sw_engine/tvgSwStroke.cpp +++ b/src/lib/sw_engine/tvgSwStroke.cpp @@ -920,12 +920,10 @@ SwOutline* strokeExportOutline(SwStroke* stroke, unsigned tid) outline->pts = static_cast(realloc(outline->pts, sizeof(SwPoint) * ptsCnt)); outline->types = static_cast(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(realloc(outline->cntrs, sizeof(uint32_t) * cntrsCnt)); outline->reservedCntrsCnt = cntrsCnt; - printf("cntrs(%d)\n", sizeof(SwPoint) * ptsCnt); } _exportBorderOutline(*stroke, outline, 0); //left -- 2.7.4