settings.h 9.0 KB
Newer Older
M
Michael Goderbauer 已提交
1
// Copyright 2013 The Flutter Authors. All rights reserved.
A
Adam Barth 已提交
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
#ifndef FLUTTER_COMMON_SETTINGS_H_
#define FLUTTER_COMMON_SETTINGS_H_
A
Adam Barth 已提交
7

8
#include <fcntl.h>
9 10
#include <stdint.h>

11
#include <chrono>
12
#include <memory>
13
#include <string>
14
#include <vector>
15

16
#include "flutter/fml/closure.h"
17
#include "flutter/fml/mapping.h"
18
#include "flutter/fml/time/time_point.h"
19 20
#include "flutter/fml/unique_fd.h"

21
namespace flutter {
A
Adam Barth 已提交
22

23 24
class FrameTiming {
 public:
25 26 27 28 29 30 31 32 33 34 35
  enum Phase {
    kVsyncStart,
    kBuildStart,
    kBuildFinish,
    kRasterStart,
    kRasterFinish,
    kCount
  };

  static constexpr Phase kPhases[kCount] = {
      kVsyncStart, kBuildStart, kBuildFinish, kRasterStart, kRasterFinish};
36 37 38 39 40 41 42 43 44 45

  fml::TimePoint Get(Phase phase) const { return data_[phase]; }
  fml::TimePoint Set(Phase phase, fml::TimePoint value) {
    return data_[phase] = value;
  }

 private:
  fml::TimePoint data_[kCount];
};

46
using TaskObserverAdd =
47
    std::function<void(intptr_t /* key */, fml::closure /* callback */)>;
48
using TaskObserverRemove = std::function<void(intptr_t /* key */)>;
49 50 51
using UnhandledExceptionCallback =
    std::function<bool(const std::string& /* error */,
                       const std::string& /* stack trace */)>;
52

53 54 55 56
// TODO(chinmaygarde): Deprecate all the "path" struct members in favor of the
// callback that generates the mapping from these paths.
// https://github.com/flutter/flutter/issues/26783
using MappingCallback = std::function<std::unique_ptr<fml::Mapping>(void)>;
57 58
using MappingsCallback =
    std::function<std::vector<std::unique_ptr<const fml::Mapping>>(void)>;
59

60 61
using FrameRasterizedCallback = std::function<void(const FrameTiming&)>;

62
struct Settings {
63 64 65 66 67 68
  Settings();

  Settings(const Settings& other);

  ~Settings();

69
  // VM settings
70 71 72 73 74 75 76 77 78
  std::string vm_snapshot_data_path;  // deprecated
  MappingCallback vm_snapshot_data;
  std::string vm_snapshot_instr_path;  // deprecated
  MappingCallback vm_snapshot_instr;

  std::string isolate_snapshot_data_path;  // deprecated
  MappingCallback isolate_snapshot_data;
  std::string isolate_snapshot_instr_path;  // deprecated
  MappingCallback isolate_snapshot_instr;
79

80 81 82 83
  // Returns the Mapping to a kernel buffer which contains sources for dart:*
  // libraries.
  MappingCallback dart_library_sources_kernel;

84 85 86 87
  // Path to a library containing the application's compiled Dart code.
  // This is a vector so that the embedder can provide fallback paths in
  // case the primary path to the library can not be loaded.
  std::vector<std::string> application_library_path;
88 89 90 91

  std::string application_kernel_asset;       // deprecated
  std::string application_kernel_list_asset;  // deprecated
  MappingsCallback application_kernels;
92

93
  std::string temp_directory_path;
94
  std::vector<std::string> dart_flags;
95 96
  // Arguments passed as a List<String> to Dart's entrypoint function.
  std::vector<std::string> dart_entrypoint_args;
97 98

  // Isolate settings
99
  bool enable_checked_mode = false;
100 101
  bool start_paused = false;
  bool trace_skia = false;
102
  std::string trace_allowlist;
103
  bool trace_startup = false;
104
  bool trace_systrace = false;
105
  bool dump_skp_on_shader_compilation = false;
L
liyuqian 已提交
106
  bool cache_sksl = false;
Y
Yuqian Li 已提交
107
  bool purge_persistent_cache = false;
108 109
  bool endless_trace_buffer = false;
  bool enable_dart_profiling = false;
110
  bool disable_dart_asserts = false;
111 112 113 114

  // Used to signal the embedder whether HTTP connections are disabled.
  bool disable_http = false;

115 116 117 118 119 120
  // Used as the script URI in debug messages. Does not affect how the Dart code
  // is executed.
  std::string advisory_script_uri = "main.dart";
  // Used as the script entrypoint in debug messages. Does not affect how the
  // Dart code is executed.
  std::string advisory_script_entrypoint = "main";
121 122

  // Observatory settings
123 124

  // Whether the Dart VM service should be enabled.
125
  bool enable_observatory = false;
126 127 128 129 130 131 132

  // The IP address to which the Dart VM service is bound.
  std::string observatory_host;

