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

Commit 1f24ccf2 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic "display_policy"

* changes:
  DisplayEventDispatcher: add DISPLAY_EVENT_CONFIG_CHANGED
  SurfaceControl: add setAllowedDisplayConfigs
parents 54beaa6c a5a21f70
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -155,6 +155,17 @@ public abstract class DisplayEventReceiver {
    public void onHotplug(long timestampNanos, long physicalDisplayId, boolean connected) {
    }

    /**
     * Called when a display config changed event is received.
     *
     * @param timestampNanos The timestamp of the event, in the {@link System#nanoTime()}
     * timebase.
     * @param physicalDisplayId Stable display ID that uniquely describes a (display, port) pair.
     * @param configId The new config Id
     */
    public void onConfigChanged(long timestampNanos, long physicalDisplayId, int configId) {
    }

    /**
     * Schedules a single vertical sync pulse to be delivered when the next
     * display frame begins.
@@ -182,4 +193,11 @@ public abstract class DisplayEventReceiver {
    private void dispatchHotplug(long timestampNanos, long physicalDisplayId, boolean connected) {
        onHotplug(timestampNanos, physicalDisplayId, connected);
    }

    // Called from native code.
    @SuppressWarnings("unused")
    private void dispatchConfigChanged(long timestampNanos, long physicalDisplayId, int configId) {
        onConfigChanged(timestampNanos, physicalDisplayId, configId);
    }

}
+16 −0
Original line number Diff line number Diff line
@@ -158,6 +158,8 @@ public final class SurfaceControl implements Parcelable {
            IBinder displayToken, long numFrames, long timestamp);
    private static native int nativeGetActiveConfig(IBinder displayToken);
    private static native boolean nativeSetActiveConfig(IBinder displayToken, int id);
    private static native boolean nativeSetAllowedDisplayConfigs(IBinder displayToken,
                                                                 int[] allowedConfigs);
    private static native int[] nativeGetDisplayColorModes(IBinder displayToken);
    private static native SurfaceControl.DisplayPrimaries nativeGetDisplayNativePrimaries(
            IBinder displayToken);
@@ -1519,6 +1521,20 @@ public final class SurfaceControl implements Parcelable {
        return nativeSetActiveConfig(displayToken, id);
    }

    /**
     * @hide
     */
    public static boolean setAllowedDisplayConfigs(IBinder displayToken, int[] allowedConfigs) {
        if (displayToken == null) {
            throw new IllegalArgumentException("displayToken must not be null");
        }
        if (allowedConfigs == null) {
            throw new IllegalArgumentException("allowedConfigs must not be null");
        }

        return nativeSetAllowedDisplayConfigs(displayToken, allowedConfigs);
    }

    /**
     * @hide
     */
+22 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ static struct {

    jmethodID dispatchVsync;
    jmethodID dispatchHotplug;
    jmethodID dispatchConfigChanged;
} gDisplayEventReceiverClassInfo;


@@ -61,6 +62,8 @@ private:

    void dispatchVsync(nsecs_t timestamp, PhysicalDisplayId displayId, uint32_t count) override;
    void dispatchHotplug(nsecs_t timestamp, PhysicalDisplayId displayId, bool connected) override;
    void dispatchConfigChanged(nsecs_t timestamp, PhysicalDisplayId displayId,
                               int32_t configId) override;
};


@@ -114,6 +117,23 @@ void NativeDisplayEventReceiver::dispatchHotplug(nsecs_t timestamp, PhysicalDisp
    mMessageQueue->raiseAndClearException(env, "dispatchHotplug");
}

