From 8a0bff5e35f63321178bbf777ec24d42544866b3 Mon Sep 17 00:00:00 2001 From: Romain Guy Date: Sun, 6 May 2012 13:14:33 -0700 Subject: [PATCH] Remove unnecessary allocations This change removes a couple of allocations per frame when the user is trying to scroll past the end of the workspace. The allocated object, PorterDuffXfermode, is pretty expensive and creating a new one on every frame could potentially defeat GL rendering optimizations. Change-Id: Iebaf579d29ad8f14112c5af8cb5dce8d7f4dfbaf --- src/com/android/launcher2/CellLayout.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/com/android/launcher2/CellLayout.java b/src/com/android/launcher2/CellLayout.java index 6f4759d1ed..ba20a76baf 100644 --- a/src/com/android/launcher2/CellLayout.java +++ b/src/com/android/launcher2/CellLayout.java @@ -160,6 +160,9 @@ public class CellLayout extends ViewGroup { private static final int INVALID_DIRECTION = -100; private DropTarget.DragEnforcer mDragEnforcer; + private final static PorterDuffXfermode sAddBlendMode = + new PorterDuffXfermode(PorterDuff.Mode.ADD); + public CellLayout(Context context) { this(context, null); } @@ -506,7 +509,7 @@ public class CellLayout extends ViewGroup { if (mForegroundAlpha > 0) { mOverScrollForegroundDrawable.setBounds(mForegroundRect); Paint p = ((NinePatchDrawable) mOverScrollForegroundDrawable).getPaint(); - p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.ADD)); + p.setXfermode(sAddBlendMode); mOverScrollForegroundDrawable.draw(canvas); p.setXfermode(null); }