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

Commit f19544f2 authored by Vishnu Nair's avatar Vishnu Nair
Browse files

Update shadow render code to use lookup texture

Optimizes performance on low end devices by avoiding exp() in the
fragment shader and lowering the precision of the shadow attributes
used in the shaders.

Test: adb shell su root dumpsys SurfaceFlinger --timestats -dump -maxlayers 0 on wembley
Test: atest SurfaceFlinger_test librenderengine_test
Test: shadows still look like shadows
Change-Id: I0e6e35a2f4f2d31b3126438ebb8b34d92a7d98c0
parent 466691be
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ filegroup {
        "gl/GLExtensions.cpp",
        "gl/GLFramebuffer.cpp",
        "gl/GLImage.cpp",
        "gl/GLShadowTexture.cpp",
        "gl/GLShadowVertexGenerator.cpp",
        "gl/GLSkiaShadowPort.cpp",
        "gl/ImageManager.cpp",
+1 −0
Original line number Diff line number Diff line
@@ -1661,6 +1661,7 @@ void GLESRenderEngine::handleShadow(const FloatRect& casterRect, float casterCor

    mState.cornerRadius = 0.0f;
    mState.drawShadows = true;
    setupLayerTexturing(mShadowTexture.getTexture());
    drawMesh(mesh);
    mState.drawShadows = false;
}
+2 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@
#include <renderengine/RenderEngine.h>
#include <renderengine/private/Description.h>
#include <sys/types.h>
#include "GLShadowTexture.h"
#include "ImageManager.h"

#define EGL_NO_CONFIG ((EGLConfig)0)
@@ -183,6 +184,7 @@ private:
    GLuint mVpWidth;
    GLuint mVpHeight;
    Description mState;
    GLShadowTexture mShadowTexture;

    mat4 mSrgbToXyz;
    mat4 mDisplayP3ToXyz;
+52 −0
Original line number Diff line number Diff line
/*
 * Copyright 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <GLES/gl.h>
#include <GLES/glext.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <GLES3/gl3.h>

#include "GLShadowTexture.h"
#include "GLSkiaShadowPort.h"

namespace android {
namespace renderengine {
namespace gl {

GLShadowTexture::GLShadowTexture() {
    fillShadowTextureData(mTextureData, SHADOW_TEXTURE_WIDTH);

    glGenTextures(1, &mName);
    glBindTexture(GL_TEXTURE_2D, mName);
    glTexImage2D(GL_TEXTURE_2D, 0 /* base image level */, GL_ALPHA, SHADOW_TEXTURE_WIDTH,
                 SHADOW_TEXTURE_HEIGHT, 0 /* border */, GL_ALPHA, GL_UNSIGNED_BYTE, mTextureData);
    mTexture.init(Texture::TEXTURE_2D, mName);
    mTexture.setFiltering(true);
    mTexture.setDimensions(SHADOW_TEXTURE_WIDTH, 1);
}

GLShadowTexture::~GLShadowTexture() {
    glDeleteTextures(1, &mName);
}

const Texture& GLShadowTexture::getTexture() {
    return mTexture;
}

} // namespace gl
} // namespace renderengine
} // namespace android
+44 −0
Original line number Diff line number Diff line
/*
 * Copyright 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <renderengine/Texture.h>
#include <cstdint>

namespace android {
namespace renderengine {
namespace gl {

class GLShadowTexture {
public:
    GLShadowTexture();
    ~GLShadowTexture();

    const Texture& getTexture();

private:
    static constexpr int SHADOW_TEXTURE_WIDTH = 128;
    static constexpr int SHADOW_TEXTURE_HEIGHT = 1;

    GLuint mName;
    Texture mTexture;
    uint8_t mTextureData[SHADOW_TEXTURE_WIDTH];
};

} // namespace gl
} // namespace renderengine
} // namespace android
Loading