From 2dae85591d4ffc8b27563706cfc68fcba59bc8bf Mon Sep 17 00:00:00 2001 From: Jorim Jaggi Date: Tue, 2 May 2017 14:10:58 +0200 Subject: [PATCH] Avoid reading HW bitmap pixels twice Both createScaledBitmap and compress read it back to regular memory. Avoid that by creating an intermediate software bitmap. Test: TaskSnapshotPersisterLoaderTest Bug: 37631016 Change-Id: Id03fa3f6a827d3bd39f8fe4fddfc2d32139dac9b --- .../java/com/android/server/wm/TaskSnapshotPersister.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/wm/TaskSnapshotPersister.java b/services/core/java/com/android/server/wm/TaskSnapshotPersister.java index f2a92df2b820d..e5c7a72c78bcb 100644 --- a/services/core/java/com/android/server/wm/TaskSnapshotPersister.java +++ b/services/core/java/com/android/server/wm/TaskSnapshotPersister.java @@ -24,6 +24,7 @@ import android.annotation.TestApi; import android.app.ActivityManager.TaskSnapshot; import android.graphics.Bitmap; import android.graphics.Bitmap.CompressFormat; +import android.graphics.Bitmap.Config; import android.os.Process; import android.os.SystemClock; import android.util.ArraySet; @@ -266,12 +267,13 @@ class TaskSnapshotPersister { final File file = getBitmapFile(mTaskId, mUserId); final File reducedFile = getReducedResolutionBitmapFile(mTaskId, mUserId); final Bitmap bitmap = Bitmap.createHardwareBitmap(mSnapshot.getSnapshot()); - final Bitmap reduced = Bitmap.createScaledBitmap(bitmap, + final Bitmap swBitmap = bitmap.copy(Config.ARGB_8888, false /* isMutable */); + final Bitmap reduced = Bitmap.createScaledBitmap(swBitmap, (int) (bitmap.getWidth() * REDUCED_SCALE), (int) (bitmap.getHeight() * REDUCED_SCALE), true /* filter */); try { FileOutputStream fos = new FileOutputStream(file); - bitmap.compress(JPEG, QUALITY, fos); + swBitmap.compress(JPEG, QUALITY, fos); fos.close(); FileOutputStream reducedFos = new FileOutputStream(reducedFile); reduced.compress(JPEG, QUALITY, reducedFos);