diff options
author | 2022-03-04 22:44:51 +0000 | |
---|---|---|
committer | 2022-03-17 17:54:17 +0000 | |
commit | 1a3c5456dd9e05642c3d0f388102c511e80b5108 (patch) | |
tree | d22652abd251e4be763ba8f21df8c486bd97c957 | |
parent | 63d679d2eb41ca10dedfb14487beae1b4c38319a (diff) |
Add AHardwareBuffer as a tone-mapping input.
This is to allow for partners to take gralloc4 metadata into account for
their tone-mapping operation.
Bug: 212641375
Test: builds
Change-Id: Id20291fc1a1a0350a7fff0a8e703f242c68d2b28
-rw-r--r-- | libs/renderengine/skia/SkiaGLRenderEngine.cpp | 6 | ||||
-rw-r--r-- | libs/renderengine/skia/filters/LinearEffect.cpp | 7 | ||||
-rw-r--r-- | libs/renderengine/skia/filters/LinearEffect.h | 5 | ||||
-rw-r--r-- | libs/shaders/Android.bp | 2 | ||||
-rw-r--r-- | libs/shaders/include/shaders/shaders.h | 3 | ||||
-rw-r--r-- | libs/shaders/shaders.cpp | 8 | ||||
-rw-r--r-- | libs/tonemap/Android.bp | 2 | ||||
-rw-r--r-- | libs/tonemap/include/tonemap/tonemap.h | 12 | ||||
-rw-r--r-- | libs/tonemap/tests/Android.bp | 1 |
9 files changed, 37 insertions, 9 deletions
diff --git a/libs/renderengine/skia/SkiaGLRenderEngine.cpp b/libs/renderengine/skia/SkiaGLRenderEngine.cpp index b467b3538d..5e5618b9aa 100644 --- a/libs/renderengine/skia/SkiaGLRenderEngine.cpp +++ b/libs/renderengine/skia/SkiaGLRenderEngine.cpp @@ -654,10 +654,14 @@ sk_sp<SkShader> SkiaGLRenderEngine::createRuntimeEffectShader( colorTransform *= mat4::scale(vec4(parameters.layerDimmingRatio, parameters.layerDimmingRatio, parameters.layerDimmingRatio, 1.f)); + const auto targetBuffer = parameters.layer.source.buffer.buffer; + const auto graphicBuffer = targetBuffer ? targetBuffer->getBuffer() : nullptr; + const auto hardwareBuffer = graphicBuffer ? graphicBuffer->toAHardwareBuffer() : nullptr; return createLinearEffectShader(parameters.shader, effect, runtimeEffect, colorTransform, parameters.display.maxLuminance, parameters.display.currentLuminanceNits, - parameters.layer.source.buffer.maxLuminanceNits); + parameters.layer.source.buffer.maxLuminanceNits, + hardwareBuffer); } return parameters.shader; } diff --git a/libs/renderengine/skia/filters/LinearEffect.cpp b/libs/renderengine/skia/filters/LinearEffect.cpp index a46329d9fc..d479606f2b 100644 --- a/libs/renderengine/skia/filters/LinearEffect.cpp +++ b/libs/renderengine/skia/filters/LinearEffect.cpp @@ -44,7 +44,8 @@ sk_sp<SkShader> createLinearEffectShader(sk_sp<SkShader> shader, const shaders::LinearEffect& linearEffect, sk_sp<SkRuntimeEffect> runtimeEffect, const mat4& colorTransform, float maxDisplayLuminance, - float currentDisplayLuminanceNits, float maxLuminance) { + float currentDisplayLuminanceNits, float maxLuminance, + AHardwareBuffer* buffer) { ATRACE_CALL(); SkRuntimeShaderBuilder effectBuilder(runtimeEffect); @@ -52,7 +53,7 @@ sk_sp<SkShader> createLinearEffectShader(sk_sp<SkShader> shader, const auto uniforms = shaders::buildLinearEffectUniforms(linearEffect, colorTransform, maxDisplayLuminance, - currentDisplayLuminanceNits, maxLuminance); + currentDisplayLuminanceNits, maxLuminance, buffer); for (const auto& uniform : uniforms) { effectBuilder.uniform(uniform.name.c_str()).set(uniform.value.data(), uniform.value.size()); @@ -63,4 +64,4 @@ sk_sp<SkShader> createLinearEffectShader(sk_sp<SkShader> shader, } // namespace skia } // namespace renderengine -} // namespace android
\ No newline at end of file +} // namespace android diff --git a/libs/renderengine/skia/filters/LinearEffect.h b/libs/renderengine/skia/filters/LinearEffect.h index e0a556b11a..26bae3b5f0 100644 --- a/libs/renderengine/skia/filters/LinearEffect.h +++ b/libs/renderengine/skia/filters/LinearEffect.h @@ -40,11 +40,14 @@ sk_sp<SkRuntimeEffect> buildRuntimeEffect(const shaders::LinearEffect& linearEff // * The current luminance of the physical display in nits // * The max luminance is provided as the max luminance for the buffer, either from the SMPTE 2086 // or as the max light level from the CTA 861.3 standard. +// * An AHardwareBuffer for implementations that support gralloc4 metadata for +// communicating any HDR metadata. sk_sp<SkShader> createLinearEffectShader(sk_sp<SkShader> inputShader, const shaders::LinearEffect& linearEffect, sk_sp<SkRuntimeEffect> runtimeEffect, const mat4& colorTransform, float maxDisplayLuminance, - float currentDisplayLuminanceNits, float maxLuminance); + float currentDisplayLuminanceNits, float maxLuminance, + AHardwareBuffer* buffer); } // namespace skia } // namespace renderengine } // namespace android diff --git a/libs/shaders/Android.bp b/libs/shaders/Android.bp index 1cd143e98d..2f8bf49c8a 100644 --- a/libs/shaders/Android.bp +++ b/libs/shaders/Android.bp @@ -30,9 +30,11 @@ cc_library_static { shared_libs: [ "android.hardware.graphics.common-V3-ndk", "android.hardware.graphics.common@1.2", + "libnativewindow", ], static_libs: [ + "libarect", "libmath", "libtonemap", "libui-types", diff --git a/libs/shaders/include/shaders/shaders.h b/libs/shaders/include/shaders/shaders.h index 43828ccd05..4ec7594901 100644 --- a/libs/shaders/include/shaders/shaders.h +++ b/libs/shaders/include/shaders/shaders.h @@ -101,6 +101,7 @@ std::vector<tonemap::ShaderUniform> buildLinearEffectUniforms(const LinearEffect const mat4& colorTransform, float maxDisplayLuminance, float currentDisplayLuminanceNits, - float maxLuminance); + float maxLuminance, + AHardwareBuffer* buffer = nullptr); } // namespace android::shaders diff --git a/libs/shaders/shaders.cpp b/libs/shaders/shaders.cpp index 03da3ecd62..0d77519ab7 100644 --- a/libs/shaders/shaders.cpp +++ b/libs/shaders/shaders.cpp @@ -476,7 +476,8 @@ std::vector<tonemap::ShaderUniform> buildLinearEffectUniforms(const LinearEffect const mat4& colorTransform, float maxDisplayLuminance, float currentDisplayLuminanceNits, - float maxLuminance) { + float maxLuminance, + AHardwareBuffer* buffer) { std::vector<tonemap::ShaderUniform> uniforms; if (linearEffect.inputDataspace == linearEffect.outputDataspace) { uniforms.push_back({.name = "in_rgbToXyz", .value = buildUniformValue<mat4>(mat4())}); @@ -504,7 +505,8 @@ std::vector<tonemap::ShaderUniform> buildLinearEffectUniforms(const LinearEffect // This will be the case for eg screenshots in addition to // uncalibrated displays .contentMaxLuminance = - maxLuminance > 0 ? maxLuminance : maxDisplayLuminance}; + maxLuminance > 0 ? maxLuminance : maxDisplayLuminance, + .buffer = buffer}; for (const auto uniform : tonemap::getToneMapper()->generateShaderSkSLUniforms(metadata)) { uniforms.push_back(uniform); @@ -513,4 +515,4 @@ std::vector<tonemap::ShaderUniform> buildLinearEffectUniforms(const LinearEffect return uniforms; } -} // namespace android::shaders
\ No newline at end of file +} // namespace android::shaders diff --git a/libs/tonemap/Android.bp b/libs/tonemap/Android.bp index 99d1b22717..dc55586a1d 100644 --- a/libs/tonemap/Android.bp +++ b/libs/tonemap/Android.bp @@ -30,9 +30,11 @@ cc_library_static { shared_libs: [ "android.hardware.graphics.common-V3-ndk", "liblog", + "libnativewindow", ], static_libs: [ + "libarect", "libmath", ], diff --git a/libs/tonemap/include/tonemap/tonemap.h b/libs/tonemap/include/tonemap/tonemap.h index 9fba642b31..e380323dd3 100644 --- a/libs/tonemap/include/tonemap/tonemap.h +++ b/libs/tonemap/include/tonemap/tonemap.h @@ -17,6 +17,7 @@ #pragma once #include <aidl/android/hardware/graphics/common/Dataspace.h> +#include <android/hardware_buffer.h> #include <math/vec3.h> #include <string> @@ -44,8 +45,19 @@ struct ShaderUniform { struct Metadata { // The maximum luminance of the display in nits float displayMaxLuminance = 0.0; + // The maximum luminance of the content in nits float contentMaxLuminance = 0.0; + + // Reference to an AHardwareBuffer. + // Devices that support gralloc 4.0 and higher may attach metadata onto a + // particular frame's buffer, including metadata used by HDR-standards like + // SMPTE 2086 or SMPTE 2094-40. + // Note that this parameter may be optional if there is no hardware buffer + // available, for instance if the source content is generated from a GL + // texture that does not have associated metadata. As such, implementations + // must support nullptr. + AHardwareBuffer* buffer = nullptr; }; // Utility class containing pre-processed conversions for a particular color diff --git a/libs/tonemap/tests/Android.bp b/libs/tonemap/tests/Android.bp index d519482fe3..26a1d79058 100644 --- a/libs/tonemap/tests/Android.bp +++ b/libs/tonemap/tests/Android.bp @@ -32,6 +32,7 @@ cc_test { ], shared_libs: [ "android.hardware.graphics.common-V3-ndk", + "libnativewindow", ], static_libs: [ "libmath", |