summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Dominik Laskowski <domlaskowski@google.com> 2024-01-29 11:51:23 -0500
committer Dominik Laskowski <domlaskowski@google.com> 2024-02-02 11:24:52 -0500
commit01f191c90ef0cf2018fc894c7bb5a54b80f5f072 (patch)
tree08230ec4797be80d55ad454e0172a5a9462e18a0
parent5caf9a926663778303291b5270f8ec99a6a61b70 (diff)
SF: Apply color matrix to newly connected displays
When a transaction adds/changes/removes displays, set the global color matrix on CompositionRefreshArgs so it gets applied to new displays on the next composite. Fixes: 321965883 Test: Connect external display while colors are inverted. Test: ColorMatrixTest Change-Id: I34af02d491243e06e6ba0cec1c9f044a2eb5a49d
-rw-r--r--services/surfaceflinger/SurfaceFlinger.cpp4
-rw-r--r--services/surfaceflinger/tests/unittests/Android.bp1
-rw-r--r--services/surfaceflinger/tests/unittests/SurfaceFlinger_ColorMatrixTest.cpp63
3 files changed, 67 insertions, 1 deletions
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index d86de844ab..8512219d35 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -3775,6 +3775,9 @@ void SurfaceFlinger::processDisplayChangesLocked() {
mVisibleRegionsDirty = true;
mUpdateInputInfo = true;
+ // Apply the current color matrix to any added or changed display.
+ mCurrentState.colorMatrixChanged = true;
+
// find the displays that were removed
// (ie: in drawing state but not in current state)
// also handle displays that changed
@@ -4273,7 +4276,6 @@ void SurfaceFlinger::doCommitTransactions() {
}
mDrawingState = mCurrentState;
- // clear the "changed" flags in current state
mCurrentState.colorMatrixChanged = false;
if (mVisibleRegionsDirty) {
diff --git a/services/surfaceflinger/tests/unittests/Android.bp b/services/surfaceflinger/tests/unittests/Android.bp
index 5809ea02f8..7c191a50e7 100644
--- a/services/surfaceflinger/tests/unittests/Android.bp
+++ b/services/surfaceflinger/tests/unittests/Android.bp
@@ -95,6 +95,7 @@ cc_test {
"MessageQueueTest.cpp",
"PowerAdvisorTest.cpp",
"SmallAreaDetectionAllowMappingsTest.cpp",
+ "SurfaceFlinger_ColorMatrixTest.cpp",
"SurfaceFlinger_CreateDisplayTest.cpp",
"SurfaceFlinger_DestroyDisplayTest.cpp",
"SurfaceFlinger_DisplayModeSwitching.cpp",
diff --git a/services/surfaceflinger/tests/unittests/SurfaceFlinger_ColorMatrixTest.cpp b/services/surfaceflinger/tests/unittests/SurfaceFlinger_ColorMatrixTest.cpp
new file mode 100644
index 0000000000..f127213f0d
--- /dev/null
+++ b/services/surfaceflinger/tests/unittests/SurfaceFlinger_ColorMatrixTest.cpp
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#undef LOG_TAG
+#define LOG_TAG "LibSurfaceFlingerUnittests"
+
+#include "CommitAndCompositeTest.h"
+
+#define EXPECT_COLOR_MATRIX_CHANGED(current, drawing) \
+ EXPECT_EQ(current, mFlinger.currentState().colorMatrixChanged); \
+ EXPECT_EQ(drawing, mFlinger.drawingState().colorMatrixChanged);
+
+namespace android {
+
+class ColorMatrixTest : public CommitAndCompositeTest {};
+
+TEST_F(ColorMatrixTest, colorMatrixChanged) {
+ EXPECT_COLOR_MATRIX_CHANGED(true, true);
+ mFlinger.mutableTransactionFlags() |= eTransactionNeeded;
+
+ mFlinger.commitAndComposite();
+ EXPECT_COLOR_MATRIX_CHANGED(false, false);
+
+ mFlinger.setDaltonizerType(ColorBlindnessType::Deuteranomaly);
+ EXPECT_COLOR_MATRIX_CHANGED(true, false);
+
+ mFlinger.commit();
+ EXPECT_COLOR_MATRIX_CHANGED(false, true);
+
+ mFlinger.commitAndComposite();
+ EXPECT_COLOR_MATRIX_CHANGED(false, false);
+}
+
+TEST_F(ColorMatrixTest, colorMatrixChangedAfterDisplayTransaction) {
+ EXPECT_COLOR_MATRIX_CHANGED(true, true);
+ mFlinger.mutableTransactionFlags() |= eTransactionNeeded;
+
+ mFlinger.commitAndComposite();
+ EXPECT_COLOR_MATRIX_CHANGED(false, false);
+
+ mFlinger.createDisplay(String8("Test Display"), false);
+
+ mFlinger.commit();
+ EXPECT_COLOR_MATRIX_CHANGED(false, true);
+
+ mFlinger.commitAndComposite();
+ EXPECT_COLOR_MATRIX_CHANGED(false, false);
+}
+
+} // namespace android