From 92c363da428985eee677acac0a3ba10c83ec1093 Mon Sep 17 00:00:00 2001 From: subhransu mohanty Date: Mon, 6 Aug 2018 10:19:57 +0900 Subject: [PATCH] lottie/render: Implement drawRle() with position information. Change-Id: Ia5bbcf911baaaa4b684045a6ac28c4dcfc14f841 --- src/vector/vdrawhelper.cpp | 11 ++++------- src/vector/vdrawhelper.h | 23 +++++++++++++++++------ src/vector/vpainter.cpp | 4 +++- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/vector/vdrawhelper.cpp b/src/vector/vdrawhelper.cpp index 76f1212..2b07529 100644 --- a/src/vector/vdrawhelper.cpp +++ b/src/vector/vdrawhelper.cpp @@ -496,8 +496,7 @@ static void blendColorARGB(int count, const VRle::Span *spans, void *userData) if (op.mode == VPainter::CompModeSrc) { // inline for performance while (count--) { - uint *target = - ((uint *)data->mRasterBuffer->scanLine(spans->y)) + spans->x; + uint *target = data->buffer(spans->x, spans->y); if (spans->coverage == 255) { memfill32(target, color, spans->len); } else { @@ -512,8 +511,7 @@ static void blendColorARGB(int count, const VRle::Span *spans, void *userData) } while (count--) { - uint *target = - ((uint *)data->mRasterBuffer->scanLine(spans->y)) + spans->x; + uint *target = data->buffer(spans->x, spans->y); op.funcSolid(target, spans->len, color, spans->coverage); ++spans; } @@ -531,9 +529,8 @@ static void blendGradientARGB(int count, const VRle::Span *spans, if (!op.srcFetch) return; while (count--) { - uint *target = - ((uint *)data->mRasterBuffer->scanLine(spans->y)) + spans->x; - int length = spans->len; + uint *target = data->buffer(spans->x, spans->y); + int length = spans->len; while (length) { int l = std::min(length, BLEND_GRADIENT_BUFFER_SIZE); op.srcFetch(buffer, &op, data, spans->y, spans->x, l); diff --git a/src/vector/vdrawhelper.h b/src/vector/vdrawhelper.h index 3ca9c43..2009298 100644 --- a/src/vector/vdrawhelper.h +++ b/src/vector/vdrawhelper.h @@ -111,12 +111,22 @@ struct VSpanData { }; enum class Type { None, Solid, LinearGradient, RadialGradient }; - void updateSpanFunc(); - void init(VRasterBuffer *image); - void setup(const VBrush & brush, - VPainter::CompositionMode mode = VPainter::CompModeSrcOver, - int alpha = 255); - void setupMatrix(const VMatrix &matrix); + void updateSpanFunc(); + void init(VRasterBuffer *image); + void setup(const VBrush & brush, + VPainter::CompositionMode mode = VPainter::CompModeSrcOver, + int alpha = 255); + void setupMatrix(const VMatrix &matrix); + void setPos(const VPoint &pos) { mPos = pos; } + VRect clipRect() const + { + return mSystemClip.translated(-mPos.x(), -mPos.y()); + } + + uint *buffer(int x, int y) const + { + return (uint *)(mRasterBuffer->scanLine(y + mPos.y())) + x + mPos.x(); + } VRasterBuffer * mRasterBuffer; ProcessRleSpan mBlendFunc; @@ -124,6 +134,7 @@ struct VSpanData { VRect mSystemClip; VSpanData::Type mType; std::shared_ptr mCachedGradient; + VPoint mPos; union { uint32_t mSolid; VGradientData mGradient; diff --git a/src/vector/vpainter.cpp b/src/vector/vpainter.cpp index c4bba88..064f634 100644 --- a/src/vector/vpainter.cpp +++ b/src/vector/vpainter.cpp @@ -19,8 +19,10 @@ void VPainterImpl::drawRle(const VPoint &pos, const VRle &rle) if (!mSpanData.mUnclippedBlendFunc) return; + mSpanData.setPos(pos); + // do draw after applying clip. - rle.intersect(mSpanData.mSystemClip, mSpanData.mUnclippedBlendFunc, + rle.intersect(mSpanData.clipRect(), mSpanData.mUnclippedBlendFunc, &mSpanData); } -- 2.7.4