Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 88acab97 authored by Alec Mouri's avatar Alec Mouri
Browse files

Dither HDR content when compositing to an 8-bit target

10-bit to 8-bit down-sampling produces unacceptable banding, especially
in low-luminance regions. This looks more acceptable.

Bug: 214319668
Test: Client composite an HDR test video which uses dark codes
Change-Id: If108ae43169882dc1051e2c370d4223bd75653f0
parent 91030925
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@
#include <gui/TraceUtils.h>
#include <sync/sync.h>
#include <ui/BlurRegion.h>
#include <ui/DataspaceUtils.h>
#include <ui/DebugUtils.h>
#include <ui/GraphicBuffer.h>
#include <utils/Trace.h>
@@ -1105,9 +1106,15 @@ void SkiaGLRenderEngine::drawLayersInternal(
                                                  .requiresLinearEffect = requiresLinearEffect,
                                                  .layerDimmingRatio = layerDimmingRatio}));

            // Turn on dithering when dimming beyond this threshold.
            // Turn on dithering when dimming beyond this (arbitrary) threshold...
            static constexpr float kDimmingThreshold = 0.2f;
            if (layerDimmingRatio <= kDimmingThreshold) {
            // ...or we're rendering an HDR layer down to an 8-bit target
            // Most HDR standards require at least 10-bits of color depth for source content, so we
            // can just extract the transfer function rather than dig into precise gralloc layout.
            // Furthermore, we can assume that the only 8-bit target we support is RGBA8888.
            const bool requiresDownsample = isHdrDataspace(layer.sourceDataspace) &&
                    buffer->getPixelFormat() == PIXEL_FORMAT_RGBA_8888;
            if (layerDimmingRatio <= kDimmingThreshold || requiresDownsample) {
                paint.setDither(true);
            }
            paint.setAlphaf(layer.alpha);