diff options
author | Romain Guy <romainguy@google.com> | 2013-03-19 18:56:19 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-03-19 18:56:19 +0000 |
commit | df9d2ba9b0b92608ea633bf04ffbef8d7ba3dd28 (patch) | |
tree | 13008d79fb703e175876db68ba31977cbb9362cc /libs | |
parent | 2d18e52b00da92ca415b9da0aaac920a5e733f8b (diff) | |
parent | 115096f50a560e64a7f95d37686d4861042c7aeb (diff) | |
download | frameworks_base-df9d2ba9b0b92608ea633bf04ffbef8d7ba3dd28.zip frameworks_base-df9d2ba9b0b92608ea633bf04ffbef8d7ba3dd28.tar.gz frameworks_base-df9d2ba9b0b92608ea633bf04ffbef8d7ba3dd28.tar.bz2 |
Merge "Minimize texture binds when drawing text" into jb-mr2-dev
Diffstat (limited to 'libs')
-rw-r--r-- | libs/hwui/FontRenderer.cpp | 29 | ||||
-rw-r--r-- | libs/hwui/FontRenderer.h | 30 | ||||
-rw-r--r-- | libs/hwui/Properties.h | 2 | ||||
-rw-r--r-- | libs/hwui/font/FontUtil.h | 2 |
4 files changed, 44 insertions, 19 deletions
diff --git a/libs/hwui/FontRenderer.cpp b/libs/hwui/FontRenderer.cpp index f0dcb30..0c70e27 100644 --- a/libs/hwui/FontRenderer.cpp +++ b/libs/hwui/FontRenderer.cpp @@ -378,9 +378,9 @@ void FontRenderer::checkInit() { void FontRenderer::updateDrawParams() { if (mCurrentQuadIndex != mLastQuadIndex) { - mDrawOffsets.add((uint16_t*)(mLastQuadIndex * sizeof(uint16_t) * 6)); - mDrawCounts.add(mCurrentQuadIndex - mLastQuadIndex); - mDrawCacheTextures.add(mCurrentCacheTexture); + uint16_t* offset = (uint16_t*)(mLastQuadIndex * sizeof(uint16_t) * 6); + uint32_t count = mCurrentQuadIndex - mLastQuadIndex; + mDrawBatch.add(TextBatch(offset, count, mCurrentCacheTexture)); mLastQuadIndex = mCurrentQuadIndex; } } @@ -438,26 +438,27 @@ void FontRenderer::issueDrawCommand() { caches.bindTexCoordsVertexPointer(force, buffer + offset); } - for (uint32_t i = 0; i < mDrawOffsets.size(); i++) { - uint16_t* offset = mDrawOffsets[i]; - uint32_t count = mDrawCounts[i]; - CacheTexture* texture = mDrawCacheTextures[i]; + caches.activeTexture(0); + GLuint lastId = 0; - caches.activeTexture(0); - glBindTexture(GL_TEXTURE_2D, texture->getTextureId()); + for (uint32_t i = 0; i < mDrawBatch.size(); i++) { + const TextBatch& batch = mDrawBatch[i]; - texture->setLinearFiltering(mLinearFiltering, false); + GLuint id = batch.texture->getTextureId(); + if (id != lastId) { + glBindTexture(GL_TEXTURE_2D, id); + batch.texture->setLinearFiltering(mLinearFiltering, false); + lastId = id; + } - glDrawElements(GL_TRIANGLES, count * 6, GL_UNSIGNED_SHORT, offset); + glDrawElements(GL_TRIANGLES, batch.count * 6, GL_UNSIGNED_SHORT, batch.offset); } mDrawn = true; mCurrentQuadIndex = 0; mLastQuadIndex = 0; - mDrawOffsets.clear(); - mDrawCounts.clear(); - mDrawCacheTextures.clear(); + mDrawBatch.clear(); } void FontRenderer::appendMeshQuadNoClip(float x1, float y1, float u1, float v1, diff --git a/libs/hwui/FontRenderer.h b/libs/hwui/FontRenderer.h index d0c44ef..442f4e2 100644 --- a/libs/hwui/FontRenderer.h +++ b/libs/hwui/FontRenderer.h @@ -28,6 +28,7 @@ #include "font/CacheTexture.h" #include "font/CachedGlyphInfo.h" #include "font/Font.h" +#include "utils/SortedList.h" #include "Matrix.h" #include "Properties.h" @@ -180,9 +181,32 @@ private: bool mLinearFiltering; - Vector<uint16_t*> mDrawOffsets; - Vector<uint32_t> mDrawCounts; - Vector<CacheTexture*> mDrawCacheTextures; + struct TextBatch { + TextBatch(): offset(NULL), count(0), texture(NULL) { + } + + TextBatch(uint16_t* offset, uint32_t count, CacheTexture* texture): + offset(offset), count(count), texture(texture) { + } + + static int compare(const TextBatch& lhs, const TextBatch& rhs) { + return lhs.texture->getTextureId() - rhs.texture->getTextureId(); + } + + friend inline int strictly_order_type(const TextBatch& lhs, const TextBatch& rhs) { + return compare(lhs, rhs) < 0; + } + + friend inline int compare_type(const TextBatch& lhs, const TextBatch& rhs) { + return compare(lhs, rhs); + } + + uint16_t* offset; + uint32_t count; + CacheTexture* texture; + }; + + SortedList<TextBatch> mDrawBatch; // RS constructs sp<RSC::RS> mRs; diff --git a/libs/hwui/Properties.h b/libs/hwui/Properties.h index 5f39abf..e4b4f3c 100644 --- a/libs/hwui/Properties.h +++ b/libs/hwui/Properties.h @@ -119,7 +119,7 @@ enum DebugLevel { #define PROPERTY_FBO_CACHE_SIZE "ro.hwui.fbo_cache_size" // These properties are defined in percentage (range 0..1) -#define PROPERTY_TEXTURE_CACHE_FLUSH_RATE "ro.hwui.texture_cache_flush_rate" +#define PROPERTY_TEXTURE_CACHE_FLUSH_RATE "ro.hwui.texture_cache_flushrate" // These properties are defined in pixels #define PROPERTY_TEXT_SMALL_CACHE_WIDTH "ro.hwui.text_small_cache_width" diff --git a/libs/hwui/font/FontUtil.h b/libs/hwui/font/FontUtil.h index 4f9c46b..f758666 100644 --- a/libs/hwui/font/FontUtil.h +++ b/libs/hwui/font/FontUtil.h @@ -26,7 +26,7 @@ /////////////////////////////////////////////////////////////////////////////// #define DEFAULT_TEXT_SMALL_CACHE_WIDTH 1024 -#define DEFAULT_TEXT_SMALL_CACHE_HEIGHT 256 +#define DEFAULT_TEXT_SMALL_CACHE_HEIGHT 512 #define DEFAULT_TEXT_LARGE_CACHE_WIDTH 2048 #define DEFAULT_TEXT_LARGE_CACHE_HEIGHT 512 |