| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 | 135 class TestNativeDisplayDelegate |
| 158 : public OutputConfigurator::NativeDisplayDelegate { | 136 : public OutputConfigurator::NativeDisplayDelegate { |
| 159 public: | 137 public: |
| 160 static const int kXRandREventBase = 10; | 138 static const int kXRandREventBase = 10; |
| 161 | 139 |
| 162 // Ownership of |log| remains with the caller. | 140 // Ownership of |log| remains with the caller. |
| 163 explicit TestNativeDisplayDelegate(ActionLogger* log) | 141 explicit TestNativeDisplayDelegate(ActionLogger* log) |
| (...skipping 1266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1430 EXPECT_EQ( | 1408 EXPECT_EQ( |
| 1431 GetSetHDCPStateAction(outputs_[1].output, ui::HDCP_STATE_DESIRED).c_str(), | 1409 GetSetHDCPStateAction(outputs_[1].output, ui::HDCP_STATE_DESIRED).c_str(), |
| 1432 log_->GetActionsAndClear()); | 1410 log_->GetActionsAndClear()); |
| 1433 EXPECT_TRUE(configurator_.EnableOutputProtection( | 1411 EXPECT_TRUE(configurator_.EnableOutputProtection( |
| 1434 client1, outputs_[1].display_id, ui::OUTPUT_PROTECTION_METHOD_NONE)); | 1412 client1, outputs_[1].display_id, ui::OUTPUT_PROTECTION_METHOD_NONE)); |
| 1435 EXPECT_EQ(GetSetHDCPStateAction(outputs_[1].output, ui::HDCP_STATE_UNDESIRED) | 1413 EXPECT_EQ(GetSetHDCPStateAction(outputs_[1].output, ui::HDCP_STATE_UNDESIRED) |
| 1436 .c_str(), | 1414 .c_str(), |
| 1437 log_->GetActionsAndClear()); | 1415 log_->GetActionsAndClear()); |
| 1438 } | 1416 } |
| 1439 | 1417 |
| 1440 TEST_F(OutputConfiguratorTest, CTMForMultiScreens) { | |
| 1441 outputs_[0].touch_device_id = 1; | |
| 1442 outputs_[1].touch_device_id = 2; | |
| 1443 | |
| 1444 UpdateOutputs(2, false); | |
| 1445 configurator_.Init(false); | |
| 1446 state_controller_.set_state(ui::OUTPUT_STATE_DUAL_EXTENDED); | |
| 1447 configurator_.Start(0); | |
| 1448 | |
| 1449 const int kDualHeight = | |
| 1450 kSmallModeHeight + OutputConfigurator::kVerticalGap + kBigModeHeight; | |
| 1451 const int kDualWidth = kBigModeWidth; | |
| 1452 | |
| 1453 OutputConfigurator::CoordinateTransformation ctm1 = | |
| 1454 touchscreen_delegate_->GetCTM(1); | |
| 1455 OutputConfigurator::CoordinateTransformation ctm2 = | |
| 1456 touchscreen_delegate_->GetCTM(2); | |
| 1457 | |
| 1458 EXPECT_EQ(kSmallModeHeight - 1, round((kDualHeight - 1) * ctm1.y_scale)); | |
| 1459 EXPECT_EQ(0, round((kDualHeight - 1) * ctm1.y_offset)); | |
| 1460 | |
| 1461 EXPECT_EQ(kBigModeHeight - 1, round((kDualHeight - 1) * ctm2.y_scale)); | |
| 1462 EXPECT_EQ(kSmallModeHeight + OutputConfigurator::kVerticalGap, | |
| 1463 round((kDualHeight - 1) * ctm2.y_offset)); | |
| 1464 | |
| 1465 EXPECT_EQ(kSmallModeWidth - 1, round((kDualWidth - 1) * ctm1.x_scale)); | |
| 1466 EXPECT_EQ(0, round((kDualWidth - 1) * ctm1.x_offset)); | |
| 1467 | |
| 1468 EXPECT_EQ(kBigModeWidth - 1, round((kDualWidth - 1) * ctm2.x_scale)); | |
| 1469 EXPECT_EQ(0, round((kDualWidth - 1) * ctm2.x_offset)); | |
| 1470 } | |
| 1471 | |
| 1472 TEST_F(OutputConfiguratorTest, HandleConfigureCrtcFailure) { | 1418 TEST_F(OutputConfiguratorTest, HandleConfigureCrtcFailure) { |
| 1473 InitWithSingleOutput(); | 1419 InitWithSingleOutput(); |
| 1474 | 1420 |
| 1475 // kFirstMode represents the first mode in the list and | 1421 // kFirstMode represents the first mode in the list and |
| 1476 // also the mode that we are requesting the output_configurator | 1422 // also the mode that we are requesting the output_configurator |
| 1477 // to choose. The test will be setup so that this mode will fail | 1423 // to choose. The test will be setup so that this mode will fail |
| 1478 // and it will have to choose the next best option. | 1424 // and it will have to choose the next best option. |
| 1479 const int kFirstMode = 11; | 1425 const int kFirstMode = 11; |
| 1480 | 1426 |
| 1481 // Give the mode_info lists a few reasonable modes. | 1427 // Give the mode_info lists a few reasonable modes. |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1581 outputs_[1].mode_infos[kFirstMode].height + | 1527 outputs_[1].mode_infos[kFirstMode].height + |
| 1582 OutputConfigurator::kVerticalGap, | 1528 OutputConfigurator::kVerticalGap, |
| 1583 kFirstMode + 3, | 1529 kFirstMode + 3, |
| 1584 outputs_[1].output).c_str(), | 1530 outputs_[1].output).c_str(), |
| 1585 kUngrab, | 1531 kUngrab, |
| 1586 NULL), | 1532 NULL), |
| 1587 log_->GetActionsAndClear()); | 1533 log_->GetActionsAndClear()); |
| 1588 } | 1534 } |
| 1589 | 1535 |
| 1590 } // namespace chromeos | 1536 } // namespace chromeos |
| OLD | NEW |