blob: 19518eaeccff4e02100f9280bd6a06892171c296 [file] [log] [blame]
Alec Mouri492c85c2021-11-19 15:58:10 -08001/*
2 * Copyright 2021 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 <shaders/shaders.h>
18
19#include <tonemap/tonemap.h>
20
Alec Mouri5a493722022-01-26 16:43:02 -080021#include <cmath>
Alec Mouri492c85c2021-11-19 15:58:10 -080022#include <optional>
23
24#include <math/mat4.h>
25#include <system/graphics-base-v1.0.h>
26#include <ui/ColorSpace.h>
27
28namespace android::shaders {
29
Alec Mouri5a493722022-01-26 16:43:02 -080030namespace {
31
32aidl::android::hardware::graphics::common::Dataspace toAidlDataspace(ui::Dataspace dataspace) {
Alec Mouri492c85c2021-11-19 15:58:10 -080033 return static_cast<aidl::android::hardware::graphics::common::Dataspace>(dataspace);
34}
35
Alec Mouri5a493722022-01-26 16:43:02 -080036void generateEOTF(ui::Dataspace dataspace, std::string& shader) {
Alec Mouri492c85c2021-11-19 15:58:10 -080037 switch (dataspace & HAL_DATASPACE_TRANSFER_MASK) {
38 case HAL_DATASPACE_TRANSFER_ST2084:
39 shader.append(R"(
40
41 float3 EOTF(float3 color) {
42 float m1 = (2610.0 / 4096.0) / 4.0;
43 float m2 = (2523.0 / 4096.0) * 128.0;
44 float c1 = (3424.0 / 4096.0);
45 float c2 = (2413.0 / 4096.0) * 32.0;
46 float c3 = (2392.0 / 4096.0) * 32.0;
47
48 float3 tmp = pow(clamp(color, 0.0, 1.0), 1.0 / float3(m2));
49 tmp = max(tmp - c1, 0.0) / (c2 - c3 * tmp);
50 return pow(tmp, 1.0 / float3(m1));
51 }
52 )");
53 break;
54 case HAL_DATASPACE_TRANSFER_HLG:
55 shader.append(R"(
56 float EOTF_channel(float channel) {
57 const float a = 0.17883277;
58 const float b = 0.28466892;
59 const float c = 0.55991073;
60 return channel <= 0.5 ? channel * channel / 3.0 :
61 (exp((channel - c) / a) + b) / 12.0;
62 }
63
64 float3 EOTF(float3 color) {
65 return float3(EOTF_channel(color.r), EOTF_channel(color.g),
66 EOTF_channel(color.b));
67 }
68 )");
69 break;
70 case HAL_DATASPACE_TRANSFER_LINEAR:
71 shader.append(R"(
72 float3 EOTF(float3 color) {
73 return color;
74 }
75 )");
76 break;
Sally Qi2019fd22021-11-22 10:19:04 -080077 case HAL_DATASPACE_TRANSFER_SMPTE_170M:
78 shader.append(R"(
79
80 float EOTF_sRGB(float srgb) {
Sally Qi575fb072022-05-09 12:34:52 -070081 return srgb <= 0.08125 ? srgb / 4.50 : pow((srgb + 0.099) / 1.099, 1 / 0.45);
Sally Qi2019fd22021-11-22 10:19:04 -080082 }
83
84 float3 EOTF_sRGB(float3 srgb) {
85 return float3(EOTF_sRGB(srgb.r), EOTF_sRGB(srgb.g), EOTF_sRGB(srgb.b));
86 }
87
88 float3 EOTF(float3 srgb) {
89 return sign(srgb.rgb) * EOTF_sRGB(abs(srgb.rgb));
90 }
91 )");
92 break;
93 case HAL_DATASPACE_TRANSFER_GAMMA2_2:
94 shader.append(R"(
95
96 float EOTF_sRGB(float srgb) {
97 return pow(srgb, 2.2);
98 }
99
100 float3 EOTF_sRGB(float3 srgb) {
101 return float3(EOTF_sRGB(srgb.r), EOTF_sRGB(srgb.g), EOTF_sRGB(srgb.b));
102 }
103
104 float3 EOTF(float3 srgb) {
105 return sign(srgb.rgb) * EOTF_sRGB(abs(srgb.rgb));
106 }
107 )");
108 break;
109 case HAL_DATASPACE_TRANSFER_GAMMA2_6:
110 shader.append(R"(
111
112 float EOTF_sRGB(float srgb) {
113 return pow(srgb, 2.6);
114 }
115
116 float3 EOTF_sRGB(float3 srgb) {
117 return float3(EOTF_sRGB(srgb.r), EOTF_sRGB(srgb.g), EOTF_sRGB(srgb.b));
118 }
119
120 float3 EOTF(float3 srgb) {
121 return sign(srgb.rgb) * EOTF_sRGB(abs(srgb.rgb));
122 }
123 )");
124 break;
125 case HAL_DATASPACE_TRANSFER_GAMMA2_8:
126 shader.append(R"(
127
128 float EOTF_sRGB(float srgb) {
129 return pow(srgb, 2.8);
130 }
131
132 float3 EOTF_sRGB(float3 srgb) {
133 return float3(EOTF_sRGB(srgb.r), EOTF_sRGB(srgb.g), EOTF_sRGB(srgb.b));
134 }
135
136 float3 EOTF(float3 srgb) {
137 return sign(srgb.rgb) * EOTF_sRGB(abs(srgb.rgb));
138 }
139 )");
140 break;
Alec Mouri492c85c2021-11-19 15:58:10 -0800141 case HAL_DATASPACE_TRANSFER_SRGB:
142 default:
143 shader.append(R"(
144
145 float EOTF_sRGB(float srgb) {
146 return srgb <= 0.04045 ? srgb / 12.92 : pow((srgb + 0.055) / 1.055, 2.4);
147 }
148
149 float3 EOTF_sRGB(float3 srgb) {
150 return float3(EOTF_sRGB(srgb.r), EOTF_sRGB(srgb.g), EOTF_sRGB(srgb.b));
151 }
152
153 float3 EOTF(float3 srgb) {
154 return sign(srgb.rgb) * EOTF_sRGB(abs(srgb.rgb));
155 }
156 )");
157 break;
158 }
159}
160
Alec Mouri5a493722022-01-26 16:43:02 -0800161void generateXYZTransforms(std::string& shader) {
Alec Mouri492c85c2021-11-19 15:58:10 -0800162 shader.append(R"(
163 uniform float4x4 in_rgbToXyz;
164 uniform float4x4 in_xyzToRgb;
165 float3 ToXYZ(float3 rgb) {
166 return (in_rgbToXyz * float4(rgb, 1.0)).rgb;
167 }
168
169 float3 ToRGB(float3 xyz) {
170 return clamp((in_xyzToRgb * float4(xyz, 1.0)).rgb, 0.0, 1.0);
171 }
172 )");
173}
174
175// Conversion from relative light to absolute light (maps from [0, 1] to [0, maxNits])
Alec Mouri5a493722022-01-26 16:43:02 -0800176void generateLuminanceScalesForOOTF(ui::Dataspace inputDataspace, ui::Dataspace outputDataspace,
177 std::string& shader) {
Alec Mouri492c85c2021-11-19 15:58:10 -0800178 switch (inputDataspace & HAL_DATASPACE_TRANSFER_MASK) {
179 case HAL_DATASPACE_TRANSFER_ST2084:
180 shader.append(R"(
181 float3 ScaleLuminance(float3 xyz) {
182 return xyz * 10000.0;
183 }
184 )");
185 break;
186 case HAL_DATASPACE_TRANSFER_HLG:
187 shader.append(R"(
188 float3 ScaleLuminance(float3 xyz) {
Alec Mouri7a577452022-03-04 23:41:38 +0000189 return xyz * 1000.0;
Alec Mouri492c85c2021-11-19 15:58:10 -0800190 }
191 )");
192 break;
193 default:
Alec Mouri3e5965f2023-04-07 18:00:58 +0000194 // Input is SDR so map to its white point luminance
Alec Mouri492c85c2021-11-19 15:58:10 -0800195 switch (outputDataspace & HAL_DATASPACE_TRANSFER_MASK) {
Alec Mouri3e5965f2023-04-07 18:00:58 +0000196 // Max HLG output is nominally 1000 nits, but BT. 2100-2 allows
197 // for gamma correcting the HLG OOTF for displays with a different
198 // dynamic range. Scale to 1000 nits to apply an inverse OOTF against
199 // a reference display correctly.
200 // TODO: Use knowledge of the dimming ratio here to prevent
201 // unintended gamma shaft.
Alec Mouri492c85c2021-11-19 15:58:10 -0800202 case HAL_DATASPACE_TRANSFER_HLG:
Alec Mouri492c85c2021-11-19 15:58:10 -0800203 shader.append(R"(
204 float3 ScaleLuminance(float3 xyz) {
Alec Mouri3e5965f2023-04-07 18:00:58 +0000205 return xyz * 1000.0;
Alec Mouri492c85c2021-11-19 15:58:10 -0800206 }
207 )");
208 break;
209 default:
Alec Mouri492c85c2021-11-19 15:58:10 -0800210 shader.append(R"(
Alec Mouri3e5965f2023-04-07 18:00:58 +0000211 float3 ScaleLuminance(float3 xyz) {
212 return xyz * in_libtonemap_displayMaxLuminance;
213 }
214 )");
Alec Mouri492c85c2021-11-19 15:58:10 -0800215 break;
216 }
217 }
218}
219
220// Normalizes from absolute light back to relative light (maps from [0, maxNits] back to [0, 1])
Alec Mouri3e5965f2023-04-07 18:00:58 +0000221static void generateLuminanceNormalizationForOOTF(ui::Dataspace inputDataspace,
222 ui::Dataspace outputDataspace,
Alec Mouri492c85c2021-11-19 15:58:10 -0800223 std::string& shader) {
224 switch (outputDataspace & HAL_DATASPACE_TRANSFER_MASK) {
225 case HAL_DATASPACE_TRANSFER_ST2084:
226 shader.append(R"(
227 float3 NormalizeLuminance(float3 xyz) {
228 return xyz / 10000.0;
229 }
230 )");
231 break;
232 case HAL_DATASPACE_TRANSFER_HLG:
Alec Mouri3e5965f2023-04-07 18:00:58 +0000233 switch (inputDataspace & HAL_DATASPACE_TRANSFER_MASK) {
234 case HAL_DATASPACE_TRANSFER_HLG:
235 shader.append(R"(
236 float3 NormalizeLuminance(float3 xyz) {
237 return xyz / 1000.0;
238 }
239 )");
240 break;
241 default:
242 // Transcoding to HLG requires applying the inverse OOTF
243 // with the expectation that the OOTF is then applied during
244 // tonemapping downstream.
245 shader.append(R"(
246 float3 NormalizeLuminance(float3 xyz) {
247 // BT. 2100-2 operates on normalized luminances,
248 // so renormalize to the input
249 float ootfGain = pow(xyz.y / 1000.0, -0.2 / 1.2) / 1000.0;
250 return xyz * ootfGain;
251 }
252 )");
253 break;
254 }
Alec Mouri492c85c2021-11-19 15:58:10 -0800255 break;
256 default:
257 shader.append(R"(
258 float3 NormalizeLuminance(float3 xyz) {
259 return xyz / in_libtonemap_displayMaxLuminance;
260 }
261 )");
262 break;
263 }
264}
265
Alec Mouri5a493722022-01-26 16:43:02 -0800266void generateOOTF(ui::Dataspace inputDataspace, ui::Dataspace outputDataspace,
267 std::string& shader) {
Alec Mouri492c85c2021-11-19 15:58:10 -0800268 shader.append(tonemap::getToneMapper()
269 ->generateTonemapGainShaderSkSL(toAidlDataspace(inputDataspace),
270 toAidlDataspace(outputDataspace))
271 .c_str());
272
273 generateLuminanceScalesForOOTF(inputDataspace, outputDataspace, shader);
Alec Mouri3e5965f2023-04-07 18:00:58 +0000274 generateLuminanceNormalizationForOOTF(inputDataspace, outputDataspace, shader);
Alec Mouri492c85c2021-11-19 15:58:10 -0800275
276 shader.append(R"(
277 float3 OOTF(float3 linearRGB, float3 xyz) {
278 float3 scaledLinearRGB = ScaleLuminance(linearRGB);
279 float3 scaledXYZ = ScaleLuminance(xyz);
280
281 float gain = libtonemap_LookupTonemapGain(scaledLinearRGB, scaledXYZ);
282
283 return NormalizeLuminance(scaledXYZ * gain);
284 }
285 )");
286}
287
Alec Mouri5a493722022-01-26 16:43:02 -0800288void generateOETF(ui::Dataspace dataspace, std::string& shader) {
Alec Mouri492c85c2021-11-19 15:58:10 -0800289 switch (dataspace & HAL_DATASPACE_TRANSFER_MASK) {
290 case HAL_DATASPACE_TRANSFER_ST2084:
291 shader.append(R"(
292
293 float3 OETF(float3 xyz) {
294 float m1 = (2610.0 / 4096.0) / 4.0;
295 float m2 = (2523.0 / 4096.0) * 128.0;
296 float c1 = (3424.0 / 4096.0);
297 float c2 = (2413.0 / 4096.0) * 32.0;
298 float c3 = (2392.0 / 4096.0) * 32.0;
299
300 float3 tmp = pow(xyz, float3(m1));
301 tmp = (c1 + c2 * tmp) / (1.0 + c3 * tmp);
302 return pow(tmp, float3(m2));
303 }
304 )");
305 break;
306 case HAL_DATASPACE_TRANSFER_HLG:
307 shader.append(R"(
308 float OETF_channel(float channel) {
309 const float a = 0.17883277;
310 const float b = 0.28466892;
311 const float c = 0.55991073;
312 return channel <= 1.0 / 12.0 ? sqrt(3.0 * channel) :
313 a * log(12.0 * channel - b) + c;
314 }
315
316 float3 OETF(float3 linear) {
317 return float3(OETF_channel(linear.r), OETF_channel(linear.g),
318 OETF_channel(linear.b));
319 }
320 )");
321 break;
322 case HAL_DATASPACE_TRANSFER_LINEAR:
323 shader.append(R"(
324 float3 OETF(float3 linear) {
325 return linear;
326 }
327 )");
328 break;
Sally Qi2019fd22021-11-22 10:19:04 -0800329 case HAL_DATASPACE_TRANSFER_SMPTE_170M:
330 shader.append(R"(
331 float OETF_sRGB(float linear) {
332 return linear <= 0.018 ?
333 linear * 4.50 : (pow(linear, 0.45) * 1.099) - 0.099;
334 }
335
336 float3 OETF_sRGB(float3 linear) {
337 return float3(OETF_sRGB(linear.r), OETF_sRGB(linear.g), OETF_sRGB(linear.b));
338 }
339
340 float3 OETF(float3 linear) {
341 return sign(linear.rgb) * OETF_sRGB(abs(linear.rgb));
342 }
343 )");
344 break;
345 case HAL_DATASPACE_TRANSFER_GAMMA2_2:
346 shader.append(R"(
347 float OETF_sRGB(float linear) {
348 return pow(linear, (1.0 / 2.2));
349 }
350
351 float3 OETF_sRGB(float3 linear) {
352 return float3(OETF_sRGB(linear.r), OETF_sRGB(linear.g), OETF_sRGB(linear.b));
353 }
354
355 float3 OETF(float3 linear) {
356 return sign(linear.rgb) * OETF_sRGB(abs(linear.rgb));
357 }
358 )");
359 break;
360 case HAL_DATASPACE_TRANSFER_GAMMA2_6:
361 shader.append(R"(
362 float OETF_sRGB(float linear) {
363 return pow(linear, (1.0 / 2.6));
364 }
365
366 float3 OETF_sRGB(float3 linear) {
367 return float3(OETF_sRGB(linear.r), OETF_sRGB(linear.g), OETF_sRGB(linear.b));
368 }
369
370 float3 OETF(float3 linear) {
371 return sign(linear.rgb) * OETF_sRGB(abs(linear.rgb));
372 }
373 )");
374 break;
375 case HAL_DATASPACE_TRANSFER_GAMMA2_8:
376 shader.append(R"(
377 float OETF_sRGB(float linear) {
378 return pow(linear, (1.0 / 2.8));
379 }
380
381 float3 OETF_sRGB(float3 linear) {
382 return float3(OETF_sRGB(linear.r), OETF_sRGB(linear.g), OETF_sRGB(linear.b));
383 }
384
385 float3 OETF(float3 linear) {
386 return sign(linear.rgb) * OETF_sRGB(abs(linear.rgb));
387 }
388 )");
389 break;
Alec Mouri492c85c2021-11-19 15:58:10 -0800390 case HAL_DATASPACE_TRANSFER_SRGB:
391 default:
392 shader.append(R"(
393 float OETF_sRGB(float linear) {
394 return linear <= 0.0031308 ?
395 linear * 12.92 : (pow(linear, 1.0 / 2.4) * 1.055) - 0.055;
396 }
397
398 float3 OETF_sRGB(float3 linear) {
399 return float3(OETF_sRGB(linear.r), OETF_sRGB(linear.g), OETF_sRGB(linear.b));
400 }
401
402 float3 OETF(float3 linear) {
403 return sign(linear.rgb) * OETF_sRGB(abs(linear.rgb));
404 }
405 )");
406 break;
407 }
408}
409
Alec Mouri3c51bc52022-11-04 01:28:55 +0000410void generateEffectiveOOTF(bool undoPremultipliedAlpha, LinearEffect::SkSLType type,
411 std::string& shader) {
412 switch (type) {
413 case LinearEffect::SkSLType::ColorFilter:
414 shader.append(R"(
415 half4 main(half4 inputColor) {
416 float4 c = float4(inputColor);
417 )");
418 break;
419 case LinearEffect::SkSLType::Shader:
420 shader.append(R"(
421 uniform shader child;
422 half4 main(float2 xy) {
423 float4 c = float4(child.eval(xy));
424 )");
425 break;
426 }
Alec Mouri492c85c2021-11-19 15:58:10 -0800427 if (undoPremultipliedAlpha) {
428 shader.append(R"(
429 c.rgb = c.rgb / (c.a + 0.0019);
430 )");
431 }
432 shader.append(R"(
433 float3 linearRGB = EOTF(c.rgb);
434 float3 xyz = ToXYZ(linearRGB);
435 c.rgb = OETF(ToRGB(OOTF(linearRGB, xyz)));
436 )");
437 if (undoPremultipliedAlpha) {
438 shader.append(R"(
439 c.rgb = c.rgb * (c.a + 0.0019);
440 )");
441 }
442 shader.append(R"(
443 return c;
444 }
445 )");
446}
Sally Qi2019fd22021-11-22 10:19:04 -0800447
448// please keep in sync with toSkColorSpace function in renderengine/skia/ColorSpaces.cpp
Alec Mouri5a493722022-01-26 16:43:02 -0800449ColorSpace toColorSpace(ui::Dataspace dataspace) {
Alec Mouri492c85c2021-11-19 15:58:10 -0800450 switch (dataspace & HAL_DATASPACE_STANDARD_MASK) {
451 case HAL_DATASPACE_STANDARD_BT709:
452 return ColorSpace::sRGB();
Alec Mouri492c85c2021-11-19 15:58:10 -0800453 case HAL_DATASPACE_STANDARD_DCI_P3:
454 return ColorSpace::DisplayP3();
Alec Mouri492c85c2021-11-19 15:58:10 -0800455 case HAL_DATASPACE_STANDARD_BT2020:
Sally Qi2019fd22021-11-22 10:19:04 -0800456 case HAL_DATASPACE_STANDARD_BT2020_CONSTANT_LUMINANCE:
Alec Mouri492c85c2021-11-19 15:58:10 -0800457 return ColorSpace::BT2020();
Sally Qi2019fd22021-11-22 10:19:04 -0800458 case HAL_DATASPACE_STANDARD_ADOBE_RGB:
459 return ColorSpace::AdobeRGB();
460 // TODO(b/208290320): BT601 format and variants return different primaries
461 case HAL_DATASPACE_STANDARD_BT601_625:
462 case HAL_DATASPACE_STANDARD_BT601_625_UNADJUSTED:
463 case HAL_DATASPACE_STANDARD_BT601_525:
464 case HAL_DATASPACE_STANDARD_BT601_525_UNADJUSTED:
465 // TODO(b/208290329): BT407M format returns different primaries
466 case HAL_DATASPACE_STANDARD_BT470M:
467 // TODO(b/208290904): FILM format returns different primaries
468 case HAL_DATASPACE_STANDARD_FILM:
469 case HAL_DATASPACE_STANDARD_UNSPECIFIED:
Alec Mouri492c85c2021-11-19 15:58:10 -0800470 default:
471 return ColorSpace::sRGB();
Alec Mouri492c85c2021-11-19 15:58:10 -0800472 }
473}
474
Alec Mouri5a493722022-01-26 16:43:02 -0800475template <typename T, std::enable_if_t<std::is_trivially_copyable<T>::value, bool> = true>
476std::vector<uint8_t> buildUniformValue(T value) {
477 std::vector<uint8_t> result;
478 result.resize(sizeof(value));
479 std::memcpy(result.data(), &value, sizeof(value));
480 return result;
481}
482
Alec Mouri5a493722022-01-26 16:43:02 -0800483} // namespace
484
Alec Mouri492c85c2021-11-19 15:58:10 -0800485std::string buildLinearEffectSkSL(const LinearEffect& linearEffect) {
486 std::string shaderString;
487 generateEOTF(linearEffect.fakeInputDataspace == ui::Dataspace::UNKNOWN
488 ? linearEffect.inputDataspace
489 : linearEffect.fakeInputDataspace,
490 shaderString);
491 generateXYZTransforms(shaderString);
492 generateOOTF(linearEffect.inputDataspace, linearEffect.outputDataspace, shaderString);
493 generateOETF(linearEffect.outputDataspace, shaderString);
Alec Mouri3c51bc52022-11-04 01:28:55 +0000494 generateEffectiveOOTF(linearEffect.undoPremultipliedAlpha, linearEffect.type, shaderString);
Alec Mouri492c85c2021-11-19 15:58:10 -0800495 return shaderString;
496}
497
Alec Mouri492c85c2021-11-19 15:58:10 -0800498// Generates a list of uniforms to set on the LinearEffect shader above.
Alec Mourifcedb9c2022-04-11 20:02:17 +0000499std::vector<tonemap::ShaderUniform> buildLinearEffectUniforms(
500 const LinearEffect& linearEffect, const mat4& colorTransform, float maxDisplayLuminance,
501 float currentDisplayLuminanceNits, float maxLuminance, AHardwareBuffer* buffer,
502 aidl::android::hardware::graphics::composer3::RenderIntent renderIntent) {
Alec Mouri492c85c2021-11-19 15:58:10 -0800503 std::vector<tonemap::ShaderUniform> uniforms;
Alec Mouri6ba7f2b2022-06-02 22:55:05 +0000504
505 const ui::Dataspace inputDataspace = linearEffect.fakeInputDataspace == ui::Dataspace::UNKNOWN
506 ? linearEffect.inputDataspace
507 : linearEffect.fakeInputDataspace;
508
509 if (inputDataspace == linearEffect.outputDataspace) {
Alec Mouri492c85c2021-11-19 15:58:10 -0800510 uniforms.push_back({.name = "in_rgbToXyz", .value = buildUniformValue<mat4>(mat4())});
511 uniforms.push_back(
512 {.name = "in_xyzToRgb", .value = buildUniformValue<mat4>(colorTransform)});
513 } else {
Alec Mouri6ba7f2b2022-06-02 22:55:05 +0000514 ColorSpace inputColorSpace = toColorSpace(inputDataspace);
Alec Mouri492c85c2021-11-19 15:58:10 -0800515 ColorSpace outputColorSpace = toColorSpace(linearEffect.outputDataspace);
516 uniforms.push_back({.name = "in_rgbToXyz",
517 .value = buildUniformValue<mat4>(mat4(inputColorSpace.getRGBtoXYZ()))});
518 uniforms.push_back({.name = "in_xyzToRgb",
519 .value = buildUniformValue<mat4>(
520 colorTransform * mat4(outputColorSpace.getXYZtoRGB()))});
521 }
522
523 tonemap::Metadata metadata{.displayMaxLuminance = maxDisplayLuminance,
Alec Mouri492c85c2021-11-19 15:58:10 -0800524 // If the input luminance is unknown, use display luminance (aka,
Alec Mouri3e5965f2023-04-07 18:00:58 +0000525 // no-op any luminance changes).
526 // This is expected to only be meaningful for PQ content
Alec Mouri492c85c2021-11-19 15:58:10 -0800527 .contentMaxLuminance =
Alec Mouri1a3c5452022-03-04 22:44:51 +0000528 maxLuminance > 0 ? maxLuminance : maxDisplayLuminance,
Alec Mouri7a577452022-03-04 23:41:38 +0000529 .currentDisplayLuminance = currentDisplayLuminanceNits > 0
530 ? currentDisplayLuminanceNits
531 : maxDisplayLuminance,
Alec Mourifcedb9c2022-04-11 20:02:17 +0000532 .buffer = buffer,
533 .renderIntent = renderIntent};
Alec Mouri492c85c2021-11-19 15:58:10 -0800534
535 for (const auto uniform : tonemap::getToneMapper()->generateShaderSkSLUniforms(metadata)) {
536 uniforms.push_back(uniform);
537 }
538
539 return uniforms;
540}
541
Alec Mouri1a3c5452022-03-04 22:44:51 +0000542} // namespace android::shaders