void NativeDisplayEventReceiver::dispatchConfigChanged(nsecs_t timestamp,
                                                       PhysicalDisplayId displayId,
                                                       int32_t configId) {
    JNIEnv* env = AndroidRuntime::getJNIEnv();

    ScopedLocalRef<jobject> receiverObj(env, jniGetReferent(env, mReceiverWeakGlobal));
    if (receiverObj.get()) {
        ALOGV("receiver %p ~ Invoking config changed handler.", this);
        env->CallVoidMethod(receiverObj.get(),
                            gDisplayEventReceiverClassInfo.dispatchConfigChanged,
                            timestamp, displayId, configId);
        ALOGV("receiver %p ~ Returned from config changed handler.", this);
    }

    mMessageQueue->raiseAndClearException(env, "dispatchConfigChanged");
}


static jlong nativeInit(JNIEnv* env, jclass clazz, jobject receiverWeak,
        jobject messageQueueObj, jint vsyncSource) {
@@ -180,6 +200,8 @@ int register_android_view_DisplayEventReceiver(JNIEnv* env) {
            gDisplayEventReceiverClassInfo.clazz, "dispatchVsync", "(JJI)V");
    gDisplayEventReceiverClassInfo.dispatchHotplug = GetMethodIDOrDie(env,
            gDisplayEventReceiverClassInfo.clazz, "dispatchHotplug", "(JJZ)V");
    gDisplayEventReceiverClassInfo.dispatchConfigChanged = GetMethodIDOrDie(env,
           gDisplayEventReceiverClassInfo.clazz, "dispatchConfigChanged", "(JJI)V");

    return res;
}
+21 −0
Original line number Diff line number Diff line
@@ -698,6 +698,25 @@ static jobjectArray nativeGetDisplayConfigs(JNIEnv* env, jclass clazz,
    return configArray;
}

static jboolean nativeSetAllowedDisplayConfigs(JNIEnv* env, jclass clazz,
        jobject tokenObj, jintArray configArray) {
    sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
    if (token == nullptr) return JNI_FALSE;

    std::vector<int32_t> allowedConfigs;
    jsize configArraySize = env->GetArrayLength(configArray);
    allowedConfigs.reserve(configArraySize);

    jint* configArrayElements = env->GetIntArrayElements(configArray, 0);
    for (int i = 0; i < configArraySize; i++) {
        allowedConfigs.push_back(configArrayElements[i]);
    }
    env->ReleaseIntArrayElements(configArray, configArrayElements, 0);

    size_t result = SurfaceComposerClient::setAllowedDisplayConfigs(token, allowedConfigs);
    return result == NO_ERROR ? JNI_TRUE : JNI_FALSE;
}

static jint nativeGetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj) {
    sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
    if (token == NULL) return -1;
@@ -1194,6 +1213,8 @@ static const JNINativeMethod sSurfaceControlMethods[] = {
            (void*)nativeGetActiveConfig },
    {"nativeSetActiveConfig", "(Landroid/os/IBinder;I)Z",
            (void*)nativeSetActiveConfig },
    {"nativeSetAllowedDisplayConfigs", "(Landroid/os/IBinder;[I)Z",
            (void*)nativeSetAllowedDisplayConfigs },
    {"nativeGetDisplayColorModes", "(Landroid/os/IBinder;)[I",
            (void*)nativeGetDisplayColorModes},
    {"nativeGetDisplayNativePrimaries", "(Landroid/os/IBinder;)Landroid/view/SurfaceControl$DisplayPrimaries;",
+3 −0
Original line number Diff line number Diff line
@@ -135,6 +135,9 @@ bool DisplayEventDispatcher::processPendingEvents(
            case DisplayEventReceiver::DISPLAY_EVENT_HOTPLUG:
                dispatchHotplug(ev.header.timestamp, ev.header.displayId, ev.hotplug.connected);
                break;
            case DisplayEventReceiver::DISPLAY_EVENT_CONFIG_CHANGED:
                dispatchConfigChanged(ev.header.timestamp, ev.header.displayId, ev.config.configId);
                break;
            default:
                ALOGW("dispatcher %p ~ ignoring unknown event type %#x", this, ev.header.type);
                break;
Loading