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

Commit 53d19086 authored by Michael Wright's avatar Michael Wright Committed by The Android Automerger
Browse files

Add support for setting color transforms

Bug: 24038268
Change-Id: I05275c906e02eb9e67331f6f909166eb08ad5536
parent 91da9a0a
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -359,6 +359,14 @@ public final class DisplayManagerGlobal {
        }
    }

    public void requestColorTransform(int displayId, int colorTransformId) {
        try {
            mDm.requestColorTransform(displayId, colorTransformId);
        } catch (RemoteException ex) {
            Log.e(TAG, "Failed to request color transform.", ex);
        }
    }

    public VirtualDisplay createVirtualDisplay(Context context, MediaProjection projection,
            String name, int width, int height, int densityDpi, Surface surface, int flags,
            VirtualDisplay.Callback callback, Handler handler) {
+3 −0
Original line number Diff line number Diff line
@@ -59,6 +59,9 @@ interface IDisplayManager {
    // No permissions required.
    WifiDisplayStatus getWifiDisplayStatus();

    // Requires CONFIGURE_DISPLAY_COLOR_TRANSFORM
    void requestColorTransform(int displayId, int colorTransformId);

    // Requires CAPTURE_VIDEO_OUTPUT, CAPTURE_SECURE_VIDEO_OUTPUT, or an appropriate
    // MediaProjection token for certain combinations of flags.
    int createVirtualDisplay(in IVirtualDisplayCallback callback,
+133 −0
Original line number Diff line number Diff line
@@ -16,7 +16,10 @@

package android.view;

import android.annotation.RequiresPermission;
import android.content.Context;
import android.content.res.CompatibilityInfo;
import android.content.res.Resources;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.graphics.Rect;
@@ -30,6 +33,8 @@ import android.util.Log;

import java.util.Arrays;

import static android.Manifest.permission.CONFIGURE_DISPLAY_COLOR_TRANSFORM;

/**
 * Provides information about the size and density of a logical display.
 * <p>
@@ -678,6 +683,49 @@ public final class Display {
        }
    }

    /**
     * Request the display applies a color transform.
     * @hide
     */
    @RequiresPermission(CONFIGURE_DISPLAY_COLOR_TRANSFORM)
    public void requestColorTransform(ColorTransform colorTransform) {
        mGlobal.requestColorTransform(mDisplayId, colorTransform.getId());
    }

    /**
     * Returns the active color transform of this display
     * @hide
     */
    public ColorTransform getColorTransform() {
        synchronized (this) {
            updateDisplayInfoLocked();
            return mDisplayInfo.getColorTransform();
        }
    }

    /**
     * Returns the default color transform of this display
     * @hide
     */
    public ColorTransform getDefaultColorTransform() {
        synchronized (this) {
            updateDisplayInfoLocked();
            return mDisplayInfo.getDefaultColorTransform();
        }
    }

    /**
     * Gets the supported color transforms of this device.
     * @hide
     */
    public ColorTransform[] getSupportedColorTransforms() {
        synchronized (this) {
            updateDisplayInfoLocked();
            ColorTransform[] transforms = mDisplayInfo.supportedColorTransforms;
            return Arrays.copyOf(transforms, transforms.length);
        }
    }

    /**
     * Gets the app VSYNC offset, in nanoseconds.  This is a positive value indicating
     * the phase offset of the VSYNC events provided by Choreographer relative to the
@@ -1054,4 +1102,89 @@ public final class Display {
            }
        };
    }

    /**
     * A color transform supported by a given display.
     *
     * @see Display#getSupportedColorTransforms()
     * @hide
     */
    public static final class ColorTransform implements Parcelable {
        public static final ColorTransform[] EMPTY_ARRAY = new ColorTransform[0];

        private final int mId;
        private final int mColorTransform;

        public ColorTransform(int id, int colorTransform) {
            mId = id;
            mColorTransform = colorTransform;
        }

        public int getId() {
            return mId;
        }

        public int getColorTransform() {
            return mColorTransform;
        }

        @Override
        public boolean equals(Object other) {
            if (this == other) {
                return true;
            }
            if (!(other instanceof ColorTransform)) {
                return false;
            }
            ColorTransform that = (ColorTransform) other;
            return mId == that.mId
                && mColorTransform == that.mColorTransform;
        }

        @Override
        public int hashCode() {
            int hash = 1;
            hash = hash * 17 + mId;
            hash = hash * 17 + mColorTransform;
            return hash;
        }

        @Override
        public String toString() {
            return new StringBuilder("{")
                    .append("id=").append(mId)
                    .append(", colorTransform=").append(mColorTransform)
                    .append("}")
                    .toString();
        }

        @Override
        public int describeContents() {
            return 0;
        }

        private ColorTransform(Parcel in) {
            this(in.readInt(), in.readInt());
        }

        @Override
        public void writeToParcel(Parcel out, int parcelableFlags) {
            out.writeInt(mId);
            out.writeInt(mColorTransform);
        }

        @SuppressWarnings("hiding")
        public static final Parcelable.Creator<ColorTransform> CREATOR
                = new Parcelable.Creator<ColorTransform>() {
            @Override
            public ColorTransform createFromParcel(Parcel in) {
                return new ColorTransform(in);
            }

            @Override
            public ColorTransform[] newArray(int size) {
                return new ColorTransform[size];
            }
        };
    }
}
+52 −0
Original line number Diff line number Diff line
@@ -169,6 +169,15 @@ public final class DisplayInfo implements Parcelable {
     */
    public Display.Mode[] supportedModes = Display.Mode.EMPTY_ARRAY;

    /** The active color transform. */
    public int colorTransformId;

    /** The default color transform. */
    public int defaultColorTransformId;

    /** The list of supported color transforms */
    public Display.ColorTransform[] supportedColorTransforms = Display.ColorTransform.EMPTY_ARRAY;

    /**
     * The logical display density which is the basis for density-independent
     * pixels.
@@ -279,6 +288,8 @@ public final class DisplayInfo implements Parcelable {
                && rotation == other.rotation
                && modeId == other.modeId
                && defaultModeId == other.defaultModeId
                && colorTransformId == other.colorTransformId
                && defaultColorTransformId == other.defaultColorTransformId
                && logicalDensityDpi == other.logicalDensityDpi
                && physicalXDpi == other.physicalXDpi
                && physicalYDpi == other.physicalYDpi
@@ -317,6 +328,10 @@ public final class DisplayInfo implements Parcelable {
        modeId = other.modeId;
        defaultModeId = other.defaultModeId;
        supportedModes = Arrays.copyOf(other.supportedModes, other.supportedModes.length);
        colorTransformId = other.colorTransformId;
        defaultColorTransformId = other.defaultColorTransformId;
        supportedColorTransforms = Arrays.copyOf(
                other.supportedColorTransforms, other.supportedColorTransforms.length);
        logicalDensityDpi = other.logicalDensityDpi;
        physicalXDpi = other.physicalXDpi;
        physicalYDpi = other.physicalYDpi;
@@ -353,6 +368,13 @@ public final class DisplayInfo implements Parcelable {
        for (int i = 0; i < nModes; i++) {
            supportedModes[i] = Display.Mode.CREATOR.createFromParcel(source);
        }
        colorTransformId = source.readInt();
        defaultColorTransformId = source.readInt();
        int nColorTransforms = source.readInt();
        supportedColorTransforms = new Display.ColorTransform[nColorTransforms];
        for (int i = 0; i < nColorTransforms; i++) {
            supportedColorTransforms[i] = Display.ColorTransform.CREATOR.createFromParcel(source);
        }
        logicalDensityDpi = source.readInt();
        physicalXDpi = source.readFloat();
        physicalYDpi = source.readFloat();
@@ -390,6 +412,12 @@ public final class DisplayInfo implements Parcelable {
        for (int i = 0; i < supportedModes.length; i++) {
            supportedModes[i].writeToParcel(dest, flags);
        }
        dest.writeInt(colorTransformId);
        dest.writeInt(defaultColorTransformId);
        dest.writeInt(supportedColorTransforms.length);
        for (int i = 0; i < supportedColorTransforms.length; i++) {
            supportedColorTransforms[i].writeToParcel(dest, flags);
        }
        dest.writeInt(logicalDensityDpi);
        dest.writeFloat(physicalXDpi);
        dest.writeFloat(physicalYDpi);
@@ -461,6 +489,24 @@ public final class DisplayInfo implements Parcelable {
        return result;
    }

    public Display.ColorTransform getColorTransform() {
        return findColorTransform(colorTransformId);
    }

    public Display.ColorTransform getDefaultColorTransform() {
        return findColorTransform(defaultColorTransformId);
    }

    private Display.ColorTransform findColorTransform(int colorTransformId) {
        for (int i = 0; i < supportedColorTransforms.length; i++) {
            Display.ColorTransform colorTransform = supportedColorTransforms[i];
            if (colorTransform.getId() == colorTransformId) {
                return colorTransform;
            }
        }
        throw new IllegalStateException("Unable to locate color transform: " + colorTransformId);
    }

    public void getAppMetrics(DisplayMetrics outMetrics) {
        getAppMetrics(outMetrics, CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
    }
@@ -562,6 +608,12 @@ public final class DisplayInfo implements Parcelable {
        sb.append(defaultModeId);
        sb.append(", modes ");
        sb.append(Arrays.toString(supportedModes));
        sb.append(", colorTransformId ");
        sb.append(colorTransformId);
        sb.append(", defaultColorTransformId ");
        sb.append(defaultColorTransformId);
        sb.append(", supportedColorTransforms ");
        sb.append(Arrays.toString(supportedColorTransforms));
        sb.append(", rotation ");
        sb.append(rotation);
        sb.append(", density ");
+7 −0
Original line number Diff line number Diff line
@@ -2160,6 +2160,13 @@
    <permission android:name="android.permission.CONTROL_WIFI_DISPLAY"
        android:protectionLevel="signature" />

    <!-- Allows an application to control the color transforms applied to
         displays system-wide.
         <p>Not for use by third-party applications.</p>
         @hide -->
    <permission android:name="android.permission.CONFIGURE_DISPLAY_COLOR_TRANSFORM"
        android:protectionLevel="signature" />

    <!-- @SystemApi Allows an application to control VPN.
         <p>Not for use by third-party applications.</p>
         @hide -->
Loading