Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[Embedder API] Introduce new semantics update callback and migrate Windows #37129

Merged
merged 1 commit into from
Nov 7, 2022

Conversation

loic-sharma
Copy link
Member

@loic-sharma loic-sharma commented Oct 28, 2022

This introduces a new embedder API to notify the embedder of semantic updates, and, migrates Windows to this new embedder API. The Linux and macOS migrations will be done in follow-up changes.

Part of flutter/flutter#114201

Background

In the old embedder API, the engine breaks up a batch of semantic updates and sends each update individually to the embedder. This is problematic as there may be dependencies across these updates, so the ordering of these updates is crucial to prevent crashes (see flutter/flutter#103808 and #35792). In other words, there was an implicit contract between the embedder and the engine on the ordering of these updates.

The new embedder API just sends the entire batch of semantic updates in one go, allowing us to remove ordering concerns from the embedder API.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See testing the engine for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard flutter-dashboard bot added embedder Related to the embedder API platform-windows labels Oct 28, 2022
ASSERT_FALSE(engine.is_valid());
engine.reset();
}

TEST_F(EmbedderA11yTest, A11yTreeIsConsistent) {
Copy link
Member Author

@loic-sharma loic-sharma Oct 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This diff is a bit confusing. The contents of the old A11TreeIsConsistent was moved to a new test A11yTreeIsConsistentUsingLegacyCallbacks, which starts below on line 215. This A11TreeIsConsistent now tests the new embedder API.

@loic-sharma loic-sharma force-pushed the embedder_update_semantics branch from b582aaf to af21cf7 Compare October 29, 2022 00:46
@loic-sharma loic-sharma marked this pull request as ready for review October 31, 2022 19:54
Copy link
Contributor

@yaakovschectman yaakovschectman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I just want to ask if there is any particular reason to have a method which returns the callback function instead of storing the sub-callbacks as members like before and calling them all from a callback method instead?

@loic-sharma
Copy link
Member Author

loic-sharma commented Oct 31, 2022

EDIT: After mulling this over, the two layers of "translation" callbacks adds too much cognitive overhead. I will simplify this to just a single layer of "translation" callbacks.

Original reply...

@yaakovschectman The high-level flow hasn't changed, here's how registering the embedder's callbacks work before and after this change:

  1. Embedder provides callbacks in FlutterProjectArgs
  2. Engine wraps the embedder's callbacks in a PlatformViewEmbedder::UpdateSemanticsCallback. This wrapper callback translates engine updates to embedder updates
  3. Engine passes this "translation" callback to PlatformViewEmbedder

... there is any particular reason to have a method which returns the callback function

After this change, there are now two layers of "translation" callbacks:

  1. Translate engine updates to embedder updates
  2. Translate embedder updates to the legacy embedder callbacks, if needed

The CreateEmbedderSemanticsUpdateCallback creates that second "translation" callback

... instead of storing the sub-callbacks as members like before and calling them all from a callback method instead

This still works the same way as before: the embedder provides its callbacks using FlutterProjectArgs, and these embedder callbacks are captured by the "translation" callback that is passed to PlatformViewEmbedder. Here is where the embedder callbacks were captured before.

Please let me know if I misunderstood something! Also, please let me know if you have suggestions on how to improve clarity!

@loic-sharma loic-sharma marked this pull request as draft October 31, 2022 22:54
@loic-sharma loic-sharma marked this pull request as ready for review November 1, 2022 00:15
@loic-sharma
Copy link
Member Author

@yaakovschectman I simplified this change, please take another look! Below is the updated version of this comment.

The high-level flow for the callbacks hasn't changed, here's it works for both before and after this change:

  1. Embedder provides callbacks in FlutterProjectArgs
  2. Engine wraps the embedder's callbacks in a PlatformViewEmbedder::UpdateSemanticsCallback. This wrapper callback translates engine updates to embedder updates
  3. Engine passes this "translation" callback to PlatformViewEmbedder

... there is any particular reason to have a method which returns the callback function

After this change, there are now three possible "translation" callbacks:

  1. Translate to the 'new' embedder callback update_semantics_callback
  2. Translate to the 'old' embedder callbacks update_semantics_node_callback and update_semantics_custom_action_callback
  3. Do nothing if the embedder registered no callbacks

The CreateEmbedderSemanticsUpdateCallback method picks which "translation" callback should be registered to the PlatformViewEmbedder.

... instead of storing the sub-callbacks as members like before and calling them all from a callback method instead

This still works the same way as before: the embedder provides its callbacks using FlutterProjectArgs, and these embedder callbacks are captured by the "translation" callback that is passed to PlatformViewEmbedder. Here is where the embedder callbacks were captured before.

Please let me know if I misunderstood something! Also, please let me know if you have suggestions on how to improve clarity!

Copy link
Contributor

@a-wallen a-wallen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@loic-sharma loic-sharma force-pushed the embedder_update_semantics branch from e01274b to 6f4996b Compare November 1, 2022 20:08
Copy link
Contributor

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, do you have a pr to migrate the macOS as well?

@loic-sharma
Copy link
Member Author

loic-sharma commented Nov 2, 2022

@chunhtai Not yet, I was waiting to in case the embedder API received feedback. The macOS changes will be very similar to the Windows changes.

EDIT: Here's a prototype of the macOS changes: loic-sharma@5ddcc8a

@loic-sharma loic-sharma force-pushed the embedder_update_semantics branch from 57db430 to ea97a5e Compare November 3, 2022 23:02
GetUpdateSemanticsNodeCallbackHook();
FlutterUpdateSemanticsCallback GetUpdateSemanticsCallbackHook();

FlutterUpdateSemanticsNodeCallback GetUpdateSemanticsNodeCallbackHook();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these be removed now that we have the alternative? It doesn't look like we ever actually use them in tests (or maybe I'm mis-grepping).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are still used by the A11yTreeIsConsistentUsingLegacyCallbacks unit test to test the legacy callbacks (see the context.SetSemanticsNodeCallback and context.SetSemanticsCustomActionCallback calls)

