From 556836cdc5efc7b75eba6e15d4d975100163ca9a Mon Sep 17 00:00:00 2001 From: subhransu mohanty Date: Mon, 19 Nov 2018 14:19:10 +0900 Subject: [PATCH] lottie/vector: add support for clip during rle generation. Change-Id: Ifbd6c3e1b362369298dd6b9333af6f9a90731dbe --- src/vector/vraster.cpp | 57 +++++++++++++++++++++++++++++++------------------- src/vector/vraster.h | 5 +++-- 2 files changed, 38 insertions(+), 24 deletions(-) diff --git a/src/vector/vraster.cpp b/src/vector/vraster.cpp index 11015a3..1c72f78 100644 --- a/src/vector/vraster.cpp +++ b/src/vector/vraster.cpp @@ -249,9 +249,34 @@ struct RleTask { JoinStyle join; float width; float meterLimit; + VRect clip; VRle operator()(FTOutline &outRef, SW_FT_Stroker &stroker); + void render(FTOutline &outRef); }; +void RleTask::render(FTOutline &outRef) +{ + SW_FT_Raster_Params params; + + params.flags = SW_FT_RASTER_FLAG_DIRECT | SW_FT_RASTER_FLAG_AA; + params.gray_spans = &rleGenerationCb; + params.user = &rle; + params.source = &outRef.ft; + + if (!clip.empty()) { + params.flags |= SW_FT_RASTER_FLAG_CLIP; + + params.clip_box.xMin = clip.left(); + params.clip_box.yMin = clip.top(); + params.clip_box.xMax = clip.right(); + params.clip_box.yMax = clip.bottom(); + } + // compute rle + sw_ft_grays_raster.raster_render(nullptr, ¶ms); + // update bounding box. + rle.boundingRect(); +} + VRle RleTask::operator()(FTOutline &outRef, SW_FT_Stroker &stroker) { rle.reset(); @@ -270,15 +295,6 @@ VRle RleTask::operator()(FTOutline &outRef, SW_FT_Stroker &stroker) SW_FT_Stroker_Export(stroker, &outRef.ft); - SW_FT_Raster_Params params; - - params.flags = SW_FT_RASTER_FLAG_DIRECT | SW_FT_RASTER_FLAG_AA; - params.gray_spans = &rleGenerationCb; - params.user = &rle; - params.source = &outRef; - - sw_ft_grays_raster.raster_render(nullptr, ¶ms); - } else { // Fill Task outRef.convert(path); int fillRuleFlag = SW_FT_OUTLINE_NONE; @@ -291,15 +307,10 @@ VRle RleTask::operator()(FTOutline &outRef, SW_FT_Stroker &stroker) break; } outRef.ft.flags = fillRuleFlag; - SW_FT_Raster_Params params; + } - params.flags = SW_FT_RASTER_FLAG_DIRECT | SW_FT_RASTER_FLAG_AA; - params.gray_spans = &rleGenerationCb; - params.user = &rle; - params.source = &outRef.ft; + render(outRef); - sw_ft_grays_raster.raster_render(nullptr, ¶ms); - } return std::move(rle); } @@ -365,7 +376,7 @@ public: } std::future strokeRle(VPath &&path, VRle &&rle, CapStyle cap, JoinStyle join, - float width, float meterLimit) + float width, float meterLimit, const VRect &clip) { RleTask *task = new RleTask(); task->stroke = true; @@ -375,15 +386,17 @@ public: task->join = join; task->width = width; task->meterLimit = meterLimit; + task->clip = clip; return async(task); } - std::future fillRle(VPath &&path, VRle &&rle, FillRule fillRule) + std::future fillRle(VPath &&path, VRle &&rle, FillRule fillRule, const VRect &clip) { RleTask *task = new RleTask(); task->path = std::move(path); task->rle = std::move(rle); task->fillRule = fillRule; + task->clip = clip; task->stroke = false; return async(task); } @@ -392,26 +405,26 @@ public: static RleTaskScheduler raster_scheduler; std::future VRaster::generateFillInfo(VPath &&path, VRle &&rle, - FillRule fillRule) + FillRule fillRule, const VRect &clip) { if (path.empty()) { std::promise promise; promise.set_value(VRle()); return promise.get_future(); } - return raster_scheduler.fillRle(std::move(path), std::move(rle), fillRule); + return raster_scheduler.fillRle(std::move(path), std::move(rle), fillRule, clip); } std::future VRaster::generateStrokeInfo(VPath &&path, VRle &&rle, CapStyle cap, JoinStyle join, float width, - float meterLimit) + float meterLimit, const VRect &clip) { if (path.empty()) { std::promise promise; promise.set_value(VRle()); return promise.get_future(); } - return raster_scheduler.strokeRle(std::move(path), std::move(rle), cap, join, width, meterLimit); + return raster_scheduler.strokeRle(std::move(path), std::move(rle), cap, join, width, meterLimit, clip); } V_END_NAMESPACE diff --git a/src/vector/vraster.h b/src/vector/vraster.h index 1eaf4dd..a25b0d2 100644 --- a/src/vector/vraster.h +++ b/src/vector/vraster.h @@ -2,6 +2,7 @@ #define VRASTER_H #include #include "vglobal.h" +#include "vrect.h" V_BEGIN_NAMESPACE @@ -12,12 +13,12 @@ struct VRaster { static std::future generateFillInfo(VPath &&path, VRle &&rle, - FillRule fillRule = FillRule::Winding); + FillRule fillRule = FillRule::Winding, const VRect &clip = VRect()); static std::future generateStrokeInfo(VPath &&path, VRle &&rle, CapStyle cap, JoinStyle join, - float width, float meterLimit); + float width, float meterLimit, const VRect &clip = VRect()); }; V_END_NAMESPACE -- 2.7.4