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

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

Issue 259253002: Add OnDisplayMetricsChanged in DisplayObserver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@update_orientation
Patch Set: Created 6 years, 7 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
« 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>
11 11
12 #include "ash/ash_switches.h" 12 #include "ash/ash_switches.h"
13 #include "ash/display/display_layout_store.h" 13 #include "ash/display/display_layout_store.h"
14 #include "ash/display/screen_ash.h" 14 #include "ash/display/screen_ash.h"
15 #include "ash/screen_util.h" 15 #include "ash/screen_util.h"
16 #include "ash/shell.h" 16 #include "ash/shell.h"
17 #include "base/auto_reset.h" 17 #include "base/auto_reset.h"
18 #include "base/command_line.h" 18 #include "base/command_line.h"
19 #include "base/logging.h" 19 #include "base/logging.h"
20 #include "base/metrics/histogram.h" 20 #include "base/metrics/histogram.h"
21 #include "base/strings/string_number_conversions.h" 21 #include "base/strings/string_number_conversions.h"
22 #include "base/strings/string_split.h" 22 #include "base/strings/string_split.h"
23 #include "base/strings/stringprintf.h" 23 #include "base/strings/stringprintf.h"
24 #include "base/strings/utf_string_conversions.h" 24 #include "base/strings/utf_string_conversions.h"
25 #include "grit/ash_strings.h" 25 #include "grit/ash_strings.h"
26 #include "ui/base/l10n/l10n_util.h" 26 #include "ui/base/l10n/l10n_util.h"
27 #include "ui/base/layout.h" 27 #include "ui/base/layout.h"
28 #include "ui/base/resource/resource_bundle.h" 28 #include "ui/base/resource/resource_bundle.h"
29 #include "ui/gfx/display.h" 29 #include "ui/gfx/display.h"
30 #include "ui/gfx/display_observer.h"
30 #include "ui/gfx/rect.h" 31 #include "ui/gfx/rect.h"
31 #include "ui/gfx/screen.h" 32 #include "ui/gfx/screen.h"
32 #include "ui/gfx/size_conversions.h" 33 #include "ui/gfx/size_conversions.h"
33 34
34 #if defined(USE_X11) 35 #if defined(USE_X11)
35 #include "ui/base/x/x11_util.h" 36 #include "ui/base/x/x11_util.h"
36 #endif 37 #endif
37 38
38 #if defined(OS_CHROMEOS) 39 #if defined(OS_CHROMEOS)
39 #include "ash/display/display_configurator_animation.h" 40 #include "ash/display/display_configurator_animation.h"
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 delegate_->PreDisplayConfigurationChange(false); 341 delegate_->PreDisplayConfigurationChange(false);
341 // PreDisplayConfigurationChange(false); 342 // PreDisplayConfigurationChange(false);
342 // TODO(oshima): Call UpdateDisplays instead. 343 // TODO(oshima): Call UpdateDisplays instead.
343 const DisplayLayout layout = GetCurrentDisplayLayout(); 344 const DisplayLayout layout = GetCurrentDisplayLayout();
344 UpdateDisplayBoundsForLayoutById( 345 UpdateDisplayBoundsForLayoutById(
345 layout, primary, 346 layout, primary,
346 ScreenUtil::GetSecondaryDisplay().id()); 347 ScreenUtil::GetSecondaryDisplay().id());
347 348
348 // Primary's bounds stay the same. Just notify bounds change 349 // Primary's bounds stay the same. Just notify bounds change
349 // on the secondary. 350 // on the secondary.
350 screen_ash_->NotifyBoundsChanged( 351 screen_ash_->NotifyMetricsChanged(
351 ScreenUtil::GetSecondaryDisplay()); 352 ScreenUtil::GetSecondaryDisplay(),
353 gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS |
354 gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA);
352 if (delegate_) 355 if (delegate_)
353 delegate_->PostDisplayConfigurationChange(); 356 delegate_->PostDisplayConfigurationChange();
354 } 357 }
355 } 358 }
356 359
357 const gfx::Display& DisplayManager::GetDisplayForId(int64 id) const { 360 const gfx::Display& DisplayManager::GetDisplayForId(int64 id) const {
358 gfx::Display* display = 361 gfx::Display* display =
359 const_cast<DisplayManager*>(this)->FindDisplayForId(id); 362 const_cast<DisplayManager*>(this)->FindDisplayForId(id);
360 return display ? *display : GetInvalidDisplay(); 363 return display ? *display : GetInvalidDisplay();
361 } 364 }
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 ": Multiple display test does not work on Windows bots. Please " 639 ": Multiple display test does not work on Windows bots. Please "
637 "skip (don't disable) the test using SupportsMultipleDisplays()"; 640 "skip (don't disable) the test using SupportsMultipleDisplays()";
638 #endif 641 #endif
639 642
640 DisplayInfoList new_display_info_list = updated_display_info_list; 643 DisplayInfoList new_display_info_list = updated_display_info_list;
641 std::sort(displays_.begin(), displays_.end(), DisplaySortFunctor()); 644 std::sort(displays_.begin(), displays_.end(), DisplaySortFunctor());
642 std::sort(new_display_info_list.begin(), 645 std::sort(new_display_info_list.begin(),
643 new_display_info_list.end(), 646 new_display_info_list.end(),
644 DisplayInfoSortFunctor()); 647 DisplayInfoSortFunctor());
645 DisplayList removed_displays; 648 DisplayList removed_displays;
646 std::vector<size_t> changed_display_indices; 649 std::map<size_t, uint32_t> display_changes;
647 std::vector<size_t> added_display_indices; 650 std::vector<size_t> added_display_indices;
648 651
649 DisplayList::iterator curr_iter = displays_.begin(); 652 DisplayList::iterator curr_iter = displays_.begin();
650 DisplayInfoList::const_iterator new_info_iter = new_display_info_list.begin(); 653 DisplayInfoList::const_iterator new_info_iter = new_display_info_list.begin();
651 654
652 DisplayList new_displays; 655 DisplayList new_displays;
653 656
654 // Use the internal display or 1st as the mirror source, then scale 657 // Use the internal display or 1st as the mirror source, then scale
655 // the root window so that it matches the external display's 658 // the root window so that it matches the external display's
656 // resolution. This is necessary in order for scaling to work while 659 // resolution. This is necessary in order for scaling to work while
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 } else if (curr_iter->id() == new_info_iter->id()) { 709 } else if (curr_iter->id() == new_info_iter->id()) {
707 const gfx::Display& current_display = *curr_iter; 710 const gfx::Display& current_display = *curr_iter;
708 // Copy the info because |CreateDisplayFromInfo| updates the instance. 711 // Copy the info because |CreateDisplayFromInfo| updates the instance.
709 const DisplayInfo current_display_info = 712 const DisplayInfo current_display_info =
710 GetDisplayInfo(current_display.id()); 713 GetDisplayInfo(current_display.id());
711 InsertAndUpdateDisplayInfo(*new_info_iter); 714 InsertAndUpdateDisplayInfo(*new_info_iter);
712 gfx::Display new_display = 715 gfx::Display new_display =
713 CreateDisplayFromDisplayInfoById(new_info_iter->id()); 716 CreateDisplayFromDisplayInfoById(new_info_iter->id());
714 const DisplayInfo& new_display_info = GetDisplayInfo(new_display.id()); 717 const DisplayInfo& new_display_info = GetDisplayInfo(new_display.id());
715 718
716 bool host_window_bounds_changed = 719 uint32_t metrics = gfx::DisplayObserver::DISPLAY_METRIC_NONE;
717 current_display_info.bounds_in_native() !=
718 new_display_info.bounds_in_native();
719 720
720 if (force_bounds_changed_ || 721 // At that point the new Display objects we have are not entirely updated,
721 host_window_bounds_changed || 722 // they are missing the translation related to the Display disposition in
722 (current_display.device_scale_factor() != 723 // the layout.
723 new_display.device_scale_factor()) || 724 // Using display.bounds() and display.work_area() would fail most of the
725 // time.
726 if (force_bounds_changed_ || (current_display_info.bounds_in_native() !=
727 new_display_info.bounds_in_native()) ||
724 (current_display_info.size_in_pixel() != 728 (current_display_info.size_in_pixel() !=
725 new_display.GetSizeInPixel()) || 729 new_display.GetSizeInPixel())) {
726 (current_display.rotation() != new_display.rotation())) { 730 metrics |= gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS |
727 changed_display_indices.push_back(new_displays.size()); 731 gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA;
732 }
733
734 if (current_display.device_scale_factor() !=
735 new_display.device_scale_factor()) {
736 metrics |= gfx::DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR;
737 }
738
739 if (current_display.rotation() != new_display.rotation())
740 metrics |= gfx::DisplayObserver::DISPLAY_METRIC_ROTATION;
741
742 if (metrics != gfx::DisplayObserver::DISPLAY_METRIC_NONE) {
743 display_changes.insert(
744 std::pair<size_t, uint32_t>(new_displays.size(), metrics));
728 } 745 }
729 746
730 new_display.UpdateWorkAreaFromInsets(current_display.GetWorkAreaInsets()); 747 new_display.UpdateWorkAreaFromInsets(current_display.GetWorkAreaInsets());
731 new_displays.push_back(new_display); 748 new_displays.push_back(new_display);
732 ++curr_iter; 749 ++curr_iter;
733 ++new_info_iter; 750 ++new_info_iter;
734 } else if (curr_iter->id() < new_info_iter->id()) { 751 } else if (curr_iter->id() < new_info_iter->id()) {
735 // more displays in current list between ids, which means it is deleted. 752 // more displays in current list between ids, which means it is deleted.
736 removed_displays.push_back(*curr_iter); 753 removed_displays.push_back(*curr_iter);
737 ++curr_iter; 754 ++curr_iter;
738 } else { 755 } else {
739 // more displays in new list between ids, which means it is added. 756 // more displays in new list between ids, which means it is added.
740 added_display_indices.push_back(new_displays.size()); 757 added_display_indices.push_back(new_displays.size());
741 InsertAndUpdateDisplayInfo(*new_info_iter); 758 InsertAndUpdateDisplayInfo(*new_info_iter);
742 new_displays.push_back( 759 new_displays.push_back(
743 CreateDisplayFromDisplayInfoById(new_info_iter->id())); 760 CreateDisplayFromDisplayInfoById(new_info_iter->id()));
744 ++new_info_iter; 761 ++new_info_iter;
745 } 762 }
746 } 763 }
747 764
748 scoped_ptr<NonDesktopDisplayUpdater> non_desktop_display_updater( 765 scoped_ptr<NonDesktopDisplayUpdater> non_desktop_display_updater(
749 new NonDesktopDisplayUpdater(this, delegate_)); 766 new NonDesktopDisplayUpdater(this, delegate_));
750 767
751 // Do not update |displays_| if there's nothing to be updated. Without this, 768 // Do not update |displays_| if there's nothing to be updated. Without this,
752 // it will not update the display layout, which causes the bug 769 // it will not update the display layout, which causes the bug
753 // http://crbug.com/155948. 770 // http://crbug.com/155948.
754 if (changed_display_indices.empty() && added_display_indices.empty() && 771 if (display_changes.empty() && added_display_indices.empty() &&
755 removed_displays.empty()) { 772 removed_displays.empty()) {
756 return; 773 return;
757 } 774 }
758 // Clear focus if the display has been removed, but don't clear focus if 775 // Clear focus if the display has been removed, but don't clear focus if
759 // the destkop has been moved from one display to another 776 // the destkop has been moved from one display to another
760 // (mirror -> docked, docked -> single internal). 777 // (mirror -> docked, docked -> single internal).
761 bool clear_focus = 778 bool clear_focus =
762 !removed_displays.empty() && 779 !removed_displays.empty() &&
763 !(removed_displays.size() == 1 && added_display_indices.size() == 1); 780 !(removed_displays.size() == 1 && added_display_indices.size() == 1);
764 if (delegate_) 781 if (delegate_)
765 delegate_->PreDisplayConfigurationChange(clear_focus); 782 delegate_->PreDisplayConfigurationChange(clear_focus);
766 783
767 size_t updated_index; 784 size_t updated_index;
768 if (UpdateSecondaryDisplayBoundsForLayout(&new_displays, &updated_index) && 785 if (UpdateSecondaryDisplayBoundsForLayout(&new_displays, &updated_index) &&
769 std::find(added_display_indices.begin(), 786 std::find(added_display_indices.begin(),
770 added_display_indices.end(), 787 added_display_indices.end(),
771 updated_index) == added_display_indices.end() && 788 updated_index) == added_display_indices.end()) {
772 std::find(changed_display_indices.begin(), 789 uint32_t metrics = gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS |
773 changed_display_indices.end(), 790 gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA;
774 updated_index) == changed_display_indices.end()) { 791 if (display_changes.find(updated_index) != display_changes.end())
775 changed_display_indices.push_back(updated_index); 792 metrics |= display_changes[updated_index];
793
794 display_changes[updated_index] = metrics;
776 } 795 }
777 796
778 displays_ = new_displays; 797 displays_ = new_displays;
779 798
780 base::AutoReset<bool> resetter(&change_display_upon_host_resize_, false); 799 base::AutoReset<bool> resetter(&change_display_upon_host_resize_, false);
781 800
782 // Temporarily add displays to be removed because display object 801 // Temporarily add displays to be removed because display object
783 // being removed are accessed during shutting down the root. 802 // being removed are accessed during shutting down the root.
784 displays_.insert(displays_.end(), removed_displays.begin(), 803 displays_.insert(displays_.end(), removed_displays.begin(),
785 removed_displays.end()); 804 removed_displays.end());
786 805
787 for (DisplayList::const_reverse_iterator iter = removed_displays.rbegin(); 806 for (DisplayList::const_reverse_iterator iter = removed_displays.rbegin();
788 iter != removed_displays.rend(); ++iter) { 807 iter != removed_displays.rend(); ++iter) {
789 screen_ash_->NotifyDisplayRemoved(displays_.back()); 808 screen_ash_->NotifyDisplayRemoved(displays_.back());
790 displays_.pop_back(); 809 displays_.pop_back();
791 } 810 }
792 // Close the non desktop window here to avoid creating two compositor on 811 // Close the non desktop window here to avoid creating two compositor on
793 // one display. 812 // one display.
794 if (!non_desktop_display_updater->enabled()) 813 if (!non_desktop_display_updater->enabled())
795 non_desktop_display_updater.reset(); 814 non_desktop_display_updater.reset();
796 for (std::vector<size_t>::iterator iter = added_display_indices.begin(); 815 for (std::vector<size_t>::iterator iter = added_display_indices.begin();
797 iter != added_display_indices.end(); ++iter) { 816 iter != added_display_indices.end(); ++iter) {
798 screen_ash_->NotifyDisplayAdded(displays_[*iter]); 817 screen_ash_->NotifyDisplayAdded(displays_[*iter]);
799 } 818 }
800 // Create the non destkop window after all displays are added so that 819 // Create the non destkop window after all displays are added so that
801 // it can mirror the display newly added. This can happen when switching 820 // it can mirror the display newly added. This can happen when switching
802 // from dock mode to software mirror mode. 821 // from dock mode to software mirror mode.
803 non_desktop_display_updater.reset(); 822 non_desktop_display_updater.reset();
804 for (std::vector<size_t>::iterator iter = changed_display_indices.begin(); 823 for (std::map<size_t, uint32_t>::iterator iter = display_changes.begin();
805 iter != changed_display_indices.end(); ++iter) { 824 iter != display_changes.end();
806 screen_ash_->NotifyBoundsChanged(displays_[*iter]); 825 ++iter) {
826 screen_ash_->NotifyMetricsChanged(displays_[iter->first], iter->second);
807 } 827 }
808 if (delegate_) 828 if (delegate_)
809 delegate_->PostDisplayConfigurationChange(); 829 delegate_->PostDisplayConfigurationChange();
810 830
811 #if defined(USE_X11) && defined(OS_CHROMEOS) 831 #if defined(USE_X11) && defined(OS_CHROMEOS)
812 if (!changed_display_indices.empty() && base::SysInfo::IsRunningOnChromeOS()) 832 if (!display_changes.empty() && base::SysInfo::IsRunningOnChromeOS())
813 ui::ClearX11DefaultRootWindow(); 833 ui::ClearX11DefaultRootWindow();
814 #endif 834 #endif
815 } 835 }
816 836
817 const gfx::Display& DisplayManager::GetDisplayAt(size_t index) const { 837 const gfx::Display& DisplayManager::GetDisplayAt(size_t index) const {
818 DCHECK_LT(index, displays_.size()); 838 DCHECK_LT(index, displays_.size());
819 return displays_[index]; 839 return displays_[index];
820 } 840 }
821 841
822 const gfx::Display& DisplayManager::GetPrimaryDisplayCandidate() const { 842 const gfx::Display& DisplayManager::GetPrimaryDisplayCandidate() const {
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 970
951 bool DisplayManager::UpdateDisplayBounds(int64 display_id, 971 bool DisplayManager::UpdateDisplayBounds(int64 display_id,
952 const gfx::Rect& new_bounds) { 972 const gfx::Rect& new_bounds) {
953 if (change_display_upon_host_resize_) { 973 if (change_display_upon_host_resize_) {
954 display_info_[display_id].SetBounds(new_bounds); 974 display_info_[display_id].SetBounds(new_bounds);
955 // Don't notify observers if the mirrored window has changed. 975 // Don't notify observers if the mirrored window has changed.
956 if (software_mirroring_enabled() && mirrored_display_id_ == display_id) 976 if (software_mirroring_enabled() && mirrored_display_id_ == display_id)
957 return false; 977 return false;
958 gfx::Display* display = FindDisplayForId(display_id); 978 gfx::Display* display = FindDisplayForId(display_id);
959 display->SetSize(display_info_[display_id].size_in_pixel()); 979 display->SetSize(display_info_[display_id].size_in_pixel());
960 screen_ash_->NotifyBoundsChanged(*display); 980 screen_ash_->NotifyMetricsChanged(
981 *display, gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS);
961 return true; 982 return true;
962 } 983 }
963 return false; 984 return false;
964 } 985 }
965 986
966 void DisplayManager::CreateMirrorWindowIfAny() { 987 void DisplayManager::CreateMirrorWindowIfAny() {
967 NonDesktopDisplayUpdater updater(this, delegate_); 988 NonDesktopDisplayUpdater updater(this, delegate_);
968 } 989 }
969 990
970 void DisplayManager::CreateScreenForShutdown() const { 991 void DisplayManager::CreateScreenForShutdown() const {
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1119 new_secondary_origin.Offset(-secondary_bounds.width(), offset); 1140 new_secondary_origin.Offset(-secondary_bounds.width(), offset);
1120 break; 1141 break;
1121 } 1142 }
1122 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); 1143 gfx::Insets insets = secondary_display->GetWorkAreaInsets();
1123 secondary_display->set_bounds( 1144 secondary_display->set_bounds(
1124 gfx::Rect(new_secondary_origin, secondary_bounds.size())); 1145 gfx::Rect(new_secondary_origin, secondary_bounds.size()));
1125 secondary_display->UpdateWorkAreaFromInsets(insets); 1146 secondary_display->UpdateWorkAreaFromInsets(insets);
1126 } 1147 }
1127 1148
1128 } // namespace ash 1149 } // 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