Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: ash/display/display_info.h

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

Powered by Google App Engine
This is Rietveld 408576698