Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
settings.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_COMMON_SETTINGS_H_
6#define FLUTTER_COMMON_SETTINGS_H_
7
8#include <fcntl.h>
9
10#include <chrono>
11#include <cstdint>
12#include <memory>
13#include <optional>
14#include <string>
15#include <vector>
16
17#include "flutter/fml/build_config.h"
18#include "flutter/fml/closure.h"
19#include "flutter/fml/mapping.h"
20#include "flutter/fml/time/time_point.h"
21#include "flutter/fml/unique_fd.h"
22
23namespace flutter {
24
25// The combination of targeted graphics API and Impeller support.
32
34 public:
44
48
49 static constexpr int kStatisticsCount = kCount + 5;
50
51 fml::TimePoint Get(Phase phase) const { return data_[phase]; }
53 return data_[phase] = value;
54 }
55
56 uint64_t GetFrameNumber() const { return frame_number_; }
57 void SetFrameNumber(uint64_t frame_number) { frame_number_ = frame_number; }
58 uint64_t GetLayerCacheCount() const { return layer_cache_count_; }
59 uint64_t GetLayerCacheBytes() const { return layer_cache_bytes_; }
60 uint64_t GetPictureCacheCount() const { return picture_cache_count_; }
61 uint64_t GetPictureCacheBytes() const { return picture_cache_bytes_; }
62 void SetRasterCacheStatistics(size_t layer_cache_count,
63 size_t layer_cache_bytes,
64 size_t picture_cache_count,
65 size_t picture_cache_bytes) {
66 layer_cache_count_ = layer_cache_count;
67 layer_cache_bytes_ = layer_cache_bytes;
68 picture_cache_count_ = picture_cache_count;
69 picture_cache_bytes_ = picture_cache_bytes;
70 }
71
72 private:
74 uint64_t frame_number_;
75 size_t layer_cache_count_;
76 size_t layer_cache_bytes_;
77 size_t picture_cache_count_;
78 size_t picture_cache_bytes_;
79};
80
82 std::function<void(intptr_t /* key */, fml::closure /* callback */)>;
83using TaskObserverRemove = std::function<void(intptr_t /* key */)>;
85 std::function<bool(const std::string& /* error */,
86 const std::string& /* stack trace */)>;
88 std::function<void(const std::string& /* tag */,
89 const std::string& /* message */)>;
90
91// TODO(26783): Deprecate all the "path" struct members in favor of the
92// callback that generates the mapping from these paths.
93using MappingCallback = std::function<std::unique_ptr<fml::Mapping>(void)>;
94using Mappings = std::vector<std::unique_ptr<const fml::Mapping>>;
95using MappingsCallback = std::function<Mappings(void)>;
96
97using FrameRasterizedCallback = std::function<void(const FrameTiming&)>;
98
99class DartIsolate;
100
101// TODO(https://github.com/flutter/flutter/issues/138750): Re-order fields to
102// reduce padding.
103// NOLINTNEXTLINE(clang-analyzer-optin.performance.Padding)
104struct Settings {
106
107 Settings(const Settings& other);
108
110
111 /// Determines if attempts at grabbing the Surface's SurfaceData can be
112 /// attempted.
113 static constexpr bool kSurfaceDataAccessible =
114#ifdef _NDEBUG
115 false;
116#else
117 true;
118#endif
119
120 // VM settings
121 std::string vm_snapshot_data_path; // deprecated
123 std::string vm_snapshot_instr_path; // deprecated
125
126 std::string isolate_snapshot_data_path; // deprecated
128 std::string isolate_snapshot_instr_path; // deprecated
130
131 std::string route;
132
133 // Returns the Mapping to a kernel buffer which contains sources for dart:*
134 // libraries.
136
137 // Path to a library containing the application's compiled Dart code.
138 // This is a vector so that the embedder can provide fallback paths in
139 // case the primary path to the library can not be loaded.
140 std::vector<std::string> application_library_path;
141
142 // Path to a library containing compiled Dart code usable for launching
143 // the VM service isolate.
144 std::vector<std::string> vmservice_snapshot_library_path;
145
146 std::string application_kernel_asset; // deprecated
147 std::string application_kernel_list_asset; // deprecated
149
151 std::vector<std::string> dart_flags;
152 // Isolate settings
154 bool start_paused = false;
155 bool trace_skia = false;
156 std::vector<std::string> trace_allowlist;
157 std::optional<std::vector<std::string>> trace_skia_allowlist;
158 bool trace_startup = false;
159 bool trace_systrace = false;
160 std::string trace_to_file;
163 bool cache_sksl = false;
168 bool enable_serial_gc = false;
169
170 // Whether embedder only allows secure connections.
172 // JSON-formatted domain network policy.
174
175 // Used as the script URI in debug messages. Does not affect how the Dart code
176 // is executed.
177 std::string advisory_script_uri = "main.dart";
178 // Used as the script entrypoint in debug messages. Does not affect how the
179 // Dart code is executed.
180 std::string advisory_script_entrypoint = "main";
181
182 // The executable path associated with this process. This is returned by
183 // Platform.executable from dart:io. If unknown, defaults to "Flutter".
184 std::string executable_name = "Flutter";
185
186 // VM Service settings
187
188 // Whether the Dart VM service should be enabled.
189 bool enable_vm_service = false;
190
191 // Whether to publish the VM Service URL over mDNS.
192 // On iOS 14 this prompts a local network permission dialog,
193 // which cannot be accepted or dismissed in a CI environment.
195
196 // The IP address to which the Dart VM service is bound.
197 std::string vm_service_host;
198
199 // The port to which the Dart VM service is bound. When set to `0`, a free
200 // port will be automatically selected by the OS. A message is logged on the
201 // target indicating the URL at which the VM service can be accessed.
202 uint32_t vm_service_port = 0;
203
204 // Determines whether an authentication code is required to communicate with
205 // the VM service.
207
208 // Determine whether the vmservice should fallback to automatic port selection
209 // after failing to bind to a specified port.
211
212 // Font settings
213 bool use_test_fonts = false;
214
215 bool use_asset_fonts = true;
216
217 // Indicates whether the embedding started a prefetch of the default font
218 // manager before creating the engine.
220
221 // Enable the rendering of colors outside of the sRGB gamut.
222 bool enable_wide_gamut = false;
223
224 // Enable the Impeller renderer on supported platforms. Ignored if Impeller is
225 // not supported on the platform.
226#if FML_OS_IOS || FML_OS_IOS_SIMULATOR
227 bool enable_impeller = true;
228#else
229 bool enable_impeller = false;
230#endif
231
232 // Log a warning during shell initialization if Impeller is not enabled.
234
235 // The selected Android rendering API.
238
239 // Requests a specific rendering backend.
240 std::optional<std::string> requested_rendering_backend;
241
242 // Enable Vulkan validation on backends that support it. The validation layers
243 // must be available to the application.
245
246 // Enable GPU tracing in GLES backends.
247 // Some devices claim to support the required APIs but crash on their usage.
249
250 // Enable GPU tracing in Vulkan backends.
252
253 // Data set by platform-specific embedders for use in font initialization.
255
256 // All shells in the process share the same VM. The last shell to shutdown
257 // should typically shut down the VM as well. However, applications depend on
258 // the behavior of "warming-up" the VM by creating a shell that does not do
259 // anything. This used to work earlier when the VM could not be shut down (and
260 // hence never was). Shutting down the VM now breaks such assumptions in
261 // existing embedders. To keep this behavior consistent and allow existing
262 // embedders the chance to migrate, this flag defaults to true. Any shell
263 // launched with this flag set to true will leak the VM in the process. There
264 // is no way to shut down the VM once such a shell has been started. All
265 // shells in the platform (via their embedding APIs) should cooperate to make
266 // sure this flag is never set if they want the VM to shutdown and free all
267 // associated resources.
268 // It can be customized by application, more detail:
269 // https://github.com/flutter/flutter/issues/95903
270 // TODO(eggfly): Should it be set to false by default?
271 // https://github.com/flutter/flutter/issues/96843
272 bool leak_vm = true;
273
274 // Engine settings
277 // The main isolate is current when this callback is made. This is a good spot
278 // to perform native Dart bindings for libraries not built in.
279 std::function<void(const DartIsolate&)> root_isolate_create_callback;
280 // TODO(68738): Update isolate callbacks in settings to accept an additional
281 // DartIsolate parameter.
283 // The isolate is not current and may have already been destroyed when this
284 // call is made.
287 // A callback made in the isolate scope of the service isolate when it is
288 // launched. Care must be taken to ensure that callers are assigning callbacks
289 // to the settings object used to launch the VM. If an existing VM is used to
290 // launch an isolate using these settings, the callback will be ignored as the
291 // service isolate has already been launched. Also, this callback will only be
292 // made in the modes in which the service isolate is eligible for launch
293 // (debug and profile).
295 // The callback made on the UI thread in an isolate scope when the engine
296 // detects that the framework is idle. The VM also uses this time to perform
297 // tasks suitable when idling. Due to this, embedders are still advised to be
298 // as fast as possible in returning from this callback. Long running
299 // operations in this callback do have the capability of introducing jank.
300 std::function<void(int64_t)> idle_notification_callback;
301 // A callback given to the embedder to react to unhandled exceptions in the
302 // running Flutter application. This callback is made on an internal engine
303 // managed thread and embedders must re-thread as necessary. Performing
304 // blocking calls in this callback will cause applications to jank.
306 // A callback given to the embedder to log print messages from the running
307 // Flutter application. This callback is made on an internal engine managed
308 // thread and embedders must re-thread if necessary. Performing blocking
309 // calls in this callback will cause applications to jank.
313 bool verbose_logging = false;
314 std::string log_tag = "flutter";
315
316 // The icu_initialization_required setting does not have a corresponding
317 // switch because it is intended to be decided during build time, not runtime.
318 // Some companies apply source modification here because their build system
319 // brings its own ICU data files.
321 std::string icu_data_path;
323
324 // Assets settings
326 fml::UniqueFD::traits_type::InvalidValue();
327 std::string assets_path;
328
329 // Callback to handle the timings of a rasterized frame. This is called as
330 // soon as a frame is rasterized.
332
333 // This data will be available to the isolate immediately on launch via the
334 // PlatformDispatcher.getPersistentIsolateData callback. This is meant for
335 // information that the isolate cannot request asynchronously (platform
336 // messages can be used for that purpose). This data is held for the lifetime
337 // of the shell and is available on isolate restarts in the shell instance.
338 // Due to this, the buffer must be as small as possible.
339 std::shared_ptr<const fml::Mapping> persistent_isolate_data;
340
341 /// Max size of old gen heap size in MB, or 0 for unlimited, -1 for default
342 /// value.
343 ///
344 /// See also:
345 /// https://github.com/dart-lang/sdk/blob/ca64509108b3e7219c50d6c52877c85ab6a35ff2/runtime/vm/flag_list.h#L150
346 int64_t old_gen_heap_size = -1;
347
348 // Max bytes threshold of resource cache, or 0 for unlimited.
350
351 /// The minimum number of samples to require in multipsampled anti-aliasing.
352 ///
353 /// Setting this value to 0 or 1 disables MSAA.
354 /// If it is not 0 or 1, it must be one of 2, 4, 8, or 16. However, if the
355 /// GPU does not support the requested sampling value, MSAA will be disabled.
356 uint8_t msaa_samples = 0;
357
358 /// Enable embedder api on the embedder.
359 ///
360 /// This is currently only used by iOS.
362
363 /// Enable support for isolates that run on the platform thread.
364 ///
365 /// This is used by the runOnPlatformThread API.
367};
368
369} // namespace flutter
370
371#endif // FLUTTER_COMMON_SETTINGS_H_
Represents an instance of a live isolate. An isolate is a separate Dart execution context....
static constexpr Phase kPhases[kCount]
Definition settings.h:45
void SetFrameNumber(uint64_t frame_number)
Definition settings.h:57
uint64_t GetPictureCacheCount() const
Definition settings.h:60
uint64_t GetLayerCacheBytes() const
Definition settings.h:59
uint64_t GetFrameNumber() const
Definition settings.h:56
uint64_t GetPictureCacheBytes() const
Definition settings.h:61
uint64_t GetLayerCacheCount() const
Definition settings.h:58
fml::TimePoint Set(Phase phase, fml::TimePoint value)
Definition settings.h:52
static constexpr int kStatisticsCount
Definition settings.h:49
void SetRasterCacheStatistics(size_t layer_cache_count, size_t layer_cache_bytes, size_t picture_cache_count, size_t picture_cache_bytes)
Definition settings.h:62
fml::TimePoint Get(Phase phase) const
Definition settings.h:51
uint8_t value
AndroidRenderingAPI
Definition settings.h:26
std::function< void(intptr_t)> TaskObserverRemove
Definition settings.h:83
std::function< void(intptr_t, fml::closure)> TaskObserverAdd
Definition settings.h:82
std::function< Mappings(void)> MappingsCallback
Definition settings.h:95
std::vector< std::unique_ptr< const fml::Mapping > > Mappings
Definition settings.h:94
std::function< void(const FrameTiming &)> FrameRasterizedCallback
Definition settings.h:97
std::function< std::unique_ptr< fml::Mapping >(void)> MappingCallback
Definition settings.h:93
std::function< bool(const std::string &, const std::string &)> UnhandledExceptionCallback
Definition settings.h:86
std::function< void(const std::string &, const std::string &)> LogMessageCallback
Definition settings.h:89
std::function< void()> closure
Definition closure.h:14
std::string advisory_script_entrypoint
Definition settings.h:180
bool prefetched_default_font_manager
Definition settings.h:219
std::string application_kernel_asset
Definition settings.h:146
bool enable_embedder_api
Definition settings.h:361
fml::UniqueFD::element_type assets_dir
Definition settings.h:325
std::vector< std::string > vmservice_snapshot_library_path
Definition settings.h:144
bool enable_software_rendering
Definition settings.h:311
bool icu_initialization_required
Definition settings.h:320
std::string advisory_script_uri
Definition settings.h:177
bool endless_trace_buffer
Definition settings.h:165
AndroidRenderingAPI android_rendering_api
Definition settings.h:236
std::vector< std::string > application_library_path
Definition settings.h:140
LogMessageCallback log_message_callback
Definition settings.h:310
std::string vm_snapshot_instr_path
Definition settings.h:123
MappingCallback isolate_snapshot_instr
Definition settings.h:129
bool disable_service_auth_codes
Definition settings.h:206
std::string temp_directory_path
Definition settings.h:150
std::function< void(const DartIsolate &)> root_isolate_create_callback
Definition settings.h:279
bool enable_opengl_gpu_tracing
Definition settings.h:248
std::string assets_path
Definition settings.h:327
bool enable_dart_profiling
Definition settings.h:166
TaskObserverRemove task_observer_remove
Definition settings.h:276
MappingCallback isolate_snapshot_data
Definition settings.h:127
MappingsCallback application_kernels
Definition settings.h:148
bool skia_deterministic_rendering_on_cpu
Definition settings.h:312
MappingCallback vm_snapshot_data
Definition settings.h:122
bool purge_persistent_cache
Definition settings.h:164
bool enable_vulkan_gpu_tracing
Definition settings.h:251
std::vector< std::string > trace_allowlist
Definition settings.h:156
std::string vm_service_host
Definition settings.h:197
bool enable_vulkan_validation
Definition settings.h:244
MappingCallback icu_mapper
Definition settings.h:322
bool dump_skp_on_shader_compilation
Definition settings.h:162
TaskObserverAdd task_observer_add
Definition settings.h:275
uint32_t font_initialization_data
Definition settings.h:254
std::string application_kernel_list_asset
Definition settings.h:147
std::string log_tag
Definition settings.h:314
fml::closure service_isolate_create_callback
Definition settings.h:294
std::shared_ptr< const fml::Mapping > persistent_isolate_data
Definition settings.h:339
std::string isolate_snapshot_data_path
Definition settings.h:126
uint8_t msaa_samples
Definition settings.h:356
uint32_t vm_service_port
Definition settings.h:202
std::vector< std::string > dart_flags
Definition settings.h:151
bool enable_timeline_event_handler
Definition settings.h:161
bool may_insecurely_connect_to_all_domains
Definition settings.h:171
std::string route
Definition settings.h:131
fml::closure isolate_shutdown_callback
Definition settings.h:286
bool enable_checked_mode
Definition settings.h:153
Settings(const Settings &other)
std::string executable_name
Definition settings.h:184
bool enable_service_port_fallback
Definition settings.h:210
static constexpr bool kSurfaceDataAccessible
Definition settings.h:113
bool enable_vm_service_publication
Definition settings.h:194
fml::closure isolate_create_callback
Definition settings.h:282
std::optional< std::vector< std::string > > trace_skia_allowlist
Definition settings.h:157
std::optional< std::string > requested_rendering_backend
Definition settings.h:240
std::string icu_data_path
Definition settings.h:321
FrameRasterizedCallback frame_rasterized_callback
Definition settings.h:331
bool enable_platform_isolates
Definition settings.h:366
std::string trace_to_file
Definition settings.h:160
bool disable_dart_asserts
Definition settings.h:167
UnhandledExceptionCallback unhandled_exception_callback
Definition settings.h:305
bool warn_on_impeller_opt_out
Definition settings.h:233
MappingCallback vm_snapshot_instr
Definition settings.h:124
std::string vm_snapshot_data_path
Definition settings.h:121
std::function< void(int64_t)> idle_notification_callback
Definition settings.h:300
fml::closure root_isolate_shutdown_callback
Definition settings.h:285
MappingCallback dart_library_sources_kernel
Definition settings.h:135
int64_t old_gen_heap_size
Definition settings.h:346
std::string isolate_snapshot_instr_path
Definition settings.h:128
size_t resource_cache_max_bytes_threshold
Definition settings.h:349
std::string domain_network_policy
Definition settings.h:173