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

Commit 013beadd authored by Alec Mouri's avatar Alec Mouri Committed by Android (Google) Code Review
Browse files

Merge "Fix extended range handling when Gamma OETF is used" into main

parents 2063dd5d e0bb6f4f
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;
@@ -907,12 +908,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
@@ -1019,7 +1022,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;
@@ -1083,7 +1087,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));
        }
    )");
}