mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-07 14:53:35 +00:00
rlottie/vector: support subsurface rendering with arbitrary offset.
This commit is contained in:
parent
a708ff3721
commit
94fd87b3d9
@ -126,16 +126,20 @@ bool LOTCompItem::render(const rlottie::Surface &surface)
|
|||||||
surface.width(), surface.height(),
|
surface.width(), surface.height(),
|
||||||
surface.bytesPerLine(), VBitmap::Format::ARGB32_Premultiplied);
|
surface.bytesPerLine(), VBitmap::Format::ARGB32_Premultiplied);
|
||||||
|
|
||||||
|
|
||||||
/* schedule all preprocess task for this frame at once.
|
/* schedule all preprocess task for this frame at once.
|
||||||
*/
|
*/
|
||||||
mDrawableList.clear();
|
mDrawableList.clear();
|
||||||
mRootLayer->renderList(mDrawableList);
|
mRootLayer->renderList(mDrawableList);
|
||||||
VRect clip(0, 0, surface.width(), surface.height());
|
VRect clip(0, 0, surface.drawRegionWidth(), surface.drawRegionHeight());
|
||||||
for (auto &e : mDrawableList) {
|
for (auto &e : mDrawableList) {
|
||||||
e->preprocess(clip);
|
e->preprocess(clip);
|
||||||
}
|
}
|
||||||
|
|
||||||
VPainter painter(&bitmap);
|
VPainter painter(&bitmap);
|
||||||
|
// set sub surface area for drawing.
|
||||||
|
painter.setDrawRegion(VRect(surface.drawRegionPosX(), surface.drawRegionPosY(),
|
||||||
|
surface.drawRegionWidth(), surface.drawRegionHeight()));
|
||||||
mRootLayer->render(&painter, {}, {});
|
mRootLayer->render(&painter, {}, {});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@ -207,7 +207,7 @@ VBitmap::Format VRasterBuffer::prepare(VBitmap *image)
|
|||||||
void VSpanData::init(VRasterBuffer *image)
|
void VSpanData::init(VRasterBuffer *image)
|
||||||
{
|
{
|
||||||
mRasterBuffer = image;
|
mRasterBuffer = image;
|
||||||
mSystemClip = VRect(0, 0, image->width(), image->height());
|
setDrawRegion(VRect(0, 0, image->width(), image->height()));
|
||||||
mType = VSpanData::Type::None;
|
mType = VSpanData::Type::None;
|
||||||
mBlendFunc = nullptr;
|
mBlendFunc = nullptr;
|
||||||
mUnclippedBlendFunc = nullptr;
|
mUnclippedBlendFunc = nullptr;
|
||||||
|
|||||||
@ -150,15 +150,21 @@ struct VSpanData {
|
|||||||
VPainter::CompositionMode mode = VPainter::CompModeSrcOver,
|
VPainter::CompositionMode mode = VPainter::CompModeSrcOver,
|
||||||
int alpha = 255);
|
int alpha = 255);
|
||||||
void setupMatrix(const VMatrix &matrix);
|
void setupMatrix(const VMatrix &matrix);
|
||||||
void setPos(const VPoint &pos) { mPos = pos; }
|
|
||||||
VRect clipRect() const
|
VRect clipRect() const
|
||||||
{
|
{
|
||||||
return mSystemClip.translated(-mPos.x(), -mPos.y());
|
return VRect(0, 0, mDrawableSize.width(), mDrawableSize.height());
|
||||||
|
}
|
||||||
|
|
||||||
|
void setDrawRegion(const VRect ®ion)
|
||||||
|
{
|
||||||
|
mOffset = VPoint(region.left(), region.top());
|
||||||
|
mDrawableSize = VSize(region.width(), region.height());
|
||||||
}
|
}
|
||||||
|
|
||||||
uint *buffer(int x, int y) const
|
uint *buffer(int x, int y) const
|
||||||
{
|
{
|
||||||
return (uint *)(mRasterBuffer->scanLine(y + mPos.y())) + x + mPos.x();
|
return (uint *)(mRasterBuffer->scanLine(y + mOffset.y())) + x + mOffset.x();
|
||||||
}
|
}
|
||||||
void initTexture(const VBitmap *image, int alpha, VBitmapData::Type type, const VRect &sourceRect);
|
void initTexture(const VBitmap *image, int alpha, VBitmapData::Type type, const VRect &sourceRect);
|
||||||
|
|
||||||
@ -166,10 +172,10 @@ struct VSpanData {
|
|||||||
VRasterBuffer * mRasterBuffer;
|
VRasterBuffer * mRasterBuffer;
|
||||||
ProcessRleSpan mBlendFunc;
|
ProcessRleSpan mBlendFunc;
|
||||||
ProcessRleSpan mUnclippedBlendFunc;
|
ProcessRleSpan mUnclippedBlendFunc;
|
||||||
VRect mSystemClip;
|
|
||||||
VSpanData::Type mType;
|
VSpanData::Type mType;
|
||||||
std::shared_ptr<VSpanData::Pinnable> mCachedGradient;
|
std::shared_ptr<VSpanData::Pinnable> mCachedGradient;
|
||||||
VPoint mPos;
|
VPoint mOffset; // offset to the subsurface
|
||||||
|
VSize mDrawableSize;// suburface size
|
||||||
union {
|
union {
|
||||||
uint32_t mSolid;
|
uint32_t mSolid;
|
||||||
VGradientData mGradient;
|
VGradientData mGradient;
|
||||||
|
|||||||
@ -32,15 +32,13 @@ public:
|
|||||||
VSpanData mSpanData;
|
VSpanData mSpanData;
|
||||||
};
|
};
|
||||||
|
|
||||||
void VPainterImpl::drawRle(const VPoint &pos, const VRle &rle)
|
void VPainterImpl::drawRle(const VPoint &, const VRle &rle)
|
||||||
{
|
{
|
||||||
if (rle.empty()) return;
|
if (rle.empty()) return;
|
||||||
// mSpanData.updateSpanFunc();
|
// mSpanData.updateSpanFunc();
|
||||||
|
|
||||||
if (!mSpanData.mUnclippedBlendFunc) return;
|
if (!mSpanData.mUnclippedBlendFunc) return;
|
||||||
|
|
||||||
mSpanData.setPos(pos);
|
|
||||||
|
|
||||||
// do draw after applying clip.
|
// do draw after applying clip.
|
||||||
rle.intersect(mSpanData.clipRect(), mSpanData.mUnclippedBlendFunc,
|
rle.intersect(mSpanData.clipRect(), mSpanData.mUnclippedBlendFunc,
|
||||||
&mSpanData);
|
&mSpanData);
|
||||||
@ -61,9 +59,9 @@ static void fillRect(const VRect &r, VSpanData *data)
|
|||||||
int x1, x2, y1, y2;
|
int x1, x2, y1, y2;
|
||||||
|
|
||||||
x1 = std::max(r.x(), 0);
|
x1 = std::max(r.x(), 0);
|
||||||
x2 = std::min(r.x() + r.width(), data->mRasterBuffer->width());
|
x2 = std::min(r.x() + r.width(), data->mDrawableSize.width());
|
||||||
y1 = std::max(r.y(), 0);
|
y1 = std::max(r.y(), 0);
|
||||||
y2 = std::min(r.y() + r.height(), data->mRasterBuffer->height());
|
y2 = std::min(r.y() + r.height(), data->mDrawableSize.height());
|
||||||
|
|
||||||
if (x2 <= x1 || y2 <= y1)
|
if (x2 <= x1 || y2 <= y1)
|
||||||
return;
|
return;
|
||||||
@ -130,6 +128,12 @@ bool VPainter::begin(VBitmap *buffer)
|
|||||||
}
|
}
|
||||||
void VPainter::end() {}
|
void VPainter::end() {}
|
||||||
|
|
||||||
|
void VPainter::setDrawRegion(const VRect ®ion)
|
||||||
|
{
|
||||||
|
mImpl->mSpanData.setDrawRegion(region);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void VPainter::setBrush(const VBrush &brush)
|
void VPainter::setBrush(const VBrush &brush)
|
||||||
{
|
{
|
||||||
mImpl->mSpanData.setup(brush);
|
mImpl->mSpanData.setup(brush);
|
||||||
@ -153,7 +157,7 @@ void VPainter::drawRle(const VRle &rle, const VRle &clip)
|
|||||||
|
|
||||||
VRect VPainter::clipBoundingRect() const
|
VRect VPainter::clipBoundingRect() const
|
||||||
{
|
{
|
||||||
return mImpl->mSpanData.mSystemClip;
|
return mImpl->mSpanData.clipRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VPainter::drawBitmap(const VPoint &point, const VBitmap &bitmap, const VRect &source)
|
void VPainter::drawBitmap(const VPoint &point, const VBitmap &bitmap, const VRect &source)
|
||||||
|
|||||||
@ -40,6 +40,7 @@ public:
|
|||||||
VPainter(VBitmap *buffer);
|
VPainter(VBitmap *buffer);
|
||||||
bool begin(VBitmap *buffer);
|
bool begin(VBitmap *buffer);
|
||||||
void end();
|
void end();
|
||||||
|
void setDrawRegion(const VRect ®ion); // sub surface rendering area.
|
||||||
void setBrush(const VBrush &brush);
|
void setBrush(const VBrush &brush);
|
||||||
void setCompositionMode(CompositionMode mode);
|
void setCompositionMode(CompositionMode mode);
|
||||||
void drawRle(const VPoint &pos, const VRle &rle);
|
void drawRle(const VPoint &pos, const VRle &rle);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user