From: Hermet Park Date: Wed, 4 Nov 2020 10:58:14 +0000 (+0900) Subject: sw_engine mempool: performance optimization. X-Git-Tag: submit/tizen/20201108.215920~14 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8a80b15794d1ecda37f9427903941c641762064b;p=platform%2Fcore%2Fgraphics%2Ftizenvg.git sw_engine mempool: performance optimization. This is a subsequential trial of 1b8188ee676eae5c690b1b88bb823b6ad126bb78 for opimizing memory alloc count. In this time, it concentrates on stroke outline. @Issues: 75 Change-Id: I0f73b83cb7aee51186455d2312fa77cdb434ab3d --- diff --git a/src/lib/sw_engine/tvgSwCommon.h b/src/lib/sw_engine/tvgSwCommon.h index 3fc777f..c5c0822 100644 --- a/src/lib/sw_engine/tvgSwCommon.h +++ b/src/lib/sw_engine/tvgSwCommon.h @@ -281,7 +281,7 @@ void shapeDelFill(SwShape* shape); void strokeReset(SwStroke* stroke, const Shape* shape, const Matrix* transform); bool strokeParseOutline(SwStroke* stroke, const SwOutline& outline); -SwOutline* strokeExportOutline(SwStroke* stroke); +SwOutline* strokeExportOutline(SwStroke* stroke, unsigned tid); void strokeFree(SwStroke* stroke); bool fillGenColorTable(SwFill* fill, const Fill* fdata, const Matrix* transform, SwSurface* surface, bool ctable); @@ -300,6 +300,8 @@ bool mpoolTerm(); bool mpoolClear(); SwOutline* mpoolReqOutline(unsigned idx); void mpoolRetOutline(unsigned idx); +SwOutline* mpoolReqStrokeOutline(unsigned idx); +void mpoolRetStrokeOutline(unsigned idx); bool rasterCompositor(SwSurface* surface); bool rasterGradientShape(SwSurface* surface, SwShape* shape, unsigned id); diff --git a/src/lib/sw_engine/tvgSwMemPool.cpp b/src/lib/sw_engine/tvgSwMemPool.cpp index decf7e9..0c7b32c 100644 --- a/src/lib/sw_engine/tvgSwMemPool.cpp +++ b/src/lib/sw_engine/tvgSwMemPool.cpp @@ -27,8 +27,8 @@ /* Internal Class Implementation */ /************************************************************************/ -static unsigned threadsCnt = 1; -static vector sharedOutline; +static vector outline; +static vector strokeOutline; /************************************************************************/ @@ -37,25 +37,49 @@ static vector sharedOutline; SwOutline* mpoolReqOutline(unsigned idx) { - return &sharedOutline[idx]; + return &outline[idx]; } void mpoolRetOutline(unsigned idx) { - sharedOutline[idx].cntrsCnt = 0; - sharedOutline[idx].ptsCnt = 0; + outline[idx].cntrsCnt = 0; + outline[idx].ptsCnt = 0; +} + + +SwOutline* mpoolReqStrokeOutline(unsigned idx) +{ + return &strokeOutline[idx]; +} + + +void mpoolRetStrokeOutline(unsigned idx) +{ + strokeOutline[idx].cntrsCnt = 0; + strokeOutline[idx].ptsCnt = 0; } bool mpoolInit(unsigned threads) { if (threads == 0) threads = 1; - sharedOutline.reserve(threads); - sharedOutline.resize(threads); - threadsCnt = threads; - for (auto& outline : sharedOutline) { + outline.reserve(threads); + outline.resize(threads); + + for (auto& outline : outline) { + outline.cntrs = nullptr; + outline.pts = nullptr; + outline.types = nullptr; + outline.cntrsCnt = outline.reservedCntrsCnt = 0; + outline.ptsCnt = outline.reservedPtsCnt = 0; + } + + strokeOutline.reserve(threads); + strokeOutline.resize(threads); + + for (auto& outline : strokeOutline) { outline.cntrs = nullptr; outline.pts = nullptr; outline.types = nullptr; @@ -69,7 +93,7 @@ bool mpoolInit(unsigned threads) bool mpoolClear() { - for (auto& outline : sharedOutline) { + for (auto& outline : outline) { if (outline.cntrs) { free(outline.cntrs); outline.cntrs = nullptr; @@ -85,6 +109,24 @@ bool mpoolClear() outline.cntrsCnt = outline.reservedCntrsCnt = 0; outline.ptsCnt = outline.reservedPtsCnt = 0; } + + for (auto& outline : strokeOutline) { + if (outline.cntrs) { + free(outline.cntrs); + outline.cntrs = nullptr; + } + if (outline.pts) { + free(outline.pts); + outline.pts = nullptr; + } + if (outline.types) { + free(outline.types); + outline.types = nullptr; + } + outline.cntrsCnt = outline.reservedCntrsCnt = 0; + outline.ptsCnt = outline.reservedPtsCnt = 0; + } + return true; } diff --git a/src/lib/sw_engine/tvgSwShape.cpp b/src/lib/sw_engine/tvgSwShape.cpp index c5f4874..ed769a2 100644 --- a/src/lib/sw_engine/tvgSwShape.cpp +++ b/src/lib/sw_engine/tvgSwShape.cpp @@ -87,17 +87,6 @@ static void _growOutlinePoint(SwOutline& outline, uint32_t n) } -static void _delOutline(SwOutline* outline) -{ - if (!outline) return; - - if (outline->cntrs) free(outline->cntrs); - if (outline->pts) free(outline->pts); - if (outline->types) free(outline->types); - free(outline); -} - - static void _outlineEnd(SwOutline& outline) { _growOutlineContour(outline, 1); @@ -639,7 +628,7 @@ bool shapeGenStrokeRle(SwShape* shape, const Shape* sdata, unsigned tid, const M goto fail; } - strokeOutline = strokeExportOutline(shape->stroke); + strokeOutline = strokeExportOutline(shape->stroke, tid); if (!strokeOutline) { ret = false; goto fail; @@ -656,8 +645,12 @@ bool shapeGenStrokeRle(SwShape* shape, const Shape* sdata, unsigned tid, const M shape->strokeRle = rleRender(strokeOutline, bbox, clip, true); fail: - if (freeOutline) _delOutline(shapeOutline); - _delOutline(strokeOutline); + if (freeOutline) { + if (shapeOutline->cntrs) free(shapeOutline->cntrs); + if (shapeOutline->pts) free(shapeOutline->pts); + if (shapeOutline->types) free(shapeOutline->types); + } + mpoolRetStrokeOutline(tid); return ret; } diff --git a/src/lib/sw_engine/tvgSwStroke.cpp b/src/lib/sw_engine/tvgSwStroke.cpp index 9f2dfe1..db4b5e5 100644 --- a/src/lib/sw_engine/tvgSwStroke.cpp +++ b/src/lib/sw_engine/tvgSwStroke.cpp @@ -27,6 +27,7 @@ /************************************************************************/ /* Internal Class Implementation */ /************************************************************************/ + static constexpr auto SW_STROKE_TAG_POINT = 1; static constexpr auto SW_STROKE_TAG_CUBIC = 2; static constexpr auto SW_STROKE_TAG_BEGIN = 4; @@ -904,7 +905,7 @@ bool strokeParseOutline(SwStroke* stroke, const SwOutline& outline) } -SwOutline* strokeExportOutline(SwStroke* stroke) +SwOutline* strokeExportOutline(SwStroke* stroke, unsigned tid) { uint32_t count1, count2, count3, count4; @@ -914,10 +915,18 @@ SwOutline* strokeExportOutline(SwStroke* stroke) auto ptsCnt = count1 + count3; auto cntrsCnt = count2 + count4; - auto outline = static_cast(calloc(1, sizeof(SwOutline))); - outline->pts = static_cast(malloc(sizeof(SwPoint) * ptsCnt)); - outline->types = static_cast(malloc(sizeof(uint8_t) * ptsCnt)); - outline->cntrs = static_cast(malloc(sizeof(uint32_t) * cntrsCnt)); + auto outline = mpoolReqStrokeOutline(tid); + if (outline->reservedPtsCnt < ptsCnt) { + 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 _exportBorderOutline(*stroke, outline, 1); //right