Ann: support alpha setting on primary and sprite plane

BZ: 179926

From HWC_DEVICE_API_VERSION_1_2, it needs HWC to support planeAlpha.
Ann HW has the ability to support const plane alpha, and this is the
HWC patch to add primary/sprite plane alpha support.

For overlay plane, our HWC implementation now does not support layers
with HWC_BLENDING_PREMULT/HWC_BLENDING_COVERAGE goes through HW overlay,
so this patch does not add const alpha support for overlay plane.

This patch needs to co-work with kernel patch
(https://android.intel.com/#/c/176482/).

Change-Id: Ie28b76ce525e6f580c176759ef43e7008ff83d80
Signed-off-by: Tan Wei <weix.z.tan@intel.com>
diff --git a/ips/anniedale/AnnDisplayPlane.cpp b/ips/anniedale/AnnDisplayPlane.cpp
index 2fb41f5..b20818b 100644
--- a/ips/anniedale/AnnDisplayPlane.cpp
+++ b/ips/anniedale/AnnDisplayPlane.cpp
@@ -84,6 +84,13 @@
     mRealPlane->setTransform(transform);
 }
 
+void AnnDisplayPlane::setPlaneAlpha(uint8_t alpha, uint32_t blending)
+{
+    RETURN_VOID_IF_NO_REAL_PLANE();
+
+    mRealPlane->setPlaneAlpha(alpha, blending);
+}
+
 bool AnnDisplayPlane::setDataBuffer(uint32_t handle)
 {
     RETURN_FALSE_IF_NO_REAL_PLANE();
diff --git a/ips/anniedale/AnnDisplayPlane.h b/ips/anniedale/AnnDisplayPlane.h
index 8491e14..2662057 100644
--- a/ips/anniedale/AnnDisplayPlane.h
+++ b/ips/anniedale/AnnDisplayPlane.h
@@ -46,6 +46,7 @@
     void setPosition(int x, int y, int w, int h);
     void setSourceCrop(int x, int y, int w, int h);
     void setTransform(int transform);
+    void setPlaneAlpha(uint8_t alpha, uint32_t blending);
 
     // data source
     bool setDataBuffer(uint32_t handle);
diff --git a/ips/anniedale/AnnRGBPlane.cpp b/ips/anniedale/AnnRGBPlane.cpp
index 93729a3..8fd2615 100644
--- a/ips/anniedale/AnnRGBPlane.cpp
+++ b/ips/anniedale/AnnRGBPlane.cpp
@@ -120,6 +120,7 @@
     uint32_t spriteFormat;
     uint32_t stride;
     uint32_t linoff;
+    uint32_t planeAlpha;
 
     CTRACE();
 
@@ -157,6 +158,14 @@
     else
         mContext.type = DC_PRIMARY_PLANE;
 
+    // setup plane alpha
+    if (0 < mPlaneAlpha && mPlaneAlpha < 0xff) {
+       planeAlpha = mPlaneAlpha | 0x80000000;
+    } else {
+       // disable plane alpha to offload HW
+       planeAlpha = 0xff;
+    }
+
     mContext.ctx.sp_ctx.index = mIndex;
     mContext.ctx.sp_ctx.pipe = mDevice;
     mContext.ctx.sp_ctx.cntr = spriteFormat | 0x80000000;
@@ -175,16 +184,18 @@
     mContext.ctx.sp_ctx.pos = (dstY & 0xfff) << 16 | (dstX & 0xfff);
     mContext.ctx.sp_ctx.size =
         ((dstH - 1) & 0xfff) << 16 | ((dstW - 1) & 0xfff);
+    mContext.ctx.sp_ctx.contalpa = planeAlpha;
     mContext.ctx.sp_ctx.update_mask = SPRITE_UPDATE_ALL;
 
     VTRACE("type = %d, index = %d, cntr = %#x, linoff = %#x, stride = %#x,"
-          "surf = %#x, pos = %#x, size = %#x", mType, mIndex,
+          "surf = %#x, pos = %#x, size = %#x, contalpa = %#x", mType, mIndex,
           mContext.ctx.sp_ctx.cntr,
           mContext.ctx.sp_ctx.linoff,
           mContext.ctx.sp_ctx.stride,
           mContext.ctx.sp_ctx.surf,
           mContext.ctx.sp_ctx.pos,
-          mContext.ctx.sp_ctx.size);
+          mContext.ctx.sp_ctx.size,
+          mContext.ctx.sp_ctx.contalpa);
     return true;
 }
 
@@ -249,6 +260,7 @@
 void AnnRGBPlane::setFramebufferTarget(uint32_t handle)
 {
     uint32_t stride;
+    uint32_t planeAlpha;
 
     CTRACE();
 
@@ -270,6 +282,13 @@
 
     stride = align_to((4 * align_to(mPosition.w, 32)), 64);
 
+    if (0 < mPlaneAlpha && mPlaneAlpha < 0xff) {
+       planeAlpha = mPlaneAlpha | 0x80000000;
+    } else {
+       // disable plane alpha to offload HW
+       planeAlpha = 0xff;
+    }
+
     // FIXME: use sprite context for sprite plane
     mContext.ctx.prim_ctx.update_mask = SPRITE_UPDATE_ALL;
     mContext.ctx.prim_ctx.index = mIndex;
@@ -281,18 +300,20 @@
     mContext.ctx.prim_ctx.size =
         ((mPosition.h - 1) & 0xfff) << 16 | ((mPosition.w - 1) & 0xfff);
     mContext.ctx.prim_ctx.surf = 0;
+    mContext.ctx.prim_ctx.contalpa = planeAlpha;
     mContext.ctx.prim_ctx.cntr = PixelFormat::PLANE_PIXEL_FORMAT_BGRA8888;
     mContext.ctx.prim_ctx.cntr |= (0x1 << 23);
     mContext.ctx.prim_ctx.cntr |= 0x80000000;
 
     VTRACE("type = %d, index = %d, cntr = %#x, linoff = %#x, stride = %#x,"
-          "surf = %#x, pos = %#x, size = %#x", mType, mIndex,
+          "surf = %#x, pos = %#x, size = %#x, contalpa = %#x", mType, mIndex,
           mContext.ctx.prim_ctx.cntr,
           mContext.ctx.prim_ctx.linoff,
           mContext.ctx.prim_ctx.stride,
           mContext.ctx.prim_ctx.surf,
           mContext.ctx.prim_ctx.pos,
-          mContext.ctx.prim_ctx.size);
+          mContext.ctx.prim_ctx.size,
+          mContext.ctx.sp_ctx.contalpa);
 
     mCurrentDataBuffer = handle;
 }