OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_util.h" | 5 #include "ash/display/display_util.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ash/common/display/display_info.h" | |
10 #include "ash/common/new_window_delegate.h" | 9 #include "ash/common/new_window_delegate.h" |
11 #include "ash/common/system/system_notifier.h" | 10 #include "ash/common/system/system_notifier.h" |
12 #include "ash/common/wm_shell.h" | 11 #include "ash/common/wm_shell.h" |
13 #include "ash/display/display_manager.h" | 12 #include "ash/display/display_manager.h" |
14 #include "ash/host/ash_window_tree_host.h" | 13 #include "ash/host/ash_window_tree_host.h" |
15 #include "ash/shell.h" | 14 #include "ash/shell.h" |
16 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
17 #include "grit/ash_resources.h" | 16 #include "grit/ash_resources.h" |
18 #include "ui/aura/env.h" | 17 #include "ui/aura/env.h" |
19 #include "ui/aura/window_tree_host.h" | 18 #include "ui/aura/window_tree_host.h" |
20 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
21 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
22 #include "ui/display/display.h" | 21 #include "ui/display/display.h" |
| 22 #include "ui/display/manager/managed_display_info.h" |
23 #include "ui/gfx/geometry/point.h" | 23 #include "ui/gfx/geometry/point.h" |
24 #include "ui/gfx/geometry/rect.h" | 24 #include "ui/gfx/geometry/rect.h" |
25 #include "ui/gfx/geometry/size_conversions.h" | 25 #include "ui/gfx/geometry/size_conversions.h" |
26 #include "ui/message_center/message_center.h" | 26 #include "ui/message_center/message_center.h" |
27 #include "ui/message_center/notification.h" | 27 #include "ui/message_center/notification.h" |
28 #include "ui/message_center/notification_delegate.h" | 28 #include "ui/message_center/notification_delegate.h" |
29 #include "ui/message_center/notification_list.h" | 29 #include "ui/message_center/notification_list.h" |
30 #include "ui/wm/core/coordinate_conversion.h" | 30 #include "ui/wm/core/coordinate_conversion.h" |
31 | 31 |
32 #if defined(OS_CHROMEOS) | 32 #if defined(OS_CHROMEOS) |
(...skipping 30 matching lines...) Expand all Loading... |
63 // 800, 1024, 1280, 1440, 1600 and 1920 pixel width respectively on | 63 // 800, 1024, 1280, 1440, 1600 and 1920 pixel width respectively on |
64 // 2560 pixel width 2x density display. Please see crbug.com/233375 | 64 // 2560 pixel width 2x density display. Please see crbug.com/233375 |
65 // for the full list of resolutions. | 65 // for the full list of resolutions. |
66 const float kUIScalesFor2x[] = {0.5f, 0.625f, 0.8f, 1.0f, | 66 const float kUIScalesFor2x[] = {0.5f, 0.625f, 0.8f, 1.0f, |
67 1.125f, 1.25f, 1.5f, 2.0f}; | 67 1.125f, 1.25f, 1.5f, 2.0f}; |
68 const float kUIScalesFor1_25x[] = {0.5f, 0.625f, 0.8f, 1.0f, 1.25f}; | 68 const float kUIScalesFor1_25x[] = {0.5f, 0.625f, 0.8f, 1.0f, 1.25f}; |
69 const float kUIScalesFor1280[] = {0.5f, 0.625f, 0.8f, 1.0f, 1.125f}; | 69 const float kUIScalesFor1280[] = {0.5f, 0.625f, 0.8f, 1.0f, 1.125f}; |
70 const float kUIScalesFor1366[] = {0.5f, 0.6f, 0.75f, 1.0f, 1.125f}; | 70 const float kUIScalesFor1366[] = {0.5f, 0.6f, 0.75f, 1.0f, 1.125f}; |
71 | 71 |
72 std::vector<float> GetScalesForDisplay( | 72 std::vector<float> GetScalesForDisplay( |
73 const scoped_refptr<ManagedDisplayMode>& native_mode) { | 73 const scoped_refptr<display::ManagedDisplayMode>& native_mode) { |
74 #define ASSIGN_ARRAY(v, a) v.assign(a, a + arraysize(a)) | 74 #define ASSIGN_ARRAY(v, a) v.assign(a, a + arraysize(a)) |
75 | 75 |
76 std::vector<float> ret; | 76 std::vector<float> ret; |
77 if (native_mode->device_scale_factor() == 2.0f) { | 77 if (native_mode->device_scale_factor() == 2.0f) { |
78 ASSIGN_ARRAY(ret, kUIScalesFor2x); | 78 ASSIGN_ARRAY(ret, kUIScalesFor2x); |
79 return ret; | 79 return ret; |
80 } else if (native_mode->device_scale_factor() == 1.25f) { | 80 } else if (native_mode->device_scale_factor() == 1.25f) { |
81 ASSIGN_ARRAY(ret, kUIScalesFor1_25x); | 81 ASSIGN_ARRAY(ret, kUIScalesFor1_25x); |
82 return ret; | 82 return ret; |
83 } | 83 } |
(...skipping 10 matching lines...) Expand all Loading... |
94 if (base::SysInfo::IsRunningOnChromeOS()) | 94 if (base::SysInfo::IsRunningOnChromeOS()) |
95 NOTREACHED() << "Unknown resolution:" << native_mode->size().ToString(); | 95 NOTREACHED() << "Unknown resolution:" << native_mode->size().ToString(); |
96 #endif | 96 #endif |
97 } | 97 } |
98 return ret; | 98 return ret; |
99 } | 99 } |
100 | 100 |
101 struct ScaleComparator { | 101 struct ScaleComparator { |
102 explicit ScaleComparator(float s) : scale(s) {} | 102 explicit ScaleComparator(float s) : scale(s) {} |
103 | 103 |
104 bool operator()(const scoped_refptr<ManagedDisplayMode>& mode) const { | 104 bool operator()( |
| 105 const scoped_refptr<display::ManagedDisplayMode>& mode) const { |
105 const float kEpsilon = 0.0001f; | 106 const float kEpsilon = 0.0001f; |
106 return std::abs(scale - mode->ui_scale()) < kEpsilon; | 107 return std::abs(scale - mode->ui_scale()) < kEpsilon; |
107 } | 108 } |
108 float scale; | 109 float scale; |
109 }; | 110 }; |
110 | 111 |
111 void ConvertPointFromScreenToNative(aura::WindowTreeHost* host, | 112 void ConvertPointFromScreenToNative(aura::WindowTreeHost* host, |
112 gfx::Point* point) { | 113 gfx::Point* point) { |
113 ::wm::ConvertPointFromScreen(host->window(), point); | 114 ::wm::ConvertPointFromScreen(host->window(), point); |
114 host->ConvertPointToNativeScreen(point); | 115 host->ConvertPointToNativeScreen(point); |
115 } | 116 } |
116 | 117 |
117 scoped_refptr<ManagedDisplayMode> GetDisplayModeForUIScale( | 118 scoped_refptr<display::ManagedDisplayMode> GetDisplayModeForUIScale( |
118 const DisplayInfo& info, | 119 const display::ManagedDisplayInfo& info, |
119 float ui_scale) { | 120 float ui_scale) { |
120 const DisplayInfo::ManagedDisplayModeList& modes = info.display_modes(); | 121 const display::ManagedDisplayInfo::ManagedDisplayModeList& modes = |
121 auto iter = | 122 info.display_modes(); |
122 std::find_if(modes.begin(), modes.end(), | 123 auto iter = std::find_if( |
123 [ui_scale](const scoped_refptr<ManagedDisplayMode>& mode) { | 124 modes.begin(), modes.end(), |
124 return mode->ui_scale() == ui_scale; | 125 [ui_scale](const scoped_refptr<display::ManagedDisplayMode>& mode) { |
125 }); | 126 return mode->ui_scale() == ui_scale; |
| 127 }); |
126 if (iter == modes.end()) | 128 if (iter == modes.end()) |
127 return scoped_refptr<ManagedDisplayMode>(); | 129 return scoped_refptr<display::ManagedDisplayMode>(); |
128 return *iter; | 130 return *iter; |
129 } | 131 } |
130 | 132 |
131 scoped_refptr<ManagedDisplayMode> FindNextMode( | 133 scoped_refptr<display::ManagedDisplayMode> FindNextMode( |
132 const DisplayInfo::ManagedDisplayModeList& modes, | 134 const display::ManagedDisplayInfo::ManagedDisplayModeList& modes, |
133 size_t index, | 135 size_t index, |
134 bool up) { | 136 bool up) { |
135 DCHECK_LT(index, modes.size()); | 137 DCHECK_LT(index, modes.size()); |
136 size_t new_index = index; | 138 size_t new_index = index; |
137 if (up && (index + 1 < modes.size())) | 139 if (up && (index + 1 < modes.size())) |
138 ++new_index; | 140 ++new_index; |
139 else if (!up && index != 0) | 141 else if (!up && index != 0) |
140 --new_index; | 142 --new_index; |
141 return modes[new_index]; | 143 return modes[new_index]; |
142 } | 144 } |
143 | 145 |
144 } // namespace | 146 } // namespace |
145 | 147 |
146 DisplayInfo::ManagedDisplayModeList CreateInternalManagedDisplayModeList( | 148 display::ManagedDisplayInfo::ManagedDisplayModeList |
147 const scoped_refptr<ManagedDisplayMode>& native_mode) { | 149 CreateInternalManagedDisplayModeList( |
148 DisplayInfo::ManagedDisplayModeList display_mode_list; | 150 const scoped_refptr<display::ManagedDisplayMode>& native_mode) { |
| 151 display::ManagedDisplayInfo::ManagedDisplayModeList display_mode_list; |
149 | 152 |
150 float native_ui_scale = (native_mode->device_scale_factor() == 1.25f) | 153 float native_ui_scale = (native_mode->device_scale_factor() == 1.25f) |
151 ? 1.0f | 154 ? 1.0f |
152 : native_mode->device_scale_factor(); | 155 : native_mode->device_scale_factor(); |
153 for (float ui_scale : GetScalesForDisplay(native_mode)) { | 156 for (float ui_scale : GetScalesForDisplay(native_mode)) { |
154 scoped_refptr<ManagedDisplayMode> mode(new ManagedDisplayMode( | 157 scoped_refptr<display::ManagedDisplayMode> mode( |
155 native_mode->size(), native_mode->refresh_rate(), | 158 new display::ManagedDisplayMode( |
156 native_mode->is_interlaced(), ui_scale == native_ui_scale, ui_scale, | 159 native_mode->size(), native_mode->refresh_rate(), |
157 native_mode->device_scale_factor())); | 160 native_mode->is_interlaced(), ui_scale == native_ui_scale, ui_scale, |
| 161 native_mode->device_scale_factor())); |
158 display_mode_list.push_back(mode); | 162 display_mode_list.push_back(mode); |
159 } | 163 } |
160 return display_mode_list; | 164 return display_mode_list; |
161 } | 165 } |
162 | 166 |
163 DisplayInfo::ManagedDisplayModeList CreateUnifiedManagedDisplayModeList( | 167 display::ManagedDisplayInfo::ManagedDisplayModeList |
164 const scoped_refptr<ManagedDisplayMode>& native_mode, | 168 CreateUnifiedManagedDisplayModeList( |
| 169 const scoped_refptr<display::ManagedDisplayMode>& native_mode, |
165 const std::set<std::pair<float, float>>& dsf_scale_list) { | 170 const std::set<std::pair<float, float>>& dsf_scale_list) { |
166 DisplayInfo::ManagedDisplayModeList display_mode_list; | 171 display::ManagedDisplayInfo::ManagedDisplayModeList display_mode_list; |
167 | 172 |
168 for (auto& pair : dsf_scale_list) { | 173 for (auto& pair : dsf_scale_list) { |
169 gfx::SizeF scaled_size(native_mode->size()); | 174 gfx::SizeF scaled_size(native_mode->size()); |
170 scaled_size.Scale(pair.second); | 175 scaled_size.Scale(pair.second); |
171 scoped_refptr<ManagedDisplayMode> mode(new ManagedDisplayMode( | 176 scoped_refptr<display::ManagedDisplayMode> mode( |
172 gfx::ToFlooredSize(scaled_size), native_mode->refresh_rate(), | 177 new display::ManagedDisplayMode( |
173 native_mode->is_interlaced(), false /* native */, | 178 gfx::ToFlooredSize(scaled_size), native_mode->refresh_rate(), |
174 native_mode->ui_scale(), pair.first /* device_scale_factor */)); | 179 native_mode->is_interlaced(), false /* native */, |
| 180 native_mode->ui_scale(), pair.first /* device_scale_factor */)); |
175 display_mode_list.push_back(mode); | 181 display_mode_list.push_back(mode); |
176 } | 182 } |
177 // Sort the mode by the size in DIP. | 183 // Sort the mode by the size in DIP. |
178 std::sort(display_mode_list.begin(), display_mode_list.end(), | 184 std::sort(display_mode_list.begin(), display_mode_list.end(), |
179 [](const scoped_refptr<ManagedDisplayMode>& a, | 185 [](const scoped_refptr<display::ManagedDisplayMode>& a, |
180 const scoped_refptr<ManagedDisplayMode>& b) { | 186 const scoped_refptr<display::ManagedDisplayMode>& b) { |
181 return a->GetSizeInDIP(false).GetArea() < | 187 return a->GetSizeInDIP(false).GetArea() < |
182 b->GetSizeInDIP(false).GetArea(); | 188 b->GetSizeInDIP(false).GetArea(); |
183 }); | 189 }); |
184 return display_mode_list; | 190 return display_mode_list; |
185 } | 191 } |
186 | 192 |
187 scoped_refptr<ManagedDisplayMode> GetDisplayModeForResolution( | 193 scoped_refptr<display::ManagedDisplayMode> GetDisplayModeForResolution( |
188 const DisplayInfo& info, | 194 const display::ManagedDisplayInfo& info, |
189 const gfx::Size& resolution) { | 195 const gfx::Size& resolution) { |
190 if (display::Display::IsInternalDisplayId(info.id())) | 196 if (display::Display::IsInternalDisplayId(info.id())) |
191 return scoped_refptr<ManagedDisplayMode>(); | 197 return scoped_refptr<display::ManagedDisplayMode>(); |
192 | 198 |
193 const DisplayInfo::ManagedDisplayModeList& modes = info.display_modes(); | 199 const display::ManagedDisplayInfo::ManagedDisplayModeList& modes = |
| 200 info.display_modes(); |
194 DCHECK_NE(0u, modes.size()); | 201 DCHECK_NE(0u, modes.size()); |
195 scoped_refptr<ManagedDisplayMode> target_mode; | 202 scoped_refptr<display::ManagedDisplayMode> target_mode; |
196 DisplayInfo::ManagedDisplayModeList::const_iterator iter = | 203 display::ManagedDisplayInfo::ManagedDisplayModeList::const_iterator iter = |
197 std::find_if(modes.begin(), modes.end(), | 204 std::find_if( |
198 [resolution](const scoped_refptr<ManagedDisplayMode>& mode) { | 205 modes.begin(), modes.end(), |
199 return mode->size() == resolution; | 206 [resolution](const scoped_refptr<display::ManagedDisplayMode>& mode) { |
200 }); | 207 return mode->size() == resolution; |
| 208 }); |
201 if (iter == modes.end()) { | 209 if (iter == modes.end()) { |
202 LOG(WARNING) << "Unsupported resolution was requested:" | 210 LOG(WARNING) << "Unsupported resolution was requested:" |
203 << resolution.ToString(); | 211 << resolution.ToString(); |
204 return scoped_refptr<ManagedDisplayMode>(); | 212 return scoped_refptr<display::ManagedDisplayMode>(); |
205 } | 213 } |
206 return *iter; | 214 return *iter; |
207 } | 215 } |
208 | 216 |
209 scoped_refptr<ManagedDisplayMode> GetDisplayModeForNextUIScale( | 217 scoped_refptr<display::ManagedDisplayMode> GetDisplayModeForNextUIScale( |
210 const DisplayInfo& info, | 218 const display::ManagedDisplayInfo& info, |
211 bool up) { | 219 bool up) { |
212 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 220 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
213 if (!display_manager->IsActiveDisplayId(info.id()) || | 221 if (!display_manager->IsActiveDisplayId(info.id()) || |
214 !display::Display::IsInternalDisplayId(info.id())) { | 222 !display::Display::IsInternalDisplayId(info.id())) { |
215 return scoped_refptr<ManagedDisplayMode>(); | 223 return scoped_refptr<display::ManagedDisplayMode>(); |
216 } | 224 } |
217 const DisplayInfo::ManagedDisplayModeList& modes = info.display_modes(); | 225 const display::ManagedDisplayInfo::ManagedDisplayModeList& modes = |
| 226 info.display_modes(); |
218 ScaleComparator comparator(info.configured_ui_scale()); | 227 ScaleComparator comparator(info.configured_ui_scale()); |
219 auto iter = std::find_if(modes.begin(), modes.end(), comparator); | 228 auto iter = std::find_if(modes.begin(), modes.end(), comparator); |
220 return FindNextMode(modes, iter - modes.begin(), up); | 229 return FindNextMode(modes, iter - modes.begin(), up); |
221 } | 230 } |
222 | 231 |
223 scoped_refptr<ManagedDisplayMode> GetDisplayModeForNextResolution( | 232 scoped_refptr<display::ManagedDisplayMode> GetDisplayModeForNextResolution( |
224 const DisplayInfo& info, | 233 const display::ManagedDisplayInfo& info, |
225 bool up) { | 234 bool up) { |
226 if (display::Display::IsInternalDisplayId(info.id())) | 235 if (display::Display::IsInternalDisplayId(info.id())) |
227 return scoped_refptr<ManagedDisplayMode>(); | 236 return scoped_refptr<display::ManagedDisplayMode>(); |
228 | 237 |
229 const DisplayInfo::ManagedDisplayModeList& modes = info.display_modes(); | 238 const display::ManagedDisplayInfo::ManagedDisplayModeList& modes = |
230 scoped_refptr<ManagedDisplayMode> tmp = new ManagedDisplayMode( | 239 info.display_modes(); |
231 info.size_in_pixel(), 0.0, false, false, 1.0, info.device_scale_factor()); | 240 scoped_refptr<display::ManagedDisplayMode> tmp = |
| 241 new display::ManagedDisplayMode(info.size_in_pixel(), 0.0, false, false, |
| 242 1.0, info.device_scale_factor()); |
232 gfx::Size resolution = tmp->GetSizeInDIP(false); | 243 gfx::Size resolution = tmp->GetSizeInDIP(false); |
233 | 244 |
234 auto iter = | 245 auto iter = std::find_if( |
235 std::find_if(modes.begin(), modes.end(), | 246 modes.begin(), modes.end(), |
236 [resolution](const scoped_refptr<ManagedDisplayMode>& mode) { | 247 [resolution](const scoped_refptr<display::ManagedDisplayMode>& mode) { |
237 return mode->GetSizeInDIP(false) == resolution; | 248 return mode->GetSizeInDIP(false) == resolution; |
238 }); | 249 }); |
239 return FindNextMode(modes, iter - modes.begin(), up); | 250 return FindNextMode(modes, iter - modes.begin(), up); |
240 } | 251 } |
241 | 252 |
242 bool SetDisplayUIScale(int64_t id, float ui_scale) { | 253 bool SetDisplayUIScale(int64_t id, float ui_scale) { |
243 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 254 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
244 if (!display_manager->IsActiveDisplayId(id) || | 255 if (!display_manager->IsActiveDisplayId(id) || |
245 !display::Display::IsInternalDisplayId(id)) { | 256 !display::Display::IsInternalDisplayId(id)) { |
246 return false; | 257 return false; |
247 } | 258 } |
248 const DisplayInfo& info = display_manager->GetDisplayInfo(id); | 259 const display::ManagedDisplayInfo& info = display_manager->GetDisplayInfo(id); |
249 | 260 |
250 scoped_refptr<ManagedDisplayMode> mode = | 261 scoped_refptr<display::ManagedDisplayMode> mode = |
251 GetDisplayModeForUIScale(info, ui_scale); | 262 GetDisplayModeForUIScale(info, ui_scale); |
252 if (!mode) | 263 if (!mode) |
253 return false; | 264 return false; |
254 return display_manager->SetDisplayMode(id, mode); | 265 return display_manager->SetDisplayMode(id, mode); |
255 } | 266 } |
256 | 267 |
257 bool HasDisplayModeForUIScale(const DisplayInfo& info, float ui_scale) { | 268 bool HasDisplayModeForUIScale(const display::ManagedDisplayInfo& info, |
| 269 float ui_scale) { |
258 ScaleComparator comparator(ui_scale); | 270 ScaleComparator comparator(ui_scale); |
259 const DisplayInfo::ManagedDisplayModeList& modes = info.display_modes(); | 271 const display::ManagedDisplayInfo::ManagedDisplayModeList& modes = |
| 272 info.display_modes(); |
260 return std::find_if(modes.begin(), modes.end(), comparator) != modes.end(); | 273 return std::find_if(modes.begin(), modes.end(), comparator) != modes.end(); |
261 } | 274 } |
262 | 275 |
263 bool ComputeBoundary(const display::Display& a_display, | 276 bool ComputeBoundary(const display::Display& a_display, |
264 const display::Display& b_display, | 277 const display::Display& b_display, |
265 gfx::Rect* a_edge_in_screen, | 278 gfx::Rect* a_edge_in_screen, |
266 gfx::Rect* b_edge_in_screen) { | 279 gfx::Rect* b_edge_in_screen) { |
267 const gfx::Rect& a_bounds = a_display.bounds(); | 280 const gfx::Rect& a_bounds = a_display.bounds(); |
268 const gfx::Rect& b_bounds = b_display.bounds(); | 281 const gfx::Rect& b_bounds = b_display.bounds(); |
269 | 282 |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 message_center::NotificationList::Notifications notifications = | 487 message_center::NotificationList::Notifications notifications = |
475 message_center::MessageCenter::Get()->GetVisibleNotifications(); | 488 message_center::MessageCenter::Get()->GetVisibleNotifications(); |
476 for (auto* const notification : notifications) { | 489 for (auto* const notification : notifications) { |
477 if (notification->id() == kDisplayErrorNotificationId) | 490 if (notification->id() == kDisplayErrorNotificationId) |
478 return notification->message(); | 491 return notification->message(); |
479 } | 492 } |
480 return base::string16(); | 493 return base::string16(); |
481 } | 494 } |
482 | 495 |
483 } // namespace ash | 496 } // namespace ash |
OLD | NEW |