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

Commit c62024fb authored by Huihong Luo's avatar Huihong Luo Committed by Android (Google) Code Review
Browse files

Merge "Migrate ITransactionCompletedListener to AIDL"

parents 1b3801e3 c50b4988
Loading
Loading
Loading
Loading
+0 −1
Original line number Original line Diff line number Diff line
@@ -230,7 +230,6 @@ constexpr const char* const kManualInterfaces[] = {
        "android.graphicsenv.IGpuService",
        "android.graphicsenv.IGpuService",
        "android.gui.IConsumerListener",
        "android.gui.IConsumerListener",
        "android.gui.IGraphicBufferConsumer",
        "android.gui.IGraphicBufferConsumer",
        "android.gui.ITransactionComposerListener",
        "android.gui.SensorEventConnection",
        "android.gui.SensorEventConnection",
        "android.gui.SensorServer",
        "android.gui.SensorServer",
        "android.hardware.ICamera",
        "android.hardware.ICamera",
+1 −0
Original line number Original line Diff line number Diff line
@@ -42,6 +42,7 @@ using namespace aidl::android::hardware::graphics;


namespace android {
namespace android {


using gui::CallbackId;
using gui::DisplayCaptureArgs;
using gui::DisplayCaptureArgs;
using gui::IDisplayEventConnection;
using gui::IDisplayEventConnection;
using gui::IRegionSamplingListener;
using gui::IRegionSamplingListener;
+3 −68
Original line number Original line Diff line number Diff line
@@ -21,22 +21,11 @@
#include <optional>
#include <optional>


#include <gui/ISurfaceComposer.h>
#include <gui/ISurfaceComposer.h>
#include <gui/ITransactionCompletedListener.h>
#include <gui/LayerState.h>
#include <gui/LayerState.h>
#include <gui/ListenerStats.h>
#include <private/gui/ParcelUtils.h>
#include <private/gui/ParcelUtils.h>


namespace android {
namespace android::gui {

namespace { // Anonymous

enum class Tag : uint32_t {
    ON_TRANSACTION_COMPLETED = IBinder::FIRST_CALL_TRANSACTION,
    ON_RELEASE_BUFFER,
    ON_TRANSACTION_QUEUE_STALLED,
    LAST = ON_TRANSACTION_QUEUE_STALLED,
};

} // Anonymous namespace


status_t FrameEventHistoryStats::writeToParcel(Parcel* output) const {
status_t FrameEventHistoryStats::writeToParcel(Parcel* output) const {
    status_t err = output->writeUint64(frameNumber);
    status_t err = output->writeUint64(frameNumber);
@@ -274,60 +263,6 @@ ListenerStats ListenerStats::createEmpty(
    return listenerStats;
    return listenerStats;
}
}


class BpTransactionCompletedListener : public SafeBpInterface<ITransactionCompletedListener> {
public:
    explicit BpTransactionCompletedListener(const sp<IBinder>& impl)
          : SafeBpInterface<ITransactionCompletedListener>(impl, "BpTransactionCompletedListener") {
    }

    ~BpTransactionCompletedListener() override;

    void onTransactionCompleted(ListenerStats stats) override {
        callRemoteAsync<decltype(&ITransactionCompletedListener::
                                         onTransactionCompleted)>(Tag::ON_TRANSACTION_COMPLETED,
                                                                  stats);
    }

    void onReleaseBuffer(ReleaseCallbackId callbackId, sp<Fence> releaseFence,
                         uint32_t currentMaxAcquiredBufferCount) override {
        callRemoteAsync<decltype(&ITransactionCompletedListener::
                                         onReleaseBuffer)>(Tag::ON_RELEASE_BUFFER, callbackId,
                                                           releaseFence,
                                                           currentMaxAcquiredBufferCount);
    }

    void onTransactionQueueStalled(const String8& reason) override {
        callRemoteAsync<
                decltype(&ITransactionCompletedListener::
                                 onTransactionQueueStalled)>(Tag::ON_TRANSACTION_QUEUE_STALLED,
                                                             reason);
    }
};

// Out-of-line virtual method definitions to trigger vtable emission in this translation unit (see
// clang warning -Wweak-vtables)
BpTransactionCompletedListener::~BpTransactionCompletedListener() = default;

IMPLEMENT_META_INTERFACE(TransactionCompletedListener, "android.gui.ITransactionComposerListener");

status_t BnTransactionCompletedListener::onTransact(uint32_t code, const Parcel& data,
                                                    Parcel* reply, uint32_t flags) {
    if (code < IBinder::FIRST_CALL_TRANSACTION || code > static_cast<uint32_t>(Tag::LAST)) {
        return BBinder::onTransact(code, data, reply, flags);
    }
    auto tag = static_cast<Tag>(code);
    switch (tag) {
        case Tag::ON_TRANSACTION_COMPLETED:
            return callLocalAsync(data, reply,
                                  &ITransactionCompletedListener::onTransactionCompleted);
        case Tag::ON_RELEASE_BUFFER:
            return callLocalAsync(data, reply, &ITransactionCompletedListener::onReleaseBuffer);
        case Tag::ON_TRANSACTION_QUEUE_STALLED:
            return callLocalAsync(data, reply,
                                  &ITransactionCompletedListener::onTransactionQueueStalled);
    }
}

ListenerCallbacks ListenerCallbacks::filter(CallbackId::Type type) const {
ListenerCallbacks ListenerCallbacks::filter(CallbackId::Type type) const {
    std::vector<CallbackId> filteredCallbackIds;
    std::vector<CallbackId> filteredCallbackIds;
    for (const auto& callbackId : callbackIds) {
    for (const auto& callbackId : callbackIds) {
@@ -366,4 +301,4 @@ status_t ReleaseCallbackId::readFromParcel(const Parcel* input) {


const ReleaseCallbackId ReleaseCallbackId::INVALID_ID = ReleaseCallbackId(0, 0);
const ReleaseCallbackId ReleaseCallbackId::INVALID_ID = ReleaseCallbackId(0, 0);


}; // namespace android
}; // namespace android::gui
+1 −0
Original line number Original line Diff line number Diff line
@@ -51,6 +51,7 @@


namespace android {
namespace android {


using gui::CallbackId;
using gui::FocusRequest;
using gui::FocusRequest;
using gui::WindowInfoHandle;
using gui::WindowInfoHandle;


+24 −9
Original line number Original line Diff line number Diff line
@@ -314,7 +314,8 @@ void TransactionCompletedListener::addSurfaceControlToCallbacks(
    }
    }
}
}


void TransactionCompletedListener::onTransactionCompleted(ListenerStats listenerStats) {
binder::Status TransactionCompletedListener::onTransactionCompleted(
        const ListenerStats& listenerStats) {
    std::unordered_map<CallbackId, CallbackTranslation, CallbackIdHash> callbacksMap;
    std::unordered_map<CallbackId, CallbackTranslation, CallbackIdHash> callbacksMap;
    std::multimap<int32_t, sp<JankDataListener>> jankListenersMap;
    std::multimap<int32_t, sp<JankDataListener>> jankListenersMap;
    {
    {
@@ -454,9 +455,10 @@ void TransactionCompletedListener::onTransactionCompleted(ListenerStats listener
            }
            }
        }
        }
    }
    }
    return binder::Status::ok();
}
}


void TransactionCompletedListener::onTransactionQueueStalled(const String8& reason) {
binder::Status TransactionCompletedListener::onTransactionQueueStalled(const std::string& reason) {
    std::unordered_map<void*, std::function<void(const std::string&)>> callbackCopy;
    std::unordered_map<void*, std::function<void(const std::string&)>> callbackCopy;
    {
    {
        std::scoped_lock<std::mutex> lock(mMutex);
        std::scoped_lock<std::mutex> lock(mMutex);
@@ -465,6 +467,7 @@ void TransactionCompletedListener::onTransactionQueueStalled(const String8& reas
    for (auto const& it : callbackCopy) {
    for (auto const& it : callbackCopy) {
        it.second(reason.c_str());
        it.second(reason.c_str());
    }
    }
    return binder::Status::ok();
}
}


void TransactionCompletedListener::addQueueStallListener(
void TransactionCompletedListener::addQueueStallListener(
@@ -478,9 +481,12 @@ void TransactionCompletedListener::removeQueueStallListener(void* id) {
    mQueueStallListeners.erase(id);
    mQueueStallListeners.erase(id);
}
}


void TransactionCompletedListener::onReleaseBuffer(ReleaseCallbackId callbackId,
binder::Status TransactionCompletedListener::onReleaseBuffer(
                                                   sp<Fence> releaseFence,
        const ReleaseCallbackId& callbackId,
                                                   uint32_t currentMaxAcquiredBufferCount) {
        const std::optional<os::ParcelFileDescriptor>& releaseFenceFd,
        int32_t currentMaxAcquiredBufferCount) {
    sp<Fence> releaseFence(releaseFenceFd ? new Fence(::dup(releaseFenceFd->get()))
                                          : Fence::NO_FENCE);
    ReleaseBufferCallback callback;
    ReleaseBufferCallback callback;
    {
    {
        std::scoped_lock<std::mutex> lock(mMutex);
        std::scoped_lock<std::mutex> lock(mMutex);
@@ -489,13 +495,14 @@ void TransactionCompletedListener::onReleaseBuffer(ReleaseCallbackId callbackId,
    if (!callback) {
    if (!callback) {
        ALOGE("Could not call release buffer callback, buffer not found %s",
        ALOGE("Could not call release buffer callback, buffer not found %s",
              callbackId.to_string().c_str());
              callbackId.to_string().c_str());
        return;
        return binder::Status::fromExceptionCode(binder::Status::EX_ILLEGAL_ARGUMENT);
    }
    }
    std::optional<uint32_t> optionalMaxAcquiredBufferCount =
    std::optional<uint32_t> optionalMaxAcquiredBufferCount =
            currentMaxAcquiredBufferCount == UINT_MAX
            static_cast<uint32_t>(currentMaxAcquiredBufferCount) == UINT_MAX
            ? std::nullopt
            ? std::nullopt
            : std::make_optional<uint32_t>(currentMaxAcquiredBufferCount);
            : std::make_optional<uint32_t>(currentMaxAcquiredBufferCount);
    callback(callbackId, releaseFence, optionalMaxAcquiredBufferCount);
    callback(callbackId, releaseFence, optionalMaxAcquiredBufferCount);
    return binder::Status::ok();
}
}


ReleaseBufferCallback TransactionCompletedListener::popReleaseBufferCallbackLocked(
ReleaseBufferCallback TransactionCompletedListener::popReleaseBufferCallbackLocked(
@@ -825,7 +832,11 @@ void SurfaceComposerClient::Transaction::releaseBufferIfOverwriting(const layer_
                ->mReleaseCallbackThread
                ->mReleaseCallbackThread
                .addReleaseCallback(state.bufferData->generateReleaseCallbackId(), fence);
                .addReleaseCallback(state.bufferData->generateReleaseCallbackId(), fence);
    } else {
    } else {
        listener->onReleaseBuffer(state.bufferData->generateReleaseCallbackId(), fence, UINT_MAX);
        std::optional<os::ParcelFileDescriptor> fenceFd;
        if (fence != Fence::NO_FENCE) {
            fenceFd = os::ParcelFileDescriptor(base::unique_fd(::dup(fence->get())));
        }
        listener->onReleaseBuffer(state.bufferData->generateReleaseCallbackId(), fenceFd, UINT_MAX);
    }
    }
}
}


@@ -2846,7 +2857,11 @@ void ReleaseCallbackThread::threadMain() {


        while (!callbackInfos.empty()) {
        while (!callbackInfos.empty()) {
            auto [callbackId, releaseFence] = callbackInfos.front();
            auto [callbackId, releaseFence] = callbackInfos.front();
            listener->onReleaseBuffer(callbackId, std::move(releaseFence), UINT_MAX);
            std::optional<os::ParcelFileDescriptor> fenceFd;
            if (releaseFence != Fence::NO_FENCE) {
                fenceFd = os::ParcelFileDescriptor(base::unique_fd(::dup(releaseFence->get())));
            }
            listener->onReleaseBuffer(callbackId, fenceFd, UINT_MAX);
            callbackInfos.pop();
            callbackInfos.pop();
        }
        }


Loading