Skip to content

Commit 7a4cb7e

Browse files
committed
Add plumbing to pass picture profiles down to Composer HAL
Bug: 337330263 Test: atest OutputLayerWriteStateToHWCTest Test: atest OutputUpdateAndWriteCompositionStateTest Flag: com.android.graphics.libgui.flags.apply_picture_profiles Change-Id: I082f4bc47c2d402e15fc3a3de5224889752272fa
1 parent 3a707e0 commit 7a4cb7e

16 files changed

Lines changed: 221 additions & 9 deletions

File tree

libs/ui/Android.bp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ cc_library_shared {
136136
"GraphicBuffer.cpp",
137137
"GraphicBufferAllocator.cpp",
138138
"GraphicBufferMapper.cpp",
139+
"PictureProfileHandle.cpp",
139140
"PixelFormat.cpp",
140141
"PublicFormat.cpp",
141142
"StaticAsserts.cpp",

libs/ui/PictureProfileHandle.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (C) 2009 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 <ui/PictureProfileHandle.h>
18+
19+
#include <format>
20+
21+
namespace android {
22+
23+
const PictureProfileHandle PictureProfileHandle::NONE(0);
24+
25+
::std::string toString(const PictureProfileHandle& handle) {
26+
return std::format("{:#010x}", handle.getId());
27+
}
28+
29+
} // namespace android
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (C) 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 <stdint.h>
20+
#include <array>
21+
#include <string>
22+
23+
namespace android {
24+
25+
/**
26+
* An opaque value that uniquely identifies a picture profile, or a set of parameters, which
27+
* describes the configuration of a picture processing pipeline that is applied to a graphic buffer
28+
* to enhance its quality prior to rendering on the display.
29+
*/
30+
typedef int64_t PictureProfileId;
31+
32+
/**
33+
* A picture profile handle wraps the picture profile ID for type-safety, and represents an opaque
34+
* handle that doesn't have the performance drawbacks of Binders.
35+
*/
36+
class PictureProfileHandle {
37+
public:
38+
// A profile that represents no picture processing.
39+
static const PictureProfileHandle NONE;
40+
41+
PictureProfileHandle() { *this = NONE; }
42+
PictureProfileHandle(PictureProfileId id) : mId(id) {}
43+
44+
PictureProfileId const& getId() const { return mId; }
45+
46+
inline bool operator==(const PictureProfileHandle& rhs) { return mId == rhs.mId; }
47+
inline bool operator!=(const PictureProfileHandle& rhs) { return !(*this == rhs); }
48+
49+
// Is the picture profile effectively null, or not-specified?
50+
inline bool operator!() const { return mId == NONE.mId; }
51+
52+
operator bool() const { return !!*this; }
53+
54+
friend ::std::string toString(const PictureProfileHandle& handle);
55+
56+
private:
57+
PictureProfileId mId;
58+
};
59+
60+
} // namespace android

services/surfaceflinger/DisplayDevice.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ struct DisplayDeviceState {
286286
bool isProtected = false;
287287
// Refer to DisplayDevice::mRequestedRefreshRate, for virtual display only
288288
Fps requestedRefreshRate;
289+
int32_t maxLayerPictureProfiles = 0;
290+
bool hasPictureProcessing = false;
289291

290292
private:
291293
static std::atomic<int32_t> sNextSequenceId;

services/surfaceflinger/DisplayHardware/AidlComposerHal.cpp

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,11 @@ using hardware::Return;
4444
using aidl::android::hardware::graphics::composer3::BnComposerCallback;
4545
using aidl::android::hardware::graphics::composer3::Capability;
4646
using aidl::android::hardware::graphics::composer3::ClientTargetPropertyWithBrightness;
47+
using aidl::android::hardware::graphics::composer3::CommandResultPayload;
4748
using aidl::android::hardware::graphics::composer3::Luts;
4849
using aidl::android::hardware::graphics::composer3::PowerMode;
4950
using aidl::android::hardware::graphics::composer3::VirtualDisplay;
5051

51-
using aidl::android::hardware::graphics::composer3::CommandResultPayload;
52-
5352
using AidlColorMode = aidl::android::hardware::graphics::composer3::ColorMode;
5453
using AidlContentType = aidl::android::hardware::graphics::composer3::ContentType;
5554
using AidlDisplayIdentification =
@@ -1639,6 +1638,41 @@ Error AidlComposer::getPhysicalDisplayOrientation(Display displayId,
16391638
return Error::NONE;
16401639
}
16411640

1641+
Error AidlComposer::getMaxLayerPictureProfiles(Display display, int32_t* outMaxProfiles) {
1642+
const auto status = mAidlComposerClient->getMaxLayerPictureProfiles(translate<int64_t>(display),
1643+
outMaxProfiles);
1644+
if (!status.isOk()) {
1645+
ALOGE("getMaxLayerPictureProfiles failed %s", status.getDescription().c_str());
1646+
return static_cast<Error>(status.getServiceSpecificError());
1647+
}
1648+
return Error::NONE;
1649+
}
1650+
1651+
Error AidlComposer::setDisplayPictureProfileId(Display display, PictureProfileId id) {
1652+
Error error = Error::NONE;
1653+
mMutex.lock_shared();
1654+
if (auto writer = getWriter(display)) {
1655+
writer->get().setDisplayPictureProfileId(translate<int64_t>(display), id);
1656+
} else {
1657+
error = Error::BAD_DISPLAY;
1658+
}
1659+
mMutex.unlock_shared();
1660+
return error;
1661+
}
1662+
1663+
Error AidlComposer::setLayerPictureProfileId(Display display, Layer layer, PictureProfileId id) {
1664+
Error error = Error::NONE;
1665+
mMutex.lock_shared();
1666+
if (auto writer = getWriter(display)) {
1667+
writer->get().setLayerPictureProfileId(translate<int64_t>(display),
1668+
translate<int64_t>(layer), id);
1669+
} else {
1670+
error = Error::BAD_DISPLAY;
1671+
}
1672+
mMutex.unlock_shared();
1673+
return error;
1674+
}
1675+
16421676
ftl::Optional<std::reference_wrapper<ComposerClientWriter>> AidlComposer::getWriter(Display display)
16431677
REQUIRES_SHARED(mMutex) {
16441678
return mWriters.get(display);

services/surfaceflinger/DisplayHardware/AidlComposerHal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@ class AidlComposer final : public Hwc2::Composer {
250250
std::vector<aidl::android::hardware::graphics::composer3::DisplayLuts::LayerLut>*
251251
outLuts) override;
252252
Error setLayerLuts(Display display, Layer layer, Luts& luts) override;
253+
Error getMaxLayerPictureProfiles(Display, int32_t* outMaxProfiles) override;
254+
Error setDisplayPictureProfileId(Display, PictureProfileId id) override;
255+
Error setLayerPictureProfileId(Display, Layer, PictureProfileId id) override;
253256

254257
private:
255258
// Many public functions above simply write a command into the command

services/surfaceflinger/DisplayHardware/ComposerHal.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@
2929
#include <math/mat4.h>
3030
#include <ui/DisplayedFrameStats.h>
3131
#include <ui/GraphicBuffer.h>
32+
#include <ui/PictureProfileHandle.h>
3233
#include <utils/StrongPointer.h>
3334

3435
#include <aidl/android/hardware/graphics/common/DisplayDecorationSupport.h>
3536
#include <aidl/android/hardware/graphics/common/HdrConversionCapability.h>
3637
#include <aidl/android/hardware/graphics/common/HdrConversionStrategy.h>
38+
#include <aidl/android/hardware/graphics/common/Transform.h>
3739
#include <aidl/android/hardware/graphics/composer3/Capability.h>
3840
#include <aidl/android/hardware/graphics/composer3/ClientTargetPropertyWithBrightness.h>
3941
#include <aidl/android/hardware/graphics/composer3/Color.h>
@@ -44,7 +46,6 @@
4446
#include <aidl/android/hardware/graphics/composer3/IComposerCallback.h>
4547
#include <aidl/android/hardware/graphics/composer3/OverlayProperties.h>
4648

47-
#include <aidl/android/hardware/graphics/common/Transform.h>
4849
#include <optional>
4950

5051
// TODO(b/129481165): remove the #pragma below and fix conversion issues
@@ -307,6 +308,9 @@ class Composer {
307308
virtual Error getRequestedLuts(Display display, std::vector<Layer>* outLayers,
308309
std::vector<V3_0::DisplayLuts::LayerLut>* outLuts) = 0;
309310
virtual Error setLayerLuts(Display display, Layer layer, V3_0::Luts& luts) = 0;
311+
virtual Error getMaxLayerPictureProfiles(Display display, int32_t* outMaxProfiles) = 0;
312+
virtual Error setDisplayPictureProfileId(Display display, PictureProfileId id) = 0;
313+
virtual Error setLayerPictureProfileId(Display display, Layer layer, PictureProfileId id) = 0;
310314
};
311315

312316
} // namespace Hwc2

services/surfaceflinger/DisplayHardware/HWC2.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <ui/Fence.h>
3232
#include <ui/FloatRect.h>
3333
#include <ui/GraphicBuffer.h>
34+
#include <ui/PictureProfileHandle.h>
3435

3536
#include <algorithm>
3637
#include <cinttypes>
@@ -53,6 +54,7 @@ using android::FloatRect;
5354
using android::GraphicBuffer;
5455
using android::HdrCapabilities;
5556
using android::HdrMetadata;
57+
using android::PictureProfileHandle;
5658
using android::Rect;
5759
using android::Region;
5860
using android::sp;
@@ -655,6 +657,16 @@ Error Display::setIdleTimerEnabled(std::chrono::milliseconds timeout) {
655657
return static_cast<Error>(error);
656658
}
657659

660+
Error Display::getMaxLayerPictureProfiles(int32_t* outMaxProfiles) {
661+
const auto error = mComposer.getMaxLayerPictureProfiles(mId, outMaxProfiles);
662+
return static_cast<Error>(error);
663+
}
664+
665+
Error Display::setPictureProfileHandle(const PictureProfileHandle& handle) {
666+
const auto error = mComposer.setDisplayPictureProfileId(mId, handle.getId());
667+
return static_cast<Error>(error);
668+
}
669+
658670
// For use by Device
659671

660672
void Display::setConnected(bool connected) {
@@ -1086,6 +1098,15 @@ Error Layer::setLuts(aidl::android::hardware::graphics::composer3::Luts& luts) {
10861098
return static_cast<Error>(intError);
10871099
}
10881100

1101+
Error Layer::setPictureProfileHandle(const PictureProfileHandle& handle) {
1102+
if (CC_UNLIKELY(!mDisplay)) {
1103+
return Error::BAD_DISPLAY;
1104+
}
1105+
const auto intError =
1106+
mComposer.setLayerPictureProfileId(mDisplay->getId(), mId, handle.getId());
1107+
return static_cast<Error>(intError);
1108+
}
1109+
10891110
} // namespace impl
10901111
} // namespace HWC2
10911112
} // namespace android

