Skip to content

Commit

Permalink
Fix shadow offset due to unintended Rect mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
geomaster committed Nov 7, 2024
1 parent 9abd8a6 commit 108060a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lottie/src/main/java/com/airbnb/lottie/utils/OffscreenLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ protected enum RenderStrategy {
private RenderStrategy currentStrategy;
/** Rectangle that the final composition will occupy in the screen */
@Nullable private RectF targetRect;
@Nullable private RectF roundedTargetRect;
/** targetRect with shadow/blur render space included */
@Nullable private RectF rectIncludingEffects;
@Nullable private Rect intRectIncludingEffects;
Expand Down Expand Up @@ -233,8 +234,8 @@ public Canvas start(Canvas parentCanvas, RectF bounds, ComposeOp op) {
this.op = op;
this.currentStrategy = chooseRenderStrategy(parentCanvas, op);
if (this.targetRect == null) this.targetRect = new RectF();
this.targetRect.set((int)bounds.left, (int)bounds.top, (int)bounds.right, (int)bounds.bottom);
this.targetRect = calculateRectIncludingEffects(targetRect, null, op.blur);
this.targetRect.set(bounds.left, bounds.top, bounds.right, bounds.bottom);
this.targetRect.set(calculateRectIncludingEffects(targetRect, null, op.blur));
float offX = bounds.left - targetRect.left, offY = bounds.top - targetRect.top;
if (composePaint == null) composePaint = new LPaint();
composePaint.reset();
Expand Down Expand Up @@ -385,13 +386,15 @@ public void finish() {
renderBitmapShadow(parentCanvas, op.shadow);
}

if (bitmapSrcRect == null) bitmapSrcRect = new Rect();
bitmapSrcRect.set(0, 0, (int)(targetRect.width() * preExistingTransform[Matrix.MSCALE_X]), (int)(targetRect.height() * preExistingTransform[Matrix.MSCALE_Y]));
if (op.hasBlur()) {
applySoftwareBlur(bitmap, (blurRadiusX + blurRadiusY) / 2.0f);
}

if (bitmapSrcRect == null) bitmapSrcRect = new Rect();
bitmapSrcRect.set(0, 0, (int)(targetRect.width() * preExistingTransform[Matrix.MSCALE_X]), (int)(targetRect.height() * preExistingTransform[Matrix.MSCALE_Y]));
parentCanvas.drawBitmap(bitmap, bitmapSrcRect, targetRect, composePaint);
if (roundedTargetRect == null) roundedTargetRect = new RectF();
roundedTargetRect.set(Math.round(targetRect.left), Math.round(targetRect.top), Math.round(targetRect.right), Math.round(targetRect.bottom));
parentCanvas.drawBitmap(bitmap, bitmapSrcRect, roundedTargetRect, composePaint);
break;

case RENDER_NODE:
Expand Down

0 comments on commit 108060a

Please sign in to comment.