Skip to content

Commit 8fada3c

Browse files
Sally QiAndroid (Google) Code Review
authored andcommitted
Merge "[Lut NDK] Add new ASurfaceTransaction_setLuts api." into main
2 parents a4bec9b + 01e9f30 commit 8fada3c

3 files changed

Lines changed: 246 additions & 0 deletions

File tree

include/android/display_luts.h

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
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+
/**
18+
* @addtogroup NativeActivity Native Activity
19+
* @{
20+
*/
21+
22+
/**
23+
* @file display_luts.h
24+
*/
25+
#pragma once
26+
27+
#include <inttypes.h>
28+
29+
__BEGIN_DECLS
30+
31+
/**
32+
* The dimension of the lut
33+
*/
34+
enum ADisplayLuts_Dimension : int32_t {
35+
ADISPLAYLUTS_ONE_DIMENSION = 1,
36+
ADISPLAYLUTS_THREE_DIMENSION = 3,
37+
};
38+
39+
/**
40+
* The sampling key used by the lut
41+
*/
42+
enum ADisplayLuts_SamplingKey : int32_t {
43+
ADISPLAYLUTS_SAMPLINGKEY_RGB = 0,
44+
ADISPLAYLUTS_SAMPLINGKEY_MAX_RGB = 1,
45+
};
46+
47+
/**
48+
* Used to get and set display luts entry
49+
*/
50+
typedef struct ADisplayLutsEntry ADisplayLutsEntry;
51+
52+
/**
53+
* Used to get and set display luts
54+
*/
55+
typedef struct ADisplayLuts ADisplayLuts;
56+
57+
/**
58+
* Creates a \a ADisplayLutsEntry entry.
59+
*
60+
* You are responsible for mamanging the memory of the returned object.
61+
* Always call \a ADisplayLutsEntry_destroy to release it after use.
62+
*
63+
* Functions like \a ADisplayLuts_set create their own copies of entries,
64+
* therefore they don't take the ownership of the instance created by
65+
* \a ADisplayLutsEntry_create.
66+
*
67+
* @param buffer The lut raw buffer. The function creates a copy of it and does not need to
68+
* outlive the life of the ADisplayLutsEntry.
69+
* @param length The length of lut raw buffer
70+
* @param dimension The dimension of the lut. see \a ADisplayLuts_Dimension
71+
* @param key The sampling key used by the lut. see \a ADisplayLuts_SamplingKey
72+
* @return a new \a ADisplayLutsEntry instance.
73+
*/
74+
ADisplayLutsEntry* _Nonnull ADisplayLutsEntry_createEntry(float* _Nonnull buffer,
75+
int32_t length, int32_t dimension, int32_t key) __INTRODUCED_IN(36);
76+
77+
/**
78+
* Destroy the \a ADisplayLutsEntry instance.
79+
*
80+
* @param entry The entry to be destroyed
81+
*/
82+
void ADisplayLutsEntry_destroy(ADisplayLutsEntry* _Nullable entry) __INTRODUCED_IN(36);
83+
84+
/**
85+
* Gets the dimension of the entry.
86+
*
87+
* The function is only valid for the lifetime of the `entry`.
88+
*
89+
* @param entry The entry to query
90+
* @return the dimension of the lut
91+
*/
92+
ADisplayLuts_Dimension ADisplayLutsEntry_getDimension(const ADisplayLutsEntry* _Nonnull entry)
93+
__INTRODUCED_IN(36);
94+
95+
/**
96+
* Gets the size for each dimension of the entry.
97+
*
98+
* The function is only valid for the lifetime of the `entry`.
99+
*
100+
* @param entry The entry to query
101+
* @return the size of each dimension of the lut
102+
*/
103+
int32_t ADisplayLutsEntry_getSize(const ADisplayLutsEntry* _Nonnull entry)
104+
__INTRODUCED_IN(36);
105+
106+
/**
107+
* Gets the sampling key used by the entry.
108+
*
109+
* The function is only valid for the lifetime of the `entry`.
110+
*
111+
* @param entry The entry to query
112+
* @return the sampling key used by the lut
113+
*/
114+
ADisplayLuts_SamplingKey ADisplayLutsEntry_getSamplingKey(const ADisplayLutsEntry* _Nonnull entry)
115+
__INTRODUCED_IN(36);
116+
117+
/**
118+
* Gets the lut buffer of the entry.
119+
*
120+
* The function is only valid for the lifetime of the `entry`.
121+
*
122+
* @param entry The entry to query
123+
* @return a pointer to the raw lut buffer
124+
*/
125+
const float* _Nonnull ADisplayLutsEntry_getBuffer(const ADisplayLutsEntry* _Nonnull entry)
126+
__INTRODUCED_IN(36);
127+
128+
/**
129+
* Creates a \a ADisplayLuts instance.
130+
*
131+
* You are responsible for mamanging the memory of the returned object.
132+
* Always call \a ADisplayLuts_destroy to release it after use. E.g., after calling
133+
* the function \a ASurfaceTransaction_setLuts.
134+
*
135+
* @return a new \a ADisplayLuts instance
136+
*/
137+
ADisplayLuts* _Nonnull ADisplayLuts_create() __INTRODUCED_IN(36);
138+
139+
/**
140+
* Sets Luts in order to be applied.
141+
*
142+
* The function accepts a single 1D Lut, or a single 3D Lut or both 1D and 3D Lut in order.
143+
* And the function will replace any previously set lut(s).
144+
* If you want to clear the previously set lut(s), set `entries` to be nullptr,
145+
* and `numEntries` will be internally ignored.
146+
*
147+
* @param luts the pointer of the \a ADisplayLuts instance
148+
* @param entries the pointer of the array of lut entries to be applied
149+
* @param numEntries the number of lut entries. The value should be either 1 or 2.
150+
*/
151+
void ADisplayLuts_setEntries(ADisplayLuts* _Nonnull luts,
152+
ADisplayLutsEntry* _Nullable *_Nullable entries, int32_t numEntries) __INTRODUCED_IN(36);
153+
154+
/**
155+
* Deletes the \a ADisplayLuts instance.
156+
*
157+
* @param luts The luts to be destroyed
158+
*/
159+
void ADisplayLuts_destroy(ADisplayLuts* _Nullable luts) __INTRODUCED_IN(36);
160+
161+
__END_DECLS
162+
163+
/** @} */

