126126#include < gui/SchedulingPolicy.h>
127127#include < gui/SyncScreenCaptureListener.h>
128128#include < ui/DisplayIdentification.h>
129- #include " ActivePictureUpdater.h"
130129#include " BackgroundExecutor.h"
131130#include " Client.h"
132131#include " ClientCache.h"
@@ -2952,7 +2951,7 @@ CompositeResultsPerDisplay SurfaceFlinger::composite(
29522951 layer->setWasClientComposed (compositionResult.lastClientCompositionFence );
29532952 }
29542953 if (com_android_graphics_libgui_flags_apply_picture_profiles ()) {
2955- mActivePictureUpdater .onLayerComposed (*layer, *layerFE, compositionResult);
2954+ mActivePictureTracker .onLayerComposed (*layer, *layerFE, compositionResult);
29562955 }
29572956 }
29582957
@@ -3264,8 +3263,8 @@ void SurfaceFlinger::onCompositionPresented(PhysicalDisplayId pacesetterId,
32643263 std::vector<std::pair<std::shared_ptr<compositionengine::Display>, sp<HdrLayerInfoReporter>>>
32653264 hdrInfoListeners;
32663265 bool haveNewHdrInfoListeners = false ;
3267- sp<gui::IActivePictureListener> activePictureListener ;
3268- bool haveNewActivePictureListener = false ;
3266+ ActivePictureTracker::Listeners activePictureListenersToAdd ;
3267+ ActivePictureTracker::Listeners activePictureListenersToRemove ;
32693268 {
32703269 Mutex::Autolock lock (mStateLock );
32713270 if (mFpsReporter ) {
@@ -3287,9 +3286,8 @@ void SurfaceFlinger::onCompositionPresented(PhysicalDisplayId pacesetterId,
32873286 haveNewHdrInfoListeners = mAddingHDRLayerInfoListener ; // grab this with state lock
32883287 mAddingHDRLayerInfoListener = false ;
32893288
3290- activePictureListener = mActivePictureListener ;
3291- haveNewActivePictureListener = mHaveNewActivePictureListener ;
3292- mHaveNewActivePictureListener = false ;
3289+ std::swap (activePictureListenersToAdd, mActivePictureListenersToAdd );
3290+ std::swap (activePictureListenersToRemove, mActivePictureListenersToRemove );
32933291 }
32943292
32953293 if (haveNewHdrInfoListeners || mHdrLayerInfoChanged ) {
@@ -3353,14 +3351,10 @@ void SurfaceFlinger::onCompositionPresented(PhysicalDisplayId pacesetterId,
33533351 mHdrLayerInfoChanged = false ;
33543352
33553353 if (com_android_graphics_libgui_flags_apply_picture_profiles ()) {
3356- // Track, update and notify changes to active pictures - layers that are undergoing picture
3357- // processing
3358- if (mActivePictureUpdater .updateAndHasChanged () || haveNewActivePictureListener) {
3359- if (activePictureListener) {
3360- activePictureListener->onActivePicturesChanged (
3361- mActivePictureUpdater .getActivePictures ());
3362- }
3363- }
3354+ // Track, update and notify changes to active pictures - layers that are undergoing
3355+ // picture processing
3356+ mActivePictureTracker .updateAndNotifyListeners (activePictureListenersToAdd,
3357+ activePictureListenersToRemove);
33643358 }
33653359
33663360 mTransactionCallbackInvoker .sendCallbacks (false /* onCommitOnly */ );
@@ -8226,12 +8220,20 @@ void SurfaceFlinger::updateHdcpLevels(hal::HWDisplayId hwcDisplayId, int32_t con
82268220 }));
82278221}
82288222
8229- void SurfaceFlinger::setActivePictureListener (const sp<gui::IActivePictureListener>& listener) {
8230- if (com_android_graphics_libgui_flags_apply_picture_profiles ()) {
8231- Mutex::Autolock lock (mStateLock );
8232- mActivePictureListener = listener;
8233- mHaveNewActivePictureListener = listener != nullptr ;
8234- }
8223+ void SurfaceFlinger::addActivePictureListener (const sp<gui::IActivePictureListener>& listener) {
8224+ Mutex::Autolock lock (mStateLock );
8225+ std::erase_if (mActivePictureListenersToRemove , [listener](const auto & otherListener) {
8226+ return IInterface::asBinder (listener) == IInterface::asBinder (otherListener);
8227+ });
8228+ mActivePictureListenersToAdd .push_back (listener);
8229+ }
8230+
8231+ void SurfaceFlinger::removeActivePictureListener (const sp<gui::IActivePictureListener>& listener) {
8232+ Mutex::Autolock lock (mStateLock );
8233+ std::erase_if (mActivePictureListenersToAdd , [listener](const auto & otherListener) {
8234+ return IInterface::asBinder (listener) == IInterface::asBinder (otherListener);
8235+ });
8236+ mActivePictureListenersToRemove .push_back (listener);
82358237}
82368238
82378239std::shared_ptr<renderengine::ExternalTexture> SurfaceFlinger::getExternalTextureFromBufferData (
@@ -9184,11 +9186,20 @@ binder::Status SurfaceComposerAIDL::removeHdrLayerInfoListener(
91849186 return binderStatusFromStatusT (status);
91859187}
91869188
9187- binder::Status SurfaceComposerAIDL::setActivePictureListener (
9189+ binder::Status SurfaceComposerAIDL::addActivePictureListener (
9190+ const sp<gui::IActivePictureListener>& listener) {
9191+ status_t status = checkObservePictureProfilesPermission ();
9192+ if (status == OK) {
9193+ mFlinger ->addActivePictureListener (listener);
9194+ }
9195+ return binderStatusFromStatusT (status);
9196+ }
9197+
9198+ binder::Status SurfaceComposerAIDL::removeActivePictureListener (
91889199 const sp<gui::IActivePictureListener>& listener) {
91899200 status_t status = checkObservePictureProfilesPermission ();
91909201 if (status == OK) {
9191- mFlinger ->setActivePictureListener (listener);
9202+ mFlinger ->removeActivePictureListener (listener);
91929203 }
91939204 return binderStatusFromStatusT (status);
91949205}
0 commit comments