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
This commit is contained in:
Winson Chung
2021-04-15 22:53:02 -07:00
parent bbf0d29880
commit e5b567749e
3 changed files with 9 additions and 8 deletions

View File

@@ -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;

View File

@@ -625,6 +625,7 @@ public class PipTouchHandler {
}
mMenuController.handlePointerEvent(cloneEvent);
cloneEvent.recycle();
}
return true;

View File

@@ -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;