| 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 "ash/touch/touch_transformer_controller.h" | 5 #include "ash/touch/touch_transformer_controller.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
| 9 #include "ui/aura/window_tree_host.h" | 9 #include "ui/aura/window_tree_host.h" |
| 10 #include "ui/events/device_data_manager.h" | 10 #include "ui/events/device_data_manager.h" |
| 11 #include "ui/events/test/events_test_utils_x11.h" | 11 #include "ui/events/test/events_test_utils_x11.h" |
| 12 #include "ui/gfx/display.h" | 12 #include "ui/gfx/display.h" |
| 13 | 13 |
| 14 namespace ash { | 14 namespace ash { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 |
| 17 DisplayInfo CreateDisplayInfo(int64 id, | 18 DisplayInfo CreateDisplayInfo(int64 id, |
| 18 unsigned int touch_device_id, | 19 unsigned int touch_device_id, |
| 19 const gfx::Rect& bounds) { | 20 const gfx::Rect& bounds) { |
| 20 DisplayInfo info(id, std::string(), false); | 21 DisplayInfo info(id, std::string(), false); |
| 21 info.SetBounds(bounds); | 22 info.SetBounds(bounds); |
| 22 info.set_touch_device_id(touch_device_id); | 23 info.set_touch_device_id(touch_device_id); |
| 24 |
| 25 // Create a default mode. |
| 26 std::vector<DisplayMode> default_modes( |
| 27 1, DisplayMode(bounds.size(), 60, false, true)); |
| 28 info.set_display_modes(default_modes); |
| 29 |
| 23 return info; | 30 return info; |
| 24 } | 31 } |
| 32 |
| 33 ui::TouchscreenDevice CreateTouchscreenDevice(unsigned int id, |
| 34 const gfx::Size& size) { |
| 35 return ui::TouchscreenDevice(id, |
| 36 ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, |
| 37 std::string(), |
| 38 size); |
| 39 } |
| 40 |
| 25 } // namespace | 41 } // namespace |
| 26 | 42 |
| 27 typedef test::AshTestBase TouchTransformerControllerTest; | 43 typedef test::AshTestBase TouchTransformerControllerTest; |
| 28 | 44 |
| 29 TEST_F(TouchTransformerControllerTest, TouchTransformerMirrorModeLetterboxing) { | 45 TEST_F(TouchTransformerControllerTest, TouchTransformerMirrorModeLetterboxing) { |
| 30 // The internal display has native resolution of 2560x1700, and in | 46 // The internal display has native resolution of 2560x1700, and in |
| 31 // mirror mode it is configured as 1920x1200. This is in letterboxing | 47 // mirror mode it is configured as 1920x1200. This is in letterboxing |
| 32 // mode. | 48 // mode. |
| 33 DisplayInfo internal_display_info = | 49 DisplayInfo internal_display_info = |
| 34 CreateDisplayInfo(1, 10u, gfx::Rect(0, 0, 1920, 1200)); | 50 CreateDisplayInfo(1, 10u, gfx::Rect(0, 0, 1920, 1200)); |
| 51 internal_display_info.set_is_aspect_preserving_scaling(true); |
| 35 std::vector<DisplayMode> internal_modes; | 52 std::vector<DisplayMode> internal_modes; |
| 36 internal_modes.push_back( | 53 internal_modes.push_back( |
| 37 DisplayMode(gfx::Size(2560, 1700), 60, false, true)); | 54 DisplayMode(gfx::Size(2560, 1700), 60, false, true)); |
| 38 internal_modes.push_back( | 55 internal_modes.push_back( |
| 39 DisplayMode(gfx::Size(1920, 1200), 60, false, false)); | 56 DisplayMode(gfx::Size(1920, 1200), 60, false, false)); |
| 40 internal_display_info.set_display_modes(internal_modes); | 57 internal_display_info.set_display_modes(internal_modes); |
| 41 | 58 |
| 42 DisplayInfo external_display_info = | 59 DisplayInfo external_display_info = |
| 43 CreateDisplayInfo(2, 11u, gfx::Rect(0, 0, 1920, 1200)); | 60 CreateDisplayInfo(2, 11u, gfx::Rect(0, 0, 1920, 1200)); |
| 44 | 61 |
| 62 gfx::Size fb_size(1920, 1200); |
| 63 |
| 64 // Create the touchscreens with the same size as the framebuffer so we can |
| 65 // share the tests between Ozone & X11. |
| 66 ui::TouchscreenDevice internal_touchscreen = |
| 67 CreateTouchscreenDevice(10, fb_size); |
| 68 ui::TouchscreenDevice external_touchscreen = |
| 69 CreateTouchscreenDevice(11, fb_size); |
| 70 |
| 45 TouchTransformerController* tt_controller = | 71 TouchTransformerController* tt_controller = |
| 46 Shell::GetInstance()->touch_transformer_controller(); | 72 Shell::GetInstance()->touch_transformer_controller(); |
| 47 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); | 73 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
| 48 | 74 |
| 49 tt_controller->force_compute_mirror_mode_touch_transformer_ = true; | |
| 50 device_manager->UpdateTouchInfoForDisplay( | 75 device_manager->UpdateTouchInfoForDisplay( |
| 51 internal_display_info.id(), | 76 internal_display_info.id(), |
| 52 internal_display_info.touch_device_id(), | 77 internal_display_info.touch_device_id(), |
| 53 tt_controller->GetMirrorModeTouchTransformer(internal_display_info)); | 78 tt_controller->GetTouchTransform(internal_display_info, |
| 79 internal_touchscreen, |
| 80 fb_size)); |
| 54 | 81 |
| 55 tt_controller->force_compute_mirror_mode_touch_transformer_ = false; | |
| 56 device_manager->UpdateTouchInfoForDisplay( | 82 device_manager->UpdateTouchInfoForDisplay( |
| 57 external_display_info.id(), | 83 external_display_info.id(), |
| 58 external_display_info.touch_device_id(), | 84 external_display_info.touch_device_id(), |
| 59 tt_controller->GetMirrorModeTouchTransformer(external_display_info)); | 85 tt_controller->GetTouchTransform(external_display_info, |
| 86 external_touchscreen, |
| 87 fb_size)); |
| 60 | 88 |
| 61 EXPECT_EQ(1, device_manager->GetDisplayForTouchDevice(10)); | 89 EXPECT_EQ(1, device_manager->GetDisplayForTouchDevice(10)); |
| 62 EXPECT_EQ(2, device_manager->GetDisplayForTouchDevice(11)); | 90 EXPECT_EQ(2, device_manager->GetDisplayForTouchDevice(11)); |
| 63 | 91 |
| 64 // External touch display has the default TouchTransformer. | 92 // External touch display has the default TouchTransformer. |
| 65 float x = 100.0; | 93 float x = 100.0; |
| 66 float y = 100.0; | 94 float y = 100.0; |
| 67 device_manager->ApplyTouchTransformer(11, &x, &y); | 95 device_manager->ApplyTouchTransformer(11, &x, &y); |
| 68 EXPECT_EQ(100, x); | 96 EXPECT_EQ(100, x); |
| 69 EXPECT_EQ(100, y); | 97 EXPECT_EQ(100, y); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 86 EXPECT_EQ(100, static_cast<int>(x)); | 114 EXPECT_EQ(100, static_cast<int>(x)); |
| 87 EXPECT_EQ(1200, static_cast<int>(y)); | 115 EXPECT_EQ(1200, static_cast<int>(y)); |
| 88 } | 116 } |
| 89 | 117 |
| 90 TEST_F(TouchTransformerControllerTest, TouchTransformerMirrorModePillarboxing) { | 118 TEST_F(TouchTransformerControllerTest, TouchTransformerMirrorModePillarboxing) { |
| 91 // The internal display has native resolution of 1366x768, and in | 119 // The internal display has native resolution of 1366x768, and in |
| 92 // mirror mode it is configured as 1024x768. This is in pillarboxing | 120 // mirror mode it is configured as 1024x768. This is in pillarboxing |
| 93 // mode. | 121 // mode. |
| 94 DisplayInfo internal_display_info = | 122 DisplayInfo internal_display_info = |
| 95 CreateDisplayInfo(1, 10, gfx::Rect(0, 0, 1024, 768)); | 123 CreateDisplayInfo(1, 10, gfx::Rect(0, 0, 1024, 768)); |
| 124 internal_display_info.set_is_aspect_preserving_scaling(true); |
| 96 std::vector<DisplayMode> internal_modes; | 125 std::vector<DisplayMode> internal_modes; |
| 97 internal_modes.push_back( | 126 internal_modes.push_back( |
| 98 DisplayMode(gfx::Size(1366, 768), 60, false, true)); | 127 DisplayMode(gfx::Size(1366, 768), 60, false, true)); |
| 99 internal_modes.push_back( | 128 internal_modes.push_back( |
| 100 DisplayMode(gfx::Size(1024, 768), 60, false, false)); | 129 DisplayMode(gfx::Size(1024, 768), 60, false, false)); |
| 101 internal_display_info.set_display_modes(internal_modes); | 130 internal_display_info.set_display_modes(internal_modes); |
| 102 | 131 |
| 103 DisplayInfo external_display_info = | 132 DisplayInfo external_display_info = |
| 104 CreateDisplayInfo(2, 11, gfx::Rect(0, 0, 1024, 768)); | 133 CreateDisplayInfo(2, 11, gfx::Rect(0, 0, 1024, 768)); |
| 105 | 134 |
| 135 gfx::Size fb_size(1024, 768); |
| 136 |
| 137 // Create the touchscreens with the same size as the framebuffer so we can |
| 138 // share the tests between Ozone & X11. |
| 139 ui::TouchscreenDevice internal_touchscreen = |
| 140 CreateTouchscreenDevice(10, fb_size); |
| 141 ui::TouchscreenDevice external_touchscreen = |
| 142 CreateTouchscreenDevice(11, fb_size); |
| 143 |
| 106 TouchTransformerController* tt_controller = | 144 TouchTransformerController* tt_controller = |
| 107 Shell::GetInstance()->touch_transformer_controller(); | 145 Shell::GetInstance()->touch_transformer_controller(); |
| 108 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); | 146 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
| 109 | 147 |
| 110 tt_controller->force_compute_mirror_mode_touch_transformer_ = true; | |
| 111 device_manager->UpdateTouchInfoForDisplay( | 148 device_manager->UpdateTouchInfoForDisplay( |
| 112 internal_display_info.id(), | 149 internal_display_info.id(), |
| 113 internal_display_info.touch_device_id(), | 150 internal_display_info.touch_device_id(), |
| 114 tt_controller->GetMirrorModeTouchTransformer(internal_display_info)); | 151 tt_controller->GetTouchTransform(internal_display_info, |
| 152 internal_touchscreen, |
| 153 fb_size)); |
| 115 | 154 |
| 116 tt_controller->force_compute_mirror_mode_touch_transformer_ = false; | |
| 117 device_manager->UpdateTouchInfoForDisplay( | 155 device_manager->UpdateTouchInfoForDisplay( |
| 118 external_display_info.id(), | 156 external_display_info.id(), |
| 119 external_display_info.touch_device_id(), | 157 external_display_info.touch_device_id(), |
| 120 tt_controller->GetMirrorModeTouchTransformer(external_display_info)); | 158 tt_controller->GetTouchTransform(external_display_info, |
| 159 external_touchscreen, |
| 160 fb_size)); |
| 121 | 161 |
| 122 EXPECT_EQ(1, device_manager->GetDisplayForTouchDevice(10)); | 162 EXPECT_EQ(1, device_manager->GetDisplayForTouchDevice(10)); |
| 123 EXPECT_EQ(2, device_manager->GetDisplayForTouchDevice(11)); | 163 EXPECT_EQ(2, device_manager->GetDisplayForTouchDevice(11)); |
| 124 | 164 |
| 125 // External touch display has the default TouchTransformer. | 165 // External touch display has the default TouchTransformer. |
| 126 float x = 100.0; | 166 float x = 100.0; |
| 127 float y = 100.0; | 167 float y = 100.0; |
| 128 device_manager->ApplyTouchTransformer(11, &x, &y); | 168 device_manager->ApplyTouchTransformer(11, &x, &y); |
| 129 EXPECT_EQ(100, x); | 169 EXPECT_EQ(100, x); |
| 130 EXPECT_EQ(100, y); | 170 EXPECT_EQ(100, y); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 152 // The internal display has size 1366 x 768. The external display has | 192 // The internal display has size 1366 x 768. The external display has |
| 153 // size 2560x1600. The total frame buffer is 2560x2428, | 193 // size 2560x1600. The total frame buffer is 2560x2428, |
| 154 // where 2428 = 768 + 60 (hidden gap) + 1600 | 194 // where 2428 = 768 + 60 (hidden gap) + 1600 |
| 155 // and the sceond monitor is translated to Point (0, 828) in the | 195 // and the sceond monitor is translated to Point (0, 828) in the |
| 156 // framebuffer. | 196 // framebuffer. |
| 157 DisplayInfo display1 = CreateDisplayInfo(1, 5u, gfx::Rect(0, 0, 1366, 768)); | 197 DisplayInfo display1 = CreateDisplayInfo(1, 5u, gfx::Rect(0, 0, 1366, 768)); |
| 158 DisplayInfo display2 = | 198 DisplayInfo display2 = |
| 159 CreateDisplayInfo(2, 6u, gfx::Rect(0, 828, 2560, 1600)); | 199 CreateDisplayInfo(2, 6u, gfx::Rect(0, 828, 2560, 1600)); |
| 160 gfx::Size fb_size(2560, 2428); | 200 gfx::Size fb_size(2560, 2428); |
| 161 | 201 |
| 202 // Create the touchscreens with the same size as the framebuffer so we can |
| 203 // share the tests between Ozone & X11. |
| 204 ui::TouchscreenDevice touchscreen1 = CreateTouchscreenDevice(5, fb_size); |
| 205 ui::TouchscreenDevice touchscreen2 = CreateTouchscreenDevice(6, fb_size); |
| 206 |
| 162 TouchTransformerController* tt_controller = | 207 TouchTransformerController* tt_controller = |
| 163 Shell::GetInstance()->touch_transformer_controller(); | 208 Shell::GetInstance()->touch_transformer_controller(); |
| 164 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); | 209 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
| 165 | 210 |
| 166 device_manager->UpdateTouchInfoForDisplay( | 211 device_manager->UpdateTouchInfoForDisplay( |
| 167 display1.id(), | 212 display1.id(), |
| 168 display1.touch_device_id(), | 213 display1.touch_device_id(), |
| 169 tt_controller->GetExtendedModeTouchTransformer(display1, fb_size)); | 214 tt_controller->GetTouchTransform(display1, |
| 215 touchscreen1, |
| 216 fb_size)); |
| 170 | 217 |
| 171 device_manager->UpdateTouchInfoForDisplay( | 218 device_manager->UpdateTouchInfoForDisplay( |
| 172 display2.id(), | 219 display2.id(), |
| 173 display2.touch_device_id(), | 220 display2.touch_device_id(), |
| 174 tt_controller->GetExtendedModeTouchTransformer(display2, fb_size)); | 221 tt_controller->GetTouchTransform(display2, |
| 222 touchscreen2, |
| 223 fb_size)); |
| 175 | 224 |
| 176 EXPECT_EQ(1, device_manager->GetDisplayForTouchDevice(5)); | 225 EXPECT_EQ(1, device_manager->GetDisplayForTouchDevice(5)); |
| 177 EXPECT_EQ(2, device_manager->GetDisplayForTouchDevice(6)); | 226 EXPECT_EQ(2, device_manager->GetDisplayForTouchDevice(6)); |
| 178 | 227 |
| 179 // Mapping for touch events from internal touch display: | 228 // Mapping for touch events from internal touch display: |
| 180 // [0, 2560) x [0, 2428) -> [0, 1366) x [0, 768) | 229 // [0, 2560) x [0, 2428) -> [0, 1366) x [0, 768) |
| 181 float x = 0.0; | 230 float x = 0.0; |
| 182 float y = 0.0; | 231 float y = 0.0; |
| 183 device_manager->ApplyTouchTransformer(5, &x, &y); | 232 device_manager->ApplyTouchTransformer(5, &x, &y); |
| 184 EXPECT_EQ(0, static_cast<int>(x)); | 233 EXPECT_EQ(0, static_cast<int>(x)); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 200 | 249 |
| 201 x = 2559.0; | 250 x = 2559.0; |
| 202 y = 2427.0; | 251 y = 2427.0; |
| 203 device_manager->ApplyTouchTransformer(6, &x, &y); | 252 device_manager->ApplyTouchTransformer(6, &x, &y); |
| 204 EXPECT_EQ(2559, static_cast<int>(x)); | 253 EXPECT_EQ(2559, static_cast<int>(x)); |
| 205 EXPECT_EQ(1599, static_cast<int>(y)); | 254 EXPECT_EQ(1599, static_cast<int>(y)); |
| 206 } | 255 } |
| 207 | 256 |
| 208 TEST_F(TouchTransformerControllerTest, TouchRadiusScale) { | 257 TEST_F(TouchTransformerControllerTest, TouchRadiusScale) { |
| 209 DisplayInfo display = CreateDisplayInfo(1, 5u, gfx::Rect(0, 0, 2560, 1600)); | 258 DisplayInfo display = CreateDisplayInfo(1, 5u, gfx::Rect(0, 0, 2560, 1600)); |
| 210 ui::TouchscreenDevice touch_device(5, | 259 ui::TouchscreenDevice touch_device = |
| 211 ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, | 260 CreateTouchscreenDevice(5, gfx::Size(1001, 1001)); |
| 212 std::string(), | |
| 213 gfx::Size(1001, 1001)); | |
| 214 | 261 |
| 215 TouchTransformerController* tt_controller = | 262 TouchTransformerController* tt_controller = |
| 216 Shell::GetInstance()->touch_transformer_controller(); | 263 Shell::GetInstance()->touch_transformer_controller(); |
| 217 // Default touchscreen position range is 1001x1001; | 264 // Default touchscreen position range is 1001x1001; |
| 218 EXPECT_EQ(sqrt((2560.0 * 1600.0) / (1001.0 * 1001.0)), | 265 EXPECT_EQ(sqrt((2560.0 * 1600.0) / (1001.0 * 1001.0)), |
| 219 tt_controller->GetTouchResolutionScale(display, touch_device)); | 266 tt_controller->GetTouchResolutionScale(display, touch_device)); |
| 220 } | 267 } |
| 221 | 268 |
| 222 } // namespace ash | 269 } // namespace ash |
| OLD | NEW |