| 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> |
| 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/screen_ash.h" | 14 #include "ash/display/screen_ash.h" |
| 15 #include "ash/screen_util.h" |
| 15 #include "ash/shell.h" | 16 #include "ash/shell.h" |
| 16 #include "base/auto_reset.h" | 17 #include "base/auto_reset.h" |
| 17 #include "base/command_line.h" | 18 #include "base/command_line.h" |
| 18 #include "base/logging.h" | 19 #include "base/logging.h" |
| 19 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
| 20 #include "base/strings/string_split.h" | 21 #include "base/strings/string_split.h" |
| 21 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
| 23 #include "grit/ash_strings.h" | 24 #include "grit/ash_strings.h" |
| 24 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 DISALLOW_COPY_AND_ASSIGN(NonDesktopDisplayUpdater); | 137 DISALLOW_COPY_AND_ASSIGN(NonDesktopDisplayUpdater); |
| 137 }; | 138 }; |
| 138 | 139 |
| 139 } // namespace | 140 } // namespace |
| 140 | 141 |
| 141 using std::string; | 142 using std::string; |
| 142 using std::vector; | 143 using std::vector; |
| 143 | 144 |
| 144 DisplayManager::DisplayManager() | 145 DisplayManager::DisplayManager() |
| 145 : delegate_(NULL), | 146 : delegate_(NULL), |
| 147 screen_ash_(new ScreenAsh), |
| 148 screen_(screen_ash_.get()), |
| 146 layout_store_(new DisplayLayoutStore), | 149 layout_store_(new DisplayLayoutStore), |
| 147 first_display_id_(gfx::Display::kInvalidDisplayID), | 150 first_display_id_(gfx::Display::kInvalidDisplayID), |
| 148 num_connected_displays_(0), | 151 num_connected_displays_(0), |
| 149 force_bounds_changed_(false), | 152 force_bounds_changed_(false), |
| 150 change_display_upon_host_resize_(false), | 153 change_display_upon_host_resize_(false), |
| 151 second_display_mode_(EXTENDED), | 154 second_display_mode_(EXTENDED), |
| 152 mirrored_display_id_(gfx::Display::kInvalidDisplayID) { | 155 mirrored_display_id_(gfx::Display::kInvalidDisplayID) { |
| 153 #if defined(OS_CHROMEOS) | 156 #if defined(OS_CHROMEOS) |
| 154 change_display_upon_host_resize_ = !base::SysInfo::IsRunningOnChromeOS(); | 157 change_display_upon_host_resize_ = !base::SysInfo::IsRunningOnChromeOS(); |
| 155 #endif | 158 #endif |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 return std::make_pair(displays_[1].id(), id_at_zero); | 298 return std::make_pair(displays_[1].id(), id_at_zero); |
| 296 } | 299 } |
| 297 } | 300 } |
| 298 } | 301 } |
| 299 | 302 |
| 300 void DisplayManager::SetLayoutForCurrentDisplays( | 303 void DisplayManager::SetLayoutForCurrentDisplays( |
| 301 const DisplayLayout& layout_relative_to_primary) { | 304 const DisplayLayout& layout_relative_to_primary) { |
| 302 DCHECK_EQ(2U, GetNumDisplays()); | 305 DCHECK_EQ(2U, GetNumDisplays()); |
| 303 if (GetNumDisplays() < 2) | 306 if (GetNumDisplays() < 2) |
| 304 return; | 307 return; |
| 305 const gfx::Display& primary = Shell::GetScreen()->GetPrimaryDisplay(); | 308 const gfx::Display& primary = screen_->GetPrimaryDisplay(); |
| 306 const DisplayIdPair pair = GetCurrentDisplayIdPair(); | 309 const DisplayIdPair pair = GetCurrentDisplayIdPair(); |
| 307 // Invert if the primary was swapped. | 310 // Invert if the primary was swapped. |
| 308 DisplayLayout to_set = pair.first == primary.id() ? | 311 DisplayLayout to_set = pair.first == primary.id() ? |
| 309 layout_relative_to_primary : layout_relative_to_primary.Invert(); | 312 layout_relative_to_primary : layout_relative_to_primary.Invert(); |
| 310 | 313 |
| 311 DisplayLayout current_layout = | 314 DisplayLayout current_layout = |
| 312 layout_store_->GetRegisteredDisplayLayout(pair); | 315 layout_store_->GetRegisteredDisplayLayout(pair); |
| 313 if (to_set.position != current_layout.position || | 316 if (to_set.position != current_layout.position || |
| 314 to_set.offset != current_layout.offset) { | 317 to_set.offset != current_layout.offset) { |
| 315 to_set.primary_id = primary.id(); | 318 to_set.primary_id = primary.id(); |
| 316 layout_store_->RegisterLayoutForDisplayIdPair( | 319 layout_store_->RegisterLayoutForDisplayIdPair( |
| 317 pair.first, pair.second, to_set); | 320 pair.first, pair.second, to_set); |
| 318 if (delegate_) | 321 if (delegate_) |
| 319 delegate_->PreDisplayConfigurationChange(false); | 322 delegate_->PreDisplayConfigurationChange(false); |
| 320 // PreDisplayConfigurationChange(false); | 323 // PreDisplayConfigurationChange(false); |
| 321 // TODO(oshima): Call UpdateDisplays instead. | 324 // TODO(oshima): Call UpdateDisplays instead. |
| 322 const DisplayLayout layout = GetCurrentDisplayLayout(); | 325 const DisplayLayout layout = GetCurrentDisplayLayout(); |
| 323 UpdateDisplayBoundsForLayoutById( | 326 UpdateDisplayBoundsForLayoutById( |
| 324 layout, primary, | 327 layout, primary, |
| 325 ScreenAsh::GetSecondaryDisplay().id()); | 328 ScreenUtil::GetSecondaryDisplay().id()); |
| 326 | 329 |
| 327 //UpdateCurrentDisplayBoundsForLayout(); | |
| 328 // Primary's bounds stay the same. Just notify bounds change | 330 // Primary's bounds stay the same. Just notify bounds change |
| 329 // on the secondary. | 331 // on the secondary. |
| 330 Shell::GetInstance()->screen()->NotifyBoundsChanged( | 332 screen_ash_->NotifyBoundsChanged( |
| 331 ScreenAsh::GetSecondaryDisplay()); | 333 ScreenUtil::GetSecondaryDisplay()); |
| 332 if (delegate_) | 334 if (delegate_) |
| 333 delegate_->PostDisplayConfigurationChange(); | 335 delegate_->PostDisplayConfigurationChange(); |
| 334 } | 336 } |
| 335 } | 337 } |
| 336 | 338 |
| 337 const gfx::Display& DisplayManager::GetDisplayForId(int64 id) const { | 339 const gfx::Display& DisplayManager::GetDisplayForId(int64 id) const { |
| 338 gfx::Display* display = | 340 gfx::Display* display = |
| 339 const_cast<DisplayManager*>(this)->FindDisplayForId(id); | 341 const_cast<DisplayManager*>(this)->FindDisplayForId(id); |
| 340 return display ? *display : GetInvalidDisplay(); | 342 return display ? *display : GetInvalidDisplay(); |
| 341 } | 343 } |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 | 746 |
| 745 base::AutoReset<bool> resetter(&change_display_upon_host_resize_, false); | 747 base::AutoReset<bool> resetter(&change_display_upon_host_resize_, false); |
| 746 | 748 |
| 747 // Temporarily add displays to be removed because display object | 749 // Temporarily add displays to be removed because display object |
| 748 // being removed are accessed during shutting down the root. | 750 // being removed are accessed during shutting down the root. |
| 749 displays_.insert(displays_.end(), removed_displays.begin(), | 751 displays_.insert(displays_.end(), removed_displays.begin(), |
| 750 removed_displays.end()); | 752 removed_displays.end()); |
| 751 | 753 |
| 752 for (DisplayList::const_reverse_iterator iter = removed_displays.rbegin(); | 754 for (DisplayList::const_reverse_iterator iter = removed_displays.rbegin(); |
| 753 iter != removed_displays.rend(); ++iter) { | 755 iter != removed_displays.rend(); ++iter) { |
| 754 Shell::GetInstance()->screen()->NotifyDisplayRemoved(displays_.back()); | 756 screen_ash_->NotifyDisplayRemoved(displays_.back()); |
| 755 displays_.pop_back(); | 757 displays_.pop_back(); |
| 756 } | 758 } |
| 757 // Close the non desktop window here to avoid creating two compositor on | 759 // Close the non desktop window here to avoid creating two compositor on |
| 758 // one display. | 760 // one display. |
| 759 if (!non_desktop_display_updater->enabled()) | 761 if (!non_desktop_display_updater->enabled()) |
| 760 non_desktop_display_updater.reset(); | 762 non_desktop_display_updater.reset(); |
| 761 for (std::vector<size_t>::iterator iter = added_display_indices.begin(); | 763 for (std::vector<size_t>::iterator iter = added_display_indices.begin(); |
| 762 iter != added_display_indices.end(); ++iter) { | 764 iter != added_display_indices.end(); ++iter) { |
| 763 Shell::GetInstance()->screen()->NotifyDisplayAdded(displays_[*iter]); | 765 screen_ash_->NotifyDisplayAdded(displays_[*iter]); |
| 764 } | 766 } |
| 765 // Create the non destkop window after all displays are added so that | 767 // Create the non destkop window after all displays are added so that |
| 766 // it can mirror the display newly added. This can happen when switching | 768 // it can mirror the display newly added. This can happen when switching |
| 767 // from dock mode to software mirror mode. | 769 // from dock mode to software mirror mode. |
| 768 non_desktop_display_updater.reset(); | 770 non_desktop_display_updater.reset(); |
| 769 for (std::vector<size_t>::iterator iter = changed_display_indices.begin(); | 771 for (std::vector<size_t>::iterator iter = changed_display_indices.begin(); |
| 770 iter != changed_display_indices.end(); ++iter) { | 772 iter != changed_display_indices.end(); ++iter) { |
| 771 Shell::GetInstance()->screen()->NotifyBoundsChanged(displays_[*iter]); | 773 screen_ash_->NotifyBoundsChanged(displays_[*iter]); |
| 772 } | 774 } |
| 773 if (delegate_) | 775 if (delegate_) |
| 774 delegate_->PostDisplayConfigurationChange(); | 776 delegate_->PostDisplayConfigurationChange(); |
| 775 | 777 |
| 776 #if defined(USE_X11) && defined(OS_CHROMEOS) | 778 #if defined(USE_X11) && defined(OS_CHROMEOS) |
| 777 if (!changed_display_indices.empty() && base::SysInfo::IsRunningOnChromeOS()) | 779 if (!changed_display_indices.empty() && base::SysInfo::IsRunningOnChromeOS()) |
| 778 ui::ClearX11DefaultRootWindow(); | 780 ui::ClearX11DefaultRootWindow(); |
| 779 #endif | 781 #endif |
| 780 } | 782 } |
| 781 | 783 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 908 | 910 |
| 909 bool DisplayManager::UpdateDisplayBounds(int64 display_id, | 911 bool DisplayManager::UpdateDisplayBounds(int64 display_id, |
| 910 const gfx::Rect& new_bounds) { | 912 const gfx::Rect& new_bounds) { |
| 911 if (change_display_upon_host_resize_) { | 913 if (change_display_upon_host_resize_) { |
| 912 display_info_[display_id].SetBounds(new_bounds); | 914 display_info_[display_id].SetBounds(new_bounds); |
| 913 // Don't notify observers if the mirrored window has changed. | 915 // Don't notify observers if the mirrored window has changed. |
| 914 if (software_mirroring_enabled() && mirrored_display_id_ == display_id) | 916 if (software_mirroring_enabled() && mirrored_display_id_ == display_id) |
| 915 return false; | 917 return false; |
| 916 gfx::Display* display = FindDisplayForId(display_id); | 918 gfx::Display* display = FindDisplayForId(display_id); |
| 917 display->SetSize(display_info_[display_id].size_in_pixel()); | 919 display->SetSize(display_info_[display_id].size_in_pixel()); |
| 918 Shell::GetInstance()->screen()->NotifyBoundsChanged(*display); | 920 screen_ash_->NotifyBoundsChanged(*display); |
| 919 return true; | 921 return true; |
| 920 } | 922 } |
| 921 return false; | 923 return false; |
| 922 } | 924 } |
| 923 | 925 |
| 924 void DisplayManager::CreateMirrorWindowIfAny() { | 926 void DisplayManager::CreateMirrorWindowIfAny() { |
| 925 NonDesktopDisplayUpdater updater(this, delegate_); | 927 NonDesktopDisplayUpdater updater(this, delegate_); |
| 926 } | 928 } |
| 927 | 929 |
| 930 gfx::Screen* DisplayManager::CreateScreenForShutdown() const{ |
| 931 return screen_ash_->CloneForShutdown(); |
| 932 } |
| 933 |
| 928 gfx::Display* DisplayManager::FindDisplayForId(int64 id) { | 934 gfx::Display* DisplayManager::FindDisplayForId(int64 id) { |
| 929 for (DisplayList::iterator iter = displays_.begin(); | 935 for (DisplayList::iterator iter = displays_.begin(); |
| 930 iter != displays_.end(); ++iter) { | 936 iter != displays_.end(); ++iter) { |
| 931 if ((*iter).id() == id) | 937 if ((*iter).id() == id) |
| 932 return &(*iter); | 938 return &(*iter); |
| 933 } | 939 } |
| 934 DLOG(WARNING) << "Could not find display:" << id; | 940 DLOG(WARNING) << "Could not find display:" << id; |
| 935 return NULL; | 941 return NULL; |
| 936 } | 942 } |
| 937 | 943 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1054 break; | 1060 break; |
| 1055 } | 1061 } |
| 1056 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); | 1062 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); |
| 1057 secondary_display->set_bounds( | 1063 secondary_display->set_bounds( |
| 1058 gfx::Rect(new_secondary_origin, secondary_bounds.size())); | 1064 gfx::Rect(new_secondary_origin, secondary_bounds.size())); |
| 1059 secondary_display->UpdateWorkAreaFromInsets(insets); | 1065 secondary_display->UpdateWorkAreaFromInsets(insets); |
| 1060 } | 1066 } |
| 1061 | 1067 |
| 1062 } // namespace internal | 1068 } // namespace internal |
| 1063 } // namespace ash | 1069 } // namespace ash |
| OLD | NEW |