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

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

Merge "Share Caches' index buffer with FontRenderer"

parents 1f54f924 31e08e95
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -386,8 +386,8 @@ bool Caches::bindIndicesBuffer(const GLuint buffer) {

bool Caches::bindIndicesBuffer() {
    if (!mMeshIndices) {
        uint16_t* regionIndices = new uint16_t[REGION_MESH_QUAD_COUNT * 6];
        for (int i = 0; i < REGION_MESH_QUAD_COUNT; i++) {
        uint16_t* regionIndices = new uint16_t[gMaxNumberOfQuads * 6];
        for (uint32_t i = 0; i < gMaxNumberOfQuads; i++) {
            uint16_t quad = i * 4;
            int index = i * 6;
            regionIndices[index    ] = quad;       // top-left
@@ -400,7 +400,7 @@ bool Caches::bindIndicesBuffer() {

        glGenBuffers(1, &mMeshIndices);
        bool force = bindIndicesBuffer(mMeshIndices);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, REGION_MESH_QUAD_COUNT * 6 * sizeof(uint16_t),
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, gMaxNumberOfQuads * 6 * sizeof(uint16_t),
                regionIndices, GL_STATIC_DRAW);

        delete[] regionIndices;
@@ -638,7 +638,7 @@ void Caches::unregisterFunctors(uint32_t functorCount) {
TextureVertex* Caches::getRegionMesh() {
    // Create the mesh, 2 triangles and 4 vertices per rectangle in the region
    if (!mRegionMesh) {
        mRegionMesh = new TextureVertex[REGION_MESH_QUAD_COUNT * 4];
        mRegionMesh = new TextureVertex[gMaxNumberOfQuads * 4];
    }

    return mRegionMesh;
+3 −2
Original line number Diff line number Diff line
@@ -58,7 +58,8 @@ namespace uirenderer {
// 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
// Maximum number of quads that pre-allocated meshes can draw
static const uint32_t gMaxNumberOfQuads = 2048;

// Generates simple and textured vertices
#define FV(x, y, u, v) { { x, y }, { u, v } }
@@ -181,7 +182,7 @@ public:

    /**
     * Binds a global indices buffer that can draw up to
     * REGION_MESH_QUAD_COUNT quads.
     * gMaxNumberOfQuads quads.
     */
    bool bindIndicesBuffer();
    bool bindIndicesBuffer(const GLuint buffer);
+8 −1
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@

#include "Debug.h"
#include "Extensions.h"
#include "Properties.h"

namespace android {

@@ -63,7 +64,13 @@ Extensions::Extensions(): Singleton<Extensions>() {

    // Query EGL extensions
    findExtensions(eglQueryString(eglGetCurrentDisplay(), EGL_EXTENSIONS), mEglExtensionList);
    mHasNvSystemTime = hasEglExtension("EGL_NV_system_time");

    char property[PROPERTY_VALUE_MAX];
    if (property_get(PROPERTY_DEBUG_NV_PROFILING, property, NULL) > 0) {
        mHasNvSystemTime = !strcmp(property, "true") && hasEglExtension("EGL_NV_system_time");
    } else {
        mHasNvSystemTime = false;
    }

    const char* version = (const char*) glGetString(GL_VERSION);

+1 −37
Original line number Diff line number Diff line
@@ -64,8 +64,6 @@ FontRenderer::FontRenderer() :

    mLinearFiltering = false;

    mIndexBufferID = 0;

    mSmallCacheWidth = DEFAULT_TEXT_SMALL_CACHE_WIDTH;
    mSmallCacheHeight = DEFAULT_TEXT_SMALL_CACHE_HEIGHT;
    mLargeCacheWidth = DEFAULT_TEXT_LARGE_CACHE_WIDTH;
@@ -111,12 +109,6 @@ FontRenderer::~FontRenderer() {
    }
    mCacheTextures.clear();

    if (mInitialized) {
        // Unbinding the buffer shouldn't be necessary but it crashes with some drivers
        Caches::getInstance().unbindIndicesBuffer();
        glDeleteBuffers(1, &mIndexBufferID);
    }

    LruCache<Font::FontDescription, Font*>::Iterator it(mActiveFonts);
    while (it.next()) {
        delete it.value();
@@ -319,33 +311,6 @@ void FontRenderer::initTextTexture() {
    mCurrentCacheTexture = mCacheTextures[0];
}

// Avoid having to reallocate memory and render quad by quad
void FontRenderer::initVertexArrayBuffers() {
    uint32_t numIndices = gMaxNumberOfQuads * 6;
    uint32_t indexBufferSizeBytes = numIndices * sizeof(uint16_t);
    uint16_t* indexBufferData = (uint16_t*) malloc(indexBufferSizeBytes);

    // Four verts, two triangles , six indices per quad
    for (uint32_t i = 0; i < gMaxNumberOfQuads; i++) {
        int i6 = i * 6;
        int i4 = i * 4;

        indexBufferData[i6 + 0] = i4 + 0;
        indexBufferData[i6 + 1] = i4 + 1;
        indexBufferData[i6 + 2] = i4 + 2;

        indexBufferData[i6 + 3] = i4 + 0;
        indexBufferData[i6 + 4] = i4 + 2;
        indexBufferData[i6 + 5] = i4 + 3;
    }

    glGenBuffers(1, &mIndexBufferID);
    Caches::getInstance().bindIndicesBuffer(mIndexBufferID);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexBufferSizeBytes, indexBufferData, GL_STATIC_DRAW);

    free(indexBufferData);
}

// We don't want to allocate anything unless we actually draw text
void FontRenderer::checkInit() {
    if (mInitialized) {
@@ -353,7 +318,6 @@ void FontRenderer::checkInit() {
    }

    initTextTexture();
    initVertexArrayBuffers();

    mInitialized = true;
}
@@ -416,7 +380,7 @@ void FontRenderer::issueDrawCommand() {
                if (mFunctor) (*mFunctor)(0, NULL);

                checkTextureUpdate();
                caches.bindIndicesBuffer(mIndexBufferID);
                caches.bindIndicesBuffer();

                if (!mDrawn) {
                    // If returns true, a VBO was bound and we must
+0 −5
Original line number Diff line number Diff line
@@ -105,8 +105,6 @@ public:
private:
    friend class Font;

    static const uint32_t gMaxNumberOfQuads = 2048;

    const uint8_t* mGammaTable;

    void allocateTextureMemory(CacheTexture* cacheTexture);
@@ -118,7 +116,6 @@ private:
    CacheTexture* cacheBitmapInTexture(const SkGlyph& glyph, uint32_t* startX, uint32_t* startY);

    void flushAllAndInvalidate();
    void initVertexArrayBuffers();

    void checkInit();
    void initRender(const Rect* clip, Rect* bounds, Functor* functor);
@@ -160,8 +157,6 @@ private:

    bool mUploadTexture;

    uint32_t mIndexBufferID;

    Functor* mFunctor;
    const Rect* mClip;
    Rect* mBounds;
Loading