drm_hwcomposer: Cleanup DRM atomic commit
Create and use DrmPlane::AtomicSet() wrapper.
Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
diff --git a/drm/DrmDevice.cpp b/drm/DrmDevice.cpp
index bd4b1e4..01327f8 100644
--- a/drm/DrmDevice.cpp
+++ b/drm/DrmDevice.cpp
@@ -547,7 +547,7 @@
for (int i = 0; !found && (size_t)i < props->count_props; ++i) {
drmModePropertyPtr p = drmModeGetProperty(fd(), props->props[i]);
if (!strcmp(p->name, prop_name)) {
- property->Init(p, props->prop_values[i]);
+ property->Init(obj_id, p, props->prop_values[i]);
found = true;
}
drmModeFreeProperty(p);
diff --git a/drm/DrmProperty.cpp b/drm/DrmProperty.cpp
index 8e6f7e5..32f1c62 100644
--- a/drm/DrmProperty.cpp
+++ b/drm/DrmProperty.cpp
@@ -14,6 +14,9 @@
* limitations under the License.
*/
+// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
+#define LOG_TAG "hwc-drm-property"
+
#include "DrmProperty.h"
#include <xf86drmMode.h>
@@ -23,6 +26,7 @@
#include <string>
#include "DrmDevice.h"
+#include "utils/log.h"
namespace android {
@@ -30,11 +34,13 @@
: value_(e->value), name_(e->name) {
}
-DrmProperty::DrmProperty(drmModePropertyPtr p, uint64_t value) {
- Init(p, value);
+DrmProperty::DrmProperty(uint32_t obj_id, drmModePropertyPtr p,
+ uint64_t value) {
+ Init(obj_id, p, value);
}
-void DrmProperty::Init(drmModePropertyPtr p, uint64_t value) {
+void DrmProperty::Init(uint32_t obj_id, drmModePropertyPtr p, uint64_t value) {
+ obj_id_ = obj_id;
id_ = p->prop_id;
flags_ = p->flags;
name_ = p->name;
@@ -131,4 +137,19 @@
return std::make_tuple(UINT64_MAX, -EINVAL);
}
+
+auto DrmProperty::AtomicSet(drmModeAtomicReq &pset, uint64_t value) const
+ -> bool {
+ if (id_ == 0) {
+ ALOGE("AtomicSet() is called on non-initialized property!");
+ return false;
+ }
+ if (drmModeAtomicAddProperty(&pset, obj_id_, id_, value) < 0) {
+ ALOGE("Failed to add obj_id: %u, prop_id: %u (%s) to pset", obj_id_, id_,
+ name_.c_str());
+ return false;
+ }
+ return true;
+}
+
} // namespace android
diff --git a/drm/DrmProperty.h b/drm/DrmProperty.h
index 70678fd..8db480a 100644
--- a/drm/DrmProperty.h
+++ b/drm/DrmProperty.h
@@ -37,11 +37,11 @@
class DrmProperty {
public:
DrmProperty() = default;
- DrmProperty(drmModePropertyPtr p, uint64_t value);
+ DrmProperty(uint32_t obj_id, drmModePropertyPtr p, uint64_t value);
DrmProperty(const DrmProperty &) = delete;
DrmProperty &operator=(const DrmProperty &) = delete;
- void Init(drmModePropertyPtr p, uint64_t value);
+ auto Init(uint32_t obj_id, drmModePropertyPtr p, uint64_t value) -> void;
std::tuple<uint64_t, int> GetEnumValueWithName(const std::string &name) const;
uint32_t id() const;
@@ -54,6 +54,13 @@
std::tuple<int, uint64_t> range_min() const;
std::tuple<int, uint64_t> range_max() const;
+ [[nodiscard]] auto AtomicSet(drmModeAtomicReq &pset, uint64_t value) const
+ -> bool;
+
+ operator bool() const {
+ return id_ != 0;
+ }
+
private:
class DrmPropertyEnum {
public:
@@ -64,6 +71,7 @@
std::string name_;
};
+ uint32_t obj_id_ = 0;
uint32_t id_ = 0;
DrmPropertyType type_ = DRM_PROPERTY_TYPE_INVALID;