[RenderEngine] correct alpha blending func

By default, the GPU composition output is assigned to be premultiplied,
the GPU composition output is assigned to coverage blend mode and then
other device comp type layers are mixed can't ouput the expected color
using current renderEngine blend function.

Previously, with premultiplied alpha, the blending function used in the
GLES back end is:

  glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

which is essentially:

  out.rgba = src.rgba * src.rgba + dst.rgba * (1 - src.rgba)

Without premultiplied alpha, the blending function is:

  glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_ALPHA);

which is essentially:

  out.rgba = dst.rgba * (1 - src.rgba)

This is not correct.

The alpha blending equation should be:
  out.a = src.a + dst.a * (1 - src.a)
  out.rgb = ((src.rgb * src.a + dst.rgb * dst.a * (1 - src.a)) / out.a

* take coverage blend mode,
  out.a = src.a + dst.a * (1 - src.a)
  out.rgb * out.a = (src.rgb * src.a + dst.rgb * dst.a * (1 - src.a)
* take premultiplied blend mode,
  out.a = src.a + dst.a * (1 - src.a)
  out.rgb = src.rgb + dst.rgb * (1 - src.a)

Bug: b/161500635, b/162919900
Test: atest RenderEngineTest

Signed-off-by: wukui1 <wukui1@xiaomi.com>
Change-Id: I3816b20be077be054df61815765674f526d354cd
2 files changed