drm_hwcomposer: Improve handling of blending mode
1. Convert to DrmHwcBlending inside HWC hook.
2. Use map for enum_values for cleaner atomic commit preparation.
Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
diff --git a/drm/DrmPlane.cpp b/drm/DrmPlane.cpp
index 78013fb..78b650c 100644
--- a/drm/DrmPlane.cpp
+++ b/drm/DrmPlane.cpp
@@ -136,8 +136,24 @@
ALOGI("Could not get alpha property");
ret = drm_->GetPlaneProperty(*this, "pixel blend mode", &blend_property_);
- if (ret)
+ 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;
+ }
+ } else {
ALOGI("Could not get pixel blend mode property");
+ }
ret = drm_->GetPlaneProperty(*this, "IN_FENCE_FD", &in_fence_fd_property_);
if (ret)
@@ -231,34 +247,10 @@
return false;
}
- if (blend_property_.id() == 0) {
- if ((layer->blending != DrmHwcBlending::kNone) &&
- (layer->blending != DrmHwcBlending::kPreMult)) {
- ALOGV("Blending is not supported on plane %d", id_);
- return false;
- }
- } else {
- int ret = 0;
-
- switch (layer->blending) {
- case DrmHwcBlending::kPreMult:
- std::tie(std::ignore,
- ret) = blend_property_.GetEnumValueWithName("Pre-multiplied");
- break;
- case DrmHwcBlending::kCoverage:
- std::tie(std::ignore,
- ret) = blend_property_.GetEnumValueWithName("Coverage");
- break;
- case DrmHwcBlending::kNone:
- default:
- std::tie(std::ignore,
- ret) = blend_property_.GetEnumValueWithName("None");
- break;
- }
- if (ret) {
- ALOGV("Expected a valid blend mode on plane %d", id_);
- return false;
- }
+ if (blending_enum_map_.count(layer->blending) == 0 &&
+ layer->blending != DrmHwcBlending::kNone) {
+ ALOGV("Blending is not supported on plane %d", id_);
+ return false;
}
uint32_t format = layer->buffer_info.format;
@@ -289,14 +281,12 @@
auto DrmPlane::AtomicSetState(drmModeAtomicReq &pset, DrmHwcLayer &layer,
uint32_t zpos, uint32_t crtc_id) -> int {
- int ret = 0;
uint32_t fb_id = UINT32_MAX;
int fence_fd = -1;
hwc_rect_t display_frame;
hwc_frect_t source_crop;
uint64_t rotation = 0;
uint64_t alpha = 0xFFFF;
- uint64_t blend = UINT64_MAX;
if (!layer.FbIdHandle) {
ALOGE("Expected a valid framebuffer for pset");
@@ -317,22 +307,6 @@
return 0;
}
- if (blend_property_) {
- switch (layer.blending) {
- case DrmHwcBlending::kPreMult:
- std::tie(blend,
- ret) = blend_property_.GetEnumValueWithName("Pre-multiplied");
- break;
- case DrmHwcBlending::kCoverage:
- std::tie(blend, ret) = blend_property_.GetEnumValueWithName("Coverage");
- break;
- case DrmHwcBlending::kNone:
- default:
- std::tie(blend, ret) = blend_property_.GetEnumValueWithName("None");
- break;
- }
- }
-
if (zpos_property_ && !zpos_property_.is_immutable()) {
uint64_t min_zpos = 0;
@@ -395,10 +369,9 @@
}
}
- if (blend_property_ && blend != UINT64_MAX) {
- if (!blend_property_.AtomicSet(pset, blend)) {
- return -EINVAL;
- }
+ if (blending_enum_map_.count(layer.blending) != 0 &&
+ !blend_property_.AtomicSet(pset, blending_enum_map_[layer.blending])) {
+ return -EINVAL;
}
if (color_encoding_enum_map_.count(layer.color_space) != 0 &&
diff --git a/drm/DrmPlane.h b/drm/DrmPlane.h
index ee619b8..5782532 100644
--- a/drm/DrmPlane.h
+++ b/drm/DrmPlane.h
@@ -81,6 +81,7 @@
DrmProperty color_encoding_propery_;
DrmProperty color_range_property_;
+ std::map<DrmHwcBlending, uint64_t> blending_enum_map_;
std::map<DrmHwcColorSpace, uint64_t> color_encoding_enum_map_;
std::map<DrmHwcSampleRange, uint64_t> color_range_enum_map_;
};