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 <cmath> | 7 #include <cmath> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 return a.id() < b.id(); | 71 return a.id() < b.id(); |
72 } | 72 } |
73 }; | 73 }; |
74 | 74 |
75 struct DisplayInfoSortFunctor { | 75 struct DisplayInfoSortFunctor { |
76 bool operator()(const DisplayInfo& a, const DisplayInfo& b) { | 76 bool operator()(const DisplayInfo& a, const DisplayInfo& b) { |
77 return a.id() < b.id(); | 77 return a.id() < b.id(); |
78 } | 78 } |
79 }; | 79 }; |
80 | 80 |
81 struct ResolutionMatcher { | 81 struct DisplayModeMatcher { |
82 explicit ResolutionMatcher(const gfx::Size& size) : size(size) {} | 82 DisplayModeMatcher(const gfx::Size& size) : size(size) {} |
83 bool operator()(const Resolution& resolution) { | 83 bool operator()(const DisplayMode& mode) { return mode.size == size; } |
84 return resolution.size == size; | |
85 } | |
86 gfx::Size size; | 84 gfx::Size size; |
87 }; | 85 }; |
88 | 86 |
89 struct ScaleComparator { | 87 struct ScaleComparator { |
90 explicit ScaleComparator(float s) : scale(s) {} | 88 explicit ScaleComparator(float s) : scale(s) {} |
91 | 89 |
92 bool operator()(float s) const { | 90 bool operator()(float s) const { |
93 const float kEpsilon = 0.0001f; | 91 const float kEpsilon = 0.0001f; |
94 return std::abs(scale - s) < kEpsilon; | 92 return std::abs(scale - s) < kEpsilon; |
95 } | 93 } |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
439 AddMirrorDisplayInfoIfAny(&display_info_list); | 437 AddMirrorDisplayInfoIfAny(&display_info_list); |
440 UpdateDisplays(display_info_list); | 438 UpdateDisplays(display_info_list); |
441 } | 439 } |
442 | 440 |
443 void DisplayManager::SetDisplayResolution(int64 display_id, | 441 void DisplayManager::SetDisplayResolution(int64 display_id, |
444 const gfx::Size& resolution) { | 442 const gfx::Size& resolution) { |
445 DCHECK_NE(gfx::Display::InternalDisplayId(), display_id); | 443 DCHECK_NE(gfx::Display::InternalDisplayId(), display_id); |
446 if (gfx::Display::InternalDisplayId() == display_id) | 444 if (gfx::Display::InternalDisplayId() == display_id) |
447 return; | 445 return; |
448 const DisplayInfo& display_info = GetDisplayInfo(display_id); | 446 const DisplayInfo& display_info = GetDisplayInfo(display_id); |
449 const std::vector<Resolution>& resolutions = display_info.resolutions(); | 447 const std::vector<DisplayMode>& modes = display_info.display_modes(); |
450 DCHECK_NE(0u, resolutions.size()); | 448 DCHECK_NE(0u, modes.size()); |
451 std::vector<Resolution>::const_iterator iter = | 449 std::vector<DisplayMode>::const_iterator iter = |
452 std::find_if(resolutions.begin(), | 450 std::find_if(modes.begin(), modes.end(), DisplayModeMatcher(resolution)); |
453 resolutions.end(), | 451 if (iter == modes.end()) { |
454 ResolutionMatcher(resolution)); | |
455 if (iter == resolutions.end()) { | |
456 LOG(WARNING) << "Unsupported resolution was requested:" | 452 LOG(WARNING) << "Unsupported resolution was requested:" |
457 << resolution.ToString(); | 453 << resolution.ToString(); |
458 return; | 454 return; |
459 } else if (iter == resolutions.begin()) { | |
460 // The best resolution was set, so forget it. | |
461 resolutions_.erase(display_id); | |
462 } else { | |
463 resolutions_[display_id] = resolution; | |
464 } | 455 } |
456 display_modes_[display_id] = *iter; | |
465 #if defined(OS_CHROMEOS) && defined(USE_X11) | 457 #if defined(OS_CHROMEOS) && defined(USE_X11) |
466 if (base::SysInfo::IsRunningOnChromeOS()) | 458 if (base::SysInfo::IsRunningOnChromeOS()) |
467 Shell::GetInstance()->output_configurator()->ScheduleConfigureOutputs(); | 459 Shell::GetInstance()->output_configurator()->ScheduleConfigureOutputs(); |
468 #endif | 460 #endif |
469 } | 461 } |
470 | 462 |
471 void DisplayManager::RegisterDisplayProperty( | 463 void DisplayManager::RegisterDisplayProperty( |
472 int64 display_id, | 464 int64 display_id, |
473 gfx::Display::Rotation rotation, | 465 gfx::Display::Rotation rotation, |
474 float ui_scale, | 466 float ui_scale, |
475 const gfx::Insets* overscan_insets, | 467 const gfx::Insets* overscan_insets, |
476 const gfx::Size& resolution_in_pixels) { | 468 const gfx::Size& resolution_in_pixels) { |
477 if (display_info_.find(display_id) == display_info_.end()) | 469 if (display_info_.find(display_id) == display_info_.end()) |
478 display_info_[display_id] = DisplayInfo(display_id, std::string(), false); | 470 display_info_[display_id] = DisplayInfo(display_id, std::string(), false); |
479 | 471 |
480 display_info_[display_id].set_rotation(rotation); | 472 display_info_[display_id].set_rotation(rotation); |
481 // Just in case the preference file was corrupted. | 473 // Just in case the preference file was corrupted. |
482 if (0.5f <= ui_scale && ui_scale <= 2.0f) | 474 if (0.5f <= ui_scale && ui_scale <= 2.0f) |
483 display_info_[display_id].set_configured_ui_scale(ui_scale); | 475 display_info_[display_id].set_configured_ui_scale(ui_scale); |
484 if (overscan_insets) | 476 if (overscan_insets) |
485 display_info_[display_id].SetOverscanInsets(*overscan_insets); | 477 display_info_[display_id].SetOverscanInsets(*overscan_insets); |
486 if (!resolution_in_pixels.IsEmpty()) | 478 if (!resolution_in_pixels.IsEmpty()) { |
487 resolutions_[display_id] = resolution_in_pixels; | 479 // Default refresh rate, until OnNativeDisplaysChanged() updates us with the |
480 // actual display info, is 60 Hz. | |
481 display_modes_[display_id] = | |
482 DisplayMode(resolution_in_pixels, 60.0f, false, false); | |
483 } | |
488 } | 484 } |
489 | 485 |
490 bool DisplayManager::GetSelectedResolutionForDisplayId( | 486 bool DisplayManager::GetSelectedModeForDisplayId(int64 id, |
491 int64 id, | 487 DisplayMode* mode_out) const { |
492 gfx::Size* resolution_out) const { | 488 std::map<int64, DisplayMode>::const_iterator iter = display_modes_.find(id); |
493 std::map<int64, gfx::Size>::const_iterator iter = | 489 if (iter == display_modes_.end()) |
494 resolutions_.find(id); | |
495 if (iter == resolutions_.end()) | |
496 return false; | 490 return false; |
497 *resolution_out = iter->second; | 491 *mode_out = iter->second; |
498 return true; | 492 return true; |
499 } | 493 } |
500 | 494 |
501 bool DisplayManager::IsDisplayUIScalingEnabled() const { | 495 bool DisplayManager::IsDisplayUIScalingEnabled() const { |
502 return GetDisplayIdForUIScaling() != gfx::Display::kInvalidDisplayID; | 496 return GetDisplayIdForUIScaling() != gfx::Display::kInvalidDisplayID; |
503 } | 497 } |
504 | 498 |
505 gfx::Insets DisplayManager::GetOverscanInsets(int64 display_id) const { | 499 gfx::Insets DisplayManager::GetOverscanInsets(int64 display_id) const { |
506 std::map<int64, DisplayInfo>::const_iterator it = | 500 std::map<int64, DisplayInfo>::const_iterator it = |
507 display_info_.find(display_id); | 501 display_info_.find(display_id); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
561 gfx::Point origin = iter->bounds_in_native().origin(); | 555 gfx::Point origin = iter->bounds_in_native().origin(); |
562 if (origins.find(origin) != origins.end()) { | 556 if (origins.find(origin) != origins.end()) { |
563 InsertAndUpdateDisplayInfo(*iter); | 557 InsertAndUpdateDisplayInfo(*iter); |
564 mirrored_display_id_ = iter->id(); | 558 mirrored_display_id_ = iter->id(); |
565 } else { | 559 } else { |
566 origins.insert(origin); | 560 origins.insert(origin); |
567 new_display_info_list.push_back(*iter); | 561 new_display_info_list.push_back(*iter); |
568 } | 562 } |
569 | 563 |
570 const gfx::Size& resolution = iter->bounds_in_native().size(); | 564 const gfx::Size& resolution = iter->bounds_in_native().size(); |
571 const std::vector<Resolution>& resolutions = iter->resolutions(); | 565 const std::vector<DisplayMode>& display_modes = iter->display_modes(); |
572 // This is empty the displays are initialized from InitFromCommandLine. | 566 // This is empty the displays are initialized from InitFromCommandLine. |
573 if (!resolutions.size()) | 567 if (!display_modes.size()) |
574 continue; | 568 continue; |
575 std::vector<Resolution>::const_iterator resolution_iter = | 569 std::vector<DisplayMode>::const_iterator display_modes_iter = |
576 std::find_if(resolutions.begin(), | 570 std::find_if(display_modes.begin(), |
577 resolutions.end(), | 571 display_modes.end(), |
578 ResolutionMatcher(resolution)); | 572 DisplayModeMatcher(resolution)); |
579 // Update the actual resolution selected as the resolution request may fail. | 573 // Update the actual resolution selected as the resolution request may fail. |
580 if (resolution_iter == resolutions.begin()) | 574 if (display_modes_iter != display_modes.end()) { |
581 resolutions_.erase(iter->id()); | 575 std::map<int64, DisplayMode>::iterator old_mode_iter = |
582 else if (resolutions_.find(iter->id()) != resolutions_.end()) | 576 display_modes_.find(iter->id()); |
583 resolutions_[iter->id()] = resolution; | 577 if (old_mode_iter != display_modes_.end()) |
578 old_mode_iter->second = *display_modes_iter; | |
579 } else { | |
580 display_modes_.erase(iter->id()); | |
581 } | |
oshima
2014/02/07 15:43:27
Does the following work?
if (display_modes_iter =
sheu
2014/02/07 21:35:36
That's two lookups on display_modes_, vs. one in t
| |
584 } | 582 } |
585 if (HasInternalDisplay() && | 583 if (HasInternalDisplay() && |
586 !internal_display_connected && | 584 !internal_display_connected && |
587 display_info_.find(gfx::Display::InternalDisplayId()) == | 585 display_info_.find(gfx::Display::InternalDisplayId()) == |
588 display_info_.end()) { | 586 display_info_.end()) { |
589 DisplayInfo internal_display_info( | 587 DisplayInfo internal_display_info( |
590 gfx::Display::InternalDisplayId(), | 588 gfx::Display::InternalDisplayId(), |
591 l10n_util::GetStringUTF8(IDS_ASH_INTERNAL_DISPLAY_NAME), | 589 l10n_util::GetStringUTF8(IDS_ASH_INTERNAL_DISPLAY_NAME), |
592 false /*Internal display must not have overscan */); | 590 false /*Internal display must not have overscan */); |
593 internal_display_info.SetBounds(gfx::Rect(0, 0, 800, 600)); | 591 internal_display_info.SetBounds(gfx::Rect(0, 0, 800, 600)); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
654 while (curr_iter != displays_.end() || | 652 while (curr_iter != displays_.end() || |
655 new_info_iter != new_display_info_list.end()) { | 653 new_info_iter != new_display_info_list.end()) { |
656 if (new_info_iter != new_display_info_list.end() && | 654 if (new_info_iter != new_display_info_list.end() && |
657 non_desktop_display_id == new_info_iter->id()) { | 655 non_desktop_display_id == new_info_iter->id()) { |
658 DisplayInfo info = *new_info_iter; | 656 DisplayInfo info = *new_info_iter; |
659 info.SetOverscanInsets(gfx::Insets()); | 657 info.SetOverscanInsets(gfx::Insets()); |
660 InsertAndUpdateDisplayInfo(info); | 658 InsertAndUpdateDisplayInfo(info); |
661 non_desktop_display_ = | 659 non_desktop_display_ = |
662 CreateDisplayFromDisplayInfoById(non_desktop_display_id); | 660 CreateDisplayFromDisplayInfoById(non_desktop_display_id); |
663 ++new_info_iter; | 661 ++new_info_iter; |
664 // Remove existing external dispaly if it is going to be used as | 662 // Remove existing external display if it is going to be used as |
665 // non desktop. | 663 // non desktop. |
666 if (curr_iter != displays_.end() && | 664 if (curr_iter != displays_.end() && |
667 curr_iter->id() == non_desktop_display_id) { | 665 curr_iter->id() == non_desktop_display_id) { |
668 removed_displays.push_back(*curr_iter); | 666 removed_displays.push_back(*curr_iter); |
669 ++curr_iter; | 667 ++curr_iter; |
670 } | 668 } |
671 continue; | 669 continue; |
672 } | 670 } |
673 | 671 |
674 if (curr_iter == displays_.end()) { | 672 if (curr_iter == displays_.end()) { |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1082 break; | 1080 break; |
1083 } | 1081 } |
1084 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); | 1082 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); |
1085 secondary_display->set_bounds( | 1083 secondary_display->set_bounds( |
1086 gfx::Rect(new_secondary_origin, secondary_bounds.size())); | 1084 gfx::Rect(new_secondary_origin, secondary_bounds.size())); |
1087 secondary_display->UpdateWorkAreaFromInsets(insets); | 1085 secondary_display->UpdateWorkAreaFromInsets(insets); |
1088 } | 1086 } |
1089 | 1087 |
1090 } // namespace internal | 1088 } // namespace internal |
1091 } // namespace ash | 1089 } // namespace ash |
OLD | NEW |