From 09b7c91de73b59aa3f679b3ae3ba299f82ec9f8a Mon Sep 17 00:00:00 2001 From: Romain Guy Date: Wed, 2 Feb 2011 20:28:09 -0800 Subject: 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 --- libs/hwui/LayerCache.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'libs/hwui/LayerCache.cpp') 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 -- cgit v1.2.3-59-g8ed1b