| 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/resolution_notification_controller.h" | 10 #include "ash/display/resolution_notification_controller.h" |
| 11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "chrome/browser/chromeos/display/display_preferences.h" | 13 #include "chrome/browser/chromeos/display/display_preferences.h" |
| 14 #include "chrome/browser/chromeos/display/overscan_calibrator.h" | 14 #include "chrome/browser/chromeos/display/overscan_calibrator.h" |
| 15 #include "extensions/common/api/system_display.h" | 15 #include "extensions/common/api/system_display.h" |
| 16 #include "ui/display/display.h" | 16 #include "ui/display/display.h" |
| 17 #include "ui/display/manager/display_layout.h" | 17 #include "ui/display/manager/display_layout.h" |
| 18 #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" | 19 #include "ui/display/manager/display_manager.h" |
| 20 #include "ui/display/types/display_constants.h" |
| 20 #include "ui/gfx/geometry/point.h" | 21 #include "ui/gfx/geometry/point.h" |
| 21 #include "ui/gfx/geometry/rect.h" | 22 #include "ui/gfx/geometry/rect.h" |
| 22 | 23 |
| 23 namespace extensions { | 24 namespace extensions { |
| 24 | 25 |
| 25 namespace system_display = api::system_display; | 26 namespace system_display = api::system_display; |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 // Maximum allowed bounds origin absolute value. | 30 // Maximum allowed bounds origin absolute value. |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 int64_t primary_display_id, | 233 int64_t primary_display_id, |
| 233 std::string* error) { | 234 std::string* error) { |
| 234 int64_t id = display.id(); | 235 int64_t id = display.id(); |
| 235 bool is_primary = | 236 bool is_primary = |
| 236 id == primary_display_id || (info.is_primary && *info.is_primary); | 237 id == primary_display_id || (info.is_primary && *info.is_primary); |
| 237 | 238 |
| 238 // If mirroring source id is set, a display with the given id should exist, | 239 // 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. | 240 // and if should not be the same as the target display's id. |
| 240 if (info.mirroring_source_id && !info.mirroring_source_id->empty()) { | 241 if (info.mirroring_source_id && !info.mirroring_source_id->empty()) { |
| 241 int64_t mirroring_id = GetDisplay(*info.mirroring_source_id).id(); | 242 int64_t mirroring_id = GetDisplay(*info.mirroring_source_id).id(); |
| 242 if (mirroring_id == display::Display::kInvalidDisplayID) { | 243 if (mirroring_id == display::kInvalidDisplayId) { |
| 243 *error = "Display " + *info.mirroring_source_id + " not found."; | 244 *error = "Display " + *info.mirroring_source_id + " not found."; |
| 244 return false; | 245 return false; |
| 245 } | 246 } |
| 246 | 247 |
| 247 if (*info.mirroring_source_id == base::Int64ToString(id)) { | 248 if (*info.mirroring_source_id == base::Int64ToString(id)) { |
| 248 *error = "Not allowed to mirror self."; | 249 *error = "Not allowed to mirror self."; |
| 249 return false; | 250 return false; |
| 250 } | 251 } |
| 251 } | 252 } |
| 252 | 253 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 const std::string& display_id_str, | 385 const std::string& display_id_str, |
| 385 const system_display::DisplayProperties& info, | 386 const system_display::DisplayProperties& info, |
| 386 std::string* error) { | 387 std::string* error) { |
| 387 display::DisplayManager* display_manager = | 388 display::DisplayManager* display_manager = |
| 388 ash::Shell::GetInstance()->display_manager(); | 389 ash::Shell::GetInstance()->display_manager(); |
| 389 ash::DisplayConfigurationController* display_configuration_controller = | 390 ash::DisplayConfigurationController* display_configuration_controller = |
| 390 ash::Shell::GetInstance()->display_configuration_controller(); | 391 ash::Shell::GetInstance()->display_configuration_controller(); |
| 391 | 392 |
| 392 const display::Display target = GetDisplay(display_id_str); | 393 const display::Display target = GetDisplay(display_id_str); |
| 393 | 394 |
| 394 if (target.id() == display::Display::kInvalidDisplayID) { | 395 if (target.id() == display::kInvalidDisplayId) { |
| 395 *error = "Display not found."; | 396 *error = "Display not found."; |
| 396 return false; | 397 return false; |
| 397 } | 398 } |
| 398 | 399 |
| 399 int64_t display_id = target.id(); | 400 int64_t display_id = target.id(); |
| 400 const display::Display& primary = | 401 const display::Display& primary = |
| 401 display::Screen::GetScreen()->GetPrimaryDisplay(); | 402 display::Screen::GetScreen()->GetPrimaryDisplay(); |
| 402 | 403 |
| 403 if (!ValidateParamsForDisplay(info, target, display_manager, primary.id(), | 404 if (!ValidateParamsForDisplay(info, target, display_manager, primary.id(), |
| 404 error)) { | 405 error)) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 const DisplayLayoutList& layouts) { | 455 const DisplayLayoutList& layouts) { |
| 455 display::DisplayManager* display_manager = | 456 display::DisplayManager* display_manager = |
| 456 ash::Shell::GetInstance()->display_manager(); | 457 ash::Shell::GetInstance()->display_manager(); |
| 457 display::DisplayLayoutBuilder builder( | 458 display::DisplayLayoutBuilder builder( |
| 458 display_manager->GetCurrentDisplayLayout()); | 459 display_manager->GetCurrentDisplayLayout()); |
| 459 | 460 |
| 460 bool have_root = false; | 461 bool have_root = false; |
| 461 builder.ClearPlacements(); | 462 builder.ClearPlacements(); |
| 462 for (const system_display::DisplayLayout& layout : layouts) { | 463 for (const system_display::DisplayLayout& layout : layouts) { |
| 463 display::Display display = GetDisplay(layout.id); | 464 display::Display display = GetDisplay(layout.id); |
| 464 if (display.id() == display::Display::kInvalidDisplayID) { | 465 if (display.id() == display::kInvalidDisplayId) { |
| 465 LOG(ERROR) << "Invalid layout: display id not found: " << layout.id; | 466 LOG(ERROR) << "Invalid layout: display id not found: " << layout.id; |
| 466 return false; | 467 return false; |
| 467 } | 468 } |
| 468 display::Display parent = GetDisplay(layout.parent_id); | 469 display::Display parent = GetDisplay(layout.parent_id); |
| 469 if (parent.id() == display::Display::kInvalidDisplayID) { | 470 if (parent.id() == display::kInvalidDisplayId) { |
| 470 if (have_root) { | 471 if (have_root) { |
| 471 LOG(ERROR) << "Invalid layout: multople roots."; | 472 LOG(ERROR) << "Invalid layout: multople roots."; |
| 472 return false; | 473 return false; |
| 473 } | 474 } |
| 474 have_root = true; | 475 have_root = true; |
| 475 continue; // No placement for root (primary) display. | 476 continue; // No placement for root (primary) display. |
| 476 } | 477 } |
| 477 display::DisplayPlacement::Position position = | 478 display::DisplayPlacement::Position position = |
| 478 GetDisplayPlacementPosition(layout.position); | 479 GetDisplayPlacementPosition(layout.position); |
| 479 builder.AddDisplayPlacement(display.id(), parent.id(), position, | 480 builder.AddDisplayPlacement(display.id(), parent.id(), position, |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 return DisplayInfoProvider::DisplayLayoutList(); | 562 return DisplayInfoProvider::DisplayLayoutList(); |
| 562 | 563 |
| 563 display::Screen* screen = display::Screen::GetScreen(); | 564 display::Screen* screen = display::Screen::GetScreen(); |
| 564 std::vector<display::Display> displays = screen->GetAllDisplays(); | 565 std::vector<display::Display> displays = screen->GetAllDisplays(); |
| 565 | 566 |
| 566 DisplayLayoutList result; | 567 DisplayLayoutList result; |
| 567 for (const display::Display& display : displays) { | 568 for (const display::Display& display : displays) { |
| 568 const display::DisplayPlacement placement = | 569 const display::DisplayPlacement placement = |
| 569 display_manager->GetCurrentDisplayLayout().FindPlacementById( | 570 display_manager->GetCurrentDisplayLayout().FindPlacementById( |
| 570 display.id()); | 571 display.id()); |
| 571 if (placement.display_id == display::Display::kInvalidDisplayID) | 572 if (placement.display_id == display::kInvalidDisplayId) |
| 572 continue; | 573 continue; |
| 573 system_display::DisplayLayout display_layout; | 574 system_display::DisplayLayout display_layout; |
| 574 display_layout.id = base::Int64ToString(placement.display_id); | 575 display_layout.id = base::Int64ToString(placement.display_id); |
| 575 display_layout.parent_id = base::Int64ToString(placement.parent_display_id); | 576 display_layout.parent_id = base::Int64ToString(placement.parent_display_id); |
| 576 display_layout.position = GetLayoutPosition(placement.position); | 577 display_layout.position = GetLayoutPosition(placement.position); |
| 577 display_layout.offset = placement.offset; | 578 display_layout.offset = placement.offset; |
| 578 result.push_back(std::move(display_layout)); | 579 result.push_back(std::move(display_layout)); |
| 579 } | 580 } |
| 580 return result; | 581 return result; |
| 581 } | 582 } |
| 582 | 583 |
| 583 bool DisplayInfoProviderChromeOS::OverscanCalibrationStart( | 584 bool DisplayInfoProviderChromeOS::OverscanCalibrationStart( |
| 584 const std::string& id) { | 585 const std::string& id) { |
| 585 VLOG(1) << "OverscanCalibrationStart: " << id; | 586 VLOG(1) << "OverscanCalibrationStart: " << id; |
| 586 const display::Display display = GetDisplay(id); | 587 const display::Display display = GetDisplay(id); |
| 587 if (display.id() == display::Display::kInvalidDisplayID) | 588 if (display.id() == display::kInvalidDisplayId) |
| 588 return false; | 589 return false; |
| 589 auto insets = | 590 auto insets = |
| 590 ash::Shell::GetInstance()->window_tree_host_manager()->GetOverscanInsets( | 591 ash::Shell::GetInstance()->window_tree_host_manager()->GetOverscanInsets( |
| 591 display.id()); | 592 display.id()); |
| 592 overscan_calibrators_[id].reset( | 593 overscan_calibrators_[id].reset( |
| 593 new chromeos::OverscanCalibrator(display, insets)); | 594 new chromeos::OverscanCalibrator(display, insets)); |
| 594 return true; | 595 return true; |
| 595 } | 596 } |
| 596 | 597 |
| 597 bool DisplayInfoProviderChromeOS::OverscanCalibrationAdjust( | 598 bool DisplayInfoProviderChromeOS::OverscanCalibrationAdjust( |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 return nullptr; | 636 return nullptr; |
| 636 return iter->second.get(); | 637 return iter->second.get(); |
| 637 } | 638 } |
| 638 | 639 |
| 639 // static | 640 // static |
| 640 DisplayInfoProvider* DisplayInfoProvider::Create() { | 641 DisplayInfoProvider* DisplayInfoProvider::Create() { |
| 641 return new DisplayInfoProviderChromeOS(); | 642 return new DisplayInfoProviderChromeOS(); |
| 642 } | 643 } |
| 643 | 644 |
| 644 } // namespace extensions | 645 } // namespace extensions |
| OLD | NEW |