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