diff options
author | 2022-11-04 01:32:24 +0000 | |
---|---|---|
committer | 2023-01-31 00:36:19 +0000 | |
commit | 9776d3e35718efd9ea08400fe0dbea61dc6386ce (patch) | |
tree | 19f4028f6ef2d32f9a8a945e0c1f2c8b4f88930e /libs/hwui/Tonemapper.cpp | |
parent | 397065c0f1c40b907c3fab6396d654c4a5b71341 (diff) |
Tonemap in RecordingCanvas
Intecepts bitmap calls to tonemap whenever the source is HDR (PQ/HLG)
and the destination is SDR.
Also, fix the following bugs discovered as part of testing:
1. Don't implicitly cast to booleans when extracting transfer functions
from a dataspace in hwui's tonemapper.
2. Fix some typos in defining the HLG/PQ transfer functions.
Bug: 261088450
Test: New ColorBitmapActivity in HwAccelerationTest
Change-Id: I9d9d68fc4f57b999b3c6d4156bef281b4409f37e
Diffstat (limited to 'libs/hwui/Tonemapper.cpp')
-rw-r--r-- | libs/hwui/Tonemapper.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/libs/hwui/Tonemapper.cpp b/libs/hwui/Tonemapper.cpp index a7e76b631140..0d39f0e33298 100644 --- a/libs/hwui/Tonemapper.cpp +++ b/libs/hwui/Tonemapper.cpp @@ -18,7 +18,10 @@ #include <SkRuntimeEffect.h> #include <log/log.h> +// libshaders only exists on Android devices +#ifdef __ANDROID__ #include <shaders/shaders.h> +#endif #include "utils/Color.h" @@ -26,6 +29,8 @@ namespace android::uirenderer { namespace { +// custom tonemapping only exists on Android devices +#ifdef __ANDROID__ class ColorFilterRuntimeEffectBuilder : public SkRuntimeEffectBuilder { public: explicit ColorFilterRuntimeEffectBuilder(sk_sp<SkRuntimeEffect> effect) @@ -59,20 +64,21 @@ static sk_sp<SkColorFilter> createLinearEffectColorFilter(const shaders::LinearE return effectBuilder.makeColorFilter(); } -static bool extractTransfer(ui::Dataspace dataspace) { - return dataspace & HAL_DATASPACE_TRANSFER_MASK; +static ui::Dataspace extractTransfer(ui::Dataspace dataspace) { + return static_cast<ui::Dataspace>(dataspace & HAL_DATASPACE_TRANSFER_MASK); } static bool isHdrDataspace(ui::Dataspace dataspace) { const auto transfer = extractTransfer(dataspace); - return transfer == HAL_DATASPACE_TRANSFER_ST2084 || transfer == HAL_DATASPACE_TRANSFER_HLG; + return transfer == ui::Dataspace::TRANSFER_ST2084 || transfer == ui::Dataspace::TRANSFER_HLG; } static ui::Dataspace getDataspace(const SkImageInfo& image) { return static_cast<ui::Dataspace>( ColorSpaceToADataSpace(image.colorSpace(), image.colorType())); } +#endif } // namespace @@ -80,6 +86,8 @@ static ui::Dataspace getDataspace(const SkImageInfo& image) { // shader and tag it on the supplied paint. void tonemapPaint(const SkImageInfo& source, const SkImageInfo& destination, float maxLuminanceNits, SkPaint& paint) { +// custom tonemapping only exists on Android devices +#ifdef __ANDROID__ const auto sourceDataspace = getDataspace(source); const auto destinationDataspace = getDataspace(destination); @@ -102,6 +110,9 @@ void tonemapPaint(const SkImageInfo& source, const SkImageInfo& destination, flo paint.setColorFilter(colorFilter); } } +#else + return; +#endif } } // namespace android::uirenderer |