| 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/devices/device_data_manager.h" | 10 #include "ui/events/devices/device_data_manager.h" |
| 11 | 11 |
| 12 namespace ash { | 12 namespace ash { |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 DisplayInfo CreateDisplayInfo(int64_t id, | 16 ui::ManagedDisplayInfo CreateDisplayInfo(int64_t id, |
| 17 unsigned int touch_device_id, | 17 unsigned int touch_device_id, |
| 18 const gfx::Rect& bounds) { | 18 const gfx::Rect& bounds) { |
| 19 DisplayInfo info(id, std::string(), false); | 19 ui::ManagedDisplayInfo info(id, std::string(), false); |
| 20 info.SetBounds(bounds); | 20 info.SetBounds(bounds); |
| 21 info.AddInputDevice(touch_device_id); | 21 info.AddInputDevice(touch_device_id); |
| 22 | 22 |
| 23 // Create a default mode. | 23 // Create a default mode. |
| 24 DisplayInfo::ManagedDisplayModeList default_modes( | 24 ui::ManagedDisplayInfo::ManagedDisplayModeList default_modes( |
| 25 1, make_scoped_refptr( | 25 1, make_scoped_refptr( |
| 26 new ManagedDisplayMode(bounds.size(), 60, false, true))); | 26 new ui::ManagedDisplayMode(bounds.size(), 60, false, true))); |
| 27 info.SetManagedDisplayModes(default_modes); | 27 info.SetManagedDisplayModes(default_modes); |
| 28 | 28 |
| 29 return info; | 29 return info; |
| 30 } | 30 } |
| 31 | 31 |
| 32 ui::TouchscreenDevice CreateTouchscreenDevice(unsigned int id, | 32 ui::TouchscreenDevice CreateTouchscreenDevice(unsigned int id, |
| 33 const gfx::Size& size) { | 33 const gfx::Size& size) { |
| 34 return ui::TouchscreenDevice(id, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, | 34 return ui::TouchscreenDevice(id, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, |
| 35 std::string(), size, 0); | 35 std::string(), size, 0); |
| 36 } | 36 } |
| 37 | 37 |
| 38 } // namespace | 38 } // namespace |
| 39 | 39 |
| 40 typedef test::AshTestBase TouchTransformerControllerTest; | 40 typedef test::AshTestBase TouchTransformerControllerTest; |
| 41 | 41 |
| 42 TEST_F(TouchTransformerControllerTest, MirrorModeLetterboxing) { | 42 TEST_F(TouchTransformerControllerTest, MirrorModeLetterboxing) { |
| 43 // The internal display has native resolution of 2560x1700, and in | 43 // The internal display has native resolution of 2560x1700, and in |
| 44 // mirror mode it is configured as 1920x1200. This is in letterboxing | 44 // mirror mode it is configured as 1920x1200. This is in letterboxing |
| 45 // mode. | 45 // mode. |
| 46 DisplayInfo internal_display_info = | 46 ui::ManagedDisplayInfo internal_display_info = |
| 47 CreateDisplayInfo(1, 10u, gfx::Rect(0, 0, 1920, 1200)); | 47 CreateDisplayInfo(1, 10u, gfx::Rect(0, 0, 1920, 1200)); |
| 48 internal_display_info.set_is_aspect_preserving_scaling(true); | 48 internal_display_info.set_is_aspect_preserving_scaling(true); |
| 49 | 49 |
| 50 DisplayInfo::ManagedDisplayModeList internal_modes; | 50 ui::ManagedDisplayInfo::ManagedDisplayModeList internal_modes; |
| 51 | 51 |
| 52 internal_modes.push_back(make_scoped_refptr( | 52 internal_modes.push_back(make_scoped_refptr( |
| 53 new ManagedDisplayMode(gfx::Size(2560, 1700), 60, false, true))); | 53 new ui::ManagedDisplayMode(gfx::Size(2560, 1700), 60, false, true))); |
| 54 internal_modes.push_back(make_scoped_refptr( | 54 internal_modes.push_back(make_scoped_refptr( |
| 55 new ManagedDisplayMode(gfx::Size(1920, 1200), 60, false, false))); | 55 new ui::ManagedDisplayMode(gfx::Size(1920, 1200), 60, false, false))); |
| 56 internal_display_info.SetManagedDisplayModes(internal_modes); | 56 internal_display_info.SetManagedDisplayModes(internal_modes); |
| 57 | 57 |
| 58 DisplayInfo external_display_info = | 58 ui::ManagedDisplayInfo external_display_info = |
| 59 CreateDisplayInfo(2, 11u, gfx::Rect(0, 0, 1920, 1200)); | 59 CreateDisplayInfo(2, 11u, gfx::Rect(0, 0, 1920, 1200)); |
| 60 | 60 |
| 61 gfx::Size fb_size(1920, 1200); | 61 gfx::Size fb_size(1920, 1200); |
| 62 | 62 |
| 63 // Create the touchscreens with the same size as the framebuffer so we can | 63 // Create the touchscreens with the same size as the framebuffer so we can |
| 64 // share the tests between Ozone & X11. | 64 // share the tests between Ozone & X11. |
| 65 ui::TouchscreenDevice internal_touchscreen = | 65 ui::TouchscreenDevice internal_touchscreen = |
| 66 CreateTouchscreenDevice(10, fb_size); | 66 CreateTouchscreenDevice(10, fb_size); |
| 67 ui::TouchscreenDevice external_touchscreen = | 67 ui::TouchscreenDevice external_touchscreen = |
| 68 CreateTouchscreenDevice(11, fb_size); | 68 CreateTouchscreenDevice(11, fb_size); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 y = 1165.0; | 109 y = 1165.0; |
| 110 device_manager->ApplyTouchTransformer(10, &x, &y); | 110 device_manager->ApplyTouchTransformer(10, &x, &y); |
| 111 EXPECT_NEAR(100, x, 0.5); | 111 EXPECT_NEAR(100, x, 0.5); |
| 112 EXPECT_NEAR(1200, y, 0.5); | 112 EXPECT_NEAR(1200, y, 0.5); |
| 113 } | 113 } |
| 114 | 114 |
| 115 TEST_F(TouchTransformerControllerTest, MirrorModePillarboxing) { | 115 TEST_F(TouchTransformerControllerTest, MirrorModePillarboxing) { |
| 116 // The internal display has native resolution of 1366x768, and in | 116 // The internal display has native resolution of 1366x768, and in |
| 117 // mirror mode it is configured as 1024x768. This is in pillarboxing | 117 // mirror mode it is configured as 1024x768. This is in pillarboxing |
| 118 // mode. | 118 // mode. |
| 119 DisplayInfo internal_display_info = | 119 ui::ManagedDisplayInfo internal_display_info = |
| 120 CreateDisplayInfo(1, 10, gfx::Rect(0, 0, 1024, 768)); | 120 CreateDisplayInfo(1, 10, gfx::Rect(0, 0, 1024, 768)); |
| 121 internal_display_info.set_is_aspect_preserving_scaling(true); | 121 internal_display_info.set_is_aspect_preserving_scaling(true); |
| 122 DisplayInfo::ManagedDisplayModeList internal_modes; | 122 ui::ManagedDisplayInfo::ManagedDisplayModeList internal_modes; |
| 123 internal_modes.push_back(make_scoped_refptr( | 123 internal_modes.push_back(make_scoped_refptr( |
| 124 new ManagedDisplayMode(gfx::Size(1366, 768), 60, false, true))); | 124 new ui::ManagedDisplayMode(gfx::Size(1366, 768), 60, false, true))); |
| 125 internal_modes.push_back(make_scoped_refptr( | 125 internal_modes.push_back(make_scoped_refptr( |
| 126 new ManagedDisplayMode(gfx::Size(1024, 768), 60, false, false))); | 126 new ui::ManagedDisplayMode(gfx::Size(1024, 768), 60, false, false))); |
| 127 internal_display_info.SetManagedDisplayModes(internal_modes); | 127 internal_display_info.SetManagedDisplayModes(internal_modes); |
| 128 | 128 |
| 129 DisplayInfo external_display_info = | 129 ui::ManagedDisplayInfo external_display_info = |
| 130 CreateDisplayInfo(2, 11, gfx::Rect(0, 0, 1024, 768)); | 130 CreateDisplayInfo(2, 11, gfx::Rect(0, 0, 1024, 768)); |
| 131 | 131 |
| 132 gfx::Size fb_size(1024, 768); | 132 gfx::Size fb_size(1024, 768); |
| 133 | 133 |
| 134 // Create the touchscreens with the same size as the framebuffer so we can | 134 // Create the touchscreens with the same size as the framebuffer so we can |
| 135 // share the tests between Ozone & X11. | 135 // share the tests between Ozone & X11. |
| 136 ui::TouchscreenDevice internal_touchscreen = | 136 ui::TouchscreenDevice internal_touchscreen = |
| 137 CreateTouchscreenDevice(10, fb_size); | 137 CreateTouchscreenDevice(10, fb_size); |
| 138 ui::TouchscreenDevice external_touchscreen = | 138 ui::TouchscreenDevice external_touchscreen = |
| 139 CreateTouchscreenDevice(11, fb_size); | 139 CreateTouchscreenDevice(11, fb_size); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 } | 184 } |
| 185 | 185 |
| 186 TEST_F(TouchTransformerControllerTest, SoftwareMirrorMode) { | 186 TEST_F(TouchTransformerControllerTest, SoftwareMirrorMode) { |
| 187 // External display 1 has size 1280x850. External display 2 has size | 187 // External display 1 has size 1280x850. External display 2 has size |
| 188 // 1920x1080. When using software mirroring to mirror display 1 onto | 188 // 1920x1080. When using software mirroring to mirror display 1 onto |
| 189 // display 2, the displays are in extended mode and we map touches from both | 189 // display 2, the displays are in extended mode and we map touches from both |
| 190 // displays to display 1. | 190 // displays to display 1. |
| 191 // The total frame buffer is 1920x1990, | 191 // The total frame buffer is 1920x1990, |
| 192 // where 1990 = 850 + 60 (hidden gap) + 1080 and the second monitor is | 192 // where 1990 = 850 + 60 (hidden gap) + 1080 and the second monitor is |
| 193 // translated to point (0, 950) in the framebuffer. | 193 // translated to point (0, 950) in the framebuffer. |
| 194 DisplayInfo display1_info = | 194 ui::ManagedDisplayInfo display1_info = |
| 195 CreateDisplayInfo(1, 10u, gfx::Rect(0, 0, 1280, 850)); | 195 CreateDisplayInfo(1, 10u, gfx::Rect(0, 0, 1280, 850)); |
| 196 DisplayInfo::ManagedDisplayModeList display1_modes; | 196 ui::ManagedDisplayInfo::ManagedDisplayModeList display1_modes; |
| 197 display1_modes.push_back(make_scoped_refptr( | 197 display1_modes.push_back(make_scoped_refptr( |
| 198 new ManagedDisplayMode(gfx::Size(1280, 850), 60, false, true))); | 198 new ui::ManagedDisplayMode(gfx::Size(1280, 850), 60, false, true))); |
| 199 display1_info.SetManagedDisplayModes(display1_modes); | 199 display1_info.SetManagedDisplayModes(display1_modes); |
| 200 | 200 |
| 201 DisplayInfo display2_info = | 201 ui::ManagedDisplayInfo display2_info = |
| 202 CreateDisplayInfo(2, 11u, gfx::Rect(0, 950, 1920, 1080)); | 202 CreateDisplayInfo(2, 11u, gfx::Rect(0, 950, 1920, 1080)); |
| 203 DisplayInfo::ManagedDisplayModeList display2_modes; | 203 ui::ManagedDisplayInfo::ManagedDisplayModeList display2_modes; |
| 204 display2_modes.push_back(make_scoped_refptr( | 204 display2_modes.push_back(make_scoped_refptr( |
| 205 new ManagedDisplayMode(gfx::Size(1920, 1080), 60, false, true))); | 205 new ui::ManagedDisplayMode(gfx::Size(1920, 1080), 60, false, true))); |
| 206 display2_info.SetManagedDisplayModes(display2_modes); | 206 display2_info.SetManagedDisplayModes(display2_modes); |
| 207 | 207 |
| 208 gfx::Size fb_size(1920, 1990); | 208 gfx::Size fb_size(1920, 1990); |
| 209 | 209 |
| 210 // Create the touchscreens with the same size as the framebuffer so we can | 210 // Create the touchscreens with the same size as the framebuffer so we can |
| 211 // share the tests between Ozone & X11. | 211 // share the tests between Ozone & X11. |
| 212 ui::TouchscreenDevice display1_touchscreen = | 212 ui::TouchscreenDevice display1_touchscreen = |
| 213 CreateTouchscreenDevice(10, fb_size); | 213 CreateTouchscreenDevice(10, fb_size); |
| 214 ui::TouchscreenDevice display2_touchscreen = | 214 ui::TouchscreenDevice display2_touchscreen = |
| 215 CreateTouchscreenDevice(11, fb_size); | 215 CreateTouchscreenDevice(11, fb_size); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 EXPECT_NEAR(1280, x, 0.5); | 267 EXPECT_NEAR(1280, x, 0.5); |
| 268 EXPECT_NEAR(850, y, 0.5); | 268 EXPECT_NEAR(850, y, 0.5); |
| 269 } | 269 } |
| 270 | 270 |
| 271 TEST_F(TouchTransformerControllerTest, ExtendedMode) { | 271 TEST_F(TouchTransformerControllerTest, ExtendedMode) { |
| 272 // The internal display has size 1366 x 768. The external display has | 272 // The internal display has size 1366 x 768. The external display has |
| 273 // size 2560x1600. The total frame buffer is 2560x2428, | 273 // size 2560x1600. The total frame buffer is 2560x2428, |
| 274 // where 2428 = 768 + 60 (hidden gap) + 1600 | 274 // where 2428 = 768 + 60 (hidden gap) + 1600 |
| 275 // and the second monitor is translated to Point (0, 828) in the | 275 // and the second monitor is translated to Point (0, 828) in the |
| 276 // framebuffer. | 276 // framebuffer. |
| 277 DisplayInfo display1 = CreateDisplayInfo(1, 5u, gfx::Rect(0, 0, 1366, 768)); | 277 ui::ManagedDisplayInfo display1 = |
| 278 DisplayInfo display2 = | 278 CreateDisplayInfo(1, 5u, gfx::Rect(0, 0, 1366, 768)); |
| 279 ui::ManagedDisplayInfo display2 = |
| 279 CreateDisplayInfo(2, 6u, gfx::Rect(0, 828, 2560, 1600)); | 280 CreateDisplayInfo(2, 6u, gfx::Rect(0, 828, 2560, 1600)); |
| 280 gfx::Size fb_size(2560, 2428); | 281 gfx::Size fb_size(2560, 2428); |
| 281 | 282 |
| 282 // Create the touchscreens with the same size as the framebuffer so we can | 283 // Create the touchscreens with the same size as the framebuffer so we can |
| 283 // share the tests between Ozone & X11. | 284 // share the tests between Ozone & X11. |
| 284 ui::TouchscreenDevice touchscreen1 = CreateTouchscreenDevice(5, fb_size); | 285 ui::TouchscreenDevice touchscreen1 = CreateTouchscreenDevice(5, fb_size); |
| 285 ui::TouchscreenDevice touchscreen2 = CreateTouchscreenDevice(6, fb_size); | 286 ui::TouchscreenDevice touchscreen2 = CreateTouchscreenDevice(6, fb_size); |
| 286 | 287 |
| 287 TouchTransformerController* tt_controller = | 288 TouchTransformerController* tt_controller = |
| 288 Shell::GetInstance()->touch_transformer_controller(); | 289 Shell::GetInstance()->touch_transformer_controller(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 // On ozone we expect screen coordinates so add display origin. | 337 // On ozone we expect screen coordinates so add display origin. |
| 337 EXPECT_NEAR(2559 + 0, x, 0.5); | 338 EXPECT_NEAR(2559 + 0, x, 0.5); |
| 338 EXPECT_NEAR(1599 + 828, y, 0.5); | 339 EXPECT_NEAR(1599 + 828, y, 0.5); |
| 339 #else | 340 #else |
| 340 EXPECT_NEAR(2559, x, 0.5); | 341 EXPECT_NEAR(2559, x, 0.5); |
| 341 EXPECT_NEAR(1599, y, 0.5); | 342 EXPECT_NEAR(1599, y, 0.5); |
| 342 #endif | 343 #endif |
| 343 } | 344 } |
| 344 | 345 |
| 345 TEST_F(TouchTransformerControllerTest, TouchRadiusScale) { | 346 TEST_F(TouchTransformerControllerTest, TouchRadiusScale) { |
| 346 DisplayInfo display = CreateDisplayInfo(1, 5u, gfx::Rect(0, 0, 2560, 1600)); | 347 ui::ManagedDisplayInfo display = |
| 348 CreateDisplayInfo(1, 5u, gfx::Rect(0, 0, 2560, 1600)); |
| 347 ui::TouchscreenDevice touch_device = | 349 ui::TouchscreenDevice touch_device = |
| 348 CreateTouchscreenDevice(5, gfx::Size(1001, 1001)); | 350 CreateTouchscreenDevice(5, gfx::Size(1001, 1001)); |
| 349 | 351 |
| 350 TouchTransformerController* tt_controller = | 352 TouchTransformerController* tt_controller = |
| 351 Shell::GetInstance()->touch_transformer_controller(); | 353 Shell::GetInstance()->touch_transformer_controller(); |
| 352 // Default touchscreen position range is 1001x1001; | 354 // Default touchscreen position range is 1001x1001; |
| 353 EXPECT_EQ(sqrt((2560.0 * 1600.0) / (1001.0 * 1001.0)), | 355 EXPECT_EQ(sqrt((2560.0 * 1600.0) / (1001.0 * 1001.0)), |
| 354 tt_controller->GetTouchResolutionScale(display, touch_device)); | 356 tt_controller->GetTouchResolutionScale(display, touch_device)); |
| 355 } | 357 } |
| 356 | 358 |
| 357 } // namespace ash | 359 } // namespace ash |
| OLD | NEW |