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

Commit 52f12890 authored by Ana Krulec's avatar Ana Krulec Committed by Steven Thomas
Browse files

1a) DM: create Class to pass around Specs

Test: observer logs.
Bug: 142507213
Change-Id: If399edd6d795e88800f6f82822e94ede13b56ac0
parent 4f753aac
Loading
Loading
Loading
Loading
+35 −4
Original line number Diff line number Diff line
@@ -162,7 +162,7 @@ public final class SurfaceControl implements Parcelable {
                                                                 int[] allowedConfigs);
    private static native int[] nativeGetAllowedDisplayConfigs(IBinder displayToken);
    private static native boolean nativeSetDesiredDisplayConfigSpecs(IBinder displayToken,
            int defaultModeId, float minRefreshRate, float maxRefreshRate);
            SurfaceControl.DesiredDisplayConfigSpecs desiredDisplayConfigSpecs);
    private static native int[] nativeGetDisplayColorModes(IBinder displayToken);
    private static native SurfaceControl.DisplayPrimaries nativeGetDisplayNativePrimaries(
            IBinder displayToken);
@@ -1490,16 +1490,47 @@ public final class SurfaceControl implements Parcelable {
    }

    /**
     * Contains information about desired display configuration.
     *
     * @hide
     */
    public static boolean setDesiredDisplayConfigSpecs(IBinder displayToken,
    public static final class DesiredDisplayConfigSpecs {
        /**
         * @hide
         */
        public int mDefaultModeId;

        /**
         * @hide
         */
        public float mMinRefreshRate;

        /**
         * @hide
         */
        public float mMaxRefreshRate;

        /**
         * @hide
         */
        public DesiredDisplayConfigSpecs(
                int defaultModeId, float minRefreshRate, float maxRefreshRate) {
            mDefaultModeId = defaultModeId;
            mMinRefreshRate = minRefreshRate;
            mMaxRefreshRate = maxRefreshRate;
        }
    }

    /**
     * @hide
     */
    public static boolean setDesiredDisplayConfigSpecs(IBinder displayToken,
            SurfaceControl.DesiredDisplayConfigSpecs desiredDisplayConfigSpecs) {
        if (displayToken == null) {
            throw new IllegalArgumentException("displayToken must not be null");
        }

        return nativeSetDesiredDisplayConfigSpecs(displayToken, defaultModeId, minRefreshRate,
            maxRefreshRate);
        return nativeSetDesiredDisplayConfigSpecs(displayToken, desiredDisplayConfigSpecs);
    }

    /**
+33 −4
Original line number Diff line number Diff line
@@ -138,6 +138,14 @@ static struct {
    jmethodID builder;
} gScreenshotGraphicBufferClassInfo;

static struct {
    jclass clazz;
    jmethodID ctor;
    jfieldID defaultModeId;
    jfieldID minRefreshRate;
    jfieldID maxRefreshRate;
} gDesiredDisplayConfigSpecsClassInfo;

class JNamedColorSpace {
public:
    // ColorSpace.Named.SRGB.ordinal() = 0;
@@ -805,13 +813,20 @@ static jintArray nativeGetAllowedDisplayConfigs(JNIEnv* env, jclass clazz, jobje
    return allowedConfigsArray;
}

static jboolean nativeSetDesiredDisplayConfigSpecs(JNIEnv* env, jclass clazz,
        jobject tokenObj, jint displayModeId, jfloat minRefreshRate, jfloat maxRefreshRate) {
static jboolean nativeSetDesiredDisplayConfigSpecs(JNIEnv* env, jclass clazz, jobject tokenObj,
                                                   jobject desiredDisplayConfigSpecs) {
    sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
    if (token == nullptr) return JNI_FALSE;

    jint defaultModeId = env->GetIntField(desiredDisplayConfigSpecs,
                                          gDesiredDisplayConfigSpecsClassInfo.defaultModeId);
    jfloat minRefreshRate = env->GetFloatField(desiredDisplayConfigSpecs,
                                               gDesiredDisplayConfigSpecsClassInfo.minRefreshRate);
    jfloat maxRefreshRate = env->GetFloatField(desiredDisplayConfigSpecs,
                                               gDesiredDisplayConfigSpecsClassInfo.maxRefreshRate);

    size_t result = SurfaceComposerClient::setDesiredDisplayConfigSpecs(
        token, displayModeId, minRefreshRate, maxRefreshRate);
            token, defaultModeId, minRefreshRate, maxRefreshRate);
    return result == NO_ERROR ? JNI_TRUE : JNI_FALSE;
}

@@ -1355,7 +1370,8 @@ static const JNINativeMethod sSurfaceControlMethods[] = {
            (void*)nativeSetAllowedDisplayConfigs },
    {"nativeGetAllowedDisplayConfigs", "(Landroid/os/IBinder;)[I",
            (void*)nativeGetAllowedDisplayConfigs },
    {"nativeSetDesiredDisplayConfigSpecs", "(Landroid/os/IBinder;IFF)Z",
    {"nativeSetDesiredDisplayConfigSpecs",
            "(Landroid/os/IBinder;Landroid/view/SurfaceControl$DesiredDisplayConfigSpecs;)Z",
            (void*)nativeSetDesiredDisplayConfigSpecs },
    {"nativeGetDisplayColorModes", "(Landroid/os/IBinder;)[I",
            (void*)nativeGetDisplayColorModes},
@@ -1524,6 +1540,19 @@ int register_android_view_SurfaceControl(JNIEnv* env)
    gDisplayPrimariesClassInfo.white = GetFieldIDOrDie(env, displayPrimariesClazz, "white",
            "Landroid/view/SurfaceControl$CieXyz;");

    jclass desiredDisplayConfigSpecsClazz =
            FindClassOrDie(env, "android/view/SurfaceControl$DesiredDisplayConfigSpecs");
    gDesiredDisplayConfigSpecsClassInfo.clazz =
            MakeGlobalRefOrDie(env, desiredDisplayConfigSpecsClazz);
    gDesiredDisplayConfigSpecsClassInfo.ctor =
            GetMethodIDOrDie(env, gDesiredDisplayConfigSpecsClassInfo.clazz, "<init>", "(IFF)V");
    gDesiredDisplayConfigSpecsClassInfo.defaultModeId =
            GetFieldIDOrDie(env, desiredDisplayConfigSpecsClazz, "mDefaultModeId", "I");
    gDesiredDisplayConfigSpecsClassInfo.minRefreshRate =
            GetFieldIDOrDie(env, desiredDisplayConfigSpecsClazz, "mMinRefreshRate", "F");
    gDesiredDisplayConfigSpecsClassInfo.maxRefreshRate =
            GetFieldIDOrDie(env, desiredDisplayConfigSpecsClazz, "mMaxRefreshRate", "F");

    return err;
}

+3 −2
Original line number Diff line number Diff line
@@ -693,8 +693,9 @@ final class LocalDisplayAdapter extends DisplayAdapter {
            }

            final IBinder token = getDisplayTokenLocked();
            SurfaceControl.setDesiredDisplayConfigSpecs(token, defaultModeId, minRefreshRate,
                    maxRefreshRate);
            SurfaceControl.setDesiredDisplayConfigSpecs(token,
                    new SurfaceControl.DesiredDisplayConfigSpecs(
                            defaultModeId, minRefreshRate, maxRefreshRate));
            int activePhysIndex = SurfaceControl.getActiveConfig(token);
            return updateActiveModeLocked(activePhysIndex);
        }