protected void releaseDiff(Diff diff) { if (ComponentsConfiguration.disablePools) { return; } ComponentsPools.release(diff); }
protected final <T> Diff<T> acquireDiff(T previousValue, T nextValue) { Diff<T> diff = ComponentsPools.acquireDiff(previousValue, nextValue); return diff; }
@Override protected void onMeasure( ComponentContext c, ComponentLayout layout, int widthSpec, int heightSpec, Size size) { final V toMeasure = (V) ComponentsPools.acquireMountContent(c.getAndroidContext(), this); final ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(size.width, size.height); toMeasure.setLayoutParams(layoutParams); mViewBinder.bind(toMeasure); if (toMeasure.getVisibility() == View.GONE) { // No need to measure the view if binding it caused its visibility to become GONE. size.width = 0; size.height = 0; } else { toMeasure.measure(widthSpec, heightSpec); size.width = toMeasure.getMeasuredWidth(); size.height = toMeasure.getMeasuredHeight(); } mViewBinder.unbind(toMeasure); ComponentsPools.release(c.getAndroidContext(), this, toMeasure); }
void processVisibilityOutputs() { assertMainThread(); if (!mIncrementalMountEnabled) { throw new IllegalStateException( "Calling processVisibilityOutputs() but incremental mount is not enabled"); } if (mLithoView == null) { return; } if (mMainThreadLayoutState == null) { Log.w(TAG, "Main Thread Layout state is not found"); return; } final Rect currentVisibleArea = ComponentsPools.acquireRect(); if (mLithoView.getLocalVisibleRect(currentVisibleArea)) { mLithoView.processVisibilityOutputs(mMainThreadLayoutState, currentVisibleArea); } // if false: no-op, doesn't have visible area, is not ready or not attached ComponentsPools.release(currentVisibleArea); }
@Test public void testDestroyingActivityDoesNotAffectPoolingOfOtherContexts() { mActivityController.destroy(); ComponentsPools.onContextDestroyed(mActivity); release(mContext1, mLifecycle, mMountContent); assertThat(acquireMountContent(mContext1, mLifecycle)).isSameAs(mMountContent); }
@Test public void testAllocationsCountTowardsPreallocationLimit() { for (int i = 0; i < POOL_SIZE - 1; i++) { maybePreallocateContent(mContext1, mLifecycle); acquireMountContent(mContext1, mLifecycle); } acquireMountContent(mContext1, mLifecycle); // Allocation limit should be hit now, so we shouldn't preallocate anything maybePreallocateContent(mContext1, mLifecycle); mNewMountContent = new View(mContext1); assertThat(acquireMountContent(mContext1, mLifecycle)).isSameAs(mNewMountContent); }
InternalNode newLayoutBuilder(@AttrRes int defStyleAttr, @StyleRes int defStyleRes) { final InternalNode node = ComponentsPools.acquireInternalNode(this); applyStyle(node, defStyleAttr, defStyleRes); return node; }
ComponentsPools.release(item); final MountItem mountItem = layoutOutputId == -1 ? null : mIndexToItemMap.get(layoutOutputId); final TestItem testItem = ComponentsPools.acquireTestItem(); testItem.setHost(hostMarker == -1 ? null : mHostsByMarker.get(hostMarker)); testItem.setBounds(testOutput.getBounds());
ComponentsPools.release(mDataHolders.get(i)); prevDataHolders.add(ComponentsPools.acquireDiff(mPrevData.get(i), null)); dataHolders.add(ComponentsPools.acquireDiff(null, model));
final ArraySet<ValueNode> leafNodes = ComponentsPools.acquireArraySet(); final SimpleArrayMap<ValueNode, Integer> nodesToOutputsLeft = new SimpleArrayMap<>(); final ArrayDeque<ValueNode> nodesToProcess = ComponentsPools.acquireArrayDeque(); nodesToProcess.addAll(leafNodes); mIsDirty = false; ComponentsPools.release(nodesToProcess); ComponentsPools.release(leafNodes);
@Test public void testPoolRelease() { final TestOutput testOutput = ComponentsPools.acquireTestOutput(); testOutput.setBounds(0, 1, 2, 3); testOutput.setTestKey("testkey"); testOutput.setHostMarker(1337); testOutput.setLayoutOutputId(42); ComponentsPools.release(testOutput); assertDefaultValues(testOutput); }
@Before public void setUp() { mDiffNode = mock(DiffNode.class); mNode = mock(InternalNode.class); final YogaNode cssNode = new YogaNode(); cssNode.setData(mNode); mNode.mYogaNode = cssNode; mockStatic(ComponentsPools.class); when(mNode.getLastWidthSpec()).thenReturn(-1); when(mNode.getDiffNode()).thenReturn(mDiffNode); when(mDiffNode.getLastMeasuredWidth()).thenReturn(-1f); when(mDiffNode.getLastMeasuredHeight()).thenReturn(-1f); when(ComponentsPools.acquireInternalNode(any(ComponentContext.class))).thenReturn(mNode); when(ComponentsPools.acquireComponentTreeBuilder( any(ComponentContext.class), any(Component.class))) .thenCallRealMethod(); mockStatic(LayoutState.class); StateHandler stateHandler = mock(StateHandler.class); mContext = spy(new ComponentContext(RuntimeEnvironment.application, stateHandler)); mNestedTreeWidthSpec = SizeSpec.makeSizeSpec(400, SizeSpec.EXACTLY); mNestedTreeHeightSpec = SizeSpec.makeSizeSpec(200, SizeSpec.EXACTLY); }
final ArrayList<LithoView> lithoViews = ComponentsPools.acquireLithoViewArrayList(); ((HasLithoViewChildren) content).obtainLithoViewChildren(lithoViews); lithoView.unmountAllItems(); ComponentsPools.release(lithoViews); ComponentsPools.release(mContext.getAndroidContext(), item);
ComponentsPools.release(visibilityItem); visibilityItem = null; } else { : null; visibilityItem = ComponentsPools.acquireVisibilityItem( globalKey, invisibleHandler, unfocusedHandler, visibilityChangedHandler); visibilityItem.setDoNotClearInThisPass(mIsDirty);
public static Object getMountContent(ComponentContext c, Component component) { return ComponentsPools.acquireMountContent(c.getAndroidContext(), component); } }
static InternalNode acquireInternalNode(ComponentContext componentContext) { InternalNode node = ComponentsConfiguration.disablePools ? null : sInternalNodePool.acquire(); if (node == null) { node = PoolsConfig.sInternalNodeFactory != null ? PoolsConfig.sInternalNodeFactory.create() : new InternalNode(); } node.init(acquireYogaNode(), componentContext); return node; }
@Override public void onActivityDestroyed(Activity activity) { ComponentsPools.onContextDestroyed(activity); } }
public static Builder create(ComponentContext context, @NonNull Component root) { if (root == null) { throw new NullPointerException("Creating a ComponentTree with a null root is not allowed!"); } return ComponentsPools.acquireComponentTreeBuilder(context, root); }
@ThreadSafe(enableChecks = false) void preAllocateMountContent(boolean shouldPreallocatePerMountSpec) { final boolean isTracing = ComponentsSystrace.isTracing(); if (isTracing) { ComponentsSystrace.beginSection("preAllocateMountContent:" + mComponent.getSimpleName()); } if (mMountableOutputs != null && !mMountableOutputs.isEmpty()) { for (int i = 0, size = mMountableOutputs.size(); i < size; i++) { final Component component = mMountableOutputs.get(i).getComponent(); if (shouldPreallocatePerMountSpec && !component.canPreallocate()) { continue; } if (Component.isMountViewSpec(component)) { if (isTracing) { ComponentsSystrace.beginSection("preAllocateMountContent:" + component.getSimpleName()); } ComponentsPools.maybePreallocateContent(mContext.getAndroidContext(), component); if (isTracing) { ComponentsSystrace.endSection(); } } } } if (isTracing) { ComponentsSystrace.endSection(); } }
private static TestOutput createTestOutput( InternalNode node, LayoutState layoutState, LayoutOutput layoutOutput) { final int l = layoutState.mCurrentX + node.getX(); final int t = layoutState.mCurrentY + node.getY(); final int r = l + node.getWidth(); final int b = t + node.getHeight(); final TestOutput output = ComponentsPools.acquireTestOutput(); output.setTestKey(node.getTestKey()); output.setBounds(l, t, r, b); output.setHostMarker(layoutState.mCurrentHostMarker); if (layoutOutput != null) { output.setLayoutOutputId(layoutOutput.getId()); } return output; }