Loading libs/hwui/FboCache.cpp +21 −2 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ #define LOG_TAG "OpenGLRenderer" #include <stdlib.h> #include "FboCache.h" #include "Properties.h" Loading Loading @@ -57,14 +59,31 @@ uint32_t FboCache::getMaxSize() { /////////////////////////////////////////////////////////////////////////////// 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() { 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) { if (mCache.size() < mMaxSize) { mCache.add(fbo); return true; } glDeleteFramebuffers(1, &fbo); return false; } Loading libs/hwui/FboCache.h +0 −2 Original line number Diff line number Diff line Loading @@ -21,8 +21,6 @@ #include <utils/SortedVector.h> #include "GenerationCache.h" namespace android { namespace uirenderer { Loading libs/hwui/GenerationCache.h +6 −0 Original line number Diff line number Diff line Loading @@ -65,6 +65,7 @@ public: void put(K key, V value); V remove(K key); V removeOldest(); V getValueAt(uint32_t index) const; uint32_t size() const; Loading Loading @@ -127,6 +128,11 @@ K GenerationCache<K, V>::getKeyAt(uint32_t index) const { 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> V GenerationCache<K, V>::get(K key) { ssize_t index = mCache.indexOfKey(key); Loading libs/hwui/Layer.h +10 −12 Original line number Diff line number Diff line Loading @@ -32,21 +32,14 @@ namespace uirenderer { * Dimensions of a layer. */ struct LayerSize { LayerSize(): width(0), height(0), id(0) { } LayerSize(const uint32_t width, const uint32_t height): width(width), height(height), id(0) { } LayerSize(const LayerSize& size): width(size.width), height(size.height), id(size.id) { } LayerSize(): width(0), height(0) { } LayerSize(const uint32_t width, const uint32_t height): width(width), height(height) { } LayerSize(const LayerSize& size): width(size.width), height(size.height) { } uint32_t width; 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 { if (id != 0 && rhs.id != 0 && id != rhs.id) { return id < rhs.id; } if (width == rhs.width) { return height < rhs.height; } Loading @@ -54,12 +47,12 @@ struct LayerSize { } 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 /** * 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 { /** Loading @@ -70,6 +63,11 @@ struct Layer { * Name of the texture used to render the layer. */ 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. */ Loading libs/hwui/LayerCache.cpp +13 −3 Original line number Diff line number Diff line Loading @@ -32,7 +32,7 @@ namespace uirenderer { LayerCache::LayerCache(): 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]; if (property_get(PROPERTY_LAYER_CACHE_SIZE, property, NULL) > 0) { LOGD(" Setting layer cache size to %sMB", property); Loading @@ -44,7 +44,7 @@ LayerCache::LayerCache(): LayerCache::LayerCache(uint32_t maxByteSize): mCache(GenerationCache<LayerSize, Layer*>::kUnlimitedCapacity), mIdGenerator(1), mSize(0), mMaxSize(maxByteSize) { mSize(0), mMaxSize(maxByteSize) { } LayerCache::~LayerCache() { Loading Loading @@ -110,6 +110,7 @@ Layer* LayerCache::get(LayerSize& size) { layer = new Layer; layer->blend = true; layer->empty = true; layer->fbo = 0; glGenTextures(1, &layer->texture); glBindTexture(GL_TEXTURE_2D, layer->texture); Loading @@ -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_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; Loading @@ -133,9 +142,10 @@ bool LayerCache::put(LayerSize& layerSize, Layer* layer) { while (mSize + size > mMaxSize) { Layer* oldest = mCache.removeOldest(); deleteLayer(oldest); LAYER_LOGD(" Deleting layer %.2fx%.2f", oldest->layer.getWidth(), oldest->layer.getHeight()); } layerSize.id = mIdGenerator++; mCache.put(layerSize, layer); mSize += size; Loading Loading
libs/hwui/FboCache.cpp +21 −2 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ #define LOG_TAG "OpenGLRenderer" #include <stdlib.h> #include "FboCache.h" #include "Properties.h" Loading Loading @@ -57,14 +59,31 @@ uint32_t FboCache::getMaxSize() { /////////////////////////////////////////////////////////////////////////////// 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() { 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) { if (mCache.size() < mMaxSize) { mCache.add(fbo); return true; } glDeleteFramebuffers(1, &fbo); return false; } Loading
libs/hwui/FboCache.h +0 −2 Original line number Diff line number Diff line Loading @@ -21,8 +21,6 @@ #include <utils/SortedVector.h> #include "GenerationCache.h" namespace android { namespace uirenderer { Loading
libs/hwui/GenerationCache.h +6 −0 Original line number Diff line number Diff line Loading @@ -65,6 +65,7 @@ public: void put(K key, V value); V remove(K key); V removeOldest(); V getValueAt(uint32_t index) const; uint32_t size() const; Loading Loading @@ -127,6 +128,11 @@ K GenerationCache<K, V>::getKeyAt(uint32_t index) const { 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> V GenerationCache<K, V>::get(K key) { ssize_t index = mCache.indexOfKey(key); Loading
libs/hwui/Layer.h +10 −12 Original line number Diff line number Diff line Loading @@ -32,21 +32,14 @@ namespace uirenderer { * Dimensions of a layer. */ struct LayerSize { LayerSize(): width(0), height(0), id(0) { } LayerSize(const uint32_t width, const uint32_t height): width(width), height(height), id(0) { } LayerSize(const LayerSize& size): width(size.width), height(size.height), id(size.id) { } LayerSize(): width(0), height(0) { } LayerSize(const uint32_t width, const uint32_t height): width(width), height(height) { } LayerSize(const LayerSize& size): width(size.width), height(size.height) { } uint32_t width; 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 { if (id != 0 && rhs.id != 0 && id != rhs.id) { return id < rhs.id; } if (width == rhs.width) { return height < rhs.height; } Loading @@ -54,12 +47,12 @@ struct LayerSize { } 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 /** * 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 { /** Loading @@ -70,6 +63,11 @@ struct Layer { * Name of the texture used to render the layer. */ 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. */ Loading
libs/hwui/LayerCache.cpp +13 −3 Original line number Diff line number Diff line Loading @@ -32,7 +32,7 @@ namespace uirenderer { LayerCache::LayerCache(): 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]; if (property_get(PROPERTY_LAYER_CACHE_SIZE, property, NULL) > 0) { LOGD(" Setting layer cache size to %sMB", property); Loading @@ -44,7 +44,7 @@ LayerCache::LayerCache(): LayerCache::LayerCache(uint32_t maxByteSize): mCache(GenerationCache<LayerSize, Layer*>::kUnlimitedCapacity), mIdGenerator(1), mSize(0), mMaxSize(maxByteSize) { mSize(0), mMaxSize(maxByteSize) { } LayerCache::~LayerCache() { Loading Loading @@ -110,6 +110,7 @@ Layer* LayerCache::get(LayerSize& size) { layer = new Layer; layer->blend = true; layer->empty = true; layer->fbo = 0; glGenTextures(1, &layer->texture); glBindTexture(GL_TEXTURE_2D, layer->texture); Loading @@ -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_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; Loading @@ -133,9 +142,10 @@ bool LayerCache::put(LayerSize& layerSize, Layer* layer) { while (mSize + size > mMaxSize) { Layer* oldest = mCache.removeOldest(); deleteLayer(oldest); LAYER_LOGD(" Deleting layer %.2fx%.2f", oldest->layer.getWidth(), oldest->layer.getHeight()); } layerSize.id = mIdGenerator++; mCache.put(layerSize, layer); mSize += size; Loading