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 <limits> | 9 #include <limits> |
10 #include <map> | 10 #include <map> |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 auto iter = std::find_if( | 122 auto iter = std::find_if( |
123 modes.begin(), modes.end(), | 123 modes.begin(), modes.end(), |
124 [ui_scale](const scoped_refptr<display::ManagedDisplayMode>& mode) { | 124 [ui_scale](const scoped_refptr<display::ManagedDisplayMode>& mode) { |
125 return mode->ui_scale() == ui_scale; | 125 return mode->ui_scale() == ui_scale; |
126 }); | 126 }); |
127 if (iter == modes.end()) | 127 if (iter == modes.end()) |
128 return scoped_refptr<display::ManagedDisplayMode>(); | 128 return scoped_refptr<display::ManagedDisplayMode>(); |
129 return *iter; | 129 return *iter; |
130 } | 130 } |
131 | 131 |
132 scoped_refptr<display::ManagedDisplayMode> GetDefaultDisplayMode( | |
133 const display::ManagedDisplayInfo& info) { | |
134 const auto& modes = info.display_modes(); | |
135 auto iter = | |
136 std::find_if(modes.begin(), modes.end(), | |
137 [](const scoped_refptr<display::ManagedDisplayMode>& mode) { | |
138 return mode->is_default(); | |
139 }); | |
140 | |
141 if (iter == modes.end()) | |
142 return scoped_refptr<display::ManagedDisplayMode>(); | |
143 return *iter; | |
144 } | |
145 | |
132 } // namespace | 146 } // namespace |
133 | 147 |
134 using std::string; | 148 using std::string; |
135 using std::vector; | 149 using std::vector; |
136 | 150 |
137 // static | 151 // static |
138 int64_t DisplayManager::kUnifiedDisplayId = -10; | 152 int64_t DisplayManager::kUnifiedDisplayId = -10; |
139 | 153 |
140 DisplayManager::DisplayManager(std::unique_ptr<display::Screen> screen) | 154 DisplayManager::DisplayManager(std::unique_ptr<display::Screen> screen) |
141 : delegate_(nullptr), | 155 : delegate_(nullptr), |
(...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1090 if (!IsActiveDisplayId(display_info.id()) || | 1104 if (!IsActiveDisplayId(display_info.id()) || |
1091 !display::Display::IsInternalDisplayId(display_info.id())) { | 1105 !display::Display::IsInternalDisplayId(display_info.id())) { |
1092 return false; | 1106 return false; |
1093 } | 1107 } |
1094 mode = GetDisplayModeForNextUIScale(display_info, up); | 1108 mode = GetDisplayModeForNextUIScale(display_info, up); |
1095 } | 1109 } |
1096 | 1110 |
1097 return mode ? SetDisplayMode(display_id, mode) : false; | 1111 return mode ? SetDisplayMode(display_id, mode) : false; |
1098 } | 1112 } |
1099 | 1113 |
1100 bool DisplayManager::SetDisplayUIScale(int64_t id, float ui_scale) { | 1114 bool DisplayManager::SetDisplayUIScale(int64_t id, float ui_scale) { |
oshima
2016/10/19 21:04:06
I believe we don't need this other than for tests.
afakhry
2016/10/24 20:21:46
Done.
| |
1101 if (!IsActiveDisplayId(id) || !display::Display::IsInternalDisplayId(id)) { | 1115 if (!IsActiveDisplayId(id) || !display::Display::IsInternalDisplayId(id)) { |
1102 return false; | 1116 return false; |
1103 } | 1117 } |
1104 const display::ManagedDisplayInfo& info = GetDisplayInfo(id); | 1118 const display::ManagedDisplayInfo& info = GetDisplayInfo(id); |
1105 | 1119 |
1106 scoped_refptr<display::ManagedDisplayMode> mode = | 1120 scoped_refptr<display::ManagedDisplayMode> mode = |
1107 GetDisplayModeForUIScale(info, ui_scale); | 1121 GetDisplayModeForUIScale(info, ui_scale); |
1108 if (!mode) | 1122 if (!mode) |
1109 return false; | 1123 return false; |
1110 return SetDisplayMode(id, mode); | 1124 return SetDisplayMode(id, mode); |
1111 } | 1125 } |
1112 | 1126 |
1127 bool DisplayManager::ResetDisplayToDefaultMode(int64_t display_id) { | |
1128 if (!IsActiveDisplayId(display_id)) | |
oshima
2016/10/19 21:04:06
Check internal display as well.
afakhry
2016/10/24 20:21:46
Done.
| |
1129 return false; | |
1130 | |
1131 const display::ManagedDisplayInfo& info = GetDisplayInfo(display_id); | |
1132 scoped_refptr<display::ManagedDisplayMode> mode = GetDefaultDisplayMode(info); | |
1133 | |
1134 return mode ? SetDisplayMode(display_id, mode) : false; | |
1135 } | |
1136 | |
1113 void DisplayManager::ResetInternalDisplayZoom() { | 1137 void DisplayManager::ResetInternalDisplayZoom() { |
1114 if (IsInUnifiedMode()) { | 1138 if (IsInUnifiedMode()) { |
1115 const display::ManagedDisplayInfo& display_info = | 1139 const display::ManagedDisplayInfo& display_info = |
1116 GetDisplayInfo(DisplayManager::kUnifiedDisplayId); | 1140 GetDisplayInfo(DisplayManager::kUnifiedDisplayId); |
1117 const display::ManagedDisplayInfo::ManagedDisplayModeList& modes = | 1141 const display::ManagedDisplayInfo::ManagedDisplayModeList& modes = |
1118 display_info.display_modes(); | 1142 display_info.display_modes(); |
1119 auto iter = std::find_if( | 1143 auto iter = std::find_if( |
1120 modes.begin(), modes.end(), | 1144 modes.begin(), modes.end(), |
1121 [](const scoped_refptr<display::ManagedDisplayMode>& mode) { | 1145 [](const scoped_refptr<display::ManagedDisplayMode>& mode) { |
1122 return mode->native(); | 1146 return mode->native(); |
1123 }); | 1147 }); |
1124 SetDisplayMode(kUnifiedDisplayId, *iter); | 1148 SetDisplayMode(kUnifiedDisplayId, *iter); |
1125 } else { | 1149 } else { |
1126 SetDisplayUIScale(GetDisplayIdForUIScaling(), 1.0f); | 1150 ResetDisplayToDefaultMode(GetDisplayIdForUIScaling()); |
1127 } | 1151 } |
1128 } | 1152 } |
1129 | 1153 |
1130 void DisplayManager::CreateSoftwareMirroringDisplayInfo( | 1154 void DisplayManager::CreateSoftwareMirroringDisplayInfo( |
1131 DisplayInfoList* display_info_list) { | 1155 DisplayInfoList* display_info_list) { |
1132 // Use the internal display or 1st as the mirror source, then scale | 1156 // Use the internal display or 1st as the mirror source, then scale |
1133 // the root window so that it matches the external display's | 1157 // the root window so that it matches the external display's |
1134 // resolution. This is necessary in order for scaling to work while | 1158 // resolution. This is necessary in order for scaling to work while |
1135 // mirrored. | 1159 // mirrored. |
1136 switch (multi_display_mode_) { | 1160 switch (multi_display_mode_) { |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1433 | 1457 |
1434 const display::Display& DisplayManager::GetSecondaryDisplay() const { | 1458 const display::Display& DisplayManager::GetSecondaryDisplay() const { |
1435 CHECK_LE(2U, GetNumDisplays()); | 1459 CHECK_LE(2U, GetNumDisplays()); |
1436 return GetDisplayAt(0).id() == | 1460 return GetDisplayAt(0).id() == |
1437 display::Screen::GetScreen()->GetPrimaryDisplay().id() | 1461 display::Screen::GetScreen()->GetPrimaryDisplay().id() |
1438 ? GetDisplayAt(1) | 1462 ? GetDisplayAt(1) |
1439 : GetDisplayAt(0); | 1463 : GetDisplayAt(0); |
1440 } | 1464 } |
1441 | 1465 |
1442 } // namespace ash | 1466 } // namespace ash |
OLD | NEW |