Skip to content

Commit 95f669a

Browse files
author
Sally Qi
committed
[Lut HAL backend] implementation
- Add Lut in HWComposer::DeviceRequestedChanges - parse lutProperties into overlayProperties - Add a mapper <layer*, pfd> to store lut fd to avoid dup() ops if passing the fds into callees. - SurfaceComposerClient::Transaction::setLuts interface Bug: 329472100 Test: builds Flag: NONE HAL backend interface change Change-Id: Ib2993ce1eab66ab456388c0d15b032201eac7e91
1 parent 9a4c026 commit 95f669a

25 files changed

Lines changed: 212 additions & 52 deletions

File tree

libs/gui/SurfaceComposerClient.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,6 +1941,20 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setDesir
19411941
return *this;
19421942
}
19431943

1944+
SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setLuts(
1945+
const sp<SurfaceControl>& sc, const base::unique_fd& /*lutFd*/,
1946+
const std::vector<int32_t>& /*offsets*/, const std::vector<int32_t>& /*dimensions*/,
1947+
const std::vector<int32_t>& /*sizes*/, const std::vector<int32_t>& /*samplingKeys*/) {
1948+
layer_state_t* s = getLayerState(sc);
1949+
if (!s) {
1950+
mStatus = BAD_INDEX;
1951+
return *this;
1952+
}
1953+
// TODO (b/329472856): update layer_state_t for lut(s)
1954+
registerSurfaceControlForCallback(sc);
1955+
return *this;
1956+
}
1957+
19441958
SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setCachingHint(
19451959
const sp<SurfaceControl>& sc, gui::CachingHint cachingHint) {
19461960
layer_state_t* s = getLayerState(sc);

libs/gui/aidl/android/gui/Lut.aidl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
package android.gui;
18+
19+
import android.gui.LutProperties;
20+
import android.os.ParcelFileDescriptor;
21+
22+
/**
23+
* This mirrors aidl::android::hardware::graphics::composer3::Lut definition
24+
* @hide
25+
*/
26+
parcelable Lut {
27+
@nullable ParcelFileDescriptor pfd;
28+
29+
LutProperties lutProperties;
30+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
package android.gui;
18+
19+
/**
20+
* This mirrors aidl::android::hardware::graphics::composer3::LutProperties definition.
21+
* @hide
22+
*/
23+
parcelable LutProperties {
24+
@Backing(type="int")
25+
enum Dimension { ONE_D = 1, THREE_D = 3 }
26+
Dimension dimension;
27+
28+
long size;
29+
@Backing(type="int")
30+
enum SamplingKey { RGB, MAX_RGB }
31+
SamplingKey[] samplingKeys;
32+
}

libs/gui/aidl/android/gui/OverlayProperties.aidl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package android.gui;
1818

19+
import android.gui.LutProperties;
20+
1921
/** @hide */
2022
parcelable OverlayProperties {
2123
parcelable SupportedBufferCombinations {
@@ -27,4 +29,6 @@ parcelable OverlayProperties {
2729
SupportedBufferCombinations[] combinations;
2830

2931
boolean supportMixedColorSpaces;
32+
33+
@nullable LutProperties[] lutProperties;
3034
}

libs/gui/include/gui/SurfaceComposerClient.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,11 @@ class SurfaceComposerClient : public RefBase
601601
Transaction& setExtendedRangeBrightness(const sp<SurfaceControl>& sc,
602602
float currentBufferRatio, float desiredRatio);
603603
Transaction& setDesiredHdrHeadroom(const sp<SurfaceControl>& sc, float desiredRatio);
604+
Transaction& setLuts(const sp<SurfaceControl>& sc, const base::unique_fd& lutFd,
605+
const std::vector<int32_t>& offsets,
606+
const std::vector<int32_t>& dimensions,
607+
const std::vector<int32_t>& sizes,
608+
const std::vector<int32_t>& samplingKeys);
604609
Transaction& setCachingHint(const sp<SurfaceControl>& sc, gui::CachingHint cachingHint);
605610
Transaction& setHdrMetadata(const sp<SurfaceControl>& sc, const HdrMetadata& hdrMetadata);
606611
Transaction& setSurfaceDamageRegion(const sp<SurfaceControl>& sc,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ class OutputLayer {
128128
// Applies a HWC device layer request
129129
virtual void applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest request) = 0;
130130

131+
// Applies a HWC device layer lut
132+
virtual void applyDeviceLayerLut(aidl::android::hardware::graphics::composer3::LutProperties,
133+
ndk::ScopedFileDescriptor) = 0;
134+
131135
// Returns true if the composition settings scale pixels
132136
virtual bool needsFiltering() const = 0;
133137

services/surfaceflinger/CompositionEngine/include/compositionengine/impl/Display.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,13 @@ class Display : public compositionengine::impl::Output, public virtual compositi
8282
using DisplayRequests = android::HWComposer::DeviceRequestedChanges::DisplayRequests;
8383
using LayerRequests = android::HWComposer::DeviceRequestedChanges::LayerRequests;
8484
using ClientTargetProperty = android::HWComposer::DeviceRequestedChanges::ClientTargetProperty;
85+
using LayerLuts = android::HWComposer::DeviceRequestedChanges::LayerLuts;
8586
virtual bool allLayersRequireClientComposition() const;
8687
virtual void applyChangedTypesToLayers(const ChangedTypes&);
8788
virtual void applyDisplayRequests(const DisplayRequests&);
8889
virtual void applyLayerRequestsToLayers(const LayerRequests&);
8990
virtual void applyClientTargetRequests(const ClientTargetProperty&);
91+
virtual void applyLayerLutsToLayers(const LayerLuts&);
9092

9193
// Internal
9294
virtual void setConfiguration(const compositionengine::DisplayCreationArgs&);

services/surfaceflinger/CompositionEngine/include/compositionengine/impl/OutputLayer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ class OutputLayer : public virtual compositionengine::OutputLayer {
6060
aidl::android::hardware::graphics::composer3::Composition) override;
6161
void prepareForDeviceLayerRequests() override;
6262
void applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest request) override;
63+
void applyDeviceLayerLut(aidl::android::hardware::graphics::composer3::LutProperties,
64+
ndk::ScopedFileDescriptor) override;
6365
bool needsFiltering() const override;
6466
std::optional<LayerFE::LayerSettings> getOverrideCompositionSettings() const override;
6567

services/surfaceflinger/CompositionEngine/include/compositionengine/mock/OutputLayer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ class OutputLayer : public compositionengine::OutputLayer {
5656
MOCK_METHOD1(applyDeviceLayerRequest, void(Hwc2::IComposerClient::LayerRequest request));
5757
MOCK_CONST_METHOD0(needsFiltering, bool());
5858
MOCK_CONST_METHOD0(getOverrideCompositionSettings, std::optional<LayerFE::LayerSettings>());
59+
MOCK_METHOD(void, applyDeviceLayerLut,
60+
(aidl::android::hardware::graphics::composer3::LutProperties,
61+
ndk::ScopedFileDescriptor));
5962

6063
MOCK_CONST_METHOD1(dump, void(std::string&));
6164
};

services/surfaceflinger/CompositionEngine/src/Display.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ void Display::applyCompositionStrategy(const std::optional<DeviceRequestedChange
278278
applyDisplayRequests(changes->displayRequests);
279279
applyLayerRequestsToLayers(changes->layerRequests);
280280
applyClientTargetRequests(changes->clientTargetProperty);
281+
applyLayerLutsToLayers(changes->layerLuts);
281282
}
282283

283284
// Determine what type of composition we are doing from the final state
@@ -359,6 +360,25 @@ void Display::applyClientTargetRequests(const ClientTargetProperty& clientTarget
359360
static_cast<ui::PixelFormat>(clientTargetProperty.clientTargetProperty.pixelFormat));
360361
}
361362

363+
void Display::applyLayerLutsToLayers(const LayerLuts& layerLuts) {
364+
auto& mapper = getCompositionEngine().getHwComposer().getLutFileDescriptorMapper();
365+
for (auto* layer : getOutputLayersOrderedByZ()) {
366+
auto hwcLayer = layer->getHwcLayer();
367+
if (!hwcLayer) {
368+
continue;
369+
}
370+
371+
if (auto lutsIt = layerLuts.find(hwcLayer); lutsIt != layerLuts.end()) {
372+
if (auto mapperIt = mapper.find(hwcLayer); mapperIt != mapper.end()) {
373+
layer->applyDeviceLayerLut(lutsIt->second,
374+
ndk::ScopedFileDescriptor(mapperIt->second.release()));
375+
}
376+
}
377+
}
378+
379+
mapper.clear();
380+
}
381+
362382
void Display::executeCommands() {
363383
const auto halDisplayIdOpt = HalDisplayId::tryCast(mId);
364384
if (mIsDisconnected || !halDisplayIdOpt) {

0 commit comments

Comments
 (0)