| 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 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 ScaleComparator(float s) : scale(s) {} | 88 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] = | 470 display_info_[display_id] = |
| 479 DisplayInfo(display_id, std::string(""), false); | 471 DisplayInfo(display_id, std::string(""), false); |
| 480 } | 472 } |
| 481 | 473 |
| 482 display_info_[display_id].set_rotation(rotation); | 474 display_info_[display_id].set_rotation(rotation); |
| 483 // Just in case the preference file was corrupted. | 475 // Just in case the preference file was corrupted. |
| 484 if (0.5f <= ui_scale && ui_scale <= 2.0f) | 476 if (0.5f <= ui_scale && ui_scale <= 2.0f) |
| 485 display_info_[display_id].set_configured_ui_scale(ui_scale); | 477 display_info_[display_id].set_configured_ui_scale(ui_scale); |
| 486 if (overscan_insets) | 478 if (overscan_insets) |
| 487 display_info_[display_id].SetOverscanInsets(*overscan_insets); | 479 display_info_[display_id].SetOverscanInsets(*overscan_insets); |
| 488 if (!resolution_in_pixels.IsEmpty()) | 480 if (!resolution_in_pixels.IsEmpty()) { |
| 489 resolutions_[display_id] = resolution_in_pixels; | 481 // Default refresh rate, until OnNativeDisplaysChanged() updates us with the |
| 482 // actual display info, is 60 Hz. |
| 483 display_modes_[display_id] = |
| 484 DisplayMode(resolution_in_pixels, 60.0f, false, false); |
| 485 } |
| 490 } | 486 } |
| 491 | 487 |
| 492 bool DisplayManager::GetSelectedResolutionForDisplayId( | 488 bool DisplayManager::GetSelectedModeForDisplayId(int64 id, |
| 493 int64 id, | 489 DisplayMode* mode_out) const { |
| 494 gfx::Size* resolution_out) const { | 490 std::map<int64, DisplayMode>::const_iterator iter = display_modes_.find(id); |
| 495 std::map<int64, gfx::Size>::const_iterator iter = | 491 if (iter == display_modes_.end()) |
| 496 resolutions_.find(id); | |
| 497 if (iter == resolutions_.end()) | |
| 498 return false; | 492 return false; |
| 499 *resolution_out = iter->second; | 493 *mode_out = iter->second; |
| 500 return true; | 494 return true; |
| 501 } | 495 } |
| 502 | 496 |
| 503 bool DisplayManager::IsDisplayUIScalingEnabled() const { | 497 bool DisplayManager::IsDisplayUIScalingEnabled() const { |
| 504 return GetDisplayIdForUIScaling() != gfx::Display::kInvalidDisplayID; | 498 return GetDisplayIdForUIScaling() != gfx::Display::kInvalidDisplayID; |
| 505 } | 499 } |
| 506 | 500 |
| 507 gfx::Insets DisplayManager::GetOverscanInsets(int64 display_id) const { | 501 gfx::Insets DisplayManager::GetOverscanInsets(int64 display_id) const { |
| 508 std::map<int64, DisplayInfo>::const_iterator it = | 502 std::map<int64, DisplayInfo>::const_iterator it = |
| 509 display_info_.find(display_id); | 503 display_info_.find(display_id); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 gfx::Point origin = iter->bounds_in_native().origin(); | 557 gfx::Point origin = iter->bounds_in_native().origin(); |
| 564 if (origins.find(origin) != origins.end()) { | 558 if (origins.find(origin) != origins.end()) { |
| 565 InsertAndUpdateDisplayInfo(*iter); | 559 InsertAndUpdateDisplayInfo(*iter); |
| 566 mirrored_display_id_ = iter->id(); | 560 mirrored_display_id_ = iter->id(); |
| 567 } else { | 561 } else { |
| 568 origins.insert(origin); | 562 origins.insert(origin); |
| 569 new_display_info_list.push_back(*iter); | 563 new_display_info_list.push_back(*iter); |
| 570 } | 564 } |
| 571 | 565 |
| 572 const gfx::Size& resolution = iter->bounds_in_native().size(); | 566 const gfx::Size& resolution = iter->bounds_in_native().size(); |
| 573 const std::vector<Resolution>& resolutions = iter->resolutions(); | 567 const std::vector<DisplayMode>& display_modes = iter->display_modes(); |
| 574 // This is empty the displays are initialized from InitFromCommandLine. | 568 // This is empty the displays are initialized from InitFromCommandLine. |
| 575 if (!resolutions.size()) | 569 if (!display_modes.size()) |
| 576 continue; | 570 continue; |
| 577 std::vector<Resolution>::const_iterator resolution_iter = | 571 std::vector<DisplayMode>::const_iterator display_modes_iter = |
| 578 std::find_if(resolutions.begin(), | 572 std::find_if(display_modes.begin(), |
| 579 resolutions.end(), | 573 display_modes.end(), |
| 580 ResolutionMatcher(resolution)); | 574 DisplayModeMatcher(resolution)); |
| 581 // Update the actual resolution selected as the resolution request may fail. | 575 // Update the actual resolution selected as the resolution request may fail. |
| 582 if (resolution_iter == resolutions.begin()) | 576 if (display_modes_iter != display_modes.end()) |
| 583 resolutions_.erase(iter->id()); | 577 display_modes_[iter->id()] = *display_modes_iter; |
| 584 else if (resolutions_.find(iter->id()) != resolutions_.end()) | 578 else |
| 585 resolutions_[iter->id()] = resolution; | 579 display_modes_.erase(iter->id()); |
| 586 } | 580 } |
| 587 if (HasInternalDisplay() && | 581 if (HasInternalDisplay() && |
| 588 !internal_display_connected && | 582 !internal_display_connected && |
| 589 display_info_.find(gfx::Display::InternalDisplayId()) == | 583 display_info_.find(gfx::Display::InternalDisplayId()) == |
| 590 display_info_.end()) { | 584 display_info_.end()) { |
| 591 DisplayInfo internal_display_info( | 585 DisplayInfo internal_display_info( |
| 592 gfx::Display::InternalDisplayId(), | 586 gfx::Display::InternalDisplayId(), |
| 593 l10n_util::GetStringUTF8(IDS_ASH_INTERNAL_DISPLAY_NAME), | 587 l10n_util::GetStringUTF8(IDS_ASH_INTERNAL_DISPLAY_NAME), |
| 594 false /*Internal display must not have overscan */); | 588 false /*Internal display must not have overscan */); |
| 595 internal_display_info.SetBounds(gfx::Rect(0, 0, 800, 600)); | 589 internal_display_info.SetBounds(gfx::Rect(0, 0, 800, 600)); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 while (curr_iter != displays_.end() || | 650 while (curr_iter != displays_.end() || |
| 657 new_info_iter != new_display_info_list.end()) { | 651 new_info_iter != new_display_info_list.end()) { |
| 658 if (new_info_iter != new_display_info_list.end() && | 652 if (new_info_iter != new_display_info_list.end() && |
| 659 non_desktop_display_id == new_info_iter->id()) { | 653 non_desktop_display_id == new_info_iter->id()) { |
| 660 DisplayInfo info = *new_info_iter; | 654 DisplayInfo info = *new_info_iter; |
| 661 info.SetOverscanInsets(gfx::Insets()); | 655 info.SetOverscanInsets(gfx::Insets()); |
| 662 InsertAndUpdateDisplayInfo(info); | 656 InsertAndUpdateDisplayInfo(info); |
| 663 non_desktop_display_ = | 657 non_desktop_display_ = |
| 664 CreateDisplayFromDisplayInfoById(non_desktop_display_id); | 658 CreateDisplayFromDisplayInfoById(non_desktop_display_id); |
| 665 ++new_info_iter; | 659 ++new_info_iter; |
| 666 // Remove existing external dispaly if it is going to be used as | 660 // Remove existing external display if it is going to be used as |
| 667 // non desktop. | 661 // non desktop. |
| 668 if (curr_iter != displays_.end() && | 662 if (curr_iter != displays_.end() && |
| 669 curr_iter->id() == non_desktop_display_id) { | 663 curr_iter->id() == non_desktop_display_id) { |
| 670 removed_displays.push_back(*curr_iter); | 664 removed_displays.push_back(*curr_iter); |
| 671 ++curr_iter; | 665 ++curr_iter; |
| 672 } | 666 } |
| 673 continue; | 667 continue; |
| 674 } | 668 } |
| 675 | 669 |
| 676 if (curr_iter == displays_.end()) { | 670 if (curr_iter == displays_.end()) { |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1085 break; | 1079 break; |
| 1086 } | 1080 } |
| 1087 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); | 1081 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); |
| 1088 secondary_display->set_bounds( | 1082 secondary_display->set_bounds( |
| 1089 gfx::Rect(new_secondary_origin, secondary_bounds.size())); | 1083 gfx::Rect(new_secondary_origin, secondary_bounds.size())); |
| 1090 secondary_display->UpdateWorkAreaFromInsets(insets); | 1084 secondary_display->UpdateWorkAreaFromInsets(insets); |
| 1091 } | 1085 } |
| 1092 | 1086 |
| 1093 } // namespace internal | 1087 } // namespace internal |
| 1094 } // namespace ash | 1088 } // namespace ash |
| OLD | NEW |