| 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/display/display_info.h" | 9 #include "ash/display/display_info.h" |
| 10 #include "ash/display/display_manager.h" | 10 #include "ash/display/display_manager.h" |
| 11 #include "ash/host/ash_window_tree_host.h" | 11 #include "ash/host/ash_window_tree_host.h" |
| 12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "ui/aura/env.h" | 14 #include "ui/aura/env.h" |
| 15 #include "ui/aura/window_tree_host.h" | 15 #include "ui/aura/window_tree_host.h" |
| 16 #include "ui/gfx/display.h" | 16 #include "ui/display/display.h" |
| 17 #include "ui/gfx/geometry/point.h" | 17 #include "ui/gfx/geometry/point.h" |
| 18 #include "ui/gfx/geometry/rect.h" | 18 #include "ui/gfx/geometry/rect.h" |
| 19 #include "ui/gfx/geometry/size_conversions.h" | 19 #include "ui/gfx/geometry/size_conversions.h" |
| 20 #include "ui/wm/core/coordinate_conversion.h" | 20 #include "ui/wm/core/coordinate_conversion.h" |
| 21 | 21 |
| 22 #if defined(OS_CHROMEOS) | 22 #if defined(OS_CHROMEOS) |
| 23 #include "base/sys_info.h" | 23 #include "base/sys_info.h" |
| 24 #endif | 24 #endif |
| 25 | 25 |
| 26 namespace ash { | 26 namespace ash { |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 [](const DisplayMode& a, const DisplayMode& b) { | 144 [](const DisplayMode& a, const DisplayMode& b) { |
| 145 return a.GetSizeInDIP(false).GetArea() < | 145 return a.GetSizeInDIP(false).GetArea() < |
| 146 b.GetSizeInDIP(false).GetArea(); | 146 b.GetSizeInDIP(false).GetArea(); |
| 147 }); | 147 }); |
| 148 return display_mode_list; | 148 return display_mode_list; |
| 149 } | 149 } |
| 150 | 150 |
| 151 bool GetDisplayModeForResolution(const DisplayInfo& info, | 151 bool GetDisplayModeForResolution(const DisplayInfo& info, |
| 152 const gfx::Size& resolution, | 152 const gfx::Size& resolution, |
| 153 DisplayMode* out) { | 153 DisplayMode* out) { |
| 154 if (gfx::Display::IsInternalDisplayId(info.id())) | 154 if (display::Display::IsInternalDisplayId(info.id())) |
| 155 return false; | 155 return false; |
| 156 | 156 |
| 157 const std::vector<DisplayMode>& modes = info.display_modes(); | 157 const std::vector<DisplayMode>& modes = info.display_modes(); |
| 158 DCHECK_NE(0u, modes.size()); | 158 DCHECK_NE(0u, modes.size()); |
| 159 DisplayMode target_mode; | 159 DisplayMode target_mode; |
| 160 target_mode.size = resolution; | 160 target_mode.size = resolution; |
| 161 std::vector<DisplayMode>::const_iterator iter = std::find_if( | 161 std::vector<DisplayMode>::const_iterator iter = std::find_if( |
| 162 modes.begin(), modes.end(), [resolution](const DisplayMode& mode) { | 162 modes.begin(), modes.end(), [resolution](const DisplayMode& mode) { |
| 163 return mode.size == resolution; | 163 return mode.size == resolution; |
| 164 }); | 164 }); |
| 165 if (iter == modes.end()) { | 165 if (iter == modes.end()) { |
| 166 LOG(WARNING) << "Unsupported resolution was requested:" | 166 LOG(WARNING) << "Unsupported resolution was requested:" |
| 167 << resolution.ToString(); | 167 << resolution.ToString(); |
| 168 return false; | 168 return false; |
| 169 } | 169 } |
| 170 *out = *iter; | 170 *out = *iter; |
| 171 return true; | 171 return true; |
| 172 } | 172 } |
| 173 | 173 |
| 174 bool GetDisplayModeForNextUIScale(const DisplayInfo& info, | 174 bool GetDisplayModeForNextUIScale(const DisplayInfo& info, |
| 175 bool up, | 175 bool up, |
| 176 DisplayMode* out) { | 176 DisplayMode* out) { |
| 177 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 177 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 178 if (!display_manager->IsActiveDisplayId(info.id()) || | 178 if (!display_manager->IsActiveDisplayId(info.id()) || |
| 179 !gfx::Display::IsInternalDisplayId(info.id())) { | 179 !display::Display::IsInternalDisplayId(info.id())) { |
| 180 return false; | 180 return false; |
| 181 } | 181 } |
| 182 const std::vector<DisplayMode>& modes = info.display_modes(); | 182 const std::vector<DisplayMode>& modes = info.display_modes(); |
| 183 ScaleComparator comparator(info.configured_ui_scale()); | 183 ScaleComparator comparator(info.configured_ui_scale()); |
| 184 auto iter = std::find_if(modes.begin(), modes.end(), comparator); | 184 auto iter = std::find_if(modes.begin(), modes.end(), comparator); |
| 185 FindNextMode(iter, modes, up, out); | 185 FindNextMode(iter, modes, up, out); |
| 186 return true; | 186 return true; |
| 187 } | 187 } |
| 188 | 188 |
| 189 bool GetDisplayModeForNextResolution(const DisplayInfo& info, | 189 bool GetDisplayModeForNextResolution(const DisplayInfo& info, |
| 190 bool up, | 190 bool up, |
| 191 DisplayMode* out) { | 191 DisplayMode* out) { |
| 192 if (gfx::Display::IsInternalDisplayId(info.id())) | 192 if (display::Display::IsInternalDisplayId(info.id())) |
| 193 return false; | 193 return false; |
| 194 const std::vector<DisplayMode>& modes = info.display_modes(); | 194 const std::vector<DisplayMode>& modes = info.display_modes(); |
| 195 DisplayMode tmp(info.size_in_pixel(), 0.0f, false, false); | 195 DisplayMode tmp(info.size_in_pixel(), 0.0f, false, false); |
| 196 tmp.device_scale_factor = info.device_scale_factor(); | 196 tmp.device_scale_factor = info.device_scale_factor(); |
| 197 gfx::Size resolution = tmp.GetSizeInDIP(false); | 197 gfx::Size resolution = tmp.GetSizeInDIP(false); |
| 198 auto iter = std::find_if(modes.begin(), modes.end(), | 198 auto iter = std::find_if(modes.begin(), modes.end(), |
| 199 [resolution](const DisplayMode& mode) { | 199 [resolution](const DisplayMode& mode) { |
| 200 return mode.GetSizeInDIP(false) == resolution; | 200 return mode.GetSizeInDIP(false) == resolution; |
| 201 }); | 201 }); |
| 202 FindNextMode(iter, modes, up, out); | 202 FindNextMode(iter, modes, up, out); |
| 203 return true; | 203 return true; |
| 204 } | 204 } |
| 205 | 205 |
| 206 bool SetDisplayUIScale(int64_t id, float ui_scale) { | 206 bool SetDisplayUIScale(int64_t id, float ui_scale) { |
| 207 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 207 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 208 if (!display_manager->IsActiveDisplayId(id) || | 208 if (!display_manager->IsActiveDisplayId(id) || |
| 209 !gfx::Display::IsInternalDisplayId(id)) { | 209 !display::Display::IsInternalDisplayId(id)) { |
| 210 return false; | 210 return false; |
| 211 } | 211 } |
| 212 const DisplayInfo& info = display_manager->GetDisplayInfo(id); | 212 const DisplayInfo& info = display_manager->GetDisplayInfo(id); |
| 213 DisplayMode mode; | 213 DisplayMode mode; |
| 214 if (!GetDisplayModeForUIScale(info, ui_scale, &mode)) | 214 if (!GetDisplayModeForUIScale(info, ui_scale, &mode)) |
| 215 return false; | 215 return false; |
| 216 return display_manager->SetDisplayMode(id, mode); | 216 return display_manager->SetDisplayMode(id, mode); |
| 217 } | 217 } |
| 218 | 218 |
| 219 bool HasDisplayModeForUIScale(const DisplayInfo& info, float ui_scale) { | 219 bool HasDisplayModeForUIScale(const DisplayInfo& info, float ui_scale) { |
| 220 ScaleComparator comparator(ui_scale); | 220 ScaleComparator comparator(ui_scale); |
| 221 const std::vector<DisplayMode>& modes = info.display_modes(); | 221 const std::vector<DisplayMode>& modes = info.display_modes(); |
| 222 return std::find_if(modes.begin(), modes.end(), comparator) != modes.end(); | 222 return std::find_if(modes.begin(), modes.end(), comparator) != modes.end(); |
| 223 } | 223 } |
| 224 | 224 |
| 225 bool ComputeBoundary(const gfx::Display& a_display, | 225 bool ComputeBoundary(const display::Display& a_display, |
| 226 const gfx::Display& b_display, | 226 const display::Display& b_display, |
| 227 gfx::Rect* a_edge_in_screen, | 227 gfx::Rect* a_edge_in_screen, |
| 228 gfx::Rect* b_edge_in_screen) { | 228 gfx::Rect* b_edge_in_screen) { |
| 229 const gfx::Rect& a_bounds = a_display.bounds(); | 229 const gfx::Rect& a_bounds = a_display.bounds(); |
| 230 const gfx::Rect& b_bounds = b_display.bounds(); | 230 const gfx::Rect& b_bounds = b_display.bounds(); |
| 231 | 231 |
| 232 // Find touching side. | 232 // Find touching side. |
| 233 int rx = std::max(a_bounds.x(), b_bounds.x()); | 233 int rx = std::max(a_bounds.x(), b_bounds.x()); |
| 234 int ry = std::max(a_bounds.y(), b_bounds.y()); | 234 int ry = std::max(a_bounds.y(), b_bounds.y()); |
| 235 int rr = std::min(a_bounds.right(), b_bounds.right()); | 235 int rr = std::min(a_bounds.right(), b_bounds.right()); |
| 236 int rb = std::min(a_bounds.bottom(), b_bounds.bottom()); | 236 int rb = std::min(a_bounds.bottom(), b_bounds.bottom()); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 &new_point_in_screen); | 358 &new_point_in_screen); |
| 359 } else { | 359 } else { |
| 360 new_point_in_screen = point_in_native; | 360 new_point_in_screen = point_in_native; |
| 361 host->ConvertPointFromNativeScreen(&new_point_in_screen); | 361 host->ConvertPointFromNativeScreen(&new_point_in_screen); |
| 362 ::wm::ConvertPointToScreen(host->window(), &new_point_in_screen); | 362 ::wm::ConvertPointToScreen(host->window(), &new_point_in_screen); |
| 363 } | 363 } |
| 364 aura::Env::GetInstance()->set_last_mouse_location(new_point_in_screen); | 364 aura::Env::GetInstance()->set_last_mouse_location(new_point_in_screen); |
| 365 } | 365 } |
| 366 } | 366 } |
| 367 | 367 |
| 368 int FindDisplayIndexContainingPoint(const std::vector<gfx::Display>& displays, | 368 int FindDisplayIndexContainingPoint( |
| 369 const gfx::Point& point_in_screen) { | 369 const std::vector<display::Display>& displays, |
| 370 const gfx::Point& point_in_screen) { |
| 370 auto iter = std::find_if(displays.begin(), displays.end(), | 371 auto iter = std::find_if(displays.begin(), displays.end(), |
| 371 [point_in_screen](const gfx::Display& display) { | 372 [point_in_screen](const display::Display& display) { |
| 372 return display.bounds().Contains(point_in_screen); | 373 return display.bounds().Contains(point_in_screen); |
| 373 }); | 374 }); |
| 374 return iter == displays.end() ? -1 : (iter - displays.begin()); | 375 return iter == displays.end() ? -1 : (iter - displays.begin()); |
| 375 } | 376 } |
| 376 | 377 |
| 377 display::DisplayIdList CreateDisplayIdList(const display::DisplayList& list) { | 378 display::DisplayIdList CreateDisplayIdList(const display::DisplayList& list) { |
| 378 return GenerateDisplayIdList( | 379 return GenerateDisplayIdList( |
| 379 list.begin(), list.end(), | 380 list.begin(), list.end(), |
| 380 [](const gfx::Display& display) { return display.id(); }); | 381 [](const display::Display& display) { return display.id(); }); |
| 381 } | 382 } |
| 382 | 383 |
| 383 void SortDisplayIdList(display::DisplayIdList* ids) { | 384 void SortDisplayIdList(display::DisplayIdList* ids) { |
| 384 std::sort(ids->begin(), ids->end(), | 385 std::sort(ids->begin(), ids->end(), |
| 385 [](int64_t a, int64_t b) { return CompareDisplayIds(a, b); }); | 386 [](int64_t a, int64_t b) { return CompareDisplayIds(a, b); }); |
| 386 } | 387 } |
| 387 | 388 |
| 388 std::string DisplayIdListToString(const display::DisplayIdList& list) { | 389 std::string DisplayIdListToString(const display::DisplayIdList& list) { |
| 389 std::stringstream s; | 390 std::stringstream s; |
| 390 const char* sep = ""; | 391 const char* sep = ""; |
| 391 for (int64_t id : list) { | 392 for (int64_t id : list) { |
| 392 s << sep << id; | 393 s << sep << id; |
| 393 sep = ","; | 394 sep = ","; |
| 394 } | 395 } |
| 395 return s.str(); | 396 return s.str(); |
| 396 } | 397 } |
| 397 | 398 |
| 398 bool CompareDisplayIds(int64_t id1, int64_t id2) { | 399 bool CompareDisplayIds(int64_t id1, int64_t id2) { |
| 399 DCHECK_NE(id1, id2); | 400 DCHECK_NE(id1, id2); |
| 400 // Output index is stored in the first 8 bits. See GetDisplayIdFromEDID | 401 // Output index is stored in the first 8 bits. See GetDisplayIdFromEDID |
| 401 // in edid_parser.cc. | 402 // in edid_parser.cc. |
| 402 int index_1 = id1 & 0xFF; | 403 int index_1 = id1 & 0xFF; |
| 403 int index_2 = id2 & 0xFF; | 404 int index_2 = id2 & 0xFF; |
| 404 DCHECK_NE(index_1, index_2) << id1 << " and " << id2; | 405 DCHECK_NE(index_1, index_2) << id1 << " and " << id2; |
| 405 return gfx::Display::IsInternalDisplayId(id1) || | 406 return display::Display::IsInternalDisplayId(id1) || |
| 406 (index_1 < index_2 && !gfx::Display::IsInternalDisplayId(id2)); | 407 (index_1 < index_2 && !display::Display::IsInternalDisplayId(id2)); |
| 407 } | 408 } |
| 408 | 409 |
| 409 } // namespace ash | 410 } // namespace ash |
| OLD | NEW |