Pass display's colorTransform to RE even if HW handles it
Even if the DPU handles the colorTransform, RE needs to know about it
for A8 screen decorations layers. So pass the colorTransform to RE
always. Add a new boolean, specifying whether the DPU handles it, so
existing use cases can continue to ignore it.
RE uses a color matrix to turn transparent pixels in the A8 screen
decorations layer to black, providing antialiasing. If the DPU handles
the colorTransform, that black will then be converted to another color
(e.g. white, if the colorTransform comes from the "Color inversion"
accesibility feature). So RE needs to convert it to a color that the DPU
will then convert back to black, matching plastic next to the screen. Do
this by inverting the upper left 3x3 of the matrix and applying it to
black. If the color matrix is not invertible (note that the one used for
"Color inversion" *is*), leave black unchanged.
If the DPU does not handle the colorTransform, concat the A8 layer's
color matrix with the colorTransform.
Update libcompositionengine_test to use the proper colorTransform.
Add GTEST_SKIP if R8 buffers are not supported (follow-up from
I340de485fd62bea12a5a097f09073c4f7d58fa90).
Bug: 215706351
Bug: 216178319
Test: librenderengine_test
Test: libcompositionengine_test
Test: manual
Change-Id: Ib127620be4e5fc400ac2525c90dea1b9a29bd1f7
diff --git a/libs/renderengine/skia/SkiaGLRenderEngine.cpp b/libs/renderengine/skia/SkiaGLRenderEngine.cpp
index 763b82d..b467b35 100644
--- a/libs/renderengine/skia/SkiaGLRenderEngine.cpp
+++ b/libs/renderengine/skia/SkiaGLRenderEngine.cpp
@@ -792,7 +792,7 @@
// setup color filter if necessary
sk_sp<SkColorFilter> displayColorTransform;
- if (display.colorTransform != mat4()) {
+ if (display.colorTransform != mat4() && !display.deviceHandlesColorTransform) {
displayColorTransform = SkColorFilters::Matrix(toSkColorMatrix(display.colorTransform));
}
const bool ctModifiesAlpha =
@@ -1107,11 +1107,37 @@
if (imageTextureRef->colorType() == kAlpha_8_SkColorType) {
LOG_ALWAYS_FATAL_IF(layer.disableBlending, "Cannot disableBlending with A8");
- float matrix[] = { 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0,
- 0, 0, 0, -1, 1 };
- paint.setColorFilter(SkColorFilters::Matrix(matrix));
+
+ // SysUI creates the alpha layer as a coverage layer, which is
+ // appropriate for the DPU. Use a color matrix to convert it to
+ // a mask.
+ // TODO (b/219525258): Handle input as a mask.
+ //
+ // The color matrix will convert A8 pixels with no alpha to
+ // black, as described by this vector. If the display handles
+ // the color transform, we need to invert it to find the color
+ // that will result in black after the DPU applies the transform.
+ SkV4 black{0.0f, 0.0f, 0.0f, 1.0f}; // r, g, b, a
+ if (display.colorTransform != mat4() && display.deviceHandlesColorTransform) {
+ SkM44 colorSpaceMatrix = getSkM44(display.colorTransform);
+ if (colorSpaceMatrix.invert(&colorSpaceMatrix)) {
+ black = colorSpaceMatrix * black;
+ } else {
+ // We'll just have to use 0,0,0 as black, which should
+ // be close to correct.
+ ALOGI("Could not invert colorTransform!");
+ }
+ }
+ SkColorMatrix colorMatrix(0, 0, 0, 0, black[0],
+ 0, 0, 0, 0, black[1],
+ 0, 0, 0, 0, black[2],
+ 0, 0, 0, -1, 1);
+ if (display.colorTransform != mat4() && !display.deviceHandlesColorTransform) {
+ // On the other hand, if the device doesn't handle it, we
+ // have to apply it ourselves.
+ colorMatrix.postConcat(toSkColorMatrix(display.colorTransform));
+ }
+ paint.setColorFilter(SkColorFilters::Matrix(colorMatrix));
}
} else {
ATRACE_NAME("DrawColor");
@@ -1134,8 +1160,8 @@
paint.setBlendMode(SkBlendMode::kSrc);
}
- // A color filter will have been set for an A8 buffer. Do not replace
- // it with the displayColorTransform, which shouldn't affect A8.
+ // An A8 buffer will already have the proper color filter attached to
+ // its paint, including the displayColorTransform as needed.
if (!paint.getColorFilter()) {
paint.setColorFilter(displayColorTransform);
}