 Chromium Code Reviews
 Chromium Code Reviews Issue 2072633002:
  Add Get/SetDisplayLayout to chrome.system.display extension API  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 2072633002:
  Add Get/SetDisplayLayout to chrome.system.display extension API  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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 "chrome/browser/extensions/display_info_provider_chromeos.h" | 5 #include "chrome/browser/extensions/display_info_provider_chromeos.h" | 
| 6 | 6 | 
| 7 #include <stdint.h> | 7 #include <stdint.h> | 
| 8 | 8 | 
| 9 #include "ash/display/display_configuration_controller.h" | 9 #include "ash/display/display_configuration_controller.h" | 
| 10 #include "ash/display/display_manager.h" | 10 #include "ash/display/display_manager.h" | 
| 11 #include "ash/display/resolution_notification_controller.h" | 11 #include "ash/display/resolution_notification_controller.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 "chrome/browser/chromeos/display/display_preferences.h" | 14 #include "chrome/browser/chromeos/display/display_preferences.h" | 
| 15 #include "chrome/browser/chromeos/display/overscan_calibrator.h" | 15 #include "chrome/browser/chromeos/display/overscan_calibrator.h" | 
| 16 #include "extensions/common/api/system_display.h" | 16 #include "extensions/common/api/system_display.h" | 
| 17 #include "ui/display/display.h" | 17 #include "ui/display/display.h" | 
| 18 #include "ui/display/manager/display_layout.h" | 18 #include "ui/display/manager/display_layout.h" | 
| 19 #include "ui/display/manager/display_layout_builder.h" | |
| 19 #include "ui/gfx/geometry/point.h" | 20 #include "ui/gfx/geometry/point.h" | 
| 20 #include "ui/gfx/geometry/rect.h" | 21 #include "ui/gfx/geometry/rect.h" | 
| 21 | 22 | 
| 22 namespace extensions { | 23 namespace extensions { | 
| 23 | 24 | 
| 24 using api::system_display::Bounds; | 25 namespace system_display = api::system_display; | 
| 25 using api::system_display::DisplayUnitInfo; | |
| 26 using api::system_display::DisplayProperties; | |
| 27 using api::system_display::Insets; | |
| 28 | 26 | 
| 29 namespace { | 27 namespace { | 
| 30 | 28 | 
| 31 // Maximum allowed bounds origin absolute value. | 29 // Maximum allowed bounds origin absolute value. | 
| 32 const int kMaxBoundsOrigin = 200 * 1000; | 30 const int kMaxBoundsOrigin = 200 * 1000; | 
| 33 | 31 | 
| 34 // Gets the display with the provided string id. | 32 // Gets the display with the provided string id. | 
| 35 display::Display GetDisplay(const std::string& display_id_str) { | 33 display::Display GetDisplay(const std::string& display_id_str) { | 
| 36 int64_t display_id; | 34 int64_t display_id; | 
| 37 if (!base::StringToInt64(display_id_str, &display_id)) | 35 if (!base::StringToInt64(display_id_str, &display_id)) | 
| (...skipping 17 matching lines...) Expand all Loading... | |
| 55 return display::Display::ROTATE_90; | 53 return display::Display::ROTATE_90; | 
| 56 case 180: | 54 case 180: | 
| 57 return display::Display::ROTATE_180; | 55 return display::Display::ROTATE_180; | 
| 58 case 270: | 56 case 270: | 
| 59 return display::Display::ROTATE_270; | 57 return display::Display::ROTATE_270; | 
| 60 default: | 58 default: | 
| 61 return display::Display::ROTATE_0; | 59 return display::Display::ROTATE_0; | 
| 62 } | 60 } | 
| 63 } | 61 } | 
| 64 | 62 | 
| 63 // Converts system_display::LayoutPosition to | |
| 64 // display::DisplayPlacement::Position. | |
| 65 display::DisplayPlacement::Position GetDisplayPlacementPosition( | |
| 66 system_display::LayoutPosition position) { | |
| 67 switch (position) { | |
| 68 case system_display::LAYOUT_POSITION_TOP: | |
| 69 return display::DisplayPlacement::TOP; | |
| 70 case system_display::LAYOUT_POSITION_BOTTOM: | |
| 71 return display::DisplayPlacement::BOTTOM; | |
| 72 case system_display::LAYOUT_POSITION_LEFT: | |
| 73 return display::DisplayPlacement::LEFT; | |
| 74 case system_display::LAYOUT_POSITION_RIGHT: | |
| 75 default: | |
| 76 // Default: layout to the right. | |
| 77 return display::DisplayPlacement::RIGHT; | |
| 78 } | |
| 79 } | |
| 80 | |
| 81 // Converts display::DisplayPlacement::Position to | |
| 82 // system_display::LayoutPosition. | |
| 83 system_display::LayoutPosition GetLayoutPosition( | |
| 84 display::DisplayPlacement::Position position) { | |
| 85 switch (position) { | |
| 86 case display::DisplayPlacement::TOP: | |
| 87 return system_display::LayoutPosition::LAYOUT_POSITION_TOP; | |
| 88 case display::DisplayPlacement::RIGHT: | |
| 89 return system_display::LayoutPosition::LAYOUT_POSITION_RIGHT; | |
| 90 case display::DisplayPlacement::BOTTOM: | |
| 91 return system_display::LayoutPosition::LAYOUT_POSITION_BOTTOM; | |
| 92 case display::DisplayPlacement::LEFT: | |
| 93 return system_display::LayoutPosition::LAYOUT_POSITION_LEFT; | |
| 94 } | |
| 95 return system_display::LayoutPosition::LAYOUT_POSITION_NONE; | |
| 96 } | |
| 97 | |
| 65 // Checks if the given point is over the radius vector described by it's end | 98 // Checks if the given point is over the radius vector described by it's end | 
| 66 // point |vector|. The point is over a vector if it's on its positive (left) | 99 // point |vector|. The point is over a vector if it's on its positive (left) | 
| 67 // side. The method sees a point on the same line as the vector as being over | 100 // side. The method sees a point on the same line as the vector as being over | 
| 68 // the vector. | 101 // the vector. | 
| 69 bool PointIsOverRadiusVector(const gfx::Point& point, | 102 bool PointIsOverRadiusVector(const gfx::Point& point, | 
| 70 const gfx::Point& vector) { | 103 const gfx::Point& vector) { | 
| 71 // |point| is left of |vector| if its radius vector's scalar product with a | 104 // |point| is left of |vector| if its radius vector's scalar product with a | 
| 72 // vector orthogonal (and facing the positive side) to |vector| is positive. | 105 // vector orthogonal (and facing the positive side) to |vector| is positive. | 
| 73 // | 106 // | 
| 74 // An orthogonal vector of (a, b) is (b, -a), as the scalar product of these | 107 // An orthogonal vector of (a, b) is (b, -a), as the scalar product of these | 
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 | 219 | 
| 187 ash::Shell::GetInstance() | 220 ash::Shell::GetInstance() | 
| 188 ->display_configuration_controller() | 221 ->display_configuration_controller() | 
| 189 ->SetDisplayLayout(std::move(layout), true /* user_action */); | 222 ->SetDisplayLayout(std::move(layout), true /* user_action */); | 
| 190 } | 223 } | 
| 191 | 224 | 
| 192 // Validates that parameters passed to the SetInfo function are valid for the | 225 // Validates that parameters passed to the SetInfo function are valid for the | 
| 193 // desired display and the current display manager state. | 226 // desired display and the current display manager state. | 
| 194 // Returns whether the parameters are valid. On failure |error| is set to the | 227 // Returns whether the parameters are valid. On failure |error| is set to the | 
| 195 // error message. | 228 // error message. | 
| 196 bool ValidateParamsForDisplay(const DisplayProperties& info, | 229 bool ValidateParamsForDisplay(const system_display::DisplayProperties& info, | 
| 197 const display::Display& display, | 230 const display::Display& display, | 
| 198 ash::DisplayManager* display_manager, | 231 ash::DisplayManager* display_manager, | 
| 199 int64_t primary_display_id, | 232 int64_t primary_display_id, | 
| 200 std::string* error) { | 233 std::string* error) { | 
| 201 int64_t id = display.id(); | 234 int64_t id = display.id(); | 
| 202 bool is_primary = | 235 bool is_primary = | 
| 203 id == primary_display_id || (info.is_primary && *info.is_primary); | 236 id == primary_display_id || (info.is_primary && *info.is_primary); | 
| 204 | 237 | 
| 205 // If mirroring source id is set, a display with the given id should exist, | 238 // If mirroring source id is set, a display with the given id should exist, | 
| 206 // and if should not be the same as the target display's id. | 239 // and if should not be the same as the target display's id. | 
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 // change. | 345 // change. | 
| 313 ash::Shell::GetInstance() | 346 ash::Shell::GetInstance() | 
| 314 ->resolution_notification_controller() | 347 ->resolution_notification_controller() | 
| 315 ->PrepareNotification(id, current_mode, new_mode, | 348 ->PrepareNotification(id, current_mode, new_mode, | 
| 316 base::Bind(&chromeos::StoreDisplayPrefs)); | 349 base::Bind(&chromeos::StoreDisplayPrefs)); | 
| 317 } | 350 } | 
| 318 } | 351 } | 
| 319 return true; | 352 return true; | 
| 320 } | 353 } | 
| 321 | 354 | 
| 322 extensions::api::system_display::DisplayMode GetDisplayMode( | 355 system_display::DisplayMode GetDisplayMode( | 
| 323 ash::DisplayManager* display_manager, | 356 ash::DisplayManager* display_manager, | 
| 324 const ash::DisplayInfo& display_info, | 357 const ash::DisplayInfo& display_info, | 
| 325 const ash::DisplayMode& display_mode) { | 358 const ash::DisplayMode& display_mode) { | 
| 326 extensions::api::system_display::DisplayMode result; | 359 system_display::DisplayMode result; | 
| 327 | 360 | 
| 328 bool is_internal = display::Display::HasInternalDisplay() && | 361 bool is_internal = display::Display::HasInternalDisplay() && | 
| 329 display::Display::InternalDisplayId() == display_info.id(); | 362 display::Display::InternalDisplayId() == display_info.id(); | 
| 330 gfx::Size size_dip = display_mode.GetSizeInDIP(is_internal); | 363 gfx::Size size_dip = display_mode.GetSizeInDIP(is_internal); | 
| 331 result.width = size_dip.width(); | 364 result.width = size_dip.width(); | 
| 332 result.height = size_dip.height(); | 365 result.height = size_dip.height(); | 
| 333 result.width_in_native_pixels = display_mode.size.width(); | 366 result.width_in_native_pixels = display_mode.size.width(); | 
| 334 result.height_in_native_pixels = display_mode.size.height(); | 367 result.height_in_native_pixels = display_mode.size.height(); | 
| 335 result.ui_scale = display_mode.ui_scale; | 368 result.ui_scale = display_mode.ui_scale; | 
| 336 result.device_scale_factor = display_mode.device_scale_factor; | 369 result.device_scale_factor = display_mode.device_scale_factor; | 
| 337 result.is_native = display_mode.native; | 370 result.is_native = display_mode.native; | 
| 338 result.is_selected = display_mode.IsEquivalent( | 371 result.is_selected = display_mode.IsEquivalent( | 
| 339 display_manager->GetActiveModeForDisplayId(display_info.id())); | 372 display_manager->GetActiveModeForDisplayId(display_info.id())); | 
| 340 return result; | 373 return result; | 
| 341 } | 374 } | 
| 342 | 375 | 
| 343 } // namespace | 376 } // namespace | 
| 344 | 377 | 
| 345 DisplayInfoProviderChromeOS::DisplayInfoProviderChromeOS() { | 378 DisplayInfoProviderChromeOS::DisplayInfoProviderChromeOS() {} | 
| 346 } | |
| 347 | 379 | 
| 348 DisplayInfoProviderChromeOS::~DisplayInfoProviderChromeOS() { | 380 DisplayInfoProviderChromeOS::~DisplayInfoProviderChromeOS() {} | 
| 349 } | |
| 350 | 381 | 
| 351 bool DisplayInfoProviderChromeOS::SetInfo(const std::string& display_id_str, | 382 bool DisplayInfoProviderChromeOS::SetInfo( | 
| 352 const DisplayProperties& info, | 383 const std::string& display_id_str, | 
| 353 std::string* error) { | 384 const system_display::DisplayProperties& info, | 
| 385 std::string* error) { | |
| 354 ash::DisplayManager* display_manager = | 386 ash::DisplayManager* display_manager = | 
| 355 ash::Shell::GetInstance()->display_manager(); | 387 ash::Shell::GetInstance()->display_manager(); | 
| 356 ash::DisplayConfigurationController* display_configuration_controller = | 388 ash::DisplayConfigurationController* display_configuration_controller = | 
| 357 ash::Shell::GetInstance()->display_configuration_controller(); | 389 ash::Shell::GetInstance()->display_configuration_controller(); | 
| 358 | 390 | 
| 359 const display::Display target = GetDisplay(display_id_str); | 391 const display::Display target = GetDisplay(display_id_str); | 
| 360 | 392 | 
| 361 if (target.id() == display::Display::kInvalidDisplayID) { | 393 if (target.id() == display::Display::kInvalidDisplayID) { | 
| 362 *error = "Display not found."; | 394 *error = "Display not found."; | 
| 363 return false; | 395 return false; | 
| 364 } | 396 } | 
| 365 | 397 | 
| 366 int64_t display_id = target.id(); | 398 int64_t display_id = target.id(); | 
| 367 const display::Display& primary = | 399 const display::Display& primary = | 
| 368 display::Screen::GetScreen()->GetPrimaryDisplay(); | 400 display::Screen::GetScreen()->GetPrimaryDisplay(); | 
| 369 | 401 | 
| 370 if (!ValidateParamsForDisplay( | 402 if (!ValidateParamsForDisplay(info, target, display_manager, primary.id(), | 
| 371 info, target, display_manager, primary.id(), error)) { | 403 error)) { | 
| 372 return false; | 404 return false; | 
| 373 } | 405 } | 
| 374 | 406 | 
| 375 // Process 'isPrimary' parameter. | 407 // Process 'isPrimary' parameter. | 
| 376 if (info.is_primary && *info.is_primary && target.id() != primary.id()) { | 408 if (info.is_primary && *info.is_primary && target.id() != primary.id()) { | 
| 377 display_configuration_controller->SetPrimaryDisplayId( | 409 display_configuration_controller->SetPrimaryDisplayId( | 
| 378 display_id, true /* user_action */); | 410 display_id, true /* user_action */); | 
| 379 } | 411 } | 
| 380 | 412 | 
| 381 // Process 'mirroringSourceId' parameter. | 413 // Process 'mirroringSourceId' parameter. | 
| 382 if (info.mirroring_source_id) { | 414 if (info.mirroring_source_id) { | 
| 383 bool mirror = !info.mirroring_source_id->empty(); | 415 bool mirror = !info.mirroring_source_id->empty(); | 
| 384 display_configuration_controller->SetMirrorMode(mirror, | 416 display_configuration_controller->SetMirrorMode(mirror, | 
| 385 true /* user_action */); | 417 true /* user_action */); | 
| 386 } | 418 } | 
| 387 | 419 | 
| 388 // Process 'overscan' parameter. | 420 // Process 'overscan' parameter. | 
| 389 if (info.overscan) { | 421 if (info.overscan) { | 
| 390 display_manager->SetOverscanInsets(display_id, | 422 display_manager->SetOverscanInsets( | 
| 391 gfx::Insets(info.overscan->top, | 423 display_id, gfx::Insets(info.overscan->top, info.overscan->left, | 
| 392 info.overscan->left, | 424 info.overscan->bottom, info.overscan->right)); | 
| 393 info.overscan->bottom, | |
| 394 info.overscan->right)); | |
| 395 } | 425 } | 
| 396 | 426 | 
| 397 // Process 'rotation' parameter. | 427 // Process 'rotation' parameter. | 
| 398 if (info.rotation) { | 428 if (info.rotation) { | 
| 399 display_configuration_controller->SetDisplayRotation( | 429 display_configuration_controller->SetDisplayRotation( | 
| 400 display_id, DegreesToRotation(*info.rotation), | 430 display_id, DegreesToRotation(*info.rotation), | 
| 401 display::Display::ROTATION_SOURCE_ACTIVE, true /* user_action */); | 431 display::Display::ROTATION_SOURCE_ACTIVE, true /* user_action */); | 
| 402 } | 432 } | 
| 403 | 433 | 
| 404 // Process new display origin parameters. | 434 // Process new display origin parameters. | 
| 405 gfx::Point new_bounds_origin = target.bounds().origin(); | 435 gfx::Point new_bounds_origin = target.bounds().origin(); | 
| 406 if (info.bounds_origin_x) | 436 if (info.bounds_origin_x) | 
| 407 new_bounds_origin.set_x(*info.bounds_origin_x); | 437 new_bounds_origin.set_x(*info.bounds_origin_x); | 
| 408 if (info.bounds_origin_y) | 438 if (info.bounds_origin_y) | 
| 409 new_bounds_origin.set_y(*info.bounds_origin_y); | 439 new_bounds_origin.set_y(*info.bounds_origin_y); | 
| 410 | 440 | 
| 411 if (new_bounds_origin != target.bounds().origin()) { | 441 if (new_bounds_origin != target.bounds().origin()) { | 
| 412 gfx::Rect target_bounds = target.bounds(); | 442 gfx::Rect target_bounds = target.bounds(); | 
| 413 target_bounds.Offset(new_bounds_origin.x() - target.bounds().x(), | 443 target_bounds.Offset(new_bounds_origin.x() - target.bounds().x(), | 
| 414 new_bounds_origin.y() - target.bounds().y()); | 444 new_bounds_origin.y() - target.bounds().y()); | 
| 415 UpdateDisplayLayout( | 445 UpdateDisplayLayout(primary.bounds(), primary.id(), target_bounds, | 
| 416 primary.bounds(), primary.id(), target_bounds, target.id()); | 446 target.id()); | 
| 417 } | 447 } | 
| 418 | 448 | 
| 419 return true; | 449 return true; | 
| 420 } | 450 } | 
| 421 | 451 | 
| 452 bool DisplayInfoProviderChromeOS::SetDisplayLayout( | |
| 453 const DisplayLayoutList& layouts) { | |
| 454 ash::DisplayManager* display_manager = | |
| 455 ash::Shell::GetInstance()->display_manager(); | |
| 456 display::DisplayLayoutBuilder builder( | |
| 457 display_manager->GetCurrentDisplayLayout()); | |
| 458 | |
| 459 bool have_root = false; | |
| 460 builder.ClearPlacements(); | |
| 461 for (const system_display::DisplayLayout& layout : layouts) { | |
| 462 display::Display display = GetDisplay(layout.id); | |
| 463 if (display.id() == display::Display::kInvalidDisplayID) | |
| 464 return false; | |
| 
oshima
2016/06/20 21:30:33
optinoal: Can this happen? If not, DCHECK or LOG(E
 
stevenjb
2016/06/20 23:28:55
It could if, e.g. the display were unplugged while
 | |
| 465 display::Display parent = GetDisplay(layout.parent_id); | |
| 466 if (parent.id() == display::Display::kInvalidDisplayID) { | |
| 467 if (have_root) | |
| 468 return false; | |
| 469 have_root = true; | |
| 470 continue; // No placement for root (primary) display. | |
| 471 } | |
| 472 display::DisplayPlacement::Position position = | |
| 473 GetDisplayPlacementPosition(layout.position); | |
| 474 builder.AddDisplayPlacement(display.id(), parent.id(), position, | |
| 475 layout.offset); | |
| 476 } | |
| 477 std::unique_ptr<display::DisplayLayout> layout = builder.Build(); | |
| 478 if (!display::DisplayLayout::Validate( | |
| 479 display_manager->GetCurrentDisplayIdList(), *layout)) { | |
| 480 LOG(ERROR) << "Invalid layout passed to SetDisplayLayout"; | |
| 481 return false; | |
| 482 } | |
| 483 ash::Shell::GetInstance() | |
| 484 ->display_configuration_controller() | |
| 485 ->SetDisplayLayout(std::move(layout), true /* user_action */); | |
| 486 return true; | |
| 487 } | |
| 488 | |
| 422 void DisplayInfoProviderChromeOS::UpdateDisplayUnitInfoForPlatform( | 489 void DisplayInfoProviderChromeOS::UpdateDisplayUnitInfoForPlatform( | 
| 423 const display::Display& display, | 490 const display::Display& display, | 
| 424 extensions::api::system_display::DisplayUnitInfo* unit) { | 491 system_display::DisplayUnitInfo* unit) { | 
| 425 ash::DisplayManager* display_manager = | 492 ash::DisplayManager* display_manager = | 
| 426 ash::Shell::GetInstance()->display_manager(); | 493 ash::Shell::GetInstance()->display_manager(); | 
| 427 unit->name = display_manager->GetDisplayNameForId(display.id()); | 494 unit->name = display_manager->GetDisplayNameForId(display.id()); | 
| 428 if (display_manager->IsInMirrorMode()) { | 495 if (display_manager->IsInMirrorMode()) { | 
| 429 unit->mirroring_source_id = | 496 unit->mirroring_source_id = | 
| 430 base::Int64ToString(display_manager->mirroring_display_id()); | 497 base::Int64ToString(display_manager->mirroring_display_id()); | 
| 431 } | 498 } | 
| 432 | 499 | 
| 433 const ash::DisplayInfo& display_info = | 500 const ash::DisplayInfo& display_info = | 
| 434 display_manager->GetDisplayInfo(display.id()); | 501 display_manager->GetDisplayInfo(display.id()); | 
| (...skipping 14 matching lines...) Expand all Loading... | |
| 449 unit->modes.push_back( | 516 unit->modes.push_back( | 
| 450 GetDisplayMode(display_manager, display_info, display_mode)); | 517 GetDisplayMode(display_manager, display_info, display_mode)); | 
| 451 } | 518 } | 
| 452 } | 519 } | 
| 453 | 520 | 
| 454 void DisplayInfoProviderChromeOS::EnableUnifiedDesktop(bool enable) { | 521 void DisplayInfoProviderChromeOS::EnableUnifiedDesktop(bool enable) { | 
| 455 ash::Shell::GetInstance()->display_manager()->SetUnifiedDesktopEnabled( | 522 ash::Shell::GetInstance()->display_manager()->SetUnifiedDesktopEnabled( | 
| 456 enable); | 523 enable); | 
| 457 } | 524 } | 
| 458 | 525 | 
| 459 DisplayUnitInfoList DisplayInfoProviderChromeOS::GetAllDisplaysInfo() { | 526 DisplayInfoProvider::DisplayUnitInfoList | 
| 527 DisplayInfoProviderChromeOS::GetAllDisplaysInfo() { | |
| 460 ash::DisplayManager* display_manager = | 528 ash::DisplayManager* display_manager = | 
| 461 ash::Shell::GetInstance()->display_manager(); | 529 ash::Shell::GetInstance()->display_manager(); | 
| 462 if (!display_manager->IsInUnifiedMode()) | 530 if (!display_manager->IsInUnifiedMode()) | 
| 463 return DisplayInfoProvider::GetAllDisplaysInfo(); | 531 return DisplayInfoProvider::GetAllDisplaysInfo(); | 
| 464 | 532 | 
| 465 std::vector<display::Display> displays = | 533 std::vector<display::Display> displays = | 
| 466 display_manager->software_mirroring_display_list(); | 534 display_manager->software_mirroring_display_list(); | 
| 467 CHECK_GT(displays.size(), 0u); | 535 CHECK_GT(displays.size(), 0u); | 
| 468 | 536 | 
| 469 // Use first display as primary. | 537 // Use first display as primary. | 
| 470 int64_t primary_id = displays[0].id(); | 538 int64_t primary_id = displays[0].id(); | 
| 471 DisplayUnitInfoList all_displays; | 539 DisplayUnitInfoList all_displays; | 
| 472 for (const display::Display& display : displays) { | 540 for (const display::Display& display : displays) { | 
| 473 api::system_display::DisplayUnitInfo unit = | 541 system_display::DisplayUnitInfo unit = | 
| 474 CreateDisplayUnitInfo(display, primary_id); | 542 CreateDisplayUnitInfo(display, primary_id); | 
| 475 UpdateDisplayUnitInfoForPlatform(display, &unit); | 543 UpdateDisplayUnitInfoForPlatform(display, &unit); | 
| 476 all_displays.push_back(std::move(unit)); | 544 all_displays.push_back(std::move(unit)); | 
| 477 } | 545 } | 
| 478 return all_displays; | 546 return all_displays; | 
| 479 } | 547 } | 
| 480 | 548 | 
| 549 DisplayInfoProvider::DisplayLayoutList | |
| 550 DisplayInfoProviderChromeOS::GetDisplayLayout() { | |
| 551 ash::DisplayManager* display_manager = | |
| 552 ash::Shell::GetInstance()->display_manager(); | |
| 553 | |
| 554 display::Screen* screen = display::Screen::GetScreen(); | |
| 555 std::vector<display::Display> displays = screen->GetAllDisplays(); | |
| 556 | |
| 557 DisplayLayoutList result; | |
| 558 for (const display::Display& display : displays) { | |
| 559 const display::DisplayPlacement placement = | |
| 560 display_manager->GetCurrentDisplayLayout().FindPlacementById( | |
| 561 display.id()); | |
| 562 if (placement.display_id == display::Display::kInvalidDisplayID) | |
| 563 continue; | |
| 564 system_display::DisplayLayout display_layout; | |
| 565 display_layout.id = base::Int64ToString(placement.display_id); | |
| 566 display_layout.parent_id = base::Int64ToString(placement.parent_display_id); | |
| 567 display_layout.position = GetLayoutPosition(placement.position); | |
| 568 display_layout.offset = placement.offset; | |
| 569 result.push_back(std::move(display_layout)); | |
| 570 } | |
| 571 return result; | |
| 572 } | |
| 573 | |
| 481 bool DisplayInfoProviderChromeOS::OverscanCalibrationStart( | 574 bool DisplayInfoProviderChromeOS::OverscanCalibrationStart( | 
| 482 const std::string& id) { | 575 const std::string& id) { | 
| 483 VLOG(1) << "OverscanCalibrationStart: " << id; | 576 VLOG(1) << "OverscanCalibrationStart: " << id; | 
| 484 const display::Display display = GetDisplay(id); | 577 const display::Display display = GetDisplay(id); | 
| 485 if (display.id() == display::Display::kInvalidDisplayID) | 578 if (display.id() == display::Display::kInvalidDisplayID) | 
| 486 return false; | 579 return false; | 
| 487 auto insets = | 580 auto insets = | 
| 488 ash::Shell::GetInstance()->window_tree_host_manager()->GetOverscanInsets( | 581 ash::Shell::GetInstance()->window_tree_host_manager()->GetOverscanInsets( | 
| 489 display.id()); | 582 display.id()); | 
| 490 overscan_calibrators_[id].reset( | 583 overscan_calibrators_[id].reset( | 
| 491 new chromeos::OverscanCalibrator(display, insets)); | 584 new chromeos::OverscanCalibrator(display, insets)); | 
| 492 return true; | 585 return true; | 
| 493 } | 586 } | 
| 494 | 587 | 
| 495 bool DisplayInfoProviderChromeOS::OverscanCalibrationAdjust( | 588 bool DisplayInfoProviderChromeOS::OverscanCalibrationAdjust( | 
| 496 const std::string& id, | 589 const std::string& id, | 
| 497 const api::system_display::Insets& delta) { | 590 const system_display::Insets& delta) { | 
| 498 VLOG(1) << "OverscanCalibrationAdjust: " << id; | 591 VLOG(1) << "OverscanCalibrationAdjust: " << id; | 
| 499 chromeos::OverscanCalibrator* calibrator = GetCalibrator(id); | 592 chromeos::OverscanCalibrator* calibrator = GetCalibrator(id); | 
| 500 if (!calibrator) | 593 if (!calibrator) | 
| 501 return false; | 594 return false; | 
| 502 gfx::Insets insets = calibrator->insets(); | 595 gfx::Insets insets = calibrator->insets(); | 
| 503 insets += gfx::Insets(delta.top, delta.left, delta.bottom, delta.right); | 596 insets += gfx::Insets(delta.top, delta.left, delta.bottom, delta.right); | 
| 504 calibrator->UpdateInsets(insets); | 597 calibrator->UpdateInsets(insets); | 
| 505 return true; | 598 return true; | 
| 506 } | 599 } | 
| 507 | 600 | 
| (...skipping 25 matching lines...) Expand all Loading... | |
| 533 return nullptr; | 626 return nullptr; | 
| 534 return iter->second.get(); | 627 return iter->second.get(); | 
| 535 } | 628 } | 
| 536 | 629 | 
| 537 // static | 630 // static | 
| 538 DisplayInfoProvider* DisplayInfoProvider::Create() { | 631 DisplayInfoProvider* DisplayInfoProvider::Create() { | 
| 539 return new DisplayInfoProviderChromeOS(); | 632 return new DisplayInfoProviderChromeOS(); | 
| 540 } | 633 } | 
| 541 | 634 | 
| 542 } // namespace extensions | 635 } // namespace extensions | 
| OLD | NEW |