Skip to content
This repository has been archived by the owner on Feb 25, 2025. It is now read-only.

Commit

Permalink
[flutter_releases] Use PorterDuff blend mode when below Android 29 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
bparrishMines authored Jul 27, 2022
1 parent 9e6306b commit fd131c3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
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;
Expand Down Expand Up @@ -169,11 +169,7 @@ public void setTexture(@Nullable SurfaceTexture newTx) {
// 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);
Expand Down Expand Up @@ -305,11 +301,7 @@ public void draw(Canvas canvas) {
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

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;
Expand Down Expand Up @@ -65,7 +65,7 @@ protected Surface createSurface(@NonNull SurfaceTexture tx) {
// 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);
}
Expand Down Expand Up @@ -112,7 +112,7 @@ public void draw(Canvas canvas) {
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);
Expand Down

0 comments on commit fd131c3

Please sign in to comment.