1
0
Fork 0

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>
This commit is contained in:
Roman Stratiienko 2021-09-29 12:59:48 +03:00
parent 6662f71844
commit 0f679aadfe
2 changed files with 41 additions and 40 deletions

View file

@ -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");
}

View file

@ -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_