Skip to content

Commit 44d6fff

Browse files
Sally QiAndroid (Google) Code Review
authored andcommitted
Merge "[Lut HAL backend] implementation 3rd patch." into main
2 parents 3f8b957 + ef00658 commit 44d6fff

13 files changed

Lines changed: 422 additions & 15 deletions

File tree

libs/gui/Android.bp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ filegroup {
274274
"LayerMetadata.cpp",
275275
"LayerStatePermissions.cpp",
276276
"LayerState.cpp",
277+
"DisplayLuts.cpp",
277278
"OccupancyTracker.cpp",
278279
"StreamSplitter.cpp",
279280
"ScreenCaptureResults.cpp",

libs/gui/DisplayLuts.cpp

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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+
#include "include/gui/DisplayLuts.h"
18+
#include <gui/DisplayLuts.h>
19+
#include <private/gui/ParcelUtils.h>
20+
21+
namespace android::gui {
22+
23+
status_t DisplayLuts::Entry::readFromParcel(const android::Parcel* parcel) {
24+
if (parcel == nullptr) {
25+
ALOGE("%s: Null parcel", __func__);
26+
return BAD_VALUE;
27+
}
28+
29+
SAFE_PARCEL(parcel->readInt32, &dimension);
30+
SAFE_PARCEL(parcel->readInt32, &size);
31+
SAFE_PARCEL(parcel->readInt32, &samplingKey);
32+
33+
return OK;
34+
}
35+
36+
status_t DisplayLuts::Entry::writeToParcel(android::Parcel* parcel) const {
37+
if (parcel == nullptr) {
38+
ALOGE("%s: Null parcel", __func__);
39+
return BAD_VALUE;
40+
}
41+
42+
SAFE_PARCEL(parcel->writeInt32, dimension);
43+
SAFE_PARCEL(parcel->writeInt32, size);
44+
SAFE_PARCEL(parcel->writeInt32, samplingKey);
45+
46+
return OK;
47+
}
48+
49+
status_t DisplayLuts::readFromParcel(const android::Parcel* parcel) {
50+
if (parcel == nullptr) {
51+
ALOGE("%s: Null parcel", __func__);
52+
return BAD_VALUE;
53+
}
54+
55+
SAFE_PARCEL(parcel->readUniqueFileDescriptor, &fd);
56+
SAFE_PARCEL(parcel->readInt32Vector, &offsets);
57+
int32_t numLutProperties;
58+
SAFE_PARCEL(parcel->readInt32, &numLutProperties);
59+
lutProperties.reserve(numLutProperties);
60+
for (int32_t i = 0; i < numLutProperties; i++) {
61+
lutProperties.push_back({});
62+
SAFE_PARCEL(lutProperties.back().readFromParcel, parcel);
63+
}
64+
return OK;
65+
}
66+
67+
status_t DisplayLuts::writeToParcel(android::Parcel* parcel) const {
68+
if (parcel == nullptr) {
69+
ALOGE("%s: Null parcel", __func__);
70+
return BAD_VALUE;
71+
}
72+
73+
SAFE_PARCEL(parcel->writeUniqueFileDescriptor, fd);
74+
SAFE_PARCEL(parcel->writeInt32Vector, offsets);
75+
SAFE_PARCEL(parcel->writeInt32, static_cast<int32_t>(lutProperties.size()));
76+
for (auto& entry : lutProperties) {
77+
SAFE_PARCEL(entry.writeToParcel, parcel);
78+
}
79+
return OK;
80+
}
81+
} // namespace android::gui

libs/gui/LayerState.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@ status_t layer_state_t::write(Parcel& output) const
203203
SAFE_PARCEL(output.writeParcelable, *bufferReleaseChannel);
204204
}
205205

206+
const bool hasLuts = (luts != nullptr);
207+
SAFE_PARCEL(output.writeBool, hasLuts);
208+
if (hasLuts) {
209+
SAFE_PARCEL(output.writeParcelable, *luts);
210+
}
211+
206212
return NO_ERROR;
207213
}
208214

@@ -358,6 +364,15 @@ status_t layer_state_t::read(const Parcel& input)
358364
SAFE_PARCEL(input.readParcelable, bufferReleaseChannel.get());
359365
}
360366

