Commit 0b0b3d3d authored by Mark Yacoub's avatar Mark Yacoub Committed by Commit Bot

Make finding primary plan for modeset responsibility of the test/modeset

Refactor: Move finding a primary plane for Test Modeset or Commit Modeset early on
so the plane args could be extended and manipulated in tests, and test
would fail quick on failure to find a plane.

BUG: 979736
TEST: Test & Commit succeeds.
Change-Id: I88de210a59dba67912227a94f542ccff7f771e36
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2505938Reviewed-by: default avatarDaniel Nicoara <dnicoara@chromium.org>
Commit-Queue: Mark Yacoub <markyacoub@google.com>
Cr-Commit-Position: refs/heads/master@{#822643}
parent bf412c93
...@@ -229,7 +229,6 @@ base::flat_map<int64_t, bool> ScreenManager::TestAndModeset( ...@@ -229,7 +229,6 @@ base::flat_map<int64_t, bool> ScreenManager::TestAndModeset(
bool ScreenManager::TestModeset( bool ScreenManager::TestModeset(
const ControllerConfigsList& controllers_params) { const ControllerConfigsList& controllers_params) {
CommitRequest commit_request; CommitRequest commit_request;
bool status = true;
auto drm = controllers_params[0].drm; auto drm = controllers_params[0].drm;
for (const auto& params : controllers_params) { for (const auto& params : controllers_params) {
...@@ -238,18 +237,22 @@ bool ScreenManager::TestModeset( ...@@ -238,18 +237,22 @@ bool ScreenManager::TestModeset(
HardwareDisplayController* controller = it->get(); HardwareDisplayController* controller = it->get();
if (params.mode) { if (params.mode) {
status &= GetModesetControllerProps(&commit_request, controller, DrmOverlayPlane primary_plane = GetModesetBuffer(
params.origin, *params.mode); controller, gfx::Rect(params.origin, ModeSize(*params.mode)),
GetModifiersForPrimaryFormat(controller));
if (!primary_plane.buffer)
return false;
GetModesetControllerProps(&commit_request, controller, params.origin,
*params.mode, primary_plane);
} else { } else {
controller->GetDisableProps(&commit_request); controller->GetDisableProps(&commit_request);
} }
} }
if (status) {
status &= drm->plane_manager()->Commit( return drm->plane_manager()->Commit(
std::move(commit_request), std::move(commit_request),
DRM_MODE_ATOMIC_TEST_ONLY | DRM_MODE_ATOMIC_ALLOW_MODESET); DRM_MODE_ATOMIC_TEST_ONLY | DRM_MODE_ATOMIC_ALLOW_MODESET);
}
return status;
} }
base::flat_map<int64_t, bool> ScreenManager::Modeset( base::flat_map<int64_t, bool> ScreenManager::Modeset(
...@@ -259,12 +262,28 @@ base::flat_map<int64_t, bool> ScreenManager::Modeset( ...@@ -259,12 +262,28 @@ base::flat_map<int64_t, bool> ScreenManager::Modeset(
for (const auto& params : controllers_params) { for (const auto& params : controllers_params) {
// Commit one controller at a time. // Commit one controller at a time.
CommitRequest commit_request; CommitRequest commit_request;
bool status = params.mode bool status = true;
? SetDisplayControllerForEnableAndGetProps( if (params.mode) {
&commit_request, params.drm, params.crtc, auto it = FindDisplayController(params.drm, params.crtc);
params.connector, params.origin, *params.mode) DCHECK(controllers_.end() != it);
: SetDisableDisplayControllerForDisableAndGetProps( HardwareDisplayController* controller = it->get();
&commit_request, params.drm, params.crtc);
DrmOverlayPlane primary_plane = GetModesetBuffer(
controller, gfx::Rect(params.origin, ModeSize(*params.mode)),
GetModifiersForPrimaryFormat(controller));
if (primary_plane.buffer) {
SetDisplayControllerForEnableAndGetProps(
&commit_request, params.drm, params.crtc, params.connector,
params.origin, *params.mode, primary_plane);
} else {
status = false;
}
} else {
status = SetDisableDisplayControllerForDisableAndGetProps(
&commit_request, params.drm, params.crtc);
}
CommitRequest request_for_update = commit_request; CommitRequest request_for_update = commit_request;
if (status) { if (status) {
status &= params.drm->plane_manager()->Commit( status &= params.drm->plane_manager()->Commit(
...@@ -280,13 +299,14 @@ base::flat_map<int64_t, bool> ScreenManager::Modeset( ...@@ -280,13 +299,14 @@ base::flat_map<int64_t, bool> ScreenManager::Modeset(
// TODO(markyacoub): As Mirroring is partially handled in // TODO(markyacoub): As Mirroring is partially handled in
// UpdateControllerStateAfterModeset(), this function can be greatly simplified. // UpdateControllerStateAfterModeset(), this function can be greatly simplified.
bool ScreenManager::SetDisplayControllerForEnableAndGetProps( void ScreenManager::SetDisplayControllerForEnableAndGetProps(
CommitRequest* commit_request, CommitRequest* commit_request,
const scoped_refptr<DrmDevice>& drm, const scoped_refptr<DrmDevice>& drm,
uint32_t crtc, uint32_t crtc,
uint32_t connector, uint32_t connector,
const gfx::Point& origin, const gfx::Point& origin,
const drmModeModeInfo& mode) { const drmModeModeInfo& mode,
const DrmOverlayPlane& primary) {
gfx::Rect modeset_bounds(origin.x(), origin.y(), mode.hdisplay, gfx::Rect modeset_bounds(origin.x(), origin.y(), mode.hdisplay,
mode.vdisplay); mode.vdisplay);
HardwareDisplayControllers::iterator it = FindDisplayController(drm, crtc); HardwareDisplayControllers::iterator it = FindDisplayController(drm, crtc);
...@@ -304,12 +324,15 @@ bool ScreenManager::SetDisplayControllerForEnableAndGetProps( ...@@ -304,12 +324,15 @@ bool ScreenManager::SetDisplayControllerForEnableAndGetProps(
FindActiveDisplayControllerByLocation(drm, modeset_bounds); FindActiveDisplayControllerByLocation(drm, modeset_bounds);
// If there is an active controller at the same location then start mirror // If there is an active controller at the same location then start mirror
// mode. // mode.
if (mirror != controllers_.end()) if (mirror != controllers_.end()) {
return HandleMirrorMode(commit_request, it, mirror, mode); HandleMirrorMode(commit_request, it, mirror, mode, primary);
return;
}
} }
// Just get props to re-enable the controller re-using the current state. // Just get props to re-enable the controller re-using the current state.
return GetEnableControllerProps(commit_request, controller); GetEnableControllerProps(commit_request, controller, primary);
return;
} }
// 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
...@@ -326,10 +349,12 @@ bool ScreenManager::SetDisplayControllerForEnableAndGetProps( ...@@ -326,10 +349,12 @@ bool ScreenManager::SetDisplayControllerForEnableAndGetProps(
HardwareDisplayControllers::iterator mirror = HardwareDisplayControllers::iterator mirror =
FindActiveDisplayControllerByLocation(drm, modeset_bounds); FindActiveDisplayControllerByLocation(drm, modeset_bounds);
// Handle mirror mode. // Handle mirror mode.
if (mirror != controllers_.end() && it != mirror) if (mirror != controllers_.end() && it != mirror) {
return HandleMirrorMode(commit_request, it, mirror, mode); HandleMirrorMode(commit_request, it, mirror, mode, primary);
return;
}
return GetModesetControllerProps(commit_request, controller, origin, mode); GetModesetControllerProps(commit_request, controller, origin, mode, primary);
} }
bool ScreenManager::SetDisableDisplayControllerForDisableAndGetProps( bool ScreenManager::SetDisableDisplayControllerForDisableAndGetProps(
...@@ -451,19 +476,20 @@ ScreenManager::FindActiveDisplayControllerByLocation( ...@@ -451,19 +476,20 @@ ScreenManager::FindActiveDisplayControllerByLocation(
return controllers_.end(); return controllers_.end();
} }
bool ScreenManager::HandleMirrorMode( void ScreenManager::HandleMirrorMode(
CommitRequest* commit_request, CommitRequest* commit_request,
HardwareDisplayControllers::iterator original, HardwareDisplayControllers::iterator original,
HardwareDisplayControllers::iterator mirror, HardwareDisplayControllers::iterator mirror,
const drmModeModeInfo& mode) { const drmModeModeInfo& mode,
const DrmOverlayPlane& primary) {
// Modeset the CRTC with its mode in the original controller so that only this // Modeset the CRTC with its mode in the original controller so that only this
// CRTC is affected by the mode. Otherwise it could apply a mode with the same // CRTC is affected by the mode. Otherwise it could apply a mode with the same
// resolution and refresh rate but with different timings to the other CRTC. // resolution and refresh rate but with different timings to the other CRTC.
// TODO(dnicoara): This is hacky, instead the DrmDisplay and CrtcController // TODO(dnicoara): This is hacky, instead the DrmDisplay and CrtcController
// should be merged and picking the mode should be done properly within // should be merged and picking the mode should be done properly within
// HardwareDisplayController. // HardwareDisplayController.
return GetModesetControllerProps(commit_request, original->get(), GetModesetControllerProps(commit_request, original->get(),
(*mirror)->origin(), mode); (*mirror)->origin(), mode, primary);
} }
void ScreenManager::UpdateControllerToWindowMapping() { void ScreenManager::UpdateControllerToWindowMapping() {
...@@ -497,8 +523,14 @@ void ScreenManager::UpdateControllerToWindowMapping() { ...@@ -497,8 +523,14 @@ void ScreenManager::UpdateControllerToWindowMapping() {
// otherwise the controller may be waiting for a page flip while the window // otherwise the controller may be waiting for a page flip while the window
// tries to schedule another buffer. // tries to schedule another buffer.
if (should_enable) { if (should_enable) {
DrmOverlayPlane primary_plane = GetModesetBuffer(
controller,
gfx::Rect(controller->origin(), controller->GetModeSize()),
GetModifiersForPrimaryFormat(controller));
DCHECK(primary_plane.buffer);
CommitRequest commit_request; CommitRequest commit_request;
GetEnableControllerProps(&commit_request, controller); GetEnableControllerProps(&commit_request, controller, primary_plane);
controller->GetDrmDevice()->plane_manager()->Commit( controller->GetDrmDevice()->plane_manager()->Commit(
std::move(commit_request), DRM_MODE_ATOMIC_ALLOW_MODESET); std::move(commit_request), DRM_MODE_ATOMIC_ALLOW_MODESET);
} }
...@@ -554,41 +586,25 @@ DrmOverlayPlane ScreenManager::GetModesetBuffer( ...@@ -554,41 +586,25 @@ DrmOverlayPlane ScreenManager::GetModesetBuffer(
return DrmOverlayPlane(framebuffer, nullptr); return DrmOverlayPlane(framebuffer, nullptr);
} }
bool ScreenManager::GetEnableControllerProps( void ScreenManager::GetEnableControllerProps(
CommitRequest* commit_request, CommitRequest* commit_request,
HardwareDisplayController* controller) { HardwareDisplayController* controller,
const DrmOverlayPlane& primary) {
DCHECK(!controller->crtc_controllers().empty()); DCHECK(!controller->crtc_controllers().empty());
gfx::Rect rect(controller->origin(), controller->GetModeSize()); controller->GetEnableProps(commit_request, primary);
auto modifiers = GetModifiersForPrimaryFormat(controller);
DrmOverlayPlane primary_plane = GetModesetBuffer(controller, rect, modifiers);
if (!primary_plane.buffer) {
PLOG(ERROR) << "Failed to find plane buffer for Enable";
return false;
}
controller->GetEnableProps(commit_request, primary_plane);
return true;
} }
bool ScreenManager::GetModesetControllerProps( void ScreenManager::GetModesetControllerProps(
CommitRequest* commit_request, CommitRequest* commit_request,
HardwareDisplayController* controller, HardwareDisplayController* controller,
const gfx::Point& origin, const gfx::Point& origin,
const drmModeModeInfo& mode) { const drmModeModeInfo& mode,
const DrmOverlayPlane& primary) {
DCHECK(!controller->crtc_controllers().empty()); DCHECK(!controller->crtc_controllers().empty());
gfx::Rect rect(origin, ModeSize(mode));
controller->set_origin(origin); controller->set_origin(origin);
auto modifiers = GetModifiersForPrimaryFormat(controller); controller->GetModesetProps(commit_request, primary, mode);
DrmOverlayPlane primary_plane = GetModesetBuffer(controller, rect, modifiers);
if (!primary_plane.buffer) {
PLOG(ERROR) << "Failed to find plane buffer for Modeset";
return false;
}
controller->GetModesetProps(commit_request, primary_plane, mode);
return true;
} }
DrmWindow* ScreenManager::FindWindowAt(const gfx::Rect& bounds) const { DrmWindow* ScreenManager::FindWindowAt(const gfx::Rect& bounds) const {
......
...@@ -114,13 +114,14 @@ class ScreenManager { ...@@ -114,13 +114,14 @@ class ScreenManager {
// Configures a display controller to be enabled. The display controller is // Configures a display controller to be enabled. The display controller is
// identified by (|crtc|, |connector|) and the controller is to be modeset // identified by (|crtc|, |connector|) and the controller is to be modeset
// using |mode|. Controller modeset props are added into |commit_request|. // using |mode|. Controller modeset props are added into |commit_request|.
bool SetDisplayControllerForEnableAndGetProps( void SetDisplayControllerForEnableAndGetProps(
CommitRequest* commit_request, CommitRequest* commit_request,
const scoped_refptr<DrmDevice>& drm, const scoped_refptr<DrmDevice>& drm,
uint32_t crtc, uint32_t crtc,
uint32_t connector, uint32_t connector,
const gfx::Point& origin, const gfx::Point& origin,
const drmModeModeInfo& mode); const drmModeModeInfo& mode,
const DrmOverlayPlane& primary);
// Configures a display controller to be disabled. The display controller is // Configures a display controller to be disabled. The display controller is
// identified by |crtc|. Controller modeset props are added into // identified by |crtc|. Controller modeset props are added into
...@@ -150,24 +151,25 @@ class ScreenManager { ...@@ -150,24 +151,25 @@ class ScreenManager {
// Tries to set the |original| controller to mirror those in |mirror|. // Tries to set the |original| controller to mirror those in |mirror|.
// |original| is an iterator to the HDC where the controller is currently // |original| is an iterator to the HDC where the controller is currently
// present. // present.
bool HandleMirrorMode(CommitRequest* commit_request, void HandleMirrorMode(CommitRequest* commit_request,
HardwareDisplayControllers::iterator original, HardwareDisplayControllers::iterator original,
HardwareDisplayControllers::iterator mirror, HardwareDisplayControllers::iterator mirror,
const drmModeModeInfo& mode); const drmModeModeInfo& mode,
const DrmOverlayPlane& primary);
DrmOverlayPlane GetModesetBuffer(HardwareDisplayController* controller, DrmOverlayPlane GetModesetBuffer(HardwareDisplayController* controller,
const gfx::Rect& bounds, const gfx::Rect& bounds,
const std::vector<uint64_t>& modifiers); const std::vector<uint64_t>& modifiers);
// Gets props for modesetting the |controller| using |origin| and |mode|. If // Gets props for modesetting the |controller| using |origin| and |mode|.
// there is a window at the controller location, then we'll re-use the current void GetModesetControllerProps(CommitRequest* commit_request,
// buffer.
bool GetModesetControllerProps(CommitRequest* commit_request,
HardwareDisplayController* controller, HardwareDisplayController* controller,
const gfx::Point& origin, const gfx::Point& origin,
const drmModeModeInfo& mode); const drmModeModeInfo& mode,
bool GetEnableControllerProps(CommitRequest* commit_request, const DrmOverlayPlane& primary);
HardwareDisplayController* controller); void GetEnableControllerProps(CommitRequest* commit_request,
HardwareDisplayController* controller,
const DrmOverlayPlane& primary);
DrmWindow* FindWindowAt(const gfx::Rect& bounds) const; DrmWindow* FindWindowAt(const gfx::Rect& bounds) const;
......
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