Skip to content

Commit f969abf

Browse files
committed
offscreen rendering of shape layer
Revert "lottieitem: Added alpha in Fill::updateContent method." This reverts commit fb12ddc8d0195672aa1ade6e181c8b26378ad10d. Revert "Update color blending style in LottieItem" This reverts commit 8cb666211b859267ec530ff8798c08c29aefecaf. Change-Id: I27d3213b04514f6c60eb817aa924ca74103c5b09
1 parent 462ace3 commit f969abf

File tree

2 files changed

+32
-64
lines changed

2 files changed

+32
-64
lines changed

‎src/lottie/lottieitem.cpp‎

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -165,28 +165,6 @@ bool renderer::Composition::render(const rlottie::Surface &surface)
165165
painter.setDrawRegion(
166166
VRect(int(surface.drawRegionPosX()), int(surface.drawRegionPosY()),
167167
int(surface.drawRegionWidth()), int(surface.drawRegionHeight())));
168-
169-
// layer surface should be created if it is not created already or its size
170-
// is changed.
171-
bool isLayerSurfaceCreated = mSurfaceCache.is_layer_surface_created();
172-
bool isLayerSurfaceSizeChanged =
173-
isLayerSurfaceCreated &&
174-
(mSurfaceCache.get_layer_surface()->width() != surface.width() ||
175-
mSurfaceCache.get_layer_surface()->height() != surface.height());
176-
177-
if (!isLayerSurfaceCreated || isLayerSurfaceSizeChanged) {
178-
if (isLayerSurfaceCreated && isLayerSurfaceSizeChanged)
179-
mSurfaceCache.delete_layer_surface();
180-
181-
mSurfaceCache.create_layer_surface(surface.width(), surface.height(),
182-
VBitmap::Format::ARGB32_Premultiplied);
183-
184-
// set layer draw region
185-
mSurfaceCache.get_layer_painter()->setDrawRegion(
186-
VRect(int(surface.drawRegionPosX()), int(surface.drawRegionPosY()),
187-
int(surface.drawRegionWidth()), int(surface.drawRegionHeight())));
188-
}
189-
190168
mRootLayer->render(&painter, {}, {}, mSurfaceCache);
191169
painter.end();
192170
return true;
@@ -236,7 +214,7 @@ void renderer::Mask::preprocess(const VRect &clip)
236214
}
237215

238216
void renderer::Layer::render(VPainter *painter, const VRle &inheritMask,
239-
const VRle &matteRle, SurfaceCache &cache)
217+
const VRle &matteRle, SurfaceCache &)
240218
{
241219
auto renderlist = renderList();
242220

@@ -252,42 +230,31 @@ void renderer::Layer::render(VPainter *painter, const VRle &inheritMask,
252230
mask = inheritMask;
253231
}
254232

255-
VPainter *usedPainter = painter;
256-
257-
if (cache.get_layer_painter() != nullptr) {
258-
usedPainter = cache.get_layer_painter();
259-
usedPainter->begin(cache.get_layer_surface());
260-
}
261-
262233
for (auto &i : renderlist) {
263-
usedPainter->setBrush(i->mBrush);
234+
painter->setBrush(i->mBrush);
264235
VRle rle = i->rle();
265236
if (matteRle.empty()) {
266237
if (mask.empty()) {
267238
// no mask no matte
268-
usedPainter->drawRle(VPoint(), rle);
239+
painter->drawRle(VPoint(), rle);
269240
} else {
270241
// only mask
271-
usedPainter->drawRle(rle, mask);
242+
painter->drawRle(rle, mask);
272243
}
244+
273245
} else {
274246
if (!mask.empty()) rle = rle & mask;
275247

276248
if (rle.empty()) continue;
277249
if (matteType() == model::MatteType::AlphaInv) {
278250
rle = rle - matteRle;
279-
usedPainter->drawRle(VPoint(), rle);
251+
painter->drawRle(VPoint(), rle);
280252
} else {
281253
// render with matteRle as clip.
282-
usedPainter->drawRle(rle, matteRle);
254+
painter->drawRle(rle, matteRle);
283255
}
284256
}
285257
}
286-
287-
if (cache.get_layer_painter() != nullptr) {
288-
usedPainter->end();
289-
painter->drawBitmap(VPoint(), *cache.get_layer_surface(), mCombinedAlpha * 255.0f);
290-
}
291258
}
292259