367+
bool hasLuts;
368+
SAFE_PARCEL(input.readBool, &hasLuts);
369+
if (hasLuts) {
370+
luts = std::make_shared<gui::DisplayLuts>();
371+
SAFE_PARCEL(input.readParcelable, luts.get());
372+
} else {
373+
luts = nullptr;
374+
}
375+
361376
return NO_ERROR;
362377
}
363378

libs/gui/SurfaceComposerClient.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1971,9 +1971,13 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setLuts(
19711971
return *this;
19721972
}
19731973

1974-
s->luts = std::make_shared<gui::DisplayLuts>(base::unique_fd(dup(lutFd.get())), offsets,
1975-
dimensions, sizes, samplingKeys);
19761974
s->what |= layer_state_t::eLutsChanged;
1975+
if (lutFd.ok()) {
1976+
s->luts = std::make_shared<gui::DisplayLuts>(base::unique_fd(dup(lutFd.get())), offsets,
1977+
dimensions, sizes, samplingKeys);
1978+
} else {
1979+
s->luts = nullptr;
1980+
}
19771981

19781982
registerSurfaceControlForCallback(sc);
19791983
return *this;

libs/gui/include/gui/DisplayLuts.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,24 @@
1616
#pragma once
1717

1818
#include <android-base/unique_fd.h>
19+
#include <binder/Parcel.h>
20+
#include <binder/Parcelable.h>
1921
#include <vector>
2022

2123
namespace android::gui {
2224

23-
struct DisplayLuts {
25+
struct DisplayLuts : public Parcelable {
2426
public:
25-
struct Entry {
27+
struct Entry : public Parcelable {
28+
Entry() {};
29+
Entry(int32_t lutDimension, int32_t lutSize, int32_t lutSamplingKey)
30+
: dimension(lutDimension), size(lutSize), samplingKey(lutSamplingKey) {}
2631
int32_t dimension;
2732
int32_t size;
2833
int32_t samplingKey;
34+
35+
status_t writeToParcel(android::Parcel* parcel) const override;
36+
status_t readFromParcel(const android::Parcel* parcel) override;
2937
};
3038

3139
DisplayLuts() {}
@@ -42,7 +50,10 @@ struct DisplayLuts {
4250
}
4351
}
4452

45-
base::unique_fd& getLutFileDescriptor() { return fd; }
53+
status_t writeToParcel(android::Parcel* parcel) const override;
54+
status_t readFromParcel(const android::Parcel* parcel) override;
55+
56+
const base::unique_fd& getLutFileDescriptor() const { return fd; }
4657

4758
std::vector<Entry> lutProperties;
4859
std::vector<int32_t> offsets;

libs/renderengine/Android.bp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ filegroup {
105105
"skia/filters/KawaseBlurDualFilter.cpp",
106106
"skia/filters/KawaseBlurFilter.cpp",
107107
"skia/filters/LinearEffect.cpp",
108+
"skia/filters/LutShader.cpp",
108109
"skia/filters/MouriMap.cpp",
109110
"skia/filters/StretchShaderFactory.cpp",
110111
"skia/filters/EdgeExtensionShaderFactory.cpp",

libs/renderengine/skia/SkiaRenderEngine.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,10 @@ sk_sp<SkShader> SkiaRenderEngine::createRuntimeEffectShader(
543543
}
544544
}
545545

546+
if (graphicBuffer && parameters.layer.luts) {
547+
shader = mLutShader.lutShader(shader, parameters.layer.luts);
548+
}
549+
546550
if (parameters.requiresLinearEffect) {
547551
const auto format = targetBuffer != nullptr
548552
? std::optional<ui::PixelFormat>(

libs/renderengine/skia/SkiaRenderEngine.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "filters/BlurFilter.h"
4040
#include "filters/EdgeExtensionShaderFactory.h"
4141
#include "filters/LinearEffect.h"
42+
#include "filters/LutShader.h"
4243
#include "filters/StretchShaderFactory.h"
4344

4445
class SkData;
@@ -184,6 +185,7 @@ class SkiaRenderEngine : public RenderEngine {
184185

185186
StretchShaderFactory mStretchShaderFactory;
186187
EdgeExtensionShaderFactory mEdgeExtensionShaderFactory;
188+
LutShader mLutShader;
187189

188190
sp<Fence> mLastDrawFence;
189191
BlurFilter* mBlurFilter = nullptr;

0 commit comments

Comments
 (0)