display_info.h revision effb81e5f8246d0db0270817048dc992db66e9fb
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 <string>
9#include <vector>
10
11#include "ash/ash_export.h"
12#include "ui/display/display_constants.h"
13#include "ui/gfx/display.h"
14#include "ui/gfx/insets.h"
15#include "ui/gfx/rect.h"
16
17namespace ash {
18namespace internal {
19
20// A struct that represents the display's mode info.
21struct ASH_EXPORT DisplayMode {
22  DisplayMode();
23  DisplayMode(const gfx::Size& size,
24              float refresh_rate,
25              bool interlaced,
26              bool native);
27
28  gfx::Size size;      // Physical pixel size of the display.
29  float refresh_rate;  // Refresh rate of the display, in Hz.
30  bool interlaced;     // True if mode is interlaced.
31  bool native;         // True if mode is native mode of the display.
32};
33
34// DisplayInfo contains metadata for each display. This is used to
35// create |gfx::Display| as well as to maintain extra infomation
36// to manage displays in ash environment.
37// This class is intentionally made copiable.
38class ASH_EXPORT DisplayInfo {
39 public:
40  // Creates a DisplayInfo from string spec. 100+200-1440x800 creates display
41  // whose size is 1440x800 at the location (100, 200) in host coordinates.
42  // The format is
43  //
44  // [origin-]widthxheight[*device_scale_factor][#resolutions list]
45  //     [/<properties>][@ui-scale]
46  //
47  // where [] are optional:
48  // - |origin| is given in x+y- format.
49  // - |device_scale_factor| is either 2 or 1 (or empty).
50  // - properties can combination of 'o', which adds default overscan insets
51  //   (5%), and one rotation property where 'r' is 90 degree clock-wise
52  //   (to the 'r'ight) 'u' is 180 degrees ('u'pside-down) and 'l' is
53  //   270 degrees (to the 'l'eft).
54  // - ui-scale is floating value, e.g. @1.5 or @1.25.
55  // - |resolution list| is the list of size that is given in
56  //   |width x height [% refresh_rate]| separated by '|'.
57  //
58  // A couple of examples:
59  // "100x100"
60  //      100x100 window at 0,0 origin. 1x device scale factor. no overscan.
61  //      no rotation. 1.0 ui scale.
62  // "5+5-300x200*2"
63  //      300x200 window at 5,5 origin. 2x device scale factor.
64  //      no overscan, no rotation. 1.0 ui scale.
65  // "300x200/ol"
66  //      300x200 window at 0,0 origin. 1x device scale factor.
67  //      with 5% overscan. rotated to left (90 degree counter clockwise).
68  //      1.0 ui scale.
69  // "10+20-300x200/u@1.5"
70  //      300x200 window at 10,20 origin. 1x device scale factor.
71  //      no overscan. flipped upside-down (180 degree) and 1.5 ui scale.
72  // "200x100#300x200|200x100%59.0|100x100%60"
73  //      200x100 window at 0,0 origin, with 3 possible resolutions,
74  //      300x200, 200x100 at 59 Hz, and 100x100 at 60 Hz.
75  static DisplayInfo CreateFromSpec(const std::string& spec);
76
77  // Creates a DisplayInfo from string spec using given |id|.
78  static DisplayInfo CreateFromSpecWithID(const std::string& spec,
79                                          int64 id);
80
81  DisplayInfo();
82  DisplayInfo(int64 id, const std::string& name, bool has_overscan);
83  ~DisplayInfo();
84
85  int64 id() const { return id_; }
86
87  // The name of the display.
88  const std::string& name() const { return name_; }
89
90  // True if the display EDID has the overscan flag. This does not create the
91  // actual overscan automatically, but used in the message.
92  bool has_overscan() const { return has_overscan_; }
93
94  void set_rotation(gfx::Display::Rotation rotation) { rotation_ = rotation; }
95  gfx::Display::Rotation rotation() const { return rotation_; }
96
97  void set_touch_support(gfx::Display::TouchSupport support) {
98    touch_support_ = support;
99  }
100  gfx::Display::TouchSupport touch_support() const { return touch_support_; }
101
102  // Gets/Sets the device scale factor of the display.
103  float device_scale_factor() const { return device_scale_factor_; }
104  void set_device_scale_factor(float scale) { device_scale_factor_ = scale; }
105
106  // The native bounds for the display. The size of this can be
107  // different from the |size_in_pixel| when overscan insets are set
108  // and/or |configured_ui_scale_| is set.
109  const gfx::Rect& bounds_in_native() const {
110    return bounds_in_native_;
111  }
112
113  // The size for the display in pixels.
114  const gfx::Size& size_in_pixel() const { return size_in_pixel_; }
115
116  // The overscan insets for the display in DIP.
117  const gfx::Insets& overscan_insets_in_dip() const {
118    return overscan_insets_in_dip_;
119  }
120
121  // Sets/gets configured ui scale. This can be different from the ui
122  // scale actually used when the scale is 2.0 and DSF is 2.0.
123  // (the effective ui scale is 1.0 in this case).
124  float configured_ui_scale() const { return configured_ui_scale_; }
125  void set_configured_ui_scale(float scale) { configured_ui_scale_ = scale; }
126
127  // Returns the ui scale used for the device scale factor. This
128  // return 1.0f if the ui scale and dsf are both set to 2.0.
129  float GetEffectiveUIScale() const;
130
131  // Copy the display info except for fields that can be modified by a
132  // user (|rotation_| and |configured_ui_scale_|). |rotation_| and
133  // |configured_ui_scale_| are copied when the |another_info| isn't native one.
134  void Copy(const DisplayInfo& another_info);
135
136  // Update the |bounds_in_native_| and |size_in_pixel_| using
137  // given |bounds_in_native|.
138  void SetBounds(const gfx::Rect& bounds_in_native);
139
140  // Update the |bounds_in_native| according to the current overscan
141  // and rotation settings.
142  void UpdateDisplaySize();
143
144  // Sets/Clears the overscan insets.
145  void SetOverscanInsets(const gfx::Insets& insets_in_dip);
146  gfx::Insets GetOverscanInsetsInPixel() const;
147
148  void set_native(bool native) { native_ = native; }
149  bool native() const { return native_; }
150
151  const std::vector<DisplayMode>& display_modes() const {
152    return display_modes_;
153  }
154  void set_display_modes(std::vector<DisplayMode>& display_modes) {
155    display_modes_.swap(display_modes);
156  }
157
158  ui::ColorCalibrationProfile color_profile() const {
159    return color_profile_;
160  }
161
162  // Sets the color profile. It will ignore if the specified |profile| is not in
163  // |available_color_profiles_|.
164  void SetColorProfile(ui::ColorCalibrationProfile profile);
165
166  // Returns true if |profile| is in |available_color_profiles_|.
167  bool IsColorProfileAvailable(ui::ColorCalibrationProfile profile) const;
168
169  const std::vector<ui::ColorCalibrationProfile>&
170      available_color_profiles() const {
171    return available_color_profiles_;
172  }
173
174  void set_available_color_profiles(
175      const std::vector<ui::ColorCalibrationProfile>& profiles) {
176    available_color_profiles_ = profiles;
177  }
178
179  // Returns a string representation of the DisplayInfo, excluding display
180  // modes.
181  std::string ToString() const;
182
183  // Returns a string representation of the DisplayInfo, including display
184  // modes.
185  std::string ToFullString() const;
186
187 private:
188  int64 id_;
189  std::string name_;
190  bool has_overscan_;
191  gfx::Display::Rotation rotation_;
192  gfx::Display::TouchSupport touch_support_;
193
194  // This specifies the device's pixel density. (For example, a
195  // display whose DPI is higher than the threshold is considered to have
196  // device_scale_factor = 2.0 on Chrome OS).  This is used by the
197  // grapics layer to choose and draw appropriate images and scale
198  // layers properly.
199  float device_scale_factor_;
200  gfx::Rect bounds_in_native_;
201
202  // The size of the display in use. The size can be different from the size
203  // of |bounds_in_native_| if the display has overscan insets and/or rotation.
204  gfx::Size size_in_pixel_;
205  gfx::Insets overscan_insets_in_dip_;
206
207  // The pixel scale of the display. This is used to simply expand (or
208  // shrink) the desktop over the native display resolution (useful in
209  // HighDPI display).  Note that this should not be confused with the
210  // device scale factor, which specifies the pixel density of the
211  // display. The actuall scale value to be used depends on the device
212  // scale factor.  See |GetEffectiveScaleFactor()|.
213  float configured_ui_scale_;
214
215  // True if this comes from native platform (DisplayChangeObserver).
216  bool native_;
217
218  // The list of modes supported by this display.
219  std::vector<DisplayMode> display_modes_;
220
221  // The current profile of the color calibration.
222  ui::ColorCalibrationProfile color_profile_;
223
224  // The list of available variations for the color calibration.
225  std::vector<ui::ColorCalibrationProfile> available_color_profiles_;
226};
227
228}  // namespace internal
229}  // namespace ash
230
231#endif  //  ASH_DISPLAY_DISPLAY_INFO_H_
232