@@ -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
238216void 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
293260void renderer::LayerMask::preprocess (const VRect &clip)
@@ -869,7 +836,7 @@ renderer::ShapeLayer::ShapeLayer(model::Layer *layerData,
869836
870837void 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+
899887bool 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 }
0 commit comments