drm_hwcomposer: refactor drmAtomicStateManager
This is a prerequisit to allow for multi-display commit at once. It also removes the cognitive complexity of CommitFrame through addition of helpers for all drm properties to be set. Change-Id: Ifad7e574c9ea6ced09c677923868ce29656f33f3 Signed-off-by: Lucas Berthou <berlu@google.com>
This commit is contained in:
parent
2a0a4114a2
commit
446c229f98
3 changed files with 414 additions and 246 deletions
|
|
@ -51,220 +51,7 @@ DrmAtomicStateManager::~DrmAtomicStateManager() {
|
|||
thread_.join();
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE (readability-function-cognitive-complexity): Fixme
|
||||
auto DrmAtomicStateManager::CommitFrame(AtomicCommitArgs &args) -> int {
|
||||
// NOLINTNEXTLINE(misc-const-correctness)
|
||||
ATRACE_CALL();
|
||||
|
||||
// new_frame_state is initialized to the current frame state and may be
|
||||
// modified below.
|
||||
auto new_frame_state = committed_frame_state_;
|
||||
KmsObjects used_kms_objects;
|
||||
|
||||
if (args.active && *args.active == new_frame_state.crtc_active_state) {
|
||||
/* Don't set the same state twice */
|
||||
args.active.reset();
|
||||
}
|
||||
|
||||
if (!args.HasInputs()) {
|
||||
/* nothing to do */
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!new_frame_state.crtc_active_state) {
|
||||
/* Force activate display */
|
||||
args.active = true;
|
||||
}
|
||||
|
||||
auto *crtc = pipe_->crtc->Get();
|
||||
|
||||
auto pset = MakeDrmModeAtomicReqUnique();
|
||||
if (!pset) {
|
||||
ALOGE("Failed to allocate property set");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
int wb_fence = -1;
|
||||
|
||||
if (pipe_->writeback_connector && args.writeback_fb) {
|
||||
if (!pipe_->writeback_connector->Get()
|
||||
->GetCrtcIdProperty()
|
||||
.AtomicSet(*pset, crtc->GetId())) {
|
||||
ALOGE("DrmAtomicStateManager: Failed to set writeback CRTC_ID property");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!pipe_->writeback_connector->Get()
|
||||
->GetWritebackFbIdProperty()
|
||||
.AtomicSet(*pset, args.writeback_fb->GetFbId())) {
|
||||
ALOGE("DrmAtomicStateManager: Failed to set writeback FB_ID property");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!pipe_->writeback_connector->Get()
|
||||
->GetWritebackOutFenceProperty()
|
||||
.AtomicSet(*pset, uint64_t(&wb_fence))) {
|
||||
ALOGE(
|
||||
"DrmAtomicStateManager: Failed to set writeback OUT_FENCE_PTR "
|
||||
"property");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
// Wait on input fence if provided
|
||||
if (args.writeback_release_fence) {
|
||||
sync_wait(*args.writeback_release_fence, -1);
|
||||
args.writeback_release_fence.reset();
|
||||
}
|
||||
}
|
||||
|
||||
int out_fence = -1;
|
||||
if (!crtc->GetOutFencePtrProperty().AtomicSet(*pset, uint64_t(&out_fence))) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
bool nonblock = !args.blocking;
|
||||
auto *connector = pipe_->connector->Get();
|
||||
if (args.active) {
|
||||
nonblock = false;
|
||||
new_frame_state.crtc_active_state = *args.active;
|
||||
if (!crtc->GetActiveProperty().AtomicSet(*pset, *args.active ? 1 : 0) ||
|
||||
!connector->GetCrtcIdProperty().AtomicSet(*pset, crtc->GetId())) {
|
||||
return -EINVAL;
|
||||
}
|
||||
if (!*args.active && args.teardown) {
|
||||
if (!connector->GetCrtcIdProperty().AtomicSet(*pset, 0) ||
|
||||
!crtc->GetModeProperty().AtomicSet(*pset, 0)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto *drm = pipe_->device;
|
||||
if (args.display_mode) {
|
||||
auto mode_blob = args.display_mode.value().CreateModeBlob(*drm);
|
||||
|
||||
if (!mode_blob) {
|
||||
ALOGE("Failed to create mode_blob");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
auto raw_mode = args.display_mode.value().GetRawMode();
|
||||
whole_display_rect_.i_rect = {0, 0, raw_mode.hdisplay, raw_mode.vdisplay};
|
||||
|
||||
if (!crtc->GetModeProperty().AtomicSet(*pset, *mode_blob)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
used_kms_objects.blobs.emplace_back(std::move(mode_blob));
|
||||
}
|
||||
|
||||
if (args.color_matrix && crtc->GetCtmProperty()) {
|
||||
auto ctm_blob = drm->RegisterUserPropertyBlob(args.color_matrix.get(),
|
||||
sizeof(drm_color_ctm));
|
||||
if (!ctm_blob) {
|
||||
ALOGE("Failed to create CTM blob");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!crtc->GetCtmProperty().AtomicSet(*pset, *ctm_blob))
|
||||
return -EINVAL;
|
||||
|
||||
used_kms_objects.blobs.emplace_back(std::move(ctm_blob));
|
||||
}
|
||||
|
||||
if (args.colorspace && connector->GetColorspaceProperty()) {
|
||||
if (!connector->GetColorspaceProperty()
|
||||
.AtomicSet(*pset, connector->GetColorspacePropertyValue(
|
||||
*args.colorspace)))
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (args.content_type && connector->GetContentTypeProperty()) {
|
||||
if (!connector->GetContentTypeProperty().AtomicSet(*pset,
|
||||
static_cast<uint64_t>(
|
||||
*args.content_type)))
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (args.hdr_metadata && connector->GetHdrOutputMetadataProperty()) {
|
||||
auto hdr_metadata_blob = drm->RegisterUserPropertyBlob(
|
||||
args.hdr_metadata.get(), sizeof(hdr_output_metadata));
|
||||
if (!hdr_metadata_blob) {
|
||||
ALOGE("Failed to create %s blob",
|
||||
connector->GetHdrOutputMetadataProperty().GetName().c_str());
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!connector->GetHdrOutputMetadataProperty()
|
||||
.AtomicSet(*pset, *hdr_metadata_blob))
|
||||
return -EINVAL;
|
||||
used_kms_objects.blobs.emplace_back(std::move(hdr_metadata_blob));
|
||||
}
|
||||
|
||||
if (args.min_bpc && connector->GetMinBpcProperty()) {
|
||||
int err = 0;
|
||||
uint64_t range_min = 0;
|
||||
uint64_t range_max = 0;
|
||||
std::tie(err, range_min) = connector->GetMinBpcProperty().RangeMin();
|
||||
if (err != 0)
|
||||
return err;
|
||||
std::tie(err, range_max) = connector->GetMinBpcProperty().RangeMax();
|
||||
if (err != 0)
|
||||
return err;
|
||||
|
||||
// Adjust requested min bpc to be within the property range
|
||||
int32_t min_bpc_val = std::max(args.min_bpc.value(),
|
||||
static_cast<int32_t>(range_min));
|
||||
min_bpc_val = std::min(min_bpc_val, static_cast<int32_t>(range_max));
|
||||
if (!connector->GetMinBpcProperty().AtomicSet(*pset, min_bpc_val))
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
auto unused_planes = new_frame_state.used_planes;
|
||||
|
||||
if (args.composition) {
|
||||
new_frame_state.used_planes.clear();
|
||||
|
||||
for (auto &joining : args.composition->plan) {
|
||||
DrmPlane *plane = joining.plane->Get();
|
||||
LayerData &layer = joining.layer;
|
||||
|
||||
used_kms_objects.framebuffers.emplace_back(layer.fb);
|
||||
new_frame_state.used_planes.emplace_back(joining.plane);
|
||||
|
||||
/* Remove from 'unused' list, since plane is re-used */
|
||||
auto &v = unused_planes;
|
||||
v.erase(std::remove(v.begin(), v.end(), joining.plane), v.end());
|
||||
|
||||
DrmModeUserPropertyBlobUnique damage_blob;
|
||||
if (plane->AtomicSetState(*pset, layer, joining.z_pos, crtc->GetId(),
|
||||
whole_display_rect_, damage_blob) != 0) {
|
||||
return -EINVAL;
|
||||
}
|
||||
used_kms_objects.blobs.emplace_back(std::move(damage_blob));
|
||||
}
|
||||
}
|
||||
|
||||
if (args.composition) {
|
||||
for (auto &plane : unused_planes) {
|
||||
if (plane->Get()->AtomicDisablePlane(*pset) != 0) {
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t flags = DRM_MODE_ATOMIC_ALLOW_MODESET;
|
||||
const int error_buf_max_size = 64;
|
||||
char err_buf[error_buf_max_size];
|
||||
|
||||
if (args.test_only) {
|
||||
auto err = drmModeAtomicCommit(*drm->GetFd(), pset.get(),
|
||||
flags | DRM_MODE_ATOMIC_TEST_ONLY, drm);
|
||||
|
||||
ALOGE_IF(err != 0, "Test-only ret=%d errno=%d strerror=%s\n", err, errno,
|
||||
strerror_r(errno, err_buf, error_buf_max_size));
|
||||
return err;
|
||||
}
|
||||
|
||||
void DrmAtomicStateManager::WaitLastFrame() {
|
||||
SharedFd present_fence;
|
||||
{
|
||||
std::lock_guard lock(mutex_);
|
||||
|
|
@ -288,32 +75,86 @@ auto DrmAtomicStateManager::CommitFrame(AtomicCommitArgs &args) -> int {
|
|||
CleanupPriorFrameResources();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DrmAtomicStateManager::CleanFailedCommit() {
|
||||
// Disable the hw used by the last active composition. This allows us to
|
||||
// signal the release fences from that composition to avoid hanging.
|
||||
AtomicCommitArgs cl_args{};
|
||||
cl_args.composition = std::make_shared<DrmKmsPlan>();
|
||||
if (CommitFrame(cl_args) != 0) {
|
||||
ALOGE("Failed to clean-up active composition for pipeline %s",
|
||||
pipe_->connector->Get()->GetName().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE (readability-function-cognitive-complexity): Fixme
|
||||
auto DrmAtomicStateManager::CommitFrame(AtomicCommitArgs &args) -> int {
|
||||
// NOLINTNEXTLINE(misc-const-correctness)
|
||||
ATRACE_CALL();
|
||||
// new_frame_state is initialized to the current frame state and may be
|
||||
// modified below.
|
||||
args.new_frame_state = committed_frame_state_;
|
||||
args.used_kms_objects = {};
|
||||
|
||||
CheckDoubleSettingState(args, args.new_frame_state.crtc_active_state);
|
||||
|
||||
if (!args.HasInputs()) {
|
||||
/* nothing to do */
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto pset = GetAtomicModeReqForArgs(args);
|
||||
|
||||
if (!pset) {
|
||||
ALOGE("Failed to get property set");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
uint32_t flags = DRM_MODE_ATOMIC_ALLOW_MODESET;
|
||||
const int error_buf_max_size = 64;
|
||||
char err_buf[error_buf_max_size];
|
||||
auto *drm = pipe_->device;
|
||||
|
||||
if (args.test_only) {
|
||||
auto err = drmModeAtomicCommit(*drm->GetFd(), pset.get(),
|
||||
flags | DRM_MODE_ATOMIC_TEST_ONLY, drm);
|
||||
|
||||
ALOGE_IF(err != 0, "Test-only ret=%d errno=%d strerror=%s\n", err, errno,
|
||||
strerror_r(errno, err_buf, error_buf_max_size));
|
||||
return err;
|
||||
}
|
||||
|
||||
WaitLastFrame();
|
||||
|
||||
bool nonblock = !args.blocking && !args.active;
|
||||
|
||||
if (nonblock) {
|
||||
flags |= DRM_MODE_ATOMIC_NONBLOCK;
|
||||
}
|
||||
|
||||
auto err = drmModeAtomicCommit(*drm->GetFd(), pset.get(), flags, drm);
|
||||
|
||||
if (err != 0) {
|
||||
ALOGE("Failed to commit pset ret=%d errno=%d strerror=%s\n", err, errno,
|
||||
strerror_r(errno, err_buf, error_buf_max_size));
|
||||
return err;
|
||||
}
|
||||
|
||||
args.out_fence = MakeSharedFd(out_fence);
|
||||
args.out_fence = MakeSharedFd(args.out_fence_address);
|
||||
|
||||
// Store the writeback fence if this operation used a writeback connector
|
||||
if (pipe_->writeback_connector && args.writeback_fb) {
|
||||
args.out_writeback_complete_fence = MakeSharedFd(wb_fence);
|
||||
args.out_writeback_complete_fence = MakeSharedFd(args.wb_fence_address);
|
||||
}
|
||||
|
||||
committed_frame_state_ = std::move(new_frame_state);
|
||||
committed_frame_state_ = std::move(args.new_frame_state);
|
||||
|
||||
if (nonblock) {
|
||||
{
|
||||
const std::lock_guard lock(mutex_);
|
||||
last_present_fence_ = args.out_fence;
|
||||
frame_objects_.emplace(std::move(used_kms_objects));
|
||||
frame_objects_.emplace(std::move(args.used_kms_objects));
|
||||
frames_staged_++;
|
||||
}
|
||||
cv_.notify_all();
|
||||
|
|
@ -321,12 +162,315 @@ auto DrmAtomicStateManager::CommitFrame(AtomicCommitArgs &args) -> int {
|
|||
const std::lock_guard lock(mutex_);
|
||||
last_present_fence_ = {};
|
||||
frame_objects_ = {};
|
||||
frame_objects_.emplace(std::move(used_kms_objects));
|
||||
frame_objects_.emplace(std::move(args.used_kms_objects));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DrmAtomicStateManager::CheckDoubleSettingState(AtomicCommitArgs &args,
|
||||
bool crtc_is_active) {
|
||||
if (args.active && *args.active == crtc_is_active) {
|
||||
/* Don't set the same state twice */
|
||||
args.active.reset();
|
||||
}
|
||||
}
|
||||
|
||||
bool DrmAtomicStateManager::SetWriteBackFenceIfNeeded(drmModeAtomicReq *pset,
|
||||
AtomicCommitArgs &args) {
|
||||
if (!pipe_->writeback_connector || !args.writeback_fb) {
|
||||
return true;
|
||||
}
|
||||
auto *crtc = pipe_->crtc->Get();
|
||||
|
||||
if (!pipe_->writeback_connector->Get()
|
||||
->GetCrtcIdProperty()
|
||||
.AtomicSet(*pset, crtc->GetId())) {
|
||||
ALOGE("DrmAtomicStateManager: Failed to set writeback CRTC_ID property");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!pipe_->writeback_connector->Get()
|
||||
->GetWritebackFbIdProperty()
|
||||
.AtomicSet(*pset, args.writeback_fb->GetFbId())) {
|
||||
ALOGE("DrmAtomicStateManager: Failed to set writeback FB_ID property");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!pipe_->writeback_connector->Get()
|
||||
->GetWritebackOutFenceProperty()
|
||||
.AtomicSet(*pset, uint64_t(&args.wb_fence_address))) {
|
||||
ALOGE(
|
||||
"DrmAtomicStateManager: Failed to set writeback OUT_FENCE_PTR "
|
||||
"property");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Wait on input fence if provided
|
||||
if (args.writeback_release_fence) {
|
||||
sync_wait(*args.writeback_release_fence, -1);
|
||||
args.writeback_release_fence.reset();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DrmAtomicStateManager::SetOutputFence(drmModeAtomicReq *pset,
|
||||
AtomicCommitArgs &args) {
|
||||
auto *crtc = pipe_->crtc->Get();
|
||||
|
||||
return crtc->GetOutFencePtrProperty().AtomicSet(*pset,
|
||||
uint64_t(
|
||||
&args.out_fence_address));
|
||||
}
|
||||
|
||||
bool DrmAtomicStateManager::SetActiveIfNeeded(drmModeAtomicReq *pset,
|
||||
AtomicCommitArgs &args) {
|
||||
if (!args.active) {
|
||||
return true;
|
||||
}
|
||||
auto *crtc = pipe_->crtc->Get();
|
||||
auto *connector = pipe_->connector->Get();
|
||||
args.new_frame_state.crtc_active_state = *args.active;
|
||||
if (!crtc->GetActiveProperty().AtomicSet(*pset, *args.active ? 1 : 0) ||
|
||||
!connector->GetCrtcIdProperty().AtomicSet(*pset, crtc->GetId())) {
|
||||
return false;
|
||||
}
|
||||
if (!*args.active && args.teardown) {
|
||||
if (!connector->GetCrtcIdProperty().AtomicSet(*pset, 0) ||
|
||||
!crtc->GetModeProperty().AtomicSet(*pset, 0)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DrmAtomicStateManager::SetDisplayModeIfNeeded(drmModeAtomicReq *pset,
|
||||
AtomicCommitArgs &args) {
|
||||
if (!args.display_mode) {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto *drm = pipe_->device;
|
||||
auto mode_blob = args.display_mode.value().CreateModeBlob(*drm);
|
||||
|
||||
if (!mode_blob) {
|
||||
ALOGE("Failed to create mode_blob");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto raw_mode = args.display_mode.value().GetRawMode();
|
||||
whole_display_rect_.i_rect = {0, 0, raw_mode.hdisplay, raw_mode.vdisplay};
|
||||
|
||||
auto *crtc = pipe_->crtc->Get();
|
||||
if (!crtc->GetModeProperty().AtomicSet(*pset, *mode_blob)) {
|
||||
return false;
|
||||
}
|
||||
args.used_kms_objects.blobs.emplace_back(std::move(mode_blob));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DrmAtomicStateManager::SetCtmIfNeeded(drmModeAtomicReq *pset,
|
||||
AtomicCommitArgs &args) {
|
||||
auto *crtc = pipe_->crtc->Get();
|
||||
if (!args.color_matrix || !crtc->GetCtmProperty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto *drm = pipe_->device;
|
||||
auto ctm_blob = drm->RegisterUserPropertyBlob(args.color_matrix.get(),
|
||||
sizeof(drm_color_ctm));
|
||||
if (!ctm_blob) {
|
||||
ALOGE("Failed to create CTM blob");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!crtc->GetCtmProperty().AtomicSet(*pset, *ctm_blob)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
args.used_kms_objects.blobs.emplace_back(std::move(ctm_blob));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DrmAtomicStateManager::SetColorSpaceIfNeeded(drmModeAtomicReq *pset,
|
||||
AtomicCommitArgs &args) {
|
||||
auto *connector = pipe_->connector->Get();
|
||||
if (!args.colorspace || !connector->GetColorspaceProperty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return connector->GetColorspaceProperty()
|
||||
.AtomicSet(*pset,
|
||||
connector->GetColorspacePropertyValue(*args.colorspace));
|
||||
}
|
||||
|
||||
bool DrmAtomicStateManager::SetContentTypeIfNeeded(drmModeAtomicReq *pset,
|
||||
AtomicCommitArgs &args) {
|
||||
auto *connector = pipe_->connector->Get();
|
||||
if (!args.content_type || !connector->GetContentTypeProperty()) {
|
||||
return true;
|
||||
}
|
||||
return connector->GetContentTypeProperty().AtomicSet(*pset,
|
||||
static_cast<uint64_t>(
|
||||
*args.content_type));
|
||||
}
|
||||
|
||||
bool DrmAtomicStateManager::SetHdrMetadataIfNeeded(drmModeAtomicReq *pset,
|
||||
AtomicCommitArgs &args) {
|
||||
auto *connector = pipe_->connector->Get();
|
||||
if (!args.hdr_metadata || !connector->GetHdrOutputMetadataProperty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto *drm = pipe_->device;
|
||||
auto hdr_metadata_blob = drm->RegisterUserPropertyBlob(
|
||||
args.hdr_metadata.get(), sizeof(hdr_output_metadata));
|
||||
if (!hdr_metadata_blob) {
|
||||
ALOGE("Failed to create %s blob",
|
||||
connector->GetHdrOutputMetadataProperty().GetName().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!connector->GetHdrOutputMetadataProperty()
|
||||
.AtomicSet(*pset, *hdr_metadata_blob)) {
|
||||
return false;
|
||||
}
|
||||
args.used_kms_objects.blobs.emplace_back(std::move(hdr_metadata_blob));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DrmAtomicStateManager::SetMinBpcIfNeeded(drmModeAtomicReq *pset,
|
||||
AtomicCommitArgs &args) {
|
||||
auto *connector = pipe_->connector->Get();
|
||||
if (!args.min_bpc || !connector->GetMinBpcProperty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int err = 0;
|
||||
uint64_t range_min = 0;
|
||||
uint64_t range_max = 0;
|
||||
std::tie(err, range_min) = connector->GetMinBpcProperty().RangeMin();
|
||||
if (err != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::tie(err, range_max) = connector->GetMinBpcProperty().RangeMax();
|
||||
if (err != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Adjust requested min bpc to be within the property range
|
||||
int32_t min_bpc_val = std::max(args.min_bpc.value(),
|
||||
static_cast<int32_t>(range_min));
|
||||
min_bpc_val = std::min(min_bpc_val, static_cast<int32_t>(range_max));
|
||||
return connector->GetMinBpcProperty().AtomicSet(*pset, min_bpc_val);
|
||||
}
|
||||
|
||||
bool DrmAtomicStateManager::SetCompositionIfNeeded(drmModeAtomicReq *pset,
|
||||
AtomicCommitArgs &args) {
|
||||
if (!args.composition) {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto unused_planes = args.new_frame_state.used_planes;
|
||||
args.new_frame_state.used_planes.clear();
|
||||
|
||||
for (auto &joining : args.composition->plan) {
|
||||
DrmPlane *plane = joining.plane->Get();
|
||||
LayerData &layer = joining.layer;
|
||||
|
||||
args.used_kms_objects.framebuffers.emplace_back(layer.fb);
|
||||
args.new_frame_state.used_planes.emplace_back(joining.plane);
|
||||
|
||||
/* Remove from 'unused' list, since plane is re-used */
|
||||
auto &v = unused_planes;
|
||||
v.erase(std::remove(v.begin(), v.end(), joining.plane), v.end());
|
||||
|
||||
DrmModeUserPropertyBlobUnique damage_blob;
|
||||
auto *crtc = pipe_->crtc->Get();
|
||||
if (plane->AtomicSetState(*pset, layer, joining.z_pos, crtc->GetId(),
|
||||
whole_display_rect_, damage_blob) != 0) {
|
||||
return false;
|
||||
}
|
||||
args.used_kms_objects.blobs.emplace_back(std::move(damage_blob));
|
||||
}
|
||||
|
||||
return std::all_of(unused_planes.begin(), unused_planes.end(),
|
||||
[&pset](auto &plane) {
|
||||
return plane->Get()->AtomicDisablePlane(*pset) == 0;
|
||||
});
|
||||
}
|
||||
|
||||
DrmModeAtomicReqUnique DrmAtomicStateManager::GetAtomicModeReqForArgs(
|
||||
AtomicCommitArgs &args) {
|
||||
ATRACE_CALL();
|
||||
if (!args.new_frame_state.crtc_active_state) {
|
||||
/* Force activate display */
|
||||
args.active = true;
|
||||
}
|
||||
|
||||
auto pset = MakeDrmModeAtomicReqUnique();
|
||||
if (!pset) {
|
||||
ALOGE("Failed to allocate property set");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!SetWriteBackFenceIfNeeded(pset.get(), args)) {
|
||||
ALOGE("Failed to set writeback fence");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!SetOutputFence(pset.get(), args)) {
|
||||
ALOGE("Failed to set output fence");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!SetActiveIfNeeded(pset.get(), args)) {
|
||||
ALOGE("Failed to set active");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!SetDisplayModeIfNeeded(pset.get(), args)) {
|
||||
ALOGE("Failed to set display mode");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!SetCtmIfNeeded(pset.get(), args)) {
|
||||
ALOGE("Failed to set CTM blob");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!SetColorSpaceIfNeeded(pset.get(), args)) {
|
||||
ALOGE("Failed to set color space");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!SetContentTypeIfNeeded(pset.get(), args)) {
|
||||
ALOGE("Failed to set content type");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!SetHdrMetadataIfNeeded(pset.get(), args)) {
|
||||
ALOGE("Failed to set HDR metadata");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!SetMinBpcIfNeeded(pset.get(), args)) {
|
||||
ALOGE("Failed to set min BPC");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!SetCompositionIfNeeded(pset.get(), args)) {
|
||||
ALOGE("Failed to set composition");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return pset;
|
||||
}
|
||||
|
||||
void DrmAtomicStateManager::ThreadFn() {
|
||||
int tracking_at_the_moment = -1;
|
||||
|
||||
|
|
@ -395,14 +539,7 @@ auto DrmAtomicStateManager::ExecuteAtomicCommit(AtomicCommitArgs &args) -> int {
|
|||
if (err != 0) {
|
||||
ALOGE("Composite failed for pipeline %s",
|
||||
pipe_->connector->Get()->GetName().c_str());
|
||||
// Disable the hw used by the last active composition. This allows us to
|
||||
// signal the release fences from that composition to avoid hanging.
|
||||
AtomicCommitArgs cl_args{};
|
||||
cl_args.composition = std::make_shared<DrmKmsPlan>();
|
||||
if (CommitFrame(cl_args) != 0) {
|
||||
ALOGE("Failed to clean-up active composition for pipeline %s",
|
||||
pipe_->connector->Get()->GetName().c_str());
|
||||
}
|
||||
CleanFailedCommit();
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,24 @@
|
|||
|
||||
namespace android {
|
||||
|
||||
// Collection of kms objects that were committed to the kernel. There must be
|
||||
// a userspace handle to keep these from being removed/unregistered until the
|
||||
// commit that used them is no longer being presented.
|
||||
struct KmsObjects {
|
||||
/* We have to hold a reference to framebuffer while displaying it ,
|
||||
* otherwise picture will blink */
|
||||
std::vector<std::shared_ptr<DrmFbIdHandle>> framebuffers;
|
||||
std::vector<DrmModeUserPropertyBlobUnique> blobs;
|
||||
};
|
||||
|
||||
struct KmsState {
|
||||
/* Required to cleanup unused planes */
|
||||
std::vector<std::shared_ptr<BindingOwner<DrmPlane>>> used_planes;
|
||||
|
||||
/* To avoid setting the inactive state twice, which will fail the commit */
|
||||
bool crtc_active_state{};
|
||||
};
|
||||
|
||||
struct AtomicCommitArgs {
|
||||
/* inputs. All fields are optional, but at least one has to be specified */
|
||||
bool test_only = false;
|
||||
|
|
@ -49,8 +67,15 @@ struct AtomicCommitArgs {
|
|||
SharedFd writeback_release_fence;
|
||||
|
||||
/* out */
|
||||
KmsState new_frame_state;
|
||||
KmsObjects used_kms_objects;
|
||||
SharedFd out_writeback_complete_fence;
|
||||
SharedFd out_fence;
|
||||
// Shared FD can't be initiallized to an invalid value, for now we keep
|
||||
// the address separate from the FD for initialization.
|
||||
// TODO: look into adding support for invalid fences.
|
||||
int wb_fence_address = -1;
|
||||
int out_fence_address = -1;
|
||||
|
||||
/* helpers */
|
||||
auto HasInputs() const -> bool {
|
||||
|
|
@ -68,6 +93,8 @@ class DrmAtomicStateManager {
|
|||
auto ExecuteAtomicCommit(AtomicCommitArgs &args) -> int;
|
||||
auto ActivateDisplayUsingDPMS() -> int;
|
||||
|
||||
void CleanFailedCommit();
|
||||
|
||||
void StopThread() {
|
||||
{
|
||||
const std::lock_guard lock(mutex_);
|
||||
|
|
@ -82,27 +109,31 @@ class DrmAtomicStateManager {
|
|||
DrmAtomicStateManager() = default;
|
||||
int CommitFrame(AtomicCommitArgs &args);
|
||||
|
||||
// Collection of kms objects that were committed to the kernel. There must be
|
||||
// a userspace handle to keep these from being removed/unregistered until the
|
||||
// commit that used them is no longer being presented.
|
||||
struct KmsObjects {
|
||||
/* We have to hold a reference to framebuffer while displaying it ,
|
||||
* otherwise picture will blink */
|
||||
std::vector<std::shared_ptr<DrmFbIdHandle>> framebuffers;
|
||||
std::vector<DrmModeUserPropertyBlobUnique> blobs;
|
||||
};
|
||||
|
||||
struct KmsState {
|
||||
/* Required to cleanup unused planes */
|
||||
std::vector<std::shared_ptr<BindingOwner<DrmPlane>>> used_planes;
|
||||
|
||||
/* To avoid setting the inactive state twice, which will fail the commit */
|
||||
bool crtc_active_state{};
|
||||
};
|
||||
|
||||
// Only accessed from main thread.
|
||||
DrmDisplayPipeline *pipe_{};
|
||||
|
||||
KmsState committed_frame_state_;
|
||||
|
||||
KmsState staged_frame_state_;
|
||||
KmsObjects used_kms_objects_;
|
||||
|
||||
void WaitLastFrame();
|
||||
bool SetWriteBackFenceIfNeeded(drmModeAtomicReq *pset,
|
||||
AtomicCommitArgs &args);
|
||||
bool SetOutputFence(drmModeAtomicReq *pset, AtomicCommitArgs &args);
|
||||
bool SetActiveIfNeeded(drmModeAtomicReq *pset, AtomicCommitArgs &args);
|
||||
bool SetDisplayModeIfNeeded(drmModeAtomicReq *pset, AtomicCommitArgs &args);
|
||||
bool SetCtmIfNeeded(drmModeAtomicReq *pset, AtomicCommitArgs &args);
|
||||
bool SetColorSpaceIfNeeded(drmModeAtomicReq *pset, AtomicCommitArgs &args);
|
||||
bool SetContentTypeIfNeeded(drmModeAtomicReq *pset, AtomicCommitArgs &args);
|
||||
bool SetHdrMetadataIfNeeded(drmModeAtomicReq *pset, AtomicCommitArgs &args);
|
||||
bool SetMinBpcIfNeeded(drmModeAtomicReq *pset, AtomicCommitArgs &args);
|
||||
bool SetCompositionIfNeeded(drmModeAtomicReq *pset, AtomicCommitArgs &args);
|
||||
|
||||
DrmModeAtomicReqUnique GetAtomicModeReqForArgs(AtomicCommitArgs &args);
|
||||
static void CheckDoubleSettingState(AtomicCommitArgs &args,
|
||||
bool crtc_is_active);
|
||||
|
||||
DstRectInfo whole_display_rect_{};
|
||||
|
||||
std::thread thread_;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue