diff options
author | 2023-06-06 13:38:43 -0500 | |
---|---|---|
committer | 2023-06-12 14:40:52 -0500 | |
commit | 20ca02e27015e8ae53f4283500fb20933d55053c (patch) | |
tree | c396485f0cc42522920bf88ed8fa46320d22192f /packages/Shell/src | |
parent | 0673acc60e4fd9e39311b86852264ef8990a42aa (diff) |
ScreenCaptureListenerWrapper - hold weak ref
This change should reduce the amount of time taken by Java's garbage collection to free hardware buffers.
Without this change, cleaning up hardware buffers via GC required:
* A GC cycle to collect ScreenCaptureListener
* NativeAllocationRegistry to clean up ScreenCaptureListenerWrapper (this can be tens of seconds)
* A second GC cycle to collect the consumer ScreenCaptureListenerWrapper referenced and the hardware buffer the consumer referenced
With this change, ScreenCaptureListenerWrapper no longer holds a global reference to the consumer allowing GC to clean up unreferenced consumers immediately.
The change also includes a small refactor of the interface used to create synchronous ScreenCaptureListeners.
Bug: 283813337
Test: presumbits
Change-Id: I318d73d6cbf2210db5e4386ab57e4ce3a3629166
Diffstat (limited to 'packages/Shell/src')
-rw-r--r-- | packages/Shell/src/com/android/shell/Screenshooter.java | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/packages/Shell/src/com/android/shell/Screenshooter.java b/packages/Shell/src/com/android/shell/Screenshooter.java index baaddf53bcab..8a5b7daab7e0 100644 --- a/packages/Shell/src/com/android/shell/Screenshooter.java +++ b/packages/Shell/src/com/android/shell/Screenshooter.java @@ -21,12 +21,10 @@ import static android.view.Display.DEFAULT_DISPLAY; import android.graphics.Bitmap; import android.os.RemoteException; import android.util.Log; -import android.util.Pair; import android.view.WindowManagerGlobal; import android.window.ScreenCapture; -import android.window.ScreenCapture.ScreenCaptureListener; import android.window.ScreenCapture.ScreenshotHardwareBuffer; -import android.window.ScreenCapture.ScreenshotSync; +import android.window.ScreenCapture.SynchronousScreenCaptureListener; /** * Helper class used to take screenshots. @@ -46,15 +44,15 @@ final class Screenshooter { static Bitmap takeScreenshot() { Log.d(TAG, "Taking fullscreen screenshot"); // Take the screenshot - final Pair<ScreenCaptureListener, ScreenshotSync> syncScreenCapture = + final SynchronousScreenCaptureListener syncScreenCapture = ScreenCapture.createSyncCaptureListener(); try { WindowManagerGlobal.getWindowManagerService().captureDisplay(DEFAULT_DISPLAY, null, - syncScreenCapture.first); + syncScreenCapture); } catch (RemoteException e) { e.rethrowAsRuntimeException(); } - final ScreenshotHardwareBuffer screenshotBuffer = syncScreenCapture.second.get(); + final ScreenshotHardwareBuffer screenshotBuffer = syncScreenCapture.getBuffer(); final Bitmap screenShot = screenshotBuffer == null ? null : screenshotBuffer.asBitmap(); if (screenShot == null) { Log.e(TAG, "Failed to take fullscreen screenshot"); |