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

Commit 11bb758c authored by Christine Franks's avatar Christine Franks Committed by android-build-merger
Browse files

Merge "Pass through color modes in vendor range to SF" into qt-dev am: e781a675

am: f562ce81

Change-Id: I540c52c15473a7be0af8dc921cb967e2c651566e
parents 3043845f f562ce81
Loading
Loading
Loading
Loading
+19 −2
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.util.Slog;
import android.util.SparseArray;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;

import java.util.Arrays;

@@ -73,15 +74,27 @@ public class DisplayTransformManager {
    private static final int SURFACE_FLINGER_TRANSACTION_DISPLAY_COLOR = 1023;
    private static final int SURFACE_FLINGER_TRANSACTION_QUERY_COLOR_MANAGED = 1030;

    private static final String PERSISTENT_PROPERTY_SATURATION = "persist.sys.sf.color_saturation";
    private static final String PERSISTENT_PROPERTY_DISPLAY_COLOR = "persist.sys.sf.native_mode";
    @VisibleForTesting
    static final String PERSISTENT_PROPERTY_SATURATION = "persist.sys.sf.color_saturation";
    @VisibleForTesting
    static final String PERSISTENT_PROPERTY_DISPLAY_COLOR = "persist.sys.sf.native_mode";

    private static final float COLOR_SATURATION_NATURAL = 1.0f;
    private static final float COLOR_SATURATION_BOOSTED = 1.1f;

    /**
     * Display color modes defined by DisplayColorSetting in
     * frameworks/native/services/surfaceflinger/SurfaceFlinger.h.
     */
    private static final int DISPLAY_COLOR_MANAGED = 0;
    private static final int DISPLAY_COLOR_UNMANAGED = 1;
    private static final int DISPLAY_COLOR_ENHANCED = 2;
    /**
     * Display color mode range reserved for vendor customizations by the RenderIntent definition in
     * hardware/interfaces/graphics/common/1.1/types.hal.
     */
    private static final int VENDOR_MODE_RANGE_MIN = 256; // 0x100
    private static final int VENDOR_MODE_RANGE_MAX = 511; // 0x1ff

    /**
     * Map of level -> color transformation matrix.
@@ -257,7 +270,11 @@ public class DisplayTransformManager {
        } else if (colorMode == ColorDisplayManager.COLOR_MODE_AUTOMATIC) {
            applySaturation(COLOR_SATURATION_NATURAL);
            setDisplayColor(DISPLAY_COLOR_ENHANCED);
        } else if (colorMode >= VENDOR_MODE_RANGE_MIN && colorMode <= VENDOR_MODE_RANGE_MAX) {
            applySaturation(COLOR_SATURATION_NATURAL);
            setDisplayColor(colorMode);
        }

        setColorMatrix(LEVEL_COLOR_MATRIX_NIGHT_DISPLAY, nightDisplayMatrix);

        updateConfiguration();
+1 −0
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@
    <uses-permission android:name="android.permission.CONTROL_DISPLAY_COLOR_TRANSFORMS" />
    <uses-permission android:name="android.permission.READ_DEVICE_CONFIG" />
    <uses-permission android:name="android.permission.WRITE_DEVICE_CONFIG" />
    <uses-permission android:name="android.permission.HARDWARE_TEST"/>

    <!-- Uses API introduced in O (26) -->
    <uses-sdk android:minSdkVersion="1"
+102 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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.
 */

package com.android.server.display.color;

import static com.android.server.display.color.DisplayTransformManager.LEVEL_COLOR_MATRIX_NIGHT_DISPLAY;
import static com.android.server.display.color.DisplayTransformManager.PERSISTENT_PROPERTY_DISPLAY_COLOR;
import static com.android.server.display.color.DisplayTransformManager.PERSISTENT_PROPERTY_SATURATION;

import static com.google.common.truth.Truth.assertThat;

import android.hardware.display.ColorDisplayManager;
import android.os.SystemProperties;

import androidx.test.runner.AndroidJUnit4;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
public class DisplayTransformManagerTest {

    private DisplayTransformManager mDtm;
    private float[] mNightDisplayMatrix;

    @Before
    public void setUp() {
        mDtm = new DisplayTransformManager();
        mNightDisplayMatrix = mDtm.getColorMatrix(LEVEL_COLOR_MATRIX_NIGHT_DISPLAY);

        SystemProperties.set(PERSISTENT_PROPERTY_DISPLAY_COLOR, null);
        SystemProperties.set(PERSISTENT_PROPERTY_SATURATION, null);
    }

    @Test
    public void setColorMode_natural() {
        mDtm.setColorMode(ColorDisplayManager.COLOR_MODE_NATURAL, mNightDisplayMatrix);
        assertThat(SystemProperties.get(PERSISTENT_PROPERTY_DISPLAY_COLOR, null))
                .isEqualTo("0" /* managed */);
        assertThat(SystemProperties.get(PERSISTENT_PROPERTY_SATURATION, null))
                .isEqualTo("1.0" /* natural */);
    }

    @Test
    public void setColorMode_boosted() {
        mDtm.setColorMode(ColorDisplayManager.COLOR_MODE_BOOSTED, mNightDisplayMatrix);
        assertThat(SystemProperties.get(PERSISTENT_PROPERTY_DISPLAY_COLOR, null))
                .isEqualTo("0" /* managed */);
        assertThat(SystemProperties.get(PERSISTENT_PROPERTY_SATURATION, null))
                .isEqualTo("1.1" /* boosted */);
    }

    @Test
    public void setColorMode_saturated() {
        mDtm.setColorMode(ColorDisplayManager.COLOR_MODE_SATURATED, mNightDisplayMatrix);
        assertThat(SystemProperties.get(PERSISTENT_PROPERTY_DISPLAY_COLOR, null))
                .isEqualTo("1" /* unmanaged */);
        assertThat(SystemProperties.get(PERSISTENT_PROPERTY_SATURATION, null))
                .isEqualTo("1.0" /* natural */);
    }

    @Test
    public void setColorMode_automatic() {
        mDtm.setColorMode(ColorDisplayManager.COLOR_MODE_AUTOMATIC, mNightDisplayMatrix);
        assertThat(SystemProperties.get(PERSISTENT_PROPERTY_DISPLAY_COLOR, null))
                .isEqualTo("2" /* enhanced */);
        assertThat(SystemProperties.get(PERSISTENT_PROPERTY_SATURATION, null))
                .isEqualTo("1.0" /* natural */);
    }

    @Test
    public void setColorMode_vendor() {
        mDtm.setColorMode(0x100, mNightDisplayMatrix);
        assertThat(SystemProperties.get(PERSISTENT_PROPERTY_DISPLAY_COLOR, null))
                .isEqualTo(Integer.toString(0x100) /* pass-through */);
        assertThat(SystemProperties.get(PERSISTENT_PROPERTY_SATURATION, null))
                .isEqualTo("1.0" /* default */);
    }

    @Test
    public void setColorMode_outOfBounds() {
        mDtm.setColorMode(0x50, mNightDisplayMatrix);
        assertThat(SystemProperties.get(PERSISTENT_PROPERTY_DISPLAY_COLOR, null))
                .isEqualTo("" /* default */);
        assertThat(SystemProperties.get(PERSISTENT_PROPERTY_SATURATION, null))
                .isEqualTo("" /* default */);
    }
}