display_info.h revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
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
10#include "ash/ash_export.h"
11#include "base/gtest_prod_util.h"
12#include "ui/gfx/display.h"
13#include "ui/gfx/insets.h"
14#include "ui/gfx/rect.h"
15
16namespace ash {
17namespace internal {
18
19// DisplayInfo contains metadata for each display. This is used to
20// create |gfx::Display| as well as to maintain extra infomation
21// to manage displays in ash environment.
22// This class is intentionally made copiable.
23class ASH_EXPORT DisplayInfo {
24 public:
25  // Creates a DisplayInfo from string spec. 100+200-1440x800 creates display
26  // whose size is 1440x800 at the location (100, 200) in host coordinates.
27  // The format is
28  //
29  // [origin-]widthxheight[*device_scale_factor][/<properties>][@ui-scale]
30  //
31  // where [] are optional:
32  // - |origin| is given in x+y- format.
33  // - |device_scale_factor| is either 2 or 1 (or empty).
34  // - properties can combination of 'o', which adds default overscan insets
35  //   (5%), and one rotation property where 'r' is 90 degree clock-wise
36  //   (to the 'r'ight) 'u' is 180 degrees ('u'pside-down) and 'l' is
37  //   270 degrees (to the 'l'eft).
38  // - ui-scale is floating value, e.g. @1.5 or @1.25.
39  //
40  // A couple of examples:
41  // "100x100"
42  //      100x100 window at 0,0 origin. 1x device scale factor. no overscan.
43  //      no rotation. 1.0 ui scale.
44  // "5+5-300x200*2"
45  //      300x200 window at 5,5 origin. 2x device scale factor.
46  //      no overscan, no rotation. 1.0 ui scale.
47  // "300x200/ol"
48  //      300x200 window at 0,0 origin. 1x device scale factor.
49  //      with 5% overscan. rotated to left (90 degree counter clockwise).
50  //      1.0 ui scale.
51  // "10+20-300x200/u@1.5"
52  //      300x200 window at 10,20 origin. 1x device scale factor.
53  //      no overscan. flipped upside-down (180 degree) and 1.5 ui scale.
54  static DisplayInfo CreateFromSpec(const std::string& spec);
55
56  // Creates a DisplayInfo from string spec using given |id|.
57  static DisplayInfo CreateFromSpecWithID(const std::string& spec,
58                                          int64 id);
59
60  DisplayInfo();
61  DisplayInfo(int64 id, const std::string& name, bool has_overscan);
62  ~DisplayInfo();
63
64  int64 id() const { return id_; }
65
66  // The name of the display.
67  const std::string& name() const { return name_; }
68
69  // True if the display EDID has the overscan flag. This does not create the
70  // actual overscan automatically, but used in the message.
71  bool has_overscan() const { return has_overscan_; }
72
73  void set_rotation(gfx::Display::Rotation rotation) { rotation_ = rotation; }
74  gfx::Display::Rotation rotation() const { return rotation_; }
75
76  // Gets/Sets the device scale factor of the display.
77  float device_scale_factor() const { return device_scale_factor_; }
78  void set_device_scale_factor(float scale) { device_scale_factor_ = scale; }
79
80  // The bounds_in_pixel for the display. The size of this can be different from
81  // the |size_in_pixel| in case of overscan insets.
82  const gfx::Rect bounds_in_pixel() const {
83    return bounds_in_pixel_;
84  }
85
86  // The size for the display in pixels.
87  const gfx::Size& size_in_pixel() const { return size_in_pixel_; }
88
89  // The overscan insets for the display in DIP.
90  const gfx::Insets& overscan_insets_in_dip() const {
91    return overscan_insets_in_dip_;
92  }
93
94  float ui_scale() const { return ui_scale_; }
95  void set_ui_scale(float scale) { ui_scale_ = scale; }
96
97  // Copy the display info except for fields that can be modified by a user
98  // (|rotation_| and |ui_scale_|). |rotation_| and |ui_scale_| are copied
99  // when the |another_info| isn't native one.
100  void Copy(const DisplayInfo& another_info);
101
102  // Update the |bounds_in_pixel_| and |size_in_pixel_| using
103  // given |bounds_in_pixel|.
104  void SetBounds(const gfx::Rect& bounds_in_pixel);
105
106  // Update the |bounds_in_pixel| according to the current overscan
107  // and rotation settings.
108  void UpdateDisplaySize();
109
110  // Sets/Clears the overscan insets.
111  void SetOverscanInsets(const gfx::Insets& insets_in_dip);
112  gfx::Insets GetOverscanInsetsInPixel() const;
113
114  void set_native(bool native) { native_ = native; }
115  bool native() const { return native_; }
116
117  // Returns a string representation of the DisplayInfo;
118  std::string ToString() const;
119
120 private:
121  int64 id_;
122  std::string name_;
123  bool has_overscan_;
124  gfx::Display::Rotation rotation_;
125  float device_scale_factor_;
126  gfx::Rect bounds_in_pixel_;
127  // The size of the display in use. The size can be different from the size
128  // of |bounds_in_pixel_| if the display has overscan insets and/or rotation.
129  gfx::Size size_in_pixel_;
130  gfx::Insets overscan_insets_in_dip_;
131
132  // UI scale of the display.
133  float ui_scale_;
134
135  // True if this comes from native platform (DisplayChangeObserverX11).
136  bool native_;
137};
138
139}  // namespace internal
140}  // namespace ash
141
142#endif  //  ASH_DISPLAY_DISPLAY_INFO_H_
143