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

Commit 814d19cc authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 7389169 from 7f09431b to sc-d1-release

Change-Id: I90f1ca7d769a9a37c0ab5467c3780fc1bf5905f3
parents 9c0248a8 7f09431b
Loading
Loading
Loading
Loading

include/input/LatencyStatistics.h

deleted100644 → 0
+0 −59
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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.
 */

#ifndef _UI_INPUT_STATISTICS_H
#define _UI_INPUT_STATISTICS_H

#include <android-base/chrono_utils.h>

#include <stddef.h>

namespace android {

class LatencyStatistics {
private:
    /* Minimum sample recorded */
    float mMin;
    /* Maximum sample recorded */
    float mMax;
    /* Sum of all samples recorded */
    float mSum;
    /* Sum of all the squares of samples recorded */
    float mSum2;
    /* Count of all samples recorded */
    size_t mCount;
    /* The last time statistics were reported */
    std::chrono::steady_clock::time_point mLastReportTime;
    /* Statistics Report Frequency */
    const std::chrono::seconds mReportPeriod;

public:
    LatencyStatistics(std::chrono::seconds period);

    void addValue(float);
    void reset();
    bool shouldReport();

    float getMean();
    float getMin();
    float getMax();
    float getStDev();
    size_t getCount();
};

} // namespace android

#endif // _UI_INPUT_STATISTICS_H
+12 −10
Original line number Diff line number Diff line
@@ -489,14 +489,16 @@ void IPCThreadState::flushCommands()

bool IPCThreadState::flushIfNeeded()
{
    if (mIsLooper || mServingStackPointer != nullptr) {
    if (mIsLooper || mServingStackPointer != nullptr || mIsFlushing) {
        return false;
    }
    mIsFlushing = true;
    // In case this thread is not a looper and is not currently serving a binder transaction,
    // there's no guarantee that this thread will call back into the kernel driver any time
    // soon. Therefore, flush pending commands such as BC_FREE_BUFFER, to prevent them from getting
    // stuck in this thread's out buffer.
    flushCommands();
    mIsFlushing = false;
    return true;
}

@@ -852,10 +854,10 @@ IPCThreadState::IPCThreadState()
        mWorkSource(kUnsetWorkSource),
        mPropagateWorkSource(false),
        mIsLooper(false),
        mIsFlushing(false),
        mStrictModePolicy(0),
        mLastTransactionBinderFlags(0),
      mCallRestriction(mProcess->mCallRestriction)
{
        mCallRestriction(mProcess->mCallRestriction) {
    pthread_setspecific(gTLS, this);
    clearCaller();
    mIn.setDataCapacity(256);
+1 −0
Original line number Diff line number Diff line
@@ -212,6 +212,7 @@ private:
            // Whether the work source should be propagated.
            bool                mPropagateWorkSource;
            bool                mIsLooper;
            bool mIsFlushing;
            int32_t             mStrictModePolicy;
            int32_t             mLastTransactionBinderFlags;
            CallRestriction     mCallRestriction;
+20 −0
Original line number Diff line number Diff line
@@ -1621,6 +1621,26 @@ status_t BufferQueueProducer::getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer,
    return NO_ERROR;
}

status_t BufferQueueProducer::getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer, sp<Fence>* outFence,
                                                  Rect* outRect, uint32_t* outTransform) {
    ATRACE_CALL();
    BQ_LOGV("getLastQueuedBuffer");

    std::lock_guard<std::mutex> lock(mCore->mMutex);
    if (mCore->mLastQueuedSlot == BufferItem::INVALID_BUFFER_SLOT) {
        *outBuffer = nullptr;
        *outFence = Fence::NO_FENCE;
        return NO_ERROR;
    }

    *outBuffer = mSlots[mCore->mLastQueuedSlot].mGraphicBuffer;
    *outFence = mLastQueueBufferFence;
    *outRect = mLastQueuedCrop;
    *outTransform = mLastQueuedTransform;

    return NO_ERROR;
}

void BufferQueueProducer::getFrameTimestamps(FrameEventHistoryDelta* outDelta) {
    addAndGetFrameTimestamps(nullptr, outDelta);
}
+95 −0
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@ enum {
    QUEUE_BUFFERS,
    CANCEL_BUFFERS,
    QUERY_MULTIPLE,
    GET_LAST_QUEUED_BUFFER2,
};

class BpGraphicBufferProducer : public BpInterface<IGraphicBufferProducer>
@@ -646,6 +647,56 @@ public:
        return result;
    }

    virtual status_t getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer, sp<Fence>* outFence,
                                         Rect* outRect, uint32_t* outTransform) override {
        Parcel data, reply;
        data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
        status_t result = remote()->transact(GET_LAST_QUEUED_BUFFER2, data, &reply);
        if (result != NO_ERROR) {
            ALOGE("getLastQueuedBuffer failed to transact: %d", result);
            return result;
        }
        status_t remoteError = NO_ERROR;
        result = reply.readInt32(&remoteError);
        if (result != NO_ERROR) {
            ALOGE("getLastQueuedBuffer failed to read status: %d", result);
            return result;
        }
        if (remoteError != NO_ERROR) {
            return remoteError;
        }
        bool hasBuffer = false;
        result = reply.readBool(&hasBuffer);
        if (result != NO_ERROR) {
            ALOGE("getLastQueuedBuffer failed to read buffer: %d", result);
            return result;
        }
        sp<GraphicBuffer> buffer;
        if (hasBuffer) {
            buffer = new GraphicBuffer();
            result = reply.read(*buffer);
            if (result == NO_ERROR) {
                result = reply.read(*outRect);
            }
            if (result == NO_ERROR) {
                result = reply.readUint32(outTransform);
            }
        }
        if (result != NO_ERROR) {
            ALOGE("getLastQueuedBuffer failed to read buffer: %d", result);
            return result;
        }
        sp<Fence> fence(new Fence);
        result = reply.read(*fence);
        if (result != NO_ERROR) {
            ALOGE("getLastQueuedBuffer failed to read fence: %d", result);
            return result;
        }
        *outBuffer = buffer;
        *outFence = fence;
        return result;
    }

    virtual void getFrameTimestamps(FrameEventHistoryDelta* outDelta) {
        Parcel data, reply;
        status_t result = data.writeInterfaceToken(
@@ -870,6 +921,11 @@ public:
                outBuffer, outFence, outTransformMatrix);
    }

    status_t getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer, sp<Fence>* outFence, Rect* outRect,
                                 uint32_t* outTransform) override {
        return mBase->getLastQueuedBuffer(outBuffer, outFence, outRect, outTransform);
    }

    void getFrameTimestamps(FrameEventHistoryDelta* outDelta) override {
        return mBase->getFrameTimestamps(outDelta);
    }
