From: subhransu mohanty Date: Fri, 1 Nov 2019 04:46:52 +0000 (+0900) Subject: rlottie/vector: refactor to make VPainter as POD object X-Git-Tag: submit/tizen/20191111.211104~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ae48c7cdf8e079b39dc6f38e84583d5d390acbae;p=platform%2Fcore%2Fuifw%2Flottie-player.git rlottie/vector: refactor to make VPainter as POD object --- diff --git a/src/lottie/lottieitem.cpp b/src/lottie/lottieitem.cpp index 93f7b77..e75bca7 100644 --- a/src/lottie/lottieitem.cpp +++ b/src/lottie/lottieitem.cpp @@ -152,13 +152,13 @@ bool LOTCompItem::render(const rlottie::Surface &surface) VRect clip(0, 0, int(surface.drawRegionWidth()), int(surface.drawRegionHeight())); mRootLayer->preprocess(clip); - mPainter.begin(&mSurface); + VPainter painter(&mSurface); // set sub surface area for drawing. - mPainter.setDrawRegion( + painter.setDrawRegion( VRect(int(surface.drawRegionPosX()), int(surface.drawRegionPosY()), int(surface.drawRegionWidth()), int(surface.drawRegionHeight()))); - mRootLayer->render(&mPainter, {}, {}); - mPainter.end(); + mRootLayer->render(&painter, {}, {}); + painter.end(); return true; } @@ -552,14 +552,12 @@ void LOTCompLayerItem::renderMatteLayer(VPainter *painter, const VRle &mask, switch (layer->matteType()) { case MatteType::Alpha: case MatteType::Luma: { - layerPainter.setCompositionMode( - VPainter::CompositionMode::CompModeDestIn); + layerPainter.setBlendMode(BlendMode::DestIn); break; } case MatteType::AlphaInv: case MatteType::LumaInv: { - layerPainter.setCompositionMode( - VPainter::CompositionMode::CompModeDestOut); + layerPainter.setBlendMode(BlendMode::DestOut); break; } default: diff --git a/src/lottie/lottieitem.h b/src/lottie/lottieitem.h index 4b8c6cd..df20910 100644 --- a/src/lottie/lottieitem.h +++ b/src/lottie/lottieitem.h @@ -72,7 +72,6 @@ public: bool render(const rlottie::Surface &surface); void setValue(const std::string &keypath, LOTVariant &value); private: - VPainter mPainter; VBitmap mSurface; VMatrix mScaleMatrix; VSize mViewSize; diff --git a/src/vector/vdrawhelper.cpp b/src/vector/vdrawhelper.cpp index e90c157..afd44e5 100644 --- a/src/vector/vdrawhelper.cpp +++ b/src/vector/vdrawhelper.cpp @@ -531,12 +531,12 @@ static inline Operator getOperator(const VSpanData *data, const VRle::Span *, break; } - op.mode = data->mCompositionMode; - if (op.mode == VPainter::CompModeSrcOver && solidSource) - op.mode = VPainter::CompModeSrc; + op.mode = data->mBlendMode; + if (op.mode == BlendMode::SrcOver && solidSource) + op.mode = BlendMode::Src; - op.funcSolid = functionForModeSolid[op.mode]; - op.func = functionForMode[op.mode]; + op.funcSolid = functionForModeSolid[uint(op.mode)]; + op.func = functionForMode[uint(op.mode)]; return op; } @@ -548,7 +548,7 @@ static void blendColorARGB(size_t count, const VRle::Span *spans, Operator op = getOperator(data, spans, count); const uint color = data->mSolid; - if (op.mode == VPainter::CompModeSrc) { + if (op.mode == BlendMode::Src) { // inline for performance while (count--) { uint *target = data->buffer(spans->x, spans->y); @@ -751,7 +751,7 @@ static void blend_untransformed_argb(size_t count, const VRle::Span *spans, } } -void VSpanData::setup(const VBrush &brush, VPainter::CompositionMode /*mode*/, +void VSpanData::setup(const VBrush &brush, BlendMode /*mode*/, int /*alpha*/) { transformType = VMatrix::MatrixType::None; @@ -924,7 +924,7 @@ void vInitDrawhelperFunctions() extern void Vcomp_func_solid_SourceOver_neon( uint32_t * dest, int length, uint32_t color, uint32_t const_alpha); - COMP_functionForModeSolid_C[VPainter::CompModeSrcOver] = + COMP_functionForModeSolid_C[uint(BlendMode::SrcOver)] = Vcomp_func_solid_SourceOver_neon; #endif @@ -939,13 +939,13 @@ void vInitDrawhelperFunctions() extern void Vcomp_func_SourceOver_sse2(uint32_t * dest, const uint32_t *src, int length, uint32_t const_alpha); - COMP_functionForModeSolid_C[VPainter::CompModeSrc] = + COMP_functionForModeSolid_C[uint(BlendMode::Src)] = Vcomp_func_solid_Source_sse2; - COMP_functionForModeSolid_C[VPainter::CompModeSrcOver] = + COMP_functionForModeSolid_C[uint(BlendMode::SrcOver)] = Vcomp_func_solid_SourceOver_sse2; - COMP_functionForMode_C[VPainter::CompModeSrc] = Vcomp_func_Source_sse2; - // COMP_functionForMode_C[VPainter::CompModeSrcOver] = + COMP_functionForMode_C[uint(BlendMode::Src)] = Vcomp_func_Source_sse2; + // COMP_functionForMode_C[uint(BlendMode::SrcOver)] = // Vcomp_func_SourceOver_sse2; #endif } diff --git a/src/vector/vdrawhelper.h b/src/vector/vdrawhelper.h index 5c9a6db..a2c7335 100644 --- a/src/vector/vdrawhelper.h +++ b/src/vector/vdrawhelper.h @@ -24,7 +24,6 @@ #include "assert.h" #include "vbitmap.h" #include "vbrush.h" -#include "vpainter.h" #include "vrect.h" #include "vrle.h" @@ -63,7 +62,7 @@ struct RadialGradientValues { }; struct Operator { - VPainter::CompositionMode mode; + BlendMode mode; SourceFetchProc srcFetch; CompositionFunctionSolid funcSolid; CompositionFunction func; @@ -152,7 +151,7 @@ struct VSpanData { void updateSpanFunc(); void init(VRasterBuffer *image); void setup(const VBrush & brush, - VPainter::CompositionMode mode = VPainter::CompModeSrcOver, + BlendMode mode = BlendMode::SrcOver, int alpha = 255); void setupMatrix(const VMatrix &matrix); @@ -173,7 +172,7 @@ struct VSpanData { } void initTexture(const VBitmap *image, int alpha, VBitmapData::Type type, const VRect &sourceRect); - VPainter::CompositionMode mCompositionMode{VPainter::CompositionMode::CompModeSrcOver}; + BlendMode mBlendMode{BlendMode::SrcOver}; VRasterBuffer * mRasterBuffer; ProcessRleSpan mBlendFunc; ProcessRleSpan mUnclippedBlendFunc; diff --git a/src/vector/vglobal.h b/src/vector/vglobal.h index cbb6363..428dbf9 100644 --- a/src/vector/vglobal.h +++ b/src/vector/vglobal.h @@ -264,6 +264,13 @@ enum class FillRule: unsigned char { EvenOdd, Winding }; enum class JoinStyle: unsigned char { Miter, Bevel, Round }; enum class CapStyle: unsigned char { Flat, Square, Round }; +enum class BlendMode { + Src, + SrcOver, + DestIn, + DestOut +}; + #ifndef V_CONSTRUCTOR_FUNCTION #define V_CONSTRUCTOR_FUNCTION0(AFUNC) \ namespace { \ diff --git a/src/vector/vpainter.cpp b/src/vector/vpainter.cpp index af0da6e..edf70bd 100644 --- a/src/vector/vpainter.cpp +++ b/src/vector/vpainter.cpp @@ -18,27 +18,12 @@ #include "vpainter.h" #include -#include "vdrawhelper.h" -V_BEGIN_NAMESPACE -class VPainterImpl { -public: - void drawRle(const VPoint &pos, const VRle &rle); - void drawRle(const VRle &rle, const VRle &clip); - void setCompositionMode(VPainter::CompositionMode mode) - { - mSpanData.mCompositionMode = mode; - } - void drawBitmapUntransform(const VRect &target, const VBitmap &bitmap, - const VRect &source, uint8_t const_alpha); +V_BEGIN_NAMESPACE -public: - VRasterBuffer mBuffer; - VSpanData mSpanData; -}; -void VPainterImpl::drawRle(const VPoint &, const VRle &rle) +void VPainter::drawRle(const VPoint &, const VRle &rle) { if (rle.empty()) return; // mSpanData.updateSpanFunc(); @@ -50,7 +35,7 @@ void VPainterImpl::drawRle(const VPoint &, const VRle &rle) &mSpanData); } -void VPainterImpl::drawRle(const VRle &rle, const VRle &clip) +void VPainter::drawRle(const VRle &rle, const VRle &clip) { if (rle.empty() || clip.empty()) return; @@ -88,7 +73,7 @@ static void fillRect(const VRect &r, VSpanData *data) } } -void VPainterImpl::drawBitmapUntransform(const VRect & target, +void VPainter::drawBitmapUntransform(const VRect & target, const VBitmap &bitmap, const VRect & source, uint8_t const_alpha) @@ -103,59 +88,38 @@ void VPainterImpl::drawBitmapUntransform(const VRect & target, fillRect(rr, &mSpanData); } -VPainter::~VPainter() -{ - delete mImpl; -} - -VPainter::VPainter() -{ - mImpl = new VPainterImpl; -} - VPainter::VPainter(VBitmap *buffer) { - mImpl = new VPainterImpl; begin(buffer); } bool VPainter::begin(VBitmap *buffer) { - mImpl->mBuffer.prepare(buffer); - mImpl->mSpanData.init(&mImpl->mBuffer); + mBuffer.prepare(buffer); + mSpanData.init(&mBuffer); // TODO find a better api to clear the surface - mImpl->mBuffer.clear(); + mBuffer.clear(); return true; } void VPainter::end() {} void VPainter::setDrawRegion(const VRect ®ion) { - mImpl->mSpanData.setDrawRegion(region); + mSpanData.setDrawRegion(region); } void VPainter::setBrush(const VBrush &brush) { - mImpl->mSpanData.setup(brush); -} - -void VPainter::setCompositionMode(CompositionMode mode) -{ - mImpl->setCompositionMode(mode); + mSpanData.setup(brush); } -void VPainter::drawRle(const VPoint &pos, const VRle &rle) -{ - mImpl->drawRle(pos, rle); -} - -void VPainter::drawRle(const VRle &rle, const VRle &clip) +void VPainter::setBlendMode(BlendMode mode) { - mImpl->drawRle(rle, clip); + mSpanData.mBlendMode = mode; } VRect VPainter::clipBoundingRect() const { - return mImpl->mSpanData.clipRect(); + return mSpanData.clipRect(); } void VPainter::drawBitmap(const VPoint &point, const VBitmap &bitmap, @@ -176,7 +140,7 @@ void VPainter::drawBitmap(const VRect &target, const VBitmap &bitmap, setBrush(VBrush()); if (target.size() == source.size()) { - mImpl->drawBitmapUntransform(target, bitmap, source, const_alpha); + drawBitmapUntransform(target, bitmap, source, const_alpha); } else { // @TODO scaling } diff --git a/src/vector/vpainter.h b/src/vector/vpainter.h index 2d52337..bffac75 100644 --- a/src/vector/vpainter.h +++ b/src/vector/vpainter.h @@ -22,27 +22,20 @@ #include "vbrush.h" #include "vpoint.h" #include "vrle.h" +#include "vdrawhelper.h" V_BEGIN_NAMESPACE class VBitmap; -class VPainterImpl; class VPainter { public: - enum CompositionMode { - CompModeSrc, - CompModeSrcOver, - CompModeDestIn, - CompModeDestOut - }; - ~VPainter(); - VPainter(); - VPainter(VBitmap *buffer); + VPainter() = default; + explicit VPainter(VBitmap *buffer); bool begin(VBitmap *buffer); void end(); void setDrawRegion(const VRect ®ion); // sub surface rendering area. void setBrush(const VBrush &brush); - void setCompositionMode(CompositionMode mode); + void setBlendMode(BlendMode mode); void drawRle(const VPoint &pos, const VRle &rle); void drawRle(const VRle &rle, const VRle &clip); VRect clipBoundingRect() const; @@ -52,7 +45,10 @@ public: void drawBitmap(const VPoint &point, const VBitmap &bitmap, uint8_t const_alpha = 255); void drawBitmap(const VRect &rect, const VBitmap &bitmap, uint8_t const_alpha = 255); private: - VPainterImpl *mImpl; + void drawBitmapUntransform(const VRect &target, const VBitmap &bitmap, + const VRect &source, uint8_t const_alpha); + VRasterBuffer mBuffer; + VSpanData mSpanData; }; V_END_NAMESPACE