From 12074f2332fac97b9567d1778226ee023c5b7e30 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Thu, 21 Jul 2022 13:11:04 -0400 Subject: [PATCH] Use PorterDuff blend mode when below Android 29 (flutter/engine#34800) --- .../plugin/platform/PlatformViewWrapper.java | 14 +++----------- .../plugin/platform/PlatformViewWrapperTest.java | 6 +++--- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewWrapper.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewWrapper.java index c57d90f016..d55b0a6b7c 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewWrapper.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewWrapper.java @@ -9,10 +9,10 @@ import static android.content.ComponentCallbacks2.TRIM_MEMORY_COMPLETE; import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.content.Context; -import android.graphics.BlendMode; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Matrix; +import android.graphics.PorterDuff; import android.graphics.Rect; import android.graphics.SurfaceTexture; import android.os.Build; @@ -169,11 +169,7 @@ class PlatformViewWrapper extends FrameLayout { // to the user until the platform view draws its first frame. final Canvas canvas = surface.lockHardwareCanvas(); try { - if (Build.VERSION.SDK_INT >= 29) { - canvas.drawColor(Color.TRANSPARENT, BlendMode.CLEAR); - } else { - canvas.drawColor(Color.TRANSPARENT); - } + canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); onFrameProduced(); } finally { surface.unlockCanvasAndPost(canvas); @@ -305,11 +301,7 @@ class PlatformViewWrapper extends FrameLayout { try { // Clear the current pixels in the canvas. // This helps when a WebView renders an HTML document with transparent background. - if (Build.VERSION.SDK_INT >= 29) { - surfaceCanvas.drawColor(Color.TRANSPARENT, BlendMode.CLEAR); - } else { - surfaceCanvas.drawColor(Color.TRANSPARENT); - } + surfaceCanvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); super.draw(surfaceCanvas); onFrameProduced(); } finally { diff --git a/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewWrapperTest.java b/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewWrapperTest.java index 2893df2283..630504f9aa 100644 --- a/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewWrapperTest.java +++ b/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewWrapperTest.java @@ -7,9 +7,9 @@ import static org.mockito.Mockito.*; import android.annotation.TargetApi; import android.content.Context; -import android.graphics.BlendMode; import android.graphics.Canvas; import android.graphics.Color; +import android.graphics.PorterDuff; import android.graphics.SurfaceTexture; import android.view.Surface; import android.view.View; @@ -65,7 +65,7 @@ public class PlatformViewWrapperTest { // Verify. verify(surface, times(1)).lockHardwareCanvas(); verify(surface, times(1)).unlockCanvasAndPost(canvas); - verify(canvas, times(1)).drawColor(Color.TRANSPARENT, BlendMode.CLEAR); + verify(canvas, times(1)).drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); verifyNoMoreInteractions(surface); verifyNoMoreInteractions(canvas); } @@ -112,7 +112,7 @@ public class PlatformViewWrapperTest { wrapper.draw(new Canvas()); // Verify. - verify(canvas, times(1)).drawColor(Color.TRANSPARENT, BlendMode.CLEAR); + verify(canvas, times(1)).drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); verify(surface, times(1)).isValid(); verify(surface, times(1)).lockHardwareCanvas(); verify(surface, times(1)).unlockCanvasAndPost(canvas);