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

Commit 58ca29d4 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Add inputEventId to SurfaceFrame

SurfaceFrame will now be aware of the id of the input event that caused
the current frame.

The flow of input event id is inputflinger -> app -> surfaceflinger.
Here, we are adding the 'inputEventId' parameter to the
'setFrameTimelineVsync' call. This call will now be responsible for
setting two pieces of information: the vsync id, and the input event id.
Since it will no longer be limited to the vsync id, we rename this call
to "setFrameTimelineInfo".

Once the inputEventId is stored in SurfaceFrame, we will add a binder
call to send the frame timing information to inputflinger (separate,
future CL). This will allow input to reconstruct the entire sequence of
events (at what time was input event getting processed in system_server,
app, and surfaceflinger) and will provide the ability to measure
end-to-end touch latency.

In a separate change, we will also add ATRACE calls to allow manual /
script-based latency analysis for local debugging. We will now know
which input event is being processed in surfaceflinger.

Bug: 169866723
Bug: 129481165
Design doc: https://docs.google.com/document/d/1G3bLaZYSmbe6AKcL-6ZChvrw_B_LXEz29Z6Ed9QoYXY/edit#
Test: atest WMShellUnitTests SurfaceParcelable_test libgui_test IPC_test SurfaceFlinger_test

Change-Id: If7e0eee82603b38b396b53ad7ced660973efcb50
parent f464f581
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ cc_library_shared {

    srcs: [
        ":framework_native_aidl",
        ":inputconstants_aidl",
        ":libgui_aidl",
        ":libgui_bufferqueue_sources",

@@ -62,6 +63,7 @@ cc_library_shared {
        "DebugEGLImageTracker.cpp",
        "DisplayEventDispatcher.cpp",
        "DisplayEventReceiver.cpp",
        "FrameTimelineInfo.cpp",
        "GLConsumer.cpp",
        "IConsumerListener.cpp",
        "IDisplayEventConnection.cpp",
@@ -154,6 +156,7 @@ cc_library_static {
    defaults: ["libgui_bufferqueue-defaults"],

    srcs: [
        ":inputconstants_aidl",
        ":libgui_aidl",
        ":libgui_bufferqueue_sources",
    ],
+7 −7
Original line number Diff line number Diff line
@@ -353,9 +353,9 @@ void BLASTBufferQueue::processNextBufferLocked(bool useNextTransaction) {
    }
    t->setFrameNumber(mSurfaceControl, bufferItem.mFrameNumber);

    if (!mNextFrameTimelineVsyncIdQueue.empty()) {
        t->setFrameTimelineVsync(mSurfaceControl, mNextFrameTimelineVsyncIdQueue.front());
        mNextFrameTimelineVsyncIdQueue.pop();
    if (!mNextFrameTimelineInfoQueue.empty()) {
        t->setFrameTimelineInfo(mSurfaceControl, mNextFrameTimelineInfoQueue.front());
        mNextFrameTimelineInfoQueue.pop();
    }

    if (mAutoRefresh != bufferItem.mAutoRefresh) {
@@ -514,8 +514,8 @@ public:
        return mBbq->setFrameRate(frameRate, compatibility, shouldBeSeamless);
    }

    status_t setFrameTimelineVsync(int64_t frameTimelineVsyncId) override {
        return mBbq->setFrameTimelineVsync(frameTimelineVsyncId);
    status_t setFrameTimelineInfo(const FrameTimelineInfo& frameTimelineInfo) override {
        return mBbq->setFrameTimelineInfo(frameTimelineInfo);
    }
};

@@ -529,9 +529,9 @@ status_t BLASTBufferQueue::setFrameRate(float frameRate, int8_t compatibility,
    return t.setFrameRate(mSurfaceControl, frameRate, compatibility, shouldBeSeamless).apply();
}

status_t BLASTBufferQueue::setFrameTimelineVsync(int64_t frameTimelineVsyncId) {
status_t BLASTBufferQueue::setFrameTimelineInfo(const FrameTimelineInfo& frameTimelineInfo) {
    std::unique_lock _lock{mMutex};
    mNextFrameTimelineVsyncIdQueue.push(frameTimelineVsyncId);
    mNextFrameTimelineInfoQueue.push(frameTimelineInfo);
    return OK;
}

+62 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#define LOG_TAG "FrameTimelineInfo"

#include <inttypes.h>

#include <android/os/IInputConstants.h>
#include <gui/FrameTimelineInfo.h>
#include <gui/LayerState.h>
#include <utils/Errors.h>

#include <cmath>

using android::os::IInputConstants;

namespace android {

status_t FrameTimelineInfo::write(Parcel& output) const {
    SAFE_PARCEL(output.writeInt64, vsyncId);
    SAFE_PARCEL(output.writeInt32, inputEventId);
    return NO_ERROR;
}

status_t FrameTimelineInfo::read(const Parcel& input) {
    SAFE_PARCEL(input.readInt64, &vsyncId);
    SAFE_PARCEL(input.readInt32, &inputEventId);
    return NO_ERROR;
}

void FrameTimelineInfo::merge(const FrameTimelineInfo& other) {
    // When merging vsync Ids we take the oldest valid one
    if (vsyncId != INVALID_VSYNC_ID && other.vsyncId != INVALID_VSYNC_ID) {
        if (other.vsyncId > vsyncId) {
            vsyncId = other.vsyncId;
            inputEventId = other.inputEventId;
        }
    } else if (vsyncId == INVALID_VSYNC_ID) {
        vsyncId = other.vsyncId;
        inputEventId = other.inputEventId;
    }
}

void FrameTimelineInfo::clear() {
    vsyncId = INVALID_VSYNC_ID;
    inputEventId = IInputConstants::INVALID_INPUT_EVENT_ID;
}

}; // namespace android
+117 −134

File changed.

Preview size limit exceeded, changes collapsed.

+2 −4
Original line number Diff line number Diff line
@@ -92,10 +92,8 @@ status_t FrameEventHistoryStats::readFromParcel(const Parcel* input) {
    return err;
}

JankData::JankData() :
        frameVsyncId(ISurfaceComposer::INVALID_VSYNC_ID),
        jankType(JankType::None) {
}
JankData::JankData()
      : frameVsyncId(FrameTimelineInfo::INVALID_VSYNC_ID), jankType(JankType::None) {}

status_t JankData::writeToParcel(Parcel* output) const {
    SAFE_PARCEL(output->writeInt64, frameVsyncId);
Loading