| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 public: | 38 public: |
| 39 HardwareDisplayControllerTest() : page_flips_(0) {} | 39 HardwareDisplayControllerTest() : page_flips_(0) {} |
| 40 ~HardwareDisplayControllerTest() override {} | 40 ~HardwareDisplayControllerTest() override {} |
| 41 | 41 |
| 42 void SetUp() override; | 42 void SetUp() override; |
| 43 void TearDown() override; | 43 void TearDown() override; |
| 44 | 44 |
| 45 void PageFlipCallback(gfx::SwapResult); | 45 void PageFlipCallback(gfx::SwapResult); |
| 46 | 46 |
| 47 protected: | 47 protected: |
| 48 scoped_ptr<ui::HardwareDisplayController> controller_; | 48 std::unique_ptr<ui::HardwareDisplayController> controller_; |
| 49 scoped_refptr<ui::MockDrmDevice> drm_; | 49 scoped_refptr<ui::MockDrmDevice> drm_; |
| 50 | 50 |
| 51 int page_flips_; | 51 int page_flips_; |
| 52 gfx::SwapResult last_swap_result_; | 52 gfx::SwapResult last_swap_result_; |
| 53 | 53 |
| 54 private: | 54 private: |
| 55 DISALLOW_COPY_AND_ASSIGN(HardwareDisplayControllerTest); | 55 DISALLOW_COPY_AND_ASSIGN(HardwareDisplayControllerTest); |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 void HardwareDisplayControllerTest::SetUp() { | 58 void HardwareDisplayControllerTest::SetUp() { |
| 59 page_flips_ = 0; | 59 page_flips_ = 0; |
| 60 last_swap_result_ = gfx::SwapResult::SWAP_FAILED; | 60 last_swap_result_ = gfx::SwapResult::SWAP_FAILED; |
| 61 | 61 |
| 62 std::vector<uint32_t> crtcs; | 62 std::vector<uint32_t> crtcs; |
| 63 crtcs.push_back(kPrimaryCrtc); | 63 crtcs.push_back(kPrimaryCrtc); |
| 64 crtcs.push_back(kSecondaryCrtc); | 64 crtcs.push_back(kSecondaryCrtc); |
| 65 drm_ = new ui::MockDrmDevice(false, crtcs, kPlanesPerCrtc); | 65 drm_ = new ui::MockDrmDevice(false, crtcs, kPlanesPerCrtc); |
| 66 controller_.reset(new ui::HardwareDisplayController( | 66 controller_.reset(new ui::HardwareDisplayController( |
| 67 scoped_ptr<ui::CrtcController>( | 67 std::unique_ptr<ui::CrtcController>( |
| 68 new ui::CrtcController(drm_.get(), kPrimaryCrtc, kPrimaryConnector)), | 68 new ui::CrtcController(drm_.get(), kPrimaryCrtc, kPrimaryConnector)), |
| 69 gfx::Point())); | 69 gfx::Point())); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void HardwareDisplayControllerTest::TearDown() { | 72 void HardwareDisplayControllerTest::TearDown() { |
| 73 controller_.reset(); | 73 controller_.reset(); |
| 74 drm_ = nullptr; | 74 drm_ = nullptr; |
| 75 } | 75 } |
| 76 | 76 |
| 77 void HardwareDisplayControllerTest::PageFlipCallback(gfx::SwapResult result) { | 77 void HardwareDisplayControllerTest::PageFlipCallback(gfx::SwapResult result) { |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 planes.push_back(plane2); | 245 planes.push_back(plane2); |
| 246 | 246 |
| 247 controller_->SchedulePageFlip( | 247 controller_->SchedulePageFlip( |
| 248 planes, base::Bind(&HardwareDisplayControllerTest::PageFlipCallback, | 248 planes, base::Bind(&HardwareDisplayControllerTest::PageFlipCallback, |
| 249 base::Unretained(this))); | 249 base::Unretained(this))); |
| 250 EXPECT_EQ(gfx::SwapResult::SWAP_FAILED, last_swap_result_); | 250 EXPECT_EQ(gfx::SwapResult::SWAP_FAILED, last_swap_result_); |
| 251 EXPECT_EQ(1, page_flips_); | 251 EXPECT_EQ(1, page_flips_); |
| 252 } | 252 } |
| 253 | 253 |
| 254 TEST_F(HardwareDisplayControllerTest, PageflipMirroredControllers) { | 254 TEST_F(HardwareDisplayControllerTest, PageflipMirroredControllers) { |
| 255 controller_->AddCrtc(scoped_ptr<ui::CrtcController>( | 255 controller_->AddCrtc(std::unique_ptr<ui::CrtcController>( |
| 256 new ui::CrtcController(drm_.get(), kSecondaryCrtc, kSecondaryConnector))); | 256 new ui::CrtcController(drm_.get(), kSecondaryCrtc, kSecondaryConnector))); |
| 257 | 257 |
| 258 ui::OverlayPlane plane1(scoped_refptr<ui::ScanoutBuffer>( | 258 ui::OverlayPlane plane1(scoped_refptr<ui::ScanoutBuffer>( |
| 259 new ui::MockScanoutBuffer(kDefaultModeSize))); | 259 new ui::MockScanoutBuffer(kDefaultModeSize))); |
| 260 EXPECT_TRUE(controller_->Modeset(plane1, kDefaultMode)); | 260 EXPECT_TRUE(controller_->Modeset(plane1, kDefaultMode)); |
| 261 EXPECT_EQ(2, drm_->get_set_crtc_call_count()); | 261 EXPECT_EQ(2, drm_->get_set_crtc_call_count()); |
| 262 | 262 |
| 263 ui::OverlayPlane plane2(scoped_refptr<ui::ScanoutBuffer>( | 263 ui::OverlayPlane plane2(scoped_refptr<ui::ScanoutBuffer>( |
| 264 new ui::MockScanoutBuffer(kDefaultModeSize))); | 264 new ui::MockScanoutBuffer(kDefaultModeSize))); |
| 265 std::vector<ui::OverlayPlane> planes = | 265 std::vector<ui::OverlayPlane> planes = |
| (...skipping 24 matching lines...) Expand all Loading... |
| 290 const ui::HardwareDisplayPlane* owned_plane = nullptr; | 290 const ui::HardwareDisplayPlane* owned_plane = nullptr; |
| 291 for (const auto& plane : drm_->plane_manager()->planes()) { | 291 for (const auto& plane : drm_->plane_manager()->planes()) { |
| 292 if (plane->in_use()) | 292 if (plane->in_use()) |
| 293 owned_plane = plane.get(); | 293 owned_plane = plane.get(); |
| 294 } | 294 } |
| 295 | 295 |
| 296 ASSERT_TRUE(owned_plane != nullptr); | 296 ASSERT_TRUE(owned_plane != nullptr); |
| 297 EXPECT_EQ(kPrimaryCrtc, owned_plane->owning_crtc()); | 297 EXPECT_EQ(kPrimaryCrtc, owned_plane->owning_crtc()); |
| 298 | 298 |
| 299 // Removing the crtc should not free the plane or change ownership. | 299 // Removing the crtc should not free the plane or change ownership. |
| 300 scoped_ptr<ui::CrtcController> crtc = | 300 std::unique_ptr<ui::CrtcController> crtc = |
| 301 controller_->RemoveCrtc(drm_, kPrimaryCrtc); | 301 controller_->RemoveCrtc(drm_, kPrimaryCrtc); |
| 302 EXPECT_TRUE(owned_plane->in_use()); | 302 EXPECT_TRUE(owned_plane->in_use()); |
| 303 EXPECT_EQ(kPrimaryCrtc, owned_plane->owning_crtc()); | 303 EXPECT_EQ(kPrimaryCrtc, owned_plane->owning_crtc()); |
| 304 // Check that controller doesn't affect the state of removed plane in | 304 // Check that controller doesn't affect the state of removed plane in |
| 305 // subsequent page flip. | 305 // subsequent page flip. |
| 306 controller_->SchedulePageFlip( | 306 controller_->SchedulePageFlip( |
| 307 planes, base::Bind(&HardwareDisplayControllerTest::PageFlipCallback, | 307 planes, base::Bind(&HardwareDisplayControllerTest::PageFlipCallback, |
| 308 base::Unretained(this))); | 308 base::Unretained(this))); |
| 309 drm_->RunCallbacks(); | 309 drm_->RunCallbacks(); |
| 310 EXPECT_EQ(gfx::SwapResult::SWAP_ACK, last_swap_result_); | 310 EXPECT_EQ(gfx::SwapResult::SWAP_ACK, last_swap_result_); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 325 drm_->RunCallbacks(); | 325 drm_->RunCallbacks(); |
| 326 EXPECT_EQ(gfx::SwapResult::SWAP_ACK, last_swap_result_); | 326 EXPECT_EQ(gfx::SwapResult::SWAP_ACK, last_swap_result_); |
| 327 EXPECT_EQ(1, page_flips_); | 327 EXPECT_EQ(1, page_flips_); |
| 328 | 328 |
| 329 const ui::HardwareDisplayPlane* owned_plane = nullptr; | 329 const ui::HardwareDisplayPlane* owned_plane = nullptr; |
| 330 for (const auto& plane : drm_->plane_manager()->planes()) | 330 for (const auto& plane : drm_->plane_manager()->planes()) |
| 331 if (plane->in_use()) | 331 if (plane->in_use()) |
| 332 owned_plane = plane.get(); | 332 owned_plane = plane.get(); |
| 333 ASSERT_TRUE(owned_plane != nullptr); | 333 ASSERT_TRUE(owned_plane != nullptr); |
| 334 EXPECT_EQ(kPrimaryCrtc, owned_plane->owning_crtc()); | 334 EXPECT_EQ(kPrimaryCrtc, owned_plane->owning_crtc()); |
| 335 scoped_ptr<ui::CrtcController> crtc = | 335 std::unique_ptr<ui::CrtcController> crtc = |
| 336 controller_->RemoveCrtc(drm_, kPrimaryCrtc); | 336 controller_->RemoveCrtc(drm_, kPrimaryCrtc); |
| 337 // Destroying crtc should free the plane. | 337 // Destroying crtc should free the plane. |
| 338 crtc.reset(); | 338 crtc.reset(); |
| 339 uint32_t crtc_nullid = 0; | 339 uint32_t crtc_nullid = 0; |
| 340 EXPECT_FALSE(owned_plane->in_use()); | 340 EXPECT_FALSE(owned_plane->in_use()); |
| 341 EXPECT_EQ(crtc_nullid, owned_plane->owning_crtc()); | 341 EXPECT_EQ(crtc_nullid, owned_plane->owning_crtc()); |
| 342 } | 342 } |
| 343 | 343 |
| 344 TEST_F(HardwareDisplayControllerTest, PlaneStateAfterAddCrtc) { | 344 TEST_F(HardwareDisplayControllerTest, PlaneStateAfterAddCrtc) { |
| 345 controller_->AddCrtc(scoped_ptr<ui::CrtcController>( | 345 controller_->AddCrtc(std::unique_ptr<ui::CrtcController>( |
| 346 new ui::CrtcController(drm_.get(), kSecondaryCrtc, kSecondaryConnector))); | 346 new ui::CrtcController(drm_.get(), kSecondaryCrtc, kSecondaryConnector))); |
| 347 | 347 |
| 348 ui::OverlayPlane plane1(scoped_refptr<ui::ScanoutBuffer>( | 348 ui::OverlayPlane plane1(scoped_refptr<ui::ScanoutBuffer>( |
| 349 new ui::MockScanoutBuffer(kDefaultModeSize))); | 349 new ui::MockScanoutBuffer(kDefaultModeSize))); |
| 350 EXPECT_TRUE(controller_->Modeset(plane1, kDefaultMode)); | 350 EXPECT_TRUE(controller_->Modeset(plane1, kDefaultMode)); |
| 351 std::vector<ui::OverlayPlane> planes = | 351 std::vector<ui::OverlayPlane> planes = |
| 352 std::vector<ui::OverlayPlane>(1, plane1); | 352 std::vector<ui::OverlayPlane>(1, plane1); |
| 353 controller_->SchedulePageFlip( | 353 controller_->SchedulePageFlip( |
| 354 planes, base::Bind(&HardwareDisplayControllerTest::PageFlipCallback, | 354 planes, base::Bind(&HardwareDisplayControllerTest::PageFlipCallback, |
| 355 base::Unretained(this))); | 355 base::Unretained(this))); |
| 356 drm_->RunCallbacks(); | 356 drm_->RunCallbacks(); |
| 357 EXPECT_EQ(gfx::SwapResult::SWAP_ACK, last_swap_result_); | 357 EXPECT_EQ(gfx::SwapResult::SWAP_ACK, last_swap_result_); |
| 358 EXPECT_EQ(1, page_flips_); | 358 EXPECT_EQ(1, page_flips_); |
| 359 | 359 |
| 360 ui::HardwareDisplayPlane* primary_crtc_plane = nullptr; | 360 ui::HardwareDisplayPlane* primary_crtc_plane = nullptr; |
| 361 for (const auto& plane : drm_->plane_manager()->planes()) { | 361 for (const auto& plane : drm_->plane_manager()->planes()) { |
| 362 if (plane->in_use() && kPrimaryCrtc == plane->owning_crtc()) | 362 if (plane->in_use() && kPrimaryCrtc == plane->owning_crtc()) |
| 363 primary_crtc_plane = plane.get(); | 363 primary_crtc_plane = plane.get(); |
| 364 } | 364 } |
| 365 | 365 |
| 366 ASSERT_TRUE(primary_crtc_plane != nullptr); | 366 ASSERT_TRUE(primary_crtc_plane != nullptr); |
| 367 | 367 |
| 368 scoped_ptr<ui::HardwareDisplayController> hdc_controller; | 368 std::unique_ptr<ui::HardwareDisplayController> hdc_controller; |
| 369 hdc_controller.reset(new ui::HardwareDisplayController( | 369 hdc_controller.reset(new ui::HardwareDisplayController( |
| 370 controller_->RemoveCrtc(drm_, kPrimaryCrtc), controller_->origin())); | 370 controller_->RemoveCrtc(drm_, kPrimaryCrtc), controller_->origin())); |
| 371 controller_->SchedulePageFlip( | 371 controller_->SchedulePageFlip( |
| 372 planes, base::Bind(&HardwareDisplayControllerTest::PageFlipCallback, | 372 planes, base::Bind(&HardwareDisplayControllerTest::PageFlipCallback, |
| 373 base::Unretained(this))); | 373 base::Unretained(this))); |
| 374 drm_->RunCallbacks(); | 374 drm_->RunCallbacks(); |
| 375 EXPECT_EQ(gfx::SwapResult::SWAP_ACK, last_swap_result_); | 375 EXPECT_EQ(gfx::SwapResult::SWAP_ACK, last_swap_result_); |
| 376 EXPECT_EQ(2, page_flips_); | 376 EXPECT_EQ(2, page_flips_); |
| 377 EXPECT_TRUE(primary_crtc_plane->in_use()); | 377 EXPECT_TRUE(primary_crtc_plane->in_use()); |
| 378 EXPECT_EQ(kPrimaryCrtc, primary_crtc_plane->owning_crtc()); | 378 EXPECT_EQ(kPrimaryCrtc, primary_crtc_plane->owning_crtc()); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 TEST_F(HardwareDisplayControllerTest, AddCrtcMidPageFlip) { | 445 TEST_F(HardwareDisplayControllerTest, AddCrtcMidPageFlip) { |
| 446 ui::OverlayPlane plane1(scoped_refptr<ui::ScanoutBuffer>( | 446 ui::OverlayPlane plane1(scoped_refptr<ui::ScanoutBuffer>( |
| 447 new ui::MockScanoutBuffer(kDefaultModeSize))); | 447 new ui::MockScanoutBuffer(kDefaultModeSize))); |
| 448 EXPECT_TRUE(controller_->Modeset(plane1, kDefaultMode)); | 448 EXPECT_TRUE(controller_->Modeset(plane1, kDefaultMode)); |
| 449 std::vector<ui::OverlayPlane> planes = | 449 std::vector<ui::OverlayPlane> planes = |
| 450 std::vector<ui::OverlayPlane>(1, plane1); | 450 std::vector<ui::OverlayPlane>(1, plane1); |
| 451 controller_->SchedulePageFlip( | 451 controller_->SchedulePageFlip( |
| 452 planes, base::Bind(&HardwareDisplayControllerTest::PageFlipCallback, | 452 planes, base::Bind(&HardwareDisplayControllerTest::PageFlipCallback, |
| 453 base::Unretained(this))); | 453 base::Unretained(this))); |
| 454 | 454 |
| 455 controller_->AddCrtc(scoped_ptr<ui::CrtcController>( | 455 controller_->AddCrtc(std::unique_ptr<ui::CrtcController>( |
| 456 new ui::CrtcController(drm_.get(), kSecondaryCrtc, kSecondaryConnector))); | 456 new ui::CrtcController(drm_.get(), kSecondaryCrtc, kSecondaryConnector))); |
| 457 | 457 |
| 458 drm_->RunCallbacks(); | 458 drm_->RunCallbacks(); |
| 459 EXPECT_EQ(gfx::SwapResult::SWAP_ACK, last_swap_result_); | 459 EXPECT_EQ(gfx::SwapResult::SWAP_ACK, last_swap_result_); |
| 460 EXPECT_EQ(1, page_flips_); | 460 EXPECT_EQ(1, page_flips_); |
| 461 } | 461 } |
| 462 | 462 |
| 463 TEST_F(HardwareDisplayControllerTest, RemoveCrtcMidPageFlip) { | 463 TEST_F(HardwareDisplayControllerTest, RemoveCrtcMidPageFlip) { |
| 464 ui::OverlayPlane plane1(scoped_refptr<ui::ScanoutBuffer>( | 464 ui::OverlayPlane plane1(scoped_refptr<ui::ScanoutBuffer>( |
| 465 new ui::MockScanoutBuffer(kDefaultModeSize))); | 465 new ui::MockScanoutBuffer(kDefaultModeSize))); |
| 466 EXPECT_TRUE(controller_->Modeset(plane1, kDefaultMode)); | 466 EXPECT_TRUE(controller_->Modeset(plane1, kDefaultMode)); |
| 467 std::vector<ui::OverlayPlane> planes = | 467 std::vector<ui::OverlayPlane> planes = |
| 468 std::vector<ui::OverlayPlane>(1, plane1); | 468 std::vector<ui::OverlayPlane>(1, plane1); |
| 469 controller_->SchedulePageFlip( | 469 controller_->SchedulePageFlip( |
| 470 planes, base::Bind(&HardwareDisplayControllerTest::PageFlipCallback, | 470 planes, base::Bind(&HardwareDisplayControllerTest::PageFlipCallback, |
| 471 base::Unretained(this))); | 471 base::Unretained(this))); |
| 472 | 472 |
| 473 controller_->RemoveCrtc(drm_, kPrimaryCrtc); | 473 controller_->RemoveCrtc(drm_, kPrimaryCrtc); |
| 474 | 474 |
| 475 EXPECT_EQ(1, page_flips_); | 475 EXPECT_EQ(1, page_flips_); |
| 476 drm_->RunCallbacks(); | 476 drm_->RunCallbacks(); |
| 477 EXPECT_EQ(gfx::SwapResult::SWAP_ACK, last_swap_result_); | 477 EXPECT_EQ(gfx::SwapResult::SWAP_ACK, last_swap_result_); |
| 478 EXPECT_EQ(1, page_flips_); | 478 EXPECT_EQ(1, page_flips_); |
| 479 } | 479 } |
| OLD | NEW |