include/android/surface_control.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include <sys/cdefs.h>
3030

31+
#include <android/display_luts.h>
3132
#include <android/choreographer.h>
3233
#include <android/data_space.h>
3334
#include <android/hardware_buffer.h>
@@ -712,6 +713,23 @@ void ASurfaceTransaction_setDesiredHdrHeadroom(ASurfaceTransaction* _Nonnull tra
712713
float desiredHeadroom)
713714
__INTRODUCED_IN(__ANDROID_API_V__);
714715

716+
/**
717+
* Sets the Lut(s) to be applied for the layer.
718+
*
719+
* The function makes a deep copy of the provided `luts`.
720+
* Any modifications made to the `luts` object after calling this function
721+
* will not affect the Lut(s) applied to the layer.
722+
*
723+
* @param surface_control The layer where Lut(s) is being applied
724+
* @param luts The Lut(s) to be applied
725+
*
726+
* Available since API level 36.
727+
*/
728+
void ASurfaceTransaction_setLuts(ASurfaceTransaction* _Nonnull transaction,
729+
ASurfaceControl* _Nonnull surface_control,
730+
const struct ADisplayLuts* _Nullable luts)
731+
__INTRODUCED_IN(36);
732+
715733
/**
716734
* Same as ASurfaceTransaction_setFrameRateWithChangeStrategy(transaction, surface_control,
717735
* frameRate, compatibility, ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS).
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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 <vector>
21+
#include <utils/RefBase.h>
22+
23+
using namespace android;
24+
25+
__BEGIN_DECLS
26+
27+
struct ADisplayLutsEntry_buffer {
28+
std::vector<float> data;
29+
};
30+
31+
struct ADisplayLutsEntry_properties {
32+
int32_t dimension;
33+
int32_t size;
34+
int32_t samplingKey;
35+
};
36+
37+
struct ADisplayLutsEntry: public RefBase {
38+
struct ADisplayLutsEntry_buffer buffer;
39+
struct ADisplayLutsEntry_properties properties;
40+
ADisplayLutsEntry() {}
41+
42+
// copy constructor
43+
ADisplayLutsEntry(const ADisplayLutsEntry& other) :
44+
buffer(other.buffer),
45+
properties(other.properties) {}
46+
47+
// copy operator
48+
ADisplayLutsEntry& operator=(const ADisplayLutsEntry& other) {
49+
if (this != &other) { // Protect against self-assignment
50+
buffer = other.buffer;
51+
properties = other.properties;
52+
}
53+
return *this;
54+
}
55+
};
56+
57+
struct ADisplayLuts: public RefBase {
58+
int32_t totalBufferSize;
59+
std::vector<int32_t> offsets;
60+
std::vector<sp<ADisplayLutsEntry>> entries;
61+
62+
ADisplayLuts() : totalBufferSize(0) {}
63+
};
64+
65+
__END_DECLS

0 commit comments

Comments
 (0)