mirror of
https://github.com/thorvg/thorvg.git
synced 2025-07-24 15:19:06 +00:00
sw_engine: utilize the memory pool for dash stroking.
This commit is contained in:
parent
64a444aeb6
commit
78cb32794a
3 changed files with 45 additions and 58 deletions
|
@ -271,6 +271,7 @@ struct SwMpool
|
|||
{
|
||||
SwOutline* outline;
|
||||
SwOutline* strokeOutline;
|
||||
SwOutline* dashOutline;
|
||||
unsigned allocSize;
|
||||
};
|
||||
|
||||
|
@ -542,6 +543,8 @@ SwOutline* mpoolReqOutline(SwMpool* mpool, unsigned idx);
|
|||
void mpoolRetOutline(SwMpool* mpool, unsigned idx);
|
||||
SwOutline* mpoolReqStrokeOutline(SwMpool* mpool, unsigned idx);
|
||||
void mpoolRetStrokeOutline(SwMpool* mpool, unsigned idx);
|
||||
SwOutline* mpoolReqDashOutline(SwMpool* mpool, unsigned idx);
|
||||
void mpoolRetDashOutline(SwMpool* mpool, unsigned idx);
|
||||
|
||||
bool rasterCompositor(SwSurface* surface);
|
||||
bool rasterGradientShape(SwSurface* surface, SwShape* shape, unsigned id);
|
||||
|
|
|
@ -62,54 +62,52 @@ void mpoolRetStrokeOutline(SwMpool* mpool, unsigned idx)
|
|||
}
|
||||
|
||||
|
||||
SwOutline* mpoolReqDashOutline(SwMpool* mpool, unsigned idx)
|
||||
{
|
||||
return &mpool->dashOutline[idx];
|
||||
}
|
||||
|
||||
|
||||
void mpoolRetDashOutline(SwMpool* mpool, unsigned idx)
|
||||
{
|
||||
mpool->dashOutline[idx].pts.clear();
|
||||
mpool->dashOutline[idx].cntrs.clear();
|
||||
mpool->dashOutline[idx].types.clear();
|
||||
mpool->dashOutline[idx].closed.clear();
|
||||
}
|
||||
|
||||
|
||||
SwMpool* mpoolInit(unsigned threads)
|
||||
{
|
||||
auto allocSize = threads + 1;
|
||||
|
||||
auto mpool = static_cast<SwMpool*>(calloc(sizeof(SwMpool), 1));
|
||||
mpool->outline = static_cast<SwOutline*>(calloc(1, sizeof(SwOutline) * allocSize));
|
||||
if (!mpool->outline) goto err;
|
||||
|
||||
mpool->strokeOutline = static_cast<SwOutline*>(calloc(1, sizeof(SwOutline) * allocSize));
|
||||
if (!mpool->strokeOutline) goto err;
|
||||
|
||||
mpool->dashOutline = static_cast<SwOutline*>(calloc(1, sizeof(SwOutline) * allocSize));
|
||||
mpool->allocSize = allocSize;
|
||||
|
||||
return mpool;
|
||||
|
||||
err:
|
||||
if (mpool->outline) {
|
||||
free(mpool->outline);
|
||||
mpool->outline = nullptr;
|
||||
}
|
||||
|
||||
if (mpool->strokeOutline) {
|
||||
free(mpool->strokeOutline);
|
||||
mpool->strokeOutline = nullptr;
|
||||
}
|
||||
free(mpool);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
bool mpoolClear(SwMpool* mpool)
|
||||
{
|
||||
SwOutline* p;
|
||||
|
||||
for (unsigned i = 0; i < mpool->allocSize; ++i) {
|
||||
//Outline
|
||||
p = &mpool->outline[i];
|
||||
p->pts.reset();
|
||||
p->cntrs.reset();
|
||||
p->types.reset();
|
||||
p->closed.reset();
|
||||
mpool->outline[i].pts.reset();
|
||||
mpool->outline[i].cntrs.reset();
|
||||
mpool->outline[i].types.reset();
|
||||
mpool->outline[i].closed.reset();
|
||||
|
||||
//StrokeOutline
|
||||
p = &mpool->strokeOutline[i];
|
||||
p->pts.reset();
|
||||
p->cntrs.reset();
|
||||
p->types.reset();
|
||||
p->closed.reset();
|
||||
mpool->strokeOutline[i].pts.reset();
|
||||
mpool->strokeOutline[i].cntrs.reset();
|
||||
mpool->strokeOutline[i].types.reset();
|
||||
mpool->strokeOutline[i].closed.reset();
|
||||
|
||||
mpool->dashOutline[i].pts.reset();
|
||||
mpool->dashOutline[i].cntrs.reset();
|
||||
mpool->dashOutline[i].types.reset();
|
||||
mpool->dashOutline[i].closed.reset();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -122,16 +120,9 @@ bool mpoolTerm(SwMpool* mpool)
|
|||
|
||||
mpoolClear(mpool);
|
||||
|
||||
if (mpool->outline) {
|
||||
free(mpool->outline);
|
||||
mpool->outline = nullptr;
|
||||
}
|
||||
|
||||
if (mpool->strokeOutline) {
|
||||
free(mpool->strokeOutline);
|
||||
mpool->strokeOutline = nullptr;
|
||||
}
|
||||
|
||||
free(mpool->outline);
|
||||
free(mpool->strokeOutline);
|
||||
free(mpool->dashOutline);
|
||||
free(mpool);
|
||||
|
||||
return true;
|
||||
|
|
|
@ -204,7 +204,7 @@ static void _dashCubicTo(SwDashStroke& dash, const Point* ctrl1, const Point* ct
|
|||
}
|
||||
|
||||
|
||||
static SwOutline* _genDashOutline(const RenderShape* rshape, const Matrix* transform, float length)
|
||||
static SwOutline* _genDashOutline(const RenderShape* rshape, const Matrix* transform, float length, SwMpool* mpool, unsigned tid)
|
||||
{
|
||||
const PathCommand* cmds = rshape->path.cmds.data;
|
||||
auto cmdCnt = rshape->path.cmds.count;
|
||||
|
@ -275,8 +275,7 @@ static SwOutline* _genDashOutline(const RenderShape* rshape, const Matrix* trans
|
|||
}
|
||||
}
|
||||
|
||||
//OPTMIZE ME: Use mempool???
|
||||
dash.outline = static_cast<SwOutline*>(calloc(1, sizeof(SwOutline)));
|
||||
dash.outline = mpoolReqDashOutline(mpool, tid);
|
||||
|
||||
//smart reservation
|
||||
auto closeCnt = 0;
|
||||
|
@ -559,16 +558,16 @@ bool shapeGenStrokeRle(SwShape* shape, const RenderShape* rshape, const Matrix*
|
|||
{
|
||||
SwOutline* shapeOutline = nullptr;
|
||||
SwOutline* strokeOutline = nullptr;
|
||||
bool freeOutline = false;
|
||||
bool ret = true;
|
||||
auto dashStroking = false;
|
||||
auto ret = true;
|
||||
|
||||
auto length = rshape->strokeTrim() ? _outlineLength(rshape) : 0.0f;
|
||||
|
||||
//Dash style (+trimming)
|
||||
if (rshape->stroke->dashCnt > 0 || length > 0) {
|
||||
shapeOutline = _genDashOutline(rshape, transform, length);
|
||||
shapeOutline = _genDashOutline(rshape, transform, length, mpool, tid);
|
||||
if (!shapeOutline) return false;
|
||||
freeOutline = true;
|
||||
dashStroking = true;
|
||||
//Normal style
|
||||
} else {
|
||||
if (!shape->outline) {
|
||||
|
@ -579,26 +578,20 @@ bool shapeGenStrokeRle(SwShape* shape, const RenderShape* rshape, const Matrix*
|
|||
|
||||
if (!strokeParseOutline(shape->stroke, *shapeOutline)) {
|
||||
ret = false;
|
||||
goto fail;
|
||||
goto clear;
|
||||
}
|
||||
|
||||
strokeOutline = strokeExportOutline(shape->stroke, mpool, tid);
|
||||
|
||||
if (!mathUpdateOutlineBBox(strokeOutline, clipRegion, renderRegion, false)) {
|
||||
ret = false;
|
||||
goto fail;
|
||||
goto clear;
|
||||
}
|
||||
|
||||
shape->strokeRle = rleRender(shape->strokeRle, strokeOutline, renderRegion, true);
|
||||
|
||||
fail:
|
||||
if (freeOutline) {
|
||||
free(shapeOutline->cntrs.data);
|
||||
free(shapeOutline->pts.data);
|
||||
free(shapeOutline->types.data);
|
||||
free(shapeOutline->closed.data);
|
||||
free(shapeOutline);
|
||||
}
|
||||
clear:
|
||||
if (dashStroking) mpoolRetDashOutline(mpool, tid);
|
||||
mpoolRetStrokeOutline(mpool, tid);
|
||||
|
||||
return ret;
|
||||
|
|
Loading…
Add table
Reference in a new issue