Loading core/java/android/view/View.java +40 −2 Original line number Original line Diff line number Diff line Loading @@ -52,6 +52,7 @@ import android.text.TextUtils; import android.util.AttributeSet; import android.util.AttributeSet; import android.util.FloatProperty; import android.util.FloatProperty; import android.util.Log; import android.util.Log; import android.util.LongSparseLongArray; import android.util.Pools.SynchronizedPool; import android.util.Pools.SynchronizedPool; import android.util.Property; import android.util.Property; import android.util.SparseArray; import android.util.SparseArray; Loading Loading @@ -2199,6 +2200,12 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ */ static final int PFLAG3_HAS_LAYOUT = 0x4; static final int PFLAG3_HAS_LAYOUT = 0x4; /** * Flag indicating that a call to measure() was skipped and should be done * instead when layout() is invoked. */ static final int PFLAG3_MEASURE_NEEDED_BEFORE_LAYOUT = 0x8; /* End of masks for mPrivateFlags3 */ /* End of masks for mPrivateFlags3 */ Loading Loading @@ -2979,6 +2986,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ */ int mOldHeightMeasureSpec = Integer.MIN_VALUE; int mOldHeightMeasureSpec = Integer.MIN_VALUE; private LongSparseLongArray mMeasureCache; @ViewDebug.ExportedProperty(deepExport = true, prefix = "bg_") @ViewDebug.ExportedProperty(deepExport = true, prefix = "bg_") private Drawable mBackground; private Drawable mBackground; Loading Loading @@ -14401,12 +14410,19 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ */ @SuppressWarnings({"unchecked"}) @SuppressWarnings({"unchecked"}) public void layout(int l, int t, int r, int b) { public void layout(int l, int t, int r, int b) { if ((mPrivateFlags3 & PFLAG3_MEASURE_NEEDED_BEFORE_LAYOUT) != 0) { onMeasure(mOldWidthMeasureSpec, mOldHeightMeasureSpec); mPrivateFlags3 &= ~PFLAG3_MEASURE_NEEDED_BEFORE_LAYOUT; } int oldL = mLeft; int oldL = mLeft; int oldT = mTop; int oldT = mTop; int oldB = mBottom; int oldB = mBottom; int oldR = mRight; int oldR = mRight; boolean changed = isLayoutModeOptical(mParent) ? boolean changed = isLayoutModeOptical(mParent) ? setOpticalFrame(l, t, r, b) : setFrame(l, t, r, b); setOpticalFrame(l, t, r, b) : setFrame(l, t, r, b); if (changed || (mPrivateFlags & PFLAG_LAYOUT_REQUIRED) == PFLAG_LAYOUT_REQUIRED) { if (changed || (mPrivateFlags & PFLAG_LAYOUT_REQUIRED) == PFLAG_LAYOUT_REQUIRED) { onLayout(changed, l, t, r, b); onLayout(changed, l, t, r, b); mPrivateFlags &= ~PFLAG_LAYOUT_REQUIRED; mPrivateFlags &= ~PFLAG_LAYOUT_REQUIRED; Loading @@ -14421,6 +14437,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } } } } } } mPrivateFlags &= ~PFLAG_FORCE_LAYOUT; mPrivateFlags &= ~PFLAG_FORCE_LAYOUT; mPrivateFlags3 |= PFLAG3_HAS_LAYOUT; mPrivateFlags3 |= PFLAG3_HAS_LAYOUT; } } Loading Loading @@ -15898,6 +15915,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * handle possible request-during-layout errors correctly.</p> * handle possible request-during-layout errors correctly.</p> */ */ public void requestLayout() { public void requestLayout() { if (mMeasureCache != null) mMeasureCache.clear(); if (mAttachInfo != null && mAttachInfo.mViewRequestingLayout == null) { if (mAttachInfo != null && mAttachInfo.mViewRequestingLayout == null) { // Only trigger request-during-layout logic if this is the view requesting it, // Only trigger request-during-layout logic if this is the view requesting it, // not the views in its parent hierarchy // not the views in its parent hierarchy Loading Loading @@ -15927,6 +15946,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * on the parent. * on the parent. */ */ public void forceLayout() { public void forceLayout() { if (mMeasureCache != null) mMeasureCache.clear(); mPrivateFlags |= PFLAG_FORCE_LAYOUT; mPrivateFlags |= PFLAG_FORCE_LAYOUT; mPrivateFlags |= PFLAG_INVALIDATED; mPrivateFlags |= PFLAG_INVALIDATED; } } Loading Loading @@ -15960,6 +15981,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback, widthMeasureSpec = MeasureSpec.adjust(widthMeasureSpec, optical ? -oWidth : oWidth); widthMeasureSpec = MeasureSpec.adjust(widthMeasureSpec, optical ? -oWidth : oWidth); heightMeasureSpec = MeasureSpec.adjust(heightMeasureSpec, optical ? -oHeight : oHeight); heightMeasureSpec = MeasureSpec.adjust(heightMeasureSpec, optical ? -oHeight : oHeight); } } // Suppress sign extension for the low bytes long key = (long) widthMeasureSpec << 32 | (long) heightMeasureSpec & 0xffffffffL; if (mMeasureCache == null) mMeasureCache = new LongSparseLongArray(2); if ((mPrivateFlags & PFLAG_FORCE_LAYOUT) == PFLAG_FORCE_LAYOUT || if ((mPrivateFlags & PFLAG_FORCE_LAYOUT) == PFLAG_FORCE_LAYOUT || widthMeasureSpec != mOldWidthMeasureSpec || widthMeasureSpec != mOldWidthMeasureSpec || heightMeasureSpec != mOldHeightMeasureSpec) { heightMeasureSpec != mOldHeightMeasureSpec) { Loading @@ -15969,8 +15995,17 @@ public class View implements Drawable.Callback, KeyEvent.Callback, resolveRtlPropertiesIfNeeded(); resolveRtlPropertiesIfNeeded(); int cacheIndex = mMeasureCache.indexOfKey(key); if (cacheIndex < 0) { // measure ourselves, this should set the measured dimension flag back // measure ourselves, this should set the measured dimension flag back onMeasure(widthMeasureSpec, heightMeasureSpec); onMeasure(widthMeasureSpec, heightMeasureSpec); mPrivateFlags3 &= ~PFLAG3_MEASURE_NEEDED_BEFORE_LAYOUT; } else { long value = mMeasureCache.valueAt(cacheIndex); // Casting a long to int drops the high 32 bits, no mask needed setMeasuredDimension((int) (value >> 32), (int) value); mPrivateFlags3 |= PFLAG3_MEASURE_NEEDED_BEFORE_LAYOUT; } // flag not set, setMeasuredDimension() was not invoked, we raise // flag not set, setMeasuredDimension() was not invoked, we raise // an exception to warn the developer // an exception to warn the developer Loading @@ -15985,6 +16020,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback, mOldWidthMeasureSpec = widthMeasureSpec; mOldWidthMeasureSpec = widthMeasureSpec; mOldHeightMeasureSpec = heightMeasureSpec; mOldHeightMeasureSpec = heightMeasureSpec; mMeasureCache.put(key, ((long) mMeasuredWidth) << 32 | (long) mMeasuredHeight & 0xffffffffL); // suppress sign extension } } /** /** Loading
core/java/android/view/View.java +40 −2 Original line number Original line Diff line number Diff line Loading @@ -52,6 +52,7 @@ import android.text.TextUtils; import android.util.AttributeSet; import android.util.AttributeSet; import android.util.FloatProperty; import android.util.FloatProperty; import android.util.Log; import android.util.Log; import android.util.LongSparseLongArray; import android.util.Pools.SynchronizedPool; import android.util.Pools.SynchronizedPool; import android.util.Property; import android.util.Property; import android.util.SparseArray; import android.util.SparseArray; Loading Loading @@ -2199,6 +2200,12 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ */ static final int PFLAG3_HAS_LAYOUT = 0x4; static final int PFLAG3_HAS_LAYOUT = 0x4; /** * Flag indicating that a call to measure() was skipped and should be done * instead when layout() is invoked. */ static final int PFLAG3_MEASURE_NEEDED_BEFORE_LAYOUT = 0x8; /* End of masks for mPrivateFlags3 */ /* End of masks for mPrivateFlags3 */ Loading Loading @@ -2979,6 +2986,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ */ int mOldHeightMeasureSpec = Integer.MIN_VALUE; int mOldHeightMeasureSpec = Integer.MIN_VALUE; private LongSparseLongArray mMeasureCache; @ViewDebug.ExportedProperty(deepExport = true, prefix = "bg_") @ViewDebug.ExportedProperty(deepExport = true, prefix = "bg_") private Drawable mBackground; private Drawable mBackground; Loading Loading @@ -14401,12 +14410,19 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ */ @SuppressWarnings({"unchecked"}) @SuppressWarnings({"unchecked"}) public void layout(int l, int t, int r, int b) { public void layout(int l, int t, int r, int b) { if ((mPrivateFlags3 & PFLAG3_MEASURE_NEEDED_BEFORE_LAYOUT) != 0) { onMeasure(mOldWidthMeasureSpec, mOldHeightMeasureSpec); mPrivateFlags3 &= ~PFLAG3_MEASURE_NEEDED_BEFORE_LAYOUT; } int oldL = mLeft; int oldL = mLeft; int oldT = mTop; int oldT = mTop; int oldB = mBottom; int oldB = mBottom; int oldR = mRight; int oldR = mRight; boolean changed = isLayoutModeOptical(mParent) ? boolean changed = isLayoutModeOptical(mParent) ? setOpticalFrame(l, t, r, b) : setFrame(l, t, r, b); setOpticalFrame(l, t, r, b) : setFrame(l, t, r, b); if (changed || (mPrivateFlags & PFLAG_LAYOUT_REQUIRED) == PFLAG_LAYOUT_REQUIRED) { if (changed || (mPrivateFlags & PFLAG_LAYOUT_REQUIRED) == PFLAG_LAYOUT_REQUIRED) { onLayout(changed, l, t, r, b); onLayout(changed, l, t, r, b); mPrivateFlags &= ~PFLAG_LAYOUT_REQUIRED; mPrivateFlags &= ~PFLAG_LAYOUT_REQUIRED; Loading @@ -14421,6 +14437,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } } } } } } mPrivateFlags &= ~PFLAG_FORCE_LAYOUT; mPrivateFlags &= ~PFLAG_FORCE_LAYOUT; mPrivateFlags3 |= PFLAG3_HAS_LAYOUT; mPrivateFlags3 |= PFLAG3_HAS_LAYOUT; } } Loading Loading @@ -15898,6 +15915,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * handle possible request-during-layout errors correctly.</p> * handle possible request-during-layout errors correctly.</p> */ */ public void requestLayout() { public void requestLayout() { if (mMeasureCache != null) mMeasureCache.clear(); if (mAttachInfo != null && mAttachInfo.mViewRequestingLayout == null) { if (mAttachInfo != null && mAttachInfo.mViewRequestingLayout == null) { // Only trigger request-during-layout logic if this is the view requesting it, // Only trigger request-during-layout logic if this is the view requesting it, // not the views in its parent hierarchy // not the views in its parent hierarchy Loading Loading @@ -15927,6 +15946,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * on the parent. * on the parent. */ */ public void forceLayout() { public void forceLayout() { if (mMeasureCache != null) mMeasureCache.clear(); mPrivateFlags |= PFLAG_FORCE_LAYOUT; mPrivateFlags |= PFLAG_FORCE_LAYOUT; mPrivateFlags |= PFLAG_INVALIDATED; mPrivateFlags |= PFLAG_INVALIDATED; } } Loading Loading @@ -15960,6 +15981,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback, widthMeasureSpec = MeasureSpec.adjust(widthMeasureSpec, optical ? -oWidth : oWidth); widthMeasureSpec = MeasureSpec.adjust(widthMeasureSpec, optical ? -oWidth : oWidth); heightMeasureSpec = MeasureSpec.adjust(heightMeasureSpec, optical ? -oHeight : oHeight); heightMeasureSpec = MeasureSpec.adjust(heightMeasureSpec, optical ? -oHeight : oHeight); } } // Suppress sign extension for the low bytes long key = (long) widthMeasureSpec << 32 | (long) heightMeasureSpec & 0xffffffffL; if (mMeasureCache == null) mMeasureCache = new LongSparseLongArray(2); if ((mPrivateFlags & PFLAG_FORCE_LAYOUT) == PFLAG_FORCE_LAYOUT || if ((mPrivateFlags & PFLAG_FORCE_LAYOUT) == PFLAG_FORCE_LAYOUT || widthMeasureSpec != mOldWidthMeasureSpec || widthMeasureSpec != mOldWidthMeasureSpec || heightMeasureSpec != mOldHeightMeasureSpec) { heightMeasureSpec != mOldHeightMeasureSpec) { Loading @@ -15969,8 +15995,17 @@ public class View implements Drawable.Callback, KeyEvent.Callback, resolveRtlPropertiesIfNeeded(); resolveRtlPropertiesIfNeeded(); int cacheIndex = mMeasureCache.indexOfKey(key); if (cacheIndex < 0) { // measure ourselves, this should set the measured dimension flag back // measure ourselves, this should set the measured dimension flag back onMeasure(widthMeasureSpec, heightMeasureSpec); onMeasure(widthMeasureSpec, heightMeasureSpec); mPrivateFlags3 &= ~PFLAG3_MEASURE_NEEDED_BEFORE_LAYOUT; } else { long value = mMeasureCache.valueAt(cacheIndex); // Casting a long to int drops the high 32 bits, no mask needed setMeasuredDimension((int) (value >> 32), (int) value); mPrivateFlags3 |= PFLAG3_MEASURE_NEEDED_BEFORE_LAYOUT; } // flag not set, setMeasuredDimension() was not invoked, we raise // flag not set, setMeasuredDimension() was not invoked, we raise // an exception to warn the developer // an exception to warn the developer Loading @@ -15985,6 +16020,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback, mOldWidthMeasureSpec = widthMeasureSpec; mOldWidthMeasureSpec = widthMeasureSpec; mOldHeightMeasureSpec = heightMeasureSpec; mOldHeightMeasureSpec = heightMeasureSpec; mMeasureCache.put(key, ((long) mMeasuredWidth) << 32 | (long) mMeasuredHeight & 0xffffffffL); // suppress sign extension } } /** /**