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