Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Skip to content
Commit 6f3c0bb2 authored by wukui1's avatar wukui1 Committed by Peiyong Lin
Browse files

[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: default avatarwukui1 <wukui1@xiaomi.com>
Change-Id: I3816b20be077be054df61815765674f526d354cd
parent 653ae188
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment