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

Side by Side Diff: chromeos/display/output_configurator_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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chromeos/display/output_configurator.h" 5 #include "chromeos/display/output_configurator.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <cstdarg> 8 #include <cstdarg>
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 // call. 60 // call.
61 std::string GetFramebufferAction(int width, 61 std::string GetFramebufferAction(int width,
62 int height, 62 int height,
63 RRCrtc crtc1, 63 RRCrtc crtc1,
64 RRCrtc crtc2) { 64 RRCrtc crtc2) {
65 return base::StringPrintf( 65 return base::StringPrintf(
66 "framebuffer(width=%d,height=%d,crtc1=%lu,crtc2=%lu)", 66 "framebuffer(width=%d,height=%d,crtc1=%lu,crtc2=%lu)",
67 width, height, crtc1, crtc2); 67 width, height, crtc1, crtc2);
68 } 68 }
69 69
70 // Returns a string describing a TestNativeDisplayDelegate::ConfigureCTM() call.
71 std::string GetCTMAction(
72 int device_id,
73 const OutputConfigurator::CoordinateTransformation& ctm) {
74 return base::StringPrintf("ctm(id=%d,transform=(%f,%f,%f,%f))", device_id,
75 ctm.x_scale, ctm.x_offset, ctm.y_scale, ctm.y_offset);
76 }
77
78 // Returns a string describing a TestNativeDisplayDelegate::SetHDCPState() call. 70 // Returns a string describing a TestNativeDisplayDelegate::SetHDCPState() call.
79 std::string GetSetHDCPStateAction(RROutput id, ui::HDCPState state) { 71 std::string GetSetHDCPStateAction(RROutput id, ui::HDCPState state) {
80 return base::StringPrintf("set_hdcp(id=%lu,state=%d)", id, state); 72 return base::StringPrintf("set_hdcp(id=%lu,state=%d)", id, state);
81 } 73 }
82 74
83 // Joins a sequence of strings describing actions (e.g. kScreenDim) such 75 // Joins a sequence of strings describing actions (e.g. kScreenDim) such
84 // that they can be compared against a string returned by 76 // that they can be compared against a string returned by
85 // ActionLogger::GetActionsAndClear(). The list of actions must be 77 // ActionLogger::GetActionsAndClear(). The list of actions must be
86 // terminated by a NULL pointer. 78 // terminated by a NULL pointer.
87 std::string JoinActions(const char* action, ...) { 79 std::string JoinActions(const char* action, ...) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 115
124 DISALLOW_COPY_AND_ASSIGN(ActionLogger); 116 DISALLOW_COPY_AND_ASSIGN(ActionLogger);
125 }; 117 };
126 118
127 class TestTouchscreenDelegate : public OutputConfigurator::TouchscreenDelegate { 119 class TestTouchscreenDelegate : public OutputConfigurator::TouchscreenDelegate {
128 public: 120 public:
129 // Ownership of |log| remains with the caller. 121 // Ownership of |log| remains with the caller.
130 explicit TestTouchscreenDelegate(ActionLogger* log) : log_(log) {} 122 explicit TestTouchscreenDelegate(ActionLogger* log) : log_(log) {}
131 virtual ~TestTouchscreenDelegate() {} 123 virtual ~TestTouchscreenDelegate() {}
132 124
133 const OutputConfigurator::CoordinateTransformation& GetCTM(
134 int touch_device_id) {
135 return ctms_[touch_device_id];
136 }
137
138 // OutputConfigurator::TouchscreenDelegate implementation: 125 // OutputConfigurator::TouchscreenDelegate implementation:
139 virtual void AssociateTouchscreens( 126 virtual void AssociateTouchscreens(
140 std::vector<OutputConfigurator::OutputSnapshot>* outputs) OVERRIDE {} 127 std::vector<OutputConfigurator::OutputSnapshot>* outputs) OVERRIDE {}
141 virtual void ConfigureCTM(
142 int touch_device_id,
143 const OutputConfigurator::CoordinateTransformation& ctm) OVERRIDE {
144 log_->AppendAction(GetCTMAction(touch_device_id, ctm));
145 ctms_[touch_device_id] = ctm;
146 }
147 128
148 private: 129 private:
149 ActionLogger* log_; // Not owned. 130 ActionLogger* log_; // Not owned.
150 131
151 // Most-recently-configured transformation matrices, keyed by touch device ID.
152 std::map<int, OutputConfigurator::CoordinateTransformation> ctms_;
153
154 DISALLOW_COPY_AND_ASSIGN(TestTouchscreenDelegate); 132 DISALLOW_COPY_AND_ASSIGN(TestTouchscreenDelegate);
155 }; 133 };
156 134
157 class TestNativeDisplayDelegate : public NativeDisplayDelegate { 135 class TestNativeDisplayDelegate : public NativeDisplayDelegate {
158 public: 136 public:
159 // Ownership of |log| remains with the caller. 137 // Ownership of |log| remains with the caller.
160 explicit TestNativeDisplayDelegate(ActionLogger* log) 138 explicit TestNativeDisplayDelegate(ActionLogger* log)
161 : max_configurable_pixels_(0), 139 : max_configurable_pixels_(0),
162 hdcp_state_(ui::HDCP_STATE_UNDESIRED), 140 hdcp_state_(ui::HDCP_STATE_UNDESIRED),
163 log_(log) {} 141 log_(log) {}
(...skipping 1112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1276 EXPECT_EQ( 1254 EXPECT_EQ(
1277 GetSetHDCPStateAction(outputs_[1].output, ui::HDCP_STATE_DESIRED).c_str(), 1255 GetSetHDCPStateAction(outputs_[1].output, ui::HDCP_STATE_DESIRED).c_str(),
1278 log_->GetActionsAndClear()); 1256 log_->GetActionsAndClear());
1279 EXPECT_TRUE(configurator_.EnableOutputProtection( 1257 EXPECT_TRUE(configurator_.EnableOutputProtection(
1280 client1, outputs_[1].display_id, ui::OUTPUT_PROTECTION_METHOD_NONE)); 1258 client1, outputs_[1].display_id, ui::OUTPUT_PROTECTION_METHOD_NONE));
1281 EXPECT_EQ(GetSetHDCPStateAction(outputs_[1].output, ui::HDCP_STATE_UNDESIRED) 1259 EXPECT_EQ(GetSetHDCPStateAction(outputs_[1].output, ui::HDCP_STATE_UNDESIRED)
1282 .c_str(), 1260 .c_str(),
1283 log_->GetActionsAndClear()); 1261 log_->GetActionsAndClear());
1284 } 1262 }
1285 1263
1286 TEST_F(OutputConfiguratorTest, CTMForMultiScreens) {
1287 outputs_[0].touch_device_id = 1;
1288 outputs_[1].touch_device_id = 2;
1289
1290 UpdateOutputs(2, false);
1291 configurator_.Init(false);
1292 state_controller_.set_state(ui::OUTPUT_STATE_DUAL_EXTENDED);
1293 configurator_.ForceInitialConfigure(0);
1294
1295 const int kDualHeight =
1296 kSmallModeHeight + OutputConfigurator::kVerticalGap + kBigModeHeight;
1297 const int kDualWidth = kBigModeWidth;
1298
1299 OutputConfigurator::CoordinateTransformation ctm1 =
1300 touchscreen_delegate_->GetCTM(1);
1301 OutputConfigurator::CoordinateTransformation ctm2 =
1302 touchscreen_delegate_->GetCTM(2);
1303
1304 EXPECT_EQ(kSmallModeHeight - 1, round((kDualHeight - 1) * ctm1.y_scale));
1305 EXPECT_EQ(0, round((kDualHeight - 1) * ctm1.y_offset));
1306
1307 EXPECT_EQ(kBigModeHeight - 1, round((kDualHeight - 1) * ctm2.y_scale));
1308 EXPECT_EQ(kSmallModeHeight + OutputConfigurator::kVerticalGap,
1309 round((kDualHeight - 1) * ctm2.y_offset));
1310
1311 EXPECT_EQ(kSmallModeWidth - 1, round((kDualWidth - 1) * ctm1.x_scale));
1312 EXPECT_EQ(0, round((kDualWidth - 1) * ctm1.x_offset));
1313
1314 EXPECT_EQ(kBigModeWidth - 1, round((kDualWidth - 1) * ctm2.x_scale));
1315 EXPECT_EQ(0, round((kDualWidth - 1) * ctm2.x_offset));
1316 }
1317
1318 TEST_F(OutputConfiguratorTest, HandleConfigureCrtcFailure) { 1264 TEST_F(OutputConfiguratorTest, HandleConfigureCrtcFailure) {
1319 InitWithSingleOutput(); 1265 InitWithSingleOutput();
1320 1266
1321 // kFirstMode represents the first mode in the list and 1267 // kFirstMode represents the first mode in the list and
1322 // also the mode that we are requesting the output_configurator 1268 // also the mode that we are requesting the output_configurator
1323 // to choose. The test will be setup so that this mode will fail 1269 // to choose. The test will be setup so that this mode will fail
1324 // and it will have to choose the next best option. 1270 // and it will have to choose the next best option.
1325 const int kFirstMode = 11; 1271 const int kFirstMode = 11;
1326 1272
1327 // Give the mode_info lists a few reasonable modes. 1273 // Give the mode_info lists a few reasonable modes.
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1425 outputs_[1].mode_infos[kFirstMode].height + 1371 outputs_[1].mode_infos[kFirstMode].height +
1426 OutputConfigurator::kVerticalGap, 1372 OutputConfigurator::kVerticalGap,
1427 kFirstMode + 3, 1373 kFirstMode + 3,
1428 outputs_[1].output).c_str(), 1374 outputs_[1].output).c_str(),
1429 kUngrab, 1375 kUngrab,
1430 NULL), 1376 NULL),
1431 log_->GetActionsAndClear()); 1377 log_->GetActionsAndClear());
1432 } 1378 }
1433 1379
1434 } // namespace chromeos 1380 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698