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

Commit 77136173 authored by Rachel Lee's avatar Rachel Lee Committed by Android (Google) Code Review
Browse files

Merge "Add method to get current vsync from sf directly."

parents 75a83966 ef2e21fa
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@

#include <gui/DisplayEventReceiver.h>
#include <gui/ISurfaceComposer.h>
#include <gui/VsyncEventData.h>

#include <private/gui/ComposerService.h>

@@ -79,6 +80,20 @@ status_t DisplayEventReceiver::requestNextVsync() {
    return NO_INIT;
}

status_t DisplayEventReceiver::getLatestVsyncEventData(VsyncEventData* outVsyncEventData) const {
    if (mEventConnection != nullptr) {
        VsyncEventData vsyncEventData;
        auto status = mEventConnection->getLatestVsyncEventData(&vsyncEventData);
        if (!status.isOk()) {
            ALOGE("Failed to get latest vsync event data: %s", status.exceptionMessage().c_str());
            return status.transactionError();
        }
        *outVsyncEventData = vsyncEventData;
        return NO_ERROR;
    }
    return NO_INIT;
}

ssize_t DisplayEventReceiver::getEvents(DisplayEventReceiver::Event* events,
        size_t count) {
    return DisplayEventReceiver::getEvents(mDataChannel.get(), events, count);
+6 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.gui;

import android.gui.BitTube;
import android.gui.VsyncEventData;

/** @hide */
interface IDisplayEventConnection {
@@ -38,4 +39,9 @@ interface IDisplayEventConnection {
     * requestNextVsync() schedules the next vsync event. It has no effect if the vsync rate is > 0.
     */
    oneway void requestNextVsync(); // Asynchronous

    /*
     * getLatestVsyncEventData() gets the latest vsync event data.
     */
    VsyncEventData getLatestVsyncEventData();
}
+19 −0
Original line number Diff line number Diff line
/*
 * Copyright 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.
 */

package android.gui;

parcelable VsyncEventData cpp_header "gui/VsyncEventData.h";
+5 −0
Original line number Diff line number Diff line
@@ -172,6 +172,11 @@ public:
     */
    status_t requestNextVsync();

    /**
     * getLatestVsyncEventData() gets the latest vsync event data.
     */
    status_t getLatestVsyncEventData(VsyncEventData* outVsyncEventData) const;

private:
    sp<IDisplayEventConnection> mEventConnection;
    std::unique_ptr<gui::BitTube> mDataChannel;
+11 −1
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
#include <mutex>

#include "EventThread.h"
#include "VSyncTracker.h"
#include "VsyncController.h"

namespace android::scheduler {
@@ -114,7 +115,7 @@ private:
    std::chrono::nanoseconds mLastCallTime GUARDED_BY(mMutex) = 0ns;
};

DispSyncSource::DispSyncSource(scheduler::VSyncDispatch& vSyncDispatch,
DispSyncSource::DispSyncSource(VSyncDispatch& vSyncDispatch, VSyncTracker& vSyncTracker,
                               std::chrono::nanoseconds workDuration,
                               std::chrono::nanoseconds readyDuration, bool traceVsync,
                               const char* name)
@@ -122,6 +123,7 @@ DispSyncSource::DispSyncSource(scheduler::VSyncDispatch& vSyncDispatch,
        mValue(base::StringPrintf("VSYNC-%s", name), 0),
        mTraceVsync(traceVsync),
        mVsyncOnLabel(base::StringPrintf("VsyncOn-%s", name)),
        mVSyncTracker(vSyncTracker),
        mWorkDuration(base::StringPrintf("VsyncWorkDuration-%s", name), workDuration),
        mReadyDuration(readyDuration) {
    mCallbackRepeater =
@@ -184,6 +186,14 @@ void DispSyncSource::onVsyncCallback(nsecs_t vsyncTime, nsecs_t targetWakeupTime
    }
}

VSyncSource::VSyncData DispSyncSource::getLatestVSyncData() const {
    std::lock_guard lock(mVsyncMutex);
    nsecs_t expectedPresentTime = mVSyncTracker.nextAnticipatedVSyncTimeFrom(
            systemTime() + mWorkDuration.get().count() + mReadyDuration.count());
    nsecs_t deadline = expectedPresentTime - mWorkDuration.get().count() - mReadyDuration.count();
    return {expectedPresentTime, deadline};
}

void DispSyncSource::dump(std::string& result) const {
    std::lock_guard lock(mVsyncMutex);
    StringAppendF(&result, "DispSyncSource: %s(%s)\n", mName, mEnabled ? "enabled" : "disabled");
Loading