From b9c76f3224611396746261a25ecf44bac41c113d Mon Sep 17 00:00:00 2001 From: Michael Jurka Date: Wed, 9 Nov 2011 20:24:03 -0800 Subject: [PATCH] Fix occasional Home/All Apps slowdowns Bug # 5581817 Change-Id: I0ee75ebe073325f89d89669b562ffc4db28f3004 --- src/com/android/launcher2/PagedView.java | 41 ++++++++++++++++-------- src/com/android/launcher2/Workspace.java | 22 +++++++++++-- 2 files changed, 47 insertions(+), 16 deletions(-) diff --git a/src/com/android/launcher2/PagedView.java b/src/com/android/launcher2/PagedView.java index 7be19bf23e..1c040babfb 100644 --- a/src/com/android/launcher2/PagedView.java +++ b/src/com/android/launcher2/PagedView.java @@ -123,6 +123,7 @@ public abstract class PagedView extends ViewGroup { protected boolean mCenterPagesVertically; protected boolean mAllowOverScroll = true; protected int mUnboundedScrollX; + protected int[] mTempVisiblePagesRange = new int[2]; // parameter that adjusts the layout to be optimized for pages with that scale factor protected float mLayoutScale = 1.0f; @@ -671,20 +672,7 @@ public abstract class PagedView extends ViewGroup { updateScrollingIndicator(); } - @Override - protected void dispatchDraw(Canvas canvas) { - int halfScreenSize = getMeasuredWidth() / 2; - int screenCenter = mScrollX + halfScreenSize; - - if (screenCenter != mLastScreenCenter) { - screenScrolled(screenCenter); - updateAdjacentPagesAlpha(); - mLastScreenCenter = screenCenter; - } - - // Find out which screens are visible; as an optimization we only call draw on them - // As an optimization, this code assumes that all pages have the same width as the 0th - // page. + protected void getVisiblePages(int[] range) { final int pageCount = getChildCount(); if (pageCount > 0) { final int pageWidth = getScaledMeasuredWidth(getPageAt(0)); @@ -702,6 +690,31 @@ public abstract class PagedView extends ViewGroup { x += getScaledMeasuredWidth(getPageAt(rightScreen)) + mPageSpacing; } rightScreen = Math.min(getChildCount() - 1, rightScreen); + range[0] = leftScreen; + range[1] = rightScreen; + } else { + range[0] = -1; + range[1] = -1; + } + } + + @Override + protected void dispatchDraw(Canvas canvas) { + int halfScreenSize = getMeasuredWidth() / 2; + int screenCenter = mScrollX + halfScreenSize; + + if (screenCenter != mLastScreenCenter) { + screenScrolled(screenCenter); + updateAdjacentPagesAlpha(); + mLastScreenCenter = screenCenter; + } + + // Find out which screens are visible; as an optimization we only call draw on them + final int pageCount = getChildCount(); + if (pageCount > 0) { + getVisiblePages(mTempVisiblePagesRange); + final int leftScreen = mTempVisiblePagesRange[0]; + final int rightScreen = mTempVisiblePagesRange[1]; final long drawingTime = getDrawingTime(); // Clip to the bounds diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java index 209bd6ad29..44d0d943f9 100644 --- a/src/com/android/launcher2/Workspace.java +++ b/src/com/android/launcher2/Workspace.java @@ -1255,6 +1255,19 @@ public class Workspace extends SmoothPagedView @Override protected void dispatchDraw(Canvas canvas) { + if (mChildrenLayersEnabled) { + getVisiblePages(mTempVisiblePagesRange); + final int leftScreen = mTempVisiblePagesRange[0]; + final int rightScreen = mTempVisiblePagesRange[1]; + if (leftScreen != -1 && rightScreen != -1) { + // calling setChildrenLayersEnabled on a view that's not visible/rendered + // causes slowdowns on some graphics cards, so we set it here to be sure + // it's only called when it's safe (ie when the view will be rendered) + for (int i = leftScreen; i <= rightScreen; i++) { + ((ViewGroup)getPageAt(i)).setChildrenLayersEnabled(true); + } + } + } super.dispatchDraw(canvas); if (mInScrollArea && !LauncherApplication.isScreenLarge()) { @@ -1359,8 +1372,13 @@ public class Workspace extends SmoothPagedView if (enableChildrenLayers != mChildrenLayersEnabled) { mChildrenLayersEnabled = enableChildrenLayers; - for (int i = 0; i < getPageCount(); i++) { - ((ViewGroup)getChildAt(i)).setChildrenLayersEnabled(enableChildrenLayers); + // calling setChildrenLayersEnabled on a view that's not visible/rendered + // causes slowdowns on some graphics cards, so we only disable it here and leave + // the enabling to dispatchDraw + if (!enableChildrenLayers) { + for (int i = 0; i < getPageCount(); i++) { + ((ViewGroup)getChildAt(i)).setChildrenLayersEnabled(false); + } } } }