| 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 size_t DisplayId; |
| 18 | |
| 19 | /// To be used when the display refresh rate is unknown. |
| 20 | static constexpr double kUnknownDisplayRefreshRate = 0; |
| 21 | |
| 22 | /// The POD of a |Display|. This data is for a point in time and suitable |
| 23 | /// for copying. |
| 24 | struct DisplayData { |
| 25 | DisplayId id; |
| 26 | double width; |
| 27 | double height; |
| 28 | double pixel_ratio; |
| 29 | double refresh_rate; |
| 30 | }; |
| 31 | |
| 32 | /// Display refers to a graphics hardware system consisting of a framebuffer, |
| 33 | /// typically a monitor or a screen. This class holds the various display |
| 34 | /// settings. |
| 35 | class Display { |
| 36 | public: |
| 37 | //------------------------------------------------------------------------------ |
| 38 | /// @brief Construct a new Display object in case where the display id of the |
| 39 | /// display is known. |
| 40 | Display(DisplayId display_id, |
| 41 | double refresh_rate, |
| 42 | double width, |
| 43 | double height, |
| 44 | double device_pixel_ratio) |
| 45 | : display_id_(display_id), |
| 46 | refresh_rate_(refresh_rate), |
| 47 | width_(width), |
| 48 | height_(height), |
| 49 | device_pixel_ratio_(device_pixel_ratio) {} |
| 50 | |
| 51 | virtual ~Display() = default; |
| 52 | |
| 53 | // Get the display's maximum refresh rate in the unit of frame per second. |
| 54 | // Return `kUnknownDisplayRefreshRate` if the refresh rate is unknown. |
| 55 | virtual double GetRefreshRate() const; |
| 56 | |
| 57 | /// Returns the `DisplayId` of the display. |
| 58 | DisplayId GetDisplayId() const { return display_id_; } |
| 59 | |
| 60 | /// The width of the display in physical pixels. |
| 61 | virtual double GetWidth() const { return width_; } |
| 62 | |
| 63 | /// The height of the display in physical pixels. |
| 64 | virtual double GetHeight() const { return height_; } |
| 65 | |
| 66 | /// The device pixel ratio of the display. |
| 67 | virtual double GetDevicePixelRatio() const { return device_pixel_ratio_; } |
| 68 | |
| 69 | DisplayData GetDisplayData() { |
| 70 | return DisplayData{ |
| 71 | .id = GetDisplayId(), |
| 72 | .width = GetWidth(), |
| 73 | .height = GetHeight(), |
| 74 | .pixel_ratio = GetDevicePixelRatio(), |
| 75 | .refresh_rate = GetRefreshRate(), |
| 76 | }; |
| 77 | } |
| 78 | |
| 79 | private: |
| 80 | DisplayId display_id_; |
| 81 | double refresh_rate_; |
| 82 | double width_; |
| 83 | double height_; |
| 84 | double device_pixel_ratio_; |
| 85 | |
| 86 | FML_DISALLOW_COPY_AND_ASSIGN(Display); |
| 87 | }; |
| 88 | |
| 89 | } // namespace flutter |
| 90 | |
| 91 | #endif // FLUTTER_SHELL_COMMON_DISPLAY_H_ |
| 92 | |