293260
void renderer::LayerMask::preprocess(const VRect &clip)
@@ -869,7 +836,7 @@ renderer::ShapeLayer::ShapeLayer(model::Layer *layerData,
869836

870837
void renderer::ShapeLayer::updateContent()
871838
{
872-
mRoot->update(frameNo(), combinedMatrix(), combinedAlpha(), flag());
839+
mRoot->update(frameNo(), combinedMatrix(), 1.0f , flag());
873840

874841
if (mLayerData->hasPathOperator()) {
875842
mRoot->applyTrim();
@@ -896,6 +863,27 @@ renderer::DrawableList renderer::ShapeLayer::renderList()
896863
return {mDrawableList.data(), mDrawableList.size()};
897864
}
898865

866+
void renderer::ShapeLayer::render(VPainter *painter, const VRle &inheritMask,
867+
const VRle &matteRle, SurfaceCache &cache)
868+
{
869+
if (vIsZero(combinedAlpha())) return;
870+
871+
if (vCompare(combinedAlpha(), 1.0)) {
872+
Layer::render(painter, inheritMask, matteRle, cache);
873+
} else {
874+
//do offscreen rendering
875+
VSize size = painter->clipBoundingRect().size();
876+
VPainter srcPainter;
877+
VBitmap srcBitmap = cache.make_surface(size.width(), size.height());
878+
srcPainter.begin(&srcBitmap);
879+
Layer::render(&srcPainter, inheritMask, matteRle, cache);
880+
srcPainter.end();
881+
painter->drawBitmap(VPoint(), srcBitmap,
882+
uint8_t(combinedAlpha() * 255.0f));
883+
cache.release_surface(srcBitmap);
884+
}
885+
}
886+
899887
bool renderer::Group::resolveKeyPath(LOTKeyPath &keyPath, uint32_t depth,
900888
LOTVariant &value)
901889
{
@@ -991,7 +979,7 @@ void renderer::Group::update(int frameNo, const VMatrix &parentMatrix,
991979

992980
mMatrix = m;
993981

994-
alpha = mModel.transform()->opacity(frameNo);
982+
alpha = parentAlpha * mModel.transform()->opacity(frameNo);
995983
if (!vCompare(alpha, parentAlpha)) {
996984
newFlag |= DirtyFlagBit::Alpha;
997985
}

‎src/lottie/lottieitem.h‎

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -106,31 +106,9 @@ class SurfaceCache {
106106
}
107107

108108
void release_surface(VBitmap &surface) { mCache.push_back(surface); }
109-
bool is_layer_surface_created() const { return mIsLayerBitmapCreated; }
110-
void create_layer_surface(size_t width, size_t height, VBitmap::Format format)
111-
{
112-
if (mIsLayerBitmapCreated) return;
113-
114-
mLayerBitmap = std::make_unique<VBitmap>(width, height, format);
115-
mBitmapPainter = std::make_unique<VPainter>(mLayerBitmap.get());
116-
mIsLayerBitmapCreated = true;
117-
}
118-
void delete_layer_surface()
119-
{
120-
if (!mIsLayerBitmapCreated) return;
121-
122-
mLayerBitmap.reset();
123-
mBitmapPainter.reset();
124-
mIsLayerBitmapCreated = false;
125-
}
126-
VPainter* get_layer_painter() const { return mBitmapPainter.get(); }
127-
VBitmap* get_layer_surface() const { return mLayerBitmap.get(); }
128109

129110
private:
130111
std::vector<VBitmap> mCache;
131-
std::unique_ptr<VBitmap> mLayerBitmap{nullptr};
132-
std::unique_ptr<VPainter> mBitmapPainter{nullptr};
133-
bool mIsLayerBitmapCreated{false};
134112
};
135113

136114
class Drawable final : public VDrawable {
@@ -341,6 +319,8 @@ class ShapeLayer final : public Layer {
341319
void buildLayerNode() final;
342320
bool resolveKeyPath(LOTKeyPath &keyPath, uint32_t depth,
343321
LOTVariant &value) override;
322+
void render(VPainter *painter, const VRle &mask, const VRle &matteRle,
323+
SurfaceCache &cache) final;
344324

345325
protected:
346326
void preprocessStage(const VRect &clip) final;

0 commit comments

Comments
 (0)