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

Commit f1cfbf64 authored by Brian Lindahl's avatar Brian Lindahl
Browse files

Support multiple active picture listeners

Bug: 337330263
Test: atest SurfaceControlPictureProfileTest
Test: atest ActivePictureTrackerTest
Flag: com.android.graphics.libgui.flags.apply_picture_profiles
Change-Id: If030b3f6177b6bd641ed7953b10a37319c9e537a
parent e8334907
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -3293,10 +3293,17 @@ status_t SurfaceComposerClient::removeHdrLayerInfoListener(
    return statusTFromBinderStatus(status);
}

status_t SurfaceComposerClient::setActivePictureListener(
status_t SurfaceComposerClient::addActivePictureListener(
        const sp<gui::IActivePictureListener>& listener) {
    binder::Status status =
            ComposerServiceAIDL::getComposerService()->setActivePictureListener(listener);
            ComposerServiceAIDL::getComposerService()->addActivePictureListener(listener);
    return statusTFromBinderStatus(status);
}

status_t SurfaceComposerClient::removeActivePictureListener(
        const sp<gui::IActivePictureListener>& listener) {
    binder::Status status =
            ComposerServiceAIDL::getComposerService()->removeActivePictureListener(listener);
    return statusTFromBinderStatus(status);
}

+8 −2
Original line number Diff line number Diff line
@@ -607,8 +607,14 @@ interface ISurfaceComposer {
    oneway void removeJankListener(int layerId, IJankListener listener, long afterVsync);

    /**
     * Sets the listener used to monitor visible content that is being processed with picture
     * Adds a listener used to monitor visible content that is being processed with picture
     * profiles.
     */
    oneway void setActivePictureListener(IActivePictureListener listener);
    oneway void addActivePictureListener(IActivePictureListener listener);

    /**
     * Removes a listener used to monitor visible content that is being processed with picture
     * profiles.
     */
    oneway void removeActivePictureListener(IActivePictureListener listener);
}
+3 −1
Original line number Diff line number Diff line
@@ -298,7 +298,9 @@ public:
    static status_t removeHdrLayerInfoListener(const sp<IBinder>& displayToken,
                                               const sp<gui::IHdrLayerInfoListener>& listener);

    static status_t setActivePictureListener(const sp<gui::IActivePictureListener>& listener);
    static status_t addActivePictureListener(const sp<gui::IActivePictureListener>& listener);

    static status_t removeActivePictureListener(const sp<gui::IActivePictureListener>& listener);

    /*
     * Sends a power boost to the composer. This function is asynchronous.
+5 −1
Original line number Diff line number Diff line
@@ -1016,7 +1016,11 @@ public:
        return binder::Status::ok();
    }

    binder::Status setActivePictureListener(const sp<gui::IActivePictureListener>&) {
    binder::Status addActivePictureListener(const sp<gui::IActivePictureListener>&) {
        return binder::Status::ok();
    }

    binder::Status removeActivePictureListener(const sp<gui::IActivePictureListener>&) {
        return binder::Status::ok();
    }

+42 −2
Original line number Diff line number Diff line
@@ -23,6 +23,9 @@

namespace android {

using gui::ActivePicture;
using gui::IActivePictureListener;

void ActivePictureTracker::onLayerComposed(const Layer& layer, const LayerFE& layerFE,
                                           const CompositionResult& result) {
    if (result.wasPictureProfileCommitted) {
@@ -39,10 +42,47 @@ void ActivePictureTracker::onLayerComposed(const Layer& layer, const LayerFE& la
    }
}

void ActivePictureTracker::updateAndNotifyListeners(const Listeners& listenersToAdd,
                                                    const Listeners& listenersToRemove) {
    Listeners newListeners = updateListeners(listenersToAdd, listenersToRemove);
    if (updateAndHasChanged()) {
        for (auto listener : mListeners) {
            listener->onActivePicturesChanged(getActivePictures());
        }
    } else {
        for (auto listener : newListeners) {
            listener->onActivePicturesChanged(getActivePictures());
        }
    }
}

ActivePictureTracker::Listeners ActivePictureTracker::updateListeners(
        const Listeners& listenersToAdd, const Listeners& listenersToRemove) {
    Listeners newListeners;
    for (auto listener : listenersToRemove) {
        std::erase_if(mListeners, [listener](const sp<IActivePictureListener>& otherListener) {
            return IInterface::asBinder(listener) == IInterface::asBinder(otherListener);
        });
    }
    for (auto listener : listenersToAdd) {
        if (std::find_if(mListeners.begin(), mListeners.end(),
                         [listener](const sp<IActivePictureListener>& otherListener) {
                             return IInterface::asBinder(listener) ==
                                     IInterface::asBinder(otherListener);
                         }) == mListeners.end()) {
            newListeners.push_back(listener);
        }
    }
    for (auto listener : newListeners) {
        mListeners.push_back(listener);
    }
    return newListeners;
}

bool ActivePictureTracker::updateAndHasChanged() {
    bool hasChanged = true;
    if (mNewActivePictures.size() == mOldActivePictures.size()) {
        auto compare = [](const gui::ActivePicture& lhs, const gui::ActivePicture& rhs) -> int {
        auto compare = [](const ActivePicture& lhs, const ActivePicture& rhs) -> int {
            if (lhs.layerId == rhs.layerId) {
                return lhs.pictureProfileId < rhs.pictureProfileId;
            }
@@ -59,7 +99,7 @@ bool ActivePictureTracker::updateAndHasChanged() {
    return hasChanged;
}

const std::vector<gui::ActivePicture>& ActivePictureTracker::getActivePictures() const {
const std::vector<ActivePicture>& ActivePictureTracker::getActivePictures() const {
    return mOldActivePictures;
}

Loading