@cbracken
Copy link
Member

cbracken commented Nov 4, 2022

LGTM stamp from a Japanese personal seal

@loic-sharma loic-sharma force-pushed the embedder_update_semantics branch from 891c857 to 775ffec Compare November 4, 2022 23:58
@loic-sharma loic-sharma added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 7, 2022
@auto-submit auto-submit bot merged commit 3d9f485 into flutter:main Nov 7, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 7, 2022
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Nov 7, 2022
…114847)

* 3d9f48580 [Embedder API] Introduce new semantics update callback (flutter/engine#37129)

* b673ce3c3 Roll Skia from da9fad017aee to dec7a930c0b7 (10 revisions) (flutter/engine#37390)

* df602070a [Web] Synthesize modifiers key up based on known logical key (flutter/engine#37280)
naudzghebre pushed a commit to naudzghebre/engine that referenced this pull request Nov 9, 2022
@cbracken
Copy link
Member

cbracken commented Nov 9, 2022

/cc @chinmaygarde

@flar
Copy link
Contributor

flar commented Nov 10, 2022

The unit test here is consistently exceeding the 120s timeouts in runs: https://ci.chromium.org/p/flutter/builders/try/Mac%20Host%20Engine

Starting a revert...

@flar
Copy link
Contributor

flar commented Nov 10, 2022

There is also a potential fix for the race conditions: #37488

@flar
Copy link
Contributor

flar commented Nov 10, 2022

I closed the revert in favor of the fix - #37488

@yaakovschectman
Copy link
Contributor

Just noticed this accidentally removed the tooltip from the embedder callback. Will need to add that back in #37676

shogohida pushed a commit to shogohida/flutter that referenced this pull request Dec 7, 2022
…lutter#114847)

* 3d9f48580 [Embedder API] Introduce new semantics update callback (flutter/engine#37129)

* b673ce3c3 Roll Skia from da9fad017aee to dec7a930c0b7 (10 revisions) (flutter/engine#37390)

* df602070a [Web] Synthesize modifiers key up based on known logical key (flutter/engine#37280)
gspencergoog pushed a commit to gspencergoog/flutter that referenced this pull request Jan 19, 2023
…lutter#114847)

* 3d9f48580 [Embedder API] Introduce new semantics update callback (flutter/engine#37129)

* b673ce3c3 Roll Skia from da9fad017aee to dec7a930c0b7 (10 revisions) (flutter/engine#37390)

* df602070a [Web] Synthesize modifiers key up based on known logical key (flutter/engine#37280)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
autosubmit Merge PR when tree becomes green via auto submit App embedder Related to the embedder API platform-windows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants