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

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

Issue 138903025: Read compositor VSync information from platform, when possible (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fd71f590e Resolution -> DisplayMode Created 6 years, 10 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 | Annotate | Revision Log
OLDNEW
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
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
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,
469 float refresh_rate) {
477 if (display_info_.find(display_id) == display_info_.end()) { 470 if (display_info_.find(display_id) == display_info_.end()) {
478 display_info_[display_id] = 471 display_info_[display_id] =
479 DisplayInfo(display_id, std::string(""), false); 472 DisplayInfo(display_id, std::string(""), false);
480 } 473 }
481 474
482 display_info_[display_id].set_rotation(rotation); 475 display_info_[display_id].set_rotation(rotation);
483 // Just in case the preference file was corrupted. 476 // Just in case the preference file was corrupted.
484 if (0.5f <= ui_scale && ui_scale <= 2.0f) 477 if (0.5f <= ui_scale && ui_scale <= 2.0f)
485 display_info_[display_id].set_configured_ui_scale(ui_scale); 478 display_info_[display_id].set_configured_ui_scale(ui_scale);
486 if (overscan_insets) 479 if (overscan_insets)
487 display_info_[display_id].SetOverscanInsets(*overscan_insets); 480 display_info_[display_id].SetOverscanInsets(*overscan_insets);
488 if (!resolution_in_pixels.IsEmpty()) 481 if (!resolution_in_pixels.IsEmpty()) {
489 resolutions_[display_id] = resolution_in_pixels; 482 display_modes_[display_id] =
483 DisplayMode(resolution_in_pixels, refresh_rate, false, false);
484 }
490 } 485 }
491 486
492 bool DisplayManager::GetSelectedResolutionForDisplayId( 487 bool DisplayManager::GetSelectedModeForDisplayId(int64 id,
493 int64 id, 488 DisplayMode* mode_out) const {
494 gfx::Size* resolution_out) const { 489 std::map<int64, DisplayMode>::const_iterator iter = display_modes_.find(id);
495 std::map<int64, gfx::Size>::const_iterator iter = 490 if (iter == display_modes_.end())
496 resolutions_.find(id);
497 if (iter == resolutions_.end())
498 return false; 491 return false;
499 *resolution_out = iter->second; 492 *mode_out = iter->second;
500 return true; 493 return true;
501 } 494 }
502 495
503 bool DisplayManager::IsDisplayUIScalingEnabled() const { 496 bool DisplayManager::IsDisplayUIScalingEnabled() const {
504 return GetDisplayIdForUIScaling() != gfx::Display::kInvalidDisplayID; 497 return GetDisplayIdForUIScaling() != gfx::Display::kInvalidDisplayID;
505 } 498 }
506 499
507 gfx::Insets DisplayManager::GetOverscanInsets(int64 display_id) const { 500 gfx::Insets DisplayManager::GetOverscanInsets(int64 display_id) const {
508 std::map<int64, DisplayInfo>::const_iterator it = 501 std::map<int64, DisplayInfo>::const_iterator it =
509 display_info_.find(display_id); 502 display_info_.find(display_id);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 gfx::Point origin = iter->bounds_in_native().origin(); 556 gfx::Point origin = iter->bounds_in_native().origin();
564 if (origins.find(origin) != origins.end()) { 557 if (origins.find(origin) != origins.end()) {
565 InsertAndUpdateDisplayInfo(*iter); 558 InsertAndUpdateDisplayInfo(*iter);
566 mirrored_display_id_ = iter->id(); 559 mirrored_display_id_ = iter->id();
567 } else { 560 } else {
568 origins.insert(origin); 561 origins.insert(origin);
569 new_display_info_list.push_back(*iter); 562 new_display_info_list.push_back(*iter);
570 } 563 }
571 564
572 const gfx::Size& resolution = iter->bounds_in_native().size(); 565 const gfx::Size& resolution = iter->bounds_in_native().size();
573 const std::vector<Resolution>& resolutions = iter->resolutions(); 566 const std::vector<DisplayMode>& display_modes = iter->display_modes();
574 // This is empty the displays are initialized from InitFromCommandLine. 567 // This is empty the displays are initialized from InitFromCommandLine.
575 if (!resolutions.size()) 568 if (!display_modes.size())
576 continue; 569 continue;
577 std::vector<Resolution>::const_iterator resolution_iter = 570 std::vector<DisplayMode>::const_iterator display_modes_iter =
578 std::find_if(resolutions.begin(), 571 std::find_if(display_modes.begin(),
579 resolutions.end(), 572 display_modes.end(),
580 ResolutionMatcher(resolution)); 573 DisplayModeMatcher(resolution));
581 // Update the actual resolution selected as the resolution request may fail. 574 // Update the actual resolution selected as the resolution request may fail.
582 if (resolution_iter == resolutions.begin()) 575 if (display_modes_iter != display_modes.end())
583 resolutions_.erase(iter->id()); 576 display_modes_[iter->id()] = *display_modes_iter;
584 else if (resolutions_.find(iter->id()) != resolutions_.end()) 577 else
585 resolutions_[iter->id()] = resolution; 578 display_modes_.erase(iter->id());
oshima 2014/01/28 22:17:09 since we changed to remember the best mode, you ne
sheu 2014/01/29 00:14:11 Not sure what you mean here. I'm adding the mode
586 } 579 }
587 if (HasInternalDisplay() && 580 if (HasInternalDisplay() &&
588 !internal_display_connected && 581 !internal_display_connected &&
589 display_info_.find(gfx::Display::InternalDisplayId()) == 582 display_info_.find(gfx::Display::InternalDisplayId()) ==
590 display_info_.end()) { 583 display_info_.end()) {
591 DisplayInfo internal_display_info( 584 DisplayInfo internal_display_info(
592 gfx::Display::InternalDisplayId(), 585 gfx::Display::InternalDisplayId(),
593 l10n_util::GetStringUTF8(IDS_ASH_INTERNAL_DISPLAY_NAME), 586 l10n_util::GetStringUTF8(IDS_ASH_INTERNAL_DISPLAY_NAME),
594 false /*Internal display must not have overscan */); 587 false /*Internal display must not have overscan */);
595 internal_display_info.SetBounds(gfx::Rect(0, 0, 800, 600)); 588 internal_display_info.SetBounds(gfx::Rect(0, 0, 800, 600));
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 while (curr_iter != displays_.end() || 649 while (curr_iter != displays_.end() ||
657 new_info_iter != new_display_info_list.end()) { 650 new_info_iter != new_display_info_list.end()) {
658 if (new_info_iter != new_display_info_list.end() && 651 if (new_info_iter != new_display_info_list.end() &&
659 non_desktop_display_id == new_info_iter->id()) { 652 non_desktop_display_id == new_info_iter->id()) {
660 DisplayInfo info = *new_info_iter; 653 DisplayInfo info = *new_info_iter;
661 info.SetOverscanInsets(gfx::Insets()); 654 info.SetOverscanInsets(gfx::Insets());
662 InsertAndUpdateDisplayInfo(info); 655 InsertAndUpdateDisplayInfo(info);
663 non_desktop_display_ = 656 non_desktop_display_ =
664 CreateDisplayFromDisplayInfoById(non_desktop_display_id); 657 CreateDisplayFromDisplayInfoById(non_desktop_display_id);
665 ++new_info_iter; 658 ++new_info_iter;
666 // Remove existing external dispaly if it is going to be used as 659 // Remove existing external display if it is going to be used as
667 // non desktop. 660 // non desktop.
668 if (curr_iter != displays_.end() && 661 if (curr_iter != displays_.end() &&
669 curr_iter->id() == non_desktop_display_id) { 662 curr_iter->id() == non_desktop_display_id) {
670 removed_displays.push_back(*curr_iter); 663 removed_displays.push_back(*curr_iter);
671 ++curr_iter; 664 ++curr_iter;
672 } 665 }
673 continue; 666 continue;
674 } 667 }
675 668
676 if (curr_iter == displays_.end()) { 669 if (curr_iter == displays_.end()) {
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
1085 break; 1078 break;
1086 } 1079 }
1087 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); 1080 gfx::Insets insets = secondary_display->GetWorkAreaInsets();
1088 secondary_display->set_bounds( 1081 secondary_display->set_bounds(
1089 gfx::Rect(new_secondary_origin, secondary_bounds.size())); 1082 gfx::Rect(new_secondary_origin, secondary_bounds.size()));
1090 secondary_display->UpdateWorkAreaFromInsets(insets); 1083 secondary_display->UpdateWorkAreaFromInsets(insets);
1091 } 1084 }
1092 1085
1093 } // namespace internal 1086 } // namespace internal
1094 } // namespace ash 1087 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698