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;
}
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:
bool render(const rlottie::Surface &surface);
void setValue(const std::string &keypath, LOTVariant &value);
private:
- VPainter mPainter;
VBitmap mSurface;
VMatrix mScaleMatrix;
VSize mViewSize;
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;
}
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);
}
}
-void VSpanData::setup(const VBrush &brush, VPainter::CompositionMode /*mode*/,
+void VSpanData::setup(const VBrush &brush, BlendMode /*mode*/,
int /*alpha*/)
{
transformType = VMatrix::MatrixType::None;
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
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
}
#include "assert.h"
#include "vbitmap.h"
#include "vbrush.h"
-#include "vpainter.h"
#include "vrect.h"
#include "vrle.h"
};
struct Operator {
- VPainter::CompositionMode mode;
+ BlendMode mode;
SourceFetchProc srcFetch;
CompositionFunctionSolid funcSolid;
CompositionFunction func;
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);
}
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;
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 { \
#include "vpainter.h"
#include <algorithm>
-#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();
&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;
}
}
-void VPainterImpl::drawBitmapUntransform(const VRect & target,
+void VPainter::drawBitmapUntransform(const VRect & target,
const VBitmap &bitmap,
const VRect & source,
uint8_t const_alpha)
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,
setBrush(VBrush());
if (target.size() == source.size()) {
- mImpl->drawBitmapUntransform(target, bitmap, source, const_alpha);
+ drawBitmapUntransform(target, bitmap, source, const_alpha);
} else {
// @TODO scaling
}
#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;
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