Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(637)

Side by Side Diff: ash/touch/touch_ctm_controller_unittest.cc

Issue 191223007: Move touch CTM from X into Chrome (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: move CTM update code into a separate file ash/touch/touch_ctm_controller.cc Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_ctm_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/gfx/display.h"
11
12 #if defined(OS_CHROMEOS) && defined(USE_X11)
13 #include "ui/events/x/device_data_manager.h"
14 #endif
15
16 namespace ash {
17
18 #if defined(OS_CHROMEOS)
19 namespace {
20 internal::DisplayInfo CreateDisplayInfo(int64 id,
21 int touch_device_id,
22 const gfx::Rect& bounds) {
23 internal::DisplayInfo info(id, "", false);
24 info.SetBounds(bounds);
25 info.set_touch_device_id(touch_device_id);
26 return info;
27 }
28 } // namespace
29
30 typedef test::AshTestBase TouchCTMControllerTest;
31
32 TEST_F(TouchCTMControllerTest, TouchCTMSingleTouchDisplay) {
33 // Touch display.
34 const internal::DisplayInfo touch_display_info =
35 CreateDisplayInfo(1, 10, gfx::Rect(0, 0, 500, 500));
36 std::vector<internal::DisplayInfo> display_info_list;
37 display_info_list.push_back(touch_display_info);
38 Shell::GetInstance()->display_manager()->OnNativeDisplaysChanged(
39 display_info_list);
40
41 std::pair<int64, int64> display_ids =
42 Shell::GetPrimaryRootWindow()->GetHost()->display_ids();
43 EXPECT_EQ(1, display_ids.first);
44 EXPECT_EQ(gfx::Display::kInvalidDisplayID, display_ids.second);
45
46 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
47 EXPECT_EQ(1, device_manager->GetDisplayForTouchDevice(10));
48
49 // Single touch display has the default TouchCTM.
50 float x = 100.0;
51 float y = 100.0;
52 device_manager->ApplyTouchCTM(10, &x, &y);
53 EXPECT_EQ(100, x);
54 EXPECT_EQ(100, y);
55 }
56
57 TEST_F(TouchCTMControllerTest, TouchCTMMirrorModeLetterboxing) {
58 // The internal display has native resolution of 2560x1700, and in
59 // mirror mode it is configured as 1920x1200. This is in letterboxing
60 // mode.
61 internal::DisplayInfo internal_display_info =
62 CreateDisplayInfo(1, 10, gfx::Rect(0, 0, 1920, 1200));
63 std::vector<internal::DisplayMode> internal_modes;
64 internal_modes.push_back(
65 internal::DisplayMode(gfx::Size(2560, 1700), 60, false, true));
66 internal_modes.push_back(
67 internal::DisplayMode(gfx::Size(1920, 1200), 60, false, false));
68 internal_display_info.set_display_modes(internal_modes);
69
70 internal::DisplayInfo external_display_info =
71 CreateDisplayInfo(2, 11, gfx::Rect(0, 0, 1920, 1200));
72
73 gfx::Display::SetInternalDisplayId(1);
74
75 std::vector<internal::DisplayInfo> display_info_list;
76 display_info_list.push_back(internal_display_info);
77 display_info_list.push_back(external_display_info);
78 Shell::GetInstance()->output_configurator()->set_output_state(
79 ui::OUTPUT_STATE_DUAL_MIRROR);
80 Shell::GetInstance()->display_manager()->OnNativeDisplaysChanged(
81 display_info_list);
82
83 // In mirror mode, the root window host is associated with both
84 // display ids.
85 std::pair<int64, int64> display_ids =
86 Shell::GetPrimaryRootWindow()->GetHost()->display_ids();
87 EXPECT_EQ(1, display_ids.first);
88 EXPECT_EQ(2, display_ids.second);
89
90 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
91 EXPECT_EQ(1, device_manager->GetDisplayForTouchDevice(10));
92 EXPECT_EQ(2, device_manager->GetDisplayForTouchDevice(11));
93
94 // External touch display has the default TouchCTM.
95 float x = 100.0;
96 float y = 100.0;
97 device_manager->ApplyTouchCTM(11, &x, &y);
98 EXPECT_EQ(100, x);
99 EXPECT_EQ(100, y);
100
101 // In letterboxing, there is (1-2560*(1200/1920)/1700)/2 = 2.95% of the
102 // height on both the top & bottom region of the screen is blank.
103 // When touch events coming at Y range [0, 1200), the mapping should be
104 // [0, ~35] ---> < 0
105 // [~35, ~1165] ---> [0, 1200)
106 // [~1165, 1200] ---> >= 1200
107 x = 100.0;
108 y = 35.0;
109 device_manager->ApplyTouchCTM(10, &x, &y);
110 EXPECT_EQ(100, x);
111 EXPECT_EQ(0, abs(y - 0));
112
113 x = 100.0;
114 y = 1165.0;
115 device_manager->ApplyTouchCTM(10, &x, &y);
116 EXPECT_EQ(100, x);
117 EXPECT_EQ(0, abs(y - 1200));
118 }
119
120 TEST_F(TouchCTMControllerTest, TouchCTMMirrorModePillarboxing) {
121 // The internal display has native resolution of 1366x768, and in
122 // mirror mode it is configured as 1024x768. This is in pillarboxing
123 // mode.
124 internal::DisplayInfo internal_display_info =
125 CreateDisplayInfo(1, 10, gfx::Rect(0, 0, 1024, 768));
126 std::vector<internal::DisplayMode> internal_modes;
127 internal_modes.push_back(
128 internal::DisplayMode(gfx::Size(1366, 768), 60, false, true));
129 internal_modes.push_back(
130 internal::DisplayMode(gfx::Size(1024, 768), 60, false, false));
131 internal_display_info.set_display_modes(internal_modes);
132
133 internal::DisplayInfo external_display_info =
134 CreateDisplayInfo(2, 11, gfx::Rect(0, 0, 1024, 768));
135
136 gfx::Display::SetInternalDisplayId(1);
137
138 std::vector<internal::DisplayInfo> display_info_list;
139 display_info_list.push_back(internal_display_info);
140 display_info_list.push_back(external_display_info);
141 Shell::GetInstance()->output_configurator()->set_output_state(
142 ui::OUTPUT_STATE_DUAL_MIRROR);
143 Shell::GetInstance()->display_manager()->OnNativeDisplaysChanged(
144 display_info_list);
145
146 // In mirror mode, the root window host is associated with both
147 // display ids.
148 std::pair<int64, int64> display_ids =
149 Shell::GetPrimaryRootWindow()->GetHost()->display_ids();
150 EXPECT_EQ(1, display_ids.first);
151 EXPECT_EQ(2, display_ids.second);
152
153 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
154 EXPECT_EQ(1, device_manager->GetDisplayForTouchDevice(10));
155 EXPECT_EQ(2, device_manager->GetDisplayForTouchDevice(11));
156
157 // External touch display has the default TouchCTM.
158 float x = 100.0;
159 float y = 100.0;
160 device_manager->ApplyTouchCTM(11, &x, &y);
161 EXPECT_EQ(100, x);
162 EXPECT_EQ(100, y);
163
164 // In pillarboxing, there is (1-768*(1024/768)/1366)/2 = 12.5% of the
165 // width on both the left & rigth region of the screen is blank.
166 // When touch events coming at X range [0, 1024), the mapping should be
167 // [0, ~128] ---> < 0
168 // [~128, ~896] ---> [0, 1024)
169 // [~896, 1024] ---> >= 1024
170 x = 128.0;
171 y = 100.0;
172 device_manager->ApplyTouchCTM(10, &x, &y);
173 EXPECT_EQ(0, abs(x - 0));
174 EXPECT_EQ(100, y);
175
176 x = 896.0;
177 y = 100.0;
178 device_manager->ApplyTouchCTM(10, &x, &y);
179 EXPECT_EQ(0, abs(x - 1024));
180 EXPECT_EQ(100, y);
181 }
182
183 TEST_F(TouchCTMControllerTest, TouchCTMExtendedMode) {
184 // The internal display has size 1366 x 768. The external display has
185 // size 2560x1600. The total frame buffer is 2560x2428,
186 // where 2428 = 768 + 60 (hidden gap) + 1600
187 // and the sceond monitor is translated to Point (0, 828) in the
188 // framebuffer.
189 internal::DisplayInfo internal_display_info =
190 CreateDisplayInfo(1, 10, gfx::Rect(0, 0, 1366, 768));
191 internal::DisplayInfo external_display_info =
192 CreateDisplayInfo(2, 11, gfx::Rect(0, 828, 2560, 1600));
193
194 std::vector<internal::DisplayInfo> display_info_list;
195 display_info_list.push_back(internal_display_info);
196 display_info_list.push_back(external_display_info);
197 Shell::GetInstance()->output_configurator()->set_output_state(
198 ui::OUTPUT_STATE_DUAL_EXTENDED);
199 Shell::GetInstance()->display_manager()->OnNativeDisplaysChanged(
200 display_info_list);
201
202 DisplayController* display_controller =
203 Shell::GetInstance()->display_controller();
204 aura::Window* primary = display_controller->GetRootWindowForDisplayId(1);
205 std::pair<int64, int64> primary_display_ids =
206 primary->GetHost()->display_ids();
207 aura::Window* secondary = display_controller->GetRootWindowForDisplayId(2);
208 std::pair<int64, int64> secondary_display_ids =
209 secondary->GetHost()->display_ids();
210 // The primary root window is associated with display ID 1.
211 EXPECT_EQ(1, primary_display_ids.first);
212 EXPECT_EQ(gfx::Display::kInvalidDisplayID, primary_display_ids.second);
213 // The secondary root window is associated with display ID 2.
214 EXPECT_EQ(2, secondary_display_ids.first);
215 EXPECT_EQ(gfx::Display::kInvalidDisplayID, secondary_display_ids.second);
216
217
218 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
219 EXPECT_EQ(1, device_manager->GetDisplayForTouchDevice(10));
220 EXPECT_EQ(2, device_manager->GetDisplayForTouchDevice(11));
221
222 // Mapping for touch events from internal touch display:
223 // [0, 2560) x [0, 2428) -> [0, 1366) x [0, 768)
224 float x = 0.0;
225 float y = 0.0;
226 device_manager->ApplyTouchCTM(10, &x, &y);
227 EXPECT_EQ(0, x);
228 EXPECT_EQ(0, y);
229
230 x = 2559.0;
231 y = 2427.0;
232 device_manager->ApplyTouchCTM(10, &x, &y);
233 EXPECT_EQ(1365, x);
234 EXPECT_EQ(767, y);
235
236 // Mapping for touch events from external touch display:
237 // [0, 2560) x [0, 2428) -> [0, 2560) x [0, 1600)
238 x = 0.0;
239 y = 0.0;
240 device_manager->ApplyTouchCTM(11, &x, &y);
241 EXPECT_EQ(0, x);
242 EXPECT_EQ(0, y);
243
244 x = 2559.0;
245 y = 2427.0;
246 device_manager->ApplyTouchCTM(11, &x, &y);
247 EXPECT_EQ(2559, x);
248 EXPECT_EQ(1599, y);
249 }
250
251 #endif // defined(OS_CHROMEOS)
252
253 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698