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

Conversation

@dkwingsmt
Copy link
Contributor

@dkwingsmt dkwingsmt commented Nov 10, 2021

This PR changes how embedder API's SendKeyData sends ui.KeyData to the framework.

Currently the packet is sent over FFI through a series of DispatchKeyData methods that drill all the way from Window to EmbedderEngine. Not only is it cumbersome, but it also bypasses the existing buffering mechanism, leading to a crash as described in flutter/flutter#89748 (comment).

This PR changes the packet to be sent over the existing platform messenger, reusing the entirety of its code path and functionalities while keeping the embedder API unchanged.

This partially fixes flutter/flutter#89748 (comment). Since the buffer size is only 1, if 2 or more events are sent during the restart (which usually means holding multiple keys) the crash will still occur. There's a way to resize the buffer, but I haven't found a way to actually do it yet, and will explore as the next step.

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-fuchsia platform-ios platform-web Code specifically for the web engine labels Nov 10, 2021
@google-cla google-cla bot added the cla: yes label Nov 10, 2021
@Hixie
Copy link
Contributor

Hixie commented Nov 10, 2021

We should document the protocol somewhere so that new embedders know what to implement.

@chinmaygarde
Copy link
Member

We should document the protocol somewhere so that new embedders know what to implement.

@Hixie: The public embedder API defines this in the FlutterKeyEvent struct. I believe this was in response to the earlier approach where embedders had to reverse-engineer the payload from what iOS or Android were doing. The protocol in this patch remains unchanged (and is documented). It just affects how the information is ferried to the framework.

Currently the packet is sent over FFI

Ah, I thought you meant dart:ffi for second and I was confused. That term is really overloaded. Yeah, making use of platform of the channels mechanism makes sense.

while keeping the embedder API unchanged.

Awesome. Yeah, this approach makes sense.

@dkwingsmt
Copy link
Contributor Author

Awesome. Thank you. I'll make some final changes before sending over for reviewing.

Comment on lines 1639 to 1640
FlutterEngineResult result2 =
FlutterPlatformMessageReleaseResponseHandle(engine, response_handle);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I think we can move this down below the if right? Also, please use a more descriptive name than result2, or, alternatively, just change the return result2 to return FlutterPlatofrmMessageReleaseResponseHandle(engine, response_handle);.

Copy link
Contributor Author

@dkwingsmt dkwingsmt Nov 11, 2021

Choose a reason for hiding this comment

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

No. It's exactly what this awkward structure means: Even if the SendPlatformMessage call fails, we still need to release the response handle (basically a manual try...finally). I'll add a comment for it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh ok, it's doing some kind of RAII thing here?

At any rate, it should be named better than result2 :)

@dnfield
Copy link
Contributor

dnfield commented Nov 11, 2021

What's the impact on latency here, if any?

I'm curious about why we don't experience the same problem(s) with pointer data packets too.

@dkwingsmt
Copy link
Contributor Author

What's the impact on latency here, if any?

I don't think it impact latency at all, since the old way is basically implementing a parallel platform messenger.

I'm curious about why we don't experience the same problem(s) with pointer data packets too.

The keyboard system uses a much stricter regularization check, which asserts for any irregular event sequence, while the pointer data converter is much more tolerant and will fill the gap if possible.

@skia-gold
Copy link

Gold has detected about 69 new digest(s) on patchset 15.
View them at https://flutter-engine-gold.skia.org/cl/github/29638

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes embedder Related to the embedder API platform-fuchsia platform-ios platform-web Code specifically for the web engine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants