From 0a4079ec0c11a3fa28ed2a82781a482372015818 Mon Sep 17 00:00:00 2001 From: John Reck Date: Mon, 30 Sep 2013 15:31:31 -0700 Subject: [PATCH] Avoid accidentally using software layers Bug: 10918599 Shaves ~1-2MB of transient memory usage from setting a hardware layer on a view that's not hardware accelerated, resulting in it falling back to a software layer which allocates a bitmap Also a bit of dejanking as a result of not hitting GC_FOR_ALLOC Change-Id: Iff00d383fca710147a48f31c7eee2b728b8412dc --- .../com/android/keyguard/KeyguardWidgetFrame.java | 10 +--------- .../android/keyguard/SlidingChallengeLayout.java | 14 ++++++++++---- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/packages/Keyguard/src/com/android/keyguard/KeyguardWidgetFrame.java b/packages/Keyguard/src/com/android/keyguard/KeyguardWidgetFrame.java index c0586d5865cd3..ab8a759c8112e 100644 --- a/packages/Keyguard/src/com/android/keyguard/KeyguardWidgetFrame.java +++ b/packages/Keyguard/src/com/android/keyguard/KeyguardWidgetFrame.java @@ -254,7 +254,7 @@ public class KeyguardWidgetFrame extends FrameLayout { */ public void enableHardwareLayersForContent() { View widget = getContent(); - if (widget != null) { + if (widget != null && widget.isHardwareAccelerated()) { widget.setLayerType(LAYER_TYPE_HARDWARE, null); } } @@ -271,14 +271,6 @@ public class KeyguardWidgetFrame extends FrameLayout { } } - public void enableHardwareLayers() { - setLayerType(LAYER_TYPE_HARDWARE, null); - } - - public void disableHardwareLayers() { - setLayerType(LAYER_TYPE_NONE, null); - } - public View getContent() { return getChildAt(0); } diff --git a/packages/Keyguard/src/com/android/keyguard/SlidingChallengeLayout.java b/packages/Keyguard/src/com/android/keyguard/SlidingChallengeLayout.java index 2e47768220d8d..9718c9bffb607 100644 --- a/packages/Keyguard/src/com/android/keyguard/SlidingChallengeLayout.java +++ b/packages/Keyguard/src/com/android/keyguard/SlidingChallengeLayout.java @@ -395,7 +395,7 @@ public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout cancelTransitionsInProgress(); mChallengeInteractiveInternal = false; - mChallengeView.setLayerType(LAYER_TYPE_HARDWARE, null); + enableHardwareLayerForChallengeView(); final int sy = mChallengeView.getBottom(); final int dy = y - sy; if (dy == 0) { @@ -580,7 +580,7 @@ public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout mGestureStartY = y; mGestureStartChallengeBottom = getChallengeBottom(); mDragging = true; - mChallengeView.setLayerType(LAYER_TYPE_HARDWARE, null); + enableHardwareLayerForChallengeView(); } else if (mChallengeShowing && isInChallengeView(x, y)) { mBlockDrag = true; } @@ -657,7 +657,7 @@ public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout mActivePointerId = ev.getPointerId(i); mGestureStartChallengeBottom = getChallengeBottom(); mDragging = true; - mChallengeView.setLayerType(LAYER_TYPE_HARDWARE, null); + enableHardwareLayerForChallengeView(); break; } } @@ -1065,7 +1065,7 @@ public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout private void onFadeStart(boolean show) { mChallengeInteractiveInternal = false; - mChallengeView.setLayerType(LAYER_TYPE_HARDWARE, null); + enableHardwareLayerForChallengeView(); if (show) { moveChallengeTo(getMinChallengeBottom()); @@ -1074,6 +1074,12 @@ public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout setScrollState(SCROLL_STATE_FADING); } + private void enableHardwareLayerForChallengeView() { + if (mChallengeView.isHardwareAccelerated()) { + mChallengeView.setLayerType(LAYER_TYPE_HARDWARE, null); + } + } + private void onFadeEnd(boolean show) { mChallengeInteractiveInternal = true; setChallengeShowing(show);