Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
flutter_project_bundle.cc
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
6
7#include <filesystem>
8
13
14namespace flutter {
15
17 const FlutterDesktopEngineProperties& properties)
18 : assets_path_(properties.assets_path),
19 icu_path_(properties.icu_data_path) {
20 if (properties.aot_library_path != nullptr) {
21 aot_library_path_ = std::filesystem::path(properties.aot_library_path);
22 }
23
24 if (properties.dart_entrypoint && properties.dart_entrypoint[0] != '\0') {
25 dart_entrypoint_ = properties.dart_entrypoint;
26 }
27
28 for (int i = 0; i < properties.dart_entrypoint_argc; i++) {
29 dart_entrypoint_arguments_.push_back(
30 std::string(properties.dart_entrypoint_argv[i]));
31 }
32
33 gpu_preference_ =
34 static_cast<FlutterGpuPreference>(properties.gpu_preference);
35
36 ui_thread_policy_ =
37 static_cast<FlutterUIThreadPolicy>(properties.ui_thread_policy);
38
39 accessibility_mode_ =
40 static_cast<FlutterAccessibilityMode>(properties.accessibility_mode);
41
42 impeller_switch_ =
43 static_cast<FlutterImpellerSwitch>(properties.impeller_switch);
44
45 // Resolve any relative paths.
46 if (assets_path_.is_relative() || icu_path_.is_relative() ||
47 (!aot_library_path_.empty() && aot_library_path_.is_relative())) {
48 std::filesystem::path executable_location = GetExecutableDirectory();
49 if (executable_location.empty()) {
50 FML_LOG(ERROR)
51 << "Unable to find executable location to resolve resource paths.";
52 assets_path_ = std::filesystem::path();
53 icu_path_ = std::filesystem::path();
54 } else {
55 assets_path_ = std::filesystem::path(executable_location) / assets_path_;
56 icu_path_ = std::filesystem::path(executable_location) / icu_path_;
57 if (!aot_library_path_.empty()) {
58 aot_library_path_ =
59 std::filesystem::path(executable_location) / aot_library_path_;
60 }
61 }
62 }
63}
64
66 return !assets_path_.empty() && !icu_path_.empty();
67}
68
69// Attempts to load AOT data from the given path, which must be absolute and
70// non-empty. Logs and returns nullptr on failure.
72 const FlutterEngineProcTable& engine_procs) {
73 if (aot_library_path_.empty()) {
74 FML_LOG(ERROR)
75 << "Attempted to load AOT data, but no aot_library_path was provided.";
76 return UniqueAotDataPtr(nullptr, nullptr);
77 }
78 if (!std::filesystem::exists(aot_library_path_)) {
79 FML_LOG(ERROR) << "Can't load AOT data from " << aot_library_path_
80 << "; no such file.";
81 return UniqueAotDataPtr(nullptr, nullptr);
82 }
83 std::string path_string = fml::PathToUtf8(aot_library_path_);
86 source.elf_path = path_string.c_str();
87 FlutterEngineAOTData data = nullptr;
88 auto result = engine_procs.CreateAOTData(&source, &data);
89 if (result != kSuccess) {
90 FML_LOG(ERROR) << "Failed to load AOT data from: " << path_string;
91 return UniqueAotDataPtr(nullptr, nullptr);
92 }
93 return UniqueAotDataPtr(data, engine_procs.CollectAOTData);
94}
95
97
99 const std::vector<std::string>& switches) {
100 engine_switches_ = switches;
101}
102
103const std::vector<std::string> FlutterProjectBundle::GetSwitches() {
104 if (engine_switches_.size() == 0) {
106 }
107 std::vector<std::string> switches;
108 switches.insert(switches.end(), engine_switches_.begin(),
109 engine_switches_.end());
110
111 auto env_switches = GetSwitchesFromEnvironment();
112 switches.insert(switches.end(), env_switches.begin(), env_switches.end());
113
114 return switches;
115}
116
117} // namespace flutter
const std::vector< std::string > GetSwitches()
FlutterProjectBundle(const FlutterDesktopEngineProperties &properties)
UniqueAotDataPtr LoadAotData(const FlutterEngineProcTable &engine_procs)
void SetSwitches(const std::vector< std::string > &switches)
@ kFlutterEngineAOTDataSourceTypeElfPath
Definition embedder.h:2483
#define FML_LOG(severity)
Definition logging.h:101
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switch_defs.h:36
std::vector< std::string > GetSwitchesFromEnvironment()
std::filesystem::path GetExecutableDirectory()
Definition path_utils.cc:16
std::unique_ptr< _FlutterEngineAOTData, FlutterEngineCollectAOTDataFnPtr > UniqueAotDataPtr
std::string PathToUtf8(const std::filesystem::path &path)
FlutterDesktopAccessibilityMode accessibility_mode
FlutterDesktopImpellerSwitch impeller_switch
FlutterDesktopUIThreadPolicy ui_thread_policy
FlutterDesktopGpuPreference gpu_preference
FlutterEngineAOTDataSourceType type
Definition embedder.h:2489
const char * elf_path
Absolute path to an ELF library file.
Definition embedder.h:2492
Function-pointer-based versions of the APIs above.
Definition embedder.h:3763
FlutterEngineCreateAOTDataFnPtr CreateAOTData
Definition embedder.h:3767
FlutterEngineCollectAOTDataFnPtr CollectAOTData
Definition embedder.h:3768