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 DisplayInfo CreateDisplayInfo(int64 id, | 17 DisplayInfo CreateDisplayInfo(int64 id, |
18 int touch_device_id, | 18 unsigned int touch_device_id, |
19 const gfx::Rect& bounds) { | 19 const gfx::Rect& bounds) { |
20 DisplayInfo info(id, std::string(), false); | 20 DisplayInfo info(id, std::string(), false); |
21 info.SetBounds(bounds); | 21 info.SetBounds(bounds); |
22 info.set_touch_device_id(touch_device_id); | 22 info.set_touch_device_id(touch_device_id); |
23 return info; | 23 return info; |
24 } | 24 } |
25 } // namespace | 25 } // namespace |
26 | 26 |
27 typedef test::AshTestBase TouchTransformerControllerTest; | 27 typedef test::AshTestBase TouchTransformerControllerTest; |
28 | 28 |
29 TEST_F(TouchTransformerControllerTest, TouchTransformerMirrorModeLetterboxing) { | 29 TEST_F(TouchTransformerControllerTest, TouchTransformerMirrorModeLetterboxing) { |
30 // The internal display has native resolution of 2560x1700, and in | 30 // The internal display has native resolution of 2560x1700, and in |
31 // mirror mode it is configured as 1920x1200. This is in letterboxing | 31 // mirror mode it is configured as 1920x1200. This is in letterboxing |
32 // mode. | 32 // mode. |
33 DisplayInfo internal_display_info = | 33 DisplayInfo internal_display_info = |
34 CreateDisplayInfo(1, 10, gfx::Rect(0, 0, 1920, 1200)); | 34 CreateDisplayInfo(1, 10u, gfx::Rect(0, 0, 1920, 1200)); |
35 std::vector<DisplayMode> internal_modes; | 35 std::vector<DisplayMode> internal_modes; |
36 internal_modes.push_back( | 36 internal_modes.push_back( |
37 DisplayMode(gfx::Size(2560, 1700), 60, false, true)); | 37 DisplayMode(gfx::Size(2560, 1700), 60, false, true)); |
38 internal_modes.push_back( | 38 internal_modes.push_back( |
39 DisplayMode(gfx::Size(1920, 1200), 60, false, false)); | 39 DisplayMode(gfx::Size(1920, 1200), 60, false, false)); |
40 internal_display_info.set_display_modes(internal_modes); | 40 internal_display_info.set_display_modes(internal_modes); |
41 | 41 |
42 DisplayInfo external_display_info = | 42 DisplayInfo external_display_info = |
43 CreateDisplayInfo(2, 11, gfx::Rect(0, 0, 1920, 1200)); | 43 CreateDisplayInfo(2, 11u, gfx::Rect(0, 0, 1920, 1200)); |
44 | 44 |
45 TouchTransformerController* tt_controller = | 45 TouchTransformerController* tt_controller = |
46 Shell::GetInstance()->touch_transformer_controller(); | 46 Shell::GetInstance()->touch_transformer_controller(); |
47 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); | 47 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
48 | 48 |
49 tt_controller->force_compute_mirror_mode_touch_transformer_ = true; | 49 tt_controller->force_compute_mirror_mode_touch_transformer_ = true; |
50 device_manager->UpdateTouchInfoForDisplay( | 50 device_manager->UpdateTouchInfoForDisplay( |
51 internal_display_info.id(), | 51 internal_display_info.id(), |
52 internal_display_info.touch_device_id(), | 52 internal_display_info.touch_device_id(), |
53 tt_controller->GetMirrorModeTouchTransformer(internal_display_info)); | 53 tt_controller->GetMirrorModeTouchTransformer(internal_display_info)); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 EXPECT_EQ(1024, static_cast<int>(x)); | 147 EXPECT_EQ(1024, static_cast<int>(x)); |
148 EXPECT_EQ(100, static_cast<int>(y)); | 148 EXPECT_EQ(100, static_cast<int>(y)); |
149 } | 149 } |
150 | 150 |
151 TEST_F(TouchTransformerControllerTest, TouchTransformerExtendedMode) { | 151 TEST_F(TouchTransformerControllerTest, TouchTransformerExtendedMode) { |
152 // The internal display has size 1366 x 768. The external display has | 152 // The internal display has size 1366 x 768. The external display has |
153 // size 2560x1600. The total frame buffer is 2560x2428, | 153 // size 2560x1600. The total frame buffer is 2560x2428, |
154 // where 2428 = 768 + 60 (hidden gap) + 1600 | 154 // where 2428 = 768 + 60 (hidden gap) + 1600 |
155 // and the sceond monitor is translated to Point (0, 828) in the | 155 // and the sceond monitor is translated to Point (0, 828) in the |
156 // framebuffer. | 156 // framebuffer. |
157 DisplayInfo display1 = CreateDisplayInfo(1, 5, gfx::Rect(0, 0, 1366, 768)); | 157 DisplayInfo display1 = CreateDisplayInfo(1, 5u, gfx::Rect(0, 0, 1366, 768)); |
158 DisplayInfo display2 = CreateDisplayInfo(2, 6, gfx::Rect(0, 828, 2560, 1600)); | 158 DisplayInfo display2 = |
| 159 CreateDisplayInfo(2, 6u, gfx::Rect(0, 828, 2560, 1600)); |
159 gfx::Size fb_size(2560, 2428); | 160 gfx::Size fb_size(2560, 2428); |
160 | 161 |
161 TouchTransformerController* tt_controller = | 162 TouchTransformerController* tt_controller = |
162 Shell::GetInstance()->touch_transformer_controller(); | 163 Shell::GetInstance()->touch_transformer_controller(); |
163 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); | 164 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
164 | 165 |
165 device_manager->UpdateTouchInfoForDisplay( | 166 device_manager->UpdateTouchInfoForDisplay( |
166 display1.id(), | 167 display1.id(), |
167 display1.touch_device_id(), | 168 display1.touch_device_id(), |
168 tt_controller->GetExtendedModeTouchTransformer(display1, fb_size)); | 169 tt_controller->GetExtendedModeTouchTransformer(display1, fb_size)); |
(...skipping 29 matching lines...) Expand all Loading... |
198 EXPECT_EQ(0, static_cast<int>(y)); | 199 EXPECT_EQ(0, static_cast<int>(y)); |
199 | 200 |
200 x = 2559.0; | 201 x = 2559.0; |
201 y = 2427.0; | 202 y = 2427.0; |
202 device_manager->ApplyTouchTransformer(6, &x, &y); | 203 device_manager->ApplyTouchTransformer(6, &x, &y); |
203 EXPECT_EQ(2559, static_cast<int>(x)); | 204 EXPECT_EQ(2559, static_cast<int>(x)); |
204 EXPECT_EQ(1599, static_cast<int>(y)); | 205 EXPECT_EQ(1599, static_cast<int>(y)); |
205 } | 206 } |
206 | 207 |
207 TEST_F(TouchTransformerControllerTest, TouchRadiusScale) { | 208 TEST_F(TouchTransformerControllerTest, TouchRadiusScale) { |
208 DisplayInfo display = CreateDisplayInfo(1, 5, gfx::Rect(0, 0, 2560, 1600)); | 209 DisplayInfo display = CreateDisplayInfo(1, 5u, gfx::Rect(0, 0, 2560, 1600)); |
209 std::vector<unsigned int> devices; | 210 std::vector<unsigned int> devices; |
210 devices.push_back(5); | 211 devices.push_back(5); |
211 ui::SetUpTouchDevicesForTest(devices); | 212 ui::SetUpTouchDevicesForTest(devices); |
212 | 213 |
213 TouchTransformerController* tt_controller = | 214 TouchTransformerController* tt_controller = |
214 Shell::GetInstance()->touch_transformer_controller(); | 215 Shell::GetInstance()->touch_transformer_controller(); |
215 // Default touchscreen position range is 1001x1001; | 216 // Default touchscreen position range is 1001x1001; |
216 EXPECT_EQ(sqrt((2560.0 * 1600.0) / (1001.0 * 1001.0)), | 217 EXPECT_EQ(sqrt((2560.0 * 1600.0) / (1001.0 * 1001.0)), |
217 tt_controller->GetTouchResolutionScale(display)); | 218 tt_controller->GetTouchResolutionScale(display)); |
218 } | 219 } |
219 | 220 |
220 } // namespace ash | 221 } // namespace ash |
OLD | NEW |