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

Commit b98adbf0 authored by Brian Lindahl's avatar Brian Lindahl Committed by Android (Google) Code Review
Browse files

Merge "Add APIs for applying picture profiles to a layer and listening" into main

parents 617b9833 a5373d49
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -53413,6 +53413,7 @@ package android.view {
    method @NonNull public android.view.SurfaceControl.Transaction setBuffer(@NonNull android.view.SurfaceControl, @Nullable android.hardware.HardwareBuffer, @Nullable android.hardware.SyncFence, @Nullable java.util.function.Consumer<android.hardware.SyncFence>);
    method @NonNull public android.view.SurfaceControl.Transaction setBufferSize(@NonNull android.view.SurfaceControl, @IntRange(from=0) int, @IntRange(from=0) int);
    method @NonNull public android.view.SurfaceControl.Transaction setBufferTransform(@NonNull android.view.SurfaceControl, int);
    method @FlaggedApi("android.media.tv.flags.apply_picture_profiles") @NonNull public android.view.SurfaceControl.Transaction setContentPriority(@NonNull android.view.SurfaceControl, int);
    method @NonNull public android.view.SurfaceControl.Transaction setCrop(@NonNull android.view.SurfaceControl, @Nullable android.graphics.Rect);
    method @NonNull public android.view.SurfaceControl.Transaction setDamageRegion(@NonNull android.view.SurfaceControl, @Nullable android.graphics.Region);
    method @NonNull public android.view.SurfaceControl.Transaction setDataSpace(@NonNull android.view.SurfaceControl, int);
+12 −0
Original line number Diff line number Diff line
@@ -8171,6 +8171,14 @@ package android.media.quality {
    method @NonNull public android.media.quality.PictureProfile.Builder setProfileType(int);
  }
  @FlaggedApi("android.media.tv.flags.apply_picture_profiles") public final class PictureProfileHandle implements android.os.Parcelable {
    method @FlaggedApi("android.media.tv.flags.apply_picture_profiles") public int describeContents();
    method @FlaggedApi("android.media.tv.flags.apply_picture_profiles") public long getId();
    method @FlaggedApi("android.media.tv.flags.apply_picture_profiles") public void writeToParcel(@NonNull android.os.Parcel, int);
    field @FlaggedApi("android.media.tv.flags.apply_picture_profiles") @NonNull public static final android.os.Parcelable.Creator<android.media.quality.PictureProfileHandle> CREATOR;
    field @NonNull public static final android.media.quality.PictureProfileHandle NONE;
  }
}
package android.media.session {
@@ -18999,6 +19007,10 @@ package android.util {
package android.view {
  public static class SurfaceControl.Transaction implements java.io.Closeable android.os.Parcelable {
    method @FlaggedApi("android.media.tv.flags.apply_picture_profiles") @NonNull public android.view.SurfaceControl.Transaction setPictureProfileHandle(@NonNull android.view.SurfaceControl, @NonNull android.media.quality.PictureProfileHandle);
  }
  @UiThread public class View implements android.view.accessibility.AccessibilityEventSource android.graphics.drawable.Drawable.Callback android.view.KeyEvent.Callback {
    method @NonNull public final java.util.List<android.graphics.Rect> getUnrestrictedPreferKeepClearRects();
    method @RequiresPermission(android.Manifest.permission.SET_UNRESTRICTED_KEEP_CLEAR_AREAS) public final void setUnrestrictedPreferKeepClearRects(@NonNull java.util.List<android.graphics.Rect>);
+99 −1
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.Size;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.compat.annotation.UnsupportedAppUsage;
import android.graphics.ColorSpace;
@@ -58,6 +59,7 @@ import android.hardware.display.DeviceProductInfo;
import android.hardware.display.DisplayedContentSample;
import android.hardware.display.DisplayedContentSamplingAttributes;
import android.hardware.graphics.common.DisplayDecorationSupport;
import android.media.quality.PictureProfileHandle;
import android.opengl.EGLDisplay;
import android.opengl.EGLSync;
import android.os.Build;
@@ -234,7 +236,6 @@ public final class SurfaceControl implements Parcelable {
            long nativeObject, float currentBufferRatio, float desiredRatio);
    private static native void nativeSetDesiredHdrHeadroom(long transactionObj,
            long nativeObject, float desiredRatio);

    private static native void nativeSetCachingHint(long transactionObj,
            long nativeObject, int cachingHint);
    private static native void nativeSetDamageRegion(long transactionObj, long nativeObject,
@@ -314,6 +315,11 @@ public final class SurfaceControl implements Parcelable {
    private static native void nativeSetLuts(long transactionObj, long nativeObject,
            float[] buffers, int[] slots, int[] dimensions, int[] sizes, int[] samplingKeys);
    private static native void nativeEnableDebugLogCallPoints(long transactionObj);
    private static native int nativeGetMaxPictureProfiles();
    private static native void nativeSetPictureProfileId(long transactionObj,
            long nativeObject, long pictureProfileId);
    private static native void nativeSetContentPriority(long transactionObj, long nativeObject,
            int priority);

    /**
     * Transforms that can be applied to buffers as they are displayed to a window.
@@ -2835,6 +2841,33 @@ public final class SurfaceControl implements Parcelable {
        return nativeBootFinished();
    }

    /**
     * Retrieve the maximum number of concurrent picture profiles allowed across all displays.
     *
     * A picture profile is assigned to a layer via:
     * <ul>
     *     <li>Picture processing via {@link MediaCodec.KEY_PICTURE_PROFILE}</li>
     *     <li>Picture processing via {@link SurfaceControl.Transaction#setPictureProfileHandle}
     *     </li>
     * </ul>
     *
     * If the maximum number is exceeded, some layers will not receive profiles based on:
     * <ul>
     *     <li>The content priority assigned by the app</li>
     *     <li>The system-determined priority of the app owning the layer</li>
     * </ul>
     *
     * @see MediaCodec.KEY_PICTURE_PROFILE
     * @see SurfaceControl.Transaction#setPictureProfileHandle
     * @see SurfaceControl.Transaction#setContentPriority
     *
     * @hide
     */
    @IntRange(from = 0)
    public static int getMaxPictureProfiles() {
        return nativeGetMaxPictureProfiles();
    }

    /**
     * Interface to handle request to
     * {@link SurfaceControl.Transaction#addTransactionCommittedListener(Executor, TransactionCommittedListener)}
@@ -4597,6 +4630,71 @@ public final class SurfaceControl implements Parcelable {
            return this;
        }

        /**
         * Sets the desired picture profile handle for a layer.
         * <p>
         * A handle, retrieved from {@link MediaQualityManager#getProfileHandles}, which
         * refers a set of parameters that are used to configure picture processing that is applied
         * to all subsequent buffers to enhance the quality of their contents (e.g. gamma, color
         * temperature, hue, saturation, etc.).
         * <p>
         * Setting a handle does not guarantee access to limited picture processing. The content
         * priority for the  as well as the prominance of app to the current user experience plays a
         * role in which layer(s) get access to the limited picture processing resources. A maximum
         * number of {@link MediaQualityManager.getMaxPictureProfiles} can be applied at any given
         * point in time.
         *
         * @param sc The SurfaceControl of the layer that should be updated
         * @param handle The picture profile handle which refers to the set of desired parameters
         *
         * @see MediaQualityManager#getMaxPictureProfiles
         * @see MediaQualityManager#getProfileHandles
         * @see MediaCodec.KEY_PICTURE_PROFILE
         * @see SurfaceControl.Transaction#setContentPriority
         *
         * @hide
         */
        @FlaggedApi(android.media.tv.flags.Flags.FLAG_APPLY_PICTURE_PROFILES)
        @SystemApi
        public @NonNull Transaction setPictureProfileHandle(@NonNull SurfaceControl sc,
                                                            @NonNull PictureProfileHandle handle) {
            checkPreconditions(sc);

            nativeSetPictureProfileId(mNativeObject, sc.mNativeObject, handle.getId());
            return this;
        }

        /**
         * Sets the importance the layer's contents has to the app's user experience.
         * <p>
         * When a two layers within the same app are competing for a limited rendering resource,
         * the priority will determine which layer gets access to the resource. The lower the
         * priority, the more likely the layer will get access to the resource.
         * <p>
         * Resources managed by this priority:
         * <ul>
         *     <li>Picture processing via {@link MediaCodec.KEY_PICTURE_PROFILE}</li>
         *     <li>Picture processing via {@link SurfaceControl.Transaction#setPictureProfileHandle}
         *     </li>
         * </ul>
         *
         * @param sc The SurfaceControl of the layer that should be updated
         * @param priority The priority this layer should have with respect to other layers in the
         *                 app. The default priority is zero.
         *
         * @see MediaQualityManager#getMaxPictureProfiles
         * @see MediaCodec.KEY_PICTURE_PROFILE
         * @see SurfaceControl.Transaction#setPictureProfileHandle
         */
        @FlaggedApi(android.media.tv.flags.Flags.FLAG_APPLY_PICTURE_PROFILES)
        public @NonNull Transaction setContentPriority(@NonNull SurfaceControl sc,
                                                       int priority) {
            checkPreconditions(sc);

            nativeSetContentPriority(mNativeObject, sc.mNativeObject, priority);
            return this;
        }

        /**
         * Sets the caching hint for the layer. By default, the caching hint is
         * {@link CACHING_ENABLED}.
+58 −0
Original line number 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.
 */

package android.view;

import android.annotation.NonNull;
import android.media.quality.PictureProfileHandle;

/**
 * A record of a visible layer that is using picture processing.
 * @hide
 */
public class SurfaceControlActivePicture {
    private final int mLayerId;
    private final int mOwnerUid;
    private final @NonNull PictureProfileHandle mPictureProfileHandle;

    /**
     * Create a record of a visible layer that is using picture processing.
     *
     * @param layerId the layer that is using picture processing
     * @param ownerUid the UID of the package that owns the layer
     * @param handle the handle for the picture profile that configured the processing
     */
    private SurfaceControlActivePicture(int layerId, int ownerUid, PictureProfileHandle handle) {
        mLayerId = layerId;
        mOwnerUid = ownerUid;
        mPictureProfileHandle = handle;
    }

    /** The layer that is using picture processing.  */
    public int getLayerId() {
        return mLayerId;
    }

    /** The UID of the package that owns the layer using picture processing. */
    public int getOwnerUid() {
        return mOwnerUid;
    }

    /** A handle that indicates which picture profile has configured the picture processing. */
    public @NonNull PictureProfileHandle getPictureProfileHandle() {
        return mPictureProfileHandle;
    }
}
+69 −0
Original line number 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.
 */

package android.view;

import android.annotation.RequiresPermission;

import libcore.util.NativeAllocationRegistry;

/**
 * Allows for the monitoring of visible layers that are using picture processing.
 * @hide
 */
public abstract class SurfaceControlActivePictureListener {
    private static final NativeAllocationRegistry sRegistry =
            NativeAllocationRegistry.createMalloced(
                    SurfaceControlActivePictureListener.class.getClassLoader(),
                    nativeGetDestructor());

    /**
      * Callback when there are changes in the visible layers that are using picture processing.
      *
      * @param activePictures The visible layers that are using picture processing.
      */
    public abstract void onActivePicturesChanged(SurfaceControlActivePicture[] activePictures);

    /**
     * Start listening to changes in active pictures.
     */
    @RequiresPermission(android.Manifest.permission.OBSERVE_PICTURE_PROFILES)
    public void startListening() {
        synchronized (this) {
            long nativePtr = nativeMakeAndStartListening();
            mDestructor = sRegistry.registerNativeAllocation(this, nativePtr);
        }
    }

    /**
     * Stop listening to changes in active pictures.
     */
    @RequiresPermission(android.Manifest.permission.OBSERVE_PICTURE_PROFILES)
    public void stopListening() {
        final Runnable destructor;
        synchronized (this) {
            destructor = mDestructor;
        }
        if (destructor != null) {
            destructor.run();
        }
    }

    private native long nativeMakeAndStartListening();
    private static native long nativeGetDestructor();

    private Runnable mDestructor;
}
Loading