Chromium Code Reviews| 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 = std::string("Display Id(" + id + ") is an invalid display ID"); | |
|
stevenjb
2016/12/27 19:37:26
nit: std::string() not needed.
malaykeshav
2016/12/27 20:07:00
Done
| |
| 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 if (touch_calibrator_controller->is_calibrating()) { | |
| 407 *error = "Another calibration is already under progress"; | |
| 408 return false; | |
| 409 } | |
| 410 return true; | |
| 411 } | |
| 412 | |
| 378 } // namespace | 413 } // namespace |
| 379 | 414 |
| 380 DisplayInfoProviderChromeOS::DisplayInfoProviderChromeOS() {} | 415 DisplayInfoProviderChromeOS::DisplayInfoProviderChromeOS() {} |
| 381 | 416 |
| 382 DisplayInfoProviderChromeOS::~DisplayInfoProviderChromeOS() {} | 417 DisplayInfoProviderChromeOS::~DisplayInfoProviderChromeOS() {} |
| 383 | 418 |
| 384 bool DisplayInfoProviderChromeOS::SetInfo( | 419 bool DisplayInfoProviderChromeOS::SetInfo( |
| 385 const std::string& display_id_str, | 420 const std::string& display_id_str, |
| 386 const system_display::DisplayProperties& info, | 421 const system_display::DisplayProperties& info, |
| 387 std::string* error) { | 422 std::string* error) { |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 592 display.id()); | 627 display.id()); |
| 593 overscan_calibrators_[id].reset( | 628 overscan_calibrators_[id].reset( |
| 594 new chromeos::OverscanCalibrator(display, insets)); | 629 new chromeos::OverscanCalibrator(display, insets)); |
| 595 return true; | 630 return true; |
| 596 } | 631 } |
| 597 | 632 |
| 598 bool DisplayInfoProviderChromeOS::OverscanCalibrationAdjust( | 633 bool DisplayInfoProviderChromeOS::OverscanCalibrationAdjust( |
| 599 const std::string& id, | 634 const std::string& id, |
| 600 const system_display::Insets& delta) { | 635 const system_display::Insets& delta) { |
| 601 VLOG(1) << "OverscanCalibrationAdjust: " << id; | 636 VLOG(1) << "OverscanCalibrationAdjust: " << id; |
| 602 chromeos::OverscanCalibrator* calibrator = GetCalibrator(id); | 637 chromeos::OverscanCalibrator* calibrator = GetOverscanCalibrator(id); |
| 603 if (!calibrator) | 638 if (!calibrator) |
| 604 return false; | 639 return false; |
| 605 gfx::Insets insets = calibrator->insets(); | 640 gfx::Insets insets = calibrator->insets(); |
| 606 insets += gfx::Insets(delta.top, delta.left, delta.bottom, delta.right); | 641 insets += gfx::Insets(delta.top, delta.left, delta.bottom, delta.right); |
| 607 calibrator->UpdateInsets(insets); | 642 calibrator->UpdateInsets(insets); |
| 608 return true; | 643 return true; |
| 609 } | 644 } |
| 610 | 645 |
| 611 bool DisplayInfoProviderChromeOS::OverscanCalibrationReset( | 646 bool DisplayInfoProviderChromeOS::OverscanCalibrationReset( |
| 612 const std::string& id) { | 647 const std::string& id) { |
| 613 VLOG(1) << "OverscanCalibrationReset: " << id; | 648 VLOG(1) << "OverscanCalibrationReset: " << id; |
| 614 chromeos::OverscanCalibrator* calibrator = GetCalibrator(id); | 649 chromeos::OverscanCalibrator* calibrator = GetOverscanCalibrator(id); |
| 615 if (!calibrator) | 650 if (!calibrator) |
| 616 return false; | 651 return false; |
| 617 calibrator->Reset(); | 652 calibrator->Reset(); |
| 618 return true; | 653 return true; |
| 619 } | 654 } |
| 620 | 655 |
| 621 bool DisplayInfoProviderChromeOS::OverscanCalibrationComplete( | 656 bool DisplayInfoProviderChromeOS::OverscanCalibrationComplete( |
| 622 const std::string& id) { | 657 const std::string& id) { |
| 623 VLOG(1) << "OverscanCalibrationComplete: " << id; | 658 VLOG(1) << "OverscanCalibrationComplete: " << id; |
| 624 chromeos::OverscanCalibrator* calibrator = GetCalibrator(id); | 659 chromeos::OverscanCalibrator* calibrator = GetOverscanCalibrator(id); |
| 625 if (!calibrator) | 660 if (!calibrator) |
| 626 return false; | 661 return false; |
| 627 calibrator->Commit(); | 662 calibrator->Commit(); |
| 628 overscan_calibrators_[id].reset(); | 663 overscan_calibrators_[id].reset(); |
| 629 return true; | 664 return true; |
| 630 } | 665 } |
| 631 | 666 |
| 632 chromeos::OverscanCalibrator* DisplayInfoProviderChromeOS::GetCalibrator( | 667 bool DisplayInfoProviderChromeOS::TouchCalibrationSet( |
| 633 const std::string& id) { | 668 const std::string& id, |
| 669 const api::system_display::TouchCalibrationPairQuad& pairs, | |
| 670 const api::system_display::Bounds& bounds, | |
| 671 std::string* error) { | |
| 672 VLOG(1) << "TouchCalibrationSet: " << id; | |
| 673 | |
| 674 const display::Display display = GetDisplay(id); | |
| 675 if (!ValidateParamsForTouchCalibration(id, display, GetTouchCalibrator(), | |
| 676 error)) { | |
| 677 return false; | |
| 678 } | |
| 679 | |
| 680 display::TouchCalibrationData::CalibrationPointPairQuad calibration_points; | |
| 681 calibration_points[0] = GetCalibrationPair(pairs.pair1); | |
| 682 calibration_points[1] = GetCalibrationPair(pairs.pair2); | |
| 683 calibration_points[2] = GetCalibrationPair(pairs.pair3); | |
| 684 calibration_points[3] = GetCalibrationPair(pairs.pair4); | |
| 685 gfx::Size display_size(bounds.width, bounds.height); | |
| 686 | |
| 687 // The display bounds cannot have negative values. | |
| 688 if (bounds.width < 0 || bounds.height < 0) { | |
| 689 *error = "Bounds cannot have negative values."; | |
| 690 return false; | |
| 691 } | |
| 692 | |
| 693 // The display points must be withing the display bounds while the touch | |
|
stevenjb
2016/12/27 19:37:26
within
malaykeshav
2016/12/27 20:07:00
done
| |
| 694 // points must be non negative. | |
| 695 for (size_t row = 0; row < calibration_points.size(); row++) { | |
| 696 if (calibration_points[row].first.x() < 0 || | |
| 697 calibration_points[row].first.y() < 0 || | |
| 698 calibration_points[row].second.x() < 0 || | |
| 699 calibration_points[row].second.y() < 0) { | |
| 700 *error = std::string("Display points and touch points cannot have") + | |
| 701 " negative coordinates"; | |
| 702 return false; | |
| 703 } | |
| 704 if (calibration_points[row].first.x() > bounds.width || | |
| 705 calibration_points[row].first.y() > bounds.height) { | |
| 706 *error = std::string("Display point coordinates cannot be more than") + | |
| 707 " size of the display."; | |
| 708 return false; | |
| 709 } | |
|
stevenjb
2016/12/27 19:37:26
Nit: invert comment above or logic order to match.
malaykeshav
2016/12/27 20:07:00
Done
| |
| 710 } | |
| 711 | |
| 712 ash::Shell::GetInstance()->display_manager()->SetTouchCalibrationData( | |
| 713 display.id(), calibration_points, display_size); | |
| 714 return true; | |
| 715 } | |
| 716 | |
| 717 bool DisplayInfoProviderChromeOS::TouchCalibrationReset(const std::string& id, | |
| 718 std::string* error) { | |
| 719 const display::Display display = GetDisplay(id); | |
| 720 | |
| 721 if (!ValidateParamsForTouchCalibration(id, display, GetTouchCalibrator(), | |
| 722 error)) { | |
| 723 return false; | |
| 724 } | |
| 725 | |
| 726 ash::Shell::GetInstance()->display_manager()->ClearTouchCalibrationData( | |
| 727 display.id()); | |
| 728 return true; | |
| 729 } | |
| 730 | |
| 731 chromeos::OverscanCalibrator* | |
| 732 DisplayInfoProviderChromeOS::GetOverscanCalibrator(const std::string& id) { | |
| 634 auto iter = overscan_calibrators_.find(id); | 733 auto iter = overscan_calibrators_.find(id); |
| 635 if (iter == overscan_calibrators_.end()) | 734 if (iter == overscan_calibrators_.end()) |
| 636 return nullptr; | 735 return nullptr; |
| 637 return iter->second.get(); | 736 return iter->second.get(); |
| 638 } | 737 } |
| 639 | 738 |
| 739 chromeos::TouchCalibratorController* | |
| 740 DisplayInfoProviderChromeOS::GetTouchCalibrator() { | |
| 741 if (!touch_calibrator_) | |
| 742 touch_calibrator_.reset(new chromeos::TouchCalibratorController); | |
| 743 return touch_calibrator_.get(); | |
| 744 } | |
| 745 | |
| 640 // static | 746 // static |
| 641 DisplayInfoProvider* DisplayInfoProvider::Create() { | 747 DisplayInfoProvider* DisplayInfoProvider::Create() { |
| 642 return new DisplayInfoProviderChromeOS(); | 748 return new DisplayInfoProviderChromeOS(); |
| 643 } | 749 } |
| 644 | 750 |
| 645 } // namespace extensions | 751 } // namespace extensions |
| OLD | NEW |