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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ash/touch/touch_ctm_controller_unittest.cc
diff --git a/ash/touch/touch_ctm_controller_unittest.cc b/ash/touch/touch_ctm_controller_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f7a66907c98aeec9cf4a634a841e79355ca41fe6
--- /dev/null
+++ b/ash/touch/touch_ctm_controller_unittest.cc
@@ -0,0 +1,253 @@
+// Copyright (c) 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_ctm_controller.h"
+
+#include "ash/shell.h"
+#include "ash/test/ash_test_base.h"
+#include "ui/aura/window_tree_host.h"
+#include "ui/gfx/display.h"
+
+#if defined(OS_CHROMEOS) && defined(USE_X11)
+#include "ui/events/x/device_data_manager.h"
+#endif
+
+namespace ash {
+
+#if defined(OS_CHROMEOS)
+namespace {
+internal::DisplayInfo CreateDisplayInfo(int64 id,
+ int touch_device_id,
+ const gfx::Rect& bounds) {
+ internal::DisplayInfo info(id, "", false);
+ info.SetBounds(bounds);
+ info.set_touch_device_id(touch_device_id);
+ return info;
+}
+} // namespace
+
+typedef test::AshTestBase TouchCTMControllerTest;
+
+TEST_F(TouchCTMControllerTest, TouchCTMSingleTouchDisplay) {
+ // Touch display.
+ const internal::DisplayInfo touch_display_info =
+ CreateDisplayInfo(1, 10, gfx::Rect(0, 0, 500, 500));
+ std::vector<internal::DisplayInfo> display_info_list;
+ display_info_list.push_back(touch_display_info);
+ Shell::GetInstance()->display_manager()->OnNativeDisplaysChanged(
+ display_info_list);
+
+ std::pair<int64, int64> display_ids =
+ Shell::GetPrimaryRootWindow()->GetHost()->display_ids();
+ EXPECT_EQ(1, display_ids.first);
+ EXPECT_EQ(gfx::Display::kInvalidDisplayID, display_ids.second);
+
+ ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
+ EXPECT_EQ(1, device_manager->GetDisplayForTouchDevice(10));
+
+ // Single touch display has the default TouchCTM.
+ float x = 100.0;
+ float y = 100.0;
+ device_manager->ApplyTouchCTM(10, &x, &y);
+ EXPECT_EQ(100, x);
+ EXPECT_EQ(100, y);
+}
+
+TEST_F(TouchCTMControllerTest, TouchCTMMirrorModeLetterboxing) {
+ // The internal display has native resolution of 2560x1700, and in
+ // mirror mode it is configured as 1920x1200. This is in letterboxing
+ // mode.
+ internal::DisplayInfo internal_display_info =
+ CreateDisplayInfo(1, 10, gfx::Rect(0, 0, 1920, 1200));
+ std::vector<internal::DisplayMode> internal_modes;
+ internal_modes.push_back(
+ internal::DisplayMode(gfx::Size(2560, 1700), 60, false, true));
+ internal_modes.push_back(
+ internal::DisplayMode(gfx::Size(1920, 1200), 60, false, false));
+ internal_display_info.set_display_modes(internal_modes);
+
+ internal::DisplayInfo external_display_info =
+ CreateDisplayInfo(2, 11, gfx::Rect(0, 0, 1920, 1200));
+
+ gfx::Display::SetInternalDisplayId(1);
+
+ std::vector<internal::DisplayInfo> display_info_list;
+ display_info_list.push_back(internal_display_info);
+ display_info_list.push_back(external_display_info);
+ Shell::GetInstance()->output_configurator()->set_output_state(
+ ui::OUTPUT_STATE_DUAL_MIRROR);
+ Shell::GetInstance()->display_manager()->OnNativeDisplaysChanged(
+ display_info_list);
+
+ // In mirror mode, the root window host is associated with both
+ // display ids.
+ std::pair<int64, int64> display_ids =
+ Shell::GetPrimaryRootWindow()->GetHost()->display_ids();
+ EXPECT_EQ(1, display_ids.first);
+ EXPECT_EQ(2, display_ids.second);
+
+ ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
+ EXPECT_EQ(1, device_manager->GetDisplayForTouchDevice(10));
+ EXPECT_EQ(2, device_manager->GetDisplayForTouchDevice(11));
+
+ // External touch display has the default TouchCTM.
+ float x = 100.0;
+ float y = 100.0;
+ device_manager->ApplyTouchCTM(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->ApplyTouchCTM(10, &x, &y);
+ EXPECT_EQ(100, x);
+ EXPECT_EQ(0, abs(y - 0));
+
+ x = 100.0;
+ y = 1165.0;
+ device_manager->ApplyTouchCTM(10, &x, &y);
+ EXPECT_EQ(100, x);
+ EXPECT_EQ(0, abs(y - 1200));
+}
+
+TEST_F(TouchCTMControllerTest, TouchCTMMirrorModePillarboxing) {
+ // The internal display has native resolution of 1366x768, and in
+ // mirror mode it is configured as 1024x768. This is in pillarboxing
+ // mode.
+ internal::DisplayInfo internal_display_info =
+ CreateDisplayInfo(1, 10, gfx::Rect(0, 0, 1024, 768));
+ std::vector<internal::DisplayMode> internal_modes;
+ internal_modes.push_back(
+ internal::DisplayMode(gfx::Size(1366, 768), 60, false, true));
+ internal_modes.push_back(
+ internal::DisplayMode(gfx::Size(1024, 768), 60, false, false));
+ internal_display_info.set_display_modes(internal_modes);
+
+ internal::DisplayInfo external_display_info =
+ CreateDisplayInfo(2, 11, gfx::Rect(0, 0, 1024, 768));
+
+ gfx::Display::SetInternalDisplayId(1);
+
+ std::vector<internal::DisplayInfo> display_info_list;
+ display_info_list.push_back(internal_display_info);
+ display_info_list.push_back(external_display_info);
+ Shell::GetInstance()->output_configurator()->set_output_state(
+ ui::OUTPUT_STATE_DUAL_MIRROR);
+ Shell::GetInstance()->display_manager()->OnNativeDisplaysChanged(
+ display_info_list);
+
+ // In mirror mode, the root window host is associated with both
+ // display ids.
+ std::pair<int64, int64> display_ids =
+ Shell::GetPrimaryRootWindow()->GetHost()->display_ids();
+ EXPECT_EQ(1, display_ids.first);
+ EXPECT_EQ(2, display_ids.second);
+
+ ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
+ EXPECT_EQ(1, device_manager->GetDisplayForTouchDevice(10));
+ EXPECT_EQ(2, device_manager->GetDisplayForTouchDevice(11));
+
+ // External touch display has the default TouchCTM.
+ float x = 100.0;
+ float y = 100.0;
+ device_manager->ApplyTouchCTM(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->ApplyTouchCTM(10, &x, &y);
+ EXPECT_EQ(0, abs(x - 0));
+ EXPECT_EQ(100, y);
+
+ x = 896.0;
+ y = 100.0;
+ device_manager->ApplyTouchCTM(10, &x, &y);
+ EXPECT_EQ(0, abs(x - 1024));
+ EXPECT_EQ(100, y);
+}
+
+TEST_F(TouchCTMControllerTest, TouchCTMExtendedMode) {
+ // 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 sceond monitor is translated to Point (0, 828) in the
+ // framebuffer.
+ internal::DisplayInfo internal_display_info =
+ CreateDisplayInfo(1, 10, gfx::Rect(0, 0, 1366, 768));
+ internal::DisplayInfo external_display_info =
+ CreateDisplayInfo(2, 11, gfx::Rect(0, 828, 2560, 1600));
+
+ std::vector<internal::DisplayInfo> display_info_list;
+ display_info_list.push_back(internal_display_info);
+ display_info_list.push_back(external_display_info);
+ Shell::GetInstance()->output_configurator()->set_output_state(
+ ui::OUTPUT_STATE_DUAL_EXTENDED);
+ Shell::GetInstance()->display_manager()->OnNativeDisplaysChanged(
+ display_info_list);
+
+ DisplayController* display_controller =
+ Shell::GetInstance()->display_controller();
+ aura::Window* primary = display_controller->GetRootWindowForDisplayId(1);
+ std::pair<int64, int64> primary_display_ids =
+ primary->GetHost()->display_ids();
+ aura::Window* secondary = display_controller->GetRootWindowForDisplayId(2);
+ std::pair<int64, int64> secondary_display_ids =
+ secondary->GetHost()->display_ids();
+ // The primary root window is associated with display ID 1.
+ EXPECT_EQ(1, primary_display_ids.first);
+ EXPECT_EQ(gfx::Display::kInvalidDisplayID, primary_display_ids.second);
+ // The secondary root window is associated with display ID 2.
+ EXPECT_EQ(2, secondary_display_ids.first);
+ EXPECT_EQ(gfx::Display::kInvalidDisplayID, secondary_display_ids.second);
+
+
+ ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
+ EXPECT_EQ(1, device_manager->GetDisplayForTouchDevice(10));
+ EXPECT_EQ(2, device_manager->GetDisplayForTouchDevice(11));
+
+ // 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->ApplyTouchCTM(10, &x, &y);
+ EXPECT_EQ(0, x);
+ EXPECT_EQ(0, y);
+
+ x = 2559.0;
+ y = 2427.0;
+ device_manager->ApplyTouchCTM(10, &x, &y);
+ EXPECT_EQ(1365, x);
+ EXPECT_EQ(767, y);
+
+ // 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->ApplyTouchCTM(11, &x, &y);
+ EXPECT_EQ(0, x);
+ EXPECT_EQ(0, y);
+
+ x = 2559.0;
+ y = 2427.0;
+ device_manager->ApplyTouchCTM(11, &x, &y);
+ EXPECT_EQ(2559, x);
+ EXPECT_EQ(1599, y);
+}
+
+#endif // defined(OS_CHROMEOS)
+
+} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698