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

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

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

Powered by Google App Engine
This is Rietveld 408576698