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

Commit 41b5d5a7 authored by Ady Abraham's avatar Ady Abraham Committed by Android (Google) Code Review
Browse files

Merge "Shared timeline plumbing"

parents a471b196 6fabb5aa
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -660,8 +660,7 @@ public final class Choreographer {
        ThreadedRenderer.setFPSDivisor(divisor);
    }

    @UnsupportedAppUsage
    void doFrame(long frameTimeNanos, int frame) {
    void doFrame(long frameTimeNanos, int frame, long frameTimelineVsyncId) {
        final long startNanos;
        synchronized (mLock) {
            if (!mFrameScheduled) {
@@ -711,7 +710,7 @@ public final class Choreographer {
                }
            }

            mFrameInfo.setVsync(intendedFrameTimeNanos, frameTimeNanos);
            mFrameInfo.setVsync(intendedFrameTimeNanos, frameTimeNanos, frameTimelineVsyncId);
            mFrameScheduled = false;
            mLastFrameTimeNanos = frameTimeNanos;
        }
@@ -897,7 +896,7 @@ public final class Choreographer {
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case MSG_DO_FRAME:
                    doFrame(System.nanoTime(), 0);
                    doFrame(System.nanoTime(), 0, FrameInfo.INVALID_VSYNC_ID);
                    break;
                case MSG_DO_SCHEDULE_VSYNC:
                    doScheduleVsync();
@@ -914,6 +913,7 @@ public final class Choreographer {
        private boolean mHavePendingVsync;
        private long mTimestampNanos;
        private int mFrame;
        private long mFrameTimelineVsyncId;

        public FrameDisplayEventReceiver(Looper looper, int vsyncSource) {
            super(looper, vsyncSource, CONFIG_CHANGED_EVENT_SUPPRESS);
@@ -923,7 +923,8 @@ public final class Choreographer {
        // the internal display and DisplayEventReceiver#scheduleVsync only allows requesting VSYNC
        // for the internal display implicitly.
        @Override
        public void onVsync(long timestampNanos, long physicalDisplayId, int frame) {
        public void onVsync(long timestampNanos, long physicalDisplayId, int frame,
                long frameTimelineVsyncId) {
            // Post the vsync event to the Handler.
            // The idea is to prevent incoming vsync events from completely starving
            // the message queue.  If there are no messages in the queue with timestamps
@@ -946,6 +947,7 @@ public final class Choreographer {

            mTimestampNanos = timestampNanos;
            mFrame = frame;
            mFrameTimelineVsyncId = frameTimelineVsyncId;
            Message msg = Message.obtain(mHandler, this);
            msg.setAsynchronous(true);
            mHandler.sendMessageAtTime(msg, timestampNanos / TimeUtils.NANOS_PER_MS);
@@ -954,7 +956,7 @@ public final class Choreographer {
        @Override
        public void run() {
            mHavePendingVsync = false;
            doFrame(mTimestampNanos, mFrame);
            doFrame(mTimestampNanos, mFrame, mFrameTimelineVsyncId);
        }
    }

+7 −5
Original line number Diff line number Diff line
@@ -154,9 +154,11 @@ public abstract class DisplayEventReceiver {
     * timebase.
     * @param physicalDisplayId Stable display ID that uniquely describes a (display, port) pair.
     * @param frame The frame number.  Increases by one for each vertical sync interval.
     * @param frameTimelineVsyncId The frame timeline vsync id, used to correlate a frame
     * produced by HWUI with the timeline data stored in Surface Flinger.
     */
    @UnsupportedAppUsage
    public void onVsync(long timestampNanos, long physicalDisplayId, int frame) {
    public void onVsync(long timestampNanos, long physicalDisplayId, int frame,
            long frameTimelineVsyncId) {
    }

    /**
@@ -198,9 +200,9 @@ public abstract class DisplayEventReceiver {

    // Called from native code.
    @SuppressWarnings("unused")
    @UnsupportedAppUsage
    private void dispatchVsync(long timestampNanos, long physicalDisplayId, int frame) {
        onVsync(timestampNanos, physicalDisplayId, frame);
    private void dispatchVsync(long timestampNanos, long physicalDisplayId, int frame,
            long frameTimelineVsyncId) {
        onVsync(timestampNanos, physicalDisplayId, frame, frameTimelineVsyncId);
    }

    // Called from native code.
+16 −14
Original line number Diff line number Diff line
@@ -189,6 +189,7 @@ public final class FrameMetrics {
     */
    @IntDef ({
            Index.FLAGS,
            Index.FRAME_TIMELINE_VSYNC_ID,
            Index.INTENDED_VSYNC,
            Index.VSYNC,
            Index.OLDEST_INPUT_EVENT,
@@ -206,21 +207,22 @@ public final class FrameMetrics {
    @Retention(RetentionPolicy.SOURCE)
    private @interface Index {
        int FLAGS = 0;
        int INTENDED_VSYNC = 1;
        int VSYNC = 2;
        int OLDEST_INPUT_EVENT = 3;
        int NEWEST_INPUT_EVENT = 4;
        int HANDLE_INPUT_START = 5;
        int ANIMATION_START = 6;
        int PERFORM_TRAVERSALS_START = 7;
        int DRAW_START = 8;
        int SYNC_QUEUED = 9;
        int SYNC_START = 10;
        int ISSUE_DRAW_COMMANDS_START = 11;
        int SWAP_BUFFERS = 12;
        int FRAME_COMPLETED = 13;
        int FRAME_TIMELINE_VSYNC_ID = 1;
        int INTENDED_VSYNC = 2;
        int VSYNC = 3;
        int OLDEST_INPUT_EVENT = 4;
        int NEWEST_INPUT_EVENT = 5;
        int HANDLE_INPUT_START = 6;
        int ANIMATION_START = 7;
        int PERFORM_TRAVERSALS_START = 8;
        int DRAW_START = 9;
        int SYNC_QUEUED = 10;
        int SYNC_START = 11;
        int ISSUE_DRAW_COMMANDS_START = 12;
        int SWAP_BUFFERS = 13;
        int FRAME_COMPLETED = 14;

        int FRAME_STATS_COUNT = 17; // must always be last
        int FRAME_STATS_COUNT = 18; // must always be last
    }

    /*
+6 −5
Original line number Diff line number Diff line
@@ -59,7 +59,8 @@ private:
    jobject mReceiverWeakGlobal;
    sp<MessageQueue> mMessageQueue;

    void dispatchVsync(nsecs_t timestamp, PhysicalDisplayId displayId, uint32_t count) override;
    void dispatchVsync(nsecs_t timestamp, PhysicalDisplayId displayId, uint32_t count,
                       int64_t sharedTimelineFrameCount) override;
    void dispatchHotplug(nsecs_t timestamp, PhysicalDisplayId displayId, bool connected) override;
    void dispatchConfigChanged(nsecs_t timestamp, PhysicalDisplayId displayId,
                               int32_t configId, nsecs_t vsyncPeriod) override;
@@ -90,14 +91,14 @@ void NativeDisplayEventReceiver::dispose() {
}

void NativeDisplayEventReceiver::dispatchVsync(nsecs_t timestamp, PhysicalDisplayId displayId,
                                               uint32_t count) {
                                               uint32_t count, int64_t frameTimelineVsyncId) {
    JNIEnv* env = AndroidRuntime::getJNIEnv();

    ScopedLocalRef<jobject> receiverObj(env, jniGetReferent(env, mReceiverWeakGlobal));
    if (receiverObj.get()) {
        ALOGV("receiver %p ~ Invoking vsync handler.", this);
        env->CallVoidMethod(receiverObj.get(), gDisplayEventReceiverClassInfo.dispatchVsync,
                            timestamp, displayId.value, count);
                            timestamp, displayId.value, count, frameTimelineVsyncId);
        ALOGV("receiver %p ~ Returned from vsync handler.", this);
    }

@@ -196,8 +197,8 @@ int register_android_view_DisplayEventReceiver(JNIEnv* env) {
    jclass clazz = FindClassOrDie(env, "android/view/DisplayEventReceiver");
    gDisplayEventReceiverClassInfo.clazz = MakeGlobalRefOrDie(env, clazz);

    gDisplayEventReceiverClassInfo.dispatchVsync = GetMethodIDOrDie(env,
            gDisplayEventReceiverClassInfo.clazz, "dispatchVsync", "(JJI)V");
    gDisplayEventReceiverClassInfo.dispatchVsync =
            GetMethodIDOrDie(env, gDisplayEventReceiverClassInfo.clazz, "dispatchVsync", "(JJIJ)V");
    gDisplayEventReceiverClassInfo.dispatchHotplug = GetMethodIDOrDie(env,
            gDisplayEventReceiverClassInfo.clazz, "dispatchHotplug", "(JJZ)V");
    gDisplayEventReceiverClassInfo.dispatchConfigChanged = GetMethodIDOrDie(env,
+16 −10
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ import java.lang.annotation.RetentionPolicy;
 */
public final class FrameInfo {

    public long[] frameInfo = new long[9];
    public long[] frameInfo = new long[10];

    // Various flags set to provide extra metadata about the current frame
    private static final int FLAGS = 0;
@@ -51,38 +51,44 @@ public final class FrameInfo {
    // A renderer associated with just a Surface, not with a ViewRootImpl instance.
    public static final long FLAG_SURFACE_CANVAS = 1 << 2;

    // An invalid vsync id to be used when FRAME_TIMELINE_VSYNC_ID is unknown
    public static final long INVALID_VSYNC_ID = -1;

    @LongDef(flag = true, value = {
            FLAG_WINDOW_LAYOUT_CHANGED, FLAG_SURFACE_CANVAS })
    @Retention(RetentionPolicy.SOURCE)
    public @interface FrameInfoFlags {}

    private static final int FRAME_TIMELINE_VSYNC_ID = 1;

    // The intended vsync time, unadjusted by jitter
    private static final int INTENDED_VSYNC = 1;
    private static final int INTENDED_VSYNC = 2;

    // Jitter-adjusted vsync time, this is what was used as input into the
    // animation & drawing system
    private static final int VSYNC = 2;
    private static final int VSYNC = 3;

    // The time of the oldest input event
    private static final int OLDEST_INPUT_EVENT = 3;
    private static final int OLDEST_INPUT_EVENT = 4;

    // The time of the newest input event
    private static final int NEWEST_INPUT_EVENT = 4;
    private static final int NEWEST_INPUT_EVENT = 5;

    // When input event handling started
    private static final int HANDLE_INPUT_START = 5;
    private static final int HANDLE_INPUT_START = 6;

    // When animation evaluations started
    private static final int ANIMATION_START = 6;
    private static final int ANIMATION_START = 7;

    // When ViewRootImpl#performTraversals() started
    private static final int PERFORM_TRAVERSALS_START = 7;
    private static final int PERFORM_TRAVERSALS_START = 8;

    // When View:draw() started
    private static final int DRAW_START = 8;
    private static final int DRAW_START = 9;

    /** checkstyle */
    public void setVsync(long intendedVsync, long usedVsync) {
    public void setVsync(long intendedVsync, long usedVsync, long frameTimelineVsyncId) {
        frameInfo[FRAME_TIMELINE_VSYNC_ID] = frameTimelineVsyncId;
        frameInfo[INTENDED_VSYNC] = intendedVsync;
        frameInfo[VSYNC] = usedVsync;
        frameInfo[OLDEST_INPUT_EVENT] = Long.MAX_VALUE;
Loading