  // The port to which the Dart VM service is bound. When set to `0`, a free
  // port will be automatically selected by the OS. A message is logged on the
  // target indicating the URL at which the VM service can be accessed.
133 134
  uint32_t observatory_port = 0;

135 136 137 138
  // Determines whether an authentication code is required to communicate with
  // the VM service.
  bool disable_service_auth_codes = true;

139 140 141 142
  // Determine whether the vmservice should fallback to automatic port selection
  // after failing to bind to a specified port.
  bool enable_service_port_fallback = false;

143 144 145
  // Font settings
  bool use_test_fonts = false;

146 147 148 149 150 151 152 153 154 155 156 157
  // All shells in the process share the same VM. The last shell to shutdown
  // should typically shut down the VM as well. However, applications depend on
  // the behavior of "warming-up" the VM by creating a shell that does not do
  // anything. This used to work earlier when the VM could not be shut down (and
  // hence never was). Shutting down the VM now breaks such assumptions in
  // existing embedders. To keep this behavior consistent and allow existing
  // embedders the chance to migrate, this flag defaults to true. Any shell
  // launched with this flag set to true will leak the VM in the process. There
  // is no way to shut down the VM once such a shell has been started. All
  // shells in the platform (via their embedding APIs) should cooperate to make
  // sure this flag is never set if they want the VM to shutdown and free all
  // associated resources.
158 159
  bool leak_vm = true;

160 161 162 163 164
  // Engine settings
  TaskObserverAdd task_observer_add;
  TaskObserverRemove task_observer_remove;
  // The main isolate is current when this callback is made. This is a good spot
  // to perform native Dart bindings for libraries not built in.
165
  fml::closure root_isolate_create_callback;
166
  fml::closure isolate_create_callback;
167 168
  // The isolate is not current and may have already been destroyed when this
  // call is made.
169
  fml::closure root_isolate_shutdown_callback;
170
  fml::closure isolate_shutdown_callback;
171 172 173 174 175
  // The callback made on the UI thread in an isolate scope when the engine
  // detects that the framework is idle. The VM also uses this time to perform
  // tasks suitable when idling. Due to this, embedders are still advised to be
  // as fast as possible in returning from this callback. Long running
  // operations in this callback do have the capability of introducing jank.
176
  std::function<void(int64_t)> idle_notification_callback;
177 178
  // A callback given to the embedder to react to unhandled exceptions in the
  // running Flutter application. This callback is made on an internal engine
179 180
  // managed thread and embedders must re-thread as necessary. Performing
  // blocking calls in this callback will cause applications to jank.
181
  UnhandledExceptionCallback unhandled_exception_callback;
182 183
  bool enable_software_rendering = false;
  bool skia_deterministic_rendering_on_cpu = false;
184
  bool verbose_logging = false;
185
  std::string log_tag = "flutter";
186

187 188 189 190 191 192
  // The icu_initialization_required setting does not have a corresponding
  // switch because it is intended to be decided during build time, not runtime.
  // Some companies apply source modification here because their build system
  // brings its own ICU data files.
  bool icu_initialization_required = true;
  std::string icu_data_path;
193
  MappingCallback icu_mapper;
194 195 196 197 198

  // Assets settings
  fml::UniqueFD::element_type assets_dir =
      fml::UniqueFD::traits_type::InvalidValue();
  std::string assets_path;
199

200 201 202 203
  // Callback to handle the timings of a rasterized frame. This is called as
  // soon as a frame is rasterized.
  FrameRasterizedCallback frame_rasterized_callback;

204 205 206 207
  // This data will be available to the isolate immediately on launch via the
  // Window.getPersistentIsolateData callback. This is meant for information
  // that the isolate cannot request asynchronously (platform messages can be
  // used for that purpose). This data is held for the lifetime of the shell and
D
Dan Field 已提交
208
  // is available on isolate restarts in the shell instance. Due to this,
209 210 211
  // the buffer must be as small as possible.
  std::shared_ptr<const fml::Mapping> persistent_isolate_data;

212 213 214 215 216 217 218
  /// Max size of old gen heap size in MB, or 0 for unlimited, -1 for default
  /// value.
  ///
  /// See also:
  /// https://github.com/dart-lang/sdk/blob/ca64509108b3e7219c50d6c52877c85ab6a35ff2/runtime/vm/flag_list.h#L150
  int64_t old_gen_heap_size = -1;

219 220 221 222 223
  /// A timestamp representing when the engine started. The value is based
  /// on the clock used by the Dart timeline APIs. This timestamp is used
  /// to log a timeline event that tracks the latency of engine startup.
  std::chrono::microseconds engine_start_timestamp = {};

224 225 226 227 228 229 230 231 232
  /// Whether the application claims that it uses the android embedded view for
  /// platform views.
  ///
  /// A `true` value will result the raster task runner always run on the
  /// platform thread.
  // TODO(cyanlaz): Remove this when dynamic thread merging is done.
  // https://github.com/flutter/flutter/issues/59930
  bool use_embedded_view = false;

233
  std::string ToString() const;
A
Adam Barth 已提交
234 235
};

236
}  // namespace flutter
A
Adam Barth 已提交
237

238
#endif  // FLUTTER_COMMON_SETTINGS_H_