From f6a801c61e0814a6290f124fa00e79ab2c28e47a Mon Sep 17 00:00:00 2001 From: Alessandro Balocco Date: Tue, 31 Oct 2023 12:56:41 -0700 Subject: [PATCH] Add handling of anti-aliasing for Circular images in IG Reviewed By: oprisnik Differential Revision: D50793891 fbshipit-source-id: 106aba2e3706e0262f50b374c0981213025431a6 --- .../fresco/vito/core/impl/ShapeCalculator.kt | 6 +++++- .../facebook/fresco/vito/renderer/Shape.kt | 21 +++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/vito/core-impl/src/main/java/com/facebook/fresco/vito/core/impl/ShapeCalculator.kt b/vito/core-impl/src/main/java/com/facebook/fresco/vito/core/impl/ShapeCalculator.kt index f359fcabab..d78ee7b9a4 100644 --- a/vito/core-impl/src/main/java/com/facebook/fresco/vito/core/impl/ShapeCalculator.kt +++ b/vito/core-impl/src/main/java/com/facebook/fresco/vito/core/impl/ShapeCalculator.kt @@ -27,7 +27,11 @@ class ShapeCalculator { return when { roundingOptions == null -> RectShape(bounds) roundingOptions.isCircular -> { - CircleShape(bounds.centerX(), bounds.centerY(), min(bounds.width(), bounds.height()) / 2f) + CircleShape( + bounds.centerX(), + bounds.centerY(), + min(bounds.width(), bounds.height()) / 2f, + roundingOptions.isAntiAliased) } roundingOptions.hasRoundedCorners() -> { when { diff --git a/vito/renderer/src/main/java/com/facebook/fresco/vito/renderer/Shape.kt b/vito/renderer/src/main/java/com/facebook/fresco/vito/renderer/Shape.kt index bf4411ea59..6c1be574d6 100644 --- a/vito/renderer/src/main/java/com/facebook/fresco/vito/renderer/Shape.kt +++ b/vito/renderer/src/main/java/com/facebook/fresco/vito/renderer/Shape.kt @@ -20,8 +20,25 @@ class RectShape(val rect: RectF) : Shape() { override fun draw(canvas: Canvas, paint: Paint) = canvas.drawRect(rect, paint) } -class CircleShape(val cx: Float, val cy: Float, val radius: Float) : Shape() { - override fun draw(canvas: Canvas, paint: Paint) = canvas.drawCircle(cx, cy, radius, paint) +class CircleShape( + private val cx: Float, + private val cy: Float, + private val radius: Float, + private val antiAliased: Boolean? = null +) : Shape() { + override fun draw(canvas: Canvas, paint: Paint) { + if (antiAliased != null) { + // Store the value for the anti-alias property this paint has + val paintAntiAliasValue = paint.isAntiAlias + // Temporarily apply anti-alias property for circle + paint.isAntiAlias = antiAliased + canvas.drawCircle(cx, cy, radius, paint) + // Restore previous value on the paint object to avoid collateral unexpected behaviours + paint.isAntiAlias = paintAntiAliasValue + } else { + canvas.drawCircle(cx, cy, radius, paint) + } + } } class RoundedRectShape(val rect: RectF, val rx: Float, val ry: Float) : Shape() {