From e5b567749e1c488489b250a252800b84d4113a6c Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Thu, 15 Apr 2021 22:53:02 -0700 Subject: [PATCH] Skip some unnecessary allocations - Move new matrix/rect construction to if the param is set on the builder, we only apply the params if the flags are set anyways and if the caller doesn't set those params then we are allocating new objects unnecessarily - Always recycle motion event Bug: 183756396 Test: Take memory profile when dragging pip Change-Id: Ie7457c8c508ee61bd27daeebe486c39a5cebe7d7 --- .../android/view/SyncRtSurfaceTransactionApplier.java | 8 ++++---- .../com/android/wm/shell/pip/phone/PipTouchHandler.java | 1 + .../system/SyncRtSurfaceTransactionApplierCompat.java | 8 ++++---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/core/java/android/view/SyncRtSurfaceTransactionApplier.java b/core/java/android/view/SyncRtSurfaceTransactionApplier.java index acbcbfad1a750..162c71bf1c16f 100644 --- a/core/java/android/view/SyncRtSurfaceTransactionApplier.java +++ b/core/java/android/view/SyncRtSurfaceTransactionApplier.java @@ -191,7 +191,7 @@ public class SyncRtSurfaceTransactionApplier { * @return this Builder */ public Builder withMatrix(Matrix matrix) { - this.matrix = matrix; + this.matrix = new Matrix(matrix); flags |= FLAG_MATRIX; return this; } @@ -201,7 +201,7 @@ public class SyncRtSurfaceTransactionApplier { * @return this Builder */ public Builder withWindowCrop(Rect windowCrop) { - this.windowCrop = windowCrop; + this.windowCrop = new Rect(windowCrop); flags |= FLAG_WINDOW_CROP; return this; } @@ -272,8 +272,8 @@ public class SyncRtSurfaceTransactionApplier { this.flags = params; this.surface = surface; this.alpha = alpha; - this.matrix = new Matrix(matrix); - this.windowCrop = new Rect(windowCrop); + this.matrix = matrix; + this.windowCrop = windowCrop; this.layer = layer; this.cornerRadius = cornerRadius; this.backgroundBlurRadius = backgroundBlurRadius; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipTouchHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipTouchHandler.java index f29d4f59493eb..2a1fe6080cb14 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipTouchHandler.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipTouchHandler.java @@ -625,6 +625,7 @@ public class PipTouchHandler { } mMenuController.handlePointerEvent(cloneEvent); + cloneEvent.recycle(); } return true; diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/SyncRtSurfaceTransactionApplierCompat.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/SyncRtSurfaceTransactionApplierCompat.java index fbabaa489d74d..e281914d560ee 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/system/SyncRtSurfaceTransactionApplierCompat.java +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/SyncRtSurfaceTransactionApplierCompat.java @@ -231,7 +231,7 @@ public class SyncRtSurfaceTransactionApplierCompat { * @return this Builder */ public Builder withMatrix(Matrix matrix) { - this.matrix = matrix; + this.matrix = new Matrix(matrix); flags |= FLAG_MATRIX; return this; } @@ -241,7 +241,7 @@ public class SyncRtSurfaceTransactionApplierCompat { * @return this Builder */ public Builder withWindowCrop(Rect windowCrop) { - this.windowCrop = windowCrop; + this.windowCrop = new Rect(windowCrop); flags |= FLAG_WINDOW_CROP; return this; } @@ -324,8 +324,8 @@ public class SyncRtSurfaceTransactionApplierCompat { this.flags = flags; this.surface = surface; this.alpha = alpha; - this.matrix = new Matrix(matrix); - this.windowCrop = windowCrop != null ? new Rect(windowCrop) : null; + this.matrix = matrix; + this.windowCrop = windowCrop; this.layer = layer; this.relativeTo = relativeTo; this.relativeLayer = relativeLayer;