Updating XTBs based on .GRDs from branch master
[chromium-blink-merge.git] / ash / display / display_info.h
blob4261da939192979c48bc1ae26c108b8197c18e0c
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 <map>
9 #include <string>
10 #include <vector>
12 #include "ash/ash_export.h"
13 #include "ui/display/types/display_constants.h"
14 #include "ui/gfx/display.h"
15 #include "ui/gfx/geometry/insets.h"
16 #include "ui/gfx/geometry/rect.h"
18 namespace ash {
20 // A struct that represents the display's mode info.
21 struct ASH_EXPORT DisplayMode {
22 DisplayMode();
23 DisplayMode(const gfx::Size& size,
24 float refresh_rate,
25 bool interlaced,
26 bool native);
28 // Returns the size in DIP which is visible to the user.
29 gfx::Size GetSizeInDIP(bool is_internal) const;
31 // Returns true if |other| has same size and scale factors.
32 bool IsEquivalent(const DisplayMode& other) const;
34 gfx::Size size; // Physical pixel size of the display.
35 float refresh_rate; // Refresh rate of the display, in Hz.
36 bool interlaced; // True if mode is interlaced.
37 bool native; // True if mode is native mode of the display.
38 float ui_scale; // The UI scale factor of the mode.
39 float device_scale_factor; // The device scale factor of the mode.
42 // DisplayInfo contains metadata for each display. This is used to
43 // create |gfx::Display| as well as to maintain extra infomation
44 // to manage displays in ash environment.
45 // This class is intentionally made copiable.
46 class ASH_EXPORT DisplayInfo {
47 public:
48 // Creates a DisplayInfo from string spec. 100+200-1440x800 creates display
49 // whose size is 1440x800 at the location (100, 200) in host coordinates.
50 // The format is
52 // [origin-]widthxheight[*device_scale_factor][#resolutions list]
53 // [/<properties>][@ui-scale]
55 // where [] are optional:
56 // - |origin| is given in x+y- format.
57 // - |device_scale_factor| is either 2 or 1 (or empty).
58 // - properties can combination of 'o', which adds default overscan insets
59 // (5%), and one rotation property where 'r' is 90 degree clock-wise
60 // (to the 'r'ight) 'u' is 180 degrees ('u'pside-down) and 'l' is
61 // 270 degrees (to the 'l'eft).
62 // - ui-scale is floating value, e.g. @1.5 or @1.25.
63 // - |resolution list| is the list of size that is given in
64 // |width x height [% refresh_rate]| separated by '|'.
66 // A couple of examples:
67 // "100x100"
68 // 100x100 window at 0,0 origin. 1x device scale factor. no overscan.
69 // no rotation. 1.0 ui scale.
70 // "5+5-300x200*2"
71 // 300x200 window at 5,5 origin. 2x device scale factor.
72 // no overscan, no rotation. 1.0 ui scale.
73 // "300x200/ol"
74 // 300x200 window at 0,0 origin. 1x device scale factor.
75 // with 5% overscan. rotated to left (90 degree counter clockwise).
76 // 1.0 ui scale.
77 // "10+20-300x200/u@1.5"
78 // 300x200 window at 10,20 origin. 1x device scale factor.
79 // no overscan. flipped upside-down (180 degree) and 1.5 ui scale.
80 // "200x100#300x200|200x100%59.0|100x100%60"
81 // 200x100 window at 0,0 origin, with 3 possible resolutions,
82 // 300x200, 200x100 at 59 Hz, and 100x100 at 60 Hz.
83 static DisplayInfo CreateFromSpec(const std::string& spec);
85 // Creates a DisplayInfo from string spec using given |id|.
86 static DisplayInfo CreateFromSpecWithID(const std::string& spec,
87 int64 id);
89 // When this is set to true on the device whose internal display has
90 // 1.25 dsf, Chrome uses 1.0f as a default scale factor, and uses
91 // dsf 1.25 when UI scaling is set to 0.8f.
92 static void SetUse125DSFForUIScalingForTest(bool enable);
94 DisplayInfo();
95 DisplayInfo(int64 id, const std::string& name, bool has_overscan);
96 ~DisplayInfo();
98 int64 id() const { return id_; }
100 // The name of the display.
101 const std::string& name() const { return name_; }
103 // True if the display EDID has the overscan flag. This does not create the
104 // actual overscan automatically, but used in the message.
105 bool has_overscan() const { return has_overscan_; }
107 void set_touch_support(gfx::Display::TouchSupport support) {
108 touch_support_ = support;
110 gfx::Display::TouchSupport touch_support() const { return touch_support_; }
112 // Associate the input device with identifier |id| with this display.
113 void AddInputDevice(int id);
115 // Clear the list of input devices associated with this display.
116 void ClearInputDevices();
118 // The input device ids that are associated with this display.
119 std::vector<int> input_devices() const { return input_devices_; }
121 // Gets/Sets the device scale factor of the display.
122 float device_scale_factor() const { return device_scale_factor_; }
123 void set_device_scale_factor(float scale) { device_scale_factor_ = scale; }
125 // The native bounds for the display. The size of this can be
126 // different from the |size_in_pixel| when overscan insets are set
127 // and/or |configured_ui_scale_| is set.
128 const gfx::Rect& bounds_in_native() const {
129 return bounds_in_native_;
132 // The size for the display in pixels.
133 const gfx::Size& size_in_pixel() const { return size_in_pixel_; }
135 // The overscan insets for the display in DIP.
136 const gfx::Insets& overscan_insets_in_dip() const {
137 return overscan_insets_in_dip_;
140 // Sets/gets configured ui scale. This can be different from the ui
141 // scale actually used when the scale is 2.0 and DSF is 2.0.
142 // (the effective ui scale is 1.0 in this case).
143 float configured_ui_scale() const { return configured_ui_scale_; }
144 void set_configured_ui_scale(float scale) { configured_ui_scale_ = scale; }
146 // Sets the rotation for the given |source|. Setting a new rotation will also
147 // have it become the active rotation.
148 void SetRotation(gfx::Display::Rotation rotation,
149 gfx::Display::RotationSource source);
151 // Returns the currently active rotation for this display.
152 gfx::Display::Rotation GetActiveRotation() const;
154 // Returns the rotation set by a given |source|.
155 gfx::Display::Rotation GetRotation(gfx::Display::RotationSource source) const;
157 // Returns the ui scale and device scale factor actually used to create
158 // display that chrome sees. This can be different from one obtained
159 // from dispaly or one specified by a user in following situation.
160 // 1) DSF is 2.0f and UI scale is 2.0f. (Returns 1.0f and 1.0f respectiely)
161 // 2) A user specified 0.8x on the device that has 1.25 DSF. 1.25 DSF device
162 // uses 1.0f DFS unless 0.8x UI scaling is specified.
163 float GetEffectiveDeviceScaleFactor() const;
165 // Returns the ui scale used for the device scale factor. This
166 // return 1.0f if the ui scale and dsf are both set to 2.0.
167 float GetEffectiveUIScale() const;
169 // Copy the display info except for fields that can be modified by a
170 // user (|rotation_| and |configured_ui_scale_|). |rotation_| and
171 // |configured_ui_scale_| are copied when the |another_info| isn't native one.
172 void Copy(const DisplayInfo& another_info);
174 // Update the |bounds_in_native_| and |size_in_pixel_| using
175 // given |bounds_in_native|.
176 void SetBounds(const gfx::Rect& bounds_in_native);
178 // Update the |bounds_in_native| according to the current overscan
179 // and rotation settings.
180 void UpdateDisplaySize();
182 // Sets/Clears the overscan insets.
183 void SetOverscanInsets(const gfx::Insets& insets_in_dip);
184 gfx::Insets GetOverscanInsetsInPixel() const;
186 // Sets/Gets the flag to clear overscan insets.
187 bool clear_overscan_insets() const { return clear_overscan_insets_; }
188 void set_clear_overscan_insets(bool clear) { clear_overscan_insets_ = clear; }
190 void set_native(bool native) { native_ = native; }
191 bool native() const { return native_; }
193 const std::vector<DisplayMode>& display_modes() const {
194 return display_modes_;
196 // Sets the display mode list. The mode list will be sorted for the
197 // display.
198 void SetDisplayModes(const std::vector<DisplayMode>& display_modes);
200 // Returns the native mode size. If a native mode is not present, return an
201 // empty size.
202 gfx::Size GetNativeModeSize() const;
204 ui::ColorCalibrationProfile color_profile() const {
205 return color_profile_;
208 // Sets the color profile. It will ignore if the specified |profile| is not in
209 // |available_color_profiles_|.
210 void SetColorProfile(ui::ColorCalibrationProfile profile);
212 // Returns true if |profile| is in |available_color_profiles_|.
213 bool IsColorProfileAvailable(ui::ColorCalibrationProfile profile) const;
215 const std::vector<ui::ColorCalibrationProfile>&
216 available_color_profiles() const {
217 return available_color_profiles_;
220 void set_available_color_profiles(
221 const std::vector<ui::ColorCalibrationProfile>& profiles) {
222 available_color_profiles_ = profiles;
225 bool is_aspect_preserving_scaling() const {
226 return is_aspect_preserving_scaling_;
229 void set_is_aspect_preserving_scaling(bool value) {
230 is_aspect_preserving_scaling_ = value;
233 // Returns a string representation of the DisplayInfo, excluding display
234 // modes.
235 std::string ToString() const;
237 // Returns a string representation of the DisplayInfo, including display
238 // modes.
239 std::string ToFullString() const;
241 private:
242 // Returns true if this display should use DSF=1.25 for UI scaling; i.e.
243 // SetUse125DSFForUIScaling(true) is called and this is the internal display.
244 bool Use125DSFForUIScaling() const;
246 int64 id_;
247 std::string name_;
248 bool has_overscan_;
249 std::map<gfx::Display::RotationSource, gfx::Display::Rotation> rotations_;
250 gfx::Display::TouchSupport touch_support_;
252 // The set of input devices associated with this display.
253 std::vector<int> input_devices_;
255 // This specifies the device's pixel density. (For example, a
256 // display whose DPI is higher than the threshold is considered to have
257 // device_scale_factor = 2.0 on Chrome OS). This is used by the
258 // grapics layer to choose and draw appropriate images and scale
259 // layers properly.
260 float device_scale_factor_;
261 gfx::Rect bounds_in_native_;
263 // The size of the display in use. The size can be different from the size
264 // of |bounds_in_native_| if the display has overscan insets and/or rotation.
265 gfx::Size size_in_pixel_;
266 gfx::Insets overscan_insets_in_dip_;
268 // The pixel scale of the display. This is used to simply expand (or
269 // shrink) the desktop over the native display resolution (useful in
270 // HighDPI display). Note that this should not be confused with the
271 // device scale factor, which specifies the pixel density of the
272 // display. The actuall scale value to be used depends on the device
273 // scale factor. See |GetEffectiveScaleFactor()|.
274 float configured_ui_scale_;
276 // True if this comes from native platform (DisplayChangeObserver).
277 bool native_;
279 // True if the display is configured to preserve the aspect ratio. When the
280 // display is configured in a non-native mode, only parts of the display will
281 // be used such that the aspect ratio is preserved.
282 bool is_aspect_preserving_scaling_;
284 // True if the displays' overscan inset should be cleared. This is
285 // to distinguish the empty overscan insets from native display info.
286 bool clear_overscan_insets_;
288 // The list of modes supported by this display.
289 std::vector<DisplayMode> display_modes_;
291 // The current profile of the color calibration.
292 ui::ColorCalibrationProfile color_profile_;
294 // The list of available variations for the color calibration.
295 std::vector<ui::ColorCalibrationProfile> available_color_profiles_;
297 // If you add a new member, you need to update Copy().
300 // Resets the synthesized display id for testing. This
301 // is necessary to avoid overflowing the output index.
302 ASH_EXPORT void ResetDisplayIdForTest();
304 } // namespace ash
306 #endif // ASH_DISPLAY_DISPLAY_INFO_H_