Commit 26b5cbee authored by dnicoara's avatar dnicoara Committed by Commit bot

[Ozone-DRI] Reuse framebuffer when re-enabling CRTC

BUG=446312
NOTRY=true

Review URL: https://codereview.chromium.org/838633002

Cr-Commit-Position: refs/heads/master@{#310197}
parent 261f7f3a
...@@ -48,6 +48,7 @@ void HandlePageFlipEvent(int fd, ...@@ -48,6 +48,7 @@ void HandlePageFlipEvent(int fd,
HardwareDisplayController::HardwareDisplayController( HardwareDisplayController::HardwareDisplayController(
scoped_ptr<CrtcController> controller) scoped_ptr<CrtcController> controller)
: is_disabled_(true) { : is_disabled_(true) {
memset(&mode_, 0, sizeof(mode_));
AddCrtc(controller.Pass()); AddCrtc(controller.Pass());
} }
...@@ -75,12 +76,8 @@ bool HardwareDisplayController::Enable() { ...@@ -75,12 +76,8 @@ bool HardwareDisplayController::Enable() {
TRACE_EVENT0("dri", "HDC::Enable"); TRACE_EVENT0("dri", "HDC::Enable");
DCHECK(!current_planes_.empty()); DCHECK(!current_planes_.empty());
const OverlayPlane* primary = OverlayPlane::GetPrimaryPlane(current_planes_); const OverlayPlane* primary = OverlayPlane::GetPrimaryPlane(current_planes_);
DCHECK(primary->buffer.get());
bool status = true;
for (size_t i = 0; i < crtc_controllers_.size(); ++i)
status &= crtc_controllers_[i]->Modeset(*primary, mode_);
return status; return Modeset(*primary, mode_);
} }
void HardwareDisplayController::Disable() { void HardwareDisplayController::Disable() {
......
...@@ -109,8 +109,19 @@ bool ScreenManager::ConfigureDisplayController(uint32_t crtc, ...@@ -109,8 +109,19 @@ bool ScreenManager::ConfigureDisplayController(uint32_t crtc,
// If nothing changed just enable the controller. Note, we perform an exact // If nothing changed just enable the controller. Note, we perform an exact
// comparison on the mode since the refresh rate may have changed. // comparison on the mode since the refresh rate may have changed.
if (SameMode(mode, controller->get_mode()) && if (SameMode(mode, controller->get_mode()) &&
origin == controller->origin() && !controller->IsDisabled()) origin == controller->origin()) {
if (controller->IsDisabled()) {
HardwareDisplayControllers::iterator mirror =
FindActiveDisplayControllerByLocation(modeset_bounds);
// If there is an active controller at the same location then start mirror
// mode.
if (mirror != controllers_.end())
return HandleMirrorMode(it, mirror, crtc, connector);
}
// Just re-enable the controller to re-use the current state.
return controller->Enable(); return controller->Enable();
}
// Either the mode or the location of the display changed, so exit mirror // Either the mode or the location of the display changed, so exit mirror
// mode and configure the display independently. If the caller still wants // mode and configure the display independently. If the caller still wants
......
...@@ -139,11 +139,16 @@ TEST_F(ScreenManagerTest, CheckDuplicateConfiguration) { ...@@ -139,11 +139,16 @@ TEST_F(ScreenManagerTest, CheckDuplicateConfiguration) {
kPrimaryConnector, kPrimaryConnector,
GetPrimaryBounds().origin(), GetPrimaryBounds().origin(),
kDefaultMode); kDefaultMode);
uint32_t framebuffer = dri_->current_framebuffer();
screen_manager_->ConfigureDisplayController(kPrimaryCrtc, screen_manager_->ConfigureDisplayController(kPrimaryCrtc,
kPrimaryConnector, kPrimaryConnector,
GetPrimaryBounds().origin(), GetPrimaryBounds().origin(),
kDefaultMode); kDefaultMode);
// Should reuse existing framebuffer.
EXPECT_EQ(framebuffer, dri_->current_framebuffer());
EXPECT_TRUE(screen_manager_->GetDisplayController(GetPrimaryBounds())); EXPECT_TRUE(screen_manager_->GetDisplayController(GetPrimaryBounds()));
EXPECT_FALSE(screen_manager_->GetDisplayController(GetSecondaryBounds())); EXPECT_FALSE(screen_manager_->GetDisplayController(GetSecondaryBounds()));
} }
...@@ -275,3 +280,48 @@ TEST_F(ScreenManagerTest, DoNotEnterMirrorModeUnlessSameBounds) { ...@@ -275,3 +280,48 @@ TEST_F(ScreenManagerTest, DoNotEnterMirrorModeUnlessSameBounds) {
EXPECT_FALSE( EXPECT_FALSE(
screen_manager_->GetDisplayController(GetPrimaryBounds())->IsMirrored()); screen_manager_->GetDisplayController(GetPrimaryBounds())->IsMirrored());
} }
TEST_F(ScreenManagerTest, ReuseFramebufferIfDisabledThenReEnabled) {
screen_manager_->AddDisplayController(dri_.get(), kPrimaryCrtc,
kPrimaryConnector);
screen_manager_->ConfigureDisplayController(kPrimaryCrtc, kPrimaryConnector,
GetPrimaryBounds().origin(),
kDefaultMode);
uint32_t framebuffer = dri_->current_framebuffer();
screen_manager_->DisableDisplayController(kPrimaryCrtc);
EXPECT_EQ(0u, dri_->current_framebuffer());
screen_manager_->ConfigureDisplayController(kPrimaryCrtc, kPrimaryConnector,
GetPrimaryBounds().origin(),
kDefaultMode);
// Should reuse existing framebuffer.
EXPECT_EQ(framebuffer, dri_->current_framebuffer());
}
TEST_F(ScreenManagerTest, CheckMirrorModeAfterBeginReEnabled) {
screen_manager_->AddDisplayController(dri_.get(), kPrimaryCrtc,
kPrimaryConnector);
screen_manager_->ConfigureDisplayController(kPrimaryCrtc, kPrimaryConnector,
GetPrimaryBounds().origin(),
kDefaultMode);
screen_manager_->DisableDisplayController(kPrimaryCrtc);
screen_manager_->AddDisplayController(dri_.get(), kSecondaryCrtc,
kSecondaryConnector);
screen_manager_->ConfigureDisplayController(
kSecondaryCrtc, kSecondaryConnector, GetPrimaryBounds().origin(),
kDefaultMode);
base::WeakPtr<ui::HardwareDisplayController> controller =
screen_manager_->GetDisplayController(GetPrimaryBounds());
EXPECT_TRUE(controller);
EXPECT_FALSE(controller->IsMirrored());
screen_manager_->ConfigureDisplayController(kPrimaryCrtc, kPrimaryConnector,
GetPrimaryBounds().origin(),
kDefaultMode);
EXPECT_TRUE(controller);
EXPECT_TRUE(controller->IsMirrored());
}
...@@ -105,6 +105,11 @@ bool MockDriWrapper::SetCrtc(drmModeCrtc* crtc, ...@@ -105,6 +105,11 @@ bool MockDriWrapper::SetCrtc(drmModeCrtc* crtc,
return true; return true;
} }
bool MockDriWrapper::DisableCrtc(uint32_t crtc_id) {
current_framebuffer_ = 0;
return true;
}
ScopedDrmConnectorPtr MockDriWrapper::GetConnector(uint32_t connector_id) { ScopedDrmConnectorPtr MockDriWrapper::GetConnector(uint32_t connector_id) {
return ScopedDrmConnectorPtr(DrmAllocator<drmModeConnector>()); return ScopedDrmConnectorPtr(DrmAllocator<drmModeConnector>());
} }
......
...@@ -63,6 +63,7 @@ class MockDriWrapper : public ui::DriWrapper { ...@@ -63,6 +63,7 @@ class MockDriWrapper : public ui::DriWrapper {
std::vector<uint32_t> connectors, std::vector<uint32_t> connectors,
drmModeModeInfo* mode) override; drmModeModeInfo* mode) override;
bool SetCrtc(drmModeCrtc* crtc, std::vector<uint32_t> connectors) override; bool SetCrtc(drmModeCrtc* crtc, std::vector<uint32_t> connectors) override;
bool DisableCrtc(uint32_t crtc_id) override;
ScopedDrmConnectorPtr GetConnector(uint32_t connector_id) override; ScopedDrmConnectorPtr GetConnector(uint32_t connector_id) override;
bool AddFramebuffer(uint32_t width, bool AddFramebuffer(uint32_t width,
uint32_t height, uint32_t height,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment