diff options
| author | 2013-06-11 16:19:24 -0700 | |
|---|---|---|
| committer | 2013-06-11 17:14:59 -0700 | |
| commit | 4c2547fa9244e78115cde0a259291053108c3dc7 (patch) | |
| tree | 4337937e216918e4febe861daa7ef093b99aff03 /libs/hwui/PatchCache.cpp | |
| parent | fadd2081443dd2f59f8e8143256a34b7485fe72e (diff) | |
Avoid 9patch cache lookups when possible
This optimization saves up to 0.3ms per frame on the Play Store's
front page, on a Nexus 4 device.
Change-Id: Iaa4ef33c6e3b37e175efd5b9eea9ef59b43f14f3
Diffstat (limited to 'libs/hwui/PatchCache.cpp')
| -rw-r--r-- | libs/hwui/PatchCache.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/libs/hwui/PatchCache.cpp b/libs/hwui/PatchCache.cpp index c6ed275e3cae..c23e99155a11 100644 --- a/libs/hwui/PatchCache.cpp +++ b/libs/hwui/PatchCache.cpp @@ -30,7 +30,9 @@ namespace uirenderer { // Constructors/destructor /////////////////////////////////////////////////////////////////////////////// -PatchCache::PatchCache(): mCache(LruCache<PatchDescription, Patch*>::kUnlimitedCapacity) { +PatchCache::PatchCache(): + mSize(0), mCache(LruCache<PatchDescription, Patch*>::kUnlimitedCapacity), + mMeshBuffer(0), mGenerationId(0) { char property[PROPERTY_VALUE_MAX]; if (property_get(PROPERTY_PATCH_CACHE_SIZE, property, NULL) > 0) { INIT_LOGD(" Setting patch cache size to %skB", property); @@ -39,8 +41,6 @@ PatchCache::PatchCache(): mCache(LruCache<PatchDescription, Patch*>::kUnlimitedC INIT_LOGD(" Using default patch cache size of %.2fkB", DEFAULT_PATCH_CACHE_SIZE); mMaxSize = KB(DEFAULT_PATCH_CACHE_SIZE); } - mSize = 0; - mMeshBuffer = 0; } PatchCache::~PatchCache() { @@ -58,7 +58,7 @@ void PatchCache::init(Caches& caches) { caches.resetVertexPointers(); if (created) { - glBufferData(GL_ARRAY_BUFFER, mMaxSize, NULL, GL_DYNAMIC_DRAW); + createVertexBuffer(); } } @@ -99,6 +99,12 @@ void PatchCache::clearCache() { mCache.clear(); } +void PatchCache::createVertexBuffer() { + glBufferData(GL_ARRAY_BUFFER, mMaxSize, NULL, GL_DYNAMIC_DRAW); + mSize = 0; + mGenerationId++; +} + const Patch* PatchCache::get(const AssetAtlas::Entry* entry, const uint32_t bitmapWidth, const uint32_t bitmapHeight, const float pixelWidth, const float pixelHeight, const Res_png_9patch* patch) { @@ -127,8 +133,7 @@ const Patch* PatchCache::get(const AssetAtlas::Entry* entry, uint32_t size = newMesh->getSize(); if (mSize + size > mMaxSize) { clearCache(); - glBufferData(GL_ARRAY_BUFFER, mMaxSize, NULL, GL_DYNAMIC_DRAW); - mSize = 0; + createVertexBuffer(); } newMesh->offset = (GLintptr) mSize; |