| 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 "chrome/browser/chromeos/display/touch_calibrator/touch_calibrator_cont
roller.h" |
| 15 #include "extensions/common/api/system_display.h" | 16 #include "extensions/common/api/system_display.h" |
| 16 #include "ui/display/display.h" | 17 #include "ui/display/display.h" |
| 17 #include "ui/display/display_layout.h" | 18 #include "ui/display/display_layout.h" |
| 18 #include "ui/display/display_layout_builder.h" | 19 #include "ui/display/display_layout_builder.h" |
| 19 #include "ui/display/manager/display_manager.h" | 20 #include "ui/display/manager/display_manager.h" |
| 20 #include "ui/display/types/display_constants.h" | 21 #include "ui/display/types/display_constants.h" |
| 21 #include "ui/gfx/geometry/point.h" | 22 #include "ui/gfx/geometry/point.h" |
| 22 #include "ui/gfx/geometry/rect.h" | 23 #include "ui/gfx/geometry/rect.h" |
| 23 | 24 |
| 24 namespace extensions { | 25 namespace extensions { |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 result.width_in_native_pixels = display_mode->size().width(); | 369 result.width_in_native_pixels = display_mode->size().width(); |
| 369 result.height_in_native_pixels = display_mode->size().height(); | 370 result.height_in_native_pixels = display_mode->size().height(); |
| 370 result.ui_scale = display_mode->ui_scale(); | 371 result.ui_scale = display_mode->ui_scale(); |
| 371 result.device_scale_factor = display_mode->device_scale_factor(); | 372 result.device_scale_factor = display_mode->device_scale_factor(); |
| 372 result.is_native = display_mode->native(); | 373 result.is_native = display_mode->native(); |
| 373 result.is_selected = display_mode->IsEquivalent( | 374 result.is_selected = display_mode->IsEquivalent( |
| 374 display_manager->GetActiveModeForDisplayId(display_info.id())); | 375 display_manager->GetActiveModeForDisplayId(display_info.id())); |
| 375 return result; | 376 return result; |
| 376 } | 377 } |
| 377 | 378 |
| 379 display::TouchCalibrationData::CalibrationPointPair GetCalibrationPair( |
| 380 const system_display::TouchCalibrationPair& pair) { |
| 381 return std::make_pair(gfx::Point(pair.display_point.x, pair.display_point.y), |
| 382 gfx::Point(pair.touch_point.x, pair.touch_point.y)); |
| 383 } |
| 384 |
| 385 bool ValidateParamsForTouchCalibration( |
| 386 const std::string& id, |
| 387 const display::Display& display, |
| 388 chromeos::TouchCalibratorController* const touch_calibrator_controller, |
| 389 std::string* error) { |
| 390 if (display.id() == display::kInvalidDisplayId) { |
| 391 *error = "Display Id(" + id + ") is an invalid display ID"; |
| 392 return false; |
| 393 } |
| 394 |
| 395 if (display.IsInternal()) { |
| 396 *error = "Display Id(" + id + ") is an internal display. Internal " + |
| 397 "displays cannot be calibrated for touch."; |
| 398 return false; |
| 399 } |
| 400 |
| 401 if (display.touch_support() != display::Display::TOUCH_SUPPORT_AVAILABLE) { |
| 402 *error = "Display Id(" + id + ") does not support touch."; |
| 403 return false; |
| 404 } |
| 405 |
| 406 return true; |
| 407 } |
| 408 |
| 378 } // namespace | 409 } // namespace |
| 379 | 410 |
| 380 DisplayInfoProviderChromeOS::DisplayInfoProviderChromeOS() {} | 411 DisplayInfoProviderChromeOS::DisplayInfoProviderChromeOS() {} |
| 381 | 412 |
| 382 DisplayInfoProviderChromeOS::~DisplayInfoProviderChromeOS() {} | 413 DisplayInfoProviderChromeOS::~DisplayInfoProviderChromeOS() {} |
| 383 | 414 |
| 384 bool DisplayInfoProviderChromeOS::SetInfo( | 415 bool DisplayInfoProviderChromeOS::SetInfo( |
| 385 const std::string& display_id_str, | 416 const std::string& display_id_str, |
| 386 const system_display::DisplayProperties& info, | 417 const system_display::DisplayProperties& info, |
| 387 std::string* error) { | 418 std::string* error) { |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 display.id()); | 623 display.id()); |
| 593 overscan_calibrators_[id].reset( | 624 overscan_calibrators_[id].reset( |
| 594 new chromeos::OverscanCalibrator(display, insets)); | 625 new chromeos::OverscanCalibrator(display, insets)); |
| 595 return true; | 626 return true; |
| 596 } | 627 } |
| 597 | 628 |
| 598 bool DisplayInfoProviderChromeOS::OverscanCalibrationAdjust( | 629 bool DisplayInfoProviderChromeOS::OverscanCalibrationAdjust( |
| 599 const std::string& id, | 630 const std::string& id, |
| 600 const system_display::Insets& delta) { | 631 const system_display::Insets& delta) { |
| 601 VLOG(1) << "OverscanCalibrationAdjust: " << id; | 632 VLOG(1) << "OverscanCalibrationAdjust: " << id; |
| 602 chromeos::OverscanCalibrator* calibrator = GetCalibrator(id); | 633 chromeos::OverscanCalibrator* calibrator = GetOverscanCalibrator(id); |
| 603 if (!calibrator) | 634 if (!calibrator) |
| 604 return false; | 635 return false; |
| 605 gfx::Insets insets = calibrator->insets(); | 636 gfx::Insets insets = calibrator->insets(); |
| 606 insets += gfx::Insets(delta.top, delta.left, delta.bottom, delta.right); | 637 insets += gfx::Insets(delta.top, delta.left, delta.bottom, delta.right); |
| 607 calibrator->UpdateInsets(insets); | 638 calibrator->UpdateInsets(insets); |
| 608 return true; | 639 return true; |
| 609 } | 640 } |
| 610 | 641 |
| 611 bool DisplayInfoProviderChromeOS::OverscanCalibrationReset( | 642 bool DisplayInfoProviderChromeOS::OverscanCalibrationReset( |
| 612 const std::string& id) { | 643 const std::string& id) { |
| 613 VLOG(1) << "OverscanCalibrationReset: " << id; | 644 VLOG(1) << "OverscanCalibrationReset: " << id; |
| 614 chromeos::OverscanCalibrator* calibrator = GetCalibrator(id); | 645 chromeos::OverscanCalibrator* calibrator = GetOverscanCalibrator(id); |
| 615 if (!calibrator) | 646 if (!calibrator) |
| 616 return false; | 647 return false; |
| 617 calibrator->Reset(); | 648 calibrator->Reset(); |
| 618 return true; | 649 return true; |
| 619 } | 650 } |
| 620 | 651 |
| 621 bool DisplayInfoProviderChromeOS::OverscanCalibrationComplete( | 652 bool DisplayInfoProviderChromeOS::OverscanCalibrationComplete( |
| 622 const std::string& id) { | 653 const std::string& id) { |
| 623 VLOG(1) << "OverscanCalibrationComplete: " << id; | 654 VLOG(1) << "OverscanCalibrationComplete: " << id; |
| 624 chromeos::OverscanCalibrator* calibrator = GetCalibrator(id); | 655 chromeos::OverscanCalibrator* calibrator = GetOverscanCalibrator(id); |
| 625 if (!calibrator) | 656 if (!calibrator) |
| 626 return false; | 657 return false; |
| 627 calibrator->Commit(); | 658 calibrator->Commit(); |
| 628 overscan_calibrators_[id].reset(); | 659 overscan_calibrators_[id].reset(); |
| 629 return true; | 660 return true; |
| 630 } | 661 } |
| 631 | 662 |
| 632 chromeos::OverscanCalibrator* DisplayInfoProviderChromeOS::GetCalibrator( | 663 bool DisplayInfoProviderChromeOS::TouchCalibrationSet( |
| 633 const std::string& id) { | 664 const std::string& id, |
| 665 const api::system_display::TouchCalibrationPairQuad& pairs, |
| 666 const api::system_display::Bounds& bounds, |
| 667 std::string* error) { |
| 668 VLOG(1) << "TouchCalibrationSet: " << id; |
| 669 |
| 670 const display::Display display = GetDisplay(id); |
| 671 if (!ValidateParamsForTouchCalibration(id, display, GetTouchCalibrator(), |
| 672 error)) { |
| 673 return false; |
| 674 } |
| 675 |
| 676 display::TouchCalibrationData::CalibrationPointPairQuad calibration_points; |
| 677 calibration_points[0] = GetCalibrationPair(pairs.pair1); |
| 678 calibration_points[1] = GetCalibrationPair(pairs.pair2); |
| 679 calibration_points[2] = GetCalibrationPair(pairs.pair3); |
| 680 calibration_points[3] = GetCalibrationPair(pairs.pair4); |
| 681 |
| 682 // The display bounds cannot have negative values. |
| 683 if (bounds.width < 0 || bounds.height < 0) { |
| 684 *error = "Bounds cannot have negative values."; |
| 685 return false; |
| 686 } |
| 687 |
| 688 for (size_t row = 0; row < calibration_points.size(); row++) { |
| 689 // Coordinates for display and touch point cannot be negative. |
| 690 if (calibration_points[row].first.x() < 0 || |
| 691 calibration_points[row].first.y() < 0 || |
| 692 calibration_points[row].second.x() < 0 || |
| 693 calibration_points[row].second.y() < 0) { |
| 694 *error = "Display points and touch points cannot have negative " |
| 695 "coordinates"; |
| 696 return false; |
| 697 } |
| 698 // Coordinates for display points cannot be greater than the screen bounds. |
| 699 if (calibration_points[row].first.x() > bounds.width || |
| 700 calibration_points[row].first.y() > bounds.height) { |
| 701 *error = "Display point coordinates cannot be more than size of the " |
| 702 "display."; |
| 703 return false; |
| 704 } |
| 705 } |
| 706 |
| 707 gfx::Size display_size(bounds.width, bounds.height); |
| 708 ash::Shell::GetInstance()->display_manager()->SetTouchCalibrationData( |
| 709 display.id(), calibration_points, display_size); |
| 710 return true; |
| 711 } |
| 712 |
| 713 bool DisplayInfoProviderChromeOS::TouchCalibrationReset(const std::string& id, |
| 714 std::string* error) { |
| 715 const display::Display display = GetDisplay(id); |
| 716 |
| 717 if (!ValidateParamsForTouchCalibration(id, display, GetTouchCalibrator(), |
| 718 error)) { |
| 719 return false; |
| 720 } |
| 721 |
| 722 ash::Shell::GetInstance()->display_manager()->ClearTouchCalibrationData( |
| 723 display.id()); |
| 724 return true; |
| 725 } |
| 726 |
| 727 bool DisplayInfoProviderChromeOS::IsTouchCalibrationActive(std::string* error) { |
| 728 if (GetTouchCalibrator()->is_calibrating()) { |
| 729 *error = "Another touch calibration is already active."; |
| 730 return true; |
| 731 } |
| 732 return false; |
| 733 } |
| 734 |
| 735 chromeos::OverscanCalibrator* |
| 736 DisplayInfoProviderChromeOS::GetOverscanCalibrator(const std::string& id) { |
| 634 auto iter = overscan_calibrators_.find(id); | 737 auto iter = overscan_calibrators_.find(id); |
| 635 if (iter == overscan_calibrators_.end()) | 738 if (iter == overscan_calibrators_.end()) |
| 636 return nullptr; | 739 return nullptr; |
| 637 return iter->second.get(); | 740 return iter->second.get(); |
| 638 } | 741 } |
| 639 | 742 |
| 743 chromeos::TouchCalibratorController* |
| 744 DisplayInfoProviderChromeOS::GetTouchCalibrator() { |
| 745 if (!touch_calibrator_) |
| 746 touch_calibrator_.reset(new chromeos::TouchCalibratorController); |
| 747 return touch_calibrator_.get(); |
| 748 } |
| 749 |
| 640 // static | 750 // static |
| 641 DisplayInfoProvider* DisplayInfoProvider::Create() { | 751 DisplayInfoProvider* DisplayInfoProvider::Create() { |
| 642 return new DisplayInfoProviderChromeOS(); | 752 return new DisplayInfoProviderChromeOS(); |
| 643 } | 753 } |
| 644 | 754 |
| 645 } // namespace extensions | 755 } // namespace extensions |
| OLD | NEW |