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