| Flutter Windows Embedder |

dart_project.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_CLIENT_WRAPPER_INCLUDE_FLUTTER_DART_PROJECT_H_
6 #define FLUTTER_SHELL_PLATFORM_WINDOWS_CLIENT_WRAPPER_INCLUDE_FLUTTER_DART_PROJECT_H_
7
8 #include <string>
9 #include <vector>
10
11 namespace flutter {
12
13 // Configures how the Flutter engine selects a GPU.
14 enum class GpuPreference {
15 // No preference.
16 NoPreference,
17 // Prefer energy efficiency over performance, such as an integrated GPU.
18 // This falls back to a high performance GPU if no low power GPU is
19 // available.
20 LowPowerPreference,
21 };
22
23 // Configures the thread policy for running the UI isolate.
24 enum class UIThreadPolicy {
25 // Default value. Currently will run the UI isolate on separate thread,
26 // later will be changed to running the UI isolate on platform thread.
27 Default,
28 // Run the UI isolate on platform thread.
29 RunOnPlatformThread,
30 // Run the UI isolate on a separate thread.
31 RunOnSeparateThread,
32 };
33
34 // A set of Flutter and Dart assets used to initialize a Flutter engine.
35 class DartProject {
36 public:
37 // Creates a DartProject from a series of absolute paths.
38 // The three paths are:
39 // - assets_path: Path to the assets directory as built by the Flutter tool.
40 // - icu_data_path: Path to the icudtl.dat file.
41 // - aot_library_path: Path to the AOT snapshot file.
42 //
43 // The paths may either be absolute or relative to the directory containing
44 // the running executable.
45 explicit DartProject(const std::wstring& assets_path,
46 const std::wstring& icu_data_path,
47 const std::wstring& aot_library_path) {
48 assets_path_ = assets_path;
49 icu_data_path_ = icu_data_path;
50 aot_library_path_ = aot_library_path;
51 }
52
53 // Creates a DartProject from a directory path. The directory should contain
54 // the following top-level items:
55 // - icudtl.dat (provided as a resource by the Flutter tool)
56 // - flutter_assets (as built by the Flutter tool)
57 // - app.so, for an AOT build (as built by the Flutter tool)
58 //
59 // The path can either be absolute, or relative to the directory containing
60 // the running executable.
61 explicit DartProject(const std::wstring& path) {
62 assets_path_ = path + L"\\flutter_assets";
63 icu_data_path_ = path + L"\\icudtl.dat";
64 aot_library_path_ = path + L"\\app.so";
65 }
66
67 ~DartProject() = default;
68
69 // Sets the Dart entrypoint to the specified value.
70 //
71 // If not set, the default entrypoint (main) is used. Custom Dart entrypoints
72 // must be decorated with `@pragma('vm:entry-point')`.
73 void set_dart_entrypoint(const std::string& entrypoint) {
74 if (entrypoint.empty()) {
75 return;
76 }
77 dart_entrypoint_ = entrypoint;
78 }
79
80 // Returns the Dart entrypoint.
81 const std::string& dart_entrypoint() const { return dart_entrypoint_; }
82
83 // Sets the command line arguments that should be passed to the Dart
84 // entrypoint.
85 void set_dart_entrypoint_arguments(std::vector<std::string> arguments) {
86 dart_entrypoint_arguments_ = std::move(arguments);
87 }
88
89 // Returns any command line arguments that should be passed to the Dart
90 // entrypoint.
91 const std::vector<std::string>& dart_entrypoint_arguments() const {
92 return dart_entrypoint_arguments_;
93 }
94
95 // Sets the GPU usage preference for flutter engine.
96 void set_gpu_preference(GpuPreference gpu_preference) {
97 gpu_preference_ = gpu_preference;
98 }
99
100 // Returns the project's GPU preference.
101 // Defaults to NoPreference.
102 GpuPreference gpu_preference() const { return gpu_preference_; }
103
104 // Sets the thread policy for UI isolate.
105 void set_ui_thread_policy(UIThreadPolicy policy) {
106 ui_thread_policy_ = policy;
107 }
108
109 // Returns the policy for UI isolate.
110 // Defaults to UIThreadPolicy::Default.
111 UIThreadPolicy ui_thread_policy() const { return ui_thread_policy_; }
112
113 private:
114 // Accessors for internals are private, so that they can be changed if more
115 // flexible options for project structures are needed later without it
116 // being a breaking change. Provide access to internal classes that need
117 // them.
118 friend class FlutterEngine;
119 friend class FlutterViewController;
120 friend class DartProjectTest;
121
122 const std::wstring& assets_path() const { return assets_path_; }
123 const std::wstring& icu_data_path() const { return icu_data_path_; }
124 const std::wstring& aot_library_path() const { return aot_library_path_; }
125
126 // The path to the assets directory.
127 std::wstring assets_path_;
128 // The path to the ICU data.
129 std::wstring icu_data_path_;
130 // The path to the AOT library. This will always return a path, but non-AOT
131 // builds will not be expected to actually have a library at that path.
132 std::wstring aot_library_path_;
133 // The Dart entrypoint to launch.
134 std::string dart_entrypoint_;
135 // The list of arguments to pass through to the Dart entrypoint.
136 std::vector<std::string> dart_entrypoint_arguments_;
137 // The preference for GPU to be used by flutter engine.
138 GpuPreference gpu_preference_ = GpuPreference::NoPreference;
139 // Thread policy for UI isolate.
140 UIThreadPolicy ui_thread_policy_ = UIThreadPolicy::Default;
141 };
142
143 } // namespace flutter
144
145 #endif // FLUTTER_SHELL_PLATFORM_WINDOWS_CLIENT_WRAPPER_INCLUDE_FLUTTER_DART_PROJECT_H_
flutter::DartProject
Definition: dart_project.h:35
flutter::DartProject::set_dart_entrypoint
void set_dart_entrypoint(const std::string &entrypoint)
Definition: dart_project.h:73
flutter::DartProject::set_ui_thread_policy
void set_ui_thread_policy(UIThreadPolicy policy)
Definition: dart_project.h:105
flutter::DartProject::set_gpu_preference
void set_gpu_preference(GpuPreference gpu_preference)
Definition: dart_project.h:96
flutter::DartProject::DartProject
DartProject(const std::wstring &assets_path, const std::wstring &icu_data_path, const std::wstring &aot_library_path)
Definition: dart_project.h:45
flutter::DartProject::DartProject
DartProject(const std::wstring &path)
Definition: dart_project.h:61
flutter::DartProject::set_dart_entrypoint_arguments
void set_dart_entrypoint_arguments(std::vector< std::string > arguments)
Definition: dart_project.h:85
flutter::DartProject::ui_thread_policy
UIThreadPolicy ui_thread_policy() const
Definition: dart_project.h:111
flutter::DartProject::dart_entrypoint
const std::string & dart_entrypoint() const
Definition: dart_project.h:81
flutter::DartProject::~DartProject
~DartProject()=default
flutter::DartProject::dart_entrypoint_arguments
const std::vector< std::string > & dart_entrypoint_arguments() const
Definition: dart_project.h:91
flutter::DartProject::gpu_preference
GpuPreference gpu_preference() const
Definition: dart_project.h:102
flutter::DartProjectTest
Definition: dart_project_unittests.cc:13
flutter::FlutterEngine
Definition: flutter_engine.h:28
flutter::FlutterViewController
Definition: flutter_view_controller.h:25
flutter
Definition: accessibility_bridge_windows.cc:11
flutter::GpuPreference
GpuPreference
Definition: dart_project.h:14
flutter::GpuPreference::NoPreference
@ NoPreference
flutter::GpuPreference::LowPowerPreference
@ LowPowerPreference
flutter::UIThreadPolicy
UIThreadPolicy
Definition: dart_project.h:24
flutter::UIThreadPolicy::RunOnPlatformThread
@ RunOnPlatformThread
flutter::UIThreadPolicy::Default
@ Default
flutter::UIThreadPolicy::RunOnSeparateThread
@ RunOnSeparateThread