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

Commit fff41d77 authored by Lucas Dupin's avatar Lucas Dupin
Browse files

Remove unnecessary blit

It's possible to keep a pointer to the current buffer, instead of
copying it's contents.

Bug: 149792636
Test: manual
Test: presubmit
Change-Id: I04f5fe51580b53a869a1911eb69c6f04ab2eefcf
parent 93c3ef10
Loading
Loading
Loading
Loading
+17 −20
Original line number Original line Diff line number Diff line
@@ -33,8 +33,8 @@ namespace gl {
BlurFilter::BlurFilter(GLESRenderEngine& engine)
BlurFilter::BlurFilter(GLESRenderEngine& engine)
      : mEngine(engine),
      : mEngine(engine),
        mCompositionFbo(engine),
        mCompositionFbo(engine),
        mBlurredFbo(engine),
        mPingFbo(engine),
        mPingPongFbo(engine),
        mPongFbo(engine),
        mMixProgram(engine),
        mMixProgram(engine),
        mBlurProgram(engine) {
        mBlurProgram(engine) {
    mMixProgram.compile(getVertexShader(), getMixFragShader());
    mMixProgram.compile(getVertexShader(), getMixFragShader());
@@ -62,14 +62,14 @@ status_t BlurFilter::setAsDrawTarget(const DisplaySettings& display, uint32_t ra


        const uint32_t fboWidth = floorf(mDisplayWidth * kFboScale);
        const uint32_t fboWidth = floorf(mDisplayWidth * kFboScale);
        const uint32_t fboHeight = floorf(mDisplayHeight * kFboScale);
        const uint32_t fboHeight = floorf(mDisplayHeight * kFboScale);
        mBlurredFbo.allocateBuffers(fboWidth, fboHeight);
        mPingFbo.allocateBuffers(fboWidth, fboHeight);
        mPingPongFbo.allocateBuffers(fboWidth, fboHeight);
        mPongFbo.allocateBuffers(fboWidth, fboHeight);
        mTexturesAllocated = true;
        mTexturesAllocated = true;
    }
    }


    if (mBlurredFbo.getStatus() != GL_FRAMEBUFFER_COMPLETE) {
    if (mPingFbo.getStatus() != GL_FRAMEBUFFER_COMPLETE) {
        ALOGE("Invalid blur buffer");
        ALOGE("Invalid blur buffer");
        return mBlurredFbo.getStatus();
        return mPingFbo.getStatus();
    }
    }
    if (mCompositionFbo.getStatus() != GL_FRAMEBUFFER_COMPLETE) {
    if (mCompositionFbo.getStatus() != GL_FRAMEBUFFER_COMPLETE) {
        ALOGE("Invalid composition buffer");
        ALOGE("Invalid composition buffer");
@@ -110,16 +110,16 @@ void BlurFilter::drawMesh(GLuint uv, GLuint position) {
status_t BlurFilter::prepare() {
status_t BlurFilter::prepare() {
    ATRACE_NAME("BlurFilter::prepare");
    ATRACE_NAME("BlurFilter::prepare");


    if (mPingPongFbo.getStatus() != GL_FRAMEBUFFER_COMPLETE) {
    if (mPongFbo.getStatus() != GL_FRAMEBUFFER_COMPLETE) {
        ALOGE("Invalid FBO");
        ALOGE("Invalid FBO");
        return mPingPongFbo.getStatus();
        return mPongFbo.getStatus();
    }
    }
    if (!mBlurProgram.isValid()) {
    if (!mBlurProgram.isValid()) {
        ALOGE("Invalid shader");
        ALOGE("Invalid shader");
        return GL_INVALID_OPERATION;
        return GL_INVALID_OPERATION;
    }
    }


    blit(mCompositionFbo, mBlurredFbo);
    blit(mCompositionFbo, mPingFbo);


    // Kawase is an approximation of Gaussian, but it behaves differently from it.
    // Kawase is an approximation of Gaussian, but it behaves differently from it.
    // A radius transformation is required for approximating them, and also to introduce
    // A radius transformation is required for approximating them, and also to introduce
@@ -132,8 +132,8 @@ status_t BlurFilter::prepare() {


    // We'll ping pong between our textures, to accumulate the result of various offsets.
    // We'll ping pong between our textures, to accumulate the result of various offsets.
    mBlurProgram.useProgram();
    mBlurProgram.useProgram();
    GLFramebuffer* draw = &mPingPongFbo;
    GLFramebuffer* read = &mPingFbo;
    GLFramebuffer* read = &mBlurredFbo;
    GLFramebuffer* draw = &mPongFbo;
    float stepX = radius / (float)mCompositionFbo.getBufferWidth() / (float)passes;
    float stepX = radius / (float)mCompositionFbo.getBufferWidth() / (float)passes;
    float stepY = radius / (float)mCompositionFbo.getBufferHeight() / (float)passes;
    float stepY = radius / (float)mCompositionFbo.getBufferHeight() / (float)passes;
    glActiveTexture(GL_TEXTURE0);
    glActiveTexture(GL_TEXTURE0);
@@ -154,11 +154,7 @@ status_t BlurFilter::prepare() {
        draw = read;
        draw = read;
        read = tmp;
        read = tmp;
    }
    }

    mLastDrawTarget = read;
    // Copy texture, given that we're expected to end on mBlurredFbo.
    if (draw == &mBlurredFbo) {
        blit(mPingPongFbo, mBlurredFbo);
    }


    // Cleanup
    // Cleanup
    glBindFramebuffer(GL_FRAMEBUFFER, 0);
    glBindFramebuffer(GL_FRAMEBUFFER, 0);
@@ -177,9 +173,10 @@ status_t BlurFilter::render(bool multiPass) {
    // be writing onto it. Let's disable the crossfade, otherwise we'd need 1 extra frame buffer,
    // be writing onto it. Let's disable the crossfade, otherwise we'd need 1 extra frame buffer,
    // as large as the screen size.
    // as large as the screen size.
    if (mix >= 1 || multiPass) {
    if (mix >= 1 || multiPass) {
        mBlurredFbo.bindAsReadBuffer();
        mLastDrawTarget->bindAsReadBuffer();
        glBlitFramebuffer(0, 0, mBlurredFbo.getBufferWidth(), mBlurredFbo.getBufferHeight(), 0, 0,
        glBlitFramebuffer(0, 0, mLastDrawTarget->getBufferWidth(),
                          mDisplayWidth, mDisplayHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR);
                          mLastDrawTarget->getBufferHeight(), 0, 0, mDisplayWidth, mDisplayHeight,
                          GL_COLOR_BUFFER_BIT, GL_LINEAR);
        glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
        glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
        return NO_ERROR;
        return NO_ERROR;
    }
    }
@@ -187,7 +184,7 @@ status_t BlurFilter::render(bool multiPass) {
    mMixProgram.useProgram();
    mMixProgram.useProgram();
    glUniform1f(mMMixLoc, mix);
    glUniform1f(mMMixLoc, mix);
    glActiveTexture(GL_TEXTURE0);
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, mBlurredFbo.getTextureName());
    glBindTexture(GL_TEXTURE_2D, mLastDrawTarget->getTextureName());
    glUniform1i(mMTextureLoc, 0);
    glUniform1i(mMTextureLoc, 0);
    glActiveTexture(GL_TEXTURE1);
    glActiveTexture(GL_TEXTURE1);
    glBindTexture(GL_TEXTURE_2D, mCompositionFbo.getTextureName());
    glBindTexture(GL_TEXTURE_2D, mCompositionFbo.getTextureName());
+5 −3
Original line number Original line Diff line number Diff line
@@ -63,11 +63,13 @@ private:
    GLESRenderEngine& mEngine;
    GLESRenderEngine& mEngine;
    // Frame buffer holding the composited background.
    // Frame buffer holding the composited background.
    GLFramebuffer mCompositionFbo;
    GLFramebuffer mCompositionFbo;
    // Frame buffer holding the blur result.
    // Frame buffers holding the blur passes.
    GLFramebuffer mBlurredFbo;
    GLFramebuffer mPingFbo;
    GLFramebuffer mPongFbo;
    uint32_t mDisplayWidth;
    uint32_t mDisplayWidth;
    uint32_t mDisplayHeight;
    uint32_t mDisplayHeight;
    GLFramebuffer mPingPongFbo;
    // Buffer holding the final blur pass.
    GLFramebuffer* mLastDrawTarget;
    bool mTexturesAllocated = false;
    bool mTexturesAllocated = false;


    GenericProgram mMixProgram;
    GenericProgram mMixProgram;