• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <stdint.h>
10 
11 #include <memory>
12 #include <string>
13 #include <vector>
14 
15 #include "flutter/fml/closure.h"
16 #include "flutter/fml/mapping.h"
17 #include "flutter/fml/time/time_point.h"
18 #include "flutter/fml/unique_fd.h"
19 
20 namespace flutter {
21 
22 enum class AcePlatform : int32_t {
23   ACE_PLATFORM_INVALID = -1,
24   ACE_PLATFORM_ANDROID,
25   ACE_PLATFORM_IOS,
26   ACE_PLATFORM_OHOS,
27 };
28 
29 class FrameTiming {
30  public:
31   enum Phase { kBuildStart, kBuildFinish, kRasterStart, kRasterFinish, kCount };
32 
33   static constexpr Phase kPhases[kCount] = {kBuildStart, kBuildFinish,
34                                             kRasterStart, kRasterFinish};
35 
Get(Phase phase)36   fml::TimePoint Get(Phase phase) const { return data_[phase]; }
Set(Phase phase,fml::TimePoint value)37   fml::TimePoint Set(Phase phase, fml::TimePoint value) {
38     return data_[phase] = value;
39   }
40 
41  private:
42   fml::TimePoint data_[kCount];
43 };
44 
45 using TaskObserverAdd =
46     std::function<void(intptr_t /* key */, fml::closure /* callback */)>;
47 using TaskObserverRemove = std::function<void(intptr_t /* key */)>;
48 using UnhandledExceptionCallback =
49     std::function<bool(const std::string& /* error */,
50                        const std::string& /* stack trace */)>;
51 
52 // TODO(chinmaygarde): Deprecate all the "path" struct members in favor of the
53 // callback that generates the mapping from these paths.
54 // https://github.com/flutter/flutter/issues/26783
55 using MappingCallback = std::function<std::unique_ptr<fml::Mapping>(void)>;
56 using MappingsCallback =
57     std::function<std::vector<std::unique_ptr<const fml::Mapping>>(void)>;
58 
59 using FrameRasterizedCallback = std::function<void(const FrameTiming&)>;
60 
61 struct Settings {
62   Settings();
63 
64   Settings(const Settings& other);
65 
66   ~Settings();
67 
68   // Font settings
69   bool use_test_fonts = false;
70 
71   // Engine settings
72   TaskObserverAdd task_observer_add;
73   TaskObserverRemove task_observer_remove;
74 
75   // The callback made on the UI thread in an isolate scope when the engine
76   // detects that the framework is idle. The VM also uses this time to perform
77   // tasks suitable when idling. Due to this, embedders are still advised to be
78   // as fast as possible in returning from this callback. Long running
79   // operations in this callback do have the capability of introducing jank.
80   std::function<void(int64_t)> idle_notification_callback;
81   // A callback given to the embedder to react to unhandled exceptions in the
82   // running Flutter application. This callback is made on an internal engine
83   // managed thread and embedders must re-thread as necessary. Performing
84   // blocking calls in this callback will cause applications to jank.
85   UnhandledExceptionCallback unhandled_exception_callback;
86   bool enable_software_rendering = false;
87   bool skia_deterministic_rendering_on_cpu = false;
88   bool verbose_logging = false;
89   std::string log_tag = "flutter";
90 
91   // The icu_initialization_required setting does not have a corresponding
92   // switch because it is intended to be decided during build time, not runtime.
93   // Some companies apply source modification here because their build system
94   // brings its own ICU data files.
95   bool icu_initialization_required = true;
96   std::string icu_data_path;
97   MappingCallback icu_mapper;
98 
99   // Assets settings
100   fml::UniqueFD::element_type assets_dir =
101       fml::UniqueFD::traits_type::InvalidValue();
102   std::string assets_path;
103 
104   // Callback to handle the timings of a rasterized frame. This is called as
105   // soon as a frame is rasterized.
106   FrameRasterizedCallback frame_rasterized_callback;
107   int32_t instanceId = 0;
108   bool platform_as_ui_thread = false;
109   bool use_current_event_runner = false;
110   bool use_system_render_thread = false;
111   bool use_io_thread = false;
112 
113   AcePlatform platform = AcePlatform::ACE_PLATFORM_INVALID;
114 
115   std::string ToString() const;
116 };
117 
118 }  // namespace flutter
119 
120 #endif  // FLUTTER_COMMON_SETTINGS_H_
121