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

[Windows] Refactor client wrapper to prepare for multi-view #52073

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions shell/platform/windows/client_wrapper/flutter_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ bool FlutterEngine::Run(const char* entry_point) {
std::cerr << "Cannot run an engine that failed creation." << std::endl;
return false;
}
if (has_been_run_) {
if (run_succeeded_) {
std::cerr << "Cannot run an engine more than once." << std::endl;
return false;
}
bool run_succeeded = FlutterDesktopEngineRun(engine_, entry_point);
if (!run_succeeded) {
std::cerr << "Failed to start engine." << std::endl;
}
has_been_run_ = true;
run_succeeded_ = true;
return run_succeeded;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace flutter {
FlutterViewController::FlutterViewController(int width,
int height,
const DartProject& project) {
engine_ = std::make_unique<FlutterEngine>(project);
engine_ = std::make_shared<FlutterEngine>(project);
controller_ = FlutterDesktopViewControllerCreate(width, height,
engine_->RelinquishEngine());
if (!controller_) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class FlutterEngine : public PluginRegistry {
LPARAM lparam);

private:
// For access to RelinquishEngine.
// For access to the engine handle.
friend class FlutterViewController;

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

// Whether the engine has been run. This will be true if Run has been called,
// or if RelinquishEngine has been called (since the view controller will
// run the engine if it hasn't already been run).
bool has_been_run_ = false;
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've updated the comment and renamed this to run_succeeded_ to reflect its current purpose better.

This comment was incorrect when it was added. See: cd4192d#diff-4d73a4226c049b829de25c009bf79a1d30674d639e9c5c23f7e508690f68d6aaR73

// Whether |Run| has been called successfully.
//
// This is used to improve error messages. This can be false while the engine
// is running if the engine was started by creating a view.
bool run_succeeded_ = false;

// The callback to execute once the next frame is drawn.
std::function<void()> next_frame_callback_ = nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ class FlutterViewController {
// Creates a FlutterView that can be parented into a Windows View hierarchy
// either using HWNDs.
//
// This also creates a new FlutterEngine.
//
// |dart_project| will be used to configure the engine backing this view.
explicit FlutterViewController(int width,
int height,
const DartProject& project);
FlutterViewController(int width, int height, const DartProject& project);

virtual ~FlutterViewController();

Expand Down Expand Up @@ -65,7 +65,7 @@ class FlutterViewController {
FlutterDesktopViewControllerRef controller_ = nullptr;

// The backing engine
std::unique_ptr<FlutterEngine> engine_;
std::shared_ptr<FlutterEngine> engine_;

// The owned FlutterView.
std::unique_ptr<FlutterView> view_;
Expand Down