Skip to content

Commit 07dcd49

Browse files
committed
Allow apps to apply picture profiles with priority to layers
Bug: 337330263 Test: build Test: atest LayerSnapshotTest Flag: com.android.graphics.libgui.flags.apply_picture_profiles Change-Id: I1adb6069d0168084abf0a76d310abb4ffad5ce5f
1 parent 1a4ffd8 commit 07dcd49

8 files changed

Lines changed: 144 additions & 7 deletions

File tree

libs/gui/LayerState.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <android/gui/ISurfaceComposerClient.h>
2222
#include <android/native_window.h>
2323
#include <binder/Parcel.h>
24+
#include <com_android_graphics_libgui_flags.h>
2425
#include <gui/FrameRateUtils.h>
2526
#include <gui/IGraphicBufferProducer.h>
2627
#include <gui/LayerState.h>
@@ -91,7 +92,9 @@ layer_state_t::layer_state_t()
9192
trustedOverlay(gui::TrustedOverlay::UNSET),
9293
bufferCrop(Rect::INVALID_RECT),
9394
destinationFrame(Rect::INVALID_RECT),
94-
dropInputMode(gui::DropInputMode::NONE) {
95+
dropInputMode(gui::DropInputMode::NONE),
96+
pictureProfileHandle(PictureProfileHandle::NONE),
97+
appContentPriority(0) {
9598
matrix.dsdx = matrix.dtdy = 1.0f;
9699
matrix.dsdy = matrix.dtdx = 0.0f;
97100
hdrMetadata.validTypes = 0;
@@ -202,6 +205,10 @@ status_t layer_state_t::write(Parcel& output) const
202205
if (hasBufferReleaseChannel) {
203206
SAFE_PARCEL(output.writeParcelable, *bufferReleaseChannel);
204207
}
208+
#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS_APPLY_PICTURE_PROFILES
209+
SAFE_PARCEL(output.writeInt64, pictureProfileHandle.getId());
210+
SAFE_PARCEL(output.writeInt32, appContentPriority);
211+
#endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS_APPLY_PICTURE_PROFILES
205212

206213
return NO_ERROR;
207214
}
@@ -357,6 +364,12 @@ status_t layer_state_t::read(const Parcel& input)
357364
bufferReleaseChannel = std::make_shared<gui::BufferReleaseChannel::ProducerEndpoint>();
358365
SAFE_PARCEL(input.readParcelable, bufferReleaseChannel.get());
359366
}
367+
#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS_APPLY_PICTURE_PROFILES
368+
int64_t pictureProfileId;
369+
SAFE_PARCEL(input.readInt64, &pictureProfileId);
370+
pictureProfileHandle = PictureProfileHandle(pictureProfileId);
371+
SAFE_PARCEL(input.readInt32, &appContentPriority);
372+
#endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS_APPLY_PICTURE_PROFILES
360373

361374
return NO_ERROR;
362375
}
@@ -745,6 +758,16 @@ void layer_state_t::merge(const layer_state_t& other) {
745758
what |= eBufferReleaseChannelChanged;
746759
bufferReleaseChannel = other.bufferReleaseChannel;
747760
}
761+
if (com_android_graphics_libgui_flags_apply_picture_profiles()) {
762+
if (other.what & ePictureProfileHandleChanged) {
763+
what |= ePictureProfileHandleChanged;
764+
pictureProfileHandle = other.pictureProfileHandle;
765+
}
766+
if (other.what & eAppContentPriorityChanged) {
767+
what |= eAppContentPriorityChanged;
768+
appContentPriority = other.appContentPriority;
769+
}
770+
}
748771
if ((other.what & what) != other.what) {
749772
ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
750773
"other.what=0x%" PRIX64 " what=0x%" PRIX64 " unmerged flags=0x%" PRIX64,
@@ -826,6 +849,8 @@ uint64_t layer_state_t::diff(const layer_state_t& other) const {
826849
CHECK_DIFF(diff, eDimmingEnabledChanged, other, dimmingEnabled);
827850
if (other.what & eBufferReleaseChannelChanged) diff |= eBufferReleaseChannelChanged;
828851
if (other.what & eLutsChanged) diff |= eLutsChanged;
852+
CHECK_DIFF(diff, ePictureProfileHandleChanged, other, pictureProfileHandle);
853+
CHECK_DIFF(diff, eAppContentPriorityChanged, other, appContentPriority);
829854

830855
return diff;
831856
}

libs/gui/SurfaceComposerClient.cpp

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@
2020
#include <stdint.h>
2121
#include <sys/types.h>
2222

23-
#include <com_android_graphics_libgui_flags.h>
24-
2523
#include <android/gui/BnWindowInfosReportedListener.h>
2624
#include <android/gui/DisplayState.h>
2725
#include <android/gui/EdgeExtensionParameters.h>
2826
#include <android/gui/ISurfaceComposerClient.h>
2927
#include <android/gui/IWindowInfosListener.h>
3028
#include <android/gui/TrustedPresentationThresholds.h>
3129
#include <android/os/IInputConstants.h>
30+
#include <com_android_graphics_libgui_flags.h>
3231
#include <gui/DisplayLuts.h>
3332
#include <gui/FrameRateUtils.h>
3433
#include <gui/TraceUtils.h>
@@ -2447,6 +2446,40 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setBuffe
24472446
return *this;
24482447
}
24492448

