| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "testing/gtest/include/gtest/gtest.h" | |
| 6 #include "ui/ozone/platform/dri/dri_buffer.h" | |
| 7 #include "ui/ozone/platform/dri/hardware_display_controller.h" | |
| 8 #include "ui/ozone/platform/dri/screen_manager.h" | |
| 9 #include "ui/ozone/platform/dri/test/mock_dri_wrapper.h" | |
| 10 | |
| 11 namespace { | |
| 12 | |
| 13 // Create a basic mode for a 6x4 screen. | |
| 14 const drmModeModeInfo kDefaultMode = | |
| 15 {0, 6, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, {'\0'}}; | |
| 16 | |
| 17 const uint32_t kPrimaryCrtc = 1; | |
| 18 const uint32_t kPrimaryConnector = 2; | |
| 19 const uint32_t kSecondaryCrtc = 3; | |
| 20 const uint32_t kSecondaryConnector = 4; | |
| 21 | |
| 22 class MockScreenManager : public ui::ScreenManager { | |
| 23 public: | |
| 24 MockScreenManager(ui::DriWrapper* dri, | |
| 25 ui::ScanoutBufferGenerator* buffer_generator) | |
| 26 : ScreenManager(dri, buffer_generator), dri_(dri) {} | |
| 27 | |
| 28 virtual void ForceInitializationOfPrimaryDisplay() override {} | |
| 29 | |
| 30 private: | |
| 31 ui::DriWrapper* dri_; | |
| 32 | |
| 33 DISALLOW_COPY_AND_ASSIGN(MockScreenManager); | |
| 34 }; | |
| 35 | |
| 36 } // namespace | |
| 37 | |
| 38 class ScreenManagerTest : public testing::Test { | |
| 39 public: | |
| 40 ScreenManagerTest() {} | |
| 41 virtual ~ScreenManagerTest() {} | |
| 42 | |
| 43 gfx::Rect GetPrimaryBounds() const { | |
| 44 return gfx::Rect(0, 0, kDefaultMode.hdisplay, kDefaultMode.vdisplay); | |
| 45 } | |
| 46 | |
| 47 // Secondary is in extended mode, right-of primary. | |
| 48 gfx::Rect GetSecondaryBounds() const { | |
| 49 return gfx::Rect( | |
| 50 kDefaultMode.hdisplay, 0, kDefaultMode.hdisplay, kDefaultMode.vdisplay); | |
| 51 } | |
| 52 | |
| 53 virtual void SetUp() override { | |
| 54 dri_.reset(new ui::MockDriWrapper(3)); | |
| 55 buffer_generator_.reset(new ui::DriBufferGenerator(dri_.get())); | |
| 56 screen_manager_.reset(new MockScreenManager( | |
| 57 dri_.get(), buffer_generator_.get())); | |
| 58 } | |
| 59 virtual void TearDown() override { | |
| 60 screen_manager_.reset(); | |
| 61 dri_.reset(); | |
| 62 } | |
| 63 | |
| 64 protected: | |
| 65 scoped_ptr<ui::MockDriWrapper> dri_; | |
| 66 scoped_ptr<ui::DriBufferGenerator> buffer_generator_; | |
| 67 scoped_ptr<MockScreenManager> screen_manager_; | |
| 68 | |
| 69 private: | |
| 70 DISALLOW_COPY_AND_ASSIGN(ScreenManagerTest); | |
| 71 }; | |
| 72 | |
| 73 TEST_F(ScreenManagerTest, CheckWithNoControllers) { | |
| 74 EXPECT_FALSE(screen_manager_->GetDisplayController(GetPrimaryBounds())); | |
| 75 } | |
| 76 | |
| 77 TEST_F(ScreenManagerTest, CheckWithValidController) { | |
| 78 screen_manager_->AddDisplayController( | |
| 79 dri_.get(), kPrimaryCrtc, kPrimaryConnector); | |
| 80 screen_manager_->ConfigureDisplayController(kPrimaryCrtc, | |
| 81 kPrimaryConnector, | |
| 82 GetPrimaryBounds().origin(), | |
| 83 kDefaultMode); | |
| 84 base::WeakPtr<ui::HardwareDisplayController> controller = | |
| 85 screen_manager_->GetDisplayController(GetPrimaryBounds()); | |
| 86 | |
| 87 EXPECT_TRUE(controller); | |
| 88 EXPECT_TRUE(controller->HasCrtc(kPrimaryCrtc)); | |
| 89 } | |
| 90 | |
| 91 TEST_F(ScreenManagerTest, CheckWithInvalidBounds) { | |
| 92 screen_manager_->AddDisplayController( | |
| 93 dri_.get(), kPrimaryCrtc, kPrimaryConnector); | |
| 94 screen_manager_->ConfigureDisplayController(kPrimaryCrtc, | |
| 95 kPrimaryConnector, | |
| 96 GetPrimaryBounds().origin(), | |
| 97 kDefaultMode); | |
| 98 | |
| 99 EXPECT_TRUE(screen_manager_->GetDisplayController(GetPrimaryBounds())); | |
| 100 EXPECT_FALSE(screen_manager_->GetDisplayController(GetSecondaryBounds())); | |
| 101 } | |
| 102 | |
| 103 TEST_F(ScreenManagerTest, CheckForSecondValidController) { | |
| 104 screen_manager_->AddDisplayController( | |
| 105 dri_.get(), kPrimaryCrtc, kPrimaryConnector); | |
| 106 screen_manager_->ConfigureDisplayController(kPrimaryCrtc, | |
| 107 kPrimaryConnector, | |
| 108 GetPrimaryBounds().origin(), | |
| 109 kDefaultMode); | |
| 110 screen_manager_->AddDisplayController( | |
| 111 dri_.get(), kSecondaryCrtc, kSecondaryConnector); | |
| 112 screen_manager_->ConfigureDisplayController(kSecondaryCrtc, | |
| 113 kSecondaryConnector, | |
| 114 GetSecondaryBounds().origin(), | |
| 115 kDefaultMode); | |
| 116 | |
| 117 EXPECT_TRUE(screen_manager_->GetDisplayController(GetPrimaryBounds())); | |
| 118 EXPECT_TRUE(screen_manager_->GetDisplayController(GetSecondaryBounds())); | |
| 119 } | |
| 120 | |
| 121 TEST_F(ScreenManagerTest, CheckControllerAfterItIsRemoved) { | |
| 122 screen_manager_->AddDisplayController( | |
| 123 dri_.get(), kPrimaryCrtc, kPrimaryConnector); | |
| 124 screen_manager_->ConfigureDisplayController(kPrimaryCrtc, | |
| 125 kPrimaryConnector, | |
| 126 GetPrimaryBounds().origin(), | |
| 127 kDefaultMode); | |
| 128 base::WeakPtr<ui::HardwareDisplayController> controller = | |
| 129 screen_manager_->GetDisplayController(GetPrimaryBounds()); | |
| 130 | |
| 131 EXPECT_TRUE(controller); | |
| 132 screen_manager_->RemoveDisplayController(kPrimaryCrtc); | |
| 133 EXPECT_FALSE(controller); | |
| 134 } | |
| 135 | |
| 136 TEST_F(ScreenManagerTest, CheckDuplicateConfiguration) { | |
| 137 screen_manager_->AddDisplayController( | |
| 138 dri_.get(), kPrimaryCrtc, kPrimaryConnector); | |
| 139 screen_manager_->ConfigureDisplayController(kPrimaryCrtc, | |
| 140 kPrimaryConnector, | |
| 141 GetPrimaryBounds().origin(), | |
| 142 kDefaultMode); | |
| 143 screen_manager_->ConfigureDisplayController(kPrimaryCrtc, | |
| 144 kPrimaryConnector, | |
| 145 GetPrimaryBounds().origin(), | |
| 146 kDefaultMode); | |
| 147 | |
| 148 EXPECT_TRUE(screen_manager_->GetDisplayController(GetPrimaryBounds())); | |
| 149 EXPECT_FALSE(screen_manager_->GetDisplayController(GetSecondaryBounds())); | |
| 150 } | |
| 151 | |
| 152 TEST_F(ScreenManagerTest, CheckChangingMode) { | |
| 153 screen_manager_->AddDisplayController( | |
| 154 dri_.get(), kPrimaryCrtc, kPrimaryConnector); | |
| 155 screen_manager_->ConfigureDisplayController(kPrimaryCrtc, | |
| 156 kPrimaryConnector, | |
| 157 GetPrimaryBounds().origin(), | |
| 158 kDefaultMode); | |
| 159 drmModeModeInfo new_mode = kDefaultMode; | |
| 160 new_mode.vdisplay = 10; | |
| 161 screen_manager_->ConfigureDisplayController( | |
| 162 kPrimaryCrtc, kPrimaryConnector, GetPrimaryBounds().origin(), new_mode); | |
| 163 | |
| 164 gfx::Rect new_bounds(0, 0, new_mode.hdisplay, new_mode.vdisplay); | |
| 165 EXPECT_TRUE(screen_manager_->GetDisplayController(new_bounds)); | |
| 166 EXPECT_FALSE(screen_manager_->GetDisplayController(GetSecondaryBounds())); | |
| 167 drmModeModeInfo mode = | |
| 168 screen_manager_->GetDisplayController(new_bounds)->get_mode(); | |
| 169 EXPECT_EQ(new_mode.vdisplay, mode.vdisplay); | |
| 170 EXPECT_EQ(new_mode.hdisplay, mode.hdisplay); | |
| 171 } | |
| 172 | |
| 173 TEST_F(ScreenManagerTest, CheckForControllersInMirroredMode) { | |
| 174 screen_manager_->AddDisplayController( | |
| 175 dri_.get(), kPrimaryCrtc, kPrimaryConnector); | |
| 176 screen_manager_->ConfigureDisplayController(kPrimaryCrtc, | |
| 177 kPrimaryConnector, | |
| 178 GetPrimaryBounds().origin(), | |
| 179 kDefaultMode); | |
| 180 screen_manager_->AddDisplayController( | |
| 181 dri_.get(), kSecondaryCrtc, kSecondaryConnector); | |
| 182 screen_manager_->ConfigureDisplayController(kSecondaryCrtc, | |
| 183 kSecondaryConnector, | |
| 184 GetPrimaryBounds().origin(), | |
| 185 kDefaultMode); | |
| 186 | |
| 187 EXPECT_TRUE(screen_manager_->GetDisplayController(GetPrimaryBounds())); | |
| 188 EXPECT_FALSE(screen_manager_->GetDisplayController(GetSecondaryBounds())); | |
| 189 } | |
| 190 | |
| 191 TEST_F(ScreenManagerTest, CheckMirrorModeTransitions) { | |
| 192 screen_manager_->AddDisplayController( | |
| 193 dri_.get(), kPrimaryCrtc, kPrimaryConnector); | |
| 194 screen_manager_->ConfigureDisplayController(kPrimaryCrtc, | |
| 195 kPrimaryConnector, | |
| 196 GetPrimaryBounds().origin(), | |
| 197 kDefaultMode); | |
| 198 screen_manager_->AddDisplayController( | |
| 199 dri_.get(), kSecondaryCrtc, kSecondaryConnector); | |
| 200 screen_manager_->ConfigureDisplayController(kSecondaryCrtc, | |
| 201 kSecondaryConnector, | |
| 202 GetSecondaryBounds().origin(), | |
| 203 kDefaultMode); | |
| 204 | |
| 205 EXPECT_TRUE(screen_manager_->GetDisplayController(GetPrimaryBounds())); | |
| 206 EXPECT_TRUE(screen_manager_->GetDisplayController(GetSecondaryBounds())); | |
| 207 | |
| 208 screen_manager_->ConfigureDisplayController(kPrimaryCrtc, | |
| 209 kPrimaryConnector, | |
| 210 GetPrimaryBounds().origin(), | |
| 211 kDefaultMode); | |
| 212 screen_manager_->ConfigureDisplayController(kSecondaryCrtc, | |
| 213 kSecondaryConnector, | |
| 214 GetPrimaryBounds().origin(), | |
| 215 kDefaultMode); | |
| 216 EXPECT_TRUE(screen_manager_->GetDisplayController(GetPrimaryBounds())); | |
| 217 EXPECT_FALSE(screen_manager_->GetDisplayController(GetSecondaryBounds())); | |
| 218 | |
| 219 screen_manager_->ConfigureDisplayController(kPrimaryCrtc, | |
| 220 kPrimaryConnector, | |
| 221 GetSecondaryBounds().origin(), | |
| 222 kDefaultMode); | |
| 223 screen_manager_->ConfigureDisplayController(kSecondaryCrtc, | |
| 224 kSecondaryConnector, | |
| 225 GetPrimaryBounds().origin(), | |
| 226 kDefaultMode); | |
| 227 EXPECT_TRUE(screen_manager_->GetDisplayController(GetPrimaryBounds())); | |
| 228 EXPECT_TRUE(screen_manager_->GetDisplayController(GetSecondaryBounds())); | |
| 229 } | |
| 230 | |
| 231 TEST_F(ScreenManagerTest, MonitorGoneInMirrorMode) { | |
| 232 screen_manager_->AddDisplayController( | |
| 233 dri_.get(), kPrimaryCrtc, kPrimaryConnector); | |
| 234 screen_manager_->ConfigureDisplayController(kPrimaryCrtc, | |
| 235 kPrimaryConnector, | |
| 236 GetPrimaryBounds().origin(), | |
| 237 kDefaultMode); | |
| 238 screen_manager_->AddDisplayController( | |
| 239 dri_.get(), kSecondaryCrtc, kSecondaryConnector); | |
| 240 screen_manager_->ConfigureDisplayController(kSecondaryCrtc, | |
| 241 kSecondaryConnector, | |
| 242 GetPrimaryBounds().origin(), | |
| 243 kDefaultMode); | |
| 244 | |
| 245 screen_manager_->RemoveDisplayController(kSecondaryCrtc); | |
| 246 EXPECT_TRUE( | |
| 247 screen_manager_->ConfigureDisplayController(kPrimaryCrtc, | |
| 248 kPrimaryConnector, | |
| 249 GetPrimaryBounds().origin(), | |
| 250 kDefaultMode)); | |
| 251 EXPECT_TRUE(screen_manager_->GetDisplayController(GetPrimaryBounds())); | |
| 252 EXPECT_FALSE(screen_manager_->GetDisplayController(GetSecondaryBounds())); | |
| 253 } | |
| OLD | NEW |