diff options
| author | 2023-01-12 15:51:09 +0000 | |
|---|---|---|
| committer | 2023-01-12 16:14:41 +0000 | |
| commit | 3c814b500096b49abfaa889c2e28cb15c033fdf6 (patch) | |
| tree | 2b6016fcbd40a84cf22823306764bcb8e1709943 | |
| parent | 8e6e692f42e3c9dbe9cf15a9f9f642834e0ed65e (diff) | |
Close HardwareBuffer used by rotation animation
The HardwareBuffer used to rely on garbage collection to release.
Since WMS.H#FROCE_GC is removed for reducing random delay, the
buffer references should be released explicitly after use. Otherwise
the lifetime of the buffer on native side may be too long, because
system may not trigger GC frequently.
Note that setBuffer will add a reference to the buffer. So the
close() can be called right after that.
Bug: 264650822
Test: Rotate screen many times, the number from
adb shell dmabuf_dump -a | grep 10200 | wc -l
adb shell dmabuf_dump -b | grep 10240000 | wc -l
should not keep increasing.
(10200,10240000 may be different according1020 to screen size)
Change-Id: I39c052ccf8f7ae7a5914532ee61596a336af0993
4 files changed, 13 insertions, 9 deletions
diff --git a/core/java/com/android/internal/policy/TransitionAnimation.java b/core/java/com/android/internal/policy/TransitionAnimation.java index 25ac1bd678c6..600ae50e8d02 100644 --- a/core/java/com/android/internal/policy/TransitionAnimation.java +++ b/core/java/com/android/internal/policy/TransitionAnimation.java @@ -1279,10 +1279,15 @@ public class TransitionAnimation { public static float getBorderLuma(SurfaceControl surfaceControl, int w, int h) { final ScreenCapture.ScreenshotHardwareBuffer buffer = ScreenCapture.captureLayers(surfaceControl, new Rect(0, 0, w, h), 1); - if (buffer != null) { - return getBorderLuma(buffer.getHardwareBuffer(), buffer.getColorSpace()); + if (buffer == null) { + return 0; + } + final HardwareBuffer hwBuffer = buffer.getHardwareBuffer(); + final float luma = getBorderLuma(hwBuffer, buffer.getColorSpace()); + if (hwBuffer != null) { + hwBuffer.close(); } - return 0; + return luma; } /** Returns the luminance in 0~1. */ diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/ScreenRotationAnimation.java b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/ScreenRotationAnimation.java index 66d0a2aa409b..665267fde6ff 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/ScreenRotationAnimation.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/ScreenRotationAnimation.java @@ -170,6 +170,7 @@ class ScreenRotationAnimation { if (!isCustomRotate()) { mStartLuma = TransitionAnimation.getBorderLuma(hardwareBuffer, colorSpace); } + hardwareBuffer.close(); } t.setLayer(mAnimLeash, SCREEN_FREEZE_LAYER_BASE); diff --git a/services/core/java/com/android/server/wm/ScreenRotationAnimation.java b/services/core/java/com/android/server/wm/ScreenRotationAnimation.java index d395f12f8a01..db88f0ff7cb1 100644 --- a/services/core/java/com/android/server/wm/ScreenRotationAnimation.java +++ b/services/core/java/com/android/server/wm/ScreenRotationAnimation.java @@ -36,7 +36,6 @@ import static com.android.server.wm.utils.CoordinateTransforms.computeRotationMa import android.animation.ArgbEvaluator; import android.content.Context; import android.graphics.Color; -import android.graphics.GraphicBuffer; import android.graphics.Matrix; import android.graphics.Point; import android.graphics.Rect; @@ -251,9 +250,6 @@ class ScreenRotationAnimation { screenshotBuffer.getColorSpace()); Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); - GraphicBuffer buffer = GraphicBuffer.createFromHardwareBuffer( - screenshotBuffer.getHardwareBuffer()); - t.setLayer(mScreenshotLayer, SCREEN_FREEZE_LAYER_BASE); t.reparent(mBackColorSurface, displayContent.getSurfaceControl()); // If hdr layers are on-screen, e.g. picture-in-picture mode, the screenshot of @@ -263,10 +259,11 @@ class ScreenRotationAnimation { t.setLayer(mBackColorSurface, -1); t.setColor(mBackColorSurface, new float[]{mStartLuma, mStartLuma, mStartLuma}); t.setAlpha(mBackColorSurface, 1); - t.setBuffer(mScreenshotLayer, buffer); + t.setBuffer(mScreenshotLayer, hardwareBuffer); t.setColorSpace(mScreenshotLayer, screenshotBuffer.getColorSpace()); t.show(mScreenshotLayer); t.show(mBackColorSurface); + hardwareBuffer.close(); if (mRoundedCornerOverlay != null) { for (SurfaceControl sc : mRoundedCornerOverlay) { diff --git a/services/core/java/com/android/server/wm/Transition.java b/services/core/java/com/android/server/wm/Transition.java index 5e081d50cc54..e5385841a9a1 100644 --- a/services/core/java/com/android/server/wm/Transition.java +++ b/services/core/java/com/android/server/wm/Transition.java @@ -2406,7 +2406,7 @@ class Transition implements BLASTSyncEngine.TransactionReadyListener { if (isDisplayRotation) { // This isn't cheap, so only do it for display rotations. changeInfo.mSnapshotLuma = TransitionAnimation.getBorderLuma( - screenshotBuffer.getHardwareBuffer(), screenshotBuffer.getColorSpace()); + buffer, screenshotBuffer.getColorSpace()); } SurfaceControl.Transaction t = wc.mWmService.mTransactionFactory.get(); @@ -2418,6 +2418,7 @@ class Transition implements BLASTSyncEngine.TransactionReadyListener { t.setLayer(snapshotSurface, Integer.MAX_VALUE); t.apply(); t.close(); + buffer.close(); // Detach the screenshot on the sync transaction (the screenshot is just meant to // freeze the window until the sync transaction is applied (with all its other |