1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/touch/touch_transformer_controller.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "ui/aura/window_tree_host.h"
#include "ui/events/devices/device_data_manager.h"
#include "ui/events/test/events_test_utils_x11.h"
#include "ui/gfx/display.h"
namespace ash {
namespace {
DisplayInfo CreateDisplayInfo(int64 id,
unsigned int touch_device_id,
const gfx::Rect& bounds) {
DisplayInfo info(id, std::string(), false);
info.SetBounds(bounds);
info.set_touch_device_id(touch_device_id);
// Create a default mode.
std::vector<DisplayMode> default_modes(
1, DisplayMode(bounds.size(), 60, false, true));
info.SetDisplayModes(default_modes);
return info;
}
ui::TouchscreenDevice CreateTouchscreenDevice(unsigned int id,
const gfx::Size& size) {
return ui::TouchscreenDevice(id, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL,
size, 0);
}
} // namespace
typedef test::AshTestBase TouchTransformerControllerTest;
TEST_F(TouchTransformerControllerTest, MirrorModeLetterboxing) {
// The internal display has native resolution of 2560x1700, and in
// mirror mode it is configured as 1920x1200. This is in letterboxing
// mode.
DisplayInfo internal_display_info =
CreateDisplayInfo(1, 10u, gfx::Rect(0, 0, 1920, 1200));
internal_display_info.set_is_aspect_preserving_scaling(true);
std::vector<DisplayMode> internal_modes;
internal_modes.push_back(
DisplayMode(gfx::Size(2560, 1700), 60, false, true));
internal_modes.push_back(
DisplayMode(gfx::Size(1920, 1200), 60, false, false));
internal_display_info.SetDisplayModes(internal_modes);
DisplayInfo external_display_info =
CreateDisplayInfo(2, 11u, gfx::Rect(0, 0, 1920, 1200));
gfx::Size fb_size(1920, 1200);
// Create the touchscreens with the same size as the framebuffer so we can
// share the tests between Ozone & X11.
ui::TouchscreenDevice internal_touchscreen =
CreateTouchscreenDevice(10, fb_size);
ui::TouchscreenDevice external_touchscreen =
CreateTouchscreenDevice(11, fb_size);
TouchTransformerController* tt_controller =
Shell::GetInstance()->touch_transformer_controller();
ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
device_manager->UpdateTouchInfoForDisplay(
internal_display_info.id(), internal_display_info.touch_device_id(),
tt_controller->GetTouchTransform(internal_display_info,
internal_display_info,
internal_touchscreen, fb_size));
device_manager->UpdateTouchInfoForDisplay(
internal_display_info.id(), external_display_info.touch_device_id(),
tt_controller->GetTouchTransform(external_display_info,
external_display_info,
external_touchscreen, fb_size));
EXPECT_EQ(1, device_manager->GetTargetDisplayForTouchDevice(10));
EXPECT_EQ(1, device_manager->GetTargetDisplayForTouchDevice(11));
// External touch display has the default TouchTransformer.
float x = 100.0;
float y = 100.0;
device_manager->ApplyTouchTransformer(11, &x, &y);
EXPECT_EQ(100, x);
EXPECT_EQ(100, y);
// In letterboxing, there is (1-2560*(1200/1920)/1700)/2 = 2.95% of the
// height on both the top & bottom region of the screen is blank.
// When touch events coming at Y range [0, 1200), the mapping should be
// [0, ~35] ---> < 0
// [~35, ~1165] ---> [0, 1200)
// [~1165, 1200] ---> >= 1200
x = 100.0;
y = 35.0;
device_manager->ApplyTouchTransformer(10, &x, &y);
EXPECT_NEAR(100, x, 0.5);
EXPECT_NEAR(0, y, 0.5);
x = 100.0;
y = 1165.0;
device_manager->ApplyTouchTransformer(10, &x, &y);
EXPECT_NEAR(100, x, 0.5);
EXPECT_NEAR(1200, y, 0.5);
}
TEST_F(TouchTransformerControllerTest, MirrorModePillarboxing) {
// The internal display has native resolution of 1366x768, and in
// mirror mode it is configured as 1024x768. This is in pillarboxing
// mode.
DisplayInfo internal_display_info =
CreateDisplayInfo(1, 10, gfx::Rect(0, 0, 1024, 768));
internal_display_info.set_is_aspect_preserving_scaling(true);
std::vector<DisplayMode> internal_modes;
internal_modes.push_back(
DisplayMode(gfx::Size(1366, 768), 60, false, true));
internal_modes.push_back(
DisplayMode(gfx::Size(1024, 768), 60, false, false));
internal_display_info.SetDisplayModes(internal_modes);
DisplayInfo external_display_info =
CreateDisplayInfo(2, 11, gfx::Rect(0, 0, 1024, 768));
gfx::Size fb_size(1024, 768);
// Create the touchscreens with the same size as the framebuffer so we can
// share the tests between Ozone & X11.
ui::TouchscreenDevice internal_touchscreen =
CreateTouchscreenDevice(10, fb_size);
ui::TouchscreenDevice external_touchscreen =
CreateTouchscreenDevice(11, fb_size);
TouchTransformerController* tt_controller =
Shell::GetInstance()->touch_transformer_controller();
ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
device_manager->UpdateTouchInfoForDisplay(
internal_display_info.id(), internal_display_info.touch_device_id(),
tt_controller->GetTouchTransform(internal_display_info,
internal_display_info,
internal_touchscreen, fb_size));
device_manager->UpdateTouchInfoForDisplay(
internal_display_info.id(), external_display_info.touch_device_id(),
tt_controller->GetTouchTransform(external_display_info,
external_display_info,
external_touchscreen, fb_size));
EXPECT_EQ(1, device_manager->GetTargetDisplayForTouchDevice(10));
EXPECT_EQ(1, device_manager->GetTargetDisplayForTouchDevice(11));
// External touch display has the default TouchTransformer.
float x = 100.0;
float y = 100.0;
device_manager->ApplyTouchTransformer(11, &x, &y);
EXPECT_EQ(100, x);
EXPECT_EQ(100, y);
// In pillarboxing, there is (1-768*(1024/768)/1366)/2 = 12.5% of the
// width on both the left & rigth region of the screen is blank.
// When touch events coming at X range [0, 1024), the mapping should be
// [0, ~128] ---> < 0
// [~128, ~896] ---> [0, 1024)
// [~896, 1024] ---> >= 1024
x = 128.0;
y = 100.0;
device_manager->ApplyTouchTransformer(10, &x, &y);
EXPECT_NEAR(0, x, 0.5);
EXPECT_NEAR(100, y, 0.5);
x = 896.0;
y = 100.0;
device_manager->ApplyTouchTransformer(10, &x, &y);
EXPECT_NEAR(1024, x, 0.5);
EXPECT_NEAR(100, y, 0.5);
}
TEST_F(TouchTransformerControllerTest, SoftwareMirrorMode) {
// External display 1 has size 1280x850. External display 2 has size
// 1920x1080. When using software mirroring to mirror display 1 onto
// display 2, the displays are in extended mode and we map touches from both
// displays to display 1.
// The total frame buffer is 1920x1990,
// where 1990 = 850 + 60 (hidden gap) + 1080 and the second monitor is
// translated to point (0, 950) in the framebuffer.
DisplayInfo display1_info =
CreateDisplayInfo(1, 10u, gfx::Rect(0, 0, 1280, 850));
std::vector<DisplayMode> display1_modes;
display1_modes.push_back(DisplayMode(gfx::Size(1280, 850), 60, false, true));
display1_info.SetDisplayModes(display1_modes);
DisplayInfo display2_info =
CreateDisplayInfo(2, 11u, gfx::Rect(0, 950, 1920, 1080));
std::vector<DisplayMode> display2_modes;
display2_modes.push_back(DisplayMode(gfx::Size(1920, 1080), 60, false, true));
display2_info.SetDisplayModes(display2_modes);
gfx::Size fb_size(1920, 1990);
// Create the touchscreens with the same size as the framebuffer so we can
// share the tests between Ozone & X11.
ui::TouchscreenDevice display1_touchscreen =
CreateTouchscreenDevice(10, fb_size);
ui::TouchscreenDevice display2_touchscreen =
CreateTouchscreenDevice(11, fb_size);
TouchTransformerController* tt_controller =
Shell::GetInstance()->touch_transformer_controller();
ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
device_manager->UpdateTouchInfoForDisplay(
display1_info.id(), display1_info.touch_device_id(),
tt_controller->GetTouchTransform(display1_info, display1_info,
display1_touchscreen, fb_size));
device_manager->UpdateTouchInfoForDisplay(
display1_info.id(), display2_info.touch_device_id(),
tt_controller->GetTouchTransform(display1_info, display2_info,
display2_touchscreen, fb_size));
EXPECT_EQ(1, device_manager->GetTargetDisplayForTouchDevice(10));
EXPECT_EQ(1, device_manager->GetTargetDisplayForTouchDevice(11));
// Mapping for touch events from display 1's touchscreen:
// [0, 1920) x [0, 1990) -> [0, 1280) x [0, 850)
float x = 0.0;
float y = 0.0;
device_manager->ApplyTouchTransformer(10, &x, &y);
EXPECT_NEAR(0, x, 0.5);
EXPECT_NEAR(0, y, 0.5);
x = 1920.0;
y = 1990.0;
device_manager->ApplyTouchTransformer(10, &x, &y);
EXPECT_NEAR(1280, x, 0.5);
EXPECT_NEAR(850, y, 0.5);
// In pillarboxing, there is (1-1280*(1080/850)/1920)/2 = 7.65% of the
// width on both the left & right region of the screen is blank.
// Events come in the range [0, 1920) x [0, 1990).
//
// X mapping:
// [0, ~147] ---> < 0
// [~147, ~1773] ---> [0, 1280)
// [~1773, 1920] ---> >= 1280
// Y mapping:
// [0, 1990) -> [0, 1080)
x = 147.0;
y = 0.0;
device_manager->ApplyTouchTransformer(11, &x, &y);
EXPECT_NEAR(0, x, 0.5);
EXPECT_NEAR(0, y, 0.5);
x = 1773.0;
y = 1990.0;
device_manager->ApplyTouchTransformer(11, &x, &y);
EXPECT_NEAR(1280, x, 0.5);
EXPECT_NEAR(850, y, 0.5);
}
TEST_F(TouchTransformerControllerTest, ExtendedMode) {
// The internal display has size 1366 x 768. The external display has
// size 2560x1600. The total frame buffer is 2560x2428,
// where 2428 = 768 + 60 (hidden gap) + 1600
// and the second monitor is translated to Point (0, 828) in the
// framebuffer.
DisplayInfo display1 = CreateDisplayInfo(1, 5u, gfx::Rect(0, 0, 1366, 768));
DisplayInfo display2 =
CreateDisplayInfo(2, 6u, gfx::Rect(0, 828, 2560, 1600));
gfx::Size fb_size(2560, 2428);
// Create the touchscreens with the same size as the framebuffer so we can
// share the tests between Ozone & X11.
ui::TouchscreenDevice touchscreen1 = CreateTouchscreenDevice(5, fb_size);
ui::TouchscreenDevice touchscreen2 = CreateTouchscreenDevice(6, fb_size);
TouchTransformerController* tt_controller =
Shell::GetInstance()->touch_transformer_controller();
ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
device_manager->UpdateTouchInfoForDisplay(
display1.id(), display1.touch_device_id(),
tt_controller->GetTouchTransform(display1, display1, touchscreen1,
fb_size));
device_manager->UpdateTouchInfoForDisplay(
display2.id(), display2.touch_device_id(),
tt_controller->GetTouchTransform(display2, display2, touchscreen2,
fb_size));
EXPECT_EQ(1, device_manager->GetTargetDisplayForTouchDevice(5));
EXPECT_EQ(2, device_manager->GetTargetDisplayForTouchDevice(6));
// Mapping for touch events from internal touch display:
// [0, 2560) x [0, 2428) -> [0, 1366) x [0, 768)
float x = 0.0;
float y = 0.0;
device_manager->ApplyTouchTransformer(5, &x, &y);
EXPECT_NEAR(0, x, 0.5);
EXPECT_NEAR(0, y, 0.5);
x = 2559.0;
y = 2427.0;
device_manager->ApplyTouchTransformer(5, &x, &y);
EXPECT_NEAR(1365, x, 0.5);
EXPECT_NEAR(768, y, 0.5);
// Mapping for touch events from external touch display:
// [0, 2560) x [0, 2428) -> [0, 2560) x [0, 1600)
x = 0.0;
y = 0.0;
device_manager->ApplyTouchTransformer(6, &x, &y);
#if defined(USE_OZONE)
// On ozone we expect screen coordinates so add display origin.
EXPECT_NEAR(0 + 0, x, 0.5);
EXPECT_NEAR(0 + 828, y, 0.5);
#else
EXPECT_NEAR(0, x, 0.5);
EXPECT_NEAR(0, y, 0.5);
#endif
x = 2559.0;
y = 2427.0;
device_manager->ApplyTouchTransformer(6, &x, &y);
#if defined(USE_OZONE)
// On ozone we expect screen coordinates so add display origin.
EXPECT_NEAR(2559 + 0, x, 0.5);
EXPECT_NEAR(1599 + 828, y, 0.5);
#else
EXPECT_NEAR(2559, x, 0.5);
EXPECT_NEAR(1599, y, 0.5);
#endif
}
TEST_F(TouchTransformerControllerTest, TouchRadiusScale) {
DisplayInfo display = CreateDisplayInfo(1, 5u, gfx::Rect(0, 0, 2560, 1600));
ui::TouchscreenDevice touch_device =
CreateTouchscreenDevice(5, gfx::Size(1001, 1001));
TouchTransformerController* tt_controller =
Shell::GetInstance()->touch_transformer_controller();
// Default touchscreen position range is 1001x1001;
EXPECT_EQ(sqrt((2560.0 * 1600.0) / (1001.0 * 1001.0)),
tt_controller->GetTouchResolutionScale(display, touch_device));
}
} // namespace ash
|