1 // Copyright (c) 2012 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 UI_GFX_DISPLAY_H_ 6 #define UI_GFX_DISPLAY_H_ 7 8 #include "base/basictypes.h" 9 #include "base/compiler_specific.h" 10 #include "ui/gfx/gfx_export.h" 11 #include "ui/gfx/rect.h" 12 13 namespace gfx { 14 15 // This class typically, but does not always, correspond to a physical display 16 // connected to the system. A fake Display may exist on a headless system, or a 17 // Display may correspond to a remote, virtual display. 18 // 19 // Note: The screen and display currently uses pixel coordinate 20 // system. For platforms that support DIP (density independent pixel), 21 // |bounds()| and |work_area| will return values in DIP coordinate 22 // system, not in backing pixels. 23 class GFX_EXPORT Display { 24 public: 25 // Screen Rotation in clock-wise degrees. 26 enum Rotation { 27 ROTATE_0 = 0, 28 ROTATE_90, 29 ROTATE_180, 30 ROTATE_270, 31 }; 32 33 // Touch support for the display. 34 enum TouchSupport { 35 TOUCH_SUPPORT_UNKNOWN, 36 TOUCH_SUPPORT_AVAILABLE, 37 TOUCH_SUPPORT_UNAVAILABLE, 38 }; 39 40 // Creates a display with kInvalidDisplayID as default. 41 Display(); 42 explicit Display(int64 id); 43 Display(int64 id, const Rect& bounds); 44 ~Display(); 45 46 // Returns the forced device scale factor, which is given by 47 // "--force-device-scale-factor". 48 static float GetForcedDeviceScaleFactor(); 49 50 // Indicates if a device scale factor is being explicitly enforced from the 51 // command line via "--force-device-scale-factor". 52 static bool HasForceDeviceScaleFactor(); 53 54 // Sets/Gets unique identifier associated with the display. 55 // -1 means invalid display and it doesn't not exit. id()56 int64 id() const { return id_; } set_id(int64 id)57 void set_id(int64 id) { id_ = id; } 58 59 // Gets/Sets the display's bounds in gfx::Screen's coordinates. bounds()60 const Rect& bounds() const { return bounds_; } set_bounds(const Rect & bounds)61 void set_bounds(const Rect& bounds) { bounds_ = bounds; } 62 63 // Gets/Sets the display's work area in gfx::Screen's coordinates. work_area()64 const Rect& work_area() const { return work_area_; } set_work_area(const Rect & work_area)65 void set_work_area(const Rect& work_area) { work_area_ = work_area; } 66 67 // Output device's pixel scale factor. This specifies how much the 68 // UI should be scaled when the actual output has more pixels than 69 // standard displays (which is around 100~120dpi.) The potential return 70 // values depend on each platforms. device_scale_factor()71 float device_scale_factor() const { return device_scale_factor_; } set_device_scale_factor(float scale)72 void set_device_scale_factor(float scale) { device_scale_factor_ = scale; } 73 rotation()74 Rotation rotation() const { return rotation_; } set_rotation(Rotation rotation)75 void set_rotation(Rotation rotation) { rotation_ = rotation; } 76 touch_support()77 TouchSupport touch_support() const { return touch_support_; } set_touch_support(TouchSupport support)78 void set_touch_support(TouchSupport support) { touch_support_ = support; } 79 80 // Utility functions that just return the size of display and 81 // work area. size()82 const Size& size() const { return bounds_.size(); } work_area_size()83 const Size& work_area_size() const { return work_area_.size(); } 84 85 // Returns the work area insets. 86 Insets GetWorkAreaInsets() const; 87 88 // Sets the device scale factor and display bounds in pixel. This 89 // updates the work are using the same insets between old bounds and 90 // work area. 91 void SetScaleAndBounds(float device_scale_factor, 92 const gfx::Rect& bounds_in_pixel); 93 94 // Sets the display's size. This updates the work area using the same insets 95 // between old bounds and work area. 96 void SetSize(const gfx::Size& size_in_pixel); 97 98 // Computes and updates the display's work are using 99 // |work_area_insets| and the bounds. 100 void UpdateWorkAreaFromInsets(const gfx::Insets& work_area_insets); 101 102 // Returns the display's size in pixel coordinates. 103 gfx::Size GetSizeInPixel() const; 104 105 // Returns a string representation of the display; 106 std::string ToString() const; 107 108 // True if the display contains valid display id. is_valid()109 bool is_valid() const { return id_ != kInvalidDisplayID; } 110 111 // True if the display corresponds to internal panel. 112 bool IsInternal() const; 113 114 // Gets/Sets an id of display corresponding to internal panel. 115 static int64 InternalDisplayId(); 116 static void SetInternalDisplayId(int64 internal_display_id); 117 118 static const int64 kInvalidDisplayID; 119 120 private: 121 int64 id_; 122 Rect bounds_; 123 Rect work_area_; 124 float device_scale_factor_; 125 Rotation rotation_; 126 TouchSupport touch_support_; 127 }; 128 129 } // namespace gfx 130 131 #endif // UI_GFX_DISPLAY_H_ 132