display.h revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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/base/ui_export.h" 11#include "ui/gfx/rect.h" 12 13namespace gfx { 14 15// Note: The screen and display currently uses pixel coordinate 16// system. For platforms that support DIP (density independent pixel), 17// |bounds()| and |work_area| will return values in DIP coordinate 18// system, not in backing pixels. 19class UI_EXPORT Display { 20 public: 21 // Screen Rotation in clock-wise degrees. 22 enum Rotation { 23 ROTATE_0 = 0, 24 ROTATE_90, 25 ROTATE_180, 26 ROTATE_270, 27 }; 28 29 // Creates a display with kInvalidDisplayID as default. 30 Display(); 31 explicit Display(int64 id); 32 Display(int64 id, const Rect& bounds); 33 ~Display(); 34 35 // Returns the forced device scale factor, which is given by 36 // "--force-device-scale-factor". 37 static float GetForcedDeviceScaleFactor(); 38 39 // Indicates if a device scale factor is being explicitly enforced from the 40 // command line via "--force-device-scale-factor". 41 static bool HasForceDeviceScaleFactor(); 42 43 // Returns 64-bit persistent ID for the specified manufacturer's ID and 44 // product_code, and the index of the output it is connected to. 45 // |output_index| is used to distinguish the displays of the same type. For 46 // example, swapping two identical display between two outputs will not be 47 // treated as swap. The 'serial number' field in EDID isn't used here because 48 // it is not guaranteed to have unique number and it may have the same fixed 49 // value (like 0). 50 static int64 GetID(uint16 manufacturer_id, 51 uint16 product_code, 52 uint8 output_index); 53 54 // Sets/Gets unique identifier associated with the display. 55 // -1 means invalid display and it doesn't not exit. 56 int64 id() const { return id_; } 57 void set_id(int64 id) { id_ = id; } 58 59 // Gets/Sets the display's bounds in gfx::Screen's coordinates. 60 const Rect& bounds() const { return bounds_; } 61 void set_bounds(const Rect& bounds) { bounds_ = bounds; } 62 63 // Gets/Sets the display's work area in gfx::Screen's coordinates. 64 const Rect& work_area() const { return 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. 71 float device_scale_factor() const { return device_scale_factor_; } 72 void set_device_scale_factor(float scale) { device_scale_factor_ = scale; } 73 74 Rotation rotation() const { return rotation_; } 75 void set_rotation(Rotation rotation) { rotation_ = rotation; } 76 77 // Utility functions that just return the size of display and 78 // work area. 79 const Size& size() const { return bounds_.size(); } 80 const Size& work_area_size() const { return work_area_.size(); } 81 82 // Returns the work area insets. 83 Insets GetWorkAreaInsets() const; 84 85 // Sets the device scale factor and display bounds in pixel. This 86 // updates the work are using the same insets between old bounds and 87 // work area. 88 void SetScaleAndBounds(float device_scale_factor, 89 const gfx::Rect& bounds_in_pixel); 90 91 // Sets the display's size. This updates the work area using the same insets 92 // between old bounds and work area. 93 void SetSize(const gfx::Size& size_in_pixel); 94 95 // Computes and updates the display's work are using 96 // |work_area_insets| and the bounds. 97 void UpdateWorkAreaFromInsets(const gfx::Insets& work_area_insets); 98 99 // Returns the display's size in pixel coordinates. 100 gfx::Size GetSizeInPixel() const; 101 102 // Returns a string representation of the display; 103 std::string ToString() const; 104 105 // True if the display contains valid display id. 106 bool is_valid() const { return id_ != kInvalidDisplayID; } 107 108 // True if the display corresponds to internal panel. 109 bool IsInternal() const; 110 111 // Gets/Sets an id of display corresponding to internal panel. 112 static int64 InternalDisplayId(); 113 static void SetInternalDisplayId(int64 internal_display_id); 114 115 static const int64 kInvalidDisplayID; 116 117 private: 118 int64 id_; 119 Rect bounds_; 120 Rect work_area_; 121 float device_scale_factor_; 122 Rotation rotation_; 123}; 124 125} // namespace gfx 126 127#endif // UI_GFX_DISPLAY_H_ 128