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

Commit a5a21f70 authored by Ady Abraham's avatar Ady Abraham
Browse files

DisplayEventDispatcher: add DISPLAY_EVENT_CONFIG_CHANGED

Add a new event for display configuration change. This event
will be sent by SF anytime it changes the display config.

Test: Generate DISPLAY_EVENT_CONFIG_CHANGED and observe the log
Bug: 122905403
Change-Id: Ifa473a34d7b313501e5e4e8a67186fb82754fdcd
parent 6070ce1b
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);
    }

}
+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;
}
+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;
+2 −0
Original line number Diff line number Diff line
@@ -40,6 +40,8 @@ private:
    virtual void dispatchVsync(nsecs_t timestamp, PhysicalDisplayId displayId, uint32_t count) = 0;
    virtual void dispatchHotplug(nsecs_t timestamp, PhysicalDisplayId displayId,
                                 bool connected) = 0;
    virtual void dispatchConfigChanged(nsecs_t timestamp, PhysicalDisplayId displayId,
                                       int32_t configId) = 0;

    virtual int handleEvent(int receiveFd, int events, void* data);
    bool processPendingEvents(nsecs_t* outTimestamp, PhysicalDisplayId* outDisplayId,
+9 −0
Original line number Diff line number Diff line
@@ -70,6 +70,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;

    void scheduleCallbacks();

@@ -164,6 +166,13 @@ void Choreographer::dispatchHotplug(nsecs_t, PhysicalDisplayId displayId, bool c
            this, displayId, toString(connected));
}

void Choreographer::dispatchConfigChanged(nsecs_t, PhysicalDisplayId displayId,
                                          int32_t configId) {
    ALOGV("choreographer %p ~ received config changed event (displayId=%"
            ANDROID_PHYSICAL_DISPLAY_ID_FORMAT ", configId=%s), ignoring.",
            this, displayId, toString(configId));
}

void Choreographer::handleMessage(const Message& message) {
    switch (message.what) {
    case MSG_SCHEDULE_CALLBACKS:
Loading