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

Conversation

@loic-sharma
Copy link
Member

@loic-sharma loic-sharma commented Mar 21, 2024

Adds FlutterDesktopEngineCreateViewController to the Windows embedder's C API. Example usage:

// Create the engine.
FlutterDesktopEngineProperties engine_properties = {};
auto engine = FlutterDesktopEngineCreate(&engine_properties);

// Create a views controller.
FlutterDesktopViewControllerProperties properties = {};
properties.width = 400;
properties.height = 400;

auto controller = FlutterDesktopEngineCreateViewController(engine, &properties);

// Run app...

// Destroy the view controller. This does not destroy the engine. 
FlutterDesktopViewControllerDestroy(controller);

// Destroy the engine.
FlutterDesktopEngineDestroy(engine);

This new API creates a view controller that does not own the engine, unlike the existing FlutterDesktopEngineCreateViewController. In the future, this new API will allow a Windows app to have multiple views that share a single engine.

This API is in the flutter_windows_internal.h, making it "pubternal". This API is not in the public Windows header files, however, one can link against this API for testing purposes. This API will be promoted to the public Windows header files once the Windows embedder is ready to have multiple views.

Relevant design documents:

  1. https://flutter.dev/go/desktop-multi-view-runner-apis
  2. http://flutter.dev/go/windows-multi-view-ownership-updates

Relevant issues:

  1. [Windows] Add multi-view runner APIs flutter#143767
  2. ☂️ Multi View for Windows/MacOS flutter#142845

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.

Copy link
Contributor

@dkwingsmt dkwingsmt left a comment

Choose a reason for hiding this comment

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

LGTM

// |FlutterDesktopViewControllerDestroy|. Returns a null pointer in the event of
// an error.
//
// Unlike |FlutterDesktopViewControllerCreate|, this does *not* take ownership
Copy link
Contributor

Choose a reason for hiding this comment

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

We might want to add a similar paragraph to FlutterDesktopViewControllerCreate as well, so that they can refer to each other. And also we might want to mention that:

// In an app with multiple view controllers, it is highly recommend to use
// `FlutterDesktopEngineCreateViewController` for all view controllers and avoid
// `FlutterDesktopViewControllerCreate`.

Copy link
Member Author

@loic-sharma loic-sharma Mar 21, 2024

Choose a reason for hiding this comment

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

We'll definitely want a blurb like this eventually, however, FlutterDesktopEngineCreateViewController isn't in the public header yet. Adding this right now would be confusing to our customers as they can't use this API yet.

I'll make sure to add such a comment when we make this runner API public.

// using |FlutterDesktopViewControllerCreate| as that takes
// ownership of the engine. View controllers created using
// |FlutterDesktopEngineCreateViewController| do not take
// ownership of the engine and do not set this.
Copy link
Contributor

Choose a reason for hiding this comment

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

Add

// If `engine_` is not null, it will be deallocated upon
// the view controller's destruction.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tweaked the wording, hopefully it's clearer now.

@loic-sharma loic-sharma added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 22, 2024
@auto-submit auto-submit bot merged commit c118a69 into flutter:main Mar 22, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 22, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Mar 22, 2024
…145611)

flutter/engine@09dadce...63ff0de

2024-03-22 [email protected] [Embedder API] Add helper to create viewport metrics (flutter/engine#51562)
2024-03-22 [email protected] [Windows] Allow view controllers to not own the engine (flutter/engine#51570)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

affects: desktop autosubmit Merge PR when tree becomes green via auto submit App platform-windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants