diff options
Diffstat (limited to 'packages/Shell/src')
-rw-r--r-- | packages/Shell/src/com/android/shell/Screenshooter.java | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/packages/Shell/src/com/android/shell/Screenshooter.java b/packages/Shell/src/com/android/shell/Screenshooter.java index 8e0161961a49..85f25528f07e 100644 --- a/packages/Shell/src/com/android/shell/Screenshooter.java +++ b/packages/Shell/src/com/android/shell/Screenshooter.java @@ -17,11 +17,8 @@ package com.android.shell; import android.graphics.Bitmap; -import android.graphics.Point; -import android.graphics.Rect; -import android.hardware.display.DisplayManagerGlobal; +import android.os.IBinder; import android.util.Log; -import android.view.Display; import android.view.SurfaceControl; /** @@ -40,22 +37,17 @@ final class Screenshooter { * @return The screenshot bitmap on success, null otherwise. */ static Bitmap takeScreenshot() { - Display display = DisplayManagerGlobal.getInstance() - .getRealDisplay(Display.DEFAULT_DISPLAY); - Point displaySize = new Point(); - display.getRealSize(displaySize); - final int displayWidth = displaySize.x; - final int displayHeight = displaySize.y; - - int rotation = display.getRotation(); - Rect crop = new Rect(0, 0, displayWidth, displayHeight); - Log.d(TAG, "Taking screenshot of dimensions " + displayWidth + " x " + displayHeight); + Log.d(TAG, "Taking fullscreen screenshot"); // Take the screenshot - Bitmap screenShot = - SurfaceControl.screenshot(crop, displayWidth, displayHeight, rotation); + final IBinder displayToken = SurfaceControl.getInternalDisplayToken(); + final SurfaceControl.DisplayCaptureArgs captureArgs = + new SurfaceControl.DisplayCaptureArgs.Builder(displayToken) + .build(); + final SurfaceControl.ScreenshotHardwareBuffer screenshotBuffer = + SurfaceControl.captureDisplay(captureArgs); + final Bitmap screenShot = screenshotBuffer == null ? null : screenshotBuffer.asBitmap(); if (screenShot == null) { - Log.e(TAG, "Failed to take screenshot of dimensions " + displayWidth + " x " - + displayHeight); + Log.e(TAG, "Failed to take fullscreen screenshot"); return null; } |