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

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

Merge "Introduce Caches::bindTexture() to reduce glBindTexture calls"

parents 65327834 8aa195d7
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ ifeq ($(USE_OPENGL_RENDERER),true)
		SkiaShader.cpp \
		Snapshot.cpp \
		Stencil.cpp \
		Texture.cpp \
		TextureCache.cpp \
		TextDropShadowCache.cpp

+8 −5
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */

#include "AssetAtlas.h"
#include "Caches.h"

#include <GLES2/gl2ext.h>

@@ -33,12 +34,14 @@ void AssetAtlas::init(sp<GraphicBuffer> buffer, int* map, int count) {
    mImage = new Image(buffer);

    if (mImage->getTexture()) {
        mTexture = new Texture();
        Caches& caches = Caches::getInstance();

        mTexture = new Texture(caches);
        mTexture->id = mImage->getTexture();
        mTexture->width = buffer->getWidth();
        mTexture->height = buffer->getHeight();

        createEntries(map, count);
        createEntries(caches, map, count);
    } else {
        ALOGW("Could not create atlas image");

@@ -82,7 +85,7 @@ Texture* AssetAtlas::getEntryTexture(SkBitmap* const bitmap) const {
 * instead of applying the changes to the virtual textures.
 */
struct DelegateTexture: public Texture {
    DelegateTexture(Texture* delegate): Texture(), mDelegate(delegate) { }
    DelegateTexture(Caches& caches, Texture* delegate): Texture(caches), mDelegate(delegate) { }

    virtual void setWrapST(GLenum wrapS, GLenum wrapT, bool bindTexture = false,
            bool force = false, GLenum renderTarget = GL_TEXTURE_2D) {
@@ -100,7 +103,7 @@ private:
/**
 * TODO: This method does not take the rotation flag into account
 */
void AssetAtlas::createEntries(int* map, int count) {
void AssetAtlas::createEntries(Caches& caches, int* map, int count) {
    const float width = float(mTexture->width);
    const float height = float(mTexture->height);

@@ -117,7 +120,7 @@ void AssetAtlas::createEntries(int* map, int count) {
                x / width, (x + bitmap->width()) / width,
                y / height, (y + bitmap->height()) / height);

        Texture* texture = new DelegateTexture(mTexture);
        Texture* texture = new DelegateTexture(caches, mTexture);
        Entry* entry = new Entry(bitmap, x, y, rotated, texture, mapper, *this);

        texture->id = mTexture->id;
+3 −1
Original line number Diff line number Diff line
@@ -34,6 +34,8 @@
namespace android {
namespace uirenderer {

class Caches;

/**
 * An asset atlas holds a collection of framework bitmaps in a single OpenGL
 * texture. Each bitmap is associated with a location, defined in pixels,
@@ -157,7 +159,7 @@ public:
    Texture* getEntryTexture(SkBitmap* const bitmap) const;

private:
    void createEntries(int* map, int count);
    void createEntries(Caches& caches, int* map, int count);

    Texture* mTexture;
    Image* mImage;
+22 −1
Original line number Diff line number Diff line
@@ -47,7 +47,8 @@ namespace uirenderer {
// Constructors/destructor
///////////////////////////////////////////////////////////////////////////////

Caches::Caches(): Singleton<Caches>(), mExtensions(Extensions::getInstance()), mInitialized(false) {
Caches::Caches(): Singleton<Caches>(),
        mExtensions(Extensions::getInstance()), mInitialized(false) {
    init();
    initFont();
    initConstraints();
@@ -100,6 +101,8 @@ bool Caches::init() {

    mInitialized = true;

    resetBoundTextures();

    return true;
}

@@ -491,6 +494,24 @@ void Caches::activeTexture(GLuint textureUnit) {
    }
}

void Caches::bindTexture(GLuint texture) {
    if (mBoundTextures[mTextureUnit] != texture) {
        glBindTexture(GL_TEXTURE_2D, texture);
        mBoundTextures[mTextureUnit] = texture;
    }
}

void Caches::bindTexture(GLenum target, GLuint texture) {
    if (mBoundTextures[mTextureUnit] != texture) {
        glBindTexture(target, texture);
        mBoundTextures[mTextureUnit] = texture;
    }
}

void Caches::resetBoundTextures() {
    memset(mBoundTextures, 0, REQUIRED_TEXTURE_UNITS_COUNT * sizeof(GLuint));
}

///////////////////////////////////////////////////////////////////////////////
// Scissor
///////////////////////////////////////////////////////////////////////////////
+20 −0
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ namespace uirenderer {
// Globals
///////////////////////////////////////////////////////////////////////////////

// GL ES 2.0 defines that at least 16 texture units must be supported
#define REQUIRED_TEXTURE_UNITS_COUNT 3

#define REGION_MESH_QUAD_COUNT 512
@@ -79,6 +80,7 @@ static const GLsizei gVertexAAWidthOffset = 2 * sizeof(float);
static const GLsizei gVertexAALengthOffset = 3 * sizeof(float);
static const GLsizei gMeshCount = 4;

// Must define as many texture units as specified by REQUIRED_TEXTURE_UNITS_COUNT
static const GLenum gTextureUnits[] = {
    GL_TEXTURE0,
    GL_TEXTURE1,
@@ -222,6 +224,22 @@ public:
     */
    void activeTexture(GLuint textureUnit);

    /**
     * Binds the specified texture as a GL_TEXTURE_2D texture.
     */
    void bindTexture(GLuint texture);

    /**
     * Binds the specified texture..
     */
    void bindTexture(GLenum target, GLuint texture);

    /**
     * Signals that the cache of bound textures should be cleared.
     * Other users of the context may have altered which textures are bound.
     */
    void resetBoundTextures();

    /**
     * Sets the scissor for the current surface.
     */
@@ -363,6 +381,8 @@ private:
    bool mInitialized;

    uint32_t mFunctorsCount;

    GLuint mBoundTextures[REQUIRED_TEXTURE_UNITS_COUNT];
}; // class Caches

}; // namespace uirenderer
Loading