OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ash/touch/touch_transformer_controller.h" | |
6 | |
7 #include "ash/shell.h" | |
8 #include "ash/test/ash_test_base.h" | |
9 #include "ui/aura/window_tree_host.h" | |
10 #include "ui/events/x/device_data_manager.h" | |
11 #include "ui/gfx/display.h" | |
12 | |
13 namespace ash { | |
14 | |
15 namespace { | |
16 DisplayInfo CreateDisplayInfo(int64 id, | |
17 int touch_device_id, | |
18 const gfx::Rect& bounds) { | |
19 DisplayInfo info(id, "", false); | |
oshima
2014/05/06 01:47:57
"" -> std::string()
Yufeng Shen (Slow to review)
2014/05/06 21:34:02
Done.
| |
20 info.SetBounds(bounds); | |
21 info.set_touch_device_id(touch_device_id); | |
22 return info; | |
23 } | |
24 } // namespace | |
25 | |
26 typedef test::AshTestBase TouchTransformerControllerTest; | |
27 | |
28 TEST_F(TouchTransformerControllerTest, TouchTransformerMirrorModeLetterboxing) { | |
29 // The internal display has native resolution of 2560x1700, and in | |
30 // mirror mode it is configured as 1920x1200. This is in letterboxing | |
31 // mode. | |
32 DisplayInfo internal_display_info = | |
33 CreateDisplayInfo(1, 10, gfx::Rect(0, 0, 1920, 1200)); | |
34 std::vector<DisplayMode> internal_modes; | |
35 internal_modes.push_back( | |
36 DisplayMode(gfx::Size(2560, 1700), 60, false, true)); | |
37 internal_modes.push_back( | |
38 DisplayMode(gfx::Size(1920, 1200), 60, false, false)); | |
39 internal_display_info.set_display_modes(internal_modes); | |
40 | |
41 DisplayInfo external_display_info = | |
42 CreateDisplayInfo(2, 11, gfx::Rect(0, 0, 1920, 1200)); | |
43 | |
44 TouchTransformerController* tt_controller = | |
45 Shell::GetInstance()->touch_transformer_controller(); | |
46 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); | |
47 | |
48 tt_controller->force_compute_mirror_mode_touch_transformer_ = true; | |
49 device_manager->UpdateTouchInfoForDisplay( | |
50 internal_display_info, | |
51 tt_controller->GetMirrorModeTouchTransformer(internal_display_info)); | |
52 | |
53 tt_controller->force_compute_mirror_mode_touch_transformer_ = false; | |
54 device_manager->UpdateTouchInfoForDisplay( | |
55 external_display_info, | |
56 tt_controller->GetMirrorModeTouchTransformer(external_display_info)); | |
57 | |
58 EXPECT_EQ(1, device_manager->GetDisplayForTouchDevice(10)); | |
59 EXPECT_EQ(2, device_manager->GetDisplayForTouchDevice(11)); | |
60 | |
61 // External touch display has the default TouchTransformer. | |
62 float x = 100.0; | |
63 float y = 100.0; | |
64 device_manager->ApplyTouchTransformer(11, &x, &y); | |
65 EXPECT_EQ(100, x); | |
66 EXPECT_EQ(100, y); | |
67 | |
68 // In letterboxing, there is (1-2560*(1200/1920)/1700)/2 = 2.95% of the | |
69 // height on both the top & bottom region of the screen is blank. | |
70 // When touch events coming at Y range [0, 1200), the mapping should be | |
71 // [0, ~35] ---> < 0 | |
72 // [~35, ~1165] ---> [0, 1200) | |
73 // [~1165, 1200] ---> >= 1200 | |
74 x = 100.0; | |
75 y = 35.0; | |
76 device_manager->ApplyTouchTransformer(10, &x, &y); | |
77 EXPECT_EQ(100, static_cast<int>(x)); | |
78 EXPECT_EQ(0, static_cast<int>(y)); | |
79 | |
80 x = 100.0; | |
81 y = 1165.0; | |
82 device_manager->ApplyTouchTransformer(10, &x, &y); | |
83 EXPECT_EQ(100, static_cast<int>(x)); | |
84 EXPECT_EQ(1200, static_cast<int>(y)); | |
85 } | |
86 | |
87 TEST_F(TouchTransformerControllerTest, TouchTransformerMirrorModePillarboxing) { | |
88 // The internal display has native resolution of 1366x768, and in | |
89 // mirror mode it is configured as 1024x768. This is in pillarboxing | |
90 // mode. | |
91 DisplayInfo internal_display_info = | |
92 CreateDisplayInfo(1, 10, gfx::Rect(0, 0, 1024, 768)); | |
93 std::vector<DisplayMode> internal_modes; | |
94 internal_modes.push_back( | |
95 DisplayMode(gfx::Size(1366, 768), 60, false, true)); | |
96 internal_modes.push_back( | |
97 DisplayMode(gfx::Size(1024, 768), 60, false, false)); | |
98 internal_display_info.set_display_modes(internal_modes); | |
99 | |
100 DisplayInfo external_display_info = | |
101 CreateDisplayInfo(2, 11, gfx::Rect(0, 0, 1024, 768)); | |
102 | |
103 TouchTransformerController* tt_controller = | |
104 Shell::GetInstance()->touch_transformer_controller(); | |
105 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); | |
106 | |
107 tt_controller->force_compute_mirror_mode_touch_transformer_ = true; | |
108 device_manager->UpdateTouchInfoForDisplay( | |
109 internal_display_info, | |
110 tt_controller->GetMirrorModeTouchTransformer(internal_display_info)); | |
111 | |
112 tt_controller->force_compute_mirror_mode_touch_transformer_ = false; | |
113 device_manager->UpdateTouchInfoForDisplay( | |
114 external_display_info, | |
115 tt_controller->GetMirrorModeTouchTransformer(external_display_info)); | |
116 | |
117 EXPECT_EQ(1, device_manager->GetDisplayForTouchDevice(10)); | |
118 EXPECT_EQ(2, device_manager->GetDisplayForTouchDevice(11)); | |
119 | |
120 // External touch display has the default TouchTransformer. | |
121 float x = 100.0; | |
122 float y = 100.0; | |
123 device_manager->ApplyTouchTransformer(11, &x, &y); | |
124 EXPECT_EQ(100, x); | |
125 EXPECT_EQ(100, y); | |
126 | |
127 // In pillarboxing, there is (1-768*(1024/768)/1366)/2 = 12.5% of the | |
128 // width on both the left & rigth region of the screen is blank. | |
129 // When touch events coming at X range [0, 1024), the mapping should be | |
130 // [0, ~128] ---> < 0 | |
131 // [~128, ~896] ---> [0, 1024) | |
132 // [~896, 1024] ---> >= 1024 | |
133 x = 128.0; | |
134 y = 100.0; | |
135 device_manager->ApplyTouchTransformer(10, &x, &y); | |
136 EXPECT_EQ(0, static_cast<int>(x)); | |
137 EXPECT_EQ(100, static_cast<int>(y)); | |
138 | |
139 x = 896.0; | |
140 y = 100.0; | |
141 device_manager->ApplyTouchTransformer(10, &x, &y); | |
142 EXPECT_EQ(1024, static_cast<int>(x)); | |
143 EXPECT_EQ(100, static_cast<int>(y)); | |
144 } | |
145 | |
146 TEST_F(TouchTransformerControllerTest, TouchTransformerExtendedMode) { | |
147 // The internal display has size 1366 x 768. The external display has | |
148 // size 2560x1600. The total frame buffer is 2560x2428, | |
149 // where 2428 = 768 + 60 (hidden gap) + 1600 | |
150 // and the sceond monitor is translated to Point (0, 828) in the | |
151 // framebuffer. | |
152 DisplayInfo display1 = CreateDisplayInfo(1, 5, gfx::Rect(0, 0, 1366, 768)); | |
153 DisplayInfo display2 = CreateDisplayInfo(2, 6, gfx::Rect(0, 828, 2560, 1600)); | |
154 gfx::Size fb_size(2560, 2428); | |
155 | |
156 TouchTransformerController* tt_controller = | |
157 Shell::GetInstance()->touch_transformer_controller(); | |
158 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); | |
159 | |
160 device_manager->UpdateTouchInfoForDisplay( | |
161 display1, | |
162 tt_controller->GetExtendedModeTouchTransformer(display1, fb_size)); | |
163 | |
164 device_manager->UpdateTouchInfoForDisplay( | |
165 display2, | |
166 tt_controller->GetExtendedModeTouchTransformer(display2, fb_size)); | |
167 | |
168 EXPECT_EQ(1, device_manager->GetDisplayForTouchDevice(5)); | |
169 EXPECT_EQ(2, device_manager->GetDisplayForTouchDevice(6)); | |
170 | |
171 // Mapping for touch events from internal touch display: | |
172 // [0, 2560) x [0, 2428) -> [0, 1366) x [0, 768) | |
173 float x = 0.0; | |
174 float y = 0.0; | |
175 device_manager->ApplyTouchTransformer(5, &x, &y); | |
176 EXPECT_EQ(0, static_cast<int>(x)); | |
177 EXPECT_EQ(0, static_cast<int>(y)); | |
178 | |
179 x = 2559.0; | |
180 y = 2427.0; | |
181 device_manager->ApplyTouchTransformer(5, &x, &y); | |
182 EXPECT_EQ(1365, static_cast<int>(x)); | |
183 EXPECT_EQ(767, static_cast<int>(y)); | |
184 | |
185 // Mapping for touch events from external touch display: | |
186 // [0, 2560) x [0, 2428) -> [0, 2560) x [0, 1600) | |
187 x = 0.0; | |
188 y = 0.0; | |
189 device_manager->ApplyTouchTransformer(6, &x, &y); | |
190 EXPECT_EQ(0, static_cast<int>(x)); | |
191 EXPECT_EQ(0, static_cast<int>(y)); | |
192 | |
193 x = 2559.0; | |
194 y = 2427.0; | |
195 device_manager->ApplyTouchTransformer(6, &x, &y); | |
196 EXPECT_EQ(2559, static_cast<int>(x)); | |
197 EXPECT_EQ(1599, static_cast<int>(y)); | |
198 } | |
199 | |
200 } // namespace ash | |
OLD | NEW |