aboutsummaryrefslogtreecommitdiff
path: root/drm
diff options
context:
space:
mode:
authorRoman Stratiienko <roman.o.stratiienko@globallogic.com>2021-09-29 12:59:48 +0300
committerRoman Stratiienko <roman.o.stratiienko@globallogic.com>2021-09-29 12:59:48 +0300
commit0f679aadfe898db7ccd6bf63c55dc57a4f157e7d (patch)
tree6f52d1559540d31c765bd6794a510c4ba0777114 /drm
parent6662f71844b7bcdc1033674cee01e04a6231d391 (diff)
downloaddrm_hwcomposer-0f679aadfe898db7ccd6bf63c55dc57a4f157e7d.tar.gz
drm_hwcomposer: Cleanup DrmPlane::Init()
Adding enum value into map looks ugly. Create a wrapper in order to fix it. Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
Diffstat (limited to 'drm')
-rw-r--r--drm/DrmPlane.cpp61
-rw-r--r--drm/DrmProperty.h20
2 files changed, 41 insertions, 40 deletions
diff --git a/drm/DrmPlane.cpp b/drm/DrmPlane.cpp
index d143a88..6720dd0 100644
--- a/drm/DrmPlane.cpp
+++ b/drm/DrmPlane.cpp
@@ -37,7 +37,6 @@ DrmPlane::DrmPlane(DrmDevice *drm, drmModePlanePtr p)
}
int DrmPlane::Init() {
- uint64_t enum_value = UINT64_MAX;
DrmProperty p;
int ret = drm_->GetPlaneProperty(*this, "type", &p);
@@ -137,20 +136,12 @@ int DrmPlane::Init() {
ret = drm_->GetPlaneProperty(*this, "pixel blend mode", &blend_property_);
if (ret == 0) {
- std::tie(enum_value,
- ret) = blend_property_.GetEnumValueWithName("Pre-multiplied");
- if (ret == 0) {
- blending_enum_map_[DrmHwcBlending::kPreMult] = enum_value;
- }
- std::tie(enum_value,
- ret) = blend_property_.GetEnumValueWithName("Coverage");
- if (ret == 0) {
- blending_enum_map_[DrmHwcBlending::kCoverage] = enum_value;
- }
- std::tie(enum_value, ret) = blend_property_.GetEnumValueWithName("None");
- if (ret == 0) {
- blending_enum_map_[DrmHwcBlending::kNone] = enum_value;
- }
+ blend_property_.AddEnumToMap("Pre-multiplied", DrmHwcBlending::kPreMult,
+ blending_enum_map_);
+ blend_property_.AddEnumToMap("Coverage", DrmHwcBlending::kCoverage,
+ blending_enum_map_);
+ blend_property_.AddEnumToMap("None", DrmHwcBlending::kNone,
+ blending_enum_map_);
} else {
ALOGI("Could not get pixel blend mode property");
}
@@ -163,37 +154,27 @@ int DrmPlane::Init() {
ret = drm_->GetPlaneProperty(*this, "COLOR_ENCODING",
&color_encoding_propery_);
if (ret == 0) {
- std::tie(enum_value, ret) = color_encoding_propery_.GetEnumValueWithName(
- "ITU-R BT.709 YCbCr");
- if (ret == 0) {
- color_encoding_enum_map_[DrmHwcColorSpace::kItuRec709] = enum_value;
- }
- std::tie(enum_value, ret) = color_encoding_propery_.GetEnumValueWithName(
- "ITU-R BT.601 YCbCr");
- if (ret == 0) {
- color_encoding_enum_map_[DrmHwcColorSpace::kItuRec601] = enum_value;
- }
- std::tie(enum_value, ret) = color_encoding_propery_.GetEnumValueWithName(
- "ITU-R BT.2020 YCbCr");
- if (ret == 0) {
- color_encoding_enum_map_[DrmHwcColorSpace::kItuRec2020] = enum_value;
- }
+ color_encoding_propery_.AddEnumToMap("ITU-R BT.709 YCbCr",
+ DrmHwcColorSpace::kItuRec709,
+ color_encoding_enum_map_);
+ color_encoding_propery_.AddEnumToMap("ITU-R BT.601 YCbCr",
+ DrmHwcColorSpace::kItuRec601,
+ color_encoding_enum_map_);
+ color_encoding_propery_.AddEnumToMap("ITU-R BT.2020 YCbCr",
+ DrmHwcColorSpace::kItuRec2020,
+ color_encoding_enum_map_);
} else {
ALOGI("Could not get COLOR_ENCODING property");
}
ret = drm_->GetPlaneProperty(*this, "COLOR_RANGE", &color_range_property_);
if (ret == 0) {
- std::tie(enum_value, ret) = color_range_property_.GetEnumValueWithName(
- "YCbCr full range");
- if (ret == 0) {
- color_range_enum_map_[DrmHwcSampleRange::kFullRange] = enum_value;
- }
- std::tie(enum_value, ret) = color_range_property_.GetEnumValueWithName(
- "YCbCr limited range");
- if (ret == 0) {
- color_range_enum_map_[DrmHwcSampleRange::kLimitedRange] = enum_value;
- }
+ color_range_property_.AddEnumToMap("YCbCr full range",
+ DrmHwcSampleRange::kFullRange,
+ color_range_enum_map_);
+ color_range_property_.AddEnumToMap("YCbCr limited range",
+ DrmHwcSampleRange::kLimitedRange,
+ color_range_enum_map_);
} else {
ALOGI("Could not get COLOR_RANGE property");
}
diff --git a/drm/DrmProperty.h b/drm/DrmProperty.h
index 8db480a..68f300f 100644
--- a/drm/DrmProperty.h
+++ b/drm/DrmProperty.h
@@ -20,6 +20,7 @@
#include <stdint.h>
#include <xf86drmMode.h>
+#include <map>
#include <string>
#include <vector>
@@ -57,6 +58,10 @@ class DrmProperty {
[[nodiscard]] auto AtomicSet(drmModeAtomicReq &pset, uint64_t value) const
-> bool;
+ template <class E>
+ auto AddEnumToMap(const std::string &name, E key, std::map<E, uint64_t> &map)
+ -> bool;
+
operator bool() const {
return id_ != 0;
}
@@ -83,6 +88,21 @@ class DrmProperty {
std::vector<DrmPropertyEnum> enums_;
std::vector<uint32_t> blob_ids_;
};
+
+template <class E>
+auto DrmProperty::AddEnumToMap(const std::string &name, E key,
+ std::map<E, uint64_t> &map) -> bool {
+ uint64_t enum_value = UINT64_MAX;
+ int err = 0;
+ std::tie(enum_value, err) = GetEnumValueWithName(name);
+ if (err == 0) {
+ map[key] = enum_value;
+ return true;
+ }
+
+ return false;
+}
+
} // namespace android
#endif // ANDROID_DRM_PROPERTY_H_