OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gfx/display.h" | 5 #include "ui/gfx/display.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> |
8 | 9 |
9 #include "base/command_line.h" | 10 #include "base/command_line.h" |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
13 #include "build/build_config.h" | 14 #include "build/build_config.h" |
14 #include "ui/gfx/geometry/insets.h" | 15 #include "ui/gfx/geometry/insets.h" |
15 #include "ui/gfx/geometry/point_conversions.h" | 16 #include "ui/gfx/geometry/point_conversions.h" |
16 #include "ui/gfx/geometry/point_f.h" | 17 #include "ui/gfx/geometry/point_f.h" |
17 #include "ui/gfx/geometry/size_conversions.h" | 18 #include "ui/gfx/geometry/size_conversions.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 // static | 71 // static |
71 void Display::ResetForceDeviceScaleFactorForTesting() { | 72 void Display::ResetForceDeviceScaleFactorForTesting() { |
72 g_has_forced_device_scale_factor = -1; | 73 g_has_forced_device_scale_factor = -1; |
73 g_forced_device_scale_factor = -1.0; | 74 g_forced_device_scale_factor = -1.0; |
74 } | 75 } |
75 | 76 |
76 Display::Display() | 77 Display::Display() |
77 : id_(kInvalidDisplayID), | 78 : id_(kInvalidDisplayID), |
78 device_scale_factor_(GetForcedDeviceScaleFactor()), | 79 device_scale_factor_(GetForcedDeviceScaleFactor()), |
79 rotation_(ROTATE_0), | 80 rotation_(ROTATE_0), |
80 touch_support_(TOUCH_SUPPORT_UNKNOWN) { | 81 touch_support_(TOUCH_SUPPORT_UNKNOWN), |
81 } | 82 physical_width_mm_(0), |
| 83 physical_height_mm_(0) {} |
82 | 84 |
83 Display::Display(int64_t id) | 85 Display::Display(int64_t id) |
84 : id_(id), | 86 : id_(id), |
85 device_scale_factor_(GetForcedDeviceScaleFactor()), | 87 device_scale_factor_(GetForcedDeviceScaleFactor()), |
86 rotation_(ROTATE_0), | 88 rotation_(ROTATE_0), |
87 touch_support_(TOUCH_SUPPORT_UNKNOWN) {} | 89 touch_support_(TOUCH_SUPPORT_UNKNOWN), |
| 90 physical_width_mm_(0), |
| 91 physical_height_mm_(0) {} |
88 | 92 |
89 Display::Display(int64_t id, const gfx::Rect& bounds) | 93 Display::Display(int64_t id, const gfx::Rect& bounds) |
90 : id_(id), | 94 : id_(id), |
91 bounds_(bounds), | 95 bounds_(bounds), |
92 work_area_(bounds), | 96 work_area_(bounds), |
93 device_scale_factor_(GetForcedDeviceScaleFactor()), | 97 device_scale_factor_(GetForcedDeviceScaleFactor()), |
94 rotation_(ROTATE_0), | 98 rotation_(ROTATE_0), |
95 touch_support_(TOUCH_SUPPORT_UNKNOWN) { | 99 touch_support_(TOUCH_SUPPORT_UNKNOWN), |
| 100 physical_width_mm_(0), |
| 101 physical_height_mm_(0) { |
96 #if defined(USE_AURA) | 102 #if defined(USE_AURA) |
97 SetScaleAndBounds(device_scale_factor_, bounds); | 103 SetScaleAndBounds(device_scale_factor_, bounds); |
98 #endif | 104 #endif |
99 } | 105 } |
100 | 106 |
101 Display::~Display() { | 107 Display::~Display() { |
102 } | 108 } |
103 | 109 |
104 int Display::RotationAsDegree() const { | 110 int Display::RotationAsDegree() const { |
105 switch (rotation_) { | 111 switch (rotation_) { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 bounds_.ToString().c_str(), | 194 bounds_.ToString().c_str(), |
189 work_area_.ToString().c_str(), | 195 work_area_.ToString().c_str(), |
190 device_scale_factor_, | 196 device_scale_factor_, |
191 IsInternal() ? "internal" : "external"); | 197 IsInternal() ? "internal" : "external"); |
192 } | 198 } |
193 | 199 |
194 bool Display::IsInternal() const { | 200 bool Display::IsInternal() const { |
195 return is_valid() && (id_ == internal_display_id_); | 201 return is_valid() && (id_ == internal_display_id_); |
196 } | 202 } |
197 | 203 |
| 204 bool Display::IsPhysicalSizeAvailable() const { |
| 205 return physical_width_mm_ != 0 && physical_height_mm_ != 0; |
| 206 } |
| 207 |
| 208 gfx::Size Display::GetPhysicalSizeMm() const { |
| 209 DCHECK(IsPhysicalSizeAvailable()); |
| 210 return gfx::Size(physical_width_mm_, physical_height_mm_); |
| 211 } |
| 212 |
| 213 void Display::SetPhysicalSize(int width_mm, int height_mm) { |
| 214 physical_width_mm_ = width_mm; |
| 215 physical_height_mm_ = height_mm; |
| 216 } |
| 217 |
198 // static | 218 // static |
199 int64_t Display::InternalDisplayId() { | 219 int64_t Display::InternalDisplayId() { |
200 DCHECK_NE(kInvalidDisplayID, internal_display_id_); | 220 DCHECK_NE(kInvalidDisplayID, internal_display_id_); |
201 return internal_display_id_; | 221 return internal_display_id_; |
202 } | 222 } |
203 | 223 |
204 // static | 224 // static |
205 void Display::SetInternalDisplayId(int64_t internal_display_id) { | 225 void Display::SetInternalDisplayId(int64_t internal_display_id) { |
206 internal_display_id_ = internal_display_id; | 226 internal_display_id_ = internal_display_id; |
207 } | 227 } |
208 | 228 |
209 // static | 229 // static |
210 bool Display::IsInternalDisplayId(int64_t display_id) { | 230 bool Display::IsInternalDisplayId(int64_t display_id) { |
211 DCHECK_NE(kInvalidDisplayID, display_id); | 231 DCHECK_NE(kInvalidDisplayID, display_id); |
212 return HasInternalDisplay() && internal_display_id_ == display_id; | 232 return HasInternalDisplay() && internal_display_id_ == display_id; |
213 } | 233 } |
214 | 234 |
215 // static | 235 // static |
216 bool Display::HasInternalDisplay() { | 236 bool Display::HasInternalDisplay() { |
217 return internal_display_id_ != kInvalidDisplayID; | 237 return internal_display_id_ != kInvalidDisplayID; |
218 } | 238 } |
219 | 239 |
220 } // namespace gfx | 240 } // namespace gfx |
OLD | NEW |