Refactor of IntBufferBatchMountItem class (#36728)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/36728

This diff refactors the creation and visibility of IntBufferBatchMountItem

This is not a breaking compatibility change because nobody should be using this class

changelog: [internal] internal

Reviewed By: javache

Differential Revision: D44115916

fbshipit-source-id: f0b0464483cafe55ffaf661b18c692be0df41199
This commit is contained in:
David Vacca
2023-03-30 23:58:25 -07:00
committed by Facebook GitHub Bot
parent ed448b5ba4
commit b1b118d0f6
8 changed files with 36 additions and 12 deletions
@@ -59,7 +59,7 @@ import com.facebook.react.fabric.mounting.MountItemDispatcher;
import com.facebook.react.fabric.mounting.MountingManager;
import com.facebook.react.fabric.mounting.SurfaceMountingManager;
import com.facebook.react.fabric.mounting.SurfaceMountingManager.ViewEvent;
import com.facebook.react.fabric.mounting.mountitems.IntBufferBatchMountItem;
import com.facebook.react.fabric.mounting.mountitems.BatchMountItem;
import com.facebook.react.fabric.mounting.mountitems.MountItem;
import com.facebook.react.fabric.mounting.mountitems.MountItemFactory;
import com.facebook.react.modules.core.ReactChoreographer;
@@ -724,7 +724,8 @@ public class FabricUIManager implements UIManager, LifecycleEventListener {
@ThreadConfined(ANY)
private MountItem createIntBufferBatchMountItem(
int rootTag, int[] intBuffer, Object[] objBuffer, int commitNumber) {
return new IntBufferBatchMountItem(rootTag, intBuffer, objBuffer, commitNumber);
return MountItemFactory.createIntBufferBatchMountItem(
rootTag, intBuffer, objBuffer, commitNumber);
}
/**
@@ -749,9 +750,9 @@ public class FabricUIManager implements UIManager, LifecycleEventListener {
// a BatchMountItem. No other sites call into this with a BatchMountItem, and Binding.cpp only
// calls scheduleMountItems with a BatchMountItem.
long scheduleMountItemStartTime = SystemClock.uptimeMillis();
boolean isBatchMountItem = mountItem instanceof IntBufferBatchMountItem;
boolean isBatchMountItem = mountItem instanceof BatchMountItem;
boolean shouldSchedule =
(isBatchMountItem && ((IntBufferBatchMountItem) mountItem).shouldSchedule())
(isBatchMountItem && !((BatchMountItem) mountItem).isBatchEmpty())
|| (!isBatchMountItem && mountItem != null);
// In case of sync rendering, this could be called on the UI thread. Otherwise,
@@ -0,0 +1,14 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.fabric.mounting.mountitems;
public interface BatchMountItem extends MountItem {
/** @return if the BatchMountItem contains any MountItem */
boolean isBatchEmpty();
}
@@ -12,7 +12,7 @@ import androidx.annotation.Nullable;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.fabric.mounting.MountingManager;
class DispatchIntCommandMountItem extends DispatchCommandMountItem {
final class DispatchIntCommandMountItem extends DispatchCommandMountItem {
private final int mSurfaceId;
private final int mReactTag;
@@ -12,7 +12,7 @@ import androidx.annotation.Nullable;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.fabric.mounting.MountingManager;
class DispatchStringCommandMountItem extends DispatchCommandMountItem {
final class DispatchStringCommandMountItem extends DispatchCommandMountItem {
private final int mSurfaceId;
private final int mReactTag;
@@ -34,7 +34,7 @@ import com.facebook.systrace.Systrace;
* allocations in C++ and JNI round-trips.
*/
@DoNotStrip
public class IntBufferBatchMountItem implements MountItem {
final class IntBufferBatchMountItem implements BatchMountItem {
static final String TAG = IntBufferBatchMountItem.class.getSimpleName();
static final int INSTRUCTION_FLAG_MULTIPLE = 1;
@@ -60,7 +60,7 @@ public class IntBufferBatchMountItem implements MountItem {
private final int mIntBufferLen;
private final int mObjBufferLen;
public IntBufferBatchMountItem(int surfaceId, int[] intBuf, Object[] objBuf, int commitNumber) {
IntBufferBatchMountItem(int surfaceId, int[] intBuf, Object[] objBuf, int commitNumber) {
mSurfaceId = surfaceId;
mCommitNumber = commitNumber;
@@ -193,8 +193,9 @@ public class IntBufferBatchMountItem implements MountItem {
return mSurfaceId;
}
public boolean shouldSchedule() {
return mIntBufferLen != 0;
@Override
public boolean isBatchEmpty() {
return mIntBufferLen == 0;
}
@Override
@@ -46,4 +46,12 @@ public class MountItemFactory {
return new PreAllocateViewMountItem(
surfaceId, reactTag, component, props, stateWrapper, eventEmitterWrapper, isLayoutable);
}
/**
* @return a {@link MountItem} that will be read and execute a collection of MountItems serialized
* in the int[] and Object[] received by parameter
*/
public static MountItem createIntBufferBatchMountItem(
int surfaceId, int[] intBuf, Object[] objBuf, int commitNumber) {
return new IntBufferBatchMountItem(surfaceId, intBuf, objBuf, commitNumber);
}
}
@@ -20,7 +20,7 @@ import com.facebook.react.fabric.mounting.SurfaceMountingManager;
import com.facebook.react.uimanager.StateWrapper;
/** {@link MountItem} that is used to pre-allocate views for JS components. */
public class PreAllocateViewMountItem implements MountItem {
final class PreAllocateViewMountItem implements MountItem {
private final @NonNull String mComponent;
private final int mSurfaceId;
@@ -12,7 +12,7 @@ import com.facebook.react.bridge.ReactSoftExceptionLogger;
import com.facebook.react.bridge.RetryableMountingLayerException;
import com.facebook.react.fabric.mounting.MountingManager;
class SendAccessibilityEventMountItem implements MountItem {
final class SendAccessibilityEventMountItem implements MountItem {
private final String TAG = "Fabric.SendAccessibilityEvent";