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