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

Commit e56b3760 authored by Chris Craik's avatar Chris Craik Committed by Android (Google) Code Review
Browse files

Merge "Remove shader based gamma approach"

parents 37386768 11718bc1
Loading
Loading
Loading
Loading
+0 −48
Original line number Diff line number Diff line
@@ -43,10 +43,6 @@ GammaFontRenderer* GammaFontRenderer::createRenderer() {
    if (property_get(PROPERTY_TEXT_GAMMA_METHOD, property, DEFAULT_TEXT_GAMMA_METHOD) > 0) {
        if (!strcasecmp(property, "lookup")) {
            return new LookupGammaFontRenderer();
        } else if (!strcasecmp(property, "shader")) {
            return new ShaderGammaFontRenderer(false);
        } else if (!strcasecmp(property, "shader3")) {
            return new ShaderGammaFontRenderer(true);
        }
    }

@@ -90,50 +86,6 @@ GammaFontRenderer::GammaFontRenderer() {
GammaFontRenderer::~GammaFontRenderer() {
}

///////////////////////////////////////////////////////////////////////////////
// Shader-based renderer
///////////////////////////////////////////////////////////////////////////////

ShaderGammaFontRenderer::ShaderGammaFontRenderer(bool multiGamma)
        : GammaFontRenderer() {
    INIT_LOGD("Creating shader gamma font renderer");
    mRenderer = nullptr;
    mMultiGamma = multiGamma;
}

void ShaderGammaFontRenderer::describe(ProgramDescription& description,
        const SkPaint* paint) const {
    if (paint->getShader() == nullptr) {
        if (mMultiGamma) {
            const int l = luminance(paint);

            if (l <= mBlackThreshold) {
                description.hasGammaCorrection = true;
                description.gamma = mGamma;
            } else if (l >= mWhiteThreshold) {
                description.hasGammaCorrection = true;
                description.gamma = 1.0f / mGamma;
            }
        } else {
            description.hasGammaCorrection = true;
            description.gamma = 1.0f / mGamma;
        }
    }
}

void ShaderGammaFontRenderer::setupProgram(ProgramDescription& description,
        Program& program) const {
    if (description.hasGammaCorrection) {
        glUniform1f(program.getUniform("gamma"), description.gamma);
    }
}

void ShaderGammaFontRenderer::endPrecaching() {
    if (mRenderer) {
        mRenderer->endPrecaching();
    }
}

///////////////////////////////////////////////////////////////////////////////
// Lookup-based renderer
///////////////////////////////////////////////////////////////////////////////
+0 −61
Original line number Diff line number Diff line
@@ -37,9 +37,6 @@ public:
    virtual uint32_t getFontRendererCount() const = 0;
    virtual uint32_t getFontRendererSize(uint32_t fontRenderer, GLenum format) const = 0;

    virtual void describe(ProgramDescription& description, const SkPaint* paint) const = 0;
    virtual void setupProgram(ProgramDescription& description, Program& program) const = 0;

    virtual void endPrecaching() = 0;

    static GammaFontRenderer* createRenderer();
@@ -53,52 +50,6 @@ protected:
    float mGamma;
};

class ShaderGammaFontRenderer: public GammaFontRenderer {
public:
    ~ShaderGammaFontRenderer() {
        delete mRenderer;
    }

    void clear() override {
        delete mRenderer;
        mRenderer = nullptr;
    }

    void flush() override {
        if (mRenderer) {
            mRenderer->flushLargeCaches();
        }
    }

    FontRenderer& getFontRenderer(const SkPaint* paint) override {
        if (!mRenderer) {
            mRenderer = new FontRenderer;
        }
        return *mRenderer;
    }

    uint32_t getFontRendererCount() const override {
        return 1;
    }

    uint32_t getFontRendererSize(uint32_t fontRenderer, GLenum format) const override {
        return mRenderer ? mRenderer->getCacheSize(format) : 0;
    }

    void describe(ProgramDescription& description, const SkPaint* paint) const override;
    void setupProgram(ProgramDescription& description, Program& program) const override;

    void endPrecaching() override;

private:
    ShaderGammaFontRenderer(bool multiGamma);

    FontRenderer* mRenderer;
    bool mMultiGamma;

    friend class GammaFontRenderer;
};

class LookupGammaFontRenderer: public GammaFontRenderer {
public:
    ~LookupGammaFontRenderer() {
@@ -132,12 +83,6 @@ public:
        return mRenderer ? mRenderer->getCacheSize(format) : 0;
    }

    void describe(ProgramDescription& description, const SkPaint* paint) const override {
    }

    void setupProgram(ProgramDescription& description, Program& program) const override {
    }

    void endPrecaching() override;

private:
@@ -168,12 +113,6 @@ public:
        return mRenderers[fontRenderer]->getCacheSize(format);
    }

    void describe(ProgramDescription& description, const SkPaint* paint) const override {
    }

    void setupProgram(ProgramDescription& description, Program& program) const override {
    }

    void endPrecaching() override;

private:
+2 −2
Original line number Diff line number Diff line
@@ -138,10 +138,10 @@ PathCache::PathCache():
        mSize(0), mMaxSize(MB(DEFAULT_PATH_CACHE_SIZE)) {
    char property[PROPERTY_VALUE_MAX];
    if (property_get(PROPERTY_PATH_CACHE_SIZE, property, nullptr) > 0) {
        INIT_LOGD("  Setting %s cache size to %sMB", name, property);
        INIT_LOGD("  Setting path cache size to %sMB", property);
        mMaxSize = MB(atof(property));
    } else {
        INIT_LOGD("  Using default %s cache size of %.2fMB", name, DEFAULT_PATH_CACHE_SIZE);
        INIT_LOGD("  Using default path cache size of %.2fMB", DEFAULT_PATH_CACHE_SIZE);
    }

    mCache.setOnEntryRemovedListener(this);
+4 −13
Original line number Diff line number Diff line
@@ -78,14 +78,12 @@ namespace uirenderer {
#define PROGRAM_HAS_EXTERNAL_TEXTURE_SHIFT 38
#define PROGRAM_HAS_TEXTURE_TRANSFORM_SHIFT 39

#define PROGRAM_HAS_GAMMA_CORRECTION 40
#define PROGRAM_IS_SIMPLE_GRADIENT 40

#define PROGRAM_IS_SIMPLE_GRADIENT 41
#define PROGRAM_HAS_COLORS 41

#define PROGRAM_HAS_COLORS 42

#define PROGRAM_HAS_DEBUG_HIGHLIGHT 43
#define PROGRAM_HAS_ROUND_RECT_CLIP 44
#define PROGRAM_HAS_DEBUG_HIGHLIGHT 42
#define PROGRAM_HAS_ROUND_RECT_CLIP 43

///////////////////////////////////////////////////////////////////////////////
// Types
@@ -157,9 +155,6 @@ struct ProgramDescription {
    SkXfermode::Mode framebufferMode;
    bool swapSrcDst;

    bool hasGammaCorrection;
    float gamma;

    bool hasDebugHighlight;
    bool hasRoundRectClip;

@@ -199,9 +194,6 @@ struct ProgramDescription {
        framebufferMode = SkXfermode::kClear_Mode;
        swapSrcDst = false;

        hasGammaCorrection = false;
        gamma = 2.2f;

        hasDebugHighlight = false;
        hasRoundRectClip = false;
    }
@@ -266,7 +258,6 @@ struct ProgramDescription {
        if (useShadowAlphaInterp) key |= programid(0x1) << PROGRAM_USE_SHADOW_ALPHA_INTERP_SHIFT;
        if (hasExternalTexture) key |= programid(0x1) << PROGRAM_HAS_EXTERNAL_TEXTURE_SHIFT;
        if (hasTextureTransform) key |= programid(0x1) << PROGRAM_HAS_TEXTURE_TRANSFORM_SHIFT;
        if (hasGammaCorrection) key |= programid(0x1) << PROGRAM_HAS_GAMMA_CORRECTION;
        if (isSimpleGradient) key |= programid(0x1) << PROGRAM_IS_SIMPLE_GRADIENT;
        if (hasColors) key |= programid(0x1) << PROGRAM_HAS_COLORS;
        if (hasDebugHighlight) key |= programid(0x1) << PROGRAM_HAS_DEBUG_HIGHLIGHT;
+7 −41
Original line number Diff line number Diff line
@@ -167,8 +167,6 @@ const char* gFS_Uniforms_ColorOp[3] = {
        // PorterDuff
        "uniform vec4 colorBlend;\n"
};
const char* gFS_Uniforms_Gamma =
        "uniform float gamma;\n";

const char* gFS_Uniforms_HasRoundRectClip =
        "uniform vec4 roundRectInnerRectLTRB;\n"
@@ -204,18 +202,10 @@ const char* gFS_Fast_SingleA8Texture =
        "\nvoid main(void) {\n"
        "    gl_FragColor = texture2D(baseSampler, outTexCoords);\n"
        "}\n\n";
const char* gFS_Fast_SingleA8Texture_ApplyGamma =
        "\nvoid main(void) {\n"
        "    gl_FragColor = vec4(0.0, 0.0, 0.0, pow(texture2D(baseSampler, outTexCoords).a, gamma));\n"
        "}\n\n";
const char* gFS_Fast_SingleModulateA8Texture =
        "\nvoid main(void) {\n"
        "    gl_FragColor = color * texture2D(baseSampler, outTexCoords).a;\n"
        "}\n\n";
const char* gFS_Fast_SingleModulateA8Texture_ApplyGamma =
        "\nvoid main(void) {\n"
        "    gl_FragColor = color * pow(texture2D(baseSampler, outTexCoords).a, gamma);\n"
        "}\n\n";
const char* gFS_Fast_SingleGradient[2] = {
        "\nvoid main(void) {\n"
        "    gl_FragColor = %s + texture2D(gradientSampler, linear);\n"
@@ -250,13 +240,11 @@ const char* gFS_Main_FetchTexture[2] = {
        // Modulate
        "    fragColor = color * texture2D(baseSampler, outTexCoords);\n"
};
const char* gFS_Main_FetchA8Texture[4] = {
const char* gFS_Main_FetchA8Texture[2] = {
        // Don't modulate
        "    fragColor = texture2D(baseSampler, outTexCoords);\n",
        "    fragColor = texture2D(baseSampler, outTexCoords);\n",
        // Modulate
        "    fragColor = color * texture2D(baseSampler, outTexCoords).a;\n",
        "    fragColor = color * pow(texture2D(baseSampler, outTexCoords).a, gamma);\n"
};
const char* gFS_Main_FetchGradient[6] = {
        // Linear
@@ -284,38 +272,29 @@ const char* gFS_Main_BlendShadersBG =
        "    fragColor = blendShaders(gradientColor, bitmapColor)";
const char* gFS_Main_BlendShadersGB =
        "    fragColor = blendShaders(bitmapColor, gradientColor)";
const char* gFS_Main_BlendShaders_Modulate[6] = {
const char* gFS_Main_BlendShaders_Modulate[3] = {
        // Don't modulate
        ";\n",
        ";\n",
        // Modulate
        " * color.a;\n",
        " * color.a;\n",
        // Modulate with alpha 8 texture
        " * texture2D(baseSampler, outTexCoords).a;\n",
        " * pow(texture2D(baseSampler, outTexCoords).a, gamma);\n"
};
const char* gFS_Main_GradientShader_Modulate[6] = {
const char* gFS_Main_GradientShader_Modulate[3] = {
        // Don't modulate
        "    fragColor = gradientColor;\n",
        "    fragColor = gradientColor;\n",
        // Modulate
        "    fragColor = gradientColor * color.a;\n",
        "    fragColor = gradientColor * color.a;\n",
        // Modulate with alpha 8 texture
        "    fragColor = gradientColor * texture2D(baseSampler, outTexCoords).a;\n",
        "    fragColor = gradientColor * pow(texture2D(baseSampler, outTexCoords).a, gamma);\n"
    };
const char* gFS_Main_BitmapShader_Modulate[6] = {
const char* gFS_Main_BitmapShader_Modulate[3] = {
        // Don't modulate
        "    fragColor = bitmapColor;\n",
        "    fragColor = bitmapColor;\n",
        // Modulate
        "    fragColor = bitmapColor * color.a;\n",
        "    fragColor = bitmapColor * color.a;\n",
        // Modulate with alpha 8 texture
        "    fragColor = bitmapColor * texture2D(baseSampler, outTexCoords).a;\n",
        "    fragColor = bitmapColor * pow(texture2D(baseSampler, outTexCoords).a, gamma);\n"
    };
const char* gFS_Main_FragColor =
        "    gl_FragColor = fragColor;\n";
@@ -540,7 +519,6 @@ String8 ProgramCache::generateVertexShader(const ProgramDescription& description
static bool shaderOp(const ProgramDescription& description, String8& shader,
        const int modulateOp, const char** snippets) {
    int op = description.hasAlpha8Texture ? MODULATE_OP_MODULATE_A8 : modulateOp;
    op = op * 2 + description.hasGammaCorrection;
    shader.append(snippets[op]);
    return description.hasAlpha8Texture;
}
@@ -596,9 +574,6 @@ String8 ProgramCache::generateFragmentShader(const ProgramDescription& descripti
        shader.appendFormat(gFS_Uniforms_GradientSampler[description.isSimpleGradient],
                gFS_Uniforms_Dither);
    }
    if (description.hasGammaCorrection) {
        shader.append(gFS_Uniforms_Gamma);
    }
    if (description.hasRoundRectClip) {
        shader.append(gFS_Uniforms_HasRoundRectClip);
    }
@@ -633,18 +608,10 @@ String8 ProgramCache::generateFragmentShader(const ProgramDescription& descripti
            fast = true;
        } else if (singleA8Texture) {
            if (!description.modulate) {
                if (description.hasGammaCorrection) {
                    shader.append(gFS_Fast_SingleA8Texture_ApplyGamma);
                } else {
                shader.append(gFS_Fast_SingleA8Texture);
                }
            } else {
                if (description.hasGammaCorrection) {
                    shader.append(gFS_Fast_SingleModulateA8Texture_ApplyGamma);
            } else {
                shader.append(gFS_Fast_SingleModulateA8Texture);
            }
            }
            fast = true;
        } else if (singleGradient) {
            if (!description.modulate) {
@@ -693,8 +660,7 @@ String8 ProgramCache::generateFragmentShader(const ProgramDescription& descripti
        if (description.hasTexture || description.hasExternalTexture) {
            if (description.hasAlpha8Texture) {
                if (!description.hasGradient && !description.hasBitmap) {
                    shader.append(gFS_Main_FetchA8Texture[modulateOp * 2 +
                                                          description.hasGammaCorrection]);
                    shader.append(gFS_Main_FetchA8Texture[modulateOp]);
                }
            } else {
                shader.append(gFS_Main_FetchTexture[modulateOp]);
Loading