sw_engine: fix render fill region

Shape's bbox represents only fill's render region.
Render region of fill and stroke is stored in SwTask.
This was visible while rendering shapes with a stroke -
fill was to big.

@Issue: https://github.com/thorvg/thorvg/issues/2908

Co-Authored-By: Hermet Park <hermet@lottiefiles.com>
This commit is contained in:
Mira Grudzinska 2024-10-30 23:47:43 +07:00 committed by Hermet Park
parent 16111bf55b
commit ed90581a1f
2 changed files with 8 additions and 5 deletions

View file

@ -119,7 +119,8 @@ struct SwShapeTask : SwTask
} }
auto strokeWidth = validStrokeWidth(); auto strokeWidth = validStrokeWidth();
bool visibleFill = false; SwBBox renderRegion{};
auto visibleFill = false;
//This checks also for the case, if the invisible shape turned to visible by alpha. //This checks also for the case, if the invisible shape turned to visible by alpha.
auto prepareShape = false; auto prepareShape = false;
@ -133,9 +134,9 @@ struct SwShapeTask : SwTask
visibleFill = (alpha > 0 || rshape->fill); visibleFill = (alpha > 0 || rshape->fill);
shapeReset(&shape); shapeReset(&shape);
if (visibleFill || clipper) { if (visibleFill || clipper) {
if (!shapePrepare(&shape, rshape, transform, bbox, shape.bbox, mpool, tid, clips.count > 0 ? true : false)) { if (!shapePrepare(&shape, rshape, transform, bbox, renderRegion, mpool, tid, clips.count > 0 ? true : false)) {
visibleFill = false; visibleFill = false;
shape.bbox.reset(); renderRegion.reset();
} }
} }
} }
@ -156,8 +157,8 @@ struct SwShapeTask : SwTask
if (flags & (RenderUpdateFlag::Path | RenderUpdateFlag::Stroke | RenderUpdateFlag::Transform)) { if (flags & (RenderUpdateFlag::Path | RenderUpdateFlag::Stroke | RenderUpdateFlag::Transform)) {
if (strokeWidth > 0.0f) { if (strokeWidth > 0.0f) {
shapeResetStroke(&shape, rshape, transform); shapeResetStroke(&shape, rshape, transform);
if (!shapeGenStrokeRle(&shape, rshape, transform, bbox, shape.bbox, mpool, tid)) goto err;
if (!shapeGenStrokeRle(&shape, rshape, transform, bbox, renderRegion, mpool, tid)) goto err;
if (auto fill = rshape->strokeFill()) { if (auto fill = rshape->strokeFill()) {
auto ctable = (flags & RenderUpdateFlag::GradientStroke) ? true : false; auto ctable = (flags & RenderUpdateFlag::GradientStroke) ? true : false;
if (ctable) shapeResetStrokeFill(&shape); if (ctable) shapeResetStrokeFill(&shape);
@ -182,7 +183,7 @@ struct SwShapeTask : SwTask
if (shape.strokeRle && !clipper->clip(shape.strokeRle)) goto err; if (shape.strokeRle && !clipper->clip(shape.strokeRle)) goto err;
} }
bbox = shape.bbox; //sync bbox = renderRegion; //sync
return; return;

View file

@ -498,6 +498,8 @@ bool shapePrepare(SwShape* shape, const RenderShape* rshape, const Matrix& trans
if (!_genOutline(shape, rshape, transform, mpool, tid, hasComposite)) return false; if (!_genOutline(shape, rshape, transform, mpool, tid, hasComposite)) return false;
if (!mathUpdateOutlineBBox(shape->outline, clipRegion, renderRegion, shape->fastTrack)) return false; if (!mathUpdateOutlineBBox(shape->outline, clipRegion, renderRegion, shape->fastTrack)) return false;
shape->bbox = renderRegion;
//Check valid region //Check valid region
if (renderRegion.max.x - renderRegion.min.x < 1 && renderRegion.max.y - renderRegion.min.y < 1) return false; if (renderRegion.max.x - renderRegion.min.x < 1 && renderRegion.max.y - renderRegion.min.y < 1) return false;