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_
11 #include "ash/ash_export.h"
12 #include "ui/display/types/display_constants.h"
13 #include "ui/gfx/display.h"
14 #include "ui/gfx/insets.h"
15 #include "ui/gfx/rect.h"
19 // A struct that represents the display's mode info.
20 struct ASH_EXPORT DisplayMode
{
22 DisplayMode(const gfx::Size
& size
,
27 gfx::Size size
; // Physical pixel size of the display.
28 float refresh_rate
; // Refresh rate of the display, in Hz.
29 bool interlaced
; // True if mode is interlaced.
30 bool native
; // True if mode is native mode of the display.
33 // DisplayInfo contains metadata for each display. This is used to
34 // create |gfx::Display| as well as to maintain extra infomation
35 // to manage displays in ash environment.
36 // This class is intentionally made copiable.
37 class ASH_EXPORT DisplayInfo
{
39 // Creates a DisplayInfo from string spec. 100+200-1440x800 creates display
40 // whose size is 1440x800 at the location (100, 200) in host coordinates.
43 // [origin-]widthxheight[*device_scale_factor][#resolutions list]
44 // [/<properties>][@ui-scale]
46 // where [] are optional:
47 // - |origin| is given in x+y- format.
48 // - |device_scale_factor| is either 2 or 1 (or empty).
49 // - properties can combination of 'o', which adds default overscan insets
50 // (5%), and one rotation property where 'r' is 90 degree clock-wise
51 // (to the 'r'ight) 'u' is 180 degrees ('u'pside-down) and 'l' is
52 // 270 degrees (to the 'l'eft).
53 // - ui-scale is floating value, e.g. @1.5 or @1.25.
54 // - |resolution list| is the list of size that is given in
55 // |width x height [% refresh_rate]| separated by '|'.
57 // A couple of examples:
59 // 100x100 window at 0,0 origin. 1x device scale factor. no overscan.
60 // no rotation. 1.0 ui scale.
62 // 300x200 window at 5,5 origin. 2x device scale factor.
63 // no overscan, no rotation. 1.0 ui scale.
65 // 300x200 window at 0,0 origin. 1x device scale factor.
66 // with 5% overscan. rotated to left (90 degree counter clockwise).
68 // "10+20-300x200/u@1.5"
69 // 300x200 window at 10,20 origin. 1x device scale factor.
70 // no overscan. flipped upside-down (180 degree) and 1.5 ui scale.
71 // "200x100#300x200|200x100%59.0|100x100%60"
72 // 200x100 window at 0,0 origin, with 3 possible resolutions,
73 // 300x200, 200x100 at 59 Hz, and 100x100 at 60 Hz.
74 static DisplayInfo
CreateFromSpec(const std::string
& spec
);
76 // Creates a DisplayInfo from string spec using given |id|.
77 static DisplayInfo
CreateFromSpecWithID(const std::string
& spec
,
81 DisplayInfo(int64 id
, const std::string
& name
, bool has_overscan
);
84 // When this is set to true, Chrome switches High DPI when lower UI scale
85 // (<1.0f) is specified on 1x device to make UI sharp, e.g, upgrade 0.6
86 // scale on 1x DSF to 1.2 scale on 2x DSF.
87 static void SetAllowUpgradeToHighDPI(bool enable
);
89 int64
id() const { return id_
; }
91 // The name of the display.
92 const std::string
& name() const { return name_
; }
94 // True if the display EDID has the overscan flag. This does not create the
95 // actual overscan automatically, but used in the message.
96 bool has_overscan() const { return has_overscan_
; }
98 void set_rotation(gfx::Display::Rotation rotation
) { rotation_
= rotation
; }
99 gfx::Display::Rotation
rotation() const { return rotation_
; }
101 void set_touch_support(gfx::Display::TouchSupport support
) {
102 touch_support_
= support
;
104 gfx::Display::TouchSupport
touch_support() const { return touch_support_
; }
106 void set_touch_device_id(int id
) { touch_device_id_
= id
; }
107 int touch_device_id() const { return touch_device_id_
; }
109 // Gets/Sets the device scale factor of the display.
110 float device_scale_factor() const { return device_scale_factor_
; }
111 void set_device_scale_factor(float scale
) { device_scale_factor_
= scale
; }
113 // The native bounds for the display. The size of this can be
114 // different from the |size_in_pixel| when overscan insets are set
115 // and/or |configured_ui_scale_| is set.
116 const gfx::Rect
& bounds_in_native() const {
117 return bounds_in_native_
;
120 // The size for the display in pixels.
121 const gfx::Size
& size_in_pixel() const { return size_in_pixel_
; }
123 // The overscan insets for the display in DIP.
124 const gfx::Insets
& overscan_insets_in_dip() const {
125 return overscan_insets_in_dip_
;
128 // Sets/gets configured ui scale. This can be different from the ui
129 // scale actually used when the scale is 2.0 and DSF is 2.0.
130 // (the effective ui scale is 1.0 in this case).
131 float configured_ui_scale() const { return configured_ui_scale_
; }
132 void set_configured_ui_scale(float scale
) { configured_ui_scale_
= scale
; }
134 // Returns the ui scale and device scale factor actually used to create
135 // display that chrome sees. This can be different from one obtained
136 // from dispaly or one specified by a user in following situation.
137 // 1) DSF is 2.0f and UI scale is 2.0f. (Returns 1.0f and 1.0f respectiely)
138 // 2) Lower UI scale (< 1.0) is specified on 1.0f DSF device
139 // when 2x resources is available. (Returns 2.0f DSF + 1.2f UI scale
140 // for 1.0DSF + 0.6 UI scale).
141 float GetEffectiveDeviceScaleFactor() const;
142 float GetEffectiveUIScale() const;
144 // Copy the display info except for fields that can be modified by a
145 // user (|rotation_| and |configured_ui_scale_|). |rotation_| and
146 // |configured_ui_scale_| are copied when the |another_info| isn't native one.
147 void Copy(const DisplayInfo
& another_info
);
149 // Update the |bounds_in_native_| and |size_in_pixel_| using
150 // given |bounds_in_native|.
151 void SetBounds(const gfx::Rect
& bounds_in_native
);
153 // Update the |bounds_in_native| according to the current overscan
154 // and rotation settings.
155 void UpdateDisplaySize();
157 // Sets/Clears the overscan insets.
158 void SetOverscanInsets(const gfx::Insets
& insets_in_dip
);
159 gfx::Insets
GetOverscanInsetsInPixel() const;
161 void set_native(bool native
) { native_
= native
; }
162 bool native() const { return native_
; }
164 const std::vector
<DisplayMode
>& display_modes() const {
165 return display_modes_
;
167 void set_display_modes(std::vector
<DisplayMode
>& display_modes
) {
168 display_modes_
.swap(display_modes
);
171 ui::ColorCalibrationProfile
color_profile() const {
172 return color_profile_
;
175 // Sets the color profile. It will ignore if the specified |profile| is not in
176 // |available_color_profiles_|.
177 void SetColorProfile(ui::ColorCalibrationProfile profile
);
179 // Returns true if |profile| is in |available_color_profiles_|.
180 bool IsColorProfileAvailable(ui::ColorCalibrationProfile profile
) const;
182 const std::vector
<ui::ColorCalibrationProfile
>&
183 available_color_profiles() const {
184 return available_color_profiles_
;
187 void set_available_color_profiles(
188 const std::vector
<ui::ColorCalibrationProfile
>& profiles
) {
189 available_color_profiles_
= profiles
;
192 bool is_aspect_preserving_scaling() const {
193 return is_aspect_preserving_scaling_
;
196 void set_is_aspect_preserving_scaling(bool value
) {
197 is_aspect_preserving_scaling_
= value
;
200 // Returns a string representation of the DisplayInfo, excluding display
202 std::string
ToString() const;
204 // Returns a string representation of the DisplayInfo, including display
206 std::string
ToFullString() const;
212 gfx::Display::Rotation rotation_
;
213 gfx::Display::TouchSupport touch_support_
;
215 // If the display is also a touch device, it will have a positive
216 // |touch_device_id_|. Otherwise |touch_device_id_| is 0.
217 int touch_device_id_
;
219 // This specifies the device's pixel density. (For example, a
220 // display whose DPI is higher than the threshold is considered to have
221 // device_scale_factor = 2.0 on Chrome OS). This is used by the
222 // grapics layer to choose and draw appropriate images and scale
224 float device_scale_factor_
;
225 gfx::Rect bounds_in_native_
;
227 // The size of the display in use. The size can be different from the size
228 // of |bounds_in_native_| if the display has overscan insets and/or rotation.
229 gfx::Size size_in_pixel_
;
230 gfx::Insets overscan_insets_in_dip_
;
232 // The pixel scale of the display. This is used to simply expand (or
233 // shrink) the desktop over the native display resolution (useful in
234 // HighDPI display). Note that this should not be confused with the
235 // device scale factor, which specifies the pixel density of the
236 // display. The actuall scale value to be used depends on the device
237 // scale factor. See |GetEffectiveScaleFactor()|.
238 float configured_ui_scale_
;
240 // True if this comes from native platform (DisplayChangeObserver).
243 // True if the display is configured to preserve the aspect ratio. When the
244 // display is configured in a non-native mode, only parts of the display will
245 // be used such that the aspect ratio is preserved.
246 bool is_aspect_preserving_scaling_
;
248 // The list of modes supported by this display.
249 std::vector
<DisplayMode
> display_modes_
;
251 // The current profile of the color calibration.
252 ui::ColorCalibrationProfile color_profile_
;
254 // The list of available variations for the color calibration.
255 std::vector
<ui::ColorCalibrationProfile
> available_color_profiles_
;
260 #endif // ASH_DISPLAY_DISPLAY_INFO_H_