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