From d70695ee34611bee420d901ac9e6470d8c211519 Mon Sep 17 00:00:00 2001 From: Derek Sollenberger Date: Fri, 5 May 2017 15:44:04 -0400 Subject: [PATCH] Add an O-release targetAPI check for Canvas.setBitmap. For apps targeting releases earlier than O setBitmap will attempt to preserve the matrix from the previous bitmap. It does not however attempt to reconstruct the save/restore stack or the clip. Test: manual test of messenger app referenced in the bug Bug: 37589964 Change-Id: I67f0928a3f84a8be41da38ef1868e79bdeb03e46 --- core/java/android/view/View.java | 1 + graphics/java/android/graphics/Canvas.java | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 6ee6d637bf797..d8eb950afc225 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -4462,6 +4462,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, sIgnoreMeasureCache = targetSdkVersion < Build.VERSION_CODES.KITKAT; Canvas.sCompatibilityRestore = targetSdkVersion < Build.VERSION_CODES.M; + Canvas.sCompatibilitySetBitmap = targetSdkVersion < Build.VERSION_CODES.O; // In M and newer, our widgets can pass a "hint" value in the size // for UNSPECIFIED MeasureSpecs. This lets child views of scrolling containers diff --git a/graphics/java/android/graphics/Canvas.java b/graphics/java/android/graphics/Canvas.java index 2a2e14b2df6df..0301f2e6b5556 100644 --- a/graphics/java/android/graphics/Canvas.java +++ b/graphics/java/android/graphics/Canvas.java @@ -49,6 +49,8 @@ import javax.microedition.khronos.opengles.GL; public class Canvas extends BaseCanvas { /** @hide */ public static boolean sCompatibilityRestore = false; + /** @hide */ + public static boolean sCompatibilitySetBitmap = false; /** @hide */ public long getNativeCanvasWrapper() { @@ -172,6 +174,11 @@ public class Canvas extends BaseCanvas { throw new RuntimeException("Can't set a bitmap device on a HW accelerated canvas"); } + Matrix preservedMatrix = null; + if (bitmap != null && sCompatibilitySetBitmap) { + preservedMatrix = getMatrix(); + } + if (bitmap == null) { nSetBitmap(mNativeCanvasWrapper, null); mDensity = Bitmap.DENSITY_NONE; @@ -185,6 +192,10 @@ public class Canvas extends BaseCanvas { mDensity = bitmap.mDensity; } + if (preservedMatrix != null) { + setMatrix(preservedMatrix); + } + mBitmap = bitmap; }