2449+
SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setPictureProfileHandle(
2450+
const sp<SurfaceControl>& sc, const PictureProfileHandle& pictureProfileHandle) {
2451+
if (com_android_graphics_libgui_flags_apply_picture_profiles()) {
2452+
layer_state_t* s = getLayerState(sc);
2453+
if (!s) {
2454+
mStatus = BAD_INDEX;
2455+
return *this;
2456+
}
2457+
2458+
s->what |= layer_state_t::ePictureProfileHandleChanged;
2459+
s->pictureProfileHandle = pictureProfileHandle;
2460+
2461+
registerSurfaceControlForCallback(sc);
2462+
}
2463+
return *this;
2464+
}
2465+
2466+
SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setContentPriority(
2467+
const sp<SurfaceControl>& sc, int32_t priority) {
2468+
if (com_android_graphics_libgui_flags_apply_picture_profiles()) {
2469+
layer_state_t* s = getLayerState(sc);
2470+
if (!s) {
2471+
mStatus = BAD_INDEX;
2472+
return *this;
2473+
}
2474+
2475+
s->what |= layer_state_t::eAppContentPriorityChanged;
2476+
s->appContentPriority = priority;
2477+
2478+
registerSurfaceControlForCallback(sc);
2479+
}
2480+
return *this;
2481+
}
2482+
24502483
// ---------------------------------------------------------------------------
24512484

