@@ -99,19 +99,23 @@ AnimationBackend::AnimationBackend(
9999
100100void AnimationBackend::onAnimationFrame (double timestamp) {
101101 std::unordered_map<Tag, AnimatedProps> updates;
102- std::unordered_set<const ShadowNodeFamily*> families;
102+ std::unordered_map<SurfaceId, std::unordered_set<const ShadowNodeFamily*>>
103+ surfaceToFamilies;
103104 bool hasAnyLayoutUpdates = false ;
104105 for (auto & callback : callbacks) {
105106 auto muatations = callback (static_cast <float >(timestamp));
106107 for (auto & mutation : muatations) {
107108 hasAnyLayoutUpdates |= mutationHasLayoutUpdates (mutation);
108- families.insert (mutation.family );
109+ const auto family = mutation.family ;
110+ if (family != nullptr ) {
111+ surfaceToFamilies[family->getSurfaceId ()].insert (family);
112+ }
109113 updates[mutation.tag ] = std::move (mutation.props );
110114 }
111115 }
112116
113117 if (hasAnyLayoutUpdates) {
114- commitUpdatesWithFamilies (families , updates);
118+ commitUpdates (surfaceToFamilies , updates);
115119 } else {
116120 synchronouslyUpdateProps (updates);
117121 }
@@ -137,29 +141,43 @@ void AnimationBackend::stop(bool isAsync) {
137141 callbacks.clear ();
138142}
139143
140- void AnimationBackend::commitUpdatesWithFamilies (
141- const std::unordered_set<const ShadowNodeFamily*>& families,
144+ void AnimationBackend::commitUpdates (
145+ const std::unordered_map<
146+ SurfaceId,
147+ std::unordered_set<const ShadowNodeFamily*>>& surfaceToFamilies,
142148 std::unordered_map<Tag, AnimatedProps>& updates) {
143- uiManager_->getShadowTreeRegistry ().enumerate(
144- [families, &updates](const ShadowTree& shadowTree, bool & /* stop*/ ) {
145- shadowTree.commit (
146- [families, &updates](const RootShadowNode& oldRootShadowNode) {
147- return std::static_pointer_cast<RootShadowNode>(
148- oldRootShadowNode.cloneMultiple (
149- families,
150- [families, &updates](
151- const ShadowNode& shadowNode,
152- const ShadowNodeFragment& fragment) {
153- auto & animatedProps = updates.at (shadowNode.getTag ());
154- auto newProps = cloneProps (animatedProps, shadowNode);
155- return shadowNode.clone (
156- {newProps,
157- fragment.children ,
158- shadowNode.getState ()});
159- }));
160- },
161- {.mountSynchronously = true });
162- });
149+ for (const auto & surfaceEntry : surfaceToFamilies) {
150+ const auto & surfaceId = surfaceEntry.first ;
151+ const auto & surfaceFamilies = surfaceEntry.second ;
152+ uiManager_->getShadowTreeRegistry ().visit (
153+ surfaceId, [&surfaceFamilies, &updates](const ShadowTree& shadowTree) {
154+ shadowTree.commit (
155+ [&surfaceFamilies,
156+ &updates](const RootShadowNode& oldRootShadowNode) {
157+ return std::static_pointer_cast<RootShadowNode>(
158+ oldRootShadowNode.cloneMultiple (
159+ surfaceFamilies,
160+ [&surfaceFamilies, &updates](
161+ const ShadowNode& shadowNode,
162+ const ShadowNodeFragment& fragment) {
163+ auto newProps =
164+ ShadowNodeFragment::propsPlaceholder ();
165+ if (surfaceFamilies.contains (
166+ &shadowNode.getFamily ())) {
167+ auto & animatedProps =
168+ updates.at (shadowNode.getTag ());
169+ newProps = cloneProps (animatedProps, shadowNode);
170+ }
171+ return shadowNode.clone (
172+ {.props = newProps,
173+ .children = fragment.children ,
174+ .state = shadowNode.getState (),
175+ .runtimeShadowNodeReference = false });
176+ }));
177+ },
178+ {.mountSynchronously = true });
179+ });
180+ }
163181}
164182
165183void AnimationBackend::synchronouslyUpdateProps (
0 commit comments