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: