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

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

Merge "Optimize away unnecessary state changes"

parents a791894f d21b6e1f
Loading
Loading
Loading
Loading
+4 −4
Original line number Original line Diff line number Diff line
@@ -147,12 +147,12 @@ struct Layer {
        this->renderTarget = renderTarget;
        this->renderTarget = renderTarget;
    }
    }


    void setWrap(GLenum wrapS, GLenum wrapT, bool bindTexture = false, bool force = false) {
    void setWrap(GLenum wrap, bool bindTexture = false, bool force = false) {
        texture.setWrap(wrapS, wrapT, bindTexture, force, renderTarget);
        texture.setWrap(wrap, bindTexture, force, renderTarget);
    }
    }


    void setFilter(GLenum min, GLenum mag, bool bindTexture = false, bool force = false) {
    void setFilter(GLenum filter, bool bindTexture = false, bool force = false) {
        texture.setFilter(min, mag,bindTexture, force, renderTarget);
        texture.setFilter(filter, bindTexture, force, renderTarget);
    }
    }


    inline bool isCacheable() {
    inline bool isCacheable() {
+2 −2
Original line number Original line Diff line number Diff line
@@ -294,8 +294,8 @@ void LayerRenderer::updateTextureLayer(Layer* layer, uint32_t width, uint32_t he
        if (renderTarget != layer->getRenderTarget()) {
        if (renderTarget != layer->getRenderTarget()) {
            layer->setRenderTarget(renderTarget);
            layer->setRenderTarget(renderTarget);
            layer->bindTexture();
            layer->bindTexture();
            layer->setFilter(GL_NEAREST, GL_NEAREST, false, true);
            layer->setFilter(GL_NEAREST, false, true);
            layer->setWrap(GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, false, true);
            layer->setWrap(GL_CLAMP_TO_EDGE, false, true);
        }
        }
    }
    }
}
}
+26 −22
Original line number Original line Diff line number Diff line
@@ -47,6 +47,8 @@ namespace uirenderer {
// TODO: This should be set in properties
// TODO: This should be set in properties
#define ALPHA_THRESHOLD (0x7f / PANEL_BIT_DEPTH)
#define ALPHA_THRESHOLD (0x7f / PANEL_BIT_DEPTH)


#define FILTER(paint) (paint && paint->isFilterBitmap() ? GL_LINEAR : GL_NEAREST)

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Globals
// Globals
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
@@ -665,10 +667,10 @@ void OpenGLRenderer::drawTextureLayer(Layer* layer, const Rect& rect) {
        const float x = (int) floorf(rect.left + mSnapshot->transform->getTranslateX() + 0.5f);
        const float x = (int) floorf(rect.left + mSnapshot->transform->getTranslateX() + 0.5f);
        const float y = (int) floorf(rect.top + mSnapshot->transform->getTranslateY() + 0.5f);
        const float y = (int) floorf(rect.top + mSnapshot->transform->getTranslateY() + 0.5f);


        layer->setFilter(GL_NEAREST, GL_NEAREST);
        layer->setFilter(GL_NEAREST);
        setupDrawModelView(x, y, x + rect.getWidth(), y + rect.getHeight(), true);
        setupDrawModelView(x, y, x + rect.getWidth(), y + rect.getHeight(), true);
    } else {
    } else {
        layer->setFilter(GL_LINEAR, GL_LINEAR);
        layer->setFilter(GL_LINEAR);
        setupDrawModelView(rect.left, rect.top, rect.right, rect.bottom);
        setupDrawModelView(rect.left, rect.top, rect.right, rect.bottom);
    }
    }
    setupDrawTextureTransformUniforms(layer->getTexTransform());
    setupDrawTextureTransformUniforms(layer->getTexTransform());
