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

Commit 9ec9ea72 authored by Chia-I Wu's avatar Chia-I Wu
Browse files

Fix night light and COLOR_MODE_AUTOMATIC

The native mode methods in DisplayTransformManager were used to
decide whether the color matrix works in linear or gamma space.  For
COLOR_MODE_AUTOMATIC, the color matrix works in lienar instead of
gamma space.

Fix the native mode methods to be more clear about the intention to
avoid future breakage.

Bug: 79257138
Test: manual and atest FrameworksServicesTests:ColorDisplayServiceTest
Change-Id: Ied60a62bd7330e87c3207f2183d7e83af9e51fb7
parent b5eca33b
Loading
Loading
Loading
Loading
+7 −8
Original line number Original line Diff line number Diff line
@@ -189,7 +189,7 @@ public final class ColorDisplayService extends SystemService
        mController = new ColorDisplayController(getContext(), mCurrentUser);
        mController = new ColorDisplayController(getContext(), mCurrentUser);
        mController.setListener(this);
        mController.setListener(this);


        setCoefficientMatrix(getContext(), DisplayTransformManager.isNativeModeEnabled());
        setCoefficientMatrix(getContext(), DisplayTransformManager.needsLinearColorMatrix());


        // Prepare color transformation matrix.
        // Prepare color transformation matrix.
        setMatrix(mController.getColorTemperature(), mMatrixNight);
        setMatrix(mController.getColorTemperature(), mMatrixNight);
@@ -293,7 +293,7 @@ public final class ColorDisplayService extends SystemService
            mColorMatrixAnimator.cancel();
            mColorMatrixAnimator.cancel();
        }
        }


        setCoefficientMatrix(getContext(), DisplayTransformManager.isColorModeNative(mode));
        setCoefficientMatrix(getContext(), DisplayTransformManager.needsLinearColorMatrix(mode));
        setMatrix(mController.getColorTemperature(), mMatrixNight);
        setMatrix(mController.getColorTemperature(), mMatrixNight);


        final DisplayTransformManager dtm = getLocalService(DisplayTransformManager.class);
        final DisplayTransformManager dtm = getLocalService(DisplayTransformManager.class);
@@ -306,13 +306,12 @@ public final class ColorDisplayService extends SystemService
    }
    }


    /**
    /**
     * Set coefficients based on native mode. Use DisplayTransformManager#isNativeModeEnabled while
     * Set coefficients based on whether the color matrix is linear or not.
     * setting is stable; when setting is changing, pass native mode selection directly.
     */
     */
    private void setCoefficientMatrix(Context context, boolean isNative) {
    private void setCoefficientMatrix(Context context, boolean needsLinear) {
        final String[] coefficients = context.getResources().getStringArray(isNative
        final String[] coefficients = context.getResources().getStringArray(needsLinear
                ? R.array.config_nightDisplayColorTemperatureCoefficientsNative
                ? R.array.config_nightDisplayColorTemperatureCoefficients
                : R.array.config_nightDisplayColorTemperatureCoefficients);
                : R.array.config_nightDisplayColorTemperatureCoefficientsNative);
        for (int i = 0; i < 9 && i < coefficients.length; i++) {
        for (int i = 0; i < 9 && i < coefficients.length; i++) {
            mColorTempCoefficients[i] = Float.parseFloat(coefficients[i]);
            mColorTempCoefficients[i] = Float.parseFloat(coefficients[i]);
        }
        }
+7 −9
Original line number Original line Diff line number Diff line
@@ -231,21 +231,19 @@ public class DisplayTransformManager {
    }
    }


    /**
    /**
     * Return true when colors are stretched from the working color space to the
     * Return true when the color matrix works in linear space.
     * native color space.
     */
     */
    public static boolean isNativeModeEnabled() {
    public static boolean needsLinearColorMatrix() {
        return SystemProperties.getInt(PERSISTENT_PROPERTY_DISPLAY_COLOR,
        return SystemProperties.getInt(PERSISTENT_PROPERTY_DISPLAY_COLOR,
                DISPLAY_COLOR_MANAGED) != DISPLAY_COLOR_MANAGED;
                DISPLAY_COLOR_UNMANAGED) != DISPLAY_COLOR_UNMANAGED;
    }
    }


    /**
    /**
     * Return true when the specified colorMode stretches colors from the
     * Return true when the specified colorMode requires the color matrix to
     * working color space to the native color space.
     * work in linear space.
     */
     */
    public static boolean isColorModeNative(int colorMode) {
    public static boolean needsLinearColorMatrix(int colorMode) {
        return !(colorMode == ColorDisplayController.COLOR_MODE_NATURAL ||
        return colorMode != ColorDisplayController.COLOR_MODE_SATURATED;
                 colorMode == ColorDisplayController.COLOR_MODE_BOOSTED);
    }
    }


    public boolean setColorMode(int colorMode, float[] nightDisplayMatrix) {
    public boolean setColorMode(int colorMode, float[] nightDisplayMatrix) {