From 3427f57e036b3e535ca40076524eb53a72df4980 Mon Sep 17 00:00:00 2001 From: Jun Mukai Date: Mon, 1 Jun 2015 18:38:17 -0700 Subject: [PATCH] Retire PFLAG_ONLY_DRAWS_BACKGROUND. Per discussion on another CL, this CL retires PFLAG_ONLY_DRAWS_BACKGROUND because this is over-optimizing and misleading. Also setFlags() needs to care both the background and the foreground. Bug: 20734520 Change-Id: I57d63e776b5fbad9effd10ad87e683bbb2a6dacd --- core/java/android/view/View.java | 44 ++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 81f9f997c4b7..28d71cb779e4 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -1661,8 +1661,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback, /** {@hide} */ static final int PFLAG_SKIP_DRAW = 0x00000080; /** {@hide} */ - static final int PFLAG_ONLY_DRAWS_BACKGROUND = 0x00000100; - /** {@hide} */ static final int PFLAG_REQUEST_TRANSPARENT_REGIONS = 0x00000200; /** {@hide} */ static final int PFLAG_DRAWABLE_STATE_DIRTY = 0x00000400; @@ -10612,9 +10610,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback, if ((changed & DRAW_MASK) != 0) { if ((mViewFlags & WILL_NOT_DRAW) != 0) { - if (mBackground != null) { + if (mBackground != null + || (mForegroundInfo != null && mForegroundInfo.mDrawable != null)) { mPrivateFlags &= ~PFLAG_SKIP_DRAW; - mPrivateFlags |= PFLAG_ONLY_DRAWS_BACKGROUND; } else { mPrivateFlags |= PFLAG_SKIP_DRAW; } @@ -17248,20 +17246,13 @@ public class View implements Drawable.Callback, KeyEvent.Callback, if ((mPrivateFlags & PFLAG_SKIP_DRAW) != 0) { mPrivateFlags &= ~PFLAG_SKIP_DRAW; - mPrivateFlags |= PFLAG_ONLY_DRAWS_BACKGROUND; requestLayout = true; } } else { /* Remove the background */ mBackground = null; - - if ((mPrivateFlags & PFLAG_ONLY_DRAWS_BACKGROUND) != 0) { - /* - * This view ONLY drew the background before and we're removing - * the background, so now it won't draw anything - * (hence we SKIP_DRAW) - */ - mPrivateFlags &= ~PFLAG_ONLY_DRAWS_BACKGROUND; + if ((mViewFlags & WILL_NOT_DRAW) != 0 + && (mForegroundInfo == null || mForegroundInfo.mDrawable == null)) { mPrivateFlags |= PFLAG_SKIP_DRAW; } @@ -17435,13 +17426,17 @@ public class View implements Drawable.Callback, KeyEvent.Callback, mForegroundInfo.mDrawable = foreground; mForegroundInfo.mBoundsChanged = true; if (foreground != null) { - setWillNotDraw(false); + if ((mPrivateFlags & PFLAG_SKIP_DRAW) != 0) { + mPrivateFlags &= ~PFLAG_SKIP_DRAW; + } foreground.setCallback(this); foreground.setLayoutDirection(getLayoutDirection()); if (foreground.isStateful()) { foreground.setState(getDrawableState()); } applyForegroundTint(); + } else if ((mViewFlags & WILL_NOT_DRAW) != 0 && mBackground == null) { + mPrivateFlags |= PFLAG_SKIP_DRAW; } requestLayout(); invalidate(); @@ -19169,16 +19164,17 @@ public class View implements Drawable.Callback, KeyEvent.Callback, getLocationInWindow(location); region.op(location[0], location[1], location[0] + mRight - mLeft, location[1] + mBottom - mTop, Region.Op.DIFFERENCE); - } else if ((pflags & PFLAG_ONLY_DRAWS_BACKGROUND) != 0 && mBackground != null && - mBackground.getOpacity() != PixelFormat.TRANSPARENT) { - // The ONLY_DRAWS_BACKGROUND flag IS set and the background drawable - // exists, so we remove the background drawable's non-transparent - // parts from this transparent region. - applyDrawableToTransparentRegion(mBackground, region); - } - final Drawable foreground = mForegroundInfo != null ? mForegroundInfo.mDrawable : null; - if (foreground != null) { - applyDrawableToTransparentRegion(mForegroundInfo.mDrawable, region); + } else { + if (mBackground != null && mBackground.getOpacity() != PixelFormat.TRANSPARENT) { + // The SKIP_DRAW flag IS set and the background drawable exists, we remove + // the background drawable's non-transparent parts from this transparent region. + applyDrawableToTransparentRegion(mBackground, region); + } + if (mForegroundInfo != null && mForegroundInfo.mDrawable != null + && mForegroundInfo.mDrawable.getOpacity() != PixelFormat.TRANSPARENT) { + // Similarly, we remove the foreground drawable's non-transparent parts. + applyDrawableToTransparentRegion(mForegroundInfo.mDrawable, region); + } } } return true; -- 2.11.0