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

Commit 88675f66 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 10127524 from 216dd850 to udc-release

Change-Id: Icb319351fe4ee0021f5be20b1dc787a08e7b8e75
parents 76bf4460 216dd850
Loading
Loading
Loading
Loading
+6 −3
Original line number Original line Diff line number Diff line
@@ -190,7 +190,8 @@ public:
        data.writeInt32(apiType);
        data.writeInt32(apiType);
        data.writeInt32(appUid);
        data.writeInt32(appUid);
        data.writeInt32(appPid);
        data.writeInt32(appPid);
        status_t err = remote()->transact(LOG_FGS_API_BEGIN_TRANSACTION, data, &reply);
        status_t err = remote()->transact(LOG_FGS_API_BEGIN_TRANSACTION, data, &reply,
                                          IBinder::FLAG_ONEWAY);
        if (err != NO_ERROR || ((err = reply.readExceptionCode()) != NO_ERROR)) {
        if (err != NO_ERROR || ((err = reply.readExceptionCode()) != NO_ERROR)) {
            ALOGD("FGS Logger Transaction failed");
            ALOGD("FGS Logger Transaction failed");
            ALOGD("%d", err);
            ALOGD("%d", err);
@@ -205,7 +206,8 @@ public:
        data.writeInt32(apiType);
        data.writeInt32(apiType);
        data.writeInt32(appUid);
        data.writeInt32(appUid);
        data.writeInt32(appPid);
        data.writeInt32(appPid);
        status_t err = remote()->transact(LOG_FGS_API_END_TRANSACTION, data, &reply);
        status_t err =
                remote()->transact(LOG_FGS_API_END_TRANSACTION, data, &reply, IBinder::FLAG_ONEWAY);
        if (err != NO_ERROR || ((err = reply.readExceptionCode()) != NO_ERROR)) {
        if (err != NO_ERROR || ((err = reply.readExceptionCode()) != NO_ERROR)) {
            ALOGD("FGS Logger Transaction failed");
            ALOGD("FGS Logger Transaction failed");
            ALOGD("%d", err);
            ALOGD("%d", err);
@@ -222,7 +224,8 @@ public:
        data.writeInt32(state);
        data.writeInt32(state);
        data.writeInt32(appUid);
        data.writeInt32(appUid);
        data.writeInt32(appPid);
        data.writeInt32(appPid);
        status_t err = remote()->transact(LOG_FGS_API_BEGIN_TRANSACTION, data, &reply);
        status_t err = remote()->transact(LOG_FGS_API_BEGIN_TRANSACTION, data, &reply,
                                          IBinder::FLAG_ONEWAY);
        if (err != NO_ERROR || ((err = reply.readExceptionCode()) != NO_ERROR)) {
        if (err != NO_ERROR || ((err = reply.readExceptionCode()) != NO_ERROR)) {
            ALOGD("FGS Logger Transaction failed");
            ALOGD("FGS Logger Transaction failed");
            ALOGD("%d", err);
            ALOGD("%d", err);
+1 −0
Original line number Original line Diff line number Diff line
@@ -217,6 +217,7 @@ cc_library_shared {
        "DebugEGLImageTracker.cpp",
        "DebugEGLImageTracker.cpp",
        "DisplayEventDispatcher.cpp",
        "DisplayEventDispatcher.cpp",
        "DisplayEventReceiver.cpp",
        "DisplayEventReceiver.cpp",
        "FenceMonitor.cpp",
        "GLConsumer.cpp",
        "GLConsumer.cpp",
        "IConsumerListener.cpp",
        "IConsumerListener.cpp",
        "IGraphicBufferConsumer.cpp",
        "IGraphicBufferConsumer.cpp",
+89 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright 2023 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 ATRACE_TAG ATRACE_TAG_GRAPHICS

#include <gui/FenceMonitor.h>
#include <gui/TraceUtils.h>
#include <log/log.h>

#include <thread>

namespace android::gui {

FenceMonitor::FenceMonitor(const char* name) : mName(name), mFencesQueued(0), mFencesSignaled(0) {
    std::thread thread(&FenceMonitor::loop, this);
    pthread_setname_np(thread.native_handle(), mName);
    thread.detach();
}

void FenceMonitor::queueFence(const sp<Fence>& fence) {
    char message[64];

    std::lock_guard<std::mutex> lock(mMutex);
    if (fence->getSignalTime() != Fence::SIGNAL_TIME_PENDING) {
        snprintf(message, sizeof(message), "%s fence %u has signaled", mName, mFencesQueued);
        ATRACE_NAME(message);
        // Need an increment on both to make the trace number correct.
        mFencesQueued++;
        mFencesSignaled++;
        return;
    }
    snprintf(message, sizeof(message), "Trace %s fence %u", mName, mFencesQueued);
    ATRACE_NAME(message);

    mQueue.push_back(fence);
    mCondition.notify_one();
    mFencesQueued++;
    ATRACE_INT(mName, int32_t(mQueue.size()));
}

void FenceMonitor::loop() {
    while (true) {
        threadLoop();
    }
}

void FenceMonitor::threadLoop() {
    sp<Fence> fence;
    uint32_t fenceNum;
    {
        std::unique_lock<std::mutex> lock(mMutex);
        while (mQueue.empty()) {
            mCondition.wait(lock);
        }
        fence = mQueue[0];
        fenceNum = mFencesSignaled;
    }
    {
        char message[64];
        snprintf(message, sizeof(message), "waiting for %s %u", mName, fenceNum);
        ATRACE_NAME(message);

        status_t result = fence->waitForever(message);
        if (result != OK) {
            ALOGE("Error waiting for fence: %d", result);
        }
    }
    {
        std::lock_guard<std::mutex> lock(mMutex);
        mQueue.pop_front();
        mFencesSignaled++;
        ATRACE_INT(mName, int32_t(mQueue.size()));
    }
}

} // namespace android::gui
 No newline at end of file
+19 −10
Original line number Original line Diff line number Diff line
@@ -59,15 +59,13 @@ public:


    virtual ~BpSurfaceComposer();
    virtual ~BpSurfaceComposer();


    status_t setTransactionState(const FrameTimelineInfo& frameTimelineInfo,
    status_t setTransactionState(
                                 Vector<ComposerState>& state, const Vector<DisplayState>& displays,
            const FrameTimelineInfo& frameTimelineInfo, Vector<ComposerState>& state,
                                 uint32_t flags, const sp<IBinder>& applyToken,
            const Vector<DisplayState>& displays, uint32_t flags, const sp<IBinder>& applyToken,
                                 InputWindowCommands commands, int64_t desiredPresentTime,
            InputWindowCommands commands, int64_t desiredPresentTime, bool isAutoTimestamp,
                                 bool isAutoTimestamp,
            const std::vector<client_cache_t>& uncacheBuffers, bool hasListenerCallbacks,
                                 const std::vector<client_cache_t>& uncacheBuffers,
            const std::vector<ListenerCallbacks>& listenerCallbacks, uint64_t transactionId,
                                 bool hasListenerCallbacks,
            const std::vector<uint64_t>& mergedTransactionIds) override {
                                 const std::vector<ListenerCallbacks>& listenerCallbacks,
                                 uint64_t transactionId) override {
        Parcel data, reply;
        Parcel data, reply;
        data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
        data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());


@@ -103,6 +101,11 @@ public:


        SAFE_PARCEL(data.writeUint64, transactionId);
        SAFE_PARCEL(data.writeUint64, transactionId);


        SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(mergedTransactionIds.size()));
        for (auto mergedTransactionId : mergedTransactionIds) {
            SAFE_PARCEL(data.writeUint64, mergedTransactionId);
        }

        if (flags & ISurfaceComposer::eOneWay) {
        if (flags & ISurfaceComposer::eOneWay) {
            return remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE,
            return remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE,
                    data, &reply, IBinder::FLAG_ONEWAY);
                    data, &reply, IBinder::FLAG_ONEWAY);
@@ -187,10 +190,16 @@ status_t BnSurfaceComposer::onTransact(
            uint64_t transactionId = -1;
            uint64_t transactionId = -1;
            SAFE_PARCEL(data.readUint64, &transactionId);
            SAFE_PARCEL(data.readUint64, &transactionId);


            SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
            std::vector<uint64_t> mergedTransactions(count);
            for (size_t i = 0; i < count; i++) {
                SAFE_PARCEL(data.readUint64, &mergedTransactions[i]);
            }

            return setTransactionState(frameTimelineInfo, state, displays, stateFlags, applyToken,
            return setTransactionState(frameTimelineInfo, state, displays, stateFlags, applyToken,
                                       std::move(inputWindowCommands), desiredPresentTime,
                                       std::move(inputWindowCommands), desiredPresentTime,
                                       isAutoTimestamp, uncacheBuffers, hasListenerCallbacks,
                                       isAutoTimestamp, uncacheBuffers, hasListenerCallbacks,
                                       listenerCallbacks, transactionId);
                                       listenerCallbacks, transactionId, mergedTransactions);
        }
        }
        default: {
        default: {
            return BBinder::onTransact(code, data, reply, flags);
            return BBinder::onTransact(code, data, reply, flags);
+4 −79
Original line number Original line Diff line number Diff line
@@ -30,6 +30,7 @@
#include <android/gui/DisplayStatInfo.h>
#include <android/gui/DisplayStatInfo.h>
#include <android/native_window.h>
#include <android/native_window.h>


#include <gui/FenceMonitor.h>
#include <gui/TraceUtils.h>
#include <gui/TraceUtils.h>
#include <utils/Log.h>
#include <utils/Log.h>
#include <utils/NativeHandle.h>
#include <utils/NativeHandle.h>
@@ -545,82 +546,6 @@ int Surface::setSwapInterval(int interval) {
    return NO_ERROR;
    return NO_ERROR;
}
}


class FenceMonitor {
public:
    explicit FenceMonitor(const char* name) : mName(name), mFencesQueued(0), mFencesSignaled(0) {
        std::thread thread(&FenceMonitor::loop, this);
        pthread_setname_np(thread.native_handle(), mName);
        thread.detach();
    }

    void queueFence(const sp<Fence>& fence) {
        char message[64];

        std::lock_guard<std::mutex> lock(mMutex);
        if (fence->getSignalTime() != Fence::SIGNAL_TIME_PENDING) {
            snprintf(message, sizeof(message), "%s fence %u has signaled", mName, mFencesQueued);
            ATRACE_NAME(message);
            // Need an increment on both to make the trace number correct.
            mFencesQueued++;
            mFencesSignaled++;
            return;
        }
        snprintf(message, sizeof(message), "Trace %s fence %u", mName, mFencesQueued);
        ATRACE_NAME(message);

        mQueue.push_back(fence);
        mCondition.notify_one();
        mFencesQueued++;
        ATRACE_INT(mName, int32_t(mQueue.size()));
    }

private:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    void loop() {
        while (true) {
            threadLoop();
        }
    }
#pragma clang diagnostic pop

    void threadLoop() {
        sp<Fence> fence;
        uint32_t fenceNum;
        {
            std::unique_lock<std::mutex> lock(mMutex);
            while (mQueue.empty()) {
                mCondition.wait(lock);
            }
            fence = mQueue[0];
            fenceNum = mFencesSignaled;
        }
        {
            char message[64];
            snprintf(message, sizeof(message), "waiting for %s %u", mName, fenceNum);
            ATRACE_NAME(message);

            status_t result = fence->waitForever(message);
            if (result != OK) {
                ALOGE("Error waiting for fence: %d", result);
            }
        }
        {
            std::lock_guard<std::mutex> lock(mMutex);
            mQueue.pop_front();
            mFencesSignaled++;
            ATRACE_INT(mName, int32_t(mQueue.size()));
        }
    }

    const char* mName;
    uint32_t mFencesQueued;
    uint32_t mFencesSignaled;
    std::deque<sp<Fence>> mQueue;
    std::condition_variable mCondition;
    std::mutex mMutex;
};

void Surface::getDequeueBufferInputLocked(
void Surface::getDequeueBufferInputLocked(
        IGraphicBufferProducer::DequeueBufferInput* dequeueInput) {
        IGraphicBufferProducer::DequeueBufferInput* dequeueInput) {
    LOG_ALWAYS_FATAL_IF(dequeueInput == nullptr, "input is null");
    LOG_ALWAYS_FATAL_IF(dequeueInput == nullptr, "input is null");
@@ -694,7 +619,7 @@ int Surface::dequeueBuffer(android_native_buffer_t** buffer, int* fenceFd) {
    ALOGE_IF(fence == nullptr, "Surface::dequeueBuffer: received null Fence! buf=%d", buf);
    ALOGE_IF(fence == nullptr, "Surface::dequeueBuffer: received null Fence! buf=%d", buf);


    if (CC_UNLIKELY(atrace_is_tag_enabled(ATRACE_TAG_GRAPHICS))) {
    if (CC_UNLIKELY(atrace_is_tag_enabled(ATRACE_TAG_GRAPHICS))) {
        static FenceMonitor hwcReleaseThread("HWC release");
        static gui::FenceMonitor hwcReleaseThread("HWC release");
        hwcReleaseThread.queueFence(fence);
        hwcReleaseThread.queueFence(fence);
    }
    }


@@ -893,7 +818,7 @@ int Surface::dequeueBuffers(std::vector<BatchBuffer>* buffers) {
        sp<GraphicBuffer>& gbuf(mSlots[slot].buffer);
        sp<GraphicBuffer>& gbuf(mSlots[slot].buffer);


        if (CC_UNLIKELY(atrace_is_tag_enabled(ATRACE_TAG_GRAPHICS))) {
        if (CC_UNLIKELY(atrace_is_tag_enabled(ATRACE_TAG_GRAPHICS))) {
            static FenceMonitor hwcReleaseThread("HWC release");
            static gui::FenceMonitor hwcReleaseThread("HWC release");
            hwcReleaseThread.queueFence(output.fence);
            hwcReleaseThread.queueFence(output.fence);
        }
        }


@@ -1163,7 +1088,7 @@ void Surface::onBufferQueuedLocked(int slot, sp<Fence> fence,
    mQueueBufferCondition.broadcast();
    mQueueBufferCondition.broadcast();


    if (CC_UNLIKELY(atrace_is_tag_enabled(ATRACE_TAG_GRAPHICS))) {
    if (CC_UNLIKELY(atrace_is_tag_enabled(ATRACE_TAG_GRAPHICS))) {
        static FenceMonitor gpuCompletionThread("GPU completion");
        static gui::FenceMonitor gpuCompletionThread("GPU completion");
        gpuCompletionThread.queueFence(fence);
        gpuCompletionThread.queueFence(fence);
    }
    }
}
}
Loading