diff options
author | miletus@chromium.org <miletus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-24 03:00:21 +0000 |
---|---|---|
committer | miletus@chromium.org <miletus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-24 03:00:21 +0000 |
commit | 7355993465b3cc0f0395ce5144c1a824af1346a0 (patch) | |
tree | cdde21b0687136cfccc690b10037db1b9fb2b99d /ash/touch | |
parent | 102b81cdfa43709db2b05af452415ccea48fb92f (diff) | |
download | chromium_src-7355993465b3cc0f0395ce5144c1a824af1346a0.zip chromium_src-7355993465b3cc0f0395ce5144c1a824af1346a0.tar.gz chromium_src-7355993465b3cc0f0395ce5144c1a824af1346a0.tar.bz2 |
Scale touch event radius
Touch event's position resolution could be quite different than the
display's resolution, e.g. the display could be set as 1920x1080
while the touchscreen is reporting touch position range at 32767x32767.
Touch event's radius is reported in the units the same as touch position.
While we are doing touch position scaling, we should also do the same
for touch radius.
BUG=392172, 233245
TEST=touch radius is scaled to be reasonable value for HP 23TM
touch monitor.
Review URL: https://codereview.chromium.org/412553005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@285132 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/touch')
-rw-r--r-- | ash/touch/touch_transformer_controller.cc | 54 | ||||
-rw-r--r-- | ash/touch/touch_transformer_controller.h | 4 | ||||
-rw-r--r-- | ash/touch/touch_transformer_controller_unittest.cc | 14 |
3 files changed, 72 insertions, 0 deletions
diff --git a/ash/touch/touch_transformer_controller.cc b/ash/touch/touch_transformer_controller.cc index 67cbab2..b99cb5a 100644 --- a/ash/touch/touch_transformer_controller.cc +++ b/ash/touch/touch_transformer_controller.cc @@ -13,6 +13,7 @@ #include "ui/display/chromeos/display_configurator.h" #include "ui/display/types/chromeos/display_snapshot.h" #include "ui/events/device_data_manager.h" +#include "ui/events/x/device_data_manager_x11.h" namespace ash { @@ -24,6 +25,52 @@ DisplayManager* GetDisplayManager() { } // namespace + +// This is to compute the scale ratio for the TouchEvent's radius. The +// configured resolution of the display is not always the same as the touch +// screen's reporting resolution, e.g. the display could be set as +// 1920x1080 while the touchscreen is reporting touch position range at +// 32767x32767. Touch radius is reported in the units the same as touch position +// so we need to scale the touch radius to be compatible with the display's +// resolution. We compute the scale as +// sqrt of (display_area / touchscreen_area) +double TouchTransformerController::GetTouchResolutionScale( + const DisplayInfo& touch_display) const { + if (touch_display.touch_device_id() == 0) + return 1.0; + + double min_x, max_x; + double min_y, max_y; + if (!ui::DeviceDataManagerX11::GetInstance()->GetDataRange( + touch_display.touch_device_id(), + ui::DeviceDataManagerX11::DT_TOUCH_POSITION_X, + &min_x, &max_x) || + !ui::DeviceDataManagerX11::GetInstance()->GetDataRange( + touch_display.touch_device_id(), + ui::DeviceDataManagerX11::DT_TOUCH_POSITION_Y, + &min_y, &max_y)) { + return 1.0; + } + + double width = touch_display.bounds_in_native().width(); + double height = touch_display.bounds_in_native().height(); + + if (max_x == 0.0 || max_y == 0.0 || width == 0.0 || height == 0.0) + return 1.0; + + // [0, max_x] -> touchscreen width = max_x + 1 + // [0, max_y] -> touchscreen height = max_y + 1 + max_x += 1.0; + max_y += 1.0; + + double ratio = std::sqrt((width * height) / (max_x * max_y)); + + VLOG(2) << "Screen width/height: " << width << "/" << height + << ", Touchscreen width/height: " << max_x << "/" << max_y + << ", Touch radius scale ratio: " << ratio; + return ratio; +} + // This function computes the extended mode TouchTransformer for // |touch_display|. The TouchTransformer maps the touch event position // from framebuffer size to the display size. @@ -158,10 +205,17 @@ void TouchTransformerController::UpdateTouchTransformer() const { display2_id != gfx::Display::kInvalidDisplayID); display1 = GetDisplayManager()->GetDisplayInfo(display1_id); display2 = GetDisplayManager()->GetDisplayInfo(display2_id); + device_manager->UpdateTouchRadiusScale(display1.touch_device_id(), + GetTouchResolutionScale(display1)); + device_manager->UpdateTouchRadiusScale(display2.touch_device_id(), + GetTouchResolutionScale(display2)); } else { single_display_id = GetDisplayManager()->first_display_id(); DCHECK(single_display_id != gfx::Display::kInvalidDisplayID); single_display = GetDisplayManager()->GetDisplayInfo(single_display_id); + device_manager->UpdateTouchRadiusScale( + single_display.touch_device_id(), + GetTouchResolutionScale(single_display)); } if (display_state == ui::MULTIPLE_DISPLAY_STATE_DUAL_MIRROR) { diff --git a/ash/touch/touch_transformer_controller.h b/ash/touch/touch_transformer_controller.h index f06be29..8512186 100644 --- a/ash/touch/touch_transformer_controller.h +++ b/ash/touch/touch_transformer_controller.h @@ -34,6 +34,8 @@ class ASH_EXPORT TouchTransformerController TouchTransformerMirrorModePillarboxing); FRIEND_TEST_ALL_PREFIXES(TouchTransformerControllerTest, TouchTransformerExtendedMode); + FRIEND_TEST_ALL_PREFIXES(TouchTransformerControllerTest, + TouchRadiusScale); bool ShouldComputeMirrorModeTouchTransformer( const DisplayInfo& touch_display) const ; @@ -44,6 +46,8 @@ class ASH_EXPORT TouchTransformerController gfx::Transform GetExtendedModeTouchTransformer( const DisplayInfo& touch_display, const gfx::Size& fb_size) const; + double GetTouchResolutionScale(const DisplayInfo& touch_display) const; + // For unittests only. bool force_compute_mirror_mode_touch_transformer_; diff --git a/ash/touch/touch_transformer_controller_unittest.cc b/ash/touch/touch_transformer_controller_unittest.cc index ca64baa..cff2c53 100644 --- a/ash/touch/touch_transformer_controller_unittest.cc +++ b/ash/touch/touch_transformer_controller_unittest.cc @@ -8,6 +8,7 @@ #include "ash/test/ash_test_base.h" #include "ui/aura/window_tree_host.h" #include "ui/events/device_data_manager.h" +#include "ui/events/test/events_test_utils_x11.h" #include "ui/gfx/display.h" namespace ash { @@ -203,4 +204,17 @@ TEST_F(TouchTransformerControllerTest, TouchTransformerExtendedMode) { EXPECT_EQ(1599, static_cast<int>(y)); } +TEST_F(TouchTransformerControllerTest, TouchRadiusScale) { + DisplayInfo display = CreateDisplayInfo(1, 5, gfx::Rect(0, 0, 2560, 1600)); + std::vector<unsigned int> devices; + devices.push_back(5); + ui::SetUpTouchDevicesForTest(devices); + + TouchTransformerController* tt_controller = + Shell::GetInstance()->touch_transformer_controller(); + // Default touchscreen position range is 1001x1001; + EXPECT_EQ(sqrt((2560.0 * 1600.0) / (1001.0 * 1001.0)), + tt_controller->GetTouchResolutionScale(display)); +} + } // namespace ash |