services/surfaceflinger/DisplayHardware/HWC2.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <gui/HdrMetadata.h>
2525
#include <math/mat4.h>
2626
#include <ui/HdrCapabilities.h>
27+
#include <ui/PictureProfileHandle.h>
2728
#include <ui/Region.h>
2829
#include <ui/StaticDisplayInfo.h>
2930
#include <utils/Log.h>
@@ -199,6 +200,9 @@ class Display {
199200
[[nodiscard]] virtual hal::Error setIdleTimerEnabled(std::chrono::milliseconds timeout) = 0;
200201
[[nodiscard]] virtual hal::Error getPhysicalDisplayOrientation(
201202
Hwc2::AidlTransform* outTransform) const = 0;
203+
[[nodiscard]] virtual hal::Error getMaxLayerPictureProfiles(int32_t* maxProfiles) = 0;
204+
[[nodiscard]] virtual hal::Error setPictureProfileHandle(
205+
const PictureProfileHandle& handle) = 0;
202206
};
203207

204208
namespace impl {
@@ -282,6 +286,8 @@ class Display : public HWC2::Display {
282286
std::optional<aidl::android::hardware::graphics::common::DisplayDecorationSupport>*
283287
support) override;
284288
hal::Error setIdleTimerEnabled(std::chrono::milliseconds timeout) override;
289+
hal::Error getMaxLayerPictureProfiles(int32_t* maxProfiles) override;
290+
hal::Error setPictureProfileHandle(const android::PictureProfileHandle& handle) override;
285291

286292
// Other Display methods
287293
hal::HWDisplayId getId() const override { return mId; }
@@ -377,6 +383,8 @@ class Layer {
377383
[[nodiscard]] virtual hal::Error setBlockingRegion(const android::Region& region) = 0;
378384
[[nodiscard]] virtual hal::Error setLuts(
379385
aidl::android::hardware::graphics::composer3::Luts& luts) = 0;
386+
[[nodiscard]] virtual hal::Error setPictureProfileHandle(
387+
const PictureProfileHandle& handle) = 0;
380388
};
381389

382390
namespace impl {
@@ -428,6 +436,7 @@ class Layer : public HWC2::Layer {
428436
hal::Error setBrightness(float brightness) override;
429437
hal::Error setBlockingRegion(const android::Region& region) override;
430438
hal::Error setLuts(aidl::android::hardware::graphics::composer3::Luts&) override;
439+
hal::Error setPictureProfileHandle(const PictureProfileHandle& handle) override;
431440

432441
private:
433442
// These are references to data owned by HWComposer, which will outlive
@@ -449,6 +458,7 @@ class Layer : public HWC2::Layer {
449458
android::HdrMetadata mHdrMetadata;
450459
android::mat4 mColorMatrix;
451460
uint32_t mBufferSlot;
461+
android::PictureProfileHandle profile;
452462
};
453463

454464
} // namespace impl

services/surfaceflinger/DisplayHardware/HWComposer.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,24 @@ status_t HWComposer::setContentType(PhysicalDisplayId displayId, hal::ContentTyp
10221022
return NO_ERROR;
10231023
}
10241024

1025+
int32_t HWComposer::getMaxLayerPictureProfiles(PhysicalDisplayId displayId) {
1026+
int32_t maxProfiles = 0;
1027+
RETURN_IF_INVALID_DISPLAY(displayId, 0);
1028+
const auto error = mDisplayData[displayId].hwcDisplay->getMaxLayerPictureProfiles(&maxProfiles);
1029+
RETURN_IF_HWC_ERROR(error, displayId, 0);
1030+
return maxProfiles;
1031+
}
1032+
1033+
status_t HWComposer::setDisplayPictureProfileHandle(PhysicalDisplayId displayId,
1034+
const PictureProfileHandle& handle) {
1035+
RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
1036+
const auto error = mDisplayData[displayId].hwcDisplay->setPictureProfileHandle(handle);
1037+
if (error != hal::Error::UNSUPPORTED) {
1038+
RETURN_IF_HWC_ERROR(error, displayId, INVALID_OPERATION);
1039+
}
1040+
return NO_ERROR;
1041+
}
1042+
10251043
const std::unordered_map<std::string, bool>& HWComposer::getSupportedLayerGenericMetadata() const {
10261044
return mSupportedLayerGenericMetadata;
10271045
}

0 commit comments

Comments
 (0)