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

Commit 2d4fd364 authored by Romain Guy's avatar Romain Guy
Browse files

Reduce the number of active texture changes

Change-Id: I94046bdfe20740c26c8183822e3002d692fde7c4
parent ec31f83b
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -615,6 +615,8 @@ void FontRenderer::checkTextureUpdate() {
        return;
    }

    Caches& caches = Caches::getInstance();
    GLuint lastTextureId = 0;
    // Iterate over all the cache lines and see which ones need to be updated
    for (uint32_t i = 0; i < mCacheLines.size(); i++) {
        CacheTextureLine* cl = mCacheLines[i];
@@ -626,7 +628,11 @@ void FontRenderer::checkTextureUpdate() {
            uint32_t height  = cl->mMaxHeight;
            void* textureData = cacheTexture->mTexture + (yOffset * width);

            if (cacheTexture->mTextureId != lastTextureId) {
                caches.activeTexture(0);
                glBindTexture(GL_TEXTURE_2D, cacheTexture->mTextureId);
                lastTextureId = cacheTexture->mTextureId;
            }
            glTexSubImage2D(GL_TEXTURE_2D, 0, xOffset, yOffset, width, height,
                    GL_ALPHA, GL_UNSIGNED_BYTE, textureData);

@@ -644,6 +650,7 @@ void FontRenderer::issueDrawCommand() {
    checkTextureUpdate();

    Caches& caches = Caches::getInstance();
    caches.bindIndicesBuffer(mIndexBufferID);
    if (!mDrawn) {
        float* buffer = mTextMeshPtr;
        int offset = 2;
@@ -654,7 +661,6 @@ void FontRenderer::issueDrawCommand() {
                buffer + offset);
    }

    caches.bindIndicesBuffer(mIndexBufferID);
    glDrawElements(GL_TRIANGLES, mCurrentQuadIndex * 6, GL_UNSIGNED_SHORT, NULL);

    mDrawn = true;
@@ -779,6 +785,7 @@ FontRenderer::DropShadow FontRenderer::renderDropShadow(SkPaint* paint, const ch
        return image;
    }

    mDrawn = false;
    mClip = NULL;
    mBounds = NULL;

@@ -806,6 +813,7 @@ FontRenderer::DropShadow FontRenderer::renderDropShadow(SkPaint* paint, const ch
    image.image = dataBuffer;
    image.penX = penX;
    image.penY = penY;

    return image;
}

+4 −5
Original line number Diff line number Diff line
@@ -1207,13 +1207,13 @@ void OpenGLRenderer::setupDrawSimpleMesh() {

void OpenGLRenderer::setupDrawTexture(GLuint texture) {
    bindTexture(texture);
    glUniform1i(mCaches.currentProgram->getUniform("sampler"), mTextureUnit++);
    mTextureUnit++;
    mCaches.enableTexCoordsVertexArray();
}

void OpenGLRenderer::setupDrawExternalTexture(GLuint texture) {
    bindExternalTexture(texture);
    glUniform1i(mCaches.currentProgram->getUniform("sampler"), mTextureUnit++);
    mTextureUnit++;
    mCaches.enableTexCoordsVertexArray();
}

@@ -2128,6 +2128,8 @@ void OpenGLRenderer::drawText(const char* text, int bytesCount, int count,
    getAlphaAndMode(paint, &alpha, &mode);

    if (mHasShadow) {
        mCaches.activeTexture(0);

        mCaches.dropShadowCache.setFontRenderer(fontRenderer);
        const ShadowTexture* shadow = mCaches.dropShadowCache.get(
                paint, text, bytesCount, count, mShadowRadius);
@@ -2142,7 +2144,6 @@ void OpenGLRenderer::drawText(const char* text, int bytesCount, int count,
            shadowColor = 0xffffffff;
        }

        mCaches.activeTexture(0);
        setupDraw();
        setupDrawWithTexture(true);
        setupDrawAlpha8Color(shadowColor, shadowAlpha < 255 ? shadowAlpha : alpha);
@@ -2158,8 +2159,6 @@ void OpenGLRenderer::drawText(const char* text, int bytesCount, int count,
        setupDrawMesh(NULL, (GLvoid*) gMeshTextureOffset);

        glDrawArrays(GL_TRIANGLE_STRIP, 0, gMeshCount);

        finishDrawTexture();
    }

    if (paint->getAlpha() == 0 && paint->getXfermode() == NULL) {
+5 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ namespace uirenderer {
Program::Program(const ProgramDescription& description, const char* vertex, const char* fragment) {
    mInitialized = false;
    mHasColorUniform = false;
    mHasSampler = false;
    mUse = false;

    // No need to cache compiled shaders, rely instead on Android's
@@ -176,6 +177,10 @@ void Program::setColor(const float r, const float g, const float b, const float

void Program::use() {
    glUseProgram(mProgramId);
    if (texCoords >= 0 && !mHasSampler) {
        glUniform1i(getUniform("sampler"), 0);
        mHasSampler = true;
    }
    mUse = true;
}

+2 −0
Original line number Diff line number Diff line
@@ -398,6 +398,8 @@ private:

    bool mHasColorUniform;
    int mColorUniform;

    bool mHasSampler;
}; // class Program

}; // namespace uirenderer