@@ -702,9 +704,9 @@ void OpenGLRenderer::composeLayerRect(Layer* layer, const Rect& rect, bool swap)
                y = (int) floorf(rect.top + mSnapshot->transform->getTranslateY() + 0.5f);
                y = (int) floorf(rect.top + mSnapshot->transform->getTranslateY() + 0.5f);
            }
            }


            layer->setFilter(GL_NEAREST, GL_NEAREST, true);
            layer->setFilter(GL_NEAREST, true);
        } else {
        } else {
            layer->setFilter(GL_LINEAR, GL_LINEAR, true);
            layer->setFilter(GL_LINEAR, true);
        }
        }


        drawTextureMesh(x, y, x + rect.getWidth(), y + rect.getHeight(),
        drawTextureMesh(x, y, x + rect.getWidth(), y + rect.getHeight(),
@@ -760,10 +762,10 @@ void OpenGLRenderer::composeLayerRegion(Layer* layer, const Rect& rect) {
            const float x = (int) floorf(rect.left + mSnapshot->transform->getTranslateX() + 0.5f);
            const float x = (int) floorf(rect.left + mSnapshot->transform->getTranslateX() + 0.5f);
            const float y = (int) floorf(rect.top + mSnapshot->transform->getTranslateY() + 0.5f);
            const float y = (int) floorf(rect.top + mSnapshot->transform->getTranslateY() + 0.5f);


            layer->setFilter(GL_NEAREST, GL_NEAREST);
            layer->setFilter(GL_NEAREST);
            setupDrawModelViewTranslate(x, y, x + rect.getWidth(), y + rect.getHeight(), true);
            setupDrawModelViewTranslate(x, y, x + rect.getWidth(), y + rect.getHeight(), true);
        } else {
        } else {
            layer->setFilter(GL_LINEAR, GL_LINEAR);
            layer->setFilter(GL_LINEAR);
            setupDrawModelViewTranslate(rect.left, rect.top, rect.right, rect.bottom);
            setupDrawModelViewTranslate(rect.left, rect.top, rect.right, rect.bottom);
        }
        }
        setupDrawMesh(&mesh[0].position[0], &mesh[0].texture[0]);
        setupDrawMesh(&mesh[0].position[0], &mesh[0].texture[0]);
@@ -1320,6 +1322,8 @@ void OpenGLRenderer::drawAlphaBitmap(Texture* texture, float left, float top, Sk
        y = (int) floorf(top + mSnapshot->transform->getTranslateY() + 0.5f);
        y = (int) floorf(top + mSnapshot->transform->getTranslateY() + 0.5f);
        ignoreTransform = true;
        ignoreTransform = true;
        filter = GL_NEAREST;
        filter = GL_NEAREST;
    } else {
        filter = FILTER(paint);
    }
    }


    setupDraw();
    setupDraw();
