OSDN Git Service

Fix software layer alpha
authorChris Craik <ccraik@google.com>
Tue, 5 Apr 2016 17:15:11 +0000 (10:15 -0700)
committerChris Craik <ccraik@google.com>
Tue, 5 Apr 2016 17:15:11 +0000 (10:15 -0700)
Fixes: 27429404

Software layers must combine layerpaint alpha, if present, with view
alpha.

Change-Id: If9c7dcb53ab8754b4e123cf9cc332a566fd792c4

core/java/android/view/View.java

index 784164d..66b3ab0 100644 (file)
@@ -16915,7 +16915,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
             }
         } else if (cache != null) {
             mPrivateFlags &= ~PFLAG_DIRTY_MASK;
-            if (layerType == LAYER_TYPE_NONE) {
+            if (layerType == LAYER_TYPE_NONE || mLayerPaint == null) {
                 // no layer paint, use temporary paint to draw bitmap
                 Paint cachePaint = parent.mCachePaint;
                 if (cachePaint == null) {
@@ -16927,13 +16927,12 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                 canvas.drawBitmap(cache, 0.0f, 0.0f, cachePaint);
             } else {
                 // use layer paint to draw the bitmap, merging the two alphas, but also restore
-                int layerPaintAlpha = mLayerPaint != null ? mLayerPaint.getAlpha() : 255;
-                if (mLayerPaint == null && alpha < 1) {
-                    mLayerPaint = new Paint();
+                int layerPaintAlpha = mLayerPaint.getAlpha();
+                if (alpha < 1) {
                     mLayerPaint.setAlpha((int) (alpha * layerPaintAlpha));
                 }
                 canvas.drawBitmap(cache, 0.0f, 0.0f, mLayerPaint);
-                if (mLayerPaint != null) {
+                if (alpha < 1) {
                     mLayerPaint.setAlpha(layerPaintAlpha);
                 }
             }