Disable Vsync when Aero Glass is enabled.
[chromium-blink-merge.git] / ash / display / display_info.h
blob69b83dce53de016376ca5dc15e92d2775e0d6471
1 // Copyright (c) 2013 The Chromium 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.
5 #ifndef ASH_DISPLAY_DISPLAY_INFO_H_
6 #define ASH_DISPLAY_DISPLAY_INFO_H_
8 #include <string>
9 #include <vector>
11 #include "ash/ash_export.h"
12 #include "ui/gfx/display.h"
13 #include "ui/gfx/insets.h"
14 #include "ui/gfx/rect.h"
16 namespace ash {
17 namespace internal {
19 // A struct that represents the display's resolution and
20 // interlaced info.
21 struct ASH_EXPORT Resolution {
22 Resolution(const gfx::Size& size, bool interlaced);
24 gfx::Size size;
25 bool interlaced;
28 // DisplayInfo contains metadata for each display. This is used to
29 // create |gfx::Display| as well as to maintain extra infomation
30 // to manage displays in ash environment.
31 // This class is intentionally made copiable.
32 class ASH_EXPORT DisplayInfo {
33 public:
34 // Creates a DisplayInfo from string spec. 100+200-1440x800 creates display
35 // whose size is 1440x800 at the location (100, 200) in host coordinates.
36 // The format is
38 // [origin-]widthxheight[*device_scale_factor][#resolutions list]
39 // [/<properties>][@ui-scale]
41 // where [] are optional:
42 // - |origin| is given in x+y- format.
43 // - |device_scale_factor| is either 2 or 1 (or empty).
44 // - properties can combination of 'o', which adds default overscan insets
45 // (5%), and one rotation property where 'r' is 90 degree clock-wise
46 // (to the 'r'ight) 'u' is 180 degrees ('u'pside-down) and 'l' is
47 // 270 degrees (to the 'l'eft).
48 // - ui-scale is floating value, e.g. @1.5 or @1.25.
49 // - |resolution list| is the list of size that is given in
50 // |width x height| separated by '|'.
52 // A couple of examples:
53 // "100x100"
54 // 100x100 window at 0,0 origin. 1x device scale factor. no overscan.
55 // no rotation. 1.0 ui scale.
56 // "5+5-300x200*2"
57 // 300x200 window at 5,5 origin. 2x device scale factor.
58 // no overscan, no rotation. 1.0 ui scale.
59 // "300x200/ol"
60 // 300x200 window at 0,0 origin. 1x device scale factor.
61 // with 5% overscan. rotated to left (90 degree counter clockwise).
62 // 1.0 ui scale.
63 // "10+20-300x200/u@1.5"
64 // 300x200 window at 10,20 origin. 1x device scale factor.
65 // no overscan. flipped upside-down (180 degree) and 1.5 ui scale.
66 // "200x100#300x200|200x100|100x100"
67 // 200x100 window at 0,0 origin, with 3 possible resolutions,
68 // 300x200, 200x100 and 100x100.
69 static DisplayInfo CreateFromSpec(const std::string& spec);
71 // Creates a DisplayInfo from string spec using given |id|.
72 static DisplayInfo CreateFromSpecWithID(const std::string& spec,
73 int64 id);
75 DisplayInfo();
76 DisplayInfo(int64 id, const std::string& name, bool has_overscan);
77 ~DisplayInfo();
79 int64 id() const { return id_; }
81 // The name of the display.
82 const std::string& name() const { return name_; }
84 // True if the display EDID has the overscan flag. This does not create the
85 // actual overscan automatically, but used in the message.
86 bool has_overscan() const { return has_overscan_; }
88 void set_rotation(gfx::Display::Rotation rotation) { rotation_ = rotation; }
89 gfx::Display::Rotation rotation() const { return rotation_; }
91 void set_touch_support(gfx::Display::TouchSupport support) {
92 touch_support_ = support;
94 gfx::Display::TouchSupport touch_support() const { return touch_support_; }
96 // Gets/Sets the device scale factor of the display.
97 float device_scale_factor() const { return device_scale_factor_; }
98 void set_device_scale_factor(float scale) { device_scale_factor_ = scale; }
100 // The native bounds for the display. The size of this can be
101 // different from the |size_in_pixel| when overscan insets are set
102 // and/or |configured_ui_scale_| is set.
103 const gfx::Rect bounds_in_native() const {
104 return bounds_in_native_;
107 // The size for the display in pixels.
108 const gfx::Size& size_in_pixel() const { return size_in_pixel_; }
110 // The overscan insets for the display in DIP.
111 const gfx::Insets& overscan_insets_in_dip() const {
112 return overscan_insets_in_dip_;
115 // Sets/gets configured ui scale. This can be different from the ui
116 // scale actually used when the scale is 2.0 and DSF is 2.0.
117 // (the effective ui scale is 1.0 in this case).
118 float configured_ui_scale() const { return configured_ui_scale_; }
119 void set_configured_ui_scale(float scale) { configured_ui_scale_ = scale; }
121 // Returns the ui scale used for the device scale factor. This
122 // return 1.0f if the ui scale and dsf are both set to 2.0.
123 float GetEffectiveUIScale() const;
125 // Copy the display info except for fields that can be modified by a
126 // user (|rotation_| and |configured_ui_scale_|). |rotation_| and
127 // |configured_ui_scale_| are copied when the |another_info| isn't native one.
128 void Copy(const DisplayInfo& another_info);
130 // Update the |bounds_in_native_| and |size_in_pixel_| using
131 // given |bounds_in_native|.
132 void SetBounds(const gfx::Rect& bounds_in_native);
134 // Update the |bounds_in_native| according to the current overscan
135 // and rotation settings.
136 void UpdateDisplaySize();
138 // Sets/Clears the overscan insets.
139 void SetOverscanInsets(const gfx::Insets& insets_in_dip);
140 gfx::Insets GetOverscanInsetsInPixel() const;
142 void set_native(bool native) { native_ = native; }
143 bool native() const { return native_; }
145 const std::vector<Resolution>& resolutions() const {
146 return resolutions_;
148 void set_resolutions(std::vector<Resolution>& resolution) {
149 resolutions_.swap(resolution);
152 // Returns a string representation of the DisplayInfo
153 // excluding resolutions.
154 std::string ToString() const;
156 // Returns a string representation of the DisplayInfo
157 // including resolutions.
158 std::string ToFullString() const;
160 private:
161 int64 id_;
162 std::string name_;
163 bool has_overscan_;
164 gfx::Display::Rotation rotation_;
165 gfx::Display::TouchSupport touch_support_;
167 // This specifies the device's pixel density. (For example, a
168 // display whose DPI is higher than the threshold is considered to have
169 // device_scale_factor = 2.0 on Chrome OS). This is used by the
170 // grapics layer to choose and draw appropriate images and scale
171 // layers properly.
172 float device_scale_factor_;
173 gfx::Rect bounds_in_native_;
175 // The size of the display in use. The size can be different from the size
176 // of |bounds_in_native_| if the display has overscan insets and/or rotation.
177 gfx::Size size_in_pixel_;
178 gfx::Insets overscan_insets_in_dip_;
180 // The pixel scale of the display. This is used to simply expand (or
181 // shrink) the desktop over the native display resolution (useful in
182 // HighDPI display). Note that this should not be confused with the
183 // device scale factor, which specifies the pixel density of the
184 // display. The actuall scale value to be used depends on the device
185 // scale factor. See |GetEffectiveScaleFactor()|.
186 float configured_ui_scale_;
188 // True if this comes from native platform (DisplayChangeObserver).
189 bool native_;
191 // The list of resolutions supported by this display.
192 std::vector<Resolution> resolutions_;
195 } // namespace internal
196 } // namespace ash
198 #endif // ASH_DISPLAY_DISPLAY_INFO_H_