Chromium Code Reviews| 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" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 } | 157 } |
| 158 } | 158 } |
| 159 | 159 |
| 160 // Set next display index as primary, or loop back to first display if last. | 160 // Set next display index as primary, or loop back to first display if last. |
| 161 if (primary_display_index + 1 == num_displays) { | 161 if (primary_display_index + 1 == num_displays) { |
| 162 primary_display_id_ = cached_displays_[0].id; | 162 primary_display_id_ = cached_displays_[0].id; |
| 163 } else { | 163 } else { |
| 164 primary_display_id_ = cached_displays_[primary_display_index + 1].id; | 164 primary_display_id_ = cached_displays_[primary_display_index + 1].id; |
| 165 } | 165 } |
| 166 | 166 |
| 167 // TODO(kylechar): Update ws::DisplayManager. | 167 delegate_->OnPrimaryDisplayChanged(primary_display_id_); |
| 168 } | 168 } |
| 169 | 169 |
| 170 void PlatformScreenOzone::SetDisplayWorkArea(int64_t display_id, | 170 void PlatformScreenOzone::SetDisplayWorkArea(int64_t display_id, |
| 171 const gfx::Size& size, | 171 const gfx::Size& size, |
| 172 const gfx::Insets& insets) { | 172 const gfx::Insets& insets) { |
| 173 CachedDisplayIterator iter = GetCachedDisplayIterator(display_id); | 173 CachedDisplayIterator iter = GetCachedDisplayIterator(display_id); |
| 174 if (iter == cached_displays_.end()) { | 174 if (iter == cached_displays_.end()) { |
| 175 NOTREACHED() << display_id; | 175 NOTREACHED() << display_id; |
| 176 return; | 176 return; |
| 177 } | 177 } |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 203 | 203 |
| 204 // Find cached displays with no matching snapshot and mark as removed. | 204 // Find cached displays with no matching snapshot and mark as removed. |
| 205 for (DisplayInfo& display : cached_displays_) { | 205 for (DisplayInfo& display : cached_displays_) { |
| 206 if (std::find(current_ids.begin(), current_ids.end(), display.id) == | 206 if (std::find(current_ids.begin(), current_ids.end(), display.id) == |
| 207 current_ids.end()) { | 207 current_ids.end()) { |
| 208 display.removed = true; | 208 display.removed = true; |
| 209 if (primary_display_id_ == display.id) | 209 if (primary_display_id_ == display.id) |
| 210 primary_display_id_ = Display::kInvalidDisplayID; | 210 primary_display_id_ = Display::kInvalidDisplayID; |
| 211 } | 211 } |
| 212 } | 212 } |
| 213 | |
| 214 // If the primary display was removed find a new primary display id. | |
| 215 if (primary_display_id_ == Display::kInvalidDisplayID) { | |
| 216 for (const DisplayInfo& display : cached_displays_) { | |
| 217 if (!display.removed) { | |
| 218 primary_display_id_ = display.id; | |
| 219 break; | |
| 220 } | |
| 221 } | |
| 222 } | |
| 223 } | 213 } |
| 224 | 214 |
| 225 void PlatformScreenOzone::ProcessModifiedDisplays( | 215 void PlatformScreenOzone::ProcessModifiedDisplays( |
| 226 const ui::DisplayConfigurator::DisplayStateList& snapshots) { | 216 const ui::DisplayConfigurator::DisplayStateList& snapshots) { |
| 227 for (ui::DisplaySnapshot* snapshot : snapshots) { | 217 for (ui::DisplaySnapshot* snapshot : snapshots) { |
| 228 auto iter = GetCachedDisplayIterator(snapshot->display_id()); | 218 auto iter = GetCachedDisplayIterator(snapshot->display_id()); |
| 229 if (iter != cached_displays_.end()) { | 219 if (iter != cached_displays_.end()) { |
| 230 DisplayInfo& display_info = *iter; | 220 DisplayInfo& display_info = *iter; |
| 231 ViewportMetrics new_metrics = | 221 ViewportMetrics new_metrics = |
| 232 MetricsFromSnapshot(*snapshot, display_info.metrics.bounds.origin()); | 222 MetricsFromSnapshot(*snapshot, display_info.metrics.bounds.origin()); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 | 262 |
| 273 void PlatformScreenOzone::AddNewDisplays( | 263 void PlatformScreenOzone::AddNewDisplays( |
| 274 const ui::DisplayConfigurator::DisplayStateList& snapshots) { | 264 const ui::DisplayConfigurator::DisplayStateList& snapshots) { |
| 275 for (ui::DisplaySnapshot* snapshot : snapshots) { | 265 for (ui::DisplaySnapshot* snapshot : snapshots) { |
| 276 const int64_t id = snapshot->display_id(); | 266 const int64_t id = snapshot->display_id(); |
| 277 | 267 |
| 278 // Check if display already exists and skip. | 268 // Check if display already exists and skip. |
| 279 if (GetCachedDisplayIterator(id) != cached_displays_.end()) | 269 if (GetCachedDisplayIterator(id) != cached_displays_.end()) |
| 280 continue; | 270 continue; |
| 281 | 271 |
| 282 // If we have no primary display then this one should be it. | |
| 283 if (primary_display_id_ == Display::kInvalidDisplayID) | |
| 284 primary_display_id_ = id; | |
| 285 | |
| 286 DisplayInfo display_info; | 272 DisplayInfo display_info; |
| 287 display_info.id = snapshot->display_id(); | 273 display_info.id = snapshot->display_id(); |
| 288 display_info.metrics = MetricsFromSnapshot(*snapshot, next_display_origin_); | 274 display_info.metrics = MetricsFromSnapshot(*snapshot, next_display_origin_); |
| 289 | 275 |
| 290 // Store the display mode sizes so we can toggle through them. | 276 // Store the display mode sizes so we can toggle through them. |
| 291 for (auto& mode : snapshot->modes()) { | 277 for (auto& mode : snapshot->modes()) { |
| 292 display_info.supported_sizes.push_back(mode->size()); | 278 display_info.supported_sizes.push_back(mode->size()); |
| 293 if (mode.get() == snapshot->current_mode()) | 279 if (mode.get() == snapshot->current_mode()) |
| 294 display_info.requested_size = mode->size(); | 280 display_info.requested_size = mode->size(); |
| 295 } | 281 } |
| 296 | 282 |
| 297 // Move the origin so that next display is to the right of current display. | 283 // Move the origin so that next display is to the right of current display. |
| 298 next_display_origin_.Offset(display_info.metrics.bounds.width(), 0); | 284 next_display_origin_.Offset(display_info.metrics.bounds.width(), 0); |
| 299 | 285 |
| 300 cached_displays_.push_back(display_info); | 286 cached_displays_.push_back(display_info); |
| 301 delegate_->OnDisplayAdded(display_info.id, display_info.metrics); | 287 delegate_->OnDisplayAdded(display_info.id, display_info.metrics); |
| 288 | |
| 289 // If we have no primary display then this one should be it. | |
| 290 if (primary_display_id_ == Display::kInvalidDisplayID) { | |
| 291 primary_display_id_ = id; | |
| 292 delegate_->OnPrimaryDisplayChanged(primary_display_id_); | |
| 293 } | |
| 302 } | 294 } |
| 303 } | 295 } |
| 304 | 296 |
| 305 PlatformScreenOzone::CachedDisplayIterator | 297 PlatformScreenOzone::CachedDisplayIterator |
| 306 PlatformScreenOzone::GetCachedDisplayIterator(int64_t display_id) { | 298 PlatformScreenOzone::GetCachedDisplayIterator(int64_t display_id) { |
| 307 return std::find_if(cached_displays_.begin(), cached_displays_.end(), | 299 return std::find_if(cached_displays_.begin(), cached_displays_.end(), |
| 308 [display_id](const DisplayInfo& display_info) { | 300 [display_id](const DisplayInfo& display_info) { |
| 309 return display_info.id == display_id; | 301 return display_info.id == display_id; |
| 310 }); | 302 }); |
| 311 } | 303 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 324 // ui scale factor is always 1.0 here for now. | 316 // ui scale factor is always 1.0 here for now. |
| 325 gfx::Size scaled_size = gfx::ScaleToRoundedSize( | 317 gfx::Size scaled_size = gfx::ScaleToRoundedSize( |
| 326 current_mode->size(), 1.0f / metrics.device_scale_factor); | 318 current_mode->size(), 1.0f / metrics.device_scale_factor); |
| 327 metrics.bounds = gfx::Rect(origin, scaled_size); | 319 metrics.bounds = gfx::Rect(origin, scaled_size); |
| 328 metrics.work_area = metrics.bounds; | 320 metrics.work_area = metrics.bounds; |
| 329 return metrics; | 321 return metrics; |
| 330 } | 322 } |
| 331 | 323 |
| 332 void PlatformScreenOzone::OnDisplayModeChanged( | 324 void PlatformScreenOzone::OnDisplayModeChanged( |
| 333 const ui::DisplayConfigurator::DisplayStateList& displays) { | 325 const ui::DisplayConfigurator::DisplayStateList& displays) { |
| 326 int64_t old_primary_display_id = primary_display_id_; | |
| 327 | |
| 334 ProcessRemovedDisplays(displays); | 328 ProcessRemovedDisplays(displays); |
| 335 ProcessModifiedDisplays(displays); | 329 ProcessModifiedDisplays(displays); |
| 330 | |
| 331 // If the primary display was removed try to find a new primary display. | |
| 332 if (primary_display_id_ == Display::kInvalidDisplayID) { | |
| 333 for (const DisplayInfo& display : cached_displays_) { | |
|
sky
2016/10/28 17:08:47
Do you need to handle the case of no more displays
kylechar
2016/10/28 19:40:36
That's handled when the last primary display is ma
| |
| 334 if (!display.removed) { | |
| 335 primary_display_id_ = display.id; | |
| 336 break; | |
| 337 } | |
| 338 } | |
| 339 } | |
| 340 | |
| 341 if (old_primary_display_id != primary_display_id_) | |
| 342 delegate_->OnPrimaryDisplayChanged(primary_display_id_); | |
| 343 | |
| 336 UpdateCachedDisplays(); | 344 UpdateCachedDisplays(); |
| 337 AddNewDisplays(displays); | 345 AddNewDisplays(displays); |
| 346 | |
| 338 wait_for_display_config_update_ = false; | 347 wait_for_display_config_update_ = false; |
| 339 } | 348 } |
| 340 | 349 |
| 341 void PlatformScreenOzone::OnDisplayModeChangeFailed( | 350 void PlatformScreenOzone::OnDisplayModeChangeFailed( |
| 342 const ui::DisplayConfigurator::DisplayStateList& displays, | 351 const ui::DisplayConfigurator::DisplayStateList& displays, |
| 343 ui::MultipleDisplayState failed_new_state) { | 352 ui::MultipleDisplayState failed_new_state) { |
| 344 LOG(ERROR) << "OnDisplayModeChangeFailed from DisplayConfigurator"; | 353 LOG(ERROR) << "OnDisplayModeChangeFailed from DisplayConfigurator"; |
| 345 wait_for_display_config_update_ = false; | 354 wait_for_display_config_update_ = false; |
| 346 } | 355 } |
| 347 | 356 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 370 return false; | 379 return false; |
| 371 } | 380 } |
| 372 | 381 |
| 373 void PlatformScreenOzone::Create( | 382 void PlatformScreenOzone::Create( |
| 374 const service_manager::Identity& remote_identity, | 383 const service_manager::Identity& remote_identity, |
| 375 mojom::TestDisplayControllerRequest request) { | 384 mojom::TestDisplayControllerRequest request) { |
| 376 test_bindings_.AddBinding(this, std::move(request)); | 385 test_bindings_.AddBinding(this, std::move(request)); |
| 377 } | 386 } |
| 378 | 387 |
| 379 } // namespace display | 388 } // namespace display |
| OLD | NEW |