Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: ash/display/display_info.cc

Issue 1924703002: Rename gfx::Display/Screen to display::Display/Screen in ash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/display/display_info.h ('k') | ash/display/display_info_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 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 "ash/display/display_info.h" 5 #include "ash/display/display_info.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/string_split.h" 15 #include "base/strings/string_split.h"
16 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
17 #include "base/strings/stringprintf.h" 17 #include "base/strings/stringprintf.h"
18 #include "ui/gfx/display.h" 18 #include "ui/display/display.h"
19 #include "ui/gfx/geometry/size_conversions.h" 19 #include "ui/gfx/geometry/size_conversions.h"
20 #include "ui/gfx/geometry/size_f.h" 20 #include "ui/gfx/geometry/size_f.h"
21 21
22 #if defined(OS_WIN) 22 #if defined(OS_WIN)
23 #include "ui/aura/window_tree_host.h" 23 #include "ui/aura/window_tree_host.h"
24 #include "ui/display/win/dpi.h" 24 #include "ui/display/win/dpi.h"
25 #endif 25 #endif
26 26
27 namespace ash { 27 namespace ash {
28 namespace { 28 namespace {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 103
104 bool DisplayMode::IsEquivalent(const DisplayMode& other) const { 104 bool DisplayMode::IsEquivalent(const DisplayMode& other) const {
105 const float kEpsilon = 0.0001f; 105 const float kEpsilon = 0.0001f;
106 return size == other.size && 106 return size == other.size &&
107 std::abs(ui_scale - other.ui_scale) < kEpsilon && 107 std::abs(ui_scale - other.ui_scale) < kEpsilon &&
108 std::abs(device_scale_factor - other.device_scale_factor) < kEpsilon; 108 std::abs(device_scale_factor - other.device_scale_factor) < kEpsilon;
109 } 109 }
110 110
111 // satic 111 // satic
112 DisplayInfo DisplayInfo::CreateFromSpec(const std::string& spec) { 112 DisplayInfo DisplayInfo::CreateFromSpec(const std::string& spec) {
113 return CreateFromSpecWithID(spec, gfx::Display::kInvalidDisplayID); 113 return CreateFromSpecWithID(spec, display::Display::kInvalidDisplayID);
114 } 114 }
115 115
116 // static 116 // static
117 DisplayInfo DisplayInfo::CreateFromSpecWithID(const std::string& spec, 117 DisplayInfo DisplayInfo::CreateFromSpecWithID(const std::string& spec,
118 int64_t id) { 118 int64_t id) {
119 #if defined(OS_WIN) 119 #if defined(OS_WIN)
120 gfx::Rect bounds_in_native( 120 gfx::Rect bounds_in_native(
121 gfx::Size(GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN))); 121 gfx::Size(GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)));
122 #else 122 #else
123 // Default bounds for a display. 123 // Default bounds for a display.
(...skipping 11 matching lines...) Expand all
135 main_spec, "@", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); 135 main_spec, "@", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
136 if (parts.size() == 2) { 136 if (parts.size() == 2) {
137 double scale_in_double = 0; 137 double scale_in_double = 0;
138 if (base::StringToDouble(parts[1], &scale_in_double)) 138 if (base::StringToDouble(parts[1], &scale_in_double))
139 ui_scale = scale_in_double; 139 ui_scale = scale_in_double;
140 main_spec = parts[0]; 140 main_spec = parts[0];
141 } 141 }
142 142
143 parts = base::SplitString(main_spec, "/", base::KEEP_WHITESPACE, 143 parts = base::SplitString(main_spec, "/", base::KEEP_WHITESPACE,
144 base::SPLIT_WANT_NONEMPTY); 144 base::SPLIT_WANT_NONEMPTY);
145 gfx::Display::Rotation rotation(gfx::Display::ROTATE_0); 145 display::Display::Rotation rotation(display::Display::ROTATE_0);
146 bool has_overscan = false; 146 bool has_overscan = false;
147 if (!parts.empty()) { 147 if (!parts.empty()) {
148 main_spec = parts[0]; 148 main_spec = parts[0];
149 if (parts.size() >= 2) { 149 if (parts.size() >= 2) {
150 std::string options = parts[1]; 150 std::string options = parts[1];
151 for (size_t i = 0; i < options.size(); ++i) { 151 for (size_t i = 0; i < options.size(); ++i) {
152 char c = options[i]; 152 char c = options[i];
153 switch (c) { 153 switch (c) {
154 case 'o': 154 case 'o':
155 has_overscan = true; 155 has_overscan = true;
156 break; 156 break;
157 case 'r': // rotate 90 degrees to 'right'. 157 case 'r': // rotate 90 degrees to 'right'.
158 rotation = gfx::Display::ROTATE_90; 158 rotation = display::Display::ROTATE_90;
159 break; 159 break;
160 case 'u': // 180 degrees, 'u'pside-down. 160 case 'u': // 180 degrees, 'u'pside-down.
161 rotation = gfx::Display::ROTATE_180; 161 rotation = display::Display::ROTATE_180;
162 break; 162 break;
163 case 'l': // rotate 90 degrees to 'left'. 163 case 'l': // rotate 90 degrees to 'left'.
164 rotation = gfx::Display::ROTATE_270; 164 rotation = display::Display::ROTATE_270;
165 break; 165 break;
166 } 166 }
167 } 167 }
168 } 168 }
169 } 169 }
170 170
171 float device_scale_factor = 1.0f; 171 float device_scale_factor = 1.0f;
172 if (!GetDisplayBounds(main_spec, &bounds_in_native, &device_scale_factor)) { 172 if (!GetDisplayBounds(main_spec, &bounds_in_native, &device_scale_factor)) {
173 #if defined(OS_WIN) 173 #if defined(OS_WIN)
174 device_scale_factor = display::win::GetDPIScale(); 174 device_scale_factor = display::win::GetDPIScale();
(...skipping 27 matching lines...) Expand all
202 largest_area = mode.size.GetArea(); 202 largest_area = mode.size.GetArea();
203 highest_refresh_rate = mode.refresh_rate; 203 highest_refresh_rate = mode.refresh_rate;
204 native_mode = i; 204 native_mode = i;
205 } 205 }
206 display_modes.push_back(mode); 206 display_modes.push_back(mode);
207 } 207 }
208 } 208 }
209 display_modes[native_mode].native = true; 209 display_modes[native_mode].native = true;
210 } 210 }
211 211
212 if (id == gfx::Display::kInvalidDisplayID) 212 if (id == display::Display::kInvalidDisplayID)
213 id = synthesized_display_id++; 213 id = synthesized_display_id++;
214 DisplayInfo display_info( 214 DisplayInfo display_info(
215 id, base::StringPrintf("Display-%d", static_cast<int>(id)), has_overscan); 215 id, base::StringPrintf("Display-%d", static_cast<int>(id)), has_overscan);
216 display_info.set_device_scale_factor(device_scale_factor); 216 display_info.set_device_scale_factor(device_scale_factor);
217 display_info.SetRotation(rotation, gfx::Display::ROTATION_SOURCE_ACTIVE); 217 display_info.SetRotation(rotation, display::Display::ROTATION_SOURCE_ACTIVE);
218 display_info.set_configured_ui_scale(ui_scale); 218 display_info.set_configured_ui_scale(ui_scale);
219 display_info.SetBounds(bounds_in_native); 219 display_info.SetBounds(bounds_in_native);
220 display_info.SetDisplayModes(display_modes); 220 display_info.SetDisplayModes(display_modes);
221 221
222 // To test the overscan, it creates the default 5% overscan. 222 // To test the overscan, it creates the default 5% overscan.
223 if (has_overscan) { 223 if (has_overscan) {
224 int width = bounds_in_native.width() / device_scale_factor / 40; 224 int width = bounds_in_native.width() / device_scale_factor / 40;
225 int height = bounds_in_native.height() / device_scale_factor / 40; 225 int height = bounds_in_native.height() / device_scale_factor / 40;
226 display_info.SetOverscanInsets(gfx::Insets(height, width, height, width)); 226 display_info.SetOverscanInsets(gfx::Insets(height, width, height, width));
227 display_info.UpdateDisplaySize(); 227 display_info.UpdateDisplaySize();
228 } 228 }
229 229
230 DVLOG(1) << "DisplayInfoFromSpec info=" << display_info.ToString() 230 DVLOG(1) << "DisplayInfoFromSpec info=" << display_info.ToString()
231 << ", spec=" << spec; 231 << ", spec=" << spec;
232 return display_info; 232 return display_info;
233 } 233 }
234 234
235 // static 235 // static
236 void DisplayInfo::SetUse125DSFForUIScalingForTest(bool enable) { 236 void DisplayInfo::SetUse125DSFForUIScalingForTest(bool enable) {
237 use_125_dsf_for_ui_scaling = enable; 237 use_125_dsf_for_ui_scaling = enable;
238 } 238 }
239 239
240 DisplayInfo::DisplayInfo() 240 DisplayInfo::DisplayInfo()
241 : id_(gfx::Display::kInvalidDisplayID), 241 : id_(display::Display::kInvalidDisplayID),
242 has_overscan_(false), 242 has_overscan_(false),
243 active_rotation_source_(gfx::Display::ROTATION_SOURCE_UNKNOWN), 243 active_rotation_source_(display::Display::ROTATION_SOURCE_UNKNOWN),
244 touch_support_(gfx::Display::TOUCH_SUPPORT_UNKNOWN), 244 touch_support_(display::Display::TOUCH_SUPPORT_UNKNOWN),
245 device_scale_factor_(1.0f), 245 device_scale_factor_(1.0f),
246 device_dpi_(kDpi96), 246 device_dpi_(kDpi96),
247 overscan_insets_in_dip_(0, 0, 0, 0), 247 overscan_insets_in_dip_(0, 0, 0, 0),
248 configured_ui_scale_(1.0f), 248 configured_ui_scale_(1.0f),
249 native_(false), 249 native_(false),
250 is_aspect_preserving_scaling_(false), 250 is_aspect_preserving_scaling_(false),
251 clear_overscan_insets_(false), 251 clear_overscan_insets_(false),
252 color_profile_(ui::COLOR_PROFILE_STANDARD) {} 252 color_profile_(ui::COLOR_PROFILE_STANDARD) {}
253 253
254 DisplayInfo::DisplayInfo(int64_t id, const std::string& name, bool has_overscan) 254 DisplayInfo::DisplayInfo(int64_t id, const std::string& name, bool has_overscan)
255 : id_(id), 255 : id_(id),
256 name_(name), 256 name_(name),
257 has_overscan_(has_overscan), 257 has_overscan_(has_overscan),
258 active_rotation_source_(gfx::Display::ROTATION_SOURCE_UNKNOWN), 258 active_rotation_source_(display::Display::ROTATION_SOURCE_UNKNOWN),
259 touch_support_(gfx::Display::TOUCH_SUPPORT_UNKNOWN), 259 touch_support_(display::Display::TOUCH_SUPPORT_UNKNOWN),
260 device_scale_factor_(1.0f), 260 device_scale_factor_(1.0f),
261 device_dpi_(kDpi96), 261 device_dpi_(kDpi96),
262 overscan_insets_in_dip_(0, 0, 0, 0), 262 overscan_insets_in_dip_(0, 0, 0, 0),
263 configured_ui_scale_(1.0f), 263 configured_ui_scale_(1.0f),
264 native_(false), 264 native_(false),
265 is_aspect_preserving_scaling_(false), 265 is_aspect_preserving_scaling_(false),
266 clear_overscan_insets_(false), 266 clear_overscan_insets_(false),
267 color_profile_(ui::COLOR_PROFILE_STANDARD) {} 267 color_profile_(ui::COLOR_PROFILE_STANDARD) {}
268 268
269 DisplayInfo::DisplayInfo(const DisplayInfo& other) = default; 269 DisplayInfo::DisplayInfo(const DisplayInfo& other) = default;
270 270
271 DisplayInfo::~DisplayInfo() { 271 DisplayInfo::~DisplayInfo() {
272 } 272 }
273 273
274 void DisplayInfo::SetRotation(gfx::Display::Rotation rotation, 274 void DisplayInfo::SetRotation(display::Display::Rotation rotation,
275 gfx::Display::RotationSource source) { 275 display::Display::RotationSource source) {
276 rotations_[source] = rotation; 276 rotations_[source] = rotation;
277 rotations_[gfx::Display::ROTATION_SOURCE_ACTIVE] = rotation; 277 rotations_[display::Display::ROTATION_SOURCE_ACTIVE] = rotation;
278 active_rotation_source_ = source; 278 active_rotation_source_ = source;
279 } 279 }
280 280
281 gfx::Display::Rotation DisplayInfo::GetActiveRotation() const { 281 display::Display::Rotation DisplayInfo::GetActiveRotation() const {
282 return GetRotation(gfx::Display::ROTATION_SOURCE_ACTIVE); 282 return GetRotation(display::Display::ROTATION_SOURCE_ACTIVE);
283 } 283 }
284 284
285 gfx::Display::Rotation DisplayInfo::GetRotation( 285 display::Display::Rotation DisplayInfo::GetRotation(
286 gfx::Display::RotationSource source) const { 286 display::Display::RotationSource source) const {
287 if (rotations_.find(source) == rotations_.end()) 287 if (rotations_.find(source) == rotations_.end())
288 return gfx::Display::ROTATE_0; 288 return display::Display::ROTATE_0;
289 return rotations_.at(source); 289 return rotations_.at(source);
290 } 290 }
291 291
292 void DisplayInfo::Copy(const DisplayInfo& native_info) { 292 void DisplayInfo::Copy(const DisplayInfo& native_info) {
293 DCHECK(id_ == native_info.id_); 293 DCHECK(id_ == native_info.id_);
294 name_ = native_info.name_; 294 name_ = native_info.name_;
295 has_overscan_ = native_info.has_overscan_; 295 has_overscan_ = native_info.has_overscan_;
296 296
297 active_rotation_source_ = native_info.active_rotation_source_; 297 active_rotation_source_ = native_info.active_rotation_source_;
298 touch_support_ = native_info.touch_support_; 298 touch_support_ = native_info.touch_support_;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 void DisplayInfo::UpdateDisplaySize() { 349 void DisplayInfo::UpdateDisplaySize() {
350 size_in_pixel_ = bounds_in_native_.size(); 350 size_in_pixel_ = bounds_in_native_.size();
351 if (!overscan_insets_in_dip_.IsEmpty()) { 351 if (!overscan_insets_in_dip_.IsEmpty()) {
352 gfx::Insets insets_in_pixel = 352 gfx::Insets insets_in_pixel =
353 overscan_insets_in_dip_.Scale(device_scale_factor_); 353 overscan_insets_in_dip_.Scale(device_scale_factor_);
354 size_in_pixel_.Enlarge(-insets_in_pixel.width(), -insets_in_pixel.height()); 354 size_in_pixel_.Enlarge(-insets_in_pixel.width(), -insets_in_pixel.height());
355 } else { 355 } else {
356 overscan_insets_in_dip_.Set(0, 0, 0, 0); 356 overscan_insets_in_dip_.Set(0, 0, 0, 0);
357 } 357 }
358 358
359 if (GetActiveRotation() == gfx::Display::ROTATE_90 || 359 if (GetActiveRotation() == display::Display::ROTATE_90 ||
360 GetActiveRotation() == gfx::Display::ROTATE_270) { 360 GetActiveRotation() == display::Display::ROTATE_270) {
361 size_in_pixel_.SetSize(size_in_pixel_.height(), size_in_pixel_.width()); 361 size_in_pixel_.SetSize(size_in_pixel_.height(), size_in_pixel_.width());
362 } 362 }
363 gfx::SizeF size_f(size_in_pixel_); 363 gfx::SizeF size_f(size_in_pixel_);
364 size_f.Scale(GetEffectiveUIScale()); 364 size_f.Scale(GetEffectiveUIScale());
365 size_in_pixel_ = gfx::ToFlooredSize(size_f); 365 size_in_pixel_ = gfx::ToFlooredSize(size_f);
366 } 366 }
367 367
368 void DisplayInfo::SetOverscanInsets(const gfx::Insets& insets_in_dip) { 368 void DisplayInfo::SetOverscanInsets(const gfx::Insets& insets_in_dip) {
369 overscan_insets_in_dip_ = insets_in_dip; 369 overscan_insets_in_dip_ = insets_in_dip;
370 } 370 }
371 371
372 gfx::Insets DisplayInfo::GetOverscanInsetsInPixel() const { 372 gfx::Insets DisplayInfo::GetOverscanInsetsInPixel() const {
373 return overscan_insets_in_dip_.Scale(device_scale_factor_); 373 return overscan_insets_in_dip_.Scale(device_scale_factor_);
374 } 374 }
375 375
376 void DisplayInfo::SetDisplayModes( 376 void DisplayInfo::SetDisplayModes(
377 const std::vector<DisplayMode>& display_modes) { 377 const std::vector<DisplayMode>& display_modes) {
378 display_modes_ = display_modes; 378 display_modes_ = display_modes;
379 std::sort(display_modes_.begin(), display_modes_.end(), 379 std::sort(display_modes_.begin(), display_modes_.end(),
380 DisplayModeSorter(gfx::Display::IsInternalDisplayId(id_))); 380 DisplayModeSorter(display::Display::IsInternalDisplayId(id_)));
381 } 381 }
382 382
383 gfx::Size DisplayInfo::GetNativeModeSize() const { 383 gfx::Size DisplayInfo::GetNativeModeSize() const {
384 for (size_t i = 0; i < display_modes_.size(); ++i) { 384 for (size_t i = 0; i < display_modes_.size(); ++i) {
385 if (display_modes_[i].native) 385 if (display_modes_[i].native)
386 return display_modes_[i].size; 386 return display_modes_[i].size;
387 } 387 }
388 388
389 return gfx::Size(); 389 return gfx::Size();
390 } 390 }
391 391
392 std::string DisplayInfo::ToString() const { 392 std::string DisplayInfo::ToString() const {
393 int rotation_degree = static_cast<int>(GetActiveRotation()) * 90; 393 int rotation_degree = static_cast<int>(GetActiveRotation()) * 90;
394 std::string devices_str; 394 std::string devices_str;
395 395
396 for (size_t i = 0; i < input_devices_.size(); ++i) { 396 for (size_t i = 0; i < input_devices_.size(); ++i) {
397 devices_str += base::IntToString(input_devices_[i]); 397 devices_str += base::IntToString(input_devices_[i]);
398 if (i != input_devices_.size() - 1) 398 if (i != input_devices_.size() - 1)
399 devices_str += ", "; 399 devices_str += ", ";
400 } 400 }
401 401
402 std::string result = base::StringPrintf( 402 std::string result = base::StringPrintf(
403 "DisplayInfo[%lld] native bounds=%s, size=%s, scale=%f, " 403 "DisplayInfo[%lld] native bounds=%s, size=%s, scale=%f, "
404 "overscan=%s, rotation=%d, ui-scale=%f, touchscreen=%s, " 404 "overscan=%s, rotation=%d, ui-scale=%f, touchscreen=%s, "
405 "input_devices=[%s]", 405 "input_devices=[%s]",
406 static_cast<long long int>(id_), bounds_in_native_.ToString().c_str(), 406 static_cast<long long int>(id_), bounds_in_native_.ToString().c_str(),
407 size_in_pixel_.ToString().c_str(), device_scale_factor_, 407 size_in_pixel_.ToString().c_str(), device_scale_factor_,
408 overscan_insets_in_dip_.ToString().c_str(), rotation_degree, 408 overscan_insets_in_dip_.ToString().c_str(), rotation_degree,
409 configured_ui_scale_, 409 configured_ui_scale_,
410 touch_support_ == gfx::Display::TOUCH_SUPPORT_AVAILABLE 410 touch_support_ == display::Display::TOUCH_SUPPORT_AVAILABLE
411 ? "yes" 411 ? "yes"
412 : touch_support_ == gfx::Display::TOUCH_SUPPORT_UNAVAILABLE 412 : touch_support_ == display::Display::TOUCH_SUPPORT_UNAVAILABLE
413 ? "no" 413 ? "no"
414 : "unknown", 414 : "unknown",
415 devices_str.c_str()); 415 devices_str.c_str());
416 416
417 return result; 417 return result;
418 } 418 }
419 419
420 std::string DisplayInfo::ToFullString() const { 420 std::string DisplayInfo::ToFullString() const {
421 std::string display_modes_str; 421 std::string display_modes_str;
422 std::vector<DisplayMode>::const_iterator iter = display_modes_.begin(); 422 std::vector<DisplayMode>::const_iterator iter = display_modes_.begin();
(...skipping 17 matching lines...) Expand all
440 } 440 }
441 441
442 bool DisplayInfo::IsColorProfileAvailable( 442 bool DisplayInfo::IsColorProfileAvailable(
443 ui::ColorCalibrationProfile profile) const { 443 ui::ColorCalibrationProfile profile) const {
444 return std::find(available_color_profiles_.begin(), 444 return std::find(available_color_profiles_.begin(),
445 available_color_profiles_.end(), 445 available_color_profiles_.end(),
446 profile) != available_color_profiles_.end(); 446 profile) != available_color_profiles_.end();
447 } 447 }
448 448
449 bool DisplayInfo::Use125DSFForUIScaling() const { 449 bool DisplayInfo::Use125DSFForUIScaling() const {
450 return use_125_dsf_for_ui_scaling && gfx::Display::IsInternalDisplayId(id_); 450 return use_125_dsf_for_ui_scaling &&
451 display::Display::IsInternalDisplayId(id_);
451 } 452 }
452 453
453 void DisplayInfo::AddInputDevice(int id) { 454 void DisplayInfo::AddInputDevice(int id) {
454 input_devices_.push_back(id); 455 input_devices_.push_back(id);
455 } 456 }
456 457
457 void DisplayInfo::ClearInputDevices() { 458 void DisplayInfo::ClearInputDevices() {
458 input_devices_.clear(); 459 input_devices_.clear();
459 } 460 }
460 461
461 void ResetDisplayIdForTest() { 462 void ResetDisplayIdForTest() {
462 synthesized_display_id = kSynthesizedDisplayIdStart; 463 synthesized_display_id = kSynthesizedDisplayIdStart;
463 } 464 }
464 465
465 } // namespace ash 466 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/display_info.h ('k') | ash/display/display_info_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698