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

Commit eb99356a authored by Romain Guy's avatar Romain Guy
Browse files

Optimize saveLayer() when the clip flag is set.

This speeds up applications, especially Launcher.
parent 7adaf3d1
Loading
Loading
Loading
Loading
+21 −2
Original line number Original line Diff line number Diff line
@@ -16,6 +16,8 @@


#define LOG_TAG "OpenGLRenderer"
#define LOG_TAG "OpenGLRenderer"


#include <stdlib.h>

#include "FboCache.h"
#include "FboCache.h"
#include "Properties.h"
#include "Properties.h"


@@ -57,14 +59,31 @@ uint32_t FboCache::getMaxSize() {
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////


void FboCache::clear() {
void FboCache::clear() {

    for (size_t i = 0; i < mCache.size(); i++) {
        const GLuint fbo = mCache.itemAt(i);
        glDeleteFramebuffers(1, &fbo);
    }
    mCache.clear();
}
}


GLuint FboCache::get() {
GLuint FboCache::get() {
    return 0;
    GLuint fbo;
    if (mCache.size() > 0) {
        fbo = mCache.itemAt(mCache.size() - 1);
        mCache.removeAt(mCache.size() - 1);
    } else {
        glGenFramebuffers(1, &fbo);
    }
    return fbo;
}
}


bool FboCache::put(GLuint fbo) {
bool FboCache::put(GLuint fbo) {
    if (mCache.size() < mMaxSize) {
        mCache.add(fbo);
        return true;
    }

    glDeleteFramebuffers(1, &fbo);
    return false;
    return false;
}
}


+0 −2
Original line number Original line Diff line number Diff line
@@ -21,8 +21,6 @@


#include <utils/SortedVector.h>
#include <utils/SortedVector.h>


#include "GenerationCache.h"

namespace android {
namespace android {
namespace uirenderer {
namespace uirenderer {


+6 −0
Original line number Original line Diff line number Diff line
@@ -65,6 +65,7 @@ public:
    void put(K key, V value);
    void put(K key, V value);
    V remove(K key);
    V remove(K key);
    V removeOldest();
    V removeOldest();
    V getValueAt(uint32_t index) const;


    uint32_t size() const;
    uint32_t size() const;


@@ -127,6 +128,11 @@ K GenerationCache<K, V>::getKeyAt(uint32_t index) const {
    return mCache.keyAt(index);
    return mCache.keyAt(index);
}
}


template<typename K, typename V>
V GenerationCache<K, V>::getValueAt(uint32_t index) const {
    return mCache.valueAt(index);
}

template<typename K, typename V>
template<typename K, typename V>
V GenerationCache<K, V>::get(K key) {
V GenerationCache<K, V>::get(K key) {
    ssize_t index = mCache.indexOfKey(key);
    ssize_t index = mCache.indexOfKey(key);
+10 −12
Original line number Original line Diff line number Diff line
@@ -32,21 +32,14 @@ namespace uirenderer {
 * Dimensions of a layer.
 * Dimensions of a layer.
 */
 */
struct LayerSize {
struct LayerSize {
    LayerSize(): width(0), height(0), id(0) { }
    LayerSize(): width(0), height(0) { }
    LayerSize(const uint32_t width, const uint32_t height): width(width), height(height), id(0) { }
    LayerSize(const uint32_t width, const uint32_t height): width(width), height(height) { }
    LayerSize(const LayerSize& size): width(size.width), height(size.height), id(size.id) { }
    LayerSize(const LayerSize& size): width(size.width), height(size.height) { }


    uint32_t width;
    uint32_t width;
    uint32_t height;
    uint32_t height;


    // Incremental id used by the layer cache to store multiple
    // LayerSize with the same dimensions
    uint32_t id;

    bool operator<(const LayerSize& rhs) const {
    bool operator<(const LayerSize& rhs) const {
        if (id != 0 && rhs.id != 0 && id != rhs.id) {
            return id < rhs.id;
        }
        if (width == rhs.width) {
        if (width == rhs.width) {
            return height < rhs.height;
            return height < rhs.height;
        }
        }
@@ -54,12 +47,12 @@ struct LayerSize {
    }
    }


    bool operator==(const LayerSize& rhs) const {
    bool operator==(const LayerSize& rhs) const {
        return id == rhs.id && width == rhs.width && height == rhs.height;
        return width == rhs.width && height == rhs.height;
    }
    }
}; // struct LayerSize
}; // struct LayerSize


/**
/**
 * A layer has dimensions and is backed by an OpenGL texture.
 * A layer has dimensions and is backed by an OpenGL texture or FBO.
 */
 */
struct Layer {
struct Layer {
    /**
    /**
@@ -70,6 +63,11 @@ struct Layer {
     * Name of the texture used to render the layer.
     * Name of the texture used to render the layer.
     */
     */
    GLuint texture;
    GLuint texture;
    /**
     * Name of the FBO used to render the layer. If the name is 0
     * this layer is not backed by an FBO, but a simple texture.
     */
    GLuint fbo;
    /**
    /**
     * Opacity of the layer.
     * Opacity of the layer.
     */
     */
+13 −3
Original line number Original line Diff line number Diff line
@@ -32,7 +32,7 @@ namespace uirenderer {


LayerCache::LayerCache():
LayerCache::LayerCache():
        mCache(GenerationCache<LayerSize, Layer*>::kUnlimitedCapacity),
        mCache(GenerationCache<LayerSize, Layer*>::kUnlimitedCapacity),
        mIdGenerator(1), mSize(0), mMaxSize(MB(DEFAULT_LAYER_CACHE_SIZE)) {
        mSize(0), mMaxSize(MB(DEFAULT_LAYER_CACHE_SIZE)) {
    char property[PROPERTY_VALUE_MAX];
    char property[PROPERTY_VALUE_MAX];
    if (property_get(PROPERTY_LAYER_CACHE_SIZE, property, NULL) > 0) {
    if (property_get(PROPERTY_LAYER_CACHE_SIZE, property, NULL) > 0) {
        LOGD("  Setting layer cache size to %sMB", property);
        LOGD("  Setting layer cache size to %sMB", property);
@@ -44,7 +44,7 @@ LayerCache::LayerCache():


LayerCache::LayerCache(uint32_t maxByteSize):
LayerCache::LayerCache(uint32_t maxByteSize):
        mCache(GenerationCache<LayerSize, Layer*>::kUnlimitedCapacity),
        mCache(GenerationCache<LayerSize, Layer*>::kUnlimitedCapacity),
        mIdGenerator(1), mSize(0), mMaxSize(maxByteSize) {
        mSize(0), mMaxSize(maxByteSize) {
}
}


LayerCache::~LayerCache() {
LayerCache::~LayerCache() {
@@ -110,6 +110,7 @@ Layer* LayerCache::get(LayerSize& size) {
        layer = new Layer;
        layer = new Layer;
        layer->blend = true;
        layer->blend = true;
        layer->empty = true;
        layer->empty = true;
        layer->fbo = 0;


        glGenTextures(1, &layer->texture);
        glGenTextures(1, &layer->texture);
        glBindTexture(GL_TEXTURE_2D, layer->texture);
        glBindTexture(GL_TEXTURE_2D, layer->texture);
@@ -121,6 +122,14 @@ Layer* LayerCache::get(LayerSize& size) {


        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

#if DEBUG_LAYERS
        uint32_t size = mCache.size();
        for (uint32_t i = 0; i < size; i++) {
            LayerSize ls = mCache.getKeyAt(i);
            LAYER_LOGD("  Layer size %dx%d", ls.width, ls.height);
        }
#endif
    }
    }


    return layer;
    return layer;
@@ -133,9 +142,10 @@ bool LayerCache::put(LayerSize& layerSize, Layer* layer) {
        while (mSize + size > mMaxSize) {
        while (mSize + size > mMaxSize) {
            Layer* oldest = mCache.removeOldest();
            Layer* oldest = mCache.removeOldest();
            deleteLayer(oldest);
            deleteLayer(oldest);
            LAYER_LOGD("  Deleting layer %.2fx%.2f", oldest->layer.getWidth(),
                    oldest->layer.getHeight());
        }
        }


        layerSize.id = mIdGenerator++;
        mCache.put(layerSize, layer);
        mCache.put(layerSize, layer);
        mSize += size;
        mSize += size;


Loading