@@ -1362,6 +1418,45 @@ status_t BnGraphicBufferProducer::onTransact(
            }
            return NO_ERROR;
        }
        case GET_LAST_QUEUED_BUFFER2: {
            CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
            sp<GraphicBuffer> buffer(nullptr);
            sp<Fence> fence(Fence::NO_FENCE);
            Rect crop;
            uint32_t transform;
            status_t result = getLastQueuedBuffer(&buffer, &fence, &crop, &transform);
            reply->writeInt32(result);
            if (result != NO_ERROR) {
                return result;
            }
            if (!buffer.get()) {
                reply->writeBool(false);
            } else {
                reply->writeBool(true);
                result = reply->write(*buffer);
                if (result == NO_ERROR) {
                    result = reply->write(crop);
                }
                if (result == NO_ERROR) {
                    result = reply->writeUint32(transform);
                }
            }
            if (result != NO_ERROR) {
                ALOGE("getLastQueuedBuffer failed to write buffer: %d", result);
                return result;
            }
            if (fence == nullptr) {
                ALOGE("getLastQueuedBuffer returned a NULL fence, setting to Fence::NO_FENCE");
                fence = Fence::NO_FENCE;
            }
            result = reply->write(*fence);
            if (result != NO_ERROR) {
                ALOGE("getLastQueuedBuffer failed to write fence: %d", result);
                return result;
            }
            return NO_ERROR;
        }

        case GET_FRAME_TIMESTAMPS: {
            CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
            FrameEventHistoryDelta frameTimestamps;
Loading