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

Commit 7808581c authored by Romain Guy's avatar Romain Guy Committed by Android (Google) Code Review
Browse files

Merge "Pre-multiply color components for 2-stop gradients Bug #7033344" into jb-mr1-dev

parents 8601e8b3 d679b57e
Loading
Loading
Loading
Loading
+13 −9
Original line number Diff line number Diff line
@@ -17625,23 +17625,27 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            // use use a height of 1, and then wack the matrix each time we
            // actually use it.
            shader = new LinearGradient(0, 0, 0, 1, 0xFF000000, 0, Shader.TileMode.CLAMP);
            paint.setShader(shader);
            paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
            this.host = host;
        }
        public void setFadeColor(int color) {
            if (color != 0 && color != mLastColor) {
            if (color != mLastColor) {
                mLastColor = color;
                color |= 0xFF000000;
                if (color != 0) {
                    shader = new LinearGradient(0, 0, 0, 1, color | 0xFF000000,
                            color & 0x00FFFFFF, Shader.TileMode.CLAMP);
                    paint.setShader(shader);
                    // Restore the default transfer mode (src_over)
                    paint.setXfermode(null);
                } else {
                    shader = new LinearGradient(0, 0, 0, 1, 0xFF000000, 0, Shader.TileMode.CLAMP);
                    paint.setShader(shader);
                    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
                }
            }
        }
+6 −4
Original line number Diff line number Diff line
@@ -217,10 +217,12 @@ void GradientCache::generateTexture(uint32_t* colors, float* positions,
        float amount = (pos - start) / distance;
        float oppAmount = 1.0f - amount;

        *p++ = uint8_t(startR * oppAmount + endR * amount);
        *p++ = uint8_t(startG * oppAmount + endG * amount);
        *p++ = uint8_t(startB * oppAmount + endB * amount);
        *p++ = uint8_t(startA * oppAmount + endA * amount);
        const float alpha = startA * oppAmount + endA * amount;
        const float a = alpha / 255.0f;
        *p++ = uint8_t(a * (startR * oppAmount + endR * amount));
        *p++ = uint8_t(a * (startG * oppAmount + endG * amount));
        *p++ = uint8_t(a * (startB * oppAmount + endB * amount));
        *p++ = uint8_t(alpha);
    }

    for (int i = 1; i < GRADIENT_TEXTURE_HEIGHT; i++) {
+5 −30
Original line number Diff line number Diff line
@@ -46,11 +46,12 @@ static inline bool isPowerOfTwo(unsigned int n) {
}

static inline void bindUniformColor(int slot, uint32_t color) {
    const float a = ((color >> 24) & 0xff) / 255.0f;
    glUniform4f(slot,
            ((color >> 16) & 0xff) / 255.0f,
            ((color >>  8) & 0xff) / 255.0f,
            ((color      ) & 0xff) / 255.0f,
            ((color >> 24) & 0xff) / 255.0f);
            a * ((color >> 16) & 0xff) / 255.0f,
            a * ((color >>  8) & 0xff) / 255.0f,
            a * ((color      ) & 0xff) / 255.0f,
            a);
}

///////////////////////////////////////////////////////////////////////////////
@@ -154,10 +155,6 @@ void SkiaBitmapShader::setupProgram(Program* program, const mat4& modelView,

    // Uniforms
    bindTexture(texture, mWrapS, mWrapT);
    // Assume linear here; we should really check the transform in
    // ::updateTransforms() but we don't have the texture object
    // available at that point. The optimization is not worth the
    // effort for now.
    texture->setFilter(GL_LINEAR);

    glUniform1i(program->getUniform("bitmapSampler"), textureSlot);
@@ -166,14 +163,6 @@ void SkiaBitmapShader::setupProgram(Program* program, const mat4& modelView,
    glUniform2f(program->getUniform("textureDimension"), 1.0f / width, 1.0f / height);
}

void SkiaBitmapShader::updateTransforms(Program* program, const mat4& modelView,
        const Snapshot& snapshot) {
    mat4 textureTransform;
    computeScreenSpaceMatrix(textureTransform, modelView);
    glUniformMatrix4fv(program->getUniform("textureTransform"), 1,
            GL_FALSE, &textureTransform.data[0]);
}

///////////////////////////////////////////////////////////////////////////////
// Linear gradient shader
///////////////////////////////////////////////////////////////////////////////
@@ -257,13 +246,6 @@ void SkiaLinearGradientShader::setupProgram(Program* program, const mat4& modelV
    glUniformMatrix4fv(program->getUniform("screenSpace"), 1, GL_FALSE, &screenSpace.data[0]);
}

void SkiaLinearGradientShader::updateTransforms(Program* program, const mat4& modelView,
        const Snapshot& snapshot) {
    mat4 screenSpace;
    computeScreenSpaceMatrix(screenSpace, modelView);
    glUniformMatrix4fv(program->getUniform("screenSpace"), 1, GL_FALSE, &screenSpace.data[0]);
}

///////////////////////////////////////////////////////////////////////////////
// Circular gradient shader
///////////////////////////////////////////////////////////////////////////////
@@ -384,13 +366,6 @@ void SkiaSweepGradientShader::setupProgram(Program* program, const mat4& modelVi
    glUniformMatrix4fv(program->getUniform("screenSpace"), 1, GL_FALSE, &screenSpace.data[0]);
}

void SkiaSweepGradientShader::updateTransforms(Program* program, const mat4& modelView,
        const Snapshot& snapshot) {
    mat4 screenSpace;
    computeScreenSpaceMatrix(screenSpace, modelView);
    glUniformMatrix4fv(program->getUniform("screenSpace"), 1, GL_FALSE, &screenSpace.data[0]);
}

///////////////////////////////////////////////////////////////////////////////
// Compose shader
///////////////////////////////////////////////////////////////////////////////
+0 −7
Original line number Diff line number Diff line
@@ -82,10 +82,6 @@ struct SkiaShader {
        mGradientCache = gradientCache;
    }

    virtual void updateTransforms(Program* program, const mat4& modelView,
            const Snapshot& snapshot) {
    }

    uint32_t getGenerationId() {
        return mGenerationId;
    }
@@ -148,7 +144,6 @@ struct SkiaBitmapShader: public SkiaShader {
    void describe(ProgramDescription& description, const Extensions& extensions);
    void setupProgram(Program* program, const mat4& modelView, const Snapshot& snapshot,
            GLuint* textureUnit);
    void updateTransforms(Program* program, const mat4& modelView, const Snapshot& snapshot);

private:
    SkiaBitmapShader() {
@@ -172,7 +167,6 @@ struct SkiaLinearGradientShader: public SkiaShader {
    void describe(ProgramDescription& description, const Extensions& extensions);
    void setupProgram(Program* program, const mat4& modelView, const Snapshot& snapshot,
            GLuint* textureUnit);
    void updateTransforms(Program* program, const mat4& modelView, const Snapshot& snapshot);

private:
    SkiaLinearGradientShader() {
@@ -197,7 +191,6 @@ struct SkiaSweepGradientShader: public SkiaShader {
    virtual void describe(ProgramDescription& description, const Extensions& extensions);
    void setupProgram(Program* program, const mat4& modelView, const Snapshot& snapshot,
            GLuint* textureUnit);
    void updateTransforms(Program* program, const mat4& modelView, const Snapshot& snapshot);

protected:
    SkiaSweepGradientShader(Type type, float x, float y, uint32_t* colors, float* positions,