aboutsummaryrefslogtreecommitdiff
path: root/drm
diff options
context:
space:
mode:
authorRoman Stratiienko <roman.o.stratiienko@globallogic.com>2022-02-09 17:40:35 +0200
committerRoman Stratiienko <roman.o.stratiienko@globallogic.com>2022-02-09 17:40:35 +0200
commit4e994055a3625e822dc04e659a1feba3017fffe6 (patch)
tree01e404ea2342b5fdd1279c2d40c4472305ed7f3a /drm
parentef5348b7a53ee7fc169956a95d959c2823aaf478 (diff)
downloaddrm_hwcomposer-4e994055a3625e822dc04e659a1feba3017fffe6.tar.gz
drm_hwcomposer: Rename DrmDisplayCompositor->DrmAtomicStateManager
Primary responsibilities of this class are: 1. Send composition/mode/active state over DRM atomic commit IOCTL to the kernel 2. Track commit state and keep planes owned by the Pipeline while they are either displayed or staged for displaying. 3. Keep framebuffers alive while they are in use or staged. Not much related to composition itself, therefore rename it to DrmAtomicStateManager and move it to drm folder. Bump clang-tidy level of DrmAtomicStateManager.c to normal by fixing minor clang-tidy findings. Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
Diffstat (limited to 'drm')
-rw-r--r--drm/DrmAtomicStateManager.cpp191
-rw-r--r--drm/DrmAtomicStateManager.h89
-rw-r--r--drm/DrmDevice.cpp2
-rw-r--r--drm/DrmDisplayPipeline.cpp5
-rw-r--r--drm/DrmDisplayPipeline.h4
-rw-r--r--drm/ResourceManager.cpp2
6 files changed, 287 insertions, 6 deletions
diff --git a/drm/DrmAtomicStateManager.cpp b/drm/DrmAtomicStateManager.cpp
new file mode 100644
index 0000000..65fb19e
--- /dev/null
+++ b/drm/DrmAtomicStateManager.cpp
@@ -0,0 +1,191 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define ATRACE_TAG ATRACE_TAG_GRAPHICS
+#define LOG_TAG "hwc-drm-atomic-state-manager"
+
+#include "DrmAtomicStateManager.h"
+
+#include <drm/drm_mode.h>
+#include <pthread.h>
+#include <sched.h>
+#include <sync/sync.h>
+#include <utils/Trace.h>
+
+#include <array>
+#include <cstdlib>
+#include <ctime>
+#include <sstream>
+#include <vector>
+
+#include "drm/DrmCrtc.h"
+#include "drm/DrmDevice.h"
+#include "drm/DrmPlane.h"
+#include "drm/DrmUnique.h"
+#include "utils/log.h"
+
+namespace android {
+
+// NOLINTNEXTLINE (readability-function-cognitive-complexity): Fixme
+auto DrmAtomicStateManager::CommitFrame(AtomicCommitArgs &args) -> int {
+ ATRACE_CALL();
+
+ if (args.active && *args.active == active_frame_state_.crtc_active_state) {
+ /* Don't set the same state twice */
+ args.active.reset();
+ }
+
+ if (!args.HasInputs()) {
+ /* nothing to do */
+ return 0;
+ }
+
+ if (!active_frame_state_.crtc_active_state) {
+ /* Force activate display */
+ args.active = true;
+ }
+
+ auto new_frame_state = NewFrameState();
+
+ auto *drm = pipe_->device;
+ auto *connector = pipe_->connector->Get();
+ auto *crtc = pipe_->crtc->Get();
+
+ auto pset = MakeDrmModeAtomicReqUnique();
+ if (!pset) {
+ ALOGE("Failed to allocate property set");
+ return -ENOMEM;
+ }
+
+ int64_t out_fence = -1;
+ if (crtc->GetOutFencePtrProperty() &&
+ !crtc->GetOutFencePtrProperty().AtomicSet(*pset, uint64_t(&out_fence))) {
+ return -EINVAL;
+ }
+
+ if (args.active) {
+ 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.display_mode) {
+ new_frame_state.mode_blob = args.display_mode.value().CreateModeBlob(*drm);
+
+ if (!new_frame_state.mode_blob) {
+ ALOGE("Failed to create mode_blob");
+ return -EINVAL;
+ }
+
+ if (!crtc->GetModeProperty().AtomicSet(*pset, *new_frame_state.mode_blob)) {
+ return -EINVAL;
+ }
+ }
+
+ auto unused_planes = new_frame_state.used_planes;
+
+ if (args.composition) {
+ new_frame_state.used_framebuffers.clear();
+ new_frame_state.used_planes.clear();
+
+ for (auto &joining : args.composition->plan) {
+ DrmPlane *plane = joining.plane->Get();
+ DrmHwcLayer &layer = joining.layer;
+
+ new_frame_state.used_framebuffers.emplace_back(layer.fb_id_handle);
+ 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());
+
+ if (plane->AtomicSetState(*pset, layer, joining.z_pos, crtc->GetId()) !=
+ 0) {
+ return -EINVAL;
+ }
+ }
+ }
+
+ if (args.composition) {
+ for (auto &plane : unused_planes) {
+ if (plane->Get()->AtomicDisablePlane(*pset) != 0) {
+ return -EINVAL;
+ }
+ }
+ }
+
+ uint32_t flags = DRM_MODE_ATOMIC_ALLOW_MODESET;
+ if (args.test_only)
+ flags |= DRM_MODE_ATOMIC_TEST_ONLY;
+
+ int err = drmModeAtomicCommit(drm->GetFd(), pset.get(), flags, drm);
+ if (err != 0) {
+ if (!args.test_only)
+ ALOGE("Failed to commit pset ret=%d\n", err);
+ return err;
+ }
+
+ if (!args.test_only) {
+ if (args.display_mode) {
+ /* TODO(nobody): we still need this for synthetic vsync, remove after
+ * vsync reworked */
+ connector->SetActiveMode(*args.display_mode);
+ }
+
+ active_frame_state_ = std::move(new_frame_state);
+
+ if (crtc->GetOutFencePtrProperty()) {
+ args.out_fence = UniqueFd((int)out_fence);
+ }
+ }
+
+ return 0;
+}
+
+auto DrmAtomicStateManager::ExecuteAtomicCommit(AtomicCommitArgs &args) -> int {
+ int err = CommitFrame(args);
+
+ if (!args.test_only) {
+ 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());
+ }
+ return err;
+ }
+ }
+
+ return err;
+} // namespace android
+
+auto DrmAtomicStateManager::ActivateDisplayUsingDPMS() -> int {
+ return drmModeConnectorSetProperty(pipe_->device->GetFd(),
+ pipe_->connector->Get()->GetId(),
+ pipe_->connector->Get()
+ ->GetDpmsProperty()
+ .id(),
+ DRM_MODE_DPMS_ON);
+}
+
+} // namespace android
diff --git a/drm/DrmAtomicStateManager.h b/drm/DrmAtomicStateManager.h
new file mode 100644
index 0000000..08a1c13
--- /dev/null
+++ b/drm/DrmAtomicStateManager.h
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_DRM_ATOMIC_STATE_MANAGER_H_
+#define ANDROID_DRM_ATOMIC_STATE_MANAGER_H_
+
+#include <pthread.h>
+
+#include <functional>
+#include <memory>
+#include <optional>
+#include <sstream>
+#include <tuple>
+
+#include "compositor/DrmKmsPlan.h"
+#include "drm/DrmPlane.h"
+#include "drm/ResourceManager.h"
+#include "drm/VSyncWorker.h"
+#include "drmhwcomposer.h"
+
+namespace android {
+
+struct AtomicCommitArgs {
+ /* inputs. All fields are optional, but at least one has to be specified */
+ bool test_only = false;
+ std::optional<DrmMode> display_mode;
+ std::optional<bool> active;
+ std::shared_ptr<DrmKmsPlan> composition;
+
+ /* out */
+ UniqueFd out_fence;
+
+ /* helpers */
+ auto HasInputs() -> bool {
+ return display_mode || active || composition;
+ }
+};
+
+class DrmAtomicStateManager {
+ public:
+ explicit DrmAtomicStateManager(DrmDisplayPipeline *pipe) : pipe_(pipe){};
+ DrmAtomicStateManager(const DrmAtomicStateManager &) = delete;
+ ~DrmAtomicStateManager() = default;
+
+ auto ExecuteAtomicCommit(AtomicCommitArgs &args) -> int;
+ auto ActivateDisplayUsingDPMS() -> int;
+
+ private:
+ auto CommitFrame(AtomicCommitArgs &args) -> int;
+
+ struct KmsState {
+ /* Required to cleanup unused planes */
+ std::vector<std::shared_ptr<BindingOwner<DrmPlane>>> used_planes;
+ /* We have to hold a reference to framebuffer while displaying it ,
+ * otherwise picture will blink */
+ std::vector<std::shared_ptr<DrmFbIdHandle>> used_framebuffers;
+
+ DrmModeUserPropertyBlobUnique mode_blob;
+
+ /* To avoid setting the inactive state twice, which will fail the commit */
+ bool crtc_active_state{};
+ } active_frame_state_;
+
+ auto NewFrameState() -> KmsState {
+ return (KmsState){
+ .used_planes = active_frame_state_.used_planes,
+ .used_framebuffers = active_frame_state_.used_framebuffers,
+ .crtc_active_state = active_frame_state_.crtc_active_state,
+ };
+ }
+
+ DrmDisplayPipeline *const pipe_;
+};
+} // namespace android
+
+#endif // ANDROID_DRM_DISPLAY_COMPOSITOR_H_
diff --git a/drm/DrmDevice.cpp b/drm/DrmDevice.cpp
index e5f41e8..fd4589e 100644
--- a/drm/DrmDevice.cpp
+++ b/drm/DrmDevice.cpp
@@ -26,7 +26,7 @@
#include <cstdint>
#include <string>
-#include "compositor/DrmDisplayCompositor.h"
+#include "drm/DrmAtomicStateManager.h"
#include "drm/DrmPlane.h"
#include "utils/log.h"
#include "utils/properties.h"
diff --git a/drm/DrmDisplayPipeline.cpp b/drm/DrmDisplayPipeline.cpp
index 31bc764..f993d28 100644
--- a/drm/DrmDisplayPipeline.cpp
+++ b/drm/DrmDisplayPipeline.cpp
@@ -18,12 +18,12 @@
#include "DrmDisplayPipeline.h"
+#include "DrmAtomicStateManager.h"
#include "DrmConnector.h"
#include "DrmCrtc.h"
#include "DrmDevice.h"
#include "DrmEncoder.h"
#include "DrmPlane.h"
-#include "compositor/DrmDisplayCompositor.h"
#include "utils/log.h"
#include "utils/properties.h"
@@ -98,7 +98,8 @@ static auto TryCreatePipeline(DrmDevice &dev, DrmConnector &connector,
return {};
}
- pipe->compositor = std::make_unique<DrmDisplayCompositor>(pipe.get());
+ pipe->atomic_state_manager = std::make_unique<DrmAtomicStateManager>(
+ pipe.get());
return pipe;
}
diff --git a/drm/DrmDisplayPipeline.h b/drm/DrmDisplayPipeline.h
index f055c85..7ec619e 100644
--- a/drm/DrmDisplayPipeline.h
+++ b/drm/DrmDisplayPipeline.h
@@ -27,7 +27,7 @@ class DrmDevice;
class DrmPlane;
class DrmCrtc;
class DrmEncoder;
-class DrmDisplayCompositor;
+class DrmAtomicStateManager;
struct DrmDisplayPipeline;
@@ -82,7 +82,7 @@ struct DrmDisplayPipeline {
std::shared_ptr<BindingOwner<DrmCrtc>> crtc;
std::shared_ptr<BindingOwner<DrmPlane>> primary_plane;
- std::unique_ptr<DrmDisplayCompositor> compositor;
+ std::unique_ptr<DrmAtomicStateManager> atomic_state_manager;
};
} // namespace android
diff --git a/drm/ResourceManager.cpp b/drm/ResourceManager.cpp
index b294180..c8235e9 100644
--- a/drm/ResourceManager.cpp
+++ b/drm/ResourceManager.cpp
@@ -25,7 +25,7 @@
#include <sstream>
#include "bufferinfo/BufferInfoGetter.h"
-#include "compositor/DrmDisplayCompositor.h"
+#include "drm/DrmAtomicStateManager.h"
#include "drm/DrmDevice.h"
#include "drm/DrmDisplayPipeline.h"
#include "drm/DrmPlane.h"