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

Commit 19031123 authored by Brian Lindahl's avatar Brian Lindahl Committed by Android (Google) Code Review
Browse files

Merge changes from topic "multiple-picture-listeners" into main

* changes:
  Add additional ActivePictureTracker test coverage and rename tests
  Support multiple active picture listeners
  Rename of ActivePictureUpdater to ActivePictureTracker
parents b95944cc bb67bf78
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();
    }

+45 −5
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
 * limitations under the License.
 */

#include "ActivePictureUpdater.h"
#include "ActivePictureTracker.h"

#include <algorithm>

@@ -23,7 +23,10 @@

namespace android {

void ActivePictureUpdater::onLayerComposed(const Layer& layer, const LayerFE& layerFE,
using gui::ActivePicture;
using gui::IActivePictureListener;

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

bool ActivePictureUpdater::updateAndHasChanged() {
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 ActivePictureUpdater::updateAndHasChanged() {
    return hasChanged;
}

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

Loading