Flutter Engine
The 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
13namespace flutter {
14
15/// Unique ID per display that is stable until the Flutter application restarts.
16/// See also: `flutter::Display`
17typedef size_t DisplayId;
18
19/// To be used when the display refresh rate is unknown.
20static constexpr double kUnknownDisplayRefreshRate = 0;
21
22/// The POD of a |Display|. This data is for a point in time and suitable
23/// for copying.
26 double width;
27 double height;
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.
35class 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
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_
virtual double GetRefreshRate() const
Definition: display.cc:8
virtual double GetWidth() const
The width of the display in physical pixels.
Definition: display.h:61
DisplayId GetDisplayId() const
Returns the DisplayId of the display.
Definition: display.h:58
virtual double GetHeight() const
The height of the display in physical pixels.
Definition: display.h:64
Display(DisplayId display_id, double refresh_rate, double width, double height, double device_pixel_ratio)
Construct a new Display object in case where the display id of the display is known.
Definition: display.h:40
DisplayData GetDisplayData()
Definition: display.h:69
virtual ~Display()=default
virtual double GetDevicePixelRatio() const
The device pixel ratio of the display.
Definition: display.h:67
size_t DisplayId
Definition: display.h:17
static constexpr double kUnknownDisplayRefreshRate
To be used when the display refresh rate is unknown.
Definition: display.h:20
int32_t height
int32_t width
double refresh_rate
Definition: display.h:29
double pixel_ratio
Definition: display.h:28
DisplayId id
Definition: display.h:25