| 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" | |
| 11 #include "ash/display/resolution_notification_controller.h" | 10 #include "ash/display/resolution_notification_controller.h" |
| 12 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 13 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 14 #include "chrome/browser/chromeos/display/display_preferences.h" | 13 #include "chrome/browser/chromeos/display/display_preferences.h" |
| 15 #include "chrome/browser/chromeos/display/overscan_calibrator.h" | 14 #include "chrome/browser/chromeos/display/overscan_calibrator.h" |
| 16 #include "extensions/common/api/system_display.h" | 15 #include "extensions/common/api/system_display.h" |
| 17 #include "ui/display/display.h" | 16 #include "ui/display/display.h" |
| 18 #include "ui/display/manager/display_layout.h" | 17 #include "ui/display/manager/display_layout.h" |
| 19 #include "ui/display/manager/display_layout_builder.h" | 18 #include "ui/display/manager/display_layout_builder.h" |
| 19 #include "ui/display/manager/display_manager.h" |
| 20 #include "ui/gfx/geometry/point.h" | 20 #include "ui/gfx/geometry/point.h" |
| 21 #include "ui/gfx/geometry/rect.h" | 21 #include "ui/gfx/geometry/rect.h" |
| 22 | 22 |
| 23 namespace extensions { | 23 namespace extensions { |
| 24 | 24 |
| 25 namespace system_display = api::system_display; | 25 namespace system_display = api::system_display; |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 // Maximum allowed bounds origin absolute value. | 29 // Maximum allowed bounds origin absolute value. |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 ->display_configuration_controller() | 221 ->display_configuration_controller() |
| 222 ->SetDisplayLayout(std::move(layout), true /* user_action */); | 222 ->SetDisplayLayout(std::move(layout), true /* user_action */); |
| 223 } | 223 } |
| 224 | 224 |
| 225 // 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 |
| 226 // desired display and the current display manager state. | 226 // desired display and the current display manager state. |
| 227 // 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 |
| 228 // error message. | 228 // error message. |
| 229 bool ValidateParamsForDisplay(const system_display::DisplayProperties& info, | 229 bool ValidateParamsForDisplay(const system_display::DisplayProperties& info, |
| 230 const display::Display& display, | 230 const display::Display& display, |
| 231 ash::DisplayManager* display_manager, | 231 display::DisplayManager* display_manager, |
| 232 int64_t primary_display_id, | 232 int64_t primary_display_id, |
| 233 std::string* error) { | 233 std::string* error) { |
| 234 int64_t id = display.id(); | 234 int64_t id = display.id(); |
| 235 bool is_primary = | 235 bool is_primary = |
| 236 id == primary_display_id || (info.is_primary && *info.is_primary); | 236 id == primary_display_id || (info.is_primary && *info.is_primary); |
| 237 | 237 |
| 238 // 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, |
| 239 // 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. |
| 240 if (info.mirroring_source_id && !info.mirroring_source_id->empty()) { | 240 if (info.mirroring_source_id && !info.mirroring_source_id->empty()) { |
| 241 int64_t mirroring_id = GetDisplay(*info.mirroring_source_id).id(); | 241 int64_t mirroring_id = GetDisplay(*info.mirroring_source_id).id(); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 ash::Shell::GetInstance() | 347 ash::Shell::GetInstance() |
| 348 ->resolution_notification_controller() | 348 ->resolution_notification_controller() |
| 349 ->PrepareNotification(id, current_mode, new_mode, | 349 ->PrepareNotification(id, current_mode, new_mode, |
| 350 base::Bind(&chromeos::StoreDisplayPrefs)); | 350 base::Bind(&chromeos::StoreDisplayPrefs)); |
| 351 } | 351 } |
| 352 } | 352 } |
| 353 return true; | 353 return true; |
| 354 } | 354 } |
| 355 | 355 |
| 356 system_display::DisplayMode GetDisplayMode( | 356 system_display::DisplayMode GetDisplayMode( |
| 357 ash::DisplayManager* display_manager, | 357 display::DisplayManager* display_manager, |
| 358 const display::ManagedDisplayInfo& display_info, | 358 const display::ManagedDisplayInfo& display_info, |
| 359 const scoped_refptr<display::ManagedDisplayMode>& display_mode) { | 359 const scoped_refptr<display::ManagedDisplayMode>& display_mode) { |
| 360 system_display::DisplayMode result; | 360 system_display::DisplayMode result; |
| 361 | 361 |
| 362 bool is_internal = display::Display::HasInternalDisplay() && | 362 bool is_internal = display::Display::HasInternalDisplay() && |
| 363 display::Display::InternalDisplayId() == display_info.id(); | 363 display::Display::InternalDisplayId() == display_info.id(); |
| 364 gfx::Size size_dip = display_mode->GetSizeInDIP(is_internal); | 364 gfx::Size size_dip = display_mode->GetSizeInDIP(is_internal); |
| 365 result.width = size_dip.width(); | 365 result.width = size_dip.width(); |
| 366 result.height = size_dip.height(); | 366 result.height = size_dip.height(); |
| 367 result.width_in_native_pixels = display_mode->size().width(); | 367 result.width_in_native_pixels = display_mode->size().width(); |
| 368 result.height_in_native_pixels = display_mode->size().height(); | 368 result.height_in_native_pixels = display_mode->size().height(); |
| 369 result.ui_scale = display_mode->ui_scale(); | 369 result.ui_scale = display_mode->ui_scale(); |
| 370 result.device_scale_factor = display_mode->device_scale_factor(); | 370 result.device_scale_factor = display_mode->device_scale_factor(); |
| 371 result.is_native = display_mode->native(); | 371 result.is_native = display_mode->native(); |
| 372 result.is_selected = display_mode->IsEquivalent( | 372 result.is_selected = display_mode->IsEquivalent( |
| 373 display_manager->GetActiveModeForDisplayId(display_info.id())); | 373 display_manager->GetActiveModeForDisplayId(display_info.id())); |
| 374 return result; | 374 return result; |
| 375 } | 375 } |
| 376 | 376 |
| 377 } // namespace | 377 } // namespace |
| 378 | 378 |
| 379 DisplayInfoProviderChromeOS::DisplayInfoProviderChromeOS() {} | 379 DisplayInfoProviderChromeOS::DisplayInfoProviderChromeOS() {} |
| 380 | 380 |
| 381 DisplayInfoProviderChromeOS::~DisplayInfoProviderChromeOS() {} | 381 DisplayInfoProviderChromeOS::~DisplayInfoProviderChromeOS() {} |
| 382 | 382 |
| 383 bool DisplayInfoProviderChromeOS::SetInfo( | 383 bool DisplayInfoProviderChromeOS::SetInfo( |
| 384 const std::string& display_id_str, | 384 const std::string& display_id_str, |
| 385 const system_display::DisplayProperties& info, | 385 const system_display::DisplayProperties& info, |
| 386 std::string* error) { | 386 std::string* error) { |
| 387 ash::DisplayManager* display_manager = | 387 display::DisplayManager* display_manager = |
| 388 ash::Shell::GetInstance()->display_manager(); | 388 ash::Shell::GetInstance()->display_manager(); |
| 389 ash::DisplayConfigurationController* display_configuration_controller = | 389 ash::DisplayConfigurationController* display_configuration_controller = |
| 390 ash::Shell::GetInstance()->display_configuration_controller(); | 390 ash::Shell::GetInstance()->display_configuration_controller(); |
| 391 | 391 |
| 392 const display::Display target = GetDisplay(display_id_str); | 392 const display::Display target = GetDisplay(display_id_str); |
| 393 | 393 |
| 394 if (target.id() == display::Display::kInvalidDisplayID) { | 394 if (target.id() == display::Display::kInvalidDisplayID) { |
| 395 *error = "Display not found."; | 395 *error = "Display not found."; |
| 396 return false; | 396 return false; |
| 397 } | 397 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 new_bounds_origin.y() - target.bounds().y()); | 445 new_bounds_origin.y() - target.bounds().y()); |
| 446 UpdateDisplayLayout(primary.bounds(), primary.id(), target_bounds, | 446 UpdateDisplayLayout(primary.bounds(), primary.id(), target_bounds, |
| 447 target.id()); | 447 target.id()); |
| 448 } | 448 } |
| 449 | 449 |
| 450 return true; | 450 return true; |
| 451 } | 451 } |
| 452 | 452 |
| 453 bool DisplayInfoProviderChromeOS::SetDisplayLayout( | 453 bool DisplayInfoProviderChromeOS::SetDisplayLayout( |
| 454 const DisplayLayoutList& layouts) { | 454 const DisplayLayoutList& layouts) { |
| 455 ash::DisplayManager* display_manager = | 455 display::DisplayManager* display_manager = |
| 456 ash::Shell::GetInstance()->display_manager(); | 456 ash::Shell::GetInstance()->display_manager(); |
| 457 display::DisplayLayoutBuilder builder( | 457 display::DisplayLayoutBuilder builder( |
| 458 display_manager->GetCurrentDisplayLayout()); | 458 display_manager->GetCurrentDisplayLayout()); |
| 459 | 459 |
| 460 bool have_root = false; | 460 bool have_root = false; |
| 461 builder.ClearPlacements(); | 461 builder.ClearPlacements(); |
| 462 for (const system_display::DisplayLayout& layout : layouts) { | 462 for (const system_display::DisplayLayout& layout : layouts) { |
| 463 display::Display display = GetDisplay(layout.id); | 463 display::Display display = GetDisplay(layout.id); |
| 464 if (display.id() == display::Display::kInvalidDisplayID) { | 464 if (display.id() == display::Display::kInvalidDisplayID) { |
| 465 LOG(ERROR) << "Invalid layout: display id not found: " << layout.id; | 465 LOG(ERROR) << "Invalid layout: display id not found: " << layout.id; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 487 } | 487 } |
| 488 ash::Shell::GetInstance() | 488 ash::Shell::GetInstance() |
| 489 ->display_configuration_controller() | 489 ->display_configuration_controller() |
| 490 ->SetDisplayLayout(std::move(layout), true /* user_action */); | 490 ->SetDisplayLayout(std::move(layout), true /* user_action */); |
| 491 return true; | 491 return true; |
| 492 } | 492 } |
| 493 | 493 |
| 494 void DisplayInfoProviderChromeOS::UpdateDisplayUnitInfoForPlatform( | 494 void DisplayInfoProviderChromeOS::UpdateDisplayUnitInfoForPlatform( |
| 495 const display::Display& display, | 495 const display::Display& display, |
| 496 system_display::DisplayUnitInfo* unit) { | 496 system_display::DisplayUnitInfo* unit) { |
| 497 ash::DisplayManager* display_manager = | 497 display::DisplayManager* display_manager = |
| 498 ash::Shell::GetInstance()->display_manager(); | 498 ash::Shell::GetInstance()->display_manager(); |
| 499 unit->name = display_manager->GetDisplayNameForId(display.id()); | 499 unit->name = display_manager->GetDisplayNameForId(display.id()); |
| 500 if (display_manager->IsInMirrorMode()) { | 500 if (display_manager->IsInMirrorMode()) { |
| 501 unit->mirroring_source_id = | 501 unit->mirroring_source_id = |
| 502 base::Int64ToString(display_manager->mirroring_display_id()); | 502 base::Int64ToString(display_manager->mirroring_display_id()); |
| 503 } | 503 } |
| 504 | 504 |
| 505 const display::ManagedDisplayInfo& display_info = | 505 const display::ManagedDisplayInfo& display_info = |
| 506 display_manager->GetDisplayInfo(display.id()); | 506 display_manager->GetDisplayInfo(display.id()); |
| 507 const float device_dpi = display_info.device_dpi(); | 507 const float device_dpi = display_info.device_dpi(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 524 } | 524 } |
| 525 } | 525 } |
| 526 | 526 |
| 527 void DisplayInfoProviderChromeOS::EnableUnifiedDesktop(bool enable) { | 527 void DisplayInfoProviderChromeOS::EnableUnifiedDesktop(bool enable) { |
| 528 ash::Shell::GetInstance()->display_manager()->SetUnifiedDesktopEnabled( | 528 ash::Shell::GetInstance()->display_manager()->SetUnifiedDesktopEnabled( |
| 529 enable); | 529 enable); |
| 530 } | 530 } |
| 531 | 531 |
| 532 DisplayInfoProvider::DisplayUnitInfoList | 532 DisplayInfoProvider::DisplayUnitInfoList |
| 533 DisplayInfoProviderChromeOS::GetAllDisplaysInfo() { | 533 DisplayInfoProviderChromeOS::GetAllDisplaysInfo() { |
| 534 ash::DisplayManager* display_manager = | 534 display::DisplayManager* display_manager = |
| 535 ash::Shell::GetInstance()->display_manager(); | 535 ash::Shell::GetInstance()->display_manager(); |
| 536 if (!display_manager->IsInUnifiedMode()) | 536 if (!display_manager->IsInUnifiedMode()) |
| 537 return DisplayInfoProvider::GetAllDisplaysInfo(); | 537 return DisplayInfoProvider::GetAllDisplaysInfo(); |
| 538 | 538 |
| 539 std::vector<display::Display> displays = | 539 std::vector<display::Display> displays = |
| 540 display_manager->software_mirroring_display_list(); | 540 display_manager->software_mirroring_display_list(); |
| 541 CHECK_GT(displays.size(), 0u); | 541 CHECK_GT(displays.size(), 0u); |
| 542 | 542 |
| 543 // Use first display as primary. | 543 // Use first display as primary. |
| 544 int64_t primary_id = displays[0].id(); | 544 int64_t primary_id = displays[0].id(); |
| 545 DisplayUnitInfoList all_displays; | 545 DisplayUnitInfoList all_displays; |
| 546 for (const display::Display& display : displays) { | 546 for (const display::Display& display : displays) { |
| 547 system_display::DisplayUnitInfo unit = | 547 system_display::DisplayUnitInfo unit = |
| 548 CreateDisplayUnitInfo(display, primary_id); | 548 CreateDisplayUnitInfo(display, primary_id); |
| 549 UpdateDisplayUnitInfoForPlatform(display, &unit); | 549 UpdateDisplayUnitInfoForPlatform(display, &unit); |
| 550 all_displays.push_back(std::move(unit)); | 550 all_displays.push_back(std::move(unit)); |
| 551 } | 551 } |
| 552 return all_displays; | 552 return all_displays; |
| 553 } | 553 } |
| 554 | 554 |
| 555 DisplayInfoProvider::DisplayLayoutList | 555 DisplayInfoProvider::DisplayLayoutList |
| 556 DisplayInfoProviderChromeOS::GetDisplayLayout() { | 556 DisplayInfoProviderChromeOS::GetDisplayLayout() { |
| 557 ash::DisplayManager* display_manager = | 557 display::DisplayManager* display_manager = |
| 558 ash::Shell::GetInstance()->display_manager(); | 558 ash::Shell::GetInstance()->display_manager(); |
| 559 | 559 |
| 560 if (display_manager->num_connected_displays() < 2) | 560 if (display_manager->num_connected_displays() < 2) |
| 561 return DisplayInfoProvider::DisplayLayoutList(); | 561 return DisplayInfoProvider::DisplayLayoutList(); |
| 562 | 562 |
| 563 display::Screen* screen = display::Screen::GetScreen(); | 563 display::Screen* screen = display::Screen::GetScreen(); |
| 564 std::vector<display::Display> displays = screen->GetAllDisplays(); | 564 std::vector<display::Display> displays = screen->GetAllDisplays(); |
| 565 | 565 |
| 566 DisplayLayoutList result; | 566 DisplayLayoutList result; |
| 567 for (const display::Display& display : displays) { | 567 for (const display::Display& display : displays) { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 return nullptr; | 635 return nullptr; |
| 636 return iter->second.get(); | 636 return iter->second.get(); |
| 637 } | 637 } |
| 638 | 638 |
| 639 // static | 639 // static |
| 640 DisplayInfoProvider* DisplayInfoProvider::Create() { | 640 DisplayInfoProvider* DisplayInfoProvider::Create() { |
| 641 return new DisplayInfoProviderChromeOS(); | 641 return new DisplayInfoProviderChromeOS(); |
| 642 } | 642 } |
| 643 | 643 |
| 644 } // namespace extensions | 644 } // namespace extensions |
| OLD | NEW |