Skip to content

Commit f5fdff8

Browse files
committed
Notify listeners about active picture profiles
Bug: 337330263 Test: atest ActivePictureUpdaterTest Test: atest SurfaceControlPictureProfileTest Flag: com.android.graphics.libgui.flags.apply_picture_profiles Change-Id: If08b79faf3d3c4c07248ecd7385a75cfe5357726
1 parent c6102c0 commit f5fdff8

21 files changed

Lines changed: 670 additions & 22 deletions

libs/gui/SurfaceComposerClient.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3280,6 +3280,13 @@ status_t SurfaceComposerClient::removeHdrLayerInfoListener(
32803280
return statusTFromBinderStatus(status);
32813281
}
32823282

3283+
status_t SurfaceComposerClient::setActivePictureListener(
3284+
const sp<gui::IActivePictureListener>& listener) {
3285+
binder::Status status =
3286+
ComposerServiceAIDL::getComposerService()->setActivePictureListener(listener);
3287+
return statusTFromBinderStatus(status);
3288+
}
3289+
32833290
status_t SurfaceComposerClient::notifyPowerBoost(int32_t boostId) {
32843291
binder::Status status = ComposerServiceAIDL::getComposerService()->notifyPowerBoost(boostId);
32853292
return statusTFromBinderStatus(status);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2024 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package android.gui;
18+
19+
/**
20+
* Visible content that is using picture processing.
21+
* @hide
22+
*/
23+
parcelable ActivePicture {
24+
/** The layer ID that is using picture processing. */
25+
int layerId;
26+
27+
/** UID that owns layer using picture processing. */
28+
int ownerUid;
29+
30+
/** ID of the picture profile that was used to configure the picture processing. */
31+
long pictureProfileId;
32+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2024 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package android.gui;
18+
19+
import android.gui.ActivePicture;
20+
21+
/**
22+
* Receive callbacks whenever the visible content using picture profiles changes.
23+
* @hide
24+
*/
25+
interface IActivePictureListener {
26+
/**
27+
* Callback reporting the visible content on the screen using picture profiles.
28+
*/
29+
oneway void onActivePicturesChanged(in ActivePicture[] activePictures);
30+
}

libs/gui/aidl/android/gui/ISurfaceComposer.aidl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import android.gui.FrameEvent;
3333
import android.gui.FrameStats;
3434
import android.gui.HdrConversionCapability;
3535
import android.gui.HdrConversionStrategy;
36+
import android.gui.IActivePictureListener;
3637
import android.gui.IDisplayEventConnection;
3738
import android.gui.IFpsListener;
3839
import android.gui.IHdrLayerInfoListener;
@@ -599,4 +600,10 @@ interface ISurfaceComposer {
599600
* past the provided VSync.
600601
*/
601602
oneway void removeJankListener(int layerId, IJankListener listener, long afterVsync);
603+
604+
/**
605+
* Sets the listener used to monitor visible content that is being processed with picture
606+
* profiles.
607+
*/
608+
oneway void setActivePictureListener(IActivePictureListener listener);
602609
}

libs/gui/include/gui/SurfaceComposerClient.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,8 @@ class SurfaceComposerClient : public RefBase
298298
static status_t removeHdrLayerInfoListener(const sp<IBinder>& displayToken,
299299
const sp<gui::IHdrLayerInfoListener>& listener);
300300

301+
static status_t setActivePictureListener(const sp<gui::IActivePictureListener>& listener);
302+
301303
/*
302304
* Sends a power boost to the composer. This function is asynchronous.
303305
*

libs/gui/tests/Surface_test.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <gtest/gtest.h>
2222

2323
#include <SurfaceFlingerProperties.h>
24+
#include <android/gui/IActivePictureListener.h>
2425
#include <android/gui/IDisplayEventConnection.h>
2526
#include <android/gui/ISurfaceComposer.h>
2627
#include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h>
@@ -1015,6 +1016,10 @@ class FakeSurfaceComposerAIDL : public gui::ISurfaceComposer {
10151016
return binder::Status::ok();
10161017
}
10171018

1019+
binder::Status setActivePictureListener(const sp<gui::IActivePictureListener>&) {
1020+
return binder::Status::ok();
1021+
}
1022+
10181023
protected:
10191024
IBinder* onAsBinder() override { return nullptr; }
10201025

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright 2024 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "ActivePictureUpdater.h"
18+
19+
#include <algorithm>
20+
21+
#include "Layer.h"
22+
#include "LayerFE.h"
23+
24+
namespace android {
25+
26+
void ActivePictureUpdater::onLayerComposed(const Layer& layer, const LayerFE& layerFE,
27+
const CompositionResult& result) {
28+
if (result.wasPictureProfileCommitted) {
29+
gui::ActivePicture picture;
30+
picture.layerId = int32_t(layer.sequence);
31+
picture.ownerUid = int32_t(layer.getOwnerUid());
32+
// TODO(b/337330263): Why does LayerFE coming from SF have a null composition state?
33+
if (layerFE.getCompositionState()) {
34+
picture.pictureProfileId = layerFE.getCompositionState()->pictureProfileHandle.getId();
35+
} else {
36+
picture.pictureProfileId = result.pictureProfileHandle.getId();
37+
}
38+
mNewActivePictures.push_back(picture);
39+
}
40+
}
41+
42+
bool ActivePictureUpdater::updateAndHasChanged() {
43+
bool hasChanged = true;
44+
if (mNewActivePictures.size() == mOldActivePictures.size()) {
45+
auto compare = [](const gui::ActivePicture& lhs, const gui::ActivePicture& rhs) -> int {
46+
if (lhs.layerId == rhs.layerId) {
47+
return lhs.pictureProfileId < rhs.pictureProfileId;
48+
}
49+
return lhs.layerId < rhs.layerId;
50+
};
51+
std::sort(mNewActivePictures.begin(), mNewActivePictures.end(), compare);
52+
if (std::equal(mNewActivePictures.begin(), mNewActivePictures.end(),
53+
mOldActivePictures.begin())) {
54+
hasChanged = false;
55+
}
56+
}
57+
std::swap(mOldActivePictures, mNewActivePictures);
58+
mNewActivePictures.resize(0);
59+
return hasChanged;
60+
}
61+
62+
const std::vector<gui::ActivePicture>& ActivePictureUpdater::getActivePictures() const {
63+
return mOldActivePictures;
64+
}
65+
66+
} // namespace android
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2024 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#pragma once
18+
19+
#include <vector>
20+
21+
#include <android/gui/ActivePicture.h>
22+
23+
namespace android {
24+
25+
class Layer;
26+
class LayerFE;
27+
struct CompositionResult;
28+
29+
// Keeps track of active pictures - layers that are undergoing picture processing.
30+
class ActivePictureUpdater {
31+
public:
32+
// Called for each visible layer when SurfaceFlinger finishes composing.
33+
void onLayerComposed(const Layer& layer, const LayerFE& layerFE,
34+
const CompositionResult& result);
35+
36+
// Update internals and return whether the set of active pictures have changed.
37+
bool updateAndHasChanged();
38+
39+
// The current set of active pictures.
40+
const std::vector<gui::ActivePicture>& getActivePictures() const;
41+
42+
private:
43+
std::vector<gui::ActivePicture> mOldActivePictures;
44+
std::vector<gui::ActivePicture> mNewActivePictures;
45+
};
46+
47+
} // namespace android

services/surfaceflinger/Android.bp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ filegroup {
199199
name: "libsurfaceflinger_sources",
200200
srcs: [
201201
":libsurfaceflinger_backend_sources",
202+
"ActivePictureUpdater.cpp",
202203
"BackgroundExecutor.cpp",
203204
"Client.cpp",
204205
"ClientCache.cpp",

services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFE.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ class LayerFE : public virtual RefBase {
161161
// Checks if the buffer's release fence has been set
162162
virtual LayerFE::ReleaseFencePromiseStatus getReleaseFencePromiseStatus() = 0;
163163

164+
// Indicates that the picture profile request was applied to this layer.
165+
virtual void onPictureProfileCommitted() = 0;
166+
164167
// Gets some kind of identifier for the layer for debug purposes.
165168
virtual const char* getDebugName() const = 0;
166169

0 commit comments

Comments
 (0)