@GuardedBy("this") private boolean hasSizeSpec() { assertHoldsLock(this); return mWidthSpec != SIZE_UNINITIALIZED && mHeightSpec != SIZE_UNINITIALIZED; }
@GuardedBy("this") private boolean isCompatibleComponentAndSpec(LayoutState layoutState) { assertHoldsLock(this); return mRoot != null && isCompatibleComponentAndSpec( layoutState, mRoot.getId(), mWidthSpec, mHeightSpec); }
@GuardedBy("this") private boolean hasCompatibleComponentAndSpec() { assertHoldsLock(this); return isCompatibleComponentAndSpec(mMainThreadLayoutState) || isCompatibleComponentAndSpec(mBackgroundLayoutState); }
/** * Picks the best LayoutState and sets it in mMainThreadLayoutState. The return value is a * LayoutState that must be released (after the lock is released). This awkward contract is * necessary to ensure thread-safety. */ @CheckReturnValue @ReturnsOwnership @ThreadConfined(ThreadConfined.UI) @GuardedBy("this") private LayoutState setBestMainThreadLayoutAndReturnOldLayout() { assertHoldsLock(this); final boolean isMainThreadLayoutBest = isBestMainThreadLayout(); if (isMainThreadLayoutBest) { // We don't want to hold onto mBackgroundLayoutState since it's unlikely // to ever be used again. We return mBackgroundLayoutState to indicate it // should be released after exiting the lock. final LayoutState toRelease = mBackgroundLayoutState; mBackgroundLayoutState = null; return toRelease; } else { // Since we are changing layout states we'll need to remount. if (mLithoView != null) { mLithoView.setMountStateDirty(); } final LayoutState toRelease = mMainThreadLayoutState; mMainThreadLayoutState = mBackgroundLayoutState; mBackgroundLayoutState = null; return toRelease; } }
@CheckReturnValue @ReturnsOwnership @ThreadConfined(ThreadConfined.UI) @GuardedBy("this") private boolean isBestMainThreadLayout() { assertHoldsLock(this); // If everything matches perfectly then we prefer mMainThreadLayoutState // because that means we don't need to remount. if (isCompatibleComponentAndSpec(mMainThreadLayoutState)) { return true; } else if (isCompatibleSpec(mBackgroundLayoutState, mWidthSpec, mHeightSpec) || !isCompatibleSpec(mMainThreadLayoutState, mWidthSpec, mHeightSpec)) { // If mMainThreadLayoutState isn't a perfect match, we'll prefer // mBackgroundLayoutState since it will have the more recent create. return false; } else { // If the main thread layout is still compatible size-wise, and the // background one is not, then we'll do nothing. We want to keep the same // main thread layout so that we don't force main thread re-layout. return true; } }