mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-14 20:14:37 +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);
|
void strokeReset(SwStroke* stroke, const Shape* shape, const Matrix* transform);
|
||||||
bool strokeParseOutline(SwStroke* stroke, const SwOutline& outline);
|
bool strokeParseOutline(SwStroke* stroke, const SwOutline& outline);
|
||||||
SwOutline* strokeExportOutline(SwStroke* stroke);
|
SwOutline* strokeExportOutline(SwStroke* stroke, unsigned tid);
|
||||||
void strokeFree(SwStroke* stroke);
|
void strokeFree(SwStroke* stroke);
|
||||||
|
|
||||||
bool fillGenColorTable(SwFill* fill, const Fill* fdata, const Matrix* transform, SwSurface* surface, bool ctable);
|
bool fillGenColorTable(SwFill* fill, const Fill* fdata, const Matrix* transform, SwSurface* surface, bool ctable);
|
||||||
|
@ -300,6 +300,8 @@ bool mpoolTerm();
|
||||||
bool mpoolClear();
|
bool mpoolClear();
|
||||||
SwOutline* mpoolReqOutline(unsigned idx);
|
SwOutline* mpoolReqOutline(unsigned idx);
|
||||||
void mpoolRetOutline(unsigned idx);
|
void mpoolRetOutline(unsigned idx);
|
||||||
|
SwOutline* mpoolReqStrokeOutline(unsigned idx);
|
||||||
|
void mpoolRetStrokeOutline(unsigned idx);
|
||||||
|
|
||||||
bool rasterCompositor(SwSurface* surface);
|
bool rasterCompositor(SwSurface* surface);
|
||||||
bool rasterGradientShape(SwSurface* surface, SwShape* shape, unsigned id);
|
bool rasterGradientShape(SwSurface* surface, SwShape* shape, unsigned id);
|
||||||
|
|
|
@ -27,8 +27,8 @@
|
||||||
/* Internal Class Implementation */
|
/* Internal Class Implementation */
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
|
|
||||||
static unsigned threadsCnt = 1;
|
static vector<SwOutline> outline;
|
||||||
static vector<SwOutline> sharedOutline;
|
static vector<SwOutline> strokeOutline;
|
||||||
|
|
||||||
|
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
|
@ -37,25 +37,49 @@ static vector<SwOutline> sharedOutline;
|
||||||
|
|
||||||
SwOutline* mpoolReqOutline(unsigned idx)
|
SwOutline* mpoolReqOutline(unsigned idx)
|
||||||
{
|
{
|
||||||
return &sharedOutline[idx];
|
return &outline[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void mpoolRetOutline(unsigned idx)
|
void mpoolRetOutline(unsigned idx)
|
||||||
{
|
{
|
||||||
sharedOutline[idx].cntrsCnt = 0;
|
outline[idx].cntrsCnt = 0;
|
||||||
sharedOutline[idx].ptsCnt = 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)
|
bool mpoolInit(unsigned threads)
|
||||||
{
|
{
|
||||||
if (threads == 0) threads = 1;
|
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.cntrs = nullptr;
|
||||||
outline.pts = nullptr;
|
outline.pts = nullptr;
|
||||||
outline.types = nullptr;
|
outline.types = nullptr;
|
||||||
|
@ -69,7 +93,7 @@ bool mpoolInit(unsigned threads)
|
||||||
|
|
||||||
bool mpoolClear()
|
bool mpoolClear()
|
||||||
{
|
{
|
||||||
for (auto& outline : sharedOutline) {
|
for (auto& outline : outline) {
|
||||||
if (outline.cntrs) {
|
if (outline.cntrs) {
|
||||||
free(outline.cntrs);
|
free(outline.cntrs);
|
||||||
outline.cntrs = nullptr;
|
outline.cntrs = nullptr;
|
||||||
|
@ -85,6 +109,24 @@ bool mpoolClear()
|
||||||
outline.cntrsCnt = outline.reservedCntrsCnt = 0;
|
outline.cntrsCnt = outline.reservedCntrsCnt = 0;
|
||||||
outline.ptsCnt = outline.reservedPtsCnt = 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;
|
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)
|
static void _outlineEnd(SwOutline& outline)
|
||||||
{
|
{
|
||||||
_growOutlineContour(outline, 1);
|
_growOutlineContour(outline, 1);
|
||||||
|
@ -639,7 +628,7 @@ bool shapeGenStrokeRle(SwShape* shape, const Shape* sdata, unsigned tid, const M
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
strokeOutline = strokeExportOutline(shape->stroke);
|
strokeOutline = strokeExportOutline(shape->stroke, tid);
|
||||||
if (!strokeOutline) {
|
if (!strokeOutline) {
|
||||||
ret = false;
|
ret = false;
|
||||||
goto fail;
|
goto fail;
|
||||||
|
@ -656,8 +645,12 @@ bool shapeGenStrokeRle(SwShape* shape, const Shape* sdata, unsigned tid, const M
|
||||||
shape->strokeRle = rleRender(strokeOutline, bbox, clip, true);
|
shape->strokeRle = rleRender(strokeOutline, bbox, clip, true);
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
if (freeOutline) _delOutline(shapeOutline);
|
if (freeOutline) {
|
||||||
_delOutline(strokeOutline);
|
if (shapeOutline->cntrs) free(shapeOutline->cntrs);
|
||||||
|
if (shapeOutline->pts) free(shapeOutline->pts);
|
||||||
|
if (shapeOutline->types) free(shapeOutline->types);
|
||||||
|
}
|
||||||
|
mpoolRetStrokeOutline(tid);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
/* Internal Class Implementation */
|
/* Internal Class Implementation */
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
|
|
||||||
static constexpr auto SW_STROKE_TAG_POINT = 1;
|
static constexpr auto SW_STROKE_TAG_POINT = 1;
|
||||||
static constexpr auto SW_STROKE_TAG_CUBIC = 2;
|
static constexpr auto SW_STROKE_TAG_CUBIC = 2;
|
||||||
static constexpr auto SW_STROKE_TAG_BEGIN = 4;
|
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;
|
uint32_t count1, count2, count3, count4;
|
||||||
|
|
||||||
|
@ -914,10 +915,18 @@ SwOutline* strokeExportOutline(SwStroke* stroke)
|
||||||
auto ptsCnt = count1 + count3;
|
auto ptsCnt = count1 + count3;
|
||||||
auto cntrsCnt = count2 + count4;
|
auto cntrsCnt = count2 + count4;
|
||||||
|
|
||||||
auto outline = static_cast<SwOutline*>(calloc(1, sizeof(SwOutline)));
|
auto outline = mpoolReqStrokeOutline(tid);
|
||||||
outline->pts = static_cast<SwPoint*>(malloc(sizeof(SwPoint) * ptsCnt));
|
if (outline->reservedPtsCnt < ptsCnt) {
|
||||||
outline->types = static_cast<uint8_t*>(malloc(sizeof(uint8_t) * ptsCnt));
|
outline->pts = static_cast<SwPoint*>(realloc(outline->pts, sizeof(SwPoint) * ptsCnt));
|
||||||
outline->cntrs = static_cast<uint32_t*>(malloc(sizeof(uint32_t) * cntrsCnt));
|
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, 0); //left
|
||||||
_exportBorderOutline(*stroke, outline, 1); //right
|
_exportBorderOutline(*stroke, outline, 1); //right
|
||||||
|
|
Loading…
Add table
Reference in a new issue