| Flutter Windows Embedder |

flutter_project_bundle.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_FLUTTER_PROJECT_BUNDLE_H_
6 #define FLUTTER_SHELL_PLATFORM_WINDOWS_FLUTTER_PROJECT_BUNDLE_H_
7
8 #include <filesystem>
9 #include <string>
10 #include <vector>
11
12 #include "flutter/shell/platform/embedder/embedder.h"
13 #include "flutter/shell/platform/windows/public/flutter_windows.h"
14
15 namespace flutter {
16
17 using UniqueAotDataPtr =
18 std::unique_ptr<_FlutterEngineAOTData, FlutterEngineCollectAOTDataFnPtr>;
19
20 enum class FlutterGpuPreference {
21 NoPreference,
22 LowPowerPreference,
23 HighPerformancePreference,
24 };
25
26 enum class FlutterUIThreadPolicy {
27 Default,
28 RunOnPlatformThread,
29 RunOnSeparateThread,
30 };
31
32 // The data associated with a Flutter project needed to run it in an engine.
33 class FlutterProjectBundle {
34 public:
35 // Creates a new project bundle from the given properties.
36 //
37 // Treats any relative paths as relative to the directory of this executable.
38 explicit FlutterProjectBundle(
39 const FlutterDesktopEngineProperties& properties);
40
41 ~FlutterProjectBundle();
42
43 // Whether or not the bundle is valid. This does not check that the paths
44 // exist, or contain valid data, just that paths were able to be constructed.
45 bool HasValidPaths();
46
47 // Returns the path to the assets directory.
48 const std::filesystem::path& assets_path() { return assets_path_; }
49
50 // Returns the path to the ICU data file.
51 const std::filesystem::path& icu_path() { return icu_path_; }
52
53 // Returns any switches that should be passed to the engine.
54 const std::vector<std::string> GetSwitches();
55
56 // Sets engine switches.
57 void SetSwitches(const std::vector<std::string>& switches);
58
59 // Attempts to load AOT data for this bundle. The returned data must be
60 // retained until any engine instance it is passed to has been shut down.
61 //
62 // Logs and returns nullptr on failure.
63 UniqueAotDataPtr LoadAotData(const FlutterEngineProcTable& engine_procs);
64
65 // Returns the Dart entrypoint.
66 const std::string& dart_entrypoint() const { return dart_entrypoint_; }
67
68 // Returns the command line arguments to be passed through to the Dart
69 // entrypoint.
70 const std::vector<std::string>& dart_entrypoint_arguments() const {
71 return dart_entrypoint_arguments_;
72 }
73
74 // Returns the app's GPU preference.
75 FlutterGpuPreference gpu_preference() const { return gpu_preference_; }
76
77 // Returns thread policy for running the UI isolate.
78 FlutterUIThreadPolicy ui_thread_policy() { return ui_thread_policy_; }
79
80 private:
81 std::filesystem::path assets_path_;
82 std::filesystem::path icu_path_;
83
84 // Path to the AOT library file, if any.
85 std::filesystem::path aot_library_path_;
86
87 // The Dart entrypoint to launch.
88 std::string dart_entrypoint_;
89
90 // Dart entrypoint arguments.
91 std::vector<std::string> dart_entrypoint_arguments_;
92
93 // Engine switches.
94 std::vector<std::string> engine_switches_;
95
96 // App's GPU preference.
97 FlutterGpuPreference gpu_preference_;
98
99 // Thread policy for running the UI isolate.
100 FlutterUIThreadPolicy ui_thread_policy_;
101 };
102
103 } // namespace flutter
104
105 #endif // FLUTTER_SHELL_PLATFORM_WINDOWS_FLUTTER_PROJECT_BUNDLE_H_
flutter::FlutterProjectBundle
Definition: flutter_project_bundle.h:33
flutter::FlutterProjectBundle::gpu_preference
FlutterGpuPreference gpu_preference() const
Definition: flutter_project_bundle.h:75
flutter::FlutterProjectBundle::assets_path
const std::filesystem::path & assets_path()
Definition: flutter_project_bundle.h:48
flutter::FlutterProjectBundle::HasValidPaths
bool HasValidPaths()
Definition: flutter_project_bundle.cc:59
flutter::FlutterProjectBundle::GetSwitches
const std::vector< std::string > GetSwitches()
Definition: flutter_project_bundle.cc:97
flutter::FlutterProjectBundle::icu_path
const std::filesystem::path & icu_path()
Definition: flutter_project_bundle.h:51
flutter::FlutterProjectBundle::~FlutterProjectBundle
~FlutterProjectBundle()
Definition: flutter_project_bundle.cc:90
flutter::FlutterProjectBundle::FlutterProjectBundle
FlutterProjectBundle(const FlutterDesktopEngineProperties &properties)
Definition: flutter_project_bundle.cc:16
flutter::FlutterProjectBundle::LoadAotData
UniqueAotDataPtr LoadAotData(const FlutterEngineProcTable &engine_procs)
Definition: flutter_project_bundle.cc:65
flutter::FlutterProjectBundle::dart_entrypoint_arguments
const std::vector< std::string > & dart_entrypoint_arguments() const
Definition: flutter_project_bundle.h:70
flutter::FlutterProjectBundle::ui_thread_policy
FlutterUIThreadPolicy ui_thread_policy()
Definition: flutter_project_bundle.h:78
flutter::FlutterProjectBundle::SetSwitches
void SetSwitches(const std::vector< std::string > &switches)
Definition: flutter_project_bundle.cc:92
flutter::FlutterProjectBundle::dart_entrypoint
const std::string & dart_entrypoint() const
Definition: flutter_project_bundle.h:66
flutter_windows.h
flutter
Definition: accessibility_bridge_windows.cc:11
flutter::FlutterUIThreadPolicy
FlutterUIThreadPolicy
Definition: flutter_project_bundle.h:26
flutter::FlutterUIThreadPolicy::RunOnPlatformThread
@ RunOnPlatformThread
flutter::FlutterUIThreadPolicy::Default
@ Default
flutter::FlutterUIThreadPolicy::RunOnSeparateThread
@ RunOnSeparateThread
flutter::FlutterGpuPreference
FlutterGpuPreference
Definition: flutter_project_bundle.h:20
flutter::FlutterGpuPreference::HighPerformancePreference
@ HighPerformancePreference
flutter::FlutterGpuPreference::NoPreference
@ NoPreference
flutter::FlutterGpuPreference::LowPowerPreference
@ LowPowerPreference
flutter::UniqueAotDataPtr
std::unique_ptr< _FlutterEngineAOTData, FlutterEngineCollectAOTDataFnPtr > UniqueAotDataPtr
Definition: flutter_project_bundle.h:18
FlutterDesktopEngineProperties
Definition: flutter_windows.h:64