24522485
DisplayState& SurfaceComposerClient::Transaction::getDisplayState(const sp<IBinder>& token) {

libs/gui/include/gui/LayerState.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include <ui/BlurRegion.h>
4848
#include <ui/GraphicTypes.h>
4949
#include <ui/LayerStack.h>
50+
#include <ui/PictureProfileHandle.h>
5051
#include <ui/Rect.h>
5152
#include <ui/Region.h>
5253
#include <ui/Rotation.h>
@@ -224,6 +225,8 @@ struct layer_state_t {
224225
eExtendedRangeBrightnessChanged = 0x10000'00000000,
225226
eEdgeExtensionChanged = 0x20000'00000000,
226227
eBufferReleaseChannelChanged = 0x40000'00000000,
228+
ePictureProfileHandleChanged = 0x80000'00000000,
229+
eAppContentPriorityChanged = 0x100000'00000000,
227230
};
228231

229232
layer_state_t();
@@ -267,7 +270,8 @@ struct layer_state_t {
267270
layer_state_t::eColorSpaceAgnosticChanged | layer_state_t::eColorTransformChanged |
268271
layer_state_t::eCornerRadiusChanged | layer_state_t::eDimmingEnabledChanged |
269272
layer_state_t::eHdrMetadataChanged | layer_state_t::eShadowRadiusChanged |
270-
layer_state_t::eStretchChanged;
273+
layer_state_t::eStretchChanged | layer_state_t::ePictureProfileHandleChanged |
274+
layer_state_t::eAppContentPriorityChanged;
271275

272276
// Changes which invalidates the layer's visible region in CE.
273277
static constexpr uint64_t CONTENT_DIRTY = layer_state_t::CONTENT_CHANGES |
@@ -412,6 +416,15 @@ struct layer_state_t {
412416
float currentHdrSdrRatio = 1.f;
413417
float desiredHdrSdrRatio = 1.f;
414418

419+
// Enhance the quality of the buffer contents by configurating a picture processing pipeline
420+
// with values as specified by this picture profile.
421+
PictureProfileHandle pictureProfileHandle{PictureProfileHandle::NONE};
422+
423+
// A value indicating the significance of the layer's content to the app's desired user
424+
// experience. A lower priority will result in more likelihood of getting access to limited
425+
// resources, such as picture processing hardware.
426+
int32_t appContentPriority = 0;
427+
415428
gui::CachingHint cachingHint = gui::CachingHint::Enabled;
416429

417430
TrustedPresentationThresholds trustedPresentationThresholds;

libs/gui/include/gui/SurfaceComposerClient.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <ui/EdgeExtensionEffect.h>
3939
#include <ui/FrameStats.h>
4040
#include <ui/GraphicTypes.h>
41+
#include <ui/PictureProfileHandle.h>
4142
#include <ui/PixelFormat.h>
4243
#include <ui/Rotation.h>
4344
#include <ui/StaticDisplayInfo.h>
@@ -775,6 +776,20 @@ class SurfaceComposerClient : public RefBase
775776
const sp<SurfaceControl>& sc,
776777
const std::shared_ptr<gui::BufferReleaseChannel::ProducerEndpoint>& channel);
777778

779+
/**
780+
* Configures a surface control to use picture processing hardware, configured as specified
781+
* by the picture profile, to enhance the quality of all subsequent buffer contents.
782+
*/
783+
Transaction& setPictureProfileHandle(const sp<SurfaceControl>& sc,
784+
const PictureProfileHandle& pictureProfileHandle);
785+
786+
/**
787+
* Configures the relative importance of the contents of the layer with respect to the app's
788+
* user experience. A lower priority value will give the layer preferred access to limited
789+
* resources, such as picture processing, over a layer with a higher priority value.
790+
*/
791+
Transaction& setContentPriority(const sp<SurfaceControl>& sc, int32_t contentPriority);
792+
778793
status_t setDisplaySurface(const sp<IBinder>& token,
779794
const sp<IGraphicBufferProducer>& bufferProducer);
780795

libs/ui/include/ui/PictureProfileHandle.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class PictureProfileHandle {
3939
static const PictureProfileHandle NONE;
4040

4141
PictureProfileHandle() { *this = NONE; }
42-
PictureProfileHandle(PictureProfileId id) : mId(id) {}
42+
explicit PictureProfileHandle(PictureProfileId id) : mId(id) {}
4343

4444
PictureProfileId const& getId() const { return mId; }
4545

services/surfaceflinger/FrontEnd/LayerSnapshot.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,13 @@ void LayerSnapshot::merge(const RequestedLayerState& requested, bool forceUpdate
413413
if (forceUpdate || requested.what & layer_state_t::eCropChanged) {
414414
geomCrop = requested.crop;
415415
}
416+
if (forceUpdate || requested.what & layer_state_t::ePictureProfileHandleChanged) {
417+
pictureProfileHandle = requested.pictureProfileHandle;
418+
}
419+
if (forceUpdate || requested.what & layer_state_t::eAppContentPriorityChanged) {
420+
// TODO(b/337330263): Also consider the system-determined priority of the app
421+
pictureProfilePriority = requested.appContentPriority;
422+
}
416423

417424
if (forceUpdate || requested.what & layer_state_t::eDefaultFrameRateCompatibilityChanged) {
418425
const auto compatibility =

services/surfaceflinger/SurfaceFlinger.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3558,7 +3558,9 @@ std::optional<DisplayModeId> SurfaceFlinger::processHotplugConnect(PhysicalDispl
35583558
}
35593559
state.isProtected = true;
35603560
state.displayName = std::move(info.name);
3561-
3561+
state.maxLayerPictureProfiles = getHwComposer().getMaxLayerPictureProfiles(displayId);
3562+
state.hasPictureProcessing =
3563+
getHwComposer().hasDisplayCapability(displayId, DisplayCapability::PICTURE_PROCESSING);
35623564
mCurrentState.displays.add(token, state);
35633565
ALOGI("Connecting %s", displayString);
35643566
return activeModeId;
@@ -3719,6 +3721,8 @@ void SurfaceFlinger::processDisplayAdded(const wp<IBinder>& displayToken,
37193721
builder.setPixels(resolution);
37203722
builder.setIsSecure(state.isSecure);
37213723
builder.setIsProtected(state.isProtected);
3724+
builder.setHasPictureProcessing(state.hasPictureProcessing);
3725+
builder.setMaxLayerPictureProfiles(state.maxLayerPictureProfiles);
37223726
builder.setPowerAdvisor(mPowerAdvisor.get());
37233727
builder.setName(state.displayName);
37243728
auto compositionDisplay = getCompositionEngine().createDisplay(builder.build());

services/surfaceflinger/tests/unittests/LayerSnapshotTest.cpp

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include "ui/GraphicTypes.h"
2929

3030
#include <com_android_graphics_libgui_flags.h>
31-
#include <com_android_graphics_surfaceflinger_flags.h>
3231

3332
#define UPDATE_AND_VERIFY(BUILDER, ...) \
3433
({ \
@@ -1985,4 +1984,45 @@ TEST_F(LayerSnapshotTest, contentDirtyWhenParentGeometryChanges) {
19851984
UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
19861985
EXPECT_FALSE(getSnapshot(1)->contentDirty);
19871986
}
1987+
TEST_F(LayerSnapshotTest, shouldUpdatePictureProfileHandle) {
1988+
if (!com_android_graphics_libgui_flags_apply_picture_profiles()) {
1989+
GTEST_SKIP() << "Flag disabled, skipping test";
1990+
}
1991+
std::vector<TransactionState> transactions;
1992+
transactions.emplace_back();
1993+
transactions.back().states.push_back({});
1994+
transactions.back().states.front().layerId = 1;
1995+
transactions.back().states.front().state.layerId = 1;
1996+
transactions.back().states.front().state.what = layer_state_t::ePictureProfileHandleChanged;
1997+
transactions.back().states.front().state.pictureProfileHandle = PictureProfileHandle(3);
1998+
1999+
mLifecycleManager.applyTransactions(transactions);
2000+
EXPECT_EQ(mLifecycleManager.getGlobalChanges(), RequestedLayerState::Changes::Content);
2001+
2002+
update(mSnapshotBuilder);
2003+
2004+
EXPECT_EQ(getSnapshot(1)->clientChanges, layer_state_t::ePictureProfileHandleChanged);
2005+
EXPECT_EQ(getSnapshot(1)->pictureProfileHandle, PictureProfileHandle(3));
2006+
}
2007+
2008+
TEST_F(LayerSnapshotTest, shouldUpdatePictureProfilePriorityFromAppContentPriority) {
2009+
if (!com_android_graphics_libgui_flags_apply_picture_profiles()) {
2010+
GTEST_SKIP() << "Flag disabled, skipping test";
2011+
}
2012+
std::vector<TransactionState> transactions;
2013+
transactions.emplace_back();
2014+
transactions.back().states.push_back({});
2015+
transactions.back().states.front().layerId = 1;
2016+
transactions.back().states.front().state.layerId = 1;
2017+
transactions.back().states.front().state.what = layer_state_t::eAppContentPriorityChanged;
2018+
transactions.back().states.front().state.appContentPriority = 3;
2019+
2020+
mLifecycleManager.applyTransactions(transactions);
2021+
EXPECT_EQ(mLifecycleManager.getGlobalChanges(), RequestedLayerState::Changes::Content);
2022+
2023+
update(mSnapshotBuilder);
2024+
2025+
EXPECT_EQ(getSnapshot(1)->pictureProfilePriority, 3);
2026+
}
2027+
19882028
} // namespace android::surfaceflinger::frontend

0 commit comments

Comments
 (0)