OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef ASH_COMMON_DISPLAY_DISPLAY_INFO_H_ | |
6 #define ASH_COMMON_DISPLAY_DISPLAY_INFO_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include <map> | |
11 #include <string> | |
12 #include <vector> | |
13 | |
14 #include "ash/ash_export.h" | |
15 #include "base/files/file_path.h" | |
16 #include "base/memory/ref_counted.h" | |
17 #include "ui/display/display.h" | |
18 #include "ui/display/types/display_constants.h" | |
19 #include "ui/gfx/geometry/insets.h" | |
20 #include "ui/gfx/geometry/rect.h" | |
21 | |
22 namespace ash { | |
23 | |
24 // A class that represents the display's mode info. | |
25 class ASH_EXPORT ManagedDisplayMode | |
26 : public base::RefCounted<ManagedDisplayMode> { | |
27 public: | |
28 ManagedDisplayMode(); | |
29 | |
30 ManagedDisplayMode(const gfx::Size& size); | |
31 | |
32 ManagedDisplayMode(const gfx::Size& size, | |
33 float refresh_rate, | |
34 bool is_interlaced, | |
35 bool native); | |
36 | |
37 ManagedDisplayMode(const gfx::Size& size, | |
38 float refresh_rate, | |
39 bool is_interlaced, | |
40 bool native, | |
41 float ui_scale, | |
42 float device_scale_factor); | |
43 // Returns the size in DIP which is visible to the user. | |
44 gfx::Size GetSizeInDIP(bool is_internal) const; | |
45 | |
46 // Returns true if |other| has same size and scale factors. | |
47 bool IsEquivalent(const scoped_refptr<ManagedDisplayMode>& other) const; | |
48 | |
49 const gfx::Size& size() const { return size_; } | |
50 bool is_interlaced() const { return is_interlaced_; } | |
51 float refresh_rate() const { return refresh_rate_; } | |
52 | |
53 bool native() const { return native_; } | |
54 | |
55 // Missing from ui::ManagedDisplayMode | |
56 float ui_scale() const { return ui_scale_; } | |
57 float device_scale_factor() const { return device_scale_factor_; } | |
58 | |
59 private: | |
60 ~ManagedDisplayMode(); | |
61 friend class base::RefCounted<ManagedDisplayMode>; | |
62 | |
63 gfx::Size size_; // Physical pixel size of the display. | |
64 float refresh_rate_; // Refresh rate of the display, in Hz. | |
65 bool is_interlaced_; // True if mode is interlaced. | |
66 bool native_; // True if mode is native mode of the display. | |
67 float ui_scale_; // The UI scale factor of the mode. | |
68 float device_scale_factor_; // The device scale factor of the mode. | |
69 | |
70 DISALLOW_COPY_AND_ASSIGN(ManagedDisplayMode); | |
71 }; | |
72 | |
73 // DisplayInfo contains metadata for each display. This is used to | |
74 // create |display::Display| as well as to maintain extra infomation | |
75 // to manage displays in ash environment. | |
76 // This class is intentionally made copiable. | |
77 class ASH_EXPORT DisplayInfo { | |
78 public: | |
79 using ManagedDisplayModeList = std::vector<scoped_refptr<ManagedDisplayMode>>; | |
80 | |
81 // Creates a DisplayInfo from string spec. 100+200-1440x800 creates display | |
82 // whose size is 1440x800 at the location (100, 200) in host coordinates. | |
83 // The format is | |
84 // | |
85 // [origin-]widthxheight[*device_scale_factor][#resolutions list] | |
86 // [/<properties>][@ui-scale] | |
87 // | |
88 // where [] are optional: | |
89 // - |origin| is given in x+y- format. | |
90 // - |device_scale_factor| is either 2 or 1 (or empty). | |
91 // - properties can combination of 'o', which adds default overscan insets | |
92 // (5%), and one rotation property where 'r' is 90 degree clock-wise | |
93 // (to the 'r'ight) 'u' is 180 degrees ('u'pside-down) and 'l' is | |
94 // 270 degrees (to the 'l'eft). | |
95 // - ui-scale is floating value, e.g. @1.5 or @1.25. | |
96 // - |resolution list| is the list of size that is given in | |
97 // |width x height [% refresh_rate]| separated by '|'. | |
98 // | |
99 // A couple of examples: | |
100 // "100x100" | |
101 // 100x100 window at 0,0 origin. 1x device scale factor. no overscan. | |
102 // no rotation. 1.0 ui scale. | |
103 // "5+5-300x200*2" | |
104 // 300x200 window at 5,5 origin. 2x device scale factor. | |
105 // no overscan, no rotation. 1.0 ui scale. | |
106 // "300x200/ol" | |
107 // 300x200 window at 0,0 origin. 1x device scale factor. | |
108 // with 5% overscan. rotated to left (90 degree counter clockwise). | |
109 // 1.0 ui scale. | |
110 // "10+20-300x200/u@1.5" | |
111 // 300x200 window at 10,20 origin. 1x device scale factor. | |
112 // no overscan. flipped upside-down (180 degree) and 1.5 ui scale. | |
113 // "200x100#300x200|200x100%59.0|100x100%60" | |
114 // 200x100 window at 0,0 origin, with 3 possible resolutions, | |
115 // 300x200, 200x100 at 59 Hz, and 100x100 at 60 Hz. | |
116 static DisplayInfo CreateFromSpec(const std::string& spec); | |
117 | |
118 // Creates a DisplayInfo from string spec using given |id|. | |
119 static DisplayInfo CreateFromSpecWithID(const std::string& spec, int64_t id); | |
120 | |
121 // When this is set to true on the device whose internal display has | |
122 // 1.25 dsf, Chrome uses 1.0f as a default scale factor, and uses | |
123 // dsf 1.25 when UI scaling is set to 0.8f. | |
124 static void SetUse125DSFForUIScalingForTest(bool enable); | |
125 | |
126 DisplayInfo(); | |
127 DisplayInfo(int64_t id, const std::string& name, bool has_overscan); | |
128 DisplayInfo(const DisplayInfo& other); | |
129 ~DisplayInfo(); | |
130 | |
131 int64_t id() const { return id_; } | |
132 | |
133 // The name of the display. | |
134 const std::string& name() const { return name_; } | |
135 | |
136 // The path to the display device in the sysfs filesystem. | |
137 void set_sys_path(const base::FilePath& sys_path) { sys_path_ = sys_path; } | |
138 const base::FilePath& sys_path() const { return sys_path_; } | |
139 | |
140 // True if the display EDID has the overscan flag. This does not create the | |
141 // actual overscan automatically, but used in the message. | |
142 bool has_overscan() const { return has_overscan_; } | |
143 | |
144 void set_touch_support(display::Display::TouchSupport support) { | |
145 touch_support_ = support; | |
146 } | |
147 display::Display::TouchSupport touch_support() const { | |
148 return touch_support_; | |
149 } | |
150 | |
151 // Associate the input device with identifier |id| with this display. | |
152 void AddInputDevice(int id); | |
153 | |
154 // Clear the list of input devices associated with this display. | |
155 void ClearInputDevices(); | |
156 | |
157 // The input device ids that are associated with this display. | |
158 std::vector<int> input_devices() const { return input_devices_; } | |
159 | |
160 // Gets/Sets the device scale factor of the display. | |
161 float device_scale_factor() const { return device_scale_factor_; } | |
162 void set_device_scale_factor(float scale) { device_scale_factor_ = scale; } | |
163 | |
164 // Gets/Sets the device DPI of the display. | |
165 float device_dpi() const { return device_dpi_; } | |
166 void set_device_dpi(float dpi) { device_dpi_ = dpi; } | |
167 | |
168 // The native bounds for the display. The size of this can be | |
169 // different from the |size_in_pixel| when overscan insets are set | |
170 // and/or |configured_ui_scale_| is set. | |
171 const gfx::Rect& bounds_in_native() const { return bounds_in_native_; } | |
172 | |
173 // The size for the display in pixels. | |
174 const gfx::Size& size_in_pixel() const { return size_in_pixel_; } | |
175 | |
176 // The overscan insets for the display in DIP. | |
177 const gfx::Insets& overscan_insets_in_dip() const { | |
178 return overscan_insets_in_dip_; | |
179 } | |
180 | |
181 // Sets/gets configured ui scale. This can be different from the ui | |
182 // scale actually used when the scale is 2.0 and DSF is 2.0. | |
183 // (the effective ui scale is 1.0 in this case). | |
184 float configured_ui_scale() const { return configured_ui_scale_; } | |
185 void set_configured_ui_scale(float scale) { configured_ui_scale_ = scale; } | |
186 | |
187 // Sets the rotation for the given |source|. Setting a new rotation will also | |
188 // have it become the active rotation. | |
189 void SetRotation(display::Display::Rotation rotation, | |
190 display::Display::RotationSource source); | |
191 | |
192 // Returns the currently active rotation for this display. | |
193 display::Display::Rotation GetActiveRotation() const; | |
194 | |
195 // Returns the source which set the active rotation for this display. | |
196 display::Display::RotationSource active_rotation_source() const { | |
197 return active_rotation_source_; | |
198 } | |
199 | |
200 // Returns the rotation set by a given |source|. | |
201 display::Display::Rotation GetRotation( | |
202 display::Display::RotationSource source) const; | |
203 | |
204 // Returns the ui scale and device scale factor actually used to create | |
205 // display that chrome sees. This can be different from one obtained | |
206 // from dispaly or one specified by a user in following situation. | |
207 // 1) DSF is 2.0f and UI scale is 2.0f. (Returns 1.0f and 1.0f respectiely) | |
208 // 2) A user specified 0.8x on the device that has 1.25 DSF. 1.25 DSF device | |
209 // uses 1.0f DFS unless 0.8x UI scaling is specified. | |
210 float GetEffectiveDeviceScaleFactor() const; | |
211 | |
212 // Returns the ui scale used for the device scale factor. This | |
213 // return 1.0f if the ui scale and dsf are both set to 2.0. | |
214 float GetEffectiveUIScale() const; | |
215 | |
216 // Copy the display info except for fields that can be modified by a | |
217 // user (|rotation_| and |configured_ui_scale_|). |rotation_| and | |
218 // |configured_ui_scale_| are copied when the |another_info| isn't native one. | |
219 void Copy(const DisplayInfo& another_info); | |
220 | |
221 // Update the |bounds_in_native_| and |size_in_pixel_| using | |
222 // given |bounds_in_native|. | |
223 void SetBounds(const gfx::Rect& bounds_in_native); | |
224 | |
225 // Update the |bounds_in_native| according to the current overscan | |
226 // and rotation settings. | |
227 void UpdateDisplaySize(); | |
228 | |
229 // Sets/Clears the overscan insets. | |
230 void SetOverscanInsets(const gfx::Insets& insets_in_dip); | |
231 gfx::Insets GetOverscanInsetsInPixel() const; | |
232 | |
233 // Sets/Gets the flag to clear overscan insets. | |
234 bool clear_overscan_insets() const { return clear_overscan_insets_; } | |
235 void set_clear_overscan_insets(bool clear) { clear_overscan_insets_ = clear; } | |
236 | |
237 void set_native(bool native) { native_ = native; } | |
238 bool native() const { return native_; } | |
239 | |
240 const ManagedDisplayModeList& display_modes() const { return display_modes_; } | |
241 // Sets the display mode list. The mode list will be sorted for the | |
242 // display. | |
243 void SetManagedDisplayModes(const ManagedDisplayModeList& display_modes); | |
244 | |
245 // Returns the native mode size. If a native mode is not present, return an | |
246 // empty size. | |
247 gfx::Size GetNativeModeSize() const; | |
248 | |
249 ui::ColorCalibrationProfile color_profile() const { return color_profile_; } | |
250 | |
251 // Sets the color profile. It will ignore if the specified |profile| is not in | |
252 // |available_color_profiles_|. | |
253 void SetColorProfile(ui::ColorCalibrationProfile profile); | |
254 | |
255 // Returns true if |profile| is in |available_color_profiles_|. | |
256 bool IsColorProfileAvailable(ui::ColorCalibrationProfile profile) const; | |
257 | |
258 const std::vector<ui::ColorCalibrationProfile>& available_color_profiles() | |
259 const { | |
260 return available_color_profiles_; | |
261 } | |
262 | |
263 void set_available_color_profiles( | |
264 const std::vector<ui::ColorCalibrationProfile>& profiles) { | |
265 available_color_profiles_ = profiles; | |
266 } | |
267 | |
268 bool is_aspect_preserving_scaling() const { | |
269 return is_aspect_preserving_scaling_; | |
270 } | |
271 | |
272 void set_is_aspect_preserving_scaling(bool value) { | |
273 is_aspect_preserving_scaling_ = value; | |
274 } | |
275 | |
276 // Maximum cursor size in native pixels. | |
277 const gfx::Size& maximum_cursor_size() const { return maximum_cursor_size_; } | |
278 void set_maximum_cursor_size(const gfx::Size& size) { | |
279 maximum_cursor_size_ = size; | |
280 } | |
281 | |
282 // Returns a string representation of the DisplayInfo, excluding display | |
283 // modes. | |
284 std::string ToString() const; | |
285 | |
286 // Returns a string representation of the DisplayInfo, including display | |
287 // modes. | |
288 std::string ToFullString() const; | |
289 | |
290 private: | |
291 // Returns true if this display should use DSF=1.25 for UI scaling; i.e. | |
292 // SetUse125DSFForUIScaling(true) is called and this is the internal display. | |
293 bool Use125DSFForUIScaling() const; | |
294 | |
295 int64_t id_; | |
296 std::string name_; | |
297 base::FilePath sys_path_; | |
298 bool has_overscan_; | |
299 std::map<display::Display::RotationSource, display::Display::Rotation> | |
300 rotations_; | |
301 display::Display::RotationSource active_rotation_source_; | |
302 display::Display::TouchSupport touch_support_; | |
303 | |
304 // The set of input devices associated with this display. | |
305 std::vector<int> input_devices_; | |
306 | |
307 // This specifies the device's pixel density. (For example, a | |
308 // display whose DPI is higher than the threshold is considered to have | |
309 // device_scale_factor = 2.0 on Chrome OS). This is used by the | |
310 // grapics layer to choose and draw appropriate images and scale | |
311 // layers properly. | |
312 float device_scale_factor_; | |
313 gfx::Rect bounds_in_native_; | |
314 | |
315 // This specifies the device's DPI. | |
316 float device_dpi_; | |
317 | |
318 // The size of the display in use. The size can be different from the size | |
319 // of |bounds_in_native_| if the display has overscan insets and/or rotation. | |
320 gfx::Size size_in_pixel_; | |
321 gfx::Insets overscan_insets_in_dip_; | |
322 | |
323 // The pixel scale of the display. This is used to simply expand (or | |
324 // shrink) the desktop over the native display resolution (useful in | |
325 // HighDPI display). Note that this should not be confused with the | |
326 // device scale factor, which specifies the pixel density of the | |
327 // display. The actuall scale value to be used depends on the device | |
328 // scale factor. See |GetEffectiveScaleFactor()|. | |
329 float configured_ui_scale_; | |
330 | |
331 // True if this comes from native platform (DisplayChangeObserver). | |
332 bool native_; | |
333 | |
334 // True if the display is configured to preserve the aspect ratio. When the | |
335 // display is configured in a non-native mode, only parts of the display will | |
336 // be used such that the aspect ratio is preserved. | |
337 bool is_aspect_preserving_scaling_; | |
338 | |
339 // True if the displays' overscan inset should be cleared. This is | |
340 // to distinguish the empty overscan insets from native display info. | |
341 bool clear_overscan_insets_; | |
342 | |
343 // The list of modes supported by this display. | |
344 ManagedDisplayModeList display_modes_; | |
345 | |
346 // The current profile of the color calibration. | |
347 ui::ColorCalibrationProfile color_profile_; | |
348 | |
349 // The list of available variations for the color calibration. | |
350 std::vector<ui::ColorCalibrationProfile> available_color_profiles_; | |
351 | |
352 // Maximum cursor size. | |
353 gfx::Size maximum_cursor_size_; | |
354 | |
355 // If you add a new member, you need to update Copy(). | |
356 }; | |
357 | |
358 // Resets the synthesized display id for testing. This | |
359 // is necessary to avoid overflowing the output index. | |
360 ASH_EXPORT void ResetDisplayIdForTest(); | |
361 | |
362 } // namespace ash | |
363 | |
364 #endif // ASH_COMMON_DISPLAY_DISPLAY_INFO_H_ | |
OLD | NEW |