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

Commit b83cd310 authored by Alec Mouri's avatar Alec Mouri
Browse files

Promote OverlayProperties' buffer combinations to public api

This is particularly useful for detecting FP16 + extended range support
for scanout.

Bug: 324578996
Test: DisplayTest
Change-Id: I803dc2ea47c0d9c3ee2655d6c037a376c2c75b10
parent 43c71956
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -18594,6 +18594,7 @@ package android.hardware {
  @FlaggedApi("android.hardware.flags.overlayproperties_class_api") public final class OverlayProperties implements android.os.Parcelable {
    method @FlaggedApi("android.hardware.flags.overlayproperties_class_api") public int describeContents();
    method @FlaggedApi("android.hardware.flags.overlayproperties_class_api") public boolean isCombinationSupported(int, int);
    method @FlaggedApi("android.hardware.flags.overlayproperties_class_api") public boolean isMixedColorSpacesSupported();
    method @FlaggedApi("android.hardware.flags.overlayproperties_class_api") public void writeToParcel(@NonNull android.os.Parcel, int);
    field @FlaggedApi("android.hardware.flags.overlayproperties_class_api") @NonNull public static final android.os.Parcelable.Creator<android.hardware.OverlayProperties> CREATOR;
+23 −2
Original line number Diff line number Diff line
@@ -71,17 +71,36 @@ public final class OverlayProperties implements Parcelable {

    /**
     * @return True if the device can support fp16, false otherwise.
     * TODO: Move this to isCombinationSupported once the flag flips
     * @hide
     */
    public boolean isFp16SupportedForHdr() {
        if (mNativeObject == 0) {
            return false;
        }
        return nSupportFp16ForHdr(mNativeObject);
        return nIsCombinationSupported(
                mNativeObject, DataSpace.DATASPACE_SCRGB, HardwareBuffer.RGBA_FP16);
    }

    /**
     * Indicates that hw composition of two or more overlays
     * Indicates that hardware composition of a buffer encoded with the provided {@link DataSpace}
     * and {@link HardwareBuffer.Format} is supported on the device.
     *
     * @return True if the device can support efficiently compositing the content described by the
     *         dataspace and format. False if GPOU composition fallback is otherwise required.
     */
    @FlaggedApi(Flags.FLAG_OVERLAYPROPERTIES_CLASS_API)
    public boolean isCombinationSupported(@DataSpace.ColorDataSpace int dataspace,
            @HardwareBuffer.Format int format) {
        if (mNativeObject == 0) {
            return false;
        }

        return nIsCombinationSupported(mNativeObject, dataspace, format);
    }

    /**
     * Indicates that hardware composition of two or more overlays
     * with different colorspaces is supported on the device.
     *
     * @return True if the device can support mixed colorspaces efficiently,
@@ -131,6 +150,8 @@ public final class OverlayProperties implements Parcelable {
    private static native long nCreateDefault();
    private static native boolean nSupportFp16ForHdr(long nativeObject);
    private static native boolean nSupportMixedColorSpaces(long nativeObject);
    private static native boolean nIsCombinationSupported(
            long nativeObject, int dataspace, int format);
    private static native void nWriteOverlayPropertiesToParcel(long nativeObject, Parcel dest);
    private static native long nReadOverlayPropertiesFromParcel(Parcel in);
}
+12 −14
Original line number Diff line number Diff line
@@ -35,7 +35,6 @@ static struct {
    jclass clazz;
    jmethodID ctor;
} gOverlayPropertiesClassInfo;

// ----------------------------------------------------------------------------
// OverlayProperties lifecycle
// ----------------------------------------------------------------------------
@@ -52,21 +51,21 @@ static jlong android_hardware_OverlayProperties_getDestructor(JNIEnv*, jclass) {
// Accessors
// ----------------------------------------------------------------------------

static jboolean android_hardware_OverlayProperties_supportFp16ForHdr(JNIEnv* env, jobject thiz,
                                                                     jlong nativeObject) {
static jboolean android_hardware_OverlayProperties_isCombinationSupported(JNIEnv* env, jobject thiz,
                                                                          jlong nativeObject,
                                                                          jint dataspace,
                                                                          jint format) {
    gui::OverlayProperties* properties = reinterpret_cast<gui::OverlayProperties*>(nativeObject);
    if (properties != nullptr) {
        for (const auto& i : properties->combinations) {
            if (std::find(i.pixelFormats.begin(), i.pixelFormats.end(),
                          static_cast<int32_t>(HAL_PIXEL_FORMAT_RGBA_FP16)) !=
            if (std::find(i.pixelFormats.begin(), i.pixelFormats.end(), format) !=
                        i.pixelFormats.end() &&
                std::find(i.standards.begin(), i.standards.end(),
                          static_cast<int32_t>(HAL_DATASPACE_STANDARD_BT709)) !=
                        i.standards.end() &&
                          dataspace & HAL_DATASPACE_STANDARD_MASK) != i.standards.end() &&
                std::find(i.transfers.begin(), i.transfers.end(),
                          static_cast<int32_t>(HAL_DATASPACE_TRANSFER_SRGB)) != i.transfers.end() &&
                std::find(i.ranges.begin(), i.ranges.end(),
                          static_cast<int32_t>(HAL_DATASPACE_RANGE_EXTENDED)) != i.ranges.end()) {
                          dataspace & HAL_DATASPACE_TRANSFER_MASK) != i.transfers.end() &&
                std::find(i.ranges.begin(), i.ranges.end(), dataspace & HAL_DATASPACE_RANGE_MASK) !=
                        i.ranges.end()) {
                return true;
            }
        }
@@ -88,7 +87,7 @@ static jlong android_hardware_OverlayProperties_createDefault(JNIEnv* env, jobje
    gui::OverlayProperties* overlayProperties = new gui::OverlayProperties;
    gui::OverlayProperties::SupportedBufferCombinations combination;
    combination.pixelFormats = {HAL_PIXEL_FORMAT_RGBA_8888};
    combination.standards = {HAL_DATASPACE_BT709};
    combination.standards = {HAL_DATASPACE_STANDARD_BT709};
    combination.transfers = {HAL_DATASPACE_TRANSFER_SRGB};
    combination.ranges = {HAL_DATASPACE_RANGE_FULL};
    overlayProperties->combinations.emplace_back(combination);
@@ -153,8 +152,8 @@ const char* const kClassPathName = "android/hardware/OverlayProperties";
// clang-format off
static const JNINativeMethod gMethods[] = {
    { "nGetDestructor", "()J", (void*) android_hardware_OverlayProperties_getDestructor },
    { "nSupportFp16ForHdr",  "(J)Z",
            (void*)  android_hardware_OverlayProperties_supportFp16ForHdr },
    { "nIsCombinationSupported",  "(JII)Z",
            (void*)  android_hardware_OverlayProperties_isCombinationSupported },
    { "nSupportMixedColorSpaces", "(J)Z",
            (void*) android_hardware_OverlayProperties_supportMixedColorSpaces },
    { "nWriteOverlayPropertiesToParcel", "(JLandroid/os/Parcel;)V",
@@ -172,6 +171,5 @@ int register_android_hardware_OverlayProperties(JNIEnv* env) {
    gOverlayPropertiesClassInfo.clazz = MakeGlobalRefOrDie(env, clazz);
    gOverlayPropertiesClassInfo.ctor =
            GetMethodIDOrDie(env, gOverlayPropertiesClassInfo.clazz, "<init>", "(J)V");

    return err;
}