Flutter Engine
display.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_SHELL_COMMON_DISPLAY_H_
6 #define FLUTTER_SHELL_COMMON_DISPLAY_H_
7 
8 #include <optional>
9 
10 namespace flutter {
11 
12 /// Unique ID per display that is stable until the Flutter application restarts.
13 /// See also: `flutter::Display`
14 typedef uint64_t DisplayId;
15 
16 /// To be used when the display refresh rate is unknown.
17 static constexpr double kUnknownDisplayRefreshRate = 0;
18 
19 /// Display refers to a graphics hardware system consisting of a framebuffer,
20 /// typically a monitor or a screen. This class holds the various display
21 /// settings.
22 class Display {
23  public:
24  //------------------------------------------------------------------------------
25  /// @brief Construct a new Display object in case where the display id of the
26  /// display is known. In cases where there is more than one display, every
27  /// display is expected to have a display id.
28  ///
29  Display(DisplayId display_id, double refresh_rate)
30  : display_id_(display_id), refresh_rate_(refresh_rate) {}
31 
32  //------------------------------------------------------------------------------
33  /// @brief Construct a new Display object when there is only a single display.
34  /// When there are multiple displays, every display must have a display id.
35  ///
36  explicit Display(double refresh_rate)
37  : display_id_({}), refresh_rate_(refresh_rate) {}
38 
39  ~Display() = default;
40 
41  // Get the display's maximum refresh rate in the unit of frame per second.
42  // Return `kUnknownDisplayRefreshRate` if the refresh rate is unknown.
43  double GetRefreshRate() const { return refresh_rate_; }
44 
45  /// Returns the `DisplayId` of the display.
46  std::optional<DisplayId> GetDisplayId() const { return display_id_; }
47 
48  private:
49  std::optional<DisplayId> display_id_;
50  double refresh_rate_;
51 };
52 
53 } // namespace flutter
54 
55 #endif // FLUTTER_SHELL_COMMON_DISPLAY_H_
Display(DisplayId display_id, double refresh_rate)
Construct a new Display object in case where the display id of the display is known. In cases where there is more than one display, every display is expected to have a display id.
Definition: display.h:29
static constexpr double kUnknownDisplayRefreshRate
To be used when the display refresh rate is unknown.
Definition: display.h:17
Display(double refresh_rate)
Construct a new Display object when there is only a single display. When there are multiple displays...
Definition: display.h:36
uint64_t DisplayId
Definition: display.h:14
std::optional< DisplayId > GetDisplayId() const
Returns the DisplayId of the display.
Definition: display.h:46
~Display()=default
double GetRefreshRate() const
Definition: display.h:43