OSDN Git Service

Allow draw hw bitmap on software canvas for hierarchyviewer
authorsergeyv <sergeyv@google.com>
Tue, 21 Mar 2017 02:07:46 +0000 (19:07 -0700)
committerSergey Vasilinets <sergeyv@google.com>
Tue, 21 Mar 2017 17:26:22 +0000 (17:26 +0000)
Test: runs hierarchyviewer on app with hw bitmaps
bug:34745484
Change-Id: I35f70f7927be23edebac171f3bc96405b14ca794

core/java/android/view/View.java
graphics/java/android/graphics/BaseCanvas.java

index 636ad45..5ba4a49 100644 (file)
@@ -17892,7 +17892,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
             // This case should hopefully never or seldom happen
             canvas = new Canvas(bitmap);
         }
-
+        boolean enabledHwBitmapsInSwMode = canvas.isHwBitmapsInSwModeEnabled();
+        canvas.setHwBitmapsInSwModeEnabled(true);
         if ((backgroundColor & 0xff000000) != 0) {
             bitmap.eraseColor(backgroundColor);
         }
@@ -17920,6 +17921,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
 
         canvas.restoreToCount(restoreCount);
         canvas.setBitmap(null);
+        canvas.setHwBitmapsInSwModeEnabled(enabledHwBitmapsInSwMode);
 
         if (attachInfo != null) {
             // Restore the cached Canvas for our siblings
index 2ebd2cc..1f339f7 100644 (file)
@@ -48,6 +48,7 @@ public abstract class BaseCanvas {
      */
     protected int mScreenDensity = Bitmap.DENSITY_NONE;
     protected int mDensity = Bitmap.DENSITY_NONE;
+    private boolean mAllowHwBitmapsInSwMode = false;
 
     protected void throwIfCannotDraw(Bitmap bitmap) {
         if (bitmap.isRecycled()) {
@@ -511,8 +512,23 @@ public abstract class BaseCanvas {
                 indices, indexOffset, indexCount, paint.getNativeInstance());
     }
 
+    /**
+     * @hide
+     */
+    public void setHwBitmapsInSwModeEnabled(boolean enabled) {
+        mAllowHwBitmapsInSwMode = enabled;
+    }
+
+    /**
+     * @hide
+     */
+    public boolean isHwBitmapsInSwModeEnabled() {
+        return mAllowHwBitmapsInSwMode;
+    }
+
     private void throwIfHwBitmapInSwMode(Bitmap bitmap) {
-        if (!isHardwareAccelerated() && bitmap.getConfig() == Bitmap.Config.HARDWARE) {
+        if (!mAllowHwBitmapsInSwMode && !isHardwareAccelerated()
+                && bitmap.getConfig() == Bitmap.Config.HARDWARE) {
             throw new IllegalStateException("Software rendering doesn't support hardware bitmaps");
         }
     }