mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-12 15:34:22 +00:00
sw_engine mempool: performance optimization.
This is a subsequential trial of 1b8188ee67
for opimizing memory alloc count.
In this time, it concentrates on stroke outline.
@Issues: 75
This commit is contained in:
parent
410fa6c115
commit
1d3c56e487
4 changed files with 76 additions and 30 deletions
|
@ -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);
|
||||
|
|
|
@ -27,8 +27,8 @@
|
|||
/* Internal Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
static unsigned threadsCnt = 1;
|
||||
static vector<SwOutline> sharedOutline;
|
||||
static vector<SwOutline> outline;
|
||||
static vector<SwOutline> strokeOutline;
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
|
@ -37,25 +37,49 @@ static vector<SwOutline> 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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<SwOutline*>(calloc(1, sizeof(SwOutline)));
|
||||
outline->pts = static_cast<SwPoint*>(malloc(sizeof(SwPoint) * ptsCnt));
|
||||
outline->types = static_cast<uint8_t*>(malloc(sizeof(uint8_t) * ptsCnt));
|
||||
outline->cntrs = static_cast<uint32_t*>(malloc(sizeof(uint32_t) * cntrsCnt));
|
||||
auto outline = mpoolReqStrokeOutline(tid);
|
||||
if (outline->reservedPtsCnt < ptsCnt) {
|
||||
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
|
||||
_exportBorderOutline(*stroke, outline, 1); //right
|
||||
|
|
Loading…
Add table
Reference in a new issue