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 16 matching lines...) Expand all Loading... |
41 #include "base/win/windows_version.h" | 42 #include "base/win/windows_version.h" |
42 #endif | 43 #endif |
43 | 44 |
44 namespace ash { | 45 namespace ash { |
45 namespace internal { | 46 namespace internal { |
46 typedef std::vector<gfx::Display> DisplayList; | 47 typedef std::vector<gfx::Display> DisplayList; |
47 typedef std::vector<DisplayInfo> DisplayInfoList; | 48 typedef std::vector<DisplayInfo> DisplayInfoList; |
48 | 49 |
49 namespace { | 50 namespace { |
50 | 51 |
| 52 // We need to keep this in order for unittests to tell if |
| 53 // the object in gfx::Screen::GetScreenByType is for shutdown. |
| 54 gfx::Screen* screen_for_shutdown = NULL; |
| 55 |
51 // The number of pixels to overlap between the primary and secondary displays, | 56 // The number of pixels to overlap between the primary and secondary displays, |
52 // in case that the offset value is too large. | 57 // in case that the offset value is too large. |
53 const int kMinimumOverlapForInvalidOffset = 100; | 58 const int kMinimumOverlapForInvalidOffset = 100; |
54 | 59 |
55 // List of value UI Scale values. Scales for 2x are equivalent to 640, | 60 // List of value UI Scale values. Scales for 2x are equivalent to 640, |
56 // 800, 1024, 1280, 1440, 1600 and 1920 pixel width respectively on | 61 // 800, 1024, 1280, 1440, 1600 and 1920 pixel width respectively on |
57 // 2560 pixel width 2x density display. Please see crbug.com/233375 | 62 // 2560 pixel width 2x density display. Please see crbug.com/233375 |
58 // for the full list of resolutions. | 63 // for the full list of resolutions. |
59 const float kUIScalesFor2x[] = | 64 const float kUIScalesFor2x[] = |
60 {0.5f, 0.625f, 0.8f, 1.0f, 1.125f, 1.25f, 1.5f, 2.0f}; | 65 {0.5f, 0.625f, 0.8f, 1.0f, 1.125f, 1.25f, 1.5f, 2.0f}; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 DISALLOW_COPY_AND_ASSIGN(NonDesktopDisplayUpdater); | 141 DISALLOW_COPY_AND_ASSIGN(NonDesktopDisplayUpdater); |
137 }; | 142 }; |
138 | 143 |
139 } // namespace | 144 } // namespace |
140 | 145 |
141 using std::string; | 146 using std::string; |
142 using std::vector; | 147 using std::vector; |
143 | 148 |
144 DisplayManager::DisplayManager() | 149 DisplayManager::DisplayManager() |
145 : delegate_(NULL), | 150 : delegate_(NULL), |
| 151 screen_ash_(new ScreenAsh), |
| 152 screen_(screen_ash_.get()), |
146 layout_store_(new DisplayLayoutStore), | 153 layout_store_(new DisplayLayoutStore), |
147 first_display_id_(gfx::Display::kInvalidDisplayID), | 154 first_display_id_(gfx::Display::kInvalidDisplayID), |
148 num_connected_displays_(0), | 155 num_connected_displays_(0), |
149 force_bounds_changed_(false), | 156 force_bounds_changed_(false), |
150 change_display_upon_host_resize_(false), | 157 change_display_upon_host_resize_(false), |
151 second_display_mode_(EXTENDED), | 158 second_display_mode_(EXTENDED), |
152 mirrored_display_id_(gfx::Display::kInvalidDisplayID) { | 159 mirrored_display_id_(gfx::Display::kInvalidDisplayID) { |
153 #if defined(OS_CHROMEOS) | 160 #if defined(OS_CHROMEOS) |
154 change_display_upon_host_resize_ = !base::SysInfo::IsRunningOnChromeOS(); | 161 change_display_upon_host_resize_ = !base::SysInfo::IsRunningOnChromeOS(); |
155 #endif | 162 #endif |
| 163 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_ALTERNATE, |
| 164 screen_ash_.get()); |
| 165 if (gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE) == |
| 166 screen_for_shutdown) { |
| 167 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, |
| 168 screen_ash_.get()); |
| 169 } |
156 } | 170 } |
157 | 171 |
158 DisplayManager::~DisplayManager() { | 172 DisplayManager::~DisplayManager() { |
159 } | 173 } |
160 | 174 |
161 // static | 175 // static |
162 std::vector<float> DisplayManager::GetScalesForDisplay( | 176 std::vector<float> DisplayManager::GetScalesForDisplay( |
163 const DisplayInfo& info) { | 177 const DisplayInfo& info) { |
164 std::vector<float> ret; | 178 std::vector<float> ret; |
165 if (info.device_scale_factor() == 2.0f) { | 179 if (info.device_scale_factor() == 2.0f) { |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 return std::make_pair(displays_[1].id(), id_at_zero); | 309 return std::make_pair(displays_[1].id(), id_at_zero); |
296 } | 310 } |
297 } | 311 } |
298 } | 312 } |
299 | 313 |
300 void DisplayManager::SetLayoutForCurrentDisplays( | 314 void DisplayManager::SetLayoutForCurrentDisplays( |
301 const DisplayLayout& layout_relative_to_primary) { | 315 const DisplayLayout& layout_relative_to_primary) { |
302 DCHECK_EQ(2U, GetNumDisplays()); | 316 DCHECK_EQ(2U, GetNumDisplays()); |
303 if (GetNumDisplays() < 2) | 317 if (GetNumDisplays() < 2) |
304 return; | 318 return; |
305 const gfx::Display& primary = Shell::GetScreen()->GetPrimaryDisplay(); | 319 const gfx::Display& primary = screen_->GetPrimaryDisplay(); |
306 const DisplayIdPair pair = GetCurrentDisplayIdPair(); | 320 const DisplayIdPair pair = GetCurrentDisplayIdPair(); |
307 // Invert if the primary was swapped. | 321 // Invert if the primary was swapped. |
308 DisplayLayout to_set = pair.first == primary.id() ? | 322 DisplayLayout to_set = pair.first == primary.id() ? |
309 layout_relative_to_primary : layout_relative_to_primary.Invert(); | 323 layout_relative_to_primary : layout_relative_to_primary.Invert(); |
310 | 324 |
311 DisplayLayout current_layout = | 325 DisplayLayout current_layout = |
312 layout_store_->GetRegisteredDisplayLayout(pair); | 326 layout_store_->GetRegisteredDisplayLayout(pair); |
313 if (to_set.position != current_layout.position || | 327 if (to_set.position != current_layout.position || |
314 to_set.offset != current_layout.offset) { | 328 to_set.offset != current_layout.offset) { |
315 to_set.primary_id = primary.id(); | 329 to_set.primary_id = primary.id(); |
316 layout_store_->RegisterLayoutForDisplayIdPair( | 330 layout_store_->RegisterLayoutForDisplayIdPair( |
317 pair.first, pair.second, to_set); | 331 pair.first, pair.second, to_set); |
318 if (delegate_) | 332 if (delegate_) |
319 delegate_->PreDisplayConfigurationChange(false); | 333 delegate_->PreDisplayConfigurationChange(false); |
320 // PreDisplayConfigurationChange(false); | 334 // PreDisplayConfigurationChange(false); |
321 // TODO(oshima): Call UpdateDisplays instead. | 335 // TODO(oshima): Call UpdateDisplays instead. |
322 const DisplayLayout layout = GetCurrentDisplayLayout(); | 336 const DisplayLayout layout = GetCurrentDisplayLayout(); |
323 UpdateDisplayBoundsForLayoutById( | 337 UpdateDisplayBoundsForLayoutById( |
324 layout, primary, | 338 layout, primary, |
325 ScreenAsh::GetSecondaryDisplay().id()); | 339 ScreenUtil::GetSecondaryDisplay().id()); |
326 | 340 |
327 //UpdateCurrentDisplayBoundsForLayout(); | |
328 // Primary's bounds stay the same. Just notify bounds change | 341 // Primary's bounds stay the same. Just notify bounds change |
329 // on the secondary. | 342 // on the secondary. |
330 Shell::GetInstance()->screen()->NotifyBoundsChanged( | 343 screen_ash_->NotifyBoundsChanged( |
331 ScreenAsh::GetSecondaryDisplay()); | 344 ScreenUtil::GetSecondaryDisplay()); |
332 if (delegate_) | 345 if (delegate_) |
333 delegate_->PostDisplayConfigurationChange(); | 346 delegate_->PostDisplayConfigurationChange(); |
334 } | 347 } |
335 } | 348 } |
336 | 349 |
337 const gfx::Display& DisplayManager::GetDisplayForId(int64 id) const { | 350 const gfx::Display& DisplayManager::GetDisplayForId(int64 id) const { |
338 gfx::Display* display = | 351 gfx::Display* display = |
339 const_cast<DisplayManager*>(this)->FindDisplayForId(id); | 352 const_cast<DisplayManager*>(this)->FindDisplayForId(id); |
340 return display ? *display : GetInvalidDisplay(); | 353 return display ? *display : GetInvalidDisplay(); |
341 } | 354 } |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 | 757 |
745 base::AutoReset<bool> resetter(&change_display_upon_host_resize_, false); | 758 base::AutoReset<bool> resetter(&change_display_upon_host_resize_, false); |
746 | 759 |
747 // Temporarily add displays to be removed because display object | 760 // Temporarily add displays to be removed because display object |
748 // being removed are accessed during shutting down the root. | 761 // being removed are accessed during shutting down the root. |
749 displays_.insert(displays_.end(), removed_displays.begin(), | 762 displays_.insert(displays_.end(), removed_displays.begin(), |
750 removed_displays.end()); | 763 removed_displays.end()); |
751 | 764 |
752 for (DisplayList::const_reverse_iterator iter = removed_displays.rbegin(); | 765 for (DisplayList::const_reverse_iterator iter = removed_displays.rbegin(); |
753 iter != removed_displays.rend(); ++iter) { | 766 iter != removed_displays.rend(); ++iter) { |
754 Shell::GetInstance()->screen()->NotifyDisplayRemoved(displays_.back()); | 767 screen_ash_->NotifyDisplayRemoved(displays_.back()); |
755 displays_.pop_back(); | 768 displays_.pop_back(); |
756 } | 769 } |
757 // Close the non desktop window here to avoid creating two compositor on | 770 // Close the non desktop window here to avoid creating two compositor on |
758 // one display. | 771 // one display. |
759 if (!non_desktop_display_updater->enabled()) | 772 if (!non_desktop_display_updater->enabled()) |
760 non_desktop_display_updater.reset(); | 773 non_desktop_display_updater.reset(); |
761 for (std::vector<size_t>::iterator iter = added_display_indices.begin(); | 774 for (std::vector<size_t>::iterator iter = added_display_indices.begin(); |
762 iter != added_display_indices.end(); ++iter) { | 775 iter != added_display_indices.end(); ++iter) { |
763 Shell::GetInstance()->screen()->NotifyDisplayAdded(displays_[*iter]); | 776 screen_ash_->NotifyDisplayAdded(displays_[*iter]); |
764 } | 777 } |
765 // Create the non destkop window after all displays are added so that | 778 // 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 | 779 // it can mirror the display newly added. This can happen when switching |
767 // from dock mode to software mirror mode. | 780 // from dock mode to software mirror mode. |
768 non_desktop_display_updater.reset(); | 781 non_desktop_display_updater.reset(); |
769 for (std::vector<size_t>::iterator iter = changed_display_indices.begin(); | 782 for (std::vector<size_t>::iterator iter = changed_display_indices.begin(); |
770 iter != changed_display_indices.end(); ++iter) { | 783 iter != changed_display_indices.end(); ++iter) { |
771 Shell::GetInstance()->screen()->NotifyBoundsChanged(displays_[*iter]); | 784 screen_ash_->NotifyBoundsChanged(displays_[*iter]); |
772 } | 785 } |
773 if (delegate_) | 786 if (delegate_) |
774 delegate_->PostDisplayConfigurationChange(); | 787 delegate_->PostDisplayConfigurationChange(); |
775 | 788 |
776 #if defined(USE_X11) && defined(OS_CHROMEOS) | 789 #if defined(USE_X11) && defined(OS_CHROMEOS) |
777 if (!changed_display_indices.empty() && base::SysInfo::IsRunningOnChromeOS()) | 790 if (!changed_display_indices.empty() && base::SysInfo::IsRunningOnChromeOS()) |
778 ui::ClearX11DefaultRootWindow(); | 791 ui::ClearX11DefaultRootWindow(); |
779 #endif | 792 #endif |
780 } | 793 } |
781 | 794 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 | 921 |
909 bool DisplayManager::UpdateDisplayBounds(int64 display_id, | 922 bool DisplayManager::UpdateDisplayBounds(int64 display_id, |
910 const gfx::Rect& new_bounds) { | 923 const gfx::Rect& new_bounds) { |
911 if (change_display_upon_host_resize_) { | 924 if (change_display_upon_host_resize_) { |
912 display_info_[display_id].SetBounds(new_bounds); | 925 display_info_[display_id].SetBounds(new_bounds); |
913 // Don't notify observers if the mirrored window has changed. | 926 // Don't notify observers if the mirrored window has changed. |
914 if (software_mirroring_enabled() && mirrored_display_id_ == display_id) | 927 if (software_mirroring_enabled() && mirrored_display_id_ == display_id) |
915 return false; | 928 return false; |
916 gfx::Display* display = FindDisplayForId(display_id); | 929 gfx::Display* display = FindDisplayForId(display_id); |
917 display->SetSize(display_info_[display_id].size_in_pixel()); | 930 display->SetSize(display_info_[display_id].size_in_pixel()); |
918 Shell::GetInstance()->screen()->NotifyBoundsChanged(*display); | 931 screen_ash_->NotifyBoundsChanged(*display); |
919 return true; | 932 return true; |
920 } | 933 } |
921 return false; | 934 return false; |
922 } | 935 } |
923 | 936 |
924 void DisplayManager::CreateMirrorWindowIfAny() { | 937 void DisplayManager::CreateMirrorWindowIfAny() { |
925 NonDesktopDisplayUpdater updater(this, delegate_); | 938 NonDesktopDisplayUpdater updater(this, delegate_); |
926 } | 939 } |
927 | 940 |
| 941 void DisplayManager::CreateScreenForShutdown() const { |
| 942 bool native_is_ash = |
| 943 gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE) == |
| 944 screen_ash_.get(); |
| 945 delete screen_for_shutdown; |
| 946 screen_for_shutdown = screen_ash_->CloneForShutdown(); |
| 947 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_ALTERNATE, |
| 948 screen_for_shutdown); |
| 949 if (native_is_ash) { |
| 950 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, |
| 951 screen_for_shutdown); |
| 952 } |
| 953 } |
| 954 |
928 gfx::Display* DisplayManager::FindDisplayForId(int64 id) { | 955 gfx::Display* DisplayManager::FindDisplayForId(int64 id) { |
929 for (DisplayList::iterator iter = displays_.begin(); | 956 for (DisplayList::iterator iter = displays_.begin(); |
930 iter != displays_.end(); ++iter) { | 957 iter != displays_.end(); ++iter) { |
931 if ((*iter).id() == id) | 958 if ((*iter).id() == id) |
932 return &(*iter); | 959 return &(*iter); |
933 } | 960 } |
934 DLOG(WARNING) << "Could not find display:" << id; | 961 DLOG(WARNING) << "Could not find display:" << id; |
935 return NULL; | 962 return NULL; |
936 } | 963 } |
937 | 964 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1054 break; | 1081 break; |
1055 } | 1082 } |
1056 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); | 1083 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); |
1057 secondary_display->set_bounds( | 1084 secondary_display->set_bounds( |
1058 gfx::Rect(new_secondary_origin, secondary_bounds.size())); | 1085 gfx::Rect(new_secondary_origin, secondary_bounds.size())); |
1059 secondary_display->UpdateWorkAreaFromInsets(insets); | 1086 secondary_display->UpdateWorkAreaFromInsets(insets); |
1060 } | 1087 } |
1061 | 1088 |
1062 } // namespace internal | 1089 } // namespace internal |
1063 } // namespace ash | 1090 } // namespace ash |
OLD | NEW |