diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2016-08-31 16:02:40 -0700 |
---|---|---|
committer | Sunny Goyal <sunnygoyal@google.com> | 2016-09-02 11:23:49 -0700 |
commit | f28e6afafdc8b5afbdf99910668a38f9252bfb47 (patch) | |
tree | 1c0b61713bb0a4e87391b9ac690d7e0577717c20 /src/com/android/launcher3/HolographicOutlineHelper.java | |
parent | 35908f9e67b9cdae917385ef9e67e168cb0c93b3 (diff) | |
download | android_packages_apps_Trebuchet-f28e6afafdc8b5afbdf99910668a38f9252bfb47.tar.gz android_packages_apps_Trebuchet-f28e6afafdc8b5afbdf99910668a38f9252bfb47.tar.bz2 android_packages_apps_Trebuchet-f28e6afafdc8b5afbdf99910668a38f9252bfb47.zip |
Some optimizations in blur outline generator
1) Using ALPHA_8 as the start and end bitmap. This removes one extra
bitmap generation step
2) Using ByteBuffer on ALPHA_8 bitmap for clipAlpha. This allows us
to use byteArray instead of intArray for representing pixels
Change-Id: I1b654c439fd491b6b91180ddc562bb97fad857aa
Diffstat (limited to 'src/com/android/launcher3/HolographicOutlineHelper.java')
-rw-r--r-- | src/com/android/launcher3/HolographicOutlineHelper.java | 50 |
1 files changed, 27 insertions, 23 deletions
diff --git a/src/com/android/launcher3/HolographicOutlineHelper.java b/src/com/android/launcher3/HolographicOutlineHelper.java index 682231198..9dec7d9e4 100644 --- a/src/com/android/launcher3/HolographicOutlineHelper.java +++ b/src/com/android/launcher3/HolographicOutlineHelper.java @@ -29,6 +29,10 @@ import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.util.SparseArray; +import com.android.launcher3.config.ProviderConfig; + +import java.nio.ByteBuffer; + /** * Utility class to generate shadow and outline effect, which are used for click feedback * and drag-n-drop respectively. @@ -79,50 +83,53 @@ public class HolographicOutlineHelper { * Applies a more expensive and accurate outline to whatever is currently drawn in a specified * bitmap. */ - public void applyExpensiveOutlineWithBlur(Bitmap srcDst, Canvas srcDstCanvas, int color, - int outlineColor) { - applyExpensiveOutlineWithBlur(srcDst, srcDstCanvas, color, outlineColor, true); + public void applyExpensiveOutlineWithBlur(Bitmap srcDst, Canvas srcDstCanvas) { + applyExpensiveOutlineWithBlur(srcDst, srcDstCanvas, true); } - public void applyExpensiveOutlineWithBlur(Bitmap srcDst, Canvas srcDstCanvas, int color, - int outlineColor, boolean clipAlpha) { + public void applyExpensiveOutlineWithBlur(Bitmap srcDst, Canvas srcDstCanvas, + boolean clipAlpha) { + if (ProviderConfig.IS_DOGFOOD_BUILD && srcDst.getConfig() != Bitmap.Config.ALPHA_8) { + throw new RuntimeException("Outline blue is only supported on alpha bitmaps"); + } // We start by removing most of the alpha channel so as to ignore shadows, and // other types of partial transparency when defining the shape of the object if (clipAlpha) { - int[] srcBuffer = new int[srcDst.getWidth() * srcDst.getHeight()]; - srcDst.getPixels(srcBuffer, - 0, srcDst.getWidth(), 0, 0, srcDst.getWidth(), srcDst.getHeight()); - for (int i = 0; i < srcBuffer.length; i++) { - final int alpha = srcBuffer[i] >>> 24; - if (alpha < 188) { - srcBuffer[i] = 0; + byte[] pixels = new byte[srcDst.getWidth() * srcDst.getHeight()]; + ByteBuffer buffer = ByteBuffer.wrap(pixels); + buffer.rewind(); + srcDst.copyPixelsToBuffer(buffer); + + for (int i = 0; i < pixels.length; i++) { + if ((pixels[i] & 0xFF) < 188) { + pixels[i] = 0; } } - srcDst.setPixels(srcBuffer, - 0, srcDst.getWidth(), 0, 0, srcDst.getWidth(), srcDst.getHeight()); + + buffer.rewind(); + srcDst.copyPixelsFromBuffer(buffer); } - Bitmap glowShape = srcDst.extractAlpha(); // calculate the outer blur first mBlurPaint.setMaskFilter(mMediumOuterBlurMaskFilter); int[] outerBlurOffset = new int[2]; - Bitmap thickOuterBlur = glowShape.extractAlpha(mBlurPaint, outerBlurOffset); + Bitmap thickOuterBlur = srcDst.extractAlpha(mBlurPaint, outerBlurOffset); mBlurPaint.setMaskFilter(mThinOuterBlurMaskFilter); int[] brightOutlineOffset = new int[2]; - Bitmap brightOutline = glowShape.extractAlpha(mBlurPaint, brightOutlineOffset); + Bitmap brightOutline = srcDst.extractAlpha(mBlurPaint, brightOutlineOffset); // calculate the inner blur - srcDstCanvas.setBitmap(glowShape); + srcDstCanvas.setBitmap(srcDst); srcDstCanvas.drawColor(0xFF000000, PorterDuff.Mode.SRC_OUT); mBlurPaint.setMaskFilter(mMediumInnerBlurMaskFilter); int[] thickInnerBlurOffset = new int[2]; - Bitmap thickInnerBlur = glowShape.extractAlpha(mBlurPaint, thickInnerBlurOffset); + Bitmap thickInnerBlur = srcDst.extractAlpha(mBlurPaint, thickInnerBlurOffset); // mask out the inner blur srcDstCanvas.setBitmap(thickInnerBlur); - srcDstCanvas.drawBitmap(glowShape, -thickInnerBlurOffset[0], + srcDstCanvas.drawBitmap(srcDst, -thickInnerBlurOffset[0], -thickInnerBlurOffset[1], mErasePaint); srcDstCanvas.drawRect(0, 0, -thickInnerBlurOffset[0], thickInnerBlur.getHeight(), mErasePaint); @@ -132,14 +139,12 @@ public class HolographicOutlineHelper { // draw the inner and outer blur srcDstCanvas.setBitmap(srcDst); srcDstCanvas.drawColor(0, PorterDuff.Mode.CLEAR); - mDrawPaint.setColor(color); srcDstCanvas.drawBitmap(thickInnerBlur, thickInnerBlurOffset[0], thickInnerBlurOffset[1], mDrawPaint); srcDstCanvas.drawBitmap(thickOuterBlur, outerBlurOffset[0], outerBlurOffset[1], mDrawPaint); // draw the bright outline - mDrawPaint.setColor(outlineColor); srcDstCanvas.drawBitmap(brightOutline, brightOutlineOffset[0], brightOutlineOffset[1], mDrawPaint); @@ -148,7 +153,6 @@ public class HolographicOutlineHelper { brightOutline.recycle(); thickOuterBlur.recycle(); thickInnerBlur.recycle(); - glowShape.recycle(); } Bitmap createMediumDropShadow(BubbleTextView view) { |