Skip to content

Commit 1a824fd

Browse files
Brian3031Android (Google) Code Review
authored andcommitted
Merge "Allow apps to apply picture profiles with priority to layers" into main
2 parents 44d6fff + 07dcd49 commit 1a824fd

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
const bool hasLuts = (luts != nullptr);
207214
SAFE_PARCEL(output.writeBool, hasLuts);
@@ -363,6 +370,12 @@ status_t layer_state_t::read(const Parcel& input)
363370
bufferReleaseChannel = std::make_shared<gui::BufferReleaseChannel::ProducerEndpoint>();
364371
SAFE_PARCEL(input.readParcelable, bufferReleaseChannel.get());
365372
}
373+
#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS_APPLY_PICTURE_PROFILES
374+
int64_t pictureProfileId;
375+
SAFE_PARCEL(input.readInt64, &pictureProfileId);
376+
pictureProfileHandle = PictureProfileHandle(pictureProfileId);
377+
SAFE_PARCEL(input.readInt32, &appContentPriority);
378+
#endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS_APPLY_PICTURE_PROFILES
366379

367380
bool hasLuts;
368381
SAFE_PARCEL(input.readBool, &hasLuts);
@@ -760,6 +773,16 @@ void layer_state_t::merge(const layer_state_t& other) {
760773
what |= eBufferReleaseChannelChanged;
761774
bufferReleaseChannel = other.bufferReleaseChannel;
762775
}
776+
if (com_android_graphics_libgui_flags_apply_picture_profiles()) {
777+
if (other.what & ePictureProfileHandleChanged) {
778+
what |= ePictureProfileHandleChanged;
779+
pictureProfileHandle = other.pictureProfileHandle;
780+
}
781+
if (other.what & eAppContentPriorityChanged) {
782+
what |= eAppContentPriorityChanged;
783+
appContentPriority = other.appContentPriority;
784+
}
785+
}
763786
if ((other.what & what) != other.what) {
764787
ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
765788
"other.what=0x%" PRIX64 " what=0x%" PRIX64 " unmerged flags=0x%" PRIX64,
@@ -841,6 +864,8 @@ uint64_t layer_state_t::diff(const layer_state_t& other) const {
841864
CHECK_DIFF(diff, eDimmingEnabledChanged, other, dimmingEnabled);
842865
if (other.what & eBufferReleaseChannelChanged) diff |= eBufferReleaseChannelChanged;
843866
if (other.what & eLutsChanged) diff |= eLutsChanged;
867+
CHECK_DIFF(diff, ePictureProfileHandleChanged, other, pictureProfileHandle);
868+
CHECK_DIFF(diff, eAppContentPriorityChanged, other, appContentPriority);
844869

845870
return diff;
846871
}

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>
@@ -2451,6 +2450,40 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setBuffe
24512450
return *this;
24522451
}
24532452

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

24562489
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>
@@ -776,6 +777,20 @@ class SurfaceComposerClient : public RefBase
776777
const sp<SurfaceControl>& sc,
777778
const std::shared_ptr<gui::BufferReleaseChannel::ProducerEndpoint>& channel);
778779

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

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)