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

Commit e0bb6f4f authored by Alec Mouri's avatar Alec Mouri
Browse files

Fix extended range handling when Gamma OETF is used

Populating fakeOutputDataspace got dropped, which turned off the one-off
workaround to bypass skia's color management to encode as gamma 2.2.

Turn it back on to prevent flickers on some devices.

Bug: 293311643
Test: SilkFX test app
Change-Id: I4370756c48fe79c1b4fcbd88a3bf2579fde1bf65
parent 88790f34
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -511,7 +511,8 @@ sk_sp<SkShader> SkiaRenderEngine::createRuntimeEffectShader(
        auto effect =
                shaders::LinearEffect{.inputDataspace = parameters.layer.sourceDataspace,
                                      .outputDataspace = parameters.outputDataSpace,
                                      .undoPremultipliedAlpha = parameters.undoPremultipliedAlpha};
                                      .undoPremultipliedAlpha = parameters.undoPremultipliedAlpha,
                                      .fakeOutputDataspace = parameters.fakeOutputDataspace};

        auto effectIter = mRuntimeEffects.find(effect);
        sk_sp<SkRuntimeEffect> runtimeEffect = nullptr;
@@ -892,12 +893,14 @@ void SkiaRenderEngine::drawLayersInternal(
                (display.outputDataspace & ui::Dataspace::TRANSFER_MASK) ==
                        static_cast<int32_t>(ui::Dataspace::TRANSFER_SRGB);

        const ui::Dataspace runtimeEffectDataspace = !dimInLinearSpace && isExtendedHdr
        const bool useFakeOutputDataspaceForRuntimeEffect = !dimInLinearSpace && isExtendedHdr;

        const ui::Dataspace fakeDataspace = useFakeOutputDataspaceForRuntimeEffect
                ? static_cast<ui::Dataspace>(
                          (display.outputDataspace & ui::Dataspace::STANDARD_MASK) |
                          ui::Dataspace::TRANSFER_GAMMA2_2 |
                          (display.outputDataspace & ui::Dataspace::RANGE_MASK))
                : display.outputDataspace;
                : ui::Dataspace::UNKNOWN;

        // If the input dataspace is range extended, the output dataspace transfer is sRGB
        // and dimmingStage is GAMMA_OETF, dim in linear space instead, and
@@ -1004,7 +1007,8 @@ void SkiaRenderEngine::drawLayersInternal(
                                                  .layerDimmingRatio = dimInLinearSpace
                                                          ? layerDimmingRatio
                                                          : 1.f,
                                                  .outputDataSpace = runtimeEffectDataspace}));
                                                  .outputDataSpace = display.outputDataspace,
                                                  .fakeOutputDataspace = fakeDataspace}));

            // Turn on dithering when dimming beyond this (arbitrary) threshold...
            static constexpr float kDimmingThreshold = 0.2f;
@@ -1068,7 +1072,8 @@ void SkiaRenderEngine::drawLayersInternal(
                                                  .undoPremultipliedAlpha = false,
                                                  .requiresLinearEffect = requiresLinearEffect,
                                                  .layerDimmingRatio = layerDimmingRatio,
                                                  .outputDataSpace = runtimeEffectDataspace}));
                                                  .outputDataSpace = display.outputDataspace,
                                                  .fakeOutputDataspace = fakeDataspace}));
        }

        if (layer.disableBlending) {
+1 −0
Original line number Diff line number Diff line
@@ -157,6 +157,7 @@ private:
        bool requiresLinearEffect;
        float layerDimmingRatio;
        const ui::Dataspace outputDataSpace;
        const ui::Dataspace fakeOutputDataspace;
    };
    sk_sp<SkShader> createRuntimeEffectShader(const RuntimeEffectShaderParameters&);

+2 −2
Original line number Diff line number Diff line
@@ -168,8 +168,8 @@ void generateOOTF(ui::Dataspace inputDataspace, ui::Dataspace outputDataspace,
void generateOETF(std::string& shader) {
    // Only support gamma 2.2 for now
    shader.append(R"(
        float OETF(float3 linear) {
            return sign(linear) * pow(abs(linear), (1.0 / 2.2));
        float3 OETF(float3 linear) {
            return sign(linear) * pow(abs(linear), float3(1.0 / 2.2));
        }
    )");
}