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

Commit b32363e

Browse files
authored
[Windows] Refactor client wrapper to prepare for multi-view (#52073)
_This is a refactoring with no semantic changes. No new public APIs are introduced by this change._ In the future, a new constructor will be added to `FlutterViewController` to allow it to use an existing `std::shared_ptr<FlutterEngine>` to create the view controller. This updates `FlutterViewController` to store a `std::shared_ptr` and other minor tweaks. For context, we plan to not land the new multi-window `FlutterViewController` constructor until Window's multi-window support is productionized. Until then, we will maintain a [patch](flutter/flutter#143767 (comment)) for folks that want to experiment with multi-window. This change makes that patch as small as possible. Design doc: [flutter.dev/go/desktop-multi-view-runner-apis](https://flutter.dev/go/desktop-multi-view-runner-apis) Part of flutter/flutter#143767 Part of flutter/flutter#142845 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent 1a13c7d commit b32363e

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

shell/platform/windows/client_wrapper/flutter_engine.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ bool FlutterEngine::Run(const char* entry_point) {
5050
std::cerr << "Cannot run an engine that failed creation." << std::endl;
5151
return false;
5252
}
53-
if (has_been_run_) {
53+
if (run_succeeded_) {
5454
std::cerr << "Cannot run an engine more than once." << std::endl;
5555
return false;
5656
}
5757
bool run_succeeded = FlutterDesktopEngineRun(engine_, entry_point);
5858
if (!run_succeeded) {
5959
std::cerr << "Failed to start engine." << std::endl;
6060
}
61-
has_been_run_ = true;
61+
run_succeeded_ = true;
6262
return run_succeeded;
6363
}
6464

shell/platform/windows/client_wrapper/flutter_view_controller.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace flutter {
1212
FlutterViewController::FlutterViewController(int width,
1313
int height,
1414
const DartProject& project) {
15-
engine_ = std::make_unique<FlutterEngine>(project);
15+
engine_ = std::make_shared<FlutterEngine>(project);
1616
controller_ = FlutterDesktopViewControllerCreate(width, height,
1717
engine_->RelinquishEngine());
1818
if (!controller_) {

shell/platform/windows/client_wrapper/include/flutter/flutter_engine.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class FlutterEngine : public PluginRegistry {
9595
LPARAM lparam);
9696

9797
private:
98-
// For access to RelinquishEngine.
98+
// For access to the engine handle.
9999
friend class FlutterViewController;
100100

101101
// Gives up ownership of |engine_|, but keeps a weak reference to it.
@@ -113,10 +113,11 @@ class FlutterEngine : public PluginRegistry {
113113
// Whether or not this wrapper owns |engine_|.
114114
bool owns_engine_ = true;
115115

116-
// Whether the engine has been run. This will be true if Run has been called,
117-
// or if RelinquishEngine has been called (since the view controller will
118-
// run the engine if it hasn't already been run).
119-
bool has_been_run_ = false;
116+
// Whether |Run| has been called successfully.
117+
//
118+
// This is used to improve error messages. This can be false while the engine
119+
// is running if the engine was started by creating a view.
120+
bool run_succeeded_ = false;
120121

121122
// The callback to execute once the next frame is drawn.
122123
std::function<void()> next_frame_callback_ = nullptr;

shell/platform/windows/client_wrapper/include/flutter/flutter_view_controller.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ class FlutterViewController {
2727
// Creates a FlutterView that can be parented into a Windows View hierarchy
2828
// either using HWNDs.
2929
//
30+
// This also creates a new FlutterEngine.
31+
//
3032
// |dart_project| will be used to configure the engine backing this view.
31-
explicit FlutterViewController(int width,
32-
int height,
33-
const DartProject& project);
33+
FlutterViewController(int width, int height, const DartProject& project);
3434

3535
virtual ~FlutterViewController();
3636

@@ -65,7 +65,7 @@ class FlutterViewController {
6565
FlutterDesktopViewControllerRef controller_ = nullptr;
6666

6767
// The backing engine
68-
std::unique_ptr<FlutterEngine> engine_;
68+
std::shared_ptr<FlutterEngine> engine_;
6969

7070
// The owned FlutterView.
7171
std::unique_ptr<FlutterView> view_;

0 commit comments

Comments
 (0)