From cb077ba635fc41eaf833305b010935487c082a95 Mon Sep 17 00:00:00 2001 From: Mark Renouf Date: Wed, 10 Feb 2021 21:39:57 -0500 Subject: [PATCH] Long screenshots: Fix/simplify ImageTileSet.toBitmap Bug: 179378294 Test: manual There were subtle mistakes in the drawing which caused bounds to fail when the image had tiles at negative offsets. toBitmap now delegates to the drawable impl which can already be cropped with setBounds In addition this fixes mistakes in TiledImageDrawable where translation is applied in the wrong direction and cropRect applied in the wrong position. Change-Id: Ica28e47031cb28353a49cdd657666f17115c4f6c --- .../systemui/screenshot/ImageTileSet.java | 17 ++++++----------- .../systemui/screenshot/TiledImageDrawable.java | 6 +++--- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ImageTileSet.java b/packages/SystemUI/src/com/android/systemui/screenshot/ImageTileSet.java index e8493f257029b..ae3cd9996f044 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/ImageTileSet.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/ImageTileSet.java @@ -22,6 +22,7 @@ import android.graphics.Rect; import android.graphics.RenderNode; import android.graphics.drawable.Drawable; import android.os.Handler; +import android.util.Log; import androidx.annotation.UiThread; @@ -141,22 +142,16 @@ class ImageTileSet { * getHeight()). */ Bitmap toBitmap(Rect bounds) { + Log.d(TAG, "exporting with bounds: " + bounds); if (mTiles.isEmpty()) { return null; } final RenderNode output = new RenderNode("Bitmap Export"); - output.setPosition(0, 0, getWidth(), getHeight()); + output.setPosition(0, 0, bounds.width(), bounds.height()); RecordingCanvas canvas = output.beginRecording(); - canvas.translate(-getLeft(), -getTop()); - // Additional translation to account for the requested bounds - canvas.translate(-bounds.left, -bounds.top); - canvas.clipRect(bounds); - for (ImageTile tile : mTiles) { - canvas.save(); - canvas.translate(tile.getLeft(), tile.getTop()); - canvas.drawRenderNode(tile.getDisplayList()); - canvas.restore(); - } + Drawable drawable = getDrawable(); + drawable.setBounds(bounds); + drawable.draw(canvas); output.endRecording(); return HardwareRenderer.createHardwareBitmap(output, bounds.width(), bounds.height()); } diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/TiledImageDrawable.java b/packages/SystemUI/src/com/android/systemui/screenshot/TiledImageDrawable.java index 72f489bdd398d..4ec8eb22c67ae 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/TiledImageDrawable.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/TiledImageDrawable.java @@ -56,7 +56,7 @@ public class TiledImageDrawable extends Drawable { mNode = new RenderNode("TiledImageDrawable"); } mNode.setPosition(0, 0, mTiles.getWidth(), mTiles.getHeight()); - Canvas canvas = mNode.beginRecording(mTiles.getWidth(), mTiles.getHeight()); + Canvas canvas = mNode.beginRecording(); // Align content (virtual) top/left with 0,0, within the render node canvas.translate(-mTiles.getLeft(), -mTiles.getTop()); for (int i = 0; i < mTiles.size(); i++) { @@ -79,8 +79,8 @@ public class TiledImageDrawable extends Drawable { if (canvas.isHardwareAccelerated()) { Rect bounds = getBounds(); canvas.save(); - canvas.clipRect(bounds); - canvas.translate(bounds.left, bounds.top); + canvas.clipRect(0, 0, bounds.width(), bounds.height()); + canvas.translate(-bounds.left, -bounds.top); canvas.drawRenderNode(mNode); canvas.restore(); } else {