OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/display/chromeos/display_configurator.h" | 5 #include "ui/display/chromeos/display_configurator.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <cmath> | 9 #include <cmath> |
10 #include <cstdarg> | 10 #include <cstdarg> |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 const DisplaySnapshot* out1, | 75 const DisplaySnapshot* out1, |
76 const DisplaySnapshot* out2) { | 76 const DisplaySnapshot* out2) { |
77 return base::StringPrintf( | 77 return base::StringPrintf( |
78 "framebuffer(width=%d,height=%d,display1=%s,display2=%s)", | 78 "framebuffer(width=%d,height=%d,display1=%s,display2=%s)", |
79 size.width(), | 79 size.width(), |
80 size.height(), | 80 size.height(), |
81 out1 ? DisplaySnapshotToString(*out1).c_str() : "NULL", | 81 out1 ? DisplaySnapshotToString(*out1).c_str() : "NULL", |
82 out2 ? DisplaySnapshotToString(*out2).c_str() : "NULL"); | 82 out2 ? DisplaySnapshotToString(*out2).c_str() : "NULL"); |
83 } | 83 } |
84 | 84 |
85 // Returns a string describing a TestNativeDisplayDelegate::ConfigureCTM() call. | |
86 std::string GetCTMAction( | |
87 int device_id, | |
88 const DisplayConfigurator::CoordinateTransformation& ctm) { | |
89 return base::StringPrintf("ctm(id=%d,transform=(%f,%f,%f,%f))", | |
90 device_id, | |
91 ctm.x_scale, | |
92 ctm.x_offset, | |
93 ctm.y_scale, | |
94 ctm.y_offset); | |
95 } | |
96 | |
97 // Returns a string describing a TestNativeDisplayDelegate::SetHDCPState() call. | 85 // Returns a string describing a TestNativeDisplayDelegate::SetHDCPState() call. |
98 std::string GetSetHDCPStateAction(const DisplaySnapshot& output, | 86 std::string GetSetHDCPStateAction(const DisplaySnapshot& output, |
99 HDCPState state) { | 87 HDCPState state) { |
100 return base::StringPrintf( | 88 return base::StringPrintf( |
101 "set_hdcp(id=%" PRId64 ",state=%d)", output.display_id(), state); | 89 "set_hdcp(id=%" PRId64 ",state=%d)", output.display_id(), state); |
102 } | 90 } |
103 | 91 |
104 // Joins a sequence of strings describing actions (e.g. kScreenDim) such | 92 // Joins a sequence of strings describing actions (e.g. kScreenDim) such |
105 // that they can be compared against a string returned by | 93 // that they can be compared against a string returned by |
106 // ActionLogger::GetActionsAndClear(). The list of actions must be | 94 // ActionLogger::GetActionsAndClear(). The list of actions must be |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 | 135 |
148 class TestTouchscreenDelegate | 136 class TestTouchscreenDelegate |
149 : public DisplayConfigurator::TouchscreenDelegate { | 137 : public DisplayConfigurator::TouchscreenDelegate { |
150 public: | 138 public: |
151 // Ownership of |log| remains with the caller. | 139 // Ownership of |log| remains with the caller. |
152 explicit TestTouchscreenDelegate(ActionLogger* log) | 140 explicit TestTouchscreenDelegate(ActionLogger* log) |
153 : log_(log), | 141 : log_(log), |
154 configure_touchscreens_(false) {} | 142 configure_touchscreens_(false) {} |
155 virtual ~TestTouchscreenDelegate() {} | 143 virtual ~TestTouchscreenDelegate() {} |
156 | 144 |
157 const DisplayConfigurator::CoordinateTransformation& GetCTM( | |
158 int touch_device_id) { | |
159 return ctms_[touch_device_id]; | |
160 } | |
161 | |
162 void set_configure_touchscreens(bool state) { | 145 void set_configure_touchscreens(bool state) { |
163 configure_touchscreens_ = state; | 146 configure_touchscreens_ = state; |
164 } | 147 } |
165 | 148 |
166 // DisplayConfigurator::TouchscreenDelegate implementation: | 149 // DisplayConfigurator::TouchscreenDelegate implementation: |
167 virtual void AssociateTouchscreens( | 150 virtual void AssociateTouchscreens( |
168 DisplayConfigurator::DisplayStateList* outputs) OVERRIDE { | 151 DisplayConfigurator::DisplayStateList* outputs) OVERRIDE { |
169 if (configure_touchscreens_) { | 152 if (configure_touchscreens_) { |
170 for (size_t i = 0; i < outputs->size(); ++i) | 153 for (size_t i = 0; i < outputs->size(); ++i) |
171 (*outputs)[i].touch_device_id = i + 1; | 154 (*outputs)[i].touch_device_id = i + 1; |
172 } | 155 } |
173 } | 156 } |
174 virtual void ConfigureCTM( | |
175 int touch_device_id, | |
176 const DisplayConfigurator::CoordinateTransformation& ctm) OVERRIDE { | |
177 log_->AppendAction(GetCTMAction(touch_device_id, ctm)); | |
178 ctms_[touch_device_id] = ctm; | |
179 } | |
180 | 157 |
181 private: | 158 private: |
182 ActionLogger* log_; // Not owned. | 159 ActionLogger* log_; // Not owned. |
183 | 160 |
184 bool configure_touchscreens_; | 161 bool configure_touchscreens_; |
185 | 162 |
186 // Most-recently-configured transformation matrices, keyed by touch device ID. | |
187 std::map<int, DisplayConfigurator::CoordinateTransformation> ctms_; | |
188 | |
189 DISALLOW_COPY_AND_ASSIGN(TestTouchscreenDelegate); | 163 DISALLOW_COPY_AND_ASSIGN(TestTouchscreenDelegate); |
190 }; | 164 }; |
191 | 165 |
192 class TestNativeDisplayDelegate : public NativeDisplayDelegate { | 166 class TestNativeDisplayDelegate : public NativeDisplayDelegate { |
193 public: | 167 public: |
194 // Ownership of |log| remains with the caller. | 168 // Ownership of |log| remains with the caller. |
195 explicit TestNativeDisplayDelegate(ActionLogger* log) | 169 explicit TestNativeDisplayDelegate(ActionLogger* log) |
196 : max_configurable_pixels_(0), | 170 : max_configurable_pixels_(0), |
197 hdcp_state_(HDCP_STATE_UNDESIRED), | 171 hdcp_state_(HDCP_STATE_UNDESIRED), |
198 log_(log) {} | 172 log_(log) {} |
(...skipping 1036 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1235 EXPECT_TRUE(configurator_.EnableContentProtection( | 1209 EXPECT_TRUE(configurator_.EnableContentProtection( |
1236 client2, outputs_[1].display_id(), CONTENT_PROTECTION_METHOD_NONE)); | 1210 client2, outputs_[1].display_id(), CONTENT_PROTECTION_METHOD_NONE)); |
1237 EXPECT_EQ(GetSetHDCPStateAction(outputs_[1], HDCP_STATE_DESIRED).c_str(), | 1211 EXPECT_EQ(GetSetHDCPStateAction(outputs_[1], HDCP_STATE_DESIRED).c_str(), |
1238 log_->GetActionsAndClear()); | 1212 log_->GetActionsAndClear()); |
1239 EXPECT_TRUE(configurator_.EnableContentProtection( | 1213 EXPECT_TRUE(configurator_.EnableContentProtection( |
1240 client1, outputs_[1].display_id(), CONTENT_PROTECTION_METHOD_NONE)); | 1214 client1, outputs_[1].display_id(), CONTENT_PROTECTION_METHOD_NONE)); |
1241 EXPECT_EQ(GetSetHDCPStateAction(outputs_[1], HDCP_STATE_UNDESIRED).c_str(), | 1215 EXPECT_EQ(GetSetHDCPStateAction(outputs_[1], HDCP_STATE_UNDESIRED).c_str(), |
1242 log_->GetActionsAndClear()); | 1216 log_->GetActionsAndClear()); |
1243 } | 1217 } |
1244 | 1218 |
1245 TEST_F(DisplayConfiguratorTest, CTMForMultiScreens) { | |
1246 touchscreen_delegate_->set_configure_touchscreens(true); | |
1247 UpdateOutputs(2, false); | |
1248 configurator_.Init(false); | |
1249 state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED); | |
1250 configurator_.ForceInitialConfigure(0); | |
1251 | |
1252 const int kDualHeight = small_mode_.size().height() + | |
1253 DisplayConfigurator::kVerticalGap + | |
1254 big_mode_.size().height(); | |
1255 const int kDualWidth = big_mode_.size().width(); | |
1256 | |
1257 DisplayConfigurator::CoordinateTransformation ctm1 = | |
1258 touchscreen_delegate_->GetCTM(1); | |
1259 DisplayConfigurator::CoordinateTransformation ctm2 = | |
1260 touchscreen_delegate_->GetCTM(2); | |
1261 | |
1262 EXPECT_EQ(small_mode_.size().height() - 1, | |
1263 round((kDualHeight - 1) * ctm1.y_scale)); | |
1264 EXPECT_EQ(0, round((kDualHeight - 1) * ctm1.y_offset)); | |
1265 | |
1266 EXPECT_EQ(big_mode_.size().height() - 1, | |
1267 round((kDualHeight - 1) * ctm2.y_scale)); | |
1268 EXPECT_EQ(small_mode_.size().height() + DisplayConfigurator::kVerticalGap, | |
1269 round((kDualHeight - 1) * ctm2.y_offset)); | |
1270 | |
1271 EXPECT_EQ(small_mode_.size().width() - 1, | |
1272 round((kDualWidth - 1) * ctm1.x_scale)); | |
1273 EXPECT_EQ(0, round((kDualWidth - 1) * ctm1.x_offset)); | |
1274 | |
1275 EXPECT_EQ(big_mode_.size().width() - 1, | |
1276 round((kDualWidth - 1) * ctm2.x_scale)); | |
1277 EXPECT_EQ(0, round((kDualWidth - 1) * ctm2.x_offset)); | |
1278 } | |
1279 | |
1280 TEST_F(DisplayConfiguratorTest, HandleConfigureCrtcFailure) { | 1219 TEST_F(DisplayConfiguratorTest, HandleConfigureCrtcFailure) { |
1281 InitWithSingleOutput(); | 1220 InitWithSingleOutput(); |
1282 | 1221 |
1283 ScopedVector<const DisplayMode> modes; | 1222 ScopedVector<const DisplayMode> modes; |
1284 // The first mode is the mode we are requesting DisplayConfigurator to choose. | 1223 // The first mode is the mode we are requesting DisplayConfigurator to choose. |
1285 // The test will be setup so that this mode will fail and it will have to | 1224 // The test will be setup so that this mode will fail and it will have to |
1286 // choose the next best option. | 1225 // choose the next best option. |
1287 modes.push_back(new DisplayMode(gfx::Size(2560, 1600), false, 60.0)); | 1226 modes.push_back(new DisplayMode(gfx::Size(2560, 1600), false, 60.0)); |
1288 modes.push_back(new DisplayMode(gfx::Size(1024, 768), false, 60.0)); | 1227 modes.push_back(new DisplayMode(gfx::Size(1024, 768), false, 60.0)); |
1289 modes.push_back(new DisplayMode(gfx::Size(1280, 720), false, 60.0)); | 1228 modes.push_back(new DisplayMode(gfx::Size(1280, 720), false, 60.0)); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1359 gfx::Point(0, | 1298 gfx::Point(0, |
1360 modes[0]->size().height() + | 1299 modes[0]->size().height() + |
1361 DisplayConfigurator::kVerticalGap)) | 1300 DisplayConfigurator::kVerticalGap)) |
1362 .c_str(), | 1301 .c_str(), |
1363 kUngrab, | 1302 kUngrab, |
1364 NULL), | 1303 NULL), |
1365 log_->GetActionsAndClear()); | 1304 log_->GetActionsAndClear()); |
1366 } | 1305 } |
1367 | 1306 |
1368 } // namespace ui | 1307 } // namespace ui |
OLD | NEW |