| 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" |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 void ComputeBoundary(const gfx::Display& a_display, | 225 bool ComputeBoundary(const gfx::Display& a_display, |
| 226 const gfx::Display& b_display, | 226 const gfx::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()); |
| 237 | 237 |
| 238 DisplayPlacement::Position position; | 238 DisplayPlacement::Position position; |
| 239 if ((rb - ry) == 0) { | 239 if ((rb - ry) == 0) { |
| 240 // top bottom | 240 // top bottom |
| 241 if (a_bounds.bottom() == b_bounds.y()) { | 241 if (a_bounds.bottom() == b_bounds.y()) { |
| 242 position = DisplayPlacement::BOTTOM; | 242 position = DisplayPlacement::BOTTOM; |
| 243 } else if (a_bounds.y() == b_bounds.bottom()) { |
| 244 position = DisplayPlacement::TOP; |
| 243 } else { | 245 } else { |
| 244 DCHECK_EQ(a_bounds.y(), b_bounds.bottom()); | 246 return false; |
| 245 position = DisplayPlacement::TOP; | |
| 246 } | 247 } |
| 247 } else { | 248 } else { |
| 248 DCHECK((rr - rx) == 0); | |
| 249 // left right | 249 // left right |
| 250 if (a_bounds.right() == b_bounds.x()) { | 250 if (a_bounds.right() == b_bounds.x()) { |
| 251 position = DisplayPlacement::RIGHT; | 251 position = DisplayPlacement::RIGHT; |
| 252 } else if (a_bounds.x() == b_bounds.right()) { |
| 253 position = DisplayPlacement::LEFT; |
| 252 } else { | 254 } else { |
| 253 DCHECK_EQ(a_bounds.x(), b_bounds.right()); | 255 DCHECK_NE(rr, rx); |
| 254 position = DisplayPlacement::LEFT; | 256 return false; |
| 255 } | 257 } |
| 256 } | 258 } |
| 257 | 259 |
| 258 switch (position) { | 260 switch (position) { |
| 259 case DisplayPlacement::TOP: | 261 case DisplayPlacement::TOP: |
| 260 case DisplayPlacement::BOTTOM: { | 262 case DisplayPlacement::BOTTOM: { |
| 261 int left = std::max(a_bounds.x(), b_bounds.x()); | 263 int left = std::max(a_bounds.x(), b_bounds.x()); |
| 262 int right = std::min(a_bounds.right(), b_bounds.right()); | 264 int right = std::min(a_bounds.right(), b_bounds.right()); |
| 263 if (position == DisplayPlacement::TOP) { | 265 if (position == DisplayPlacement::TOP) { |
| 264 a_edge_in_screen->SetRect(left, a_bounds.y(), right - left, 1); | 266 a_edge_in_screen->SetRect(left, a_bounds.y(), right - left, 1); |
| 265 b_edge_in_screen->SetRect(left, b_bounds.bottom() - 1, right - left, 1); | 267 b_edge_in_screen->SetRect(left, b_bounds.bottom() - 1, right - left, 1); |
| 266 } else { | 268 } else { |
| 267 a_edge_in_screen->SetRect(left, a_bounds.bottom() - 1, right - left, 1); | 269 a_edge_in_screen->SetRect(left, a_bounds.bottom() - 1, right - left, 1); |
| 268 b_edge_in_screen->SetRect(left, b_bounds.y(), right - left, 1); | 270 b_edge_in_screen->SetRect(left, b_bounds.y(), right - left, 1); |
| 269 } | 271 } |
| 270 break; | 272 break; |
| 271 } | 273 } |
| 272 case DisplayPlacement::LEFT: | 274 case DisplayPlacement::LEFT: |
| 273 case DisplayPlacement::RIGHT: { | 275 case DisplayPlacement::RIGHT: { |
| 274 int top = std::max(a_bounds.y(), b_bounds.y()); | 276 int top = std::max(a_bounds.y(), b_bounds.y()); |
| 275 int bottom = std::min(a_bounds.bottom(), b_bounds.bottom()); | 277 int bottom = std::min(a_bounds.bottom(), b_bounds.bottom()); |
| 276 if (position == DisplayPlacement::LEFT) { | 278 if (position == DisplayPlacement::LEFT) { |
| 277 a_edge_in_screen->SetRect(a_bounds.x(), top, 1, bottom - top); | 279 a_edge_in_screen->SetRect(a_bounds.x(), top, 1, bottom - top); |
| 278 b_edge_in_screen->SetRect(b_bounds.right() - 1, top, 1, bottom - top); | 280 b_edge_in_screen->SetRect(b_bounds.right() - 1, top, 1, bottom - top); |
| 279 } else { | 281 } else { |
| 280 a_edge_in_screen->SetRect(a_bounds.right() - 1, top, 1, bottom - top); | 282 a_edge_in_screen->SetRect(a_bounds.right() - 1, top, 1, bottom - top); |
| 281 b_edge_in_screen->SetRect(b_bounds.y(), top, 1, bottom - top); | 283 b_edge_in_screen->SetRect(b_bounds.x(), top, 1, bottom - top); |
| 282 } | 284 } |
| 283 break; | 285 break; |
| 284 } | 286 } |
| 285 } | 287 } |
| 288 return true; |
| 286 } | 289 } |
| 287 | 290 |
| 288 gfx::Rect GetNativeEdgeBounds(AshWindowTreeHost* ash_host, | 291 gfx::Rect GetNativeEdgeBounds(AshWindowTreeHost* ash_host, |
| 289 const gfx::Rect& bounds_in_screen) { | 292 const gfx::Rect& bounds_in_screen) { |
| 290 aura::WindowTreeHost* host = ash_host->AsWindowTreeHost(); | 293 aura::WindowTreeHost* host = ash_host->AsWindowTreeHost(); |
| 291 gfx::Rect native_bounds = host->GetBounds(); | 294 gfx::Rect native_bounds = host->GetBounds(); |
| 292 native_bounds.Inset(ash_host->GetHostInsets()); | 295 native_bounds.Inset(ash_host->GetHostInsets()); |
| 293 gfx::Point start_in_native = bounds_in_screen.origin(); | 296 gfx::Point start_in_native = bounds_in_screen.origin(); |
| 294 gfx::Point end_in_native = bounds_in_screen.bottom_right(); | 297 gfx::Point end_in_native = bounds_in_screen.bottom_right(); |
| 295 | 298 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 list.begin(), list.end(), | 379 list.begin(), list.end(), |
| 377 [](const gfx::Display& display) { return display.id(); }); | 380 [](const gfx::Display& display) { return display.id(); }); |
| 378 } | 381 } |
| 379 | 382 |
| 380 void SortDisplayIdList(DisplayIdList* ids) { | 383 void SortDisplayIdList(DisplayIdList* ids) { |
| 381 std::sort(ids->begin(), ids->end(), | 384 std::sort(ids->begin(), ids->end(), |
| 382 [](int64_t a, int64_t b) { return CompareDisplayIds(a, b); }); | 385 [](int64_t a, int64_t b) { return CompareDisplayIds(a, b); }); |
| 383 } | 386 } |
| 384 | 387 |
| 385 std::string DisplayIdListToString(const ash::DisplayIdList& list) { | 388 std::string DisplayIdListToString(const ash::DisplayIdList& list) { |
| 386 return base::Int64ToString(list[0]) + "," + base::Int64ToString(list[1]); | 389 std::stringstream s; |
| 390 const char* sep = ""; |
| 391 for (int64_t id : list) { |
| 392 s << sep << id; |
| 393 sep = ","; |
| 394 } |
| 395 return s.str(); |
| 387 } | 396 } |
| 388 | 397 |
| 389 bool CompareDisplayIds(int64_t id1, int64_t id2) { | 398 bool CompareDisplayIds(int64_t id1, int64_t id2) { |
| 390 DCHECK_NE(id1, id2); | 399 DCHECK_NE(id1, id2); |
| 391 // Output index is stored in the first 8 bits. See GetDisplayIdFromEDID | 400 // Output index is stored in the first 8 bits. See GetDisplayIdFromEDID |
| 392 // in edid_parser.cc. | 401 // in edid_parser.cc. |
| 393 int index_1 = id1 & 0xFF; | 402 int index_1 = id1 & 0xFF; |
| 394 int index_2 = id2 & 0xFF; | 403 int index_2 = id2 & 0xFF; |
| 395 DCHECK_NE(index_1, index_2) << id1 << " and " << id2; | 404 DCHECK_NE(index_1, index_2) << id1 << " and " << id2; |
| 396 return gfx::Display::IsInternalDisplayId(id1) || | 405 return gfx::Display::IsInternalDisplayId(id1) || |
| 397 (index_1 < index_2 && !gfx::Display::IsInternalDisplayId(id2)); | 406 (index_1 < index_2 && !gfx::Display::IsInternalDisplayId(id2)); |
| 398 } | 407 } |
| 399 | 408 |
| 400 } // namespace ash | 409 } // namespace ash |
| OLD | NEW |