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 "ash/display/display_manager.h" | 5 #include "ash/display/display_manager.h" |
6 | 6 |
7 #include <algorithm> | |
7 #include <cmath> | 8 #include <cmath> |
8 #include <set> | 9 #include <set> |
9 #include <string> | 10 #include <string> |
10 #include <vector> | 11 #include <vector> |
11 | 12 |
12 #include "ash/ash_switches.h" | 13 #include "ash/ash_switches.h" |
13 #include "ash/display/display_layout_store.h" | 14 #include "ash/display/display_layout_store.h" |
14 #include "ash/display/screen_ash.h" | 15 #include "ash/display/screen_ash.h" |
15 #include "ash/screen_util.h" | 16 #include "ash/screen_util.h" |
16 #include "ash/shell.h" | 17 #include "ash/shell.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 return a.id() < b.id(); | 75 return a.id() < b.id(); |
75 } | 76 } |
76 }; | 77 }; |
77 | 78 |
78 struct DisplayInfoSortFunctor { | 79 struct DisplayInfoSortFunctor { |
79 bool operator()(const DisplayInfo& a, const DisplayInfo& b) { | 80 bool operator()(const DisplayInfo& a, const DisplayInfo& b) { |
80 return a.id() < b.id(); | 81 return a.id() < b.id(); |
81 } | 82 } |
82 }; | 83 }; |
83 | 84 |
84 struct DisplayModeMatcher { | |
85 DisplayModeMatcher(const gfx::Size& size) : size(size) {} | |
86 bool operator()(const DisplayMode& mode) { return mode.size == size; } | |
87 gfx::Size size; | |
88 }; | |
89 | |
90 struct ScaleComparator { | 85 struct ScaleComparator { |
91 explicit ScaleComparator(float s) : scale(s) {} | 86 explicit ScaleComparator(float s) : scale(s) {} |
92 | 87 |
93 bool operator()(float s) const { | 88 bool operator()(float s) const { |
94 const float kEpsilon = 0.0001f; | 89 const float kEpsilon = 0.0001f; |
95 return std::abs(scale - s) < kEpsilon; | 90 return std::abs(scale - s) < kEpsilon; |
96 } | 91 } |
97 float scale; | 92 float scale; |
98 }; | 93 }; |
99 | 94 |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
422 UpdateDisplays(display_info_list); | 417 UpdateDisplays(display_info_list); |
423 } | 418 } |
424 | 419 |
425 void DisplayManager::SetDisplayUIScale(int64 display_id, | 420 void DisplayManager::SetDisplayUIScale(int64 display_id, |
426 float ui_scale) { | 421 float ui_scale) { |
427 if (!IsDisplayUIScalingEnabled() || | 422 if (!IsDisplayUIScalingEnabled() || |
428 gfx::Display::InternalDisplayId() != display_id) { | 423 gfx::Display::InternalDisplayId() != display_id) { |
429 return; | 424 return; |
430 } | 425 } |
431 | 426 |
427 // TODO(mukai): merge this implementation into SetDisplayMode(). | |
432 DisplayInfoList display_info_list; | 428 DisplayInfoList display_info_list; |
433 for (DisplayList::const_iterator iter = displays_.begin(); | 429 for (DisplayList::const_iterator iter = displays_.begin(); |
434 iter != displays_.end(); ++iter) { | 430 iter != displays_.end(); ++iter) { |
435 DisplayInfo info = GetDisplayInfo(iter->id()); | 431 DisplayInfo info = GetDisplayInfo(iter->id()); |
436 if (info.id() == display_id) { | 432 if (info.id() == display_id) { |
437 if (info.configured_ui_scale() == ui_scale) | 433 if (info.configured_ui_scale() == ui_scale) |
438 return; | 434 return; |
439 std::vector<float> scales = GetScalesForDisplay(info); | 435 std::vector<float> scales = GetScalesForDisplay(info); |
440 ScaleComparator comparator(ui_scale); | 436 ScaleComparator comparator(ui_scale); |
441 if (std::find_if(scales.begin(), scales.end(), comparator) == | 437 if (std::find_if(scales.begin(), scales.end(), comparator) == |
442 scales.end()) { | 438 scales.end()) { |
443 return; | 439 return; |
444 } | 440 } |
445 info.set_configured_ui_scale(ui_scale); | 441 info.set_configured_ui_scale(ui_scale); |
446 } | 442 } |
447 display_info_list.push_back(info); | 443 display_info_list.push_back(info); |
448 } | 444 } |
449 AddMirrorDisplayInfoIfAny(&display_info_list); | 445 AddMirrorDisplayInfoIfAny(&display_info_list); |
450 UpdateDisplays(display_info_list); | 446 UpdateDisplays(display_info_list); |
451 } | 447 } |
452 | 448 |
453 void DisplayManager::SetDisplayResolution(int64 display_id, | 449 void DisplayManager::SetDisplayResolution(int64 display_id, |
454 const gfx::Size& resolution) { | 450 const gfx::Size& resolution) { |
455 DCHECK_NE(gfx::Display::InternalDisplayId(), display_id); | 451 DCHECK_NE(gfx::Display::InternalDisplayId(), display_id); |
456 if (gfx::Display::InternalDisplayId() == display_id) | 452 if (gfx::Display::InternalDisplayId() == display_id) |
457 return; | 453 return; |
458 const DisplayInfo& display_info = GetDisplayInfo(display_id); | 454 const DisplayInfo& display_info = GetDisplayInfo(display_id); |
459 const std::vector<DisplayMode>& modes = display_info.display_modes(); | 455 const std::vector<DisplayMode>& modes = display_info.display_modes(); |
460 DCHECK_NE(0u, modes.size()); | 456 DCHECK_NE(0u, modes.size()); |
457 DisplayMode target_mode; | |
458 target_mode.size = resolution; | |
461 std::vector<DisplayMode>::const_iterator iter = | 459 std::vector<DisplayMode>::const_iterator iter = |
462 std::find_if(modes.begin(), modes.end(), DisplayModeMatcher(resolution)); | 460 std::find(modes.begin(), modes.end(), target_mode); |
463 if (iter == modes.end()) { | 461 if (iter == modes.end()) { |
464 LOG(WARNING) << "Unsupported resolution was requested:" | 462 LOG(WARNING) << "Unsupported resolution was requested:" |
465 << resolution.ToString(); | 463 << resolution.ToString(); |
466 return; | 464 return; |
467 } | 465 } |
468 display_modes_[display_id] = *iter; | 466 display_modes_[display_id] = *iter; |
469 #if defined(OS_CHROMEOS) | 467 #if defined(OS_CHROMEOS) |
470 if (base::SysInfo::IsRunningOnChromeOS()) | 468 if (base::SysInfo::IsRunningOnChromeOS()) |
471 Shell::GetInstance()->display_configurator()->OnConfigurationChanged(); | 469 Shell::GetInstance()->display_configurator()->OnConfigurationChanged(); |
472 #endif | 470 #endif |
473 } | 471 } |
474 | 472 |
473 bool DisplayManager::SetDisplayMode(int64 display_id, | |
474 const DisplayMode& display_mode) { | |
475 if (IsInternalDisplayId(display_id)) { | |
476 SetDisplayUIScale(display_id, display_mode.ui_scale); | |
477 return false; | |
478 } | |
479 | |
480 DisplayInfoList display_info_list; | |
481 bool display_property_changed = false; | |
482 bool resolution_changed = false; | |
483 for (DisplayList::const_iterator iter = displays_.begin(); | |
484 iter != displays_.end(); ++iter) { | |
485 DisplayInfo info = GetDisplayInfo(iter->id()); | |
486 if (info.id() == display_id) { | |
487 const std::vector<DisplayMode>& modes = info.display_modes(); | |
488 std::vector<DisplayMode>::const_iterator iter = | |
489 std::find(modes.begin(), modes.end(), display_mode); | |
490 if (iter == modes.end()) { | |
491 LOG(WARNING) << "Unsupported resolution was requested:" | |
492 << display_mode.size.ToString(); | |
493 return false; | |
494 } | |
495 display_modes_[display_id] = *iter; | |
496 if (info.bounds_in_native().size() != display_mode.size) | |
497 resolution_changed = true; | |
498 if (info.device_scale_factor() != display_mode.device_scale_factor) { | |
499 info.set_device_scale_factor(display_mode.device_scale_factor); | |
500 display_property_changed = true; | |
501 } | |
502 } | |
503 display_info_list.push_back(info); | |
504 } | |
505 if (display_property_changed) { | |
506 AddMirrorDisplayInfoIfAny(&display_info_list); | |
507 UpdateDisplays(display_info_list); | |
508 } | |
509 #if defined(OS_CHROMEOS) | |
510 if (resolution_changed && base::SysInfo::IsRunningOnChromeOS()) | |
511 Shell::GetInstance()->display_configurator()->OnConfigurationChanged(); | |
512 #endif | |
513 return resolution_changed; | |
514 } | |
515 | |
475 void DisplayManager::RegisterDisplayProperty( | 516 void DisplayManager::RegisterDisplayProperty( |
476 int64 display_id, | 517 int64 display_id, |
477 gfx::Display::Rotation rotation, | 518 gfx::Display::Rotation rotation, |
478 float ui_scale, | 519 float ui_scale, |
479 const gfx::Insets* overscan_insets, | 520 const gfx::Insets* overscan_insets, |
480 const gfx::Size& resolution_in_pixels, | 521 const gfx::Size& resolution_in_pixels, |
481 ui::ColorCalibrationProfile color_profile) { | 522 ui::ColorCalibrationProfile color_profile) { |
482 if (display_info_.find(display_id) == display_info_.end()) | 523 if (display_info_.find(display_id) == display_info_.end()) |
483 display_info_[display_id] = DisplayInfo(display_id, std::string(), false); | 524 display_info_[display_id] = DisplayInfo(display_id, std::string(), false); |
484 | 525 |
485 display_info_[display_id].set_rotation(rotation); | 526 display_info_[display_id].set_rotation(rotation); |
486 display_info_[display_id].SetColorProfile(color_profile); | 527 display_info_[display_id].SetColorProfile(color_profile); |
487 // Just in case the preference file was corrupted. | 528 // Just in case the preference file was corrupted. |
488 if (0.5f <= ui_scale && ui_scale <= 2.0f) | 529 if (0.5f <= ui_scale && ui_scale <= 2.0f) |
489 display_info_[display_id].set_configured_ui_scale(ui_scale); | 530 display_info_[display_id].set_configured_ui_scale(ui_scale); |
490 if (overscan_insets) | 531 if (overscan_insets) |
491 display_info_[display_id].SetOverscanInsets(*overscan_insets); | 532 display_info_[display_id].SetOverscanInsets(*overscan_insets); |
492 if (!resolution_in_pixels.IsEmpty()) { | 533 if (!resolution_in_pixels.IsEmpty()) { |
493 // Default refresh rate, until OnNativeDisplaysChanged() updates us with the | 534 // Default refresh rate, until OnNativeDisplaysChanged() updates us with the |
494 // actual display info, is 60 Hz. | 535 // actual display info, is 60 Hz. |
495 display_modes_[display_id] = | 536 display_modes_[display_id] = |
496 DisplayMode(resolution_in_pixels, 60.0f, false, false); | 537 DisplayMode(resolution_in_pixels, 60.0f, false, false); |
497 } | 538 } |
498 } | 539 } |
499 | 540 |
541 DisplayMode DisplayManager::GetActiveModeForDisplayId(int64 display_id) const { | |
542 DisplayMode selected_mode; | |
543 if (GetSelectedModeForDisplayId(display_id, &selected_mode)) | |
544 return selected_mode; | |
545 | |
oshima
2014/07/31 02:16:52
can you add comment that this is looking for "defa
Jun Mukai
2014/07/31 04:57:52
Done.
| |
546 const DisplayInfo& info = GetDisplayInfo(display_id); | |
547 const std::vector<DisplayMode>& display_modes = info.display_modes(); | |
548 | |
549 if (IsInternalDisplayId(display_id)) { | |
550 for (size_t i = 0; i < display_modes.size(); ++i) { | |
551 if (info.configured_ui_scale() == display_modes[i].ui_scale) | |
oshima
2014/07/31 02:16:52
I believe the ui scale should always be 1.0f in th
Jun Mukai
2014/07/31 04:57:52
This case, ui scale comes from the pref store, can
oshima
2014/07/31 18:52:37
Discussed offline and understood the issue. please
Jun Mukai
2014/07/31 20:32:50
Done.
| |
552 return display_modes[i]; | |
553 } | |
554 } else { | |
555 for (size_t i = 0; i < display_modes.size(); ++i) { | |
556 if (display_modes[i].native) | |
557 return display_modes[i]; | |
558 } | |
559 } | |
560 return selected_mode; | |
561 } | |
562 | |
500 bool DisplayManager::GetSelectedModeForDisplayId(int64 id, | 563 bool DisplayManager::GetSelectedModeForDisplayId(int64 id, |
501 DisplayMode* mode_out) const { | 564 DisplayMode* mode_out) const { |
502 std::map<int64, DisplayMode>::const_iterator iter = display_modes_.find(id); | 565 std::map<int64, DisplayMode>::const_iterator iter = display_modes_.find(id); |
503 if (iter == display_modes_.end()) | 566 if (iter == display_modes_.end()) |
504 return false; | 567 return false; |
505 *mode_out = iter->second; | 568 *mode_out = iter->second; |
506 return true; | 569 return true; |
507 } | 570 } |
508 | 571 |
509 bool DisplayManager::IsDisplayUIScalingEnabled() const { | 572 bool DisplayManager::IsDisplayUIScalingEnabled() const { |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
590 // Mirrored monitors have the same origins. | 653 // Mirrored monitors have the same origins. |
591 gfx::Point origin = iter->bounds_in_native().origin(); | 654 gfx::Point origin = iter->bounds_in_native().origin(); |
592 if (origins.find(origin) != origins.end()) { | 655 if (origins.find(origin) != origins.end()) { |
593 InsertAndUpdateDisplayInfo(*iter); | 656 InsertAndUpdateDisplayInfo(*iter); |
594 mirrored_display_id_ = iter->id(); | 657 mirrored_display_id_ = iter->id(); |
595 } else { | 658 } else { |
596 origins.insert(origin); | 659 origins.insert(origin); |
597 new_display_info_list.push_back(*iter); | 660 new_display_info_list.push_back(*iter); |
598 } | 661 } |
599 | 662 |
600 const gfx::Size& resolution = iter->bounds_in_native().size(); | 663 DisplayMode new_mode; |
664 new_mode.size = iter->bounds_in_native().size(); | |
665 new_mode.device_scale_factor = iter->device_scale_factor(); | |
666 new_mode.ui_scale = iter->configured_ui_scale(); | |
601 const std::vector<DisplayMode>& display_modes = iter->display_modes(); | 667 const std::vector<DisplayMode>& display_modes = iter->display_modes(); |
602 // This is empty the displays are initialized from InitFromCommandLine. | 668 // This is empty the displays are initialized from InitFromCommandLine. |
603 if (!display_modes.size()) | 669 if (!display_modes.size()) |
604 continue; | 670 continue; |
605 std::vector<DisplayMode>::const_iterator display_modes_iter = | 671 std::vector<DisplayMode>::const_iterator display_modes_iter = |
606 std::find_if(display_modes.begin(), | 672 std::find(display_modes.begin(), display_modes.end(), new_mode); |
607 display_modes.end(), | |
608 DisplayModeMatcher(resolution)); | |
609 // Update the actual resolution selected as the resolution request may fail. | 673 // Update the actual resolution selected as the resolution request may fail. |
610 if (display_modes_iter == display_modes.end()) | 674 if (display_modes_iter == display_modes.end()) |
611 display_modes_.erase(iter->id()); | 675 display_modes_.erase(iter->id()); |
612 else if (display_modes_.find(iter->id()) != display_modes_.end()) | 676 else if (display_modes_.find(iter->id()) != display_modes_.end()) |
613 display_modes_[iter->id()] = *display_modes_iter; | 677 display_modes_[iter->id()] = *display_modes_iter; |
614 } | 678 } |
615 if (HasInternalDisplay() && | 679 if (HasInternalDisplay() && |
616 !internal_display_connected && | 680 !internal_display_connected && |
617 display_info_.find(gfx::Display::InternalDisplayId()) == | 681 display_info_.find(gfx::Display::InternalDisplayId()) == |
618 display_info_.end()) { | 682 display_info_.end()) { |
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1144 new_secondary_origin.Offset(-secondary_bounds.width(), offset); | 1208 new_secondary_origin.Offset(-secondary_bounds.width(), offset); |
1145 break; | 1209 break; |
1146 } | 1210 } |
1147 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); | 1211 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); |
1148 secondary_display->set_bounds( | 1212 secondary_display->set_bounds( |
1149 gfx::Rect(new_secondary_origin, secondary_bounds.size())); | 1213 gfx::Rect(new_secondary_origin, secondary_bounds.size())); |
1150 secondary_display->UpdateWorkAreaFromInsets(insets); | 1214 secondary_display->UpdateWorkAreaFromInsets(insets); |
1151 } | 1215 } |
1152 | 1216 |
1153 } // namespace ash | 1217 } // namespace ash |
OLD | NEW |