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