Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: chrome/browser/extensions/display_info_provider_chromeos.cc

Issue 2656433004: - Plumbs through native touch calibration from MD settings to display manager via the system dis… (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "ash/touch/ash_touch_transform_controller.h"
12 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
13 #include "chrome/browser/chromeos/display/display_preferences.h" 14 #include "chrome/browser/chromeos/display/display_preferences.h"
14 #include "chrome/browser/chromeos/display/overscan_calibrator.h" 15 #include "chrome/browser/chromeos/display/overscan_calibrator.h"
15 #include "chrome/browser/chromeos/display/touch_calibrator/touch_calibrator_cont roller.h" 16 #include "chrome/browser/chromeos/display/touch_calibrator/touch_calibrator_cont roller.h"
16 #include "extensions/common/api/system_display.h" 17 #include "extensions/common/api/system_display.h"
17 #include "ui/display/display.h" 18 #include "ui/display/display.h"
18 #include "ui/display/display_layout.h" 19 #include "ui/display/display_layout.h"
19 #include "ui/display/display_layout_builder.h" 20 #include "ui/display/display_layout_builder.h"
20 #include "ui/display/manager/display_manager.h" 21 #include "ui/display/manager/display_manager.h"
21 #include "ui/display/types/display_constants.h" 22 #include "ui/display/types/display_constants.h"
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 if (display.touch_support() != display::Display::TOUCH_SUPPORT_AVAILABLE) { 402 if (display.touch_support() != display::Display::TOUCH_SUPPORT_AVAILABLE) {
402 *error = "Display Id(" + id + ") does not support touch."; 403 *error = "Display Id(" + id + ") does not support touch.";
403 return false; 404 return false;
404 } 405 }
405 406
406 return true; 407 return true;
407 } 408 }
408 409
409 } // namespace 410 } // namespace
410 411
412 // static
413 const char DisplayInfoProviderChromeOS::
414 kCustomTouchCalibrationInProgressError[] =
415 "Another custom touch calibration already under progress.";
416
417 // static
418 const char DisplayInfoProviderChromeOS::
419 kCompleteCalibrationCalledBeforeStartError[] =
420 "system.display.completeCustomTouchCalibration called before "
421 "system.display.startCustomTouchCalibration before.";
422
423 // static
424 const char DisplayInfoProviderChromeOS::kTouchBoundsNegativeError[] =
425 "Bounds cannot have negative values.";
426
427 // static
428 const char DisplayInfoProviderChromeOS::kTouchCalibrationPointsNegativeError[] =
429 "Display points and touch points cannot have negative coordinates";
430
431 // static
432 const char DisplayInfoProviderChromeOS::kTouchCalibrationPointsTooLargeError[] =
433 "Display point coordinates cannot be more than size of the display.";
434
435 // static
436 const char DisplayInfoProviderChromeOS::kNativeTouchCalibrationActiveError[] =
437 "Another touch calibration is already active.";
438
411 DisplayInfoProviderChromeOS::DisplayInfoProviderChromeOS() {} 439 DisplayInfoProviderChromeOS::DisplayInfoProviderChromeOS() {}
412 440
413 DisplayInfoProviderChromeOS::~DisplayInfoProviderChromeOS() {} 441 DisplayInfoProviderChromeOS::~DisplayInfoProviderChromeOS() {}
414 442
415 bool DisplayInfoProviderChromeOS::SetInfo( 443 bool DisplayInfoProviderChromeOS::SetInfo(
416 const std::string& display_id_str, 444 const std::string& display_id_str,
417 const system_display::DisplayProperties& info, 445 const system_display::DisplayProperties& info,
418 std::string* error) { 446 std::string* error) {
419 display::DisplayManager* display_manager = 447 display::DisplayManager* display_manager =
420 ash::Shell::GetInstance()->display_manager(); 448 ash::Shell::GetInstance()->display_manager();
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 const std::string& id) { 681 const std::string& id) {
654 VLOG(1) << "OverscanCalibrationComplete: " << id; 682 VLOG(1) << "OverscanCalibrationComplete: " << id;
655 chromeos::OverscanCalibrator* calibrator = GetOverscanCalibrator(id); 683 chromeos::OverscanCalibrator* calibrator = GetOverscanCalibrator(id);
656 if (!calibrator) 684 if (!calibrator)
657 return false; 685 return false;
658 calibrator->Commit(); 686 calibrator->Commit();
659 overscan_calibrators_[id].reset(); 687 overscan_calibrators_[id].reset();
660 return true; 688 return true;
661 } 689 }
662 690
663 bool DisplayInfoProviderChromeOS::TouchCalibrationSet( 691 bool DisplayInfoProviderChromeOS::ShowNativeTouchCalibration(
664 const std::string& id, 692 const std::string& id, std::string* error,
665 const api::system_display::TouchCalibrationPairQuad& pairs, 693 const DisplayInfoProvider::TouchCalibrationCallback& callback) {
666 const api::system_display::Bounds& bounds, 694 VLOG(1) << "StartNativeTouchCalibration: " << id;
667 std::string* error) { 695
668 VLOG(1) << "TouchCalibrationSet: " << id; 696 // If a custom calibration is already running, then throw an error.
697 if (custom_touch_calibration_active_) {
698 *error = kCustomTouchCalibrationInProgressError;
699 return false;
700 }
669 701
670 const display::Display display = GetDisplay(id); 702 const display::Display display = GetDisplay(id);
671 if (!ValidateParamsForTouchCalibration(id, display, GetTouchCalibrator(), 703 if (!ValidateParamsForTouchCalibration(id, display, GetTouchCalibrator(),
672 error)) { 704 error)) {
673 return false; 705 return false;
674 } 706 }
675 707
708 GetTouchCalibrator()->StartCalibration(display, callback);
709 return true;
710 }
711
712 bool DisplayInfoProviderChromeOS::StartCustomTouchCalibration(
713 const std::string& id,
714 std::string* error) {
715 VLOG(1) << "StartCustomTouchCalibration: " << id;
716 const display::Display display = GetDisplay(id);
717 if (!ValidateParamsForTouchCalibration(id, display, GetTouchCalibrator(),
718 error)) {
719 return false;
720 }
721
722 touch_calibration_target_id_ = id;
723 custom_touch_calibration_active_ = true;
724
725 // Enable un-transformed touch input.
726 ash::Shell::GetInstance()->touch_transformer_controller()->SetForCalibration(
727 true);
728 return true;
729 }
730
731 bool DisplayInfoProviderChromeOS::CompleteCustomTouchCalibration(
732 const api::system_display::TouchCalibrationPairQuad& pairs,
733 const api::system_display::Bounds& bounds,
734 std::string* error) {
735 VLOG(1) << "CompleteCustomTouchCalibration: " << touch_calibration_target_id_;
736
737 ash::Shell::GetInstance()->touch_transformer_controller()->SetForCalibration(
738 false);
739
740 const display::Display display = GetDisplay(touch_calibration_target_id_);
741 touch_calibration_target_id_.clear();
742
743 // If Complete() is called before calling Start(), throw an error.
744 if (!custom_touch_calibration_active_) {
745 *error = kCompleteCalibrationCalledBeforeStartError;
746 return false;
747 }
748
749 custom_touch_calibration_active_ = false;
750
751 if (!ValidateParamsForTouchCalibration(
752 touch_calibration_target_id_, display, GetTouchCalibrator(), error)) {
753 return false;
754 }
755
676 display::TouchCalibrationData::CalibrationPointPairQuad calibration_points; 756 display::TouchCalibrationData::CalibrationPointPairQuad calibration_points;
677 calibration_points[0] = GetCalibrationPair(pairs.pair1); 757 calibration_points[0] = GetCalibrationPair(pairs.pair1);
678 calibration_points[1] = GetCalibrationPair(pairs.pair2); 758 calibration_points[1] = GetCalibrationPair(pairs.pair2);
679 calibration_points[2] = GetCalibrationPair(pairs.pair3); 759 calibration_points[2] = GetCalibrationPair(pairs.pair3);
680 calibration_points[3] = GetCalibrationPair(pairs.pair4); 760 calibration_points[3] = GetCalibrationPair(pairs.pair4);
681 761
682 // The display bounds cannot have negative values. 762 // The display bounds cannot have negative values.
683 if (bounds.width < 0 || bounds.height < 0) { 763 if (bounds.width < 0 || bounds.height < 0) {
684 *error = "Bounds cannot have negative values."; 764 *error = kTouchBoundsNegativeError;
685 return false; 765 return false;
686 } 766 }
687 767
688 for (size_t row = 0; row < calibration_points.size(); row++) { 768 for (size_t row = 0; row < calibration_points.size(); row++) {
689 // Coordinates for display and touch point cannot be negative. 769 // Coordinates for display and touch point cannot be negative.
690 if (calibration_points[row].first.x() < 0 || 770 if (calibration_points[row].first.x() < 0 ||
691 calibration_points[row].first.y() < 0 || 771 calibration_points[row].first.y() < 0 ||
692 calibration_points[row].second.x() < 0 || 772 calibration_points[row].second.x() < 0 ||
693 calibration_points[row].second.y() < 0) { 773 calibration_points[row].second.y() < 0) {
694 *error = "Display points and touch points cannot have negative " 774 *error = kTouchCalibrationPointsNegativeError;
695 "coordinates";
696 return false; 775 return false;
697 } 776 }
698 // Coordinates for display points cannot be greater than the screen bounds. 777 // Coordinates for display points cannot be greater than the screen bounds.
699 if (calibration_points[row].first.x() > bounds.width || 778 if (calibration_points[row].first.x() > bounds.width ||
700 calibration_points[row].first.y() > bounds.height) { 779 calibration_points[row].first.y() > bounds.height) {
701 *error = "Display point coordinates cannot be more than size of the " 780 *error = kTouchCalibrationPointsTooLargeError;
702 "display.";
703 return false; 781 return false;
704 } 782 }
705 } 783 }
706 784
707 gfx::Size display_size(bounds.width, bounds.height); 785 gfx::Size display_size(bounds.width, bounds.height);
708 ash::Shell::GetInstance()->display_manager()->SetTouchCalibrationData( 786 ash::Shell::GetInstance()->display_manager()->SetTouchCalibrationData(
709 display.id(), calibration_points, display_size); 787 display.id(), calibration_points, display_size);
710 return true; 788 return true;
711 } 789 }
712 790
713 bool DisplayInfoProviderChromeOS::TouchCalibrationReset(const std::string& id, 791 bool DisplayInfoProviderChromeOS::ClearTouchCalibration(const std::string& id,
714 std::string* error) { 792 std::string* error) {
715 const display::Display display = GetDisplay(id); 793 const display::Display display = GetDisplay(id);
716 794
717 if (!ValidateParamsForTouchCalibration(id, display, GetTouchCalibrator(), 795 if (!ValidateParamsForTouchCalibration(id, display, GetTouchCalibrator(),
718 error)) { 796 error)) {
719 return false; 797 return false;
720 } 798 }
721 799
722 ash::Shell::GetInstance()->display_manager()->ClearTouchCalibrationData( 800 ash::Shell::GetInstance()->display_manager()->ClearTouchCalibrationData(
723 display.id()); 801 display.id());
724 return true; 802 return true;
725 } 803 }
726 804
727 bool DisplayInfoProviderChromeOS::IsTouchCalibrationActive(std::string* error) { 805 bool DisplayInfoProviderChromeOS::IsNativeTouchCalibrationActive(
806 std::string* error) {
807 // If native touch calibration UX is active, set error and return false.
728 if (GetTouchCalibrator()->is_calibrating()) { 808 if (GetTouchCalibrator()->is_calibrating()) {
729 *error = "Another touch calibration is already active."; 809 *error = kNativeTouchCalibrationActiveError;
730 return true; 810 return true;
731 } 811 }
732 return false; 812 return false;
733 } 813 }
734 814
735 chromeos::OverscanCalibrator* 815 chromeos::OverscanCalibrator*
736 DisplayInfoProviderChromeOS::GetOverscanCalibrator(const std::string& id) { 816 DisplayInfoProviderChromeOS::GetOverscanCalibrator(const std::string& id) {
737 auto iter = overscan_calibrators_.find(id); 817 auto iter = overscan_calibrators_.find(id);
738 if (iter == overscan_calibrators_.end()) 818 if (iter == overscan_calibrators_.end())
739 return nullptr; 819 return nullptr;
740 return iter->second.get(); 820 return iter->second.get();
741 } 821 }
742 822
743 chromeos::TouchCalibratorController* 823 chromeos::TouchCalibratorController*
744 DisplayInfoProviderChromeOS::GetTouchCalibrator() { 824 DisplayInfoProviderChromeOS::GetTouchCalibrator() {
745 if (!touch_calibrator_) 825 if (!touch_calibrator_)
746 touch_calibrator_.reset(new chromeos::TouchCalibratorController); 826 touch_calibrator_.reset(new chromeos::TouchCalibratorController);
747 return touch_calibrator_.get(); 827 return touch_calibrator_.get();
748 } 828 }
749 829
750 // static 830 // static
751 DisplayInfoProvider* DisplayInfoProvider::Create() { 831 DisplayInfoProvider* DisplayInfoProvider::Create() {
752 return new DisplayInfoProviderChromeOS(); 832 return new DisplayInfoProviderChromeOS();
753 } 833 }
754 834
755 } // namespace extensions 835 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698