| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "services/ui/display/platform_screen_ozone.h" | 5 #include "services/ui/display/platform_screen_ozone.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/sys_info.h" | 12 #include "base/sys_info.h" |
| 13 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
| 14 #include "services/service_manager/public/cpp/interface_registry.h" | 14 #include "services/service_manager/public/cpp/interface_registry.h" |
| 15 #include "third_party/skia/include/core/SkColor.h" | 15 #include "third_party/skia/include/core/SkColor.h" |
| 16 #include "ui/display/types/display_constants.h" | |
| 17 #include "ui/display/types/display_snapshot.h" | 16 #include "ui/display/types/display_snapshot.h" |
| 18 #include "ui/display/types/native_display_delegate.h" | 17 #include "ui/display/types/native_display_delegate.h" |
| 19 #include "ui/gfx/geometry/rect.h" | 18 #include "ui/gfx/geometry/rect.h" |
| 20 #include "ui/ozone/public/ozone_platform.h" | 19 #include "ui/ozone/public/ozone_platform.h" |
| 21 | 20 |
| 22 namespace display { | 21 namespace display { |
| 23 namespace { | 22 namespace { |
| 24 | 23 |
| 25 // Needed for DisplayConfigurator::ForceInitialConfigure. | 24 // Needed for DisplayConfigurator::ForceInitialConfigure. |
| 26 const SkColor kChromeOsBootColor = SkColorSetRGB(0xfe, 0xfe, 0xfe); | 25 const SkColor kChromeOsBootColor = SkColorSetRGB(0xfe, 0xfe, 0xfe); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 return primary_display_id_; | 107 return primary_display_id_; |
| 109 } | 108 } |
| 110 | 109 |
| 111 void PlatformScreenOzone::ToggleAddRemoveDisplay() { | 110 void PlatformScreenOzone::ToggleAddRemoveDisplay() { |
| 112 if (!fake_display_controller_ || wait_for_display_config_update_) | 111 if (!fake_display_controller_ || wait_for_display_config_update_) |
| 113 return; | 112 return; |
| 114 | 113 |
| 115 if (cached_displays_.size() == 1) { | 114 if (cached_displays_.size() == 1) { |
| 116 const gfx::Size& pixel_size = cached_displays_[0].metrics.pixel_size; | 115 const gfx::Size& pixel_size = cached_displays_[0].metrics.pixel_size; |
| 117 wait_for_display_config_update_ = | 116 wait_for_display_config_update_ = |
| 118 fake_display_controller_->AddDisplay(pixel_size) != | 117 fake_display_controller_->AddDisplay(pixel_size) != kInvalidDisplayId; |
| 119 Display::kInvalidDisplayID; | |
| 120 } else if (cached_displays_.size() > 1) { | 118 } else if (cached_displays_.size() > 1) { |
| 121 wait_for_display_config_update_ = | 119 wait_for_display_config_update_ = |
| 122 fake_display_controller_->RemoveDisplay(cached_displays_.back().id); | 120 fake_display_controller_->RemoveDisplay(cached_displays_.back().id); |
| 123 } else { | 121 } else { |
| 124 NOTREACHED(); | 122 NOTREACHED(); |
| 125 } | 123 } |
| 126 } | 124 } |
| 127 | 125 |
| 128 void PlatformScreenOzone::ToggleDisplayResolution() { | 126 void PlatformScreenOzone::ToggleDisplayResolution() { |
| 129 DisplayInfo& display = cached_displays_[0]; | 127 DisplayInfo& display = cached_displays_[0]; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 std::vector<int64_t> current_ids; | 198 std::vector<int64_t> current_ids; |
| 201 for (ui::DisplaySnapshot* snapshot : snapshots) | 199 for (ui::DisplaySnapshot* snapshot : snapshots) |
| 202 current_ids.push_back(snapshot->display_id()); | 200 current_ids.push_back(snapshot->display_id()); |
| 203 | 201 |
| 204 // Find cached displays with no matching snapshot and mark as removed. | 202 // Find cached displays with no matching snapshot and mark as removed. |
| 205 for (DisplayInfo& display : cached_displays_) { | 203 for (DisplayInfo& display : cached_displays_) { |
| 206 if (std::find(current_ids.begin(), current_ids.end(), display.id) == | 204 if (std::find(current_ids.begin(), current_ids.end(), display.id) == |
| 207 current_ids.end()) { | 205 current_ids.end()) { |
| 208 display.removed = true; | 206 display.removed = true; |
| 209 if (primary_display_id_ == display.id) | 207 if (primary_display_id_ == display.id) |
| 210 primary_display_id_ = Display::kInvalidDisplayID; | 208 primary_display_id_ = kInvalidDisplayId; |
| 211 } | 209 } |
| 212 } | 210 } |
| 213 } | 211 } |
| 214 | 212 |
| 215 void PlatformScreenOzone::ProcessModifiedDisplays( | 213 void PlatformScreenOzone::ProcessModifiedDisplays( |
| 216 const ui::DisplayConfigurator::DisplayStateList& snapshots) { | 214 const ui::DisplayConfigurator::DisplayStateList& snapshots) { |
| 217 for (ui::DisplaySnapshot* snapshot : snapshots) { | 215 for (ui::DisplaySnapshot* snapshot : snapshots) { |
| 218 auto iter = GetCachedDisplayIterator(snapshot->display_id()); | 216 auto iter = GetCachedDisplayIterator(snapshot->display_id()); |
| 219 if (iter != cached_displays_.end()) { | 217 if (iter != cached_displays_.end()) { |
| 220 DisplayInfo& display_info = *iter; | 218 DisplayInfo& display_info = *iter; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 display_info.requested_size = mode->size(); | 278 display_info.requested_size = mode->size(); |
| 281 } | 279 } |
| 282 | 280 |
| 283 // Move the origin so that next display is to the right of current display. | 281 // Move the origin so that next display is to the right of current display. |
| 284 next_display_origin_.Offset(display_info.metrics.bounds.width(), 0); | 282 next_display_origin_.Offset(display_info.metrics.bounds.width(), 0); |
| 285 | 283 |
| 286 cached_displays_.push_back(display_info); | 284 cached_displays_.push_back(display_info); |
| 287 delegate_->OnDisplayAdded(display_info.id, display_info.metrics); | 285 delegate_->OnDisplayAdded(display_info.id, display_info.metrics); |
| 288 | 286 |
| 289 // If we have no primary display then this one should be it. | 287 // If we have no primary display then this one should be it. |
| 290 if (primary_display_id_ == Display::kInvalidDisplayID) { | 288 if (primary_display_id_ == kInvalidDisplayId) { |
| 291 primary_display_id_ = id; | 289 primary_display_id_ = id; |
| 292 delegate_->OnPrimaryDisplayChanged(primary_display_id_); | 290 delegate_->OnPrimaryDisplayChanged(primary_display_id_); |
| 293 } | 291 } |
| 294 } | 292 } |
| 295 } | 293 } |
| 296 | 294 |
| 297 PlatformScreenOzone::CachedDisplayIterator | 295 PlatformScreenOzone::CachedDisplayIterator |
| 298 PlatformScreenOzone::GetCachedDisplayIterator(int64_t display_id) { | 296 PlatformScreenOzone::GetCachedDisplayIterator(int64_t display_id) { |
| 299 return std::find_if(cached_displays_.begin(), cached_displays_.end(), | 297 return std::find_if(cached_displays_.begin(), cached_displays_.end(), |
| 300 [display_id](const DisplayInfo& display_info) { | 298 [display_id](const DisplayInfo& display_info) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 321 return metrics; | 319 return metrics; |
| 322 } | 320 } |
| 323 | 321 |
| 324 void PlatformScreenOzone::OnDisplayModeChanged( | 322 void PlatformScreenOzone::OnDisplayModeChanged( |
| 325 const ui::DisplayConfigurator::DisplayStateList& displays) { | 323 const ui::DisplayConfigurator::DisplayStateList& displays) { |
| 326 ProcessRemovedDisplays(displays); | 324 ProcessRemovedDisplays(displays); |
| 327 ProcessModifiedDisplays(displays); | 325 ProcessModifiedDisplays(displays); |
| 328 | 326 |
| 329 // If the primary display is marked as removed we'll try to find a new primary | 327 // If the primary display is marked as removed we'll try to find a new primary |
| 330 // display and update the delegate before removing the old primary display. | 328 // display and update the delegate before removing the old primary display. |
| 331 if (primary_display_id_ == Display::kInvalidDisplayID) { | 329 if (primary_display_id_ == kInvalidDisplayId) { |
| 332 for (const DisplayInfo& display : cached_displays_) { | 330 for (const DisplayInfo& display : cached_displays_) { |
| 333 if (!display.removed) { | 331 if (!display.removed) { |
| 334 primary_display_id_ = display.id; | 332 primary_display_id_ = display.id; |
| 335 delegate_->OnPrimaryDisplayChanged(primary_display_id_); | 333 delegate_->OnPrimaryDisplayChanged(primary_display_id_); |
| 336 break; | 334 break; |
| 337 } | 335 } |
| 338 } | 336 } |
| 339 } | 337 } |
| 340 | 338 |
| 341 UpdateCachedDisplays(); | 339 UpdateCachedDisplays(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 return false; | 374 return false; |
| 377 } | 375 } |
| 378 | 376 |
| 379 void PlatformScreenOzone::Create( | 377 void PlatformScreenOzone::Create( |
| 380 const service_manager::Identity& remote_identity, | 378 const service_manager::Identity& remote_identity, |
| 381 mojom::TestDisplayControllerRequest request) { | 379 mojom::TestDisplayControllerRequest request) { |
| 382 test_bindings_.AddBinding(this, std::move(request)); | 380 test_bindings_.AddBinding(this, std::move(request)); |
| 383 } | 381 } |
| 384 | 382 |
| 385 } // namespace display | 383 } // namespace display |
| OLD | NEW |