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

Commit 01f191c9 authored by Dominik Laskowski's avatar Dominik Laskowski
Browse files

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
parent 5caf9a92
Loading
Loading
Loading
Loading
+3 −1
Original line number Original line Diff line number Diff line
@@ -3775,6 +3775,9 @@ void SurfaceFlinger::processDisplayChangesLocked() {
        mVisibleRegionsDirty = true;
        mVisibleRegionsDirty = true;
        mUpdateInputInfo = true;
        mUpdateInputInfo = true;


        // Apply the current color matrix to any added or changed display.
        mCurrentState.colorMatrixChanged = true;

        // find the displays that were removed
        // find the displays that were removed
        // (ie: in drawing state but not in current state)
        // (ie: in drawing state but not in current state)
        // also handle displays that changed
        // also handle displays that changed
@@ -4273,7 +4276,6 @@ void SurfaceFlinger::doCommitTransactions() {
    }
    }


    mDrawingState = mCurrentState;
    mDrawingState = mCurrentState;
    // clear the "changed" flags in current state
    mCurrentState.colorMatrixChanged = false;
    mCurrentState.colorMatrixChanged = false;


    if (mVisibleRegionsDirty) {
    if (mVisibleRegionsDirty) {
+1 −0
Original line number Original line Diff line number Diff line
@@ -95,6 +95,7 @@ cc_test {
        "MessageQueueTest.cpp",
        "MessageQueueTest.cpp",
        "PowerAdvisorTest.cpp",
        "PowerAdvisorTest.cpp",
        "SmallAreaDetectionAllowMappingsTest.cpp",
        "SmallAreaDetectionAllowMappingsTest.cpp",
        "SurfaceFlinger_ColorMatrixTest.cpp",
        "SurfaceFlinger_CreateDisplayTest.cpp",
        "SurfaceFlinger_CreateDisplayTest.cpp",
        "SurfaceFlinger_DestroyDisplayTest.cpp",
        "SurfaceFlinger_DestroyDisplayTest.cpp",
        "SurfaceFlinger_DisplayModeSwitching.cpp",
        "SurfaceFlinger_DisplayModeSwitching.cpp",
+63 −0
Original line number Original line Diff line number Diff line
/*
 * 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