OSDN Git Service

drm_hwcomposer: Use layer alpha to blend planes
authorSean Paul <seanpaul@chromium.org>
Thu, 15 Oct 2015 19:17:31 +0000 (15:17 -0400)
committerSean Paul <seanpaul@chromium.org>
Thu, 15 Oct 2015 20:59:45 +0000 (16:59 -0400)
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>
drmdisplaycompositor.cpp
drmplane.cpp
drmplane.h

index 9f349c0..4a0d296 100644 (file)
@@ -429,6 +429,7 @@ int DrmDisplayCompositor::ApplyFrame(DrmDisplayComposition *display_comp) {
     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 @@ int DrmDisplayCompositor::ApplyFrame(DrmDisplayComposition *display_comp) {
         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 @@ int DrmDisplayCompositor::ApplyFrame(DrmDisplayComposition *display_comp) {
       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 @@ int DrmDisplayCompositor::ApplyFrame(DrmDisplayComposition *display_comp) {
         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:
index 3f17d7c..5785d5a 100644 (file)
@@ -124,6 +124,10 @@ int DrmPlane::Init() {
   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::src_h_property() const {
 const DrmProperty &DrmPlane::rotation_property() const {
   return rotation_property_;
 }
+
+const DrmProperty &DrmPlane::alpha_property() const {
+  return alpha_property_;
+}
 }
index 1969d52..ff3380f 100644 (file)
@@ -52,6 +52,7 @@ class DrmPlane {
   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 @@ class DrmPlane {
   DrmProperty src_w_property_;
   DrmProperty src_h_property_;
   DrmProperty rotation_property_;
+  DrmProperty alpha_property_;
 };
 }