@@ -1334,8 +1338,8 @@ void OpenGLRenderer::drawAlphaBitmap(Texture* texture, float left, float top, Sk
    setupDrawModelView(x, y, x + texture->width, y + texture->height, ignoreTransform);
    setupDrawModelView(x, y, x + texture->width, y + texture->height, ignoreTransform);


    setupDrawTexture(texture->id);
    setupDrawTexture(texture->id);
    texture->setWrap(GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
    texture->setWrap(GL_CLAMP_TO_EDGE);
    texture->setFilter(filter, filter);
    texture->setFilter(filter);


    setupDrawPureColorUniforms();
    setupDrawPureColorUniforms();
    setupDrawColorFilterUniforms();
    setupDrawColorFilterUniforms();
@@ -1401,8 +1405,8 @@ void OpenGLRenderer::drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHei
    if (!texture) return;
    if (!texture) return;
    const AutoTexture autoCleanup(texture);
    const AutoTexture autoCleanup(texture);


    texture->setWrap(GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, true);
    texture->setWrap(GL_CLAMP_TO_EDGE, true);
    texture->setFilter(GL_LINEAR, GL_LINEAR, true);
    texture->setFilter(FILTER(paint), true);


    int alpha;
    int alpha;
    SkXfermode::Mode mode;
    SkXfermode::Mode mode;
@@ -1485,7 +1489,6 @@ void OpenGLRenderer::drawBitmap(SkBitmap* bitmap,
    Texture* texture = mCaches.textureCache.get(bitmap);
    Texture* texture = mCaches.textureCache.get(bitmap);
    if (!texture) return;
    if (!texture) return;
    const AutoTexture autoCleanup(texture);
    const AutoTexture autoCleanup(texture);
    texture->setWrap(GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, true);


    const float width = texture->width;
    const float width = texture->width;
    const float height = texture->height;
    const float height = texture->height;
@@ -1502,6 +1505,8 @@ void OpenGLRenderer::drawBitmap(SkBitmap* bitmap,
    SkXfermode::Mode mode;
    SkXfermode::Mode mode;
    getAlphaAndMode(paint, &alpha, &mode);
    getAlphaAndMode(paint, &alpha, &mode);


    texture->setWrap(GL_CLAMP_TO_EDGE, true);

    if (mSnapshot->transform->isPureTranslate()) {
    if (mSnapshot->transform->isPureTranslate()) {
        const float x = (int) floorf(dstLeft + mSnapshot->transform->getTranslateX() + 0.5f);
        const float x = (int) floorf(dstLeft + mSnapshot->transform->getTranslateX() + 0.5f);
        const float y = (int) floorf(dstTop + mSnapshot->transform->getTranslateY() + 0.5f);
        const float y = (int) floorf(dstTop + mSnapshot->transform->getTranslateY() + 0.5f);
@@ -1509,17 +1514,16 @@ void OpenGLRenderer::drawBitmap(SkBitmap* bitmap,
        GLenum filter = GL_NEAREST;
        GLenum filter = GL_NEAREST;
        // Enable linear filtering if the source rectangle is scaled
        // Enable linear filtering if the source rectangle is scaled
        if (srcRight - srcLeft != dstRight - dstLeft || srcBottom - srcTop != dstBottom - dstTop) {
        if (srcRight - srcLeft != dstRight - dstLeft || srcBottom - srcTop != dstBottom - dstTop) {
            filter = GL_LINEAR;
            filter = FILTER(paint);
        }
        }
        texture->setFilter(filter, filter, true);


        texture->setFilter(filter, true);
        drawTextureMesh(x, y, x + (dstRight - dstLeft), y + (dstBottom - dstTop),
        drawTextureMesh(x, y, x + (dstRight - dstLeft), y + (dstBottom - dstTop),
                texture->id, alpha / 255.0f, mode, texture->blend,
                texture->id, alpha / 255.0f, mode, texture->blend,
                &mMeshVertices[0].position[0], &mMeshVertices[0].texture[0],
                &mMeshVertices[0].position[0], &mMeshVertices[0].texture[0],
                GL_TRIANGLE_STRIP, gMeshCount, false, true);
                GL_TRIANGLE_STRIP, gMeshCount, false, true);
    } else {
    } else {
        texture->setFilter(GL_LINEAR, GL_LINEAR, true);
        texture->setFilter(FILTER(paint), true);

        drawTextureMesh(dstLeft, dstTop, dstRight, dstBottom, texture->id, alpha / 255.0f,
        drawTextureMesh(dstLeft, dstTop, dstRight, dstBottom, texture->id, alpha / 255.0f,
                mode, texture->blend, &mMeshVertices[0].position[0], &mMeshVertices[0].texture[0],
                mode, texture->blend, &mMeshVertices[0].position[0], &mMeshVertices[0].texture[0],
                GL_TRIANGLE_STRIP, gMeshCount);
                GL_TRIANGLE_STRIP, gMeshCount);
@@ -1539,8 +1543,8 @@ void OpenGLRenderer::drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int
    Texture* texture = mCaches.textureCache.get(bitmap);
    Texture* texture = mCaches.textureCache.get(bitmap);
    if (!texture) return;
    if (!texture) return;
    const AutoTexture autoCleanup(texture);
    const AutoTexture autoCleanup(texture);
    texture->setWrap(GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, true);
    texture->setWrap(GL_CLAMP_TO_EDGE, true);
    texture->setFilter(GL_LINEAR, GL_LINEAR, true);
    texture->setFilter(GL_LINEAR, true);


    int alpha;
    int alpha;
    SkXfermode::Mode mode;
    SkXfermode::Mode mode;
@@ -2250,11 +2254,11 @@ void OpenGLRenderer::drawLayer(Layer* layer, float x, float y, SkPaint* paint) {
                x = (int) floorf(x + mSnapshot->transform->getTranslateX() + 0.5f);
                x = (int) floorf(x + mSnapshot->transform->getTranslateX() + 0.5f);
                y = (int) floorf(y + mSnapshot->transform->getTranslateY() + 0.5f);
                y = (int) floorf(y + mSnapshot->transform->getTranslateY() + 0.5f);


                layer->setFilter(GL_NEAREST, GL_NEAREST);
                layer->setFilter(GL_NEAREST);
                setupDrawModelViewTranslate(x, y,
                setupDrawModelViewTranslate(x, y,
                        x + layer->layer.getWidth(), y + layer->layer.getHeight(), true);
                        x + layer->layer.getWidth(), y + layer->layer.getHeight(), true);
            } else {
            } else {
                layer->setFilter(GL_LINEAR, GL_LINEAR);
                layer->setFilter(GL_LINEAR);
                setupDrawModelViewTranslate(x, y,
                setupDrawModelViewTranslate(x, y,
                        x + layer->layer.getWidth(), y + layer->layer.getHeight());
                        x + layer->layer.getWidth(), y + layer->layer.getHeight());
            }
            }
@@ -2447,18 +2451,18 @@ void OpenGLRenderer::drawTextureRect(float left, float top, float right, float b
    SkXfermode::Mode mode;
    SkXfermode::Mode mode;
    getAlphaAndMode(paint, &alpha, &mode);
    getAlphaAndMode(paint, &alpha, &mode);


    texture->setWrap(GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, true);
    texture->setWrap(GL_CLAMP_TO_EDGE, true);


    if (mSnapshot->transform->isPureTranslate()) {
    if (mSnapshot->transform->isPureTranslate()) {
        const float x = (int) floorf(left + mSnapshot->transform->getTranslateX() + 0.5f);
        const float x = (int) floorf(left + mSnapshot->transform->getTranslateX() + 0.5f);
        const float y = (int) floorf(top + mSnapshot->transform->getTranslateY() + 0.5f);
        const float y = (int) floorf(top + mSnapshot->transform->getTranslateY() + 0.5f);


        texture->setFilter(GL_NEAREST, GL_NEAREST, true);
        texture->setFilter(GL_NEAREST, true);
        drawTextureMesh(x, y, x + texture->width, y + texture->height, texture->id,
        drawTextureMesh(x, y, x + texture->width, y + texture->height, texture->id,
                alpha / 255.0f, mode, texture->blend, (GLvoid*) NULL,
                alpha / 255.0f, mode, texture->blend, (GLvoid*) NULL,
                (GLvoid*) gMeshTextureOffset, GL_TRIANGLE_STRIP, gMeshCount, false, true);
                (GLvoid*) gMeshTextureOffset, GL_TRIANGLE_STRIP, gMeshCount, false, true);
    } else {
    } else {
        texture->setFilter(GL_LINEAR, GL_LINEAR, true);
        texture->setFilter(FILTER(paint), true);
        drawTextureMesh(left, top, right, bottom, texture->id, alpha / 255.0f, mode,
        drawTextureMesh(left, top, right, bottom, texture->id, alpha / 255.0f, mode,
                texture->blend, (GLvoid*) NULL, (GLvoid*) gMeshTextureOffset,
                texture->blend, (GLvoid*) NULL, (GLvoid*) gMeshTextureOffset,
                GL_TRIANGLE_STRIP, gMeshCount);
                GL_TRIANGLE_STRIP, gMeshCount);
+2 −2
Original line number Original line Diff line number Diff line
@@ -584,8 +584,8 @@ void ShapeCache<Entry>::generateTexture(SkBitmap& bitmap, Texture* texture) {
    glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, texture->width, texture->height, 0,
    glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, texture->width, texture->height, 0,
            GL_ALPHA, GL_UNSIGNED_BYTE, bitmap.getPixels());
            GL_ALPHA, GL_UNSIGNED_BYTE, bitmap.getPixels());


    texture->setFilter(GL_LINEAR, GL_LINEAR);
    texture->setFilter(GL_LINEAR);
    texture->setWrap(GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
    texture->setWrap(GL_CLAMP_TO_EDGE);
}
}


}; // namespace uirenderer
}; // namespace uirenderer
+2 −2
Original line number Original line Diff line number Diff line
@@ -77,7 +77,7 @@ void SkiaShader::setupProgram(Program* program, const mat4& modelView, const Sna


void SkiaShader::bindTexture(Texture* texture, GLenum wrapS, GLenum wrapT) {
void SkiaShader::bindTexture(Texture* texture, GLenum wrapS, GLenum wrapT) {
    glBindTexture(GL_TEXTURE_2D, texture->id);
    glBindTexture(GL_TEXTURE_2D, texture->id);
    texture->setWrap(wrapS, wrapT);
    texture->setWrapST(wrapS, wrapT);
}
}


void SkiaShader::computeScreenSpaceMatrix(mat4& screenSpace, const mat4& modelView) {
void SkiaShader::computeScreenSpaceMatrix(mat4& screenSpace, const mat4& modelView) {
@@ -148,7 +148,7 @@ void SkiaBitmapShader::setupProgram(Program* program, const mat4& modelView,
    // ::updateTransforms() but we don't have the texture object
    // ::updateTransforms() but we don't have the texture object
    // available at that point. The optimization is not worth the
    // available at that point. The optimization is not worth the
    // effort for now.
    // effort for now.
    texture->setFilter(GL_LINEAR, GL_LINEAR);
    texture->setFilter(GL_LINEAR);


    glUniform1i(program->getUniform("bitmapSampler"), textureSlot);
    glUniform1i(program->getUniform("bitmapSampler"), textureSlot);
    glUniformMatrix4fv(program->getUniform("textureTransform"), 1,
    glUniformMatrix4fv(program->getUniform("textureTransform"), 1,
Loading