Skip to content

Improve logic to report mounted surfaces #43337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicBoolean;

/**
* We instruct ProGuard not to strip out any fields or methods, because many of these methods are
Expand Down Expand Up @@ -173,7 +172,8 @@ public class FabricUIManager implements UIManager, LifecycleEventListener {
@NonNull
private final CopyOnWriteArrayList<UIManagerListener> mListeners = new CopyOnWriteArrayList<>();

@NonNull private final AtomicBoolean mMountNotificationScheduled = new AtomicBoolean(false);
private boolean mMountNotificationScheduled = false;
private final List<Integer> mMountedSurfaceIds = new ArrayList<>();

@ThreadConfined(UI)
@NonNull
Expand Down Expand Up @@ -1203,54 +1203,55 @@ public Map<String, Long> getPerformanceCounters() {
}

private class MountItemDispatchListener implements MountItemDispatcher.ItemDispatchListener {
@UiThread
@ThreadConfined(UI)
@Override
public void willMountItems(@Nullable List<MountItem> mountItems) {
for (UIManagerListener listener : mListeners) {
listener.willMountItems(FabricUIManager.this);
}
}

@UiThread
@ThreadConfined(UI)
@Override
public void didMountItems(@Nullable List<MountItem> mountItems) {
for (UIManagerListener listener : mListeners) {
listener.didMountItems(FabricUIManager.this);
}

if (!ReactFeatureFlags.enableMountHooks) {
if (!ReactFeatureFlags.enableMountHooks || mountItems == null || mountItems.isEmpty()) {
return;
}

boolean mountNotificationScheduled = mMountNotificationScheduled.getAndSet(true);
if (!mountNotificationScheduled) {
// Collect surface IDs for all the mount items
for (MountItem mountItem : mountItems) {
if (mountItem != null && !mMountedSurfaceIds.contains(mountItem.getSurfaceId())) {
mMountedSurfaceIds.add(mountItem.getSurfaceId());
}
}

if (!mMountNotificationScheduled && !mMountedSurfaceIds.isEmpty()) {
// Notify mount when the effects are visible and prevent mount hooks to
// delay paint.
UiThreadUtil.getUiThreadHandler()
.postAtFrontOfQueue(
new Runnable() {
@Override
public void run() {
mMountNotificationScheduled.set(false);

if (mDestroyed) {
return;
}
mMountNotificationScheduled = false;

final @Nullable Binding binding = mBinding;
if (mountItems == null || binding == null) {
if (binding == null || mDestroyed) {
mMountedSurfaceIds.clear();
return;
}

// Collect surface IDs for all the mount items
List<Integer> surfaceIds = new ArrayList<>();
for (MountItem mountItem : mountItems) {
if (mountItem != null && !surfaceIds.contains(mountItem.getSurfaceId())) {
surfaceIds.add(mountItem.getSurfaceId());
}
}

for (int surfaceId : surfaceIds) {
for (int surfaceId : mMountedSurfaceIds) {
binding.reportMount(surfaceId);
}

mMountedSurfaceIds.clear();
}
});
}
Expand Down