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 <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 !removed_displays.empty() && | 803 !removed_displays.empty() && |
804 !(removed_displays.size() == 1 && added_display_indices.size() == 1); | 804 !(removed_displays.size() == 1 && added_display_indices.size() == 1); |
805 if (delegate_) | 805 if (delegate_) |
806 delegate_->PreDisplayConfigurationChange(clear_focus); | 806 delegate_->PreDisplayConfigurationChange(clear_focus); |
807 | 807 |
808 // Do not update |displays_| if there's nothing to be updated. Without this, | 808 // Do not update |displays_| if there's nothing to be updated. Without this, |
809 // it will not update the display layout, which causes the bug | 809 // it will not update the display layout, which causes the bug |
810 // http://crbug.com/155948. | 810 // http://crbug.com/155948. |
811 if (display_changes.empty() && added_display_indices.empty() && | 811 if (display_changes.empty() && added_display_indices.empty() && |
812 removed_displays.empty()) { | 812 removed_displays.empty()) { |
813 // When changing from software mirroring mode to sinlge display mode, it | 813 // When changing from software mirroring mode to sinlge display |
814 // is possible there is no need to update |displays_| and we early out | 814 // mode, it is possible there is no need to update |displays_| and |
815 // here. But we still want to run the PostDisplayConfigurationChange() | 815 // we early out here. But we still need to update the mirroring |
816 // cause there are some clients need to act on this, e.g. | 816 // window and call the PostDisplayConfigurationChange() cause |
817 // TouchTransformerController needs to adjust the TouchTransformer when | 817 // there are some clients need to act on this, |
818 // switching from dual displays to single display. | 818 // e.g. TouchTransformerController needs to adjust the |
819 if (delegate_) | 819 // TouchTransformer when/ switching from dual displays to single |
| 820 // display. |
| 821 if (delegate_) { |
| 822 if (HasSoftwareMirroringDisplay()) |
| 823 CreateMirrorWindowAsyncIfAny(); |
| 824 else |
| 825 delegate_->CloseMirroringDisplay(); |
820 delegate_->PostDisplayConfigurationChange(); | 826 delegate_->PostDisplayConfigurationChange(); |
| 827 } |
821 return; | 828 return; |
822 } | 829 } |
823 | 830 |
824 std::vector<size_t> updated_indices; | 831 std::vector<size_t> updated_indices; |
825 if (UpdateNonPrimaryDisplayBoundsForLayout(&new_displays, &updated_indices)) { | 832 if (UpdateNonPrimaryDisplayBoundsForLayout(&new_displays, &updated_indices)) { |
826 for (std::vector<size_t>::iterator it = updated_indices.begin(); | 833 for (std::vector<size_t>::iterator it = updated_indices.begin(); |
827 it != updated_indices.end(); ++it) { | 834 it != updated_indices.end(); ++it) { |
828 size_t updated_index = *it; | 835 size_t updated_index = *it; |
829 if (std::find(added_display_indices.begin(), | 836 if (std::find(added_display_indices.begin(), |
830 added_display_indices.end(), | 837 added_display_indices.end(), |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
904 delegate_->PostDisplayConfigurationChange(); | 911 delegate_->PostDisplayConfigurationChange(); |
905 | 912 |
906 #if defined(USE_X11) && defined(OS_CHROMEOS) | 913 #if defined(USE_X11) && defined(OS_CHROMEOS) |
907 if (!display_changes.empty() && base::SysInfo::IsRunningOnChromeOS()) | 914 if (!display_changes.empty() && base::SysInfo::IsRunningOnChromeOS()) |
908 ui::ClearX11DefaultRootWindow(); | 915 ui::ClearX11DefaultRootWindow(); |
909 #endif | 916 #endif |
910 | 917 |
911 // Create the mirroring window asynchronously after all displays | 918 // Create the mirroring window asynchronously after all displays |
912 // are added so that it can mirror the display newly added. This can | 919 // are added so that it can mirror the display newly added. This can |
913 // happen when switching from dock mode to software mirror mode. | 920 // happen when switching from dock mode to software mirror mode. |
914 if (has_mirroring_display && delegate_) | 921 CreateMirrorWindowAsyncIfAny(); |
915 CreateMirrorWindowAsyncIfAny(); | |
916 } | 922 } |
917 | 923 |
918 const gfx::Display& DisplayManager::GetDisplayAt(size_t index) const { | 924 const gfx::Display& DisplayManager::GetDisplayAt(size_t index) const { |
919 DCHECK_LT(index, displays_.size()); | 925 DCHECK_LT(index, displays_.size()); |
920 return displays_[index]; | 926 return displays_[index]; |
921 } | 927 } |
922 | 928 |
923 const gfx::Display& DisplayManager::GetPrimaryDisplayCandidate() const { | 929 const gfx::Display& DisplayManager::GetPrimaryDisplayCandidate() const { |
924 if (GetNumDisplays() != 2) | 930 if (GetNumDisplays() != 2) |
925 return displays_[0]; | 931 return displays_[0]; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1055 gfx::Display* display = FindDisplayForId(display_id); | 1061 gfx::Display* display = FindDisplayForId(display_id); |
1056 display->SetSize(display_info_[display_id].size_in_pixel()); | 1062 display->SetSize(display_info_[display_id].size_in_pixel()); |
1057 screen_ash_->NotifyMetricsChanged( | 1063 screen_ash_->NotifyMetricsChanged( |
1058 *display, gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS); | 1064 *display, gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS); |
1059 return true; | 1065 return true; |
1060 } | 1066 } |
1061 return false; | 1067 return false; |
1062 } | 1068 } |
1063 | 1069 |
1064 void DisplayManager::CreateMirrorWindowAsyncIfAny() { | 1070 void DisplayManager::CreateMirrorWindowAsyncIfAny() { |
| 1071 // Do not post a task if the software mirroring doesn't exist. |
| 1072 if (!HasSoftwareMirroringDisplay() || !delegate_) |
| 1073 return; |
1065 base::MessageLoopForUI::current()->PostTask( | 1074 base::MessageLoopForUI::current()->PostTask( |
1066 FROM_HERE, | 1075 FROM_HERE, |
1067 base::Bind(&DisplayManager::CreateMirrorWindowIfAny, | 1076 base::Bind(&DisplayManager::CreateMirrorWindowIfAny, |
1068 weak_ptr_factory_.GetWeakPtr())); | 1077 weak_ptr_factory_.GetWeakPtr())); |
1069 } | 1078 } |
1070 | 1079 |
1071 void DisplayManager::CreateScreenForShutdown() const { | 1080 void DisplayManager::CreateScreenForShutdown() const { |
1072 bool native_is_ash = | 1081 bool native_is_ash = |
1073 gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE) == | 1082 gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE) == |
1074 screen_ash_.get(); | 1083 screen_ash_.get(); |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1255 new_secondary_origin.Offset(-secondary_bounds.width(), offset); | 1264 new_secondary_origin.Offset(-secondary_bounds.width(), offset); |
1256 break; | 1265 break; |
1257 } | 1266 } |
1258 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); | 1267 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); |
1259 secondary_display->set_bounds( | 1268 secondary_display->set_bounds( |
1260 gfx::Rect(new_secondary_origin, secondary_bounds.size())); | 1269 gfx::Rect(new_secondary_origin, secondary_bounds.size())); |
1261 secondary_display->UpdateWorkAreaFromInsets(insets); | 1270 secondary_display->UpdateWorkAreaFromInsets(insets); |
1262 } | 1271 } |
1263 | 1272 |
1264 } // namespace ash | 1273 } // namespace ash |
OLD | NEW |