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