Skip to content
Open
Show file tree
Hide file tree
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 @@ -1092,7 +1092,17 @@ void FabricMountingManager::drainPreallocateViewsQueue() {
{
std::lock_guard allocatedViewsLock(allocatedViewsMutex_);
for (auto& [shadowView, family] : queuedViews) {
if (pullModel && family.expired()) {
auto queuedFamily = family.lock();
if (pullModel && queuedFamily == nullptr) {
continue;
}
// Once a family is part of a committed tree, its view is executeMount's
// to create. The commit can run before this drain and both create and
// delete the view, e.g. when it is flattened again by the next commit;
// registering the tag now would leave it allocated with no view behind
// it, and its next Create would be skipped. executeMount takes
// allocatedViewsMutex_ after the commit has marked the family mounted.
if (queuedFamily != nullptr && queuedFamily->hasBeenMounted()) {
continue;
}
auto allocatedViewsIterator =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ void FabricMountingManagerTestHelper::drainPreallocationQueue() {
mountingManager_->drainPreallocateViewsQueue();
}

void FabricMountingManagerTestHelper::executeCreateMutation(
void FabricMountingManagerTestHelper::executeMutation(
jint surfaceId,
jint tag) {
ShadowViewMutation mutation) {
auto telemetry = TransactionTelemetry{};
telemetry.willCommit();
telemetry.willDiff();
Expand All @@ -233,11 +233,27 @@ void FabricMountingManagerTestHelper::executeCreateMutation(
telemetry.didLayout();
telemetry.didCommit();
mountingManager_->executeMount(
MountingTransaction{
surfaceId,
0,
{ShadowViewMutation::CreateMutation(makeShadowView(surfaceId, tag))},
telemetry});
MountingTransaction{surfaceId, 0, {std::move(mutation)}, telemetry});
}

void FabricMountingManagerTestHelper::executeCreateMutation(
jint surfaceId,
jint tag) {
executeMutation(
surfaceId,
ShadowViewMutation::CreateMutation(makeShadowView(surfaceId, tag)));
}

void FabricMountingManagerTestHelper::executeDeleteMutation(
jint surfaceId,
jint tag) {
executeMutation(
surfaceId,
ShadowViewMutation::DeleteMutation(makeShadowView(surfaceId, tag)));
}

void FabricMountingManagerTestHelper::commitQueuedView(jint tag) {
queuedShadowNodes_.at(tag)->setMounted(true);
}

void FabricMountingManagerTestHelper::dropFamily(jint tag) {
Expand Down Expand Up @@ -495,6 +511,12 @@ void FabricMountingManagerTestHelper::registerNatives() {
makeNativeMethod(
"executeCreateMutation",
FabricMountingManagerTestHelper::executeCreateMutation),
makeNativeMethod(
"executeDeleteMutation",
FabricMountingManagerTestHelper::executeDeleteMutation),
makeNativeMethod(
"commitQueuedView",
FabricMountingManagerTestHelper::commitQueuedView),
makeNativeMethod(
"dropFamily", FabricMountingManagerTestHelper::dropFamily),
makeNativeMethod(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class FabricMountingManagerTestHelper : public jni::HybridClass<FabricMountingMa
void queuePreallocation(jint surfaceId, jint tag);
void drainPreallocationQueue();
void executeCreateMutation(jint surfaceId, jint tag);
void executeDeleteMutation(jint surfaceId, jint tag);
// Marks the family of a view queued by queuePreallocation as part of a
// committed tree, as ShadowTree's commit does.
void commitQueuedView(jint tag);
void dropFamily(jint tag);
void destroyUnmountedView(jint surfaceId, jint tag);
void destroyCommittedView(jint surfaceId, jint tag);
Expand Down Expand Up @@ -66,6 +70,8 @@ class FabricMountingManagerTestHelper : public jni::HybridClass<FabricMountingMa

explicit FabricMountingManagerTestHelper(jni::alias_ref<JFabricUIManager::javaobject> jFabricUIManager);

void executeMutation(jint surfaceId, ShadowViewMutation mutation);

static void initHybrid(
jni::alias_ref<jhybridobject> jobj,
jni::alias_ref<JFabricUIManager::javaobject> jFabricUIManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,37 @@ class FabricMountingManagerInstrumentationTest {
assertThat(helper.isTagAllocated(surfaceId, 42)).isFalse()
}

/**
* A commit can create and delete a view before the queue drains, when the view is flattened again
* by the next commit. The drain must not register the tag again: its next Create would be skipped
* and the view would never exist.
*/
@Test
fun native_drainPreallocationQueue_skipsViewThatACommitCreatedAndDeleted() {
val helper = createTestHelper()
helper.startSurface(surfaceId)
helper.queuePreallocation(surfaceId, 42)
helper.commitQueuedView(42)
helper.executeCreateMutation(surfaceId, 42)
helper.executeDeleteMutation(surfaceId, 42)

helper.drainPreallocationQueue()

assertThat(helper.isTagAllocated(surfaceId, 42)).isFalse()
}

/** A view that no commit has taken yet is still preallocated. */
@Test
fun native_drainPreallocationQueue_preallocatesViewNotYetCommitted() {
val helper = createTestHelper()
helper.startSurface(surfaceId)
helper.queuePreallocation(surfaceId, 42)

helper.drainPreallocationQueue()

assertThat(helper.isTagAllocated(surfaceId, 42)).isTrue()
}

/** Without the pull model, a committed family does not destroy its view. */
@Test
fun native_destroyCommittedView_keepsPreallocatedView() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ private constructor(fabricUIManager: FabricUIManager) : HybridClassBase() {

external fun executeCreateMutation(surfaceId: Int, tag: Int)

external fun executeDeleteMutation(surfaceId: Int, tag: Int)

external fun commitQueuedView(tag: Int)

external fun dropFamily(tag: Int)

external fun destroyUnmountedView(surfaceId: Int, tag: Int)
Expand Down
Loading