drm_hwcomposer: Use layer alpha to blend planes
Send the layer alpha to the drm plane's alpha property to
properly blend layers.
BUG=b/24821110
TEST=Tested on smaug with Downloads/About windows, blend properly
Change-Id: If96eb28d65d018863c39bc5a3554daef0264144b
Signed-off-by: Sean Paul <seanpaul@chromium.org>
diff --git a/drmdisplaycompositor.cpp b/drmdisplaycompositor.cpp
index 9f349c0..4a0d296 100644
--- a/drmdisplaycompositor.cpp
+++ b/drmdisplaycompositor.cpp
@@ -429,6 +429,7 @@
DrmHwcRect<int> display_frame;
DrmHwcRect<float> source_crop;
uint64_t rotation = 0;
+ uint64_t alpha = 0xFF;
switch (comp_plane.source_layer) {
case DrmCompositionPlane::kSourceNone:
break;
@@ -475,6 +476,8 @@
fb_id = layer.buffer->fb_id;
display_frame = layer.display_frame;
source_crop = layer.source_crop;
+ if (layer.blending == DrmHwcBlending::kPreMult)
+ alpha = layer.alpha;
switch (layer.transform) {
case DrmHwcTransform::kFlipH:
rotation = 1 << DRM_REFLECT_X;
@@ -521,6 +524,13 @@
break;
}
+ // TODO: Once we have atomic test, this should fall back to GL
+ if (alpha != 0xFF && plane->alpha_property().id() == 0) {
+ ALOGE("Alpha is not supported on plane %d", plane->id());
+ ret = -EINVAL;
+ break;
+ }
+
ret =
drmModePropertySetAdd(pset, plane->id(), plane->crtc_property().id(),
crtc->id()) ||
@@ -558,6 +568,16 @@
break;
}
}
+
+ if (plane->alpha_property().id()) {
+ ret = drmModePropertySetAdd(pset, plane->id(),
+ plane->alpha_property().id(), alpha);
+ if (ret) {
+ ALOGE("Failed to add alpha property %d to plane %d",
+ plane->alpha_property().id(), plane->id());
+ break;
+ }
+ }
}
out:
diff --git a/drmplane.cpp b/drmplane.cpp
index 3f17d7c..5785d5a 100644
--- a/drmplane.cpp
+++ b/drmplane.cpp
@@ -124,6 +124,10 @@
if (ret)
ALOGE("Could not get rotation property");
+ ret = drm_->GetPlaneProperty(*this, "alpha", &alpha_property_);
+ if (ret)
+ ALOGI("Could not get alpha property");
+
return 0;
}
@@ -182,4 +186,8 @@
const DrmProperty &DrmPlane::rotation_property() const {
return rotation_property_;
}
+
+const DrmProperty &DrmPlane::alpha_property() const {
+ return alpha_property_;
+}
}
diff --git a/drmplane.h b/drmplane.h
index 1969d52..ff3380f 100644
--- a/drmplane.h
+++ b/drmplane.h
@@ -52,6 +52,7 @@
const DrmProperty &src_w_property() const;
const DrmProperty &src_h_property() const;
const DrmProperty &rotation_property() const;
+ const DrmProperty &alpha_property() const;
private:
DrmPlane(const DrmPlane &);
@@ -74,6 +75,7 @@
DrmProperty src_w_property_;
DrmProperty src_h_property_;
DrmProperty rotation_property_;
+ DrmProperty alpha_property_;
};
}