mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-14 20:14:37 +00:00
sw_engine renderer: add clip() interface.
As there are multiple types of painting tasks, the clip() interface has been newly designed to handle clipping behavior according to each task's role when requested." Now Scene clipper could implement clipping behavior on it.
This commit is contained in:
parent
a0fbe7db41
commit
a45275b779
1 changed files with 23 additions and 19 deletions
|
@ -61,6 +61,7 @@ struct SwTask : Task
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool dispose() = 0;
|
virtual bool dispose() = 0;
|
||||||
|
virtual bool clip(SwRleData* target) = 0;
|
||||||
|
|
||||||
virtual ~SwTask()
|
virtual ~SwTask()
|
||||||
{
|
{
|
||||||
|
@ -76,6 +77,15 @@ struct SwShapeTask : SwTask
|
||||||
bool cmpStroking = false;
|
bool cmpStroking = false;
|
||||||
bool clipper = false;
|
bool clipper = false;
|
||||||
|
|
||||||
|
bool clip(SwRleData* target) override
|
||||||
|
{
|
||||||
|
if (shape.fastTrack) rleClipRect(target, &bbox);
|
||||||
|
else if (shape.rle) rleClipPath(target, shape.rle);
|
||||||
|
else return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void run(unsigned tid) override
|
void run(unsigned tid) override
|
||||||
{
|
{
|
||||||
if (opacity == 0 && !clipper) return; //Invisible
|
if (opacity == 0 && !clipper) return; //Invisible
|
||||||
|
@ -150,22 +160,13 @@ struct SwShapeTask : SwTask
|
||||||
|
|
||||||
//Clip Path
|
//Clip Path
|
||||||
for (auto clip = clips.data; clip < (clips.data + clips.count); ++clip) {
|
for (auto clip = clips.data; clip < (clips.data + clips.count); ++clip) {
|
||||||
|
auto clipper = static_cast<SwTask*>(*clip);
|
||||||
//Guarantee composition targets get ready.
|
//Guarantee composition targets get ready.
|
||||||
static_cast<SwShapeTask*>(*clip)->done(tid);
|
clipper->done(tid);
|
||||||
|
|
||||||
auto clipper = &static_cast<SwShapeTask*>(*clip)->shape;
|
|
||||||
//Clip shape rle
|
//Clip shape rle
|
||||||
if (shape.rle) {
|
if (shape.rle && !clipper->clip(shape.rle)) goto err;
|
||||||
if (clipper->fastTrack) rleClipRect(shape.rle, &clipper->bbox);
|
|
||||||
else if (clipper->rle) rleClipPath(shape.rle, clipper->rle);
|
|
||||||
else goto err;
|
|
||||||
}
|
|
||||||
//Clip stroke rle
|
//Clip stroke rle
|
||||||
if (shape.strokeRle) {
|
if (shape.strokeRle && !clipper->clip(shape.strokeRle)) goto err;
|
||||||
if (clipper->fastTrack) rleClipRect(shape.strokeRle, &clipper->bbox);
|
|
||||||
else if (clipper->rle) rleClipPath(shape.strokeRle, clipper->rle);
|
|
||||||
else goto err;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
|
@ -189,6 +190,12 @@ struct SwImageTask : SwTask
|
||||||
Polygon* triangles;
|
Polygon* triangles;
|
||||||
uint32_t triangleCnt;
|
uint32_t triangleCnt;
|
||||||
|
|
||||||
|
bool clip(SwRleData* target) override
|
||||||
|
{
|
||||||
|
TVGERR("SW_ENGINE", "Image is used as ClipPath?");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void run(unsigned tid) override
|
void run(unsigned tid) override
|
||||||
{
|
{
|
||||||
auto clipRegion = bbox;
|
auto clipRegion = bbox;
|
||||||
|
@ -205,13 +212,10 @@ struct SwImageTask : SwTask
|
||||||
if (!imageGenRle(&image, bbox, false)) goto end;
|
if (!imageGenRle(&image, bbox, false)) goto end;
|
||||||
if (image.rle) {
|
if (image.rle) {
|
||||||
for (auto clip = clips.data; clip < (clips.data + clips.count); ++clip) {
|
for (auto clip = clips.data; clip < (clips.data + clips.count); ++clip) {
|
||||||
|
auto clipper = static_cast<SwTask*>(*clip);
|
||||||
//Guarantee composition targets get ready.
|
//Guarantee composition targets get ready.
|
||||||
static_cast<SwShapeTask*>(*clip)->done(tid);
|
clipper->done(tid);
|
||||||
|
if (!clipper->clip(image.rle)) goto err;
|
||||||
auto clipper = &static_cast<SwShapeTask*>(*clip)->shape;
|
|
||||||
if (clipper->fastTrack) rleClipRect(image.rle, &clipper->bbox);
|
|
||||||
else if (clipper->rle) rleClipPath(image.rle, clipper->rle);
|
|
||||||
else goto err;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue