diff options
author | 2010-10-08 18:36:15 -0700 | |
---|---|---|
committer | 2010-10-08 18:36:57 -0700 | |
commit | 2728f961614a385df1f056fc24803a9f65c90fab (patch) | |
tree | c09ff5c42f949f4b9e76e197108cc5a506113ca3 /libs/hwui/PatchCache.cpp | |
parent | 8550c4c7b5952b7a4e1e0ede95c9492d03099a13 (diff) |
Don't update 9patches on every frame.
Change-Id: I7ffb2365f83e0453e7d0a0cdcb3fc9308b305238
Diffstat (limited to 'libs/hwui/PatchCache.cpp')
-rw-r--r-- | libs/hwui/PatchCache.cpp | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/libs/hwui/PatchCache.cpp b/libs/hwui/PatchCache.cpp index f2cf5485a09f..4dc1a4dd1e31 100644 --- a/libs/hwui/PatchCache.cpp +++ b/libs/hwui/PatchCache.cpp @@ -29,10 +29,10 @@ namespace uirenderer { // Constructors/destructor /////////////////////////////////////////////////////////////////////////////// -PatchCache::PatchCache(): mCache(DEFAULT_PATCH_CACHE_SIZE) { +PatchCache::PatchCache(): mMaxEntries(DEFAULT_PATCH_CACHE_SIZE) { } -PatchCache::PatchCache(uint32_t maxEntries): mCache(maxEntries) { +PatchCache::PatchCache(uint32_t maxEntries): mMaxEntries(maxEntries) { } PatchCache::~PatchCache() { @@ -40,31 +40,44 @@ PatchCache::~PatchCache() { } /////////////////////////////////////////////////////////////////////////////// -// Callbacks -/////////////////////////////////////////////////////////////////////////////// - -void PatchCache::operator()(PatchDescription& description, Patch*& mesh) { - if (mesh) delete mesh; -} - -/////////////////////////////////////////////////////////////////////////////// // Caching /////////////////////////////////////////////////////////////////////////////// void PatchCache::clear() { - mCache.setOnEntryRemovedListener(this); + size_t count = mCache.size(); + for (int i = 0; i < count; i++) { + delete mCache.valueAt(i); + } mCache.clear(); - mCache.setOnEntryRemovedListener(NULL); } -Patch* PatchCache::get(uint32_t width, uint32_t height) { - const PatchDescription description(width, height); +Patch* PatchCache::get(const float bitmapWidth, const float bitmapHeight, + const float pixelWidth, const float pixelHeight, + const int32_t* xDivs, const int32_t* yDivs, + const uint32_t width, const uint32_t height) { + + const PatchDescription description(bitmapWidth, bitmapHeight, + pixelWidth, pixelHeight, width, height); + + ssize_t index = mCache.indexOfKey(description); + Patch* mesh = NULL; + if (index >= 0) { + mesh = mCache.valueAt(index); + } - Patch* mesh = mCache.get(description); if (!mesh) { PATCH_LOGD("Creating new patch mesh, w=%d h=%d", width, height); + mesh = new Patch(width, height); - mCache.put(description, mesh); + mesh->updateVertices(bitmapWidth, bitmapHeight, 0.0f, 0.0f, + pixelWidth, pixelHeight, xDivs, yDivs, width, height); + + if (mCache.size() >= mMaxEntries) { + delete mCache.valueAt(0); + mCache.removeItemsAt(0, 1); + } + + mCache.add(description, mesh); } return mesh; |