| 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 "ui/display/manager/display_manager.h" | 5 #include "ui/display/manager/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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 DisplayIdList list = GetCurrentDisplayIdList(); | 199 DisplayIdList list = GetCurrentDisplayIdList(); |
| 200 return layout_store_->GetRegisteredDisplayLayout(list); | 200 return layout_store_->GetRegisteredDisplayLayout(list); |
| 201 } | 201 } |
| 202 LOG(ERROR) << "DisplayLayout is requested for single display"; | 202 LOG(ERROR) << "DisplayLayout is requested for single display"; |
| 203 // On release build, just fallback to default instead of blowing up. | 203 // On release build, just fallback to default instead of blowing up. |
| 204 static DisplayLayout layout; | 204 static DisplayLayout layout; |
| 205 layout.primary_id = active_display_list_[0].id(); | 205 layout.primary_id = active_display_list_[0].id(); |
| 206 return layout; | 206 return layout; |
| 207 } | 207 } |
| 208 | 208 |
| 209 const DisplayLayout& DisplayManager::GetCurrentResolvedDisplayLayout() const { |
| 210 return current_resolved_layout_ ? *current_resolved_layout_ |
| 211 : GetCurrentDisplayLayout(); |
| 212 } |
| 213 |
| 209 DisplayIdList DisplayManager::GetCurrentDisplayIdList() const { | 214 DisplayIdList DisplayManager::GetCurrentDisplayIdList() const { |
| 210 if (IsInUnifiedMode()) { | 215 if (IsInUnifiedMode()) { |
| 211 return CreateDisplayIdList(software_mirroring_display_list_); | 216 return CreateDisplayIdList(software_mirroring_display_list_); |
| 212 } else if (IsInMirrorMode()) { | 217 } else if (IsInMirrorMode()) { |
| 213 if (software_mirroring_enabled()) { | 218 if (software_mirroring_enabled()) { |
| 214 CHECK_EQ(2u, num_connected_displays()); | 219 CHECK_EQ(2u, num_connected_displays()); |
| 215 // This comment is to make it easy to distinguish the crash | 220 // This comment is to make it easy to distinguish the crash |
| 216 // between two checks. | 221 // between two checks. |
| 217 CHECK_EQ(1u, active_display_list_.size()); | 222 CHECK_EQ(1u, active_display_list_.size()); |
| 218 } | 223 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 237 | 242 |
| 238 if (layout->HasSamePlacementList(current_layout)) | 243 if (layout->HasSamePlacementList(current_layout)) |
| 239 return; | 244 return; |
| 240 | 245 |
| 241 layout_store_->RegisterLayoutForDisplayIdList(list, std::move(layout)); | 246 layout_store_->RegisterLayoutForDisplayIdList(list, std::move(layout)); |
| 242 if (delegate_) | 247 if (delegate_) |
| 243 delegate_->PreDisplayConfigurationChange(false); | 248 delegate_->PreDisplayConfigurationChange(false); |
| 244 | 249 |
| 245 // TODO(oshima): Call UpdateDisplays instead. | 250 // TODO(oshima): Call UpdateDisplays instead. |
| 246 std::vector<int64_t> updated_ids; | 251 std::vector<int64_t> updated_ids; |
| 247 ApplyDisplayLayout(GetCurrentDisplayLayout(), &active_display_list_, | 252 current_resolved_layout_ = GetCurrentDisplayLayout().Copy(); |
| 253 ApplyDisplayLayout(current_resolved_layout_.get(), &active_display_list_, |
| 248 &updated_ids); | 254 &updated_ids); |
| 249 for (int64_t id : updated_ids) { | 255 for (int64_t id : updated_ids) { |
| 250 NotifyMetricsChanged(GetDisplayForId(id), | 256 NotifyMetricsChanged(GetDisplayForId(id), |
| 251 DisplayObserver::DISPLAY_METRIC_BOUNDS | | 257 DisplayObserver::DISPLAY_METRIC_BOUNDS | |
| 252 DisplayObserver::DISPLAY_METRIC_WORK_AREA); | 258 DisplayObserver::DISPLAY_METRIC_WORK_AREA); |
| 253 } | 259 } |
| 254 | 260 |
| 255 if (delegate_) | 261 if (delegate_) |
| 256 delegate_->PostDisplayConfigurationChange(false); | 262 delegate_->PostDisplayConfigurationChange(false); |
| 257 } | 263 } |
| (...skipping 1114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1372 const DisplayLayout& layout = layout_store_->GetRegisteredDisplayLayout( | 1378 const DisplayLayout& layout = layout_store_->GetRegisteredDisplayLayout( |
| 1373 CreateDisplayIdList(*display_list)); | 1379 CreateDisplayIdList(*display_list)); |
| 1374 | 1380 |
| 1375 // Ignore if a user has a old format (should be extremely rare) | 1381 // Ignore if a user has a old format (should be extremely rare) |
| 1376 // and this will be replaced with DCHECK. | 1382 // and this will be replaced with DCHECK. |
| 1377 if (layout.primary_id == kInvalidDisplayId) | 1383 if (layout.primary_id == kInvalidDisplayId) |
| 1378 return; | 1384 return; |
| 1379 | 1385 |
| 1380 // display_list does not have translation set, so ApplyDisplayLayout cannot | 1386 // display_list does not have translation set, so ApplyDisplayLayout cannot |
| 1381 // provide accurate change information. We'll find the changes after the call. | 1387 // provide accurate change information. We'll find the changes after the call. |
| 1382 ApplyDisplayLayout(layout, display_list, nullptr); | 1388 current_resolved_layout_ = layout.Copy(); |
| 1389 ApplyDisplayLayout(current_resolved_layout_.get(), display_list, nullptr); |
| 1383 size_t num_displays = display_list->size(); | 1390 size_t num_displays = display_list->size(); |
| 1384 for (size_t index = 0; index < num_displays; ++index) { | 1391 for (size_t index = 0; index < num_displays; ++index) { |
| 1385 const Display& display = (*display_list)[index]; | 1392 const Display& display = (*display_list)[index]; |
| 1386 int64_t id = display.id(); | 1393 int64_t id = display.id(); |
| 1387 const Display* active_display = FindDisplayForId(id); | 1394 const Display* active_display = FindDisplayForId(id); |
| 1388 if (!active_display || (active_display->bounds() != display.bounds())) | 1395 if (!active_display || (active_display->bounds() != display.bounds())) |
| 1389 updated_indices->push_back(index); | 1396 updated_indices->push_back(index); |
| 1390 } | 1397 } |
| 1391 } | 1398 } |
| 1392 | 1399 |
| 1393 void DisplayManager::CreateMirrorWindowIfAny() { | 1400 void DisplayManager::CreateMirrorWindowIfAny() { |
| 1394 if (software_mirroring_display_list_.empty() || !delegate_) | 1401 if (software_mirroring_display_list_.empty() || !delegate_) |
| 1395 return; | 1402 return; |
| 1396 DisplayInfoList list; | 1403 DisplayInfoList list; |
| 1397 for (auto& display : software_mirroring_display_list_) | 1404 for (auto& display : software_mirroring_display_list_) |
| 1398 list.push_back(GetDisplayInfo(display.id())); | 1405 list.push_back(GetDisplayInfo(display.id())); |
| 1399 delegate_->CreateOrUpdateMirroringDisplay(list); | 1406 delegate_->CreateOrUpdateMirroringDisplay(list); |
| 1400 } | 1407 } |
| 1401 | 1408 |
| 1402 void DisplayManager::ApplyDisplayLayout(const DisplayLayout& layout, | 1409 void DisplayManager::ApplyDisplayLayout(DisplayLayout* layout, |
| 1403 Displays* display_list, | 1410 Displays* display_list, |
| 1404 std::vector<int64_t>* updated_ids) { | 1411 std::vector<int64_t>* updated_ids) { |
| 1405 layout.ApplyToDisplayList(display_list, updated_ids, | 1412 layout->ApplyToDisplayList(display_list, updated_ids, |
| 1406 kMinimumOverlapForInvalidOffset); | 1413 kMinimumOverlapForInvalidOffset); |
| 1407 } | 1414 } |
| 1408 | 1415 |
| 1409 void DisplayManager::RunPendingTasksForTest() { | 1416 void DisplayManager::RunPendingTasksForTest() { |
| 1410 if (!software_mirroring_display_list_.empty()) | 1417 if (!software_mirroring_display_list_.empty()) |
| 1411 base::RunLoop().RunUntilIdle(); | 1418 base::RunLoop().RunUntilIdle(); |
| 1412 } | 1419 } |
| 1413 | 1420 |
| 1414 void DisplayManager::NotifyMetricsChanged(const Display& display, | 1421 void DisplayManager::NotifyMetricsChanged(const Display& display, |
| 1415 uint32_t metrics) { | 1422 uint32_t metrics) { |
| 1416 for (auto& observer : observers_) | 1423 for (auto& observer : observers_) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1436 } | 1443 } |
| 1437 | 1444 |
| 1438 const Display& DisplayManager::GetSecondaryDisplay() const { | 1445 const Display& DisplayManager::GetSecondaryDisplay() const { |
| 1439 CHECK_LE(2U, GetNumDisplays()); | 1446 CHECK_LE(2U, GetNumDisplays()); |
| 1440 return GetDisplayAt(0).id() == Screen::GetScreen()->GetPrimaryDisplay().id() | 1447 return GetDisplayAt(0).id() == Screen::GetScreen()->GetPrimaryDisplay().id() |
| 1441 ? GetDisplayAt(1) | 1448 ? GetDisplayAt(1) |
| 1442 : GetDisplayAt(0); | 1449 : GetDisplayAt(0); |
| 1443 } | 1450 } |
| 1444 | 1451 |
| 1445 } // namespace display | 1452 } // namespace display |
| OLD | NEW |