mirror of
https://github.com/thorvg/thorvg.git
synced 2025-07-25 15:48:58 +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* outline;
|
||||||
SwOutline* strokeOutline;
|
SwOutline* strokeOutline;
|
||||||
|
SwOutline* dashOutline;
|
||||||
unsigned allocSize;
|
unsigned allocSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -542,6 +543,8 @@ SwOutline* mpoolReqOutline(SwMpool* mpool, unsigned idx);
|
||||||
void mpoolRetOutline(SwMpool* mpool, unsigned idx);
|
void mpoolRetOutline(SwMpool* mpool, unsigned idx);
|
||||||
SwOutline* mpoolReqStrokeOutline(SwMpool* mpool, unsigned idx);
|
SwOutline* mpoolReqStrokeOutline(SwMpool* mpool, unsigned idx);
|
||||||
void mpoolRetStrokeOutline(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 rasterCompositor(SwSurface* surface);
|
||||||
bool rasterGradientShape(SwSurface* surface, SwShape* shape, unsigned id);
|
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)
|
SwMpool* mpoolInit(unsigned threads)
|
||||||
{
|
{
|
||||||
auto allocSize = threads + 1;
|
auto allocSize = threads + 1;
|
||||||
|
|
||||||
auto mpool = static_cast<SwMpool*>(calloc(sizeof(SwMpool), 1));
|
auto mpool = static_cast<SwMpool*>(calloc(sizeof(SwMpool), 1));
|
||||||
mpool->outline = static_cast<SwOutline*>(calloc(1, sizeof(SwOutline) * allocSize));
|
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));
|
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;
|
mpool->allocSize = allocSize;
|
||||||
|
|
||||||
return mpool;
|
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)
|
bool mpoolClear(SwMpool* mpool)
|
||||||
{
|
{
|
||||||
SwOutline* p;
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < mpool->allocSize; ++i) {
|
for (unsigned i = 0; i < mpool->allocSize; ++i) {
|
||||||
//Outline
|
mpool->outline[i].pts.reset();
|
||||||
p = &mpool->outline[i];
|
mpool->outline[i].cntrs.reset();
|
||||||
p->pts.reset();
|
mpool->outline[i].types.reset();
|
||||||
p->cntrs.reset();
|
mpool->outline[i].closed.reset();
|
||||||
p->types.reset();
|
|
||||||
p->closed.reset();
|
|
||||||
|
|
||||||
//StrokeOutline
|
mpool->strokeOutline[i].pts.reset();
|
||||||
p = &mpool->strokeOutline[i];
|
mpool->strokeOutline[i].cntrs.reset();
|
||||||
p->pts.reset();
|
mpool->strokeOutline[i].types.reset();
|
||||||
p->cntrs.reset();
|
mpool->strokeOutline[i].closed.reset();
|
||||||
p->types.reset();
|
|
||||||
p->closed.reset();
|
mpool->dashOutline[i].pts.reset();
|
||||||
|
mpool->dashOutline[i].cntrs.reset();
|
||||||
|
mpool->dashOutline[i].types.reset();
|
||||||
|
mpool->dashOutline[i].closed.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -122,16 +120,9 @@ bool mpoolTerm(SwMpool* mpool)
|
||||||
|
|
||||||
mpoolClear(mpool);
|
mpoolClear(mpool);
|
||||||
|
|
||||||
if (mpool->outline) {
|
free(mpool->outline);
|
||||||
free(mpool->outline);
|
free(mpool->strokeOutline);
|
||||||
mpool->outline = nullptr;
|
free(mpool->dashOutline);
|
||||||
}
|
|
||||||
|
|
||||||
if (mpool->strokeOutline) {
|
|
||||||
free(mpool->strokeOutline);
|
|
||||||
mpool->strokeOutline = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
free(mpool);
|
free(mpool);
|
||||||
|
|
||||||
return true;
|
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;
|
const PathCommand* cmds = rshape->path.cmds.data;
|
||||||
auto cmdCnt = rshape->path.cmds.count;
|
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 = mpoolReqDashOutline(mpool, tid);
|
||||||
dash.outline = static_cast<SwOutline*>(calloc(1, sizeof(SwOutline)));
|
|
||||||
|
|
||||||
//smart reservation
|
//smart reservation
|
||||||
auto closeCnt = 0;
|
auto closeCnt = 0;
|
||||||
|
@ -559,16 +558,16 @@ bool shapeGenStrokeRle(SwShape* shape, const RenderShape* rshape, const Matrix*
|
||||||
{
|
{
|
||||||
SwOutline* shapeOutline = nullptr;
|
SwOutline* shapeOutline = nullptr;
|
||||||
SwOutline* strokeOutline = nullptr;
|
SwOutline* strokeOutline = nullptr;
|
||||||
bool freeOutline = false;
|
auto dashStroking = false;
|
||||||
bool ret = true;
|
auto ret = true;
|
||||||
|
|
||||||
auto length = rshape->strokeTrim() ? _outlineLength(rshape) : 0.0f;
|
auto length = rshape->strokeTrim() ? _outlineLength(rshape) : 0.0f;
|
||||||
|
|
||||||
//Dash style (+trimming)
|
//Dash style (+trimming)
|
||||||
if (rshape->stroke->dashCnt > 0 || length > 0) {
|
if (rshape->stroke->dashCnt > 0 || length > 0) {
|
||||||
shapeOutline = _genDashOutline(rshape, transform, length);
|
shapeOutline = _genDashOutline(rshape, transform, length, mpool, tid);
|
||||||
if (!shapeOutline) return false;
|
if (!shapeOutline) return false;
|
||||||
freeOutline = true;
|
dashStroking = true;
|
||||||
//Normal style
|
//Normal style
|
||||||
} else {
|
} else {
|
||||||
if (!shape->outline) {
|
if (!shape->outline) {
|
||||||
|
@ -579,26 +578,20 @@ bool shapeGenStrokeRle(SwShape* shape, const RenderShape* rshape, const Matrix*
|
||||||
|
|
||||||
if (!strokeParseOutline(shape->stroke, *shapeOutline)) {
|
if (!strokeParseOutline(shape->stroke, *shapeOutline)) {
|
||||||
ret = false;
|
ret = false;
|
||||||
goto fail;
|
goto clear;
|
||||||
}
|
}
|
||||||
|
|
||||||
strokeOutline = strokeExportOutline(shape->stroke, mpool, tid);
|
strokeOutline = strokeExportOutline(shape->stroke, mpool, tid);
|
||||||
|
|
||||||
if (!mathUpdateOutlineBBox(strokeOutline, clipRegion, renderRegion, false)) {
|
if (!mathUpdateOutlineBBox(strokeOutline, clipRegion, renderRegion, false)) {
|
||||||
ret = false;
|
ret = false;
|
||||||
goto fail;
|
goto clear;
|
||||||
}
|
}
|
||||||
|
|
||||||
shape->strokeRle = rleRender(shape->strokeRle, strokeOutline, renderRegion, true);
|
shape->strokeRle = rleRender(shape->strokeRle, strokeOutline, renderRegion, true);
|
||||||
|
|
||||||
fail:
|
clear:
|
||||||
if (freeOutline) {
|
if (dashStroking) mpoolRetDashOutline(mpool, tid);
|
||||||
free(shapeOutline->cntrs.data);
|
|
||||||
free(shapeOutline->pts.data);
|
|
||||||
free(shapeOutline->types.data);
|
|
||||||
free(shapeOutline->closed.data);
|
|
||||||
free(shapeOutline);
|
|
||||||
}
|
|
||||||
mpoolRetStrokeOutline(mpool, tid);
|
mpoolRetStrokeOutline(mpool, tid);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
Loading…
Add table
Reference in a new issue