From 263e019baafb3b6cbcfdef9c81d74a4bea769180 Mon Sep 17 00:00:00 2001 From: Romain Guy Date: Mon, 11 May 2009 11:50:46 -0700 Subject: [PATCH] Fixes #1596240. Optimize invalidate/draw passes by marking opaque views and avoiding drawing them. Whenever a View requests an invalidate its parent check whether the view is opaque or not. When the view is not opaque, the framework behaves as it used to. However, when a view is opaque, the parent marks itself as being dirty because of an opaque view. Its parent then does the same, and so on. When the framework then starts drawing the views, it does not draw views marked as dirty opaque. If a view is dirty opaque and receives an invalidate request from a non-opaque view, it then clears the dirty opaque flag and behaves as before. --- src/com/android/launcher/Workspace.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/com/android/launcher/Workspace.java b/src/com/android/launcher/Workspace.java index f20572e82b..b246ddb9d1 100644 --- a/src/com/android/launcher/Workspace.java +++ b/src/com/android/launcher/Workspace.java @@ -456,6 +456,11 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag } } + @Override + public boolean isOpaque() { + return !mWallpaper.hasAlpha(); + } + @Override protected void dispatchDraw(Canvas canvas) { boolean restore = false; @@ -915,7 +920,7 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag originalCellLayout.removeView(cell); cellLayout.addView(cell); } - mTargetCell = estimateDropCell(source, x - xOffset, y - yOffset, + mTargetCell = estimateDropCell(x - xOffset, y - yOffset, mDragInfo.spanX, mDragInfo.spanY, cell, cellLayout, mTargetCell); cellLayout.onDropChild(cell, mTargetCell); @@ -972,7 +977,7 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag cellLayout.addView(view, insertAtFirst ? 0 : -1); view.setOnLongClickListener(mLongClickListener); - mTargetCell = estimateDropCell(null, x, y, 1, 1, view, cellLayout, mTargetCell); + mTargetCell = estimateDropCell(x, y, 1, 1, view, cellLayout, mTargetCell); cellLayout.onDropChild(view, mTargetCell); CellLayout.LayoutParams lp = (CellLayout.LayoutParams) view.getLayoutParams(); @@ -1015,7 +1020,7 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag final Rect location = recycle != null ? recycle : new Rect(); // Find drop cell and convert into rectangle - int[] dropCell = estimateDropCell(source, x - xOffset, y - yOffset, + int[] dropCell = estimateDropCell(x - xOffset, y - yOffset, spanX, spanY, ignoreView, layout, mTempCell); if (dropCell == null) { @@ -1036,7 +1041,7 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag /** * Calculate the nearest cell where the given object would be dropped. */ - private int[] estimateDropCell(DragSource source, int pixelX, int pixelY, + private int[] estimateDropCell(int pixelX, int pixelY, int spanX, int spanY, View ignoreView, CellLayout layout, int[] recycle) { // Create vacant cell cache if none exists if (mVacantCache == null) {