Skip to content
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

[macOS] Multiview compositor #52253

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

dkwingsmt
Copy link
Contributor

This PR makes the macOS FlutterCompositor able to handle multiple views by adding methods AddView and RemoveView.

These two methods must take place on the main queue (platform thread), which is indeed the case, but extra effort is made to assert so. This is important because, due to the constraint of the macOS system that requires rendering to take place on the platform thread (hence FlutterThreadSynchronizer), no locks are needed to avoid race condition between Add/RemoveView and presenting.

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 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.

@dkwingsmt
Copy link
Contributor Author

Also cc @loic-sharma

Copy link
Member

@loic-sharma loic-sharma left a comment

Choose a reason for hiding this comment

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

This looks good to me, but please get approval from someone familiar with this area

@@ -851,10 +860,6 @@ - (FlutterViewController*)viewController {
}

- (FlutterCompositor*)createFlutterCompositor {
Copy link
Member

Choose a reason for hiding this comment

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

Is this still the right name for the method? "Create" usually implies allocation of some sort. Here what we're doing is more like initialisation the existing field and returning a pointer to it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's still a reasonable name. For whoever uses FlutterEngine, this method creates a embedderAPI/FlutterCompositor object and returns it. How the object is memory-managed is implementation detail.

FlutterCompositor(id<FlutterViewProvider> view_provider,
FlutterTimeConverter* time_converter,
FlutterPlatformViewController* platform_views_controller);
FlutterPlatformViewController* platform_views_controller,
dispatch_queue_t main_queue);
Copy link
Member

Choose a reason for hiding this comment

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

Is there ever a case where this isn't the main queue returned by dispatch_get_main_queue()? If not, I think we should just test dispatch_get_current_queue() == dispatch_get_main_queue() where necessary.

Copy link
Contributor Author

@dkwingsmt dkwingsmt Apr 25, 2024

Choose a reason for hiding this comment

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

I'm mostly thinking about testability, although there really aren't many tests for FlutterCompositor. However, the ThreadSynchronizer accepts the queue as a replaceable parameter (which was added when I wrote tests for it). I think it's a clearer design if the same queue is passed in for both classes in production code.

Copy link
Contributor Author

@dkwingsmt dkwingsmt Apr 25, 2024

Choose a reason for hiding this comment

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

Ok, ThreadSynchronizer has two initializers, one of which uses the main queue implicitly, which is used in production code. Still, its internal implementation allows a replaceable queue. I'm ok with any suggestion.

Copy link
Member

@cbracken cbracken left a comment

Choose a reason for hiding this comment

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

Mostly lgtm - main question is why we need to pass in the dispatch queue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants