From: sub.mohanty@samsung.com Date: Sat, 1 Dec 2018 12:20:44 +0000 (+0900) Subject: lottie/vector: add boundingbox callback in freetype renderer. X-Git-Tag: submit/tizen/20181211.054046~13 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7c6cbe8ae741eb498440d80fc420498241ce60d3;p=platform%2Fcore%2Fuifw%2Flottie-player.git lottie/vector: add boundingbox callback in freetype renderer. Change-Id: I50a56b109b89a3b0f1ddb4b4983e4d9ba2aaabc3 --- diff --git a/src/vector/freetype/v_ft_raster.cpp b/src/vector/freetype/v_ft_raster.cpp index 7e668f3..639eaaa 100644 --- a/src/vector/freetype/v_ft_raster.cpp +++ b/src/vector/freetype/v_ft_raster.cpp @@ -311,6 +311,11 @@ typedef struct gray_TWorker_ { SW_FT_Outline outline; SW_FT_BBox clip_box; + int bound_left; + int bound_top; + int bound_right; + int bound_bottom; + SW_FT_Span gray_spans[SW_FT_MAX_GRAY_SPANS]; int num_gray_spans; @@ -361,6 +366,11 @@ static void gray_init_cells(RAS_ARG_ void* buffer, long byte_size) ras.area = 0; ras.cover = 0; ras.invalid = 1; + + ras.bound_left = INT_MAX; + ras.bound_top = INT_MAX; + ras.bound_right = INT_MIN; + ras.bound_bottom = INT_MIN; } /*************************************************************************/ @@ -906,6 +916,12 @@ static void gray_hline(RAS_ARG_ TCoord x, TCoord y, TPos area, TCoord acount) SW_FT_Span* span; int count; + // update bounding box. + if (x < ras.bound_left) ras.bound_left = x; + if (y < ras.bound_top) ras.bound_top = y; + if (y > ras.bound_bottom) ras.bound_bottom = y; + if (x + acount > ras.bound_right) ras.bound_right = x + acount; + /* see whether we can add this span to the current list */ count = ras.num_gray_spans; span = ras.gray_spans + count - 1; @@ -1396,7 +1412,11 @@ static int gray_raster_render(gray_PRaster raster, ras.render_span = (SW_FT_Raster_Span_Func)params->gray_spans; ras.render_span_data = params->user; - return gray_convert_glyph(RAS_VAR); + gray_convert_glyph(RAS_VAR); + params->bbox_cb(ras.bound_left, ras.bound_top, + ras.bound_right - ras.bound_left, + ras.bound_bottom - ras.bound_top + 1, params->user); + return 1; } /**** RASTER OBJECT CREATION: In stand-alone mode, we simply use *****/ diff --git a/src/vector/freetype/v_ft_raster.h b/src/vector/freetype/v_ft_raster.h index aad2a8a..bab40ef 100644 --- a/src/vector/freetype/v_ft_raster.h +++ b/src/vector/freetype/v_ft_raster.h @@ -285,6 +285,10 @@ typedef struct SW_FT_Outline_ const SW_FT_Span* spans, void* user ); + typedef void + (*SW_FT_BboxFunc)( int x, int y, int w, int h, + void* user); + #define SW_FT_Raster_Span_Func SW_FT_SpanFunc @@ -396,6 +400,7 @@ typedef struct SW_FT_Outline_ const void* source; int flags; SW_FT_SpanFunc gray_spans; + SW_FT_BboxFunc bbox_cb; void* user; SW_FT_BBox clip_box; diff --git a/src/vector/vraster.cpp b/src/vector/vraster.cpp index 8f638b6..ea254ca 100644 --- a/src/vector/vraster.cpp +++ b/src/vector/vraster.cpp @@ -237,6 +237,12 @@ static void rleGenerationCb(int count, const SW_FT_Span *spans, void *user) rle->addSpan(rleSpan, count); } +static void bboxCb(int x, int y, int w, int h, void *user) +{ + VRle * rle = (VRle *)user; + rle->setBoundingRect({x, y, w, h}); +} + struct RleTask { std::promise sender; VPath path; @@ -258,6 +264,7 @@ void RleTask::render(FTOutline &outRef) params.flags = SW_FT_RASTER_FLAG_DIRECT | SW_FT_RASTER_FLAG_AA; params.gray_spans = &rleGenerationCb; + params.bbox_cb = &bboxCb; params.user = &rle; params.source = &outRef.ft; @@ -271,8 +278,6 @@ void RleTask::render(FTOutline &outRef) } // compute rle sw_ft_grays_raster.raster_render(nullptr, ¶ms); - // update bounding box. - rle.boundingRect(); } VRle RleTask::operator()(FTOutline &outRef, SW_FT_Stroker &stroker) diff --git a/src/vector/vrle.cpp b/src/vector/vrle.cpp index 7db043b..7668218 100644 --- a/src/vector/vrle.cpp +++ b/src/vector/vrle.cpp @@ -51,6 +51,12 @@ VRect VRle::VRleData::bbox() const return mBbox; } +void VRle::VRleData::setBbox(const VRect &bbox) const +{ + mBboxDirty = false; + mBbox = bbox; +} + void VRle::VRleData::reset() { mSpans.clear(); diff --git a/src/vector/vrle.h b/src/vector/vrle.h index 8790497..a5f1d75 100644 --- a/src/vector/vrle.h +++ b/src/vector/vrle.h @@ -21,6 +21,7 @@ public: void *userData); bool empty() const; VRect boundingRect() const; + void setBoundingRect(const VRect &bbox); void addSpan(const VRle::Span *span, int count); void reset(); @@ -48,6 +49,7 @@ private: void addSpan(const VRle::Span *span, int count); void updateBbox() const; VRect bbox() const; + void setBbox(const VRect &bbox) const; void reset(); void translate(const VPoint &p); void operator*=(int alpha); @@ -81,6 +83,11 @@ inline VRect VRle::boundingRect() const return d->bbox(); } +inline void VRle::setBoundingRect(const VRect & bbox) +{ + d->setBbox(bbox); +} + inline void VRle::invert() { d.write().invert();