summaryrefslogtreecommitdiff
path: root/libs/hwui/LayerCache.cpp
diff options
context:
space:
mode:
author Romain Guy <romainguy@google.com> 2011-02-02 20:28:09 -0800
committer Romain Guy <romainguy@google.com> 2011-02-02 20:28:09 -0800
commit09b7c91de73b59aa3f679b3ae3ba299f82ec9f8a (patch)
tree9eb49f2fedb60e6df37b54216ed20f054a6f55fd /libs/hwui/LayerCache.cpp
parent62687ec12cb8e0b1d4044a235b1387b9a8c3b4b4 (diff)
Allocate layers from the layers pool.
Bug #3413433 This change will be beneficial to Launcher to avoid hiccups when swiping pages of icons. When a layer is discarded, it is kept in the layers pool instead of being destroyed right away. This favors memory reuse over allocations. Change-Id: Ifb6944ba83d6ceb67c331527c0827b26ce648eb1
Diffstat (limited to 'libs/hwui/LayerCache.cpp')
-rw-r--r--libs/hwui/LayerCache.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/libs/hwui/LayerCache.cpp b/libs/hwui/LayerCache.cpp
index 7667af5fe018..a9710ad6adbf 100644
--- a/libs/hwui/LayerCache.cpp
+++ b/libs/hwui/LayerCache.cpp
@@ -128,6 +128,31 @@ Layer* LayerCache::get(const uint32_t width, const uint32_t height) {
return layer;
}
+bool LayerCache::resize(Layer* layer, const uint32_t width, const uint32_t height) {
+ // TODO: We should be smarter and see if we have a texture of the appropriate
+ // size already in the cache, and reuse it instead of creating a new one
+
+ LayerEntry entry(width, height);
+ if (entry.mWidth <= layer->width && entry.mHeight <= layer->height) {
+ return true;
+ }
+
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, layer->texture);
+
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, entry.mWidth, entry.mHeight, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+
+ if (glGetError() != GL_NO_ERROR) {
+ return false;
+ }
+
+ layer->width = entry.mWidth;
+ layer->height = entry.mHeight;
+
+ return true;
+}
+
bool LayerCache::put(Layer* layer) {
const uint32_t size = layer->width * layer->height * 4;
// Don't even try to cache a layer that's bigger than the cache