diff options
author | Romain Guy <romainguy@google.com> | 2011-12-13 22:00:19 -0800 |
---|---|---|
committer | Romain Guy <romainguy@google.com> | 2011-12-13 22:00:19 -0800 |
commit | 2d4fd364843d3efc6e6ee59ccc5beb513a86d789 (patch) | |
tree | e6314681f94a7fcd0355a5700ecf65d9e3e0c5bb | |
parent | ec31f83bd3af1f900d1ee9116b15f56904c66dcd (diff) | |
download | frameworks_base-2d4fd364843d3efc6e6ee59ccc5beb513a86d789.zip frameworks_base-2d4fd364843d3efc6e6ee59ccc5beb513a86d789.tar.gz frameworks_base-2d4fd364843d3efc6e6ee59ccc5beb513a86d789.tar.bz2 |
Reduce the number of active texture changes
Change-Id: I94046bdfe20740c26c8183822e3002d692fde7c4
-rw-r--r-- | libs/hwui/FontRenderer.cpp | 12 | ||||
-rw-r--r-- | libs/hwui/OpenGLRenderer.cpp | 9 | ||||
-rw-r--r-- | libs/hwui/Program.cpp | 5 | ||||
-rw-r--r-- | libs/hwui/Program.h | 2 |
4 files changed, 21 insertions, 7 deletions
diff --git a/libs/hwui/FontRenderer.cpp b/libs/hwui/FontRenderer.cpp index 27556d9..3c6a952 100644 --- a/libs/hwui/FontRenderer.cpp +++ b/libs/hwui/FontRenderer.cpp @@ -615,6 +615,8 @@ void FontRenderer::checkTextureUpdate() { return; } + Caches& caches = Caches::getInstance(); + GLuint lastTextureId = 0; // Iterate over all the cache lines and see which ones need to be updated for (uint32_t i = 0; i < mCacheLines.size(); i++) { CacheTextureLine* cl = mCacheLines[i]; @@ -626,7 +628,11 @@ void FontRenderer::checkTextureUpdate() { uint32_t height = cl->mMaxHeight; void* textureData = cacheTexture->mTexture + (yOffset * width); - glBindTexture(GL_TEXTURE_2D, cacheTexture->mTextureId); + if (cacheTexture->mTextureId != lastTextureId) { + caches.activeTexture(0); + glBindTexture(GL_TEXTURE_2D, cacheTexture->mTextureId); + lastTextureId = cacheTexture->mTextureId; + } glTexSubImage2D(GL_TEXTURE_2D, 0, xOffset, yOffset, width, height, GL_ALPHA, GL_UNSIGNED_BYTE, textureData); @@ -644,6 +650,7 @@ void FontRenderer::issueDrawCommand() { checkTextureUpdate(); Caches& caches = Caches::getInstance(); + caches.bindIndicesBuffer(mIndexBufferID); if (!mDrawn) { float* buffer = mTextMeshPtr; int offset = 2; @@ -654,7 +661,6 @@ void FontRenderer::issueDrawCommand() { buffer + offset); } - caches.bindIndicesBuffer(mIndexBufferID); glDrawElements(GL_TRIANGLES, mCurrentQuadIndex * 6, GL_UNSIGNED_SHORT, NULL); mDrawn = true; @@ -779,6 +785,7 @@ FontRenderer::DropShadow FontRenderer::renderDropShadow(SkPaint* paint, const ch return image; } + mDrawn = false; mClip = NULL; mBounds = NULL; @@ -806,6 +813,7 @@ FontRenderer::DropShadow FontRenderer::renderDropShadow(SkPaint* paint, const ch image.image = dataBuffer; image.penX = penX; image.penY = penY; + return image; } diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp index 1f5d13b..cbfd778 100644 --- a/libs/hwui/OpenGLRenderer.cpp +++ b/libs/hwui/OpenGLRenderer.cpp @@ -1207,13 +1207,13 @@ void OpenGLRenderer::setupDrawSimpleMesh() { void OpenGLRenderer::setupDrawTexture(GLuint texture) { bindTexture(texture); - glUniform1i(mCaches.currentProgram->getUniform("sampler"), mTextureUnit++); + mTextureUnit++; mCaches.enableTexCoordsVertexArray(); } void OpenGLRenderer::setupDrawExternalTexture(GLuint texture) { bindExternalTexture(texture); - glUniform1i(mCaches.currentProgram->getUniform("sampler"), mTextureUnit++); + mTextureUnit++; mCaches.enableTexCoordsVertexArray(); } @@ -2128,6 +2128,8 @@ void OpenGLRenderer::drawText(const char* text, int bytesCount, int count, getAlphaAndMode(paint, &alpha, &mode); if (mHasShadow) { + mCaches.activeTexture(0); + mCaches.dropShadowCache.setFontRenderer(fontRenderer); const ShadowTexture* shadow = mCaches.dropShadowCache.get( paint, text, bytesCount, count, mShadowRadius); @@ -2142,7 +2144,6 @@ void OpenGLRenderer::drawText(const char* text, int bytesCount, int count, shadowColor = 0xffffffff; } - mCaches.activeTexture(0); setupDraw(); setupDrawWithTexture(true); setupDrawAlpha8Color(shadowColor, shadowAlpha < 255 ? shadowAlpha : alpha); @@ -2158,8 +2159,6 @@ void OpenGLRenderer::drawText(const char* text, int bytesCount, int count, setupDrawMesh(NULL, (GLvoid*) gMeshTextureOffset); glDrawArrays(GL_TRIANGLE_STRIP, 0, gMeshCount); - - finishDrawTexture(); } if (paint->getAlpha() == 0 && paint->getXfermode() == NULL) { diff --git a/libs/hwui/Program.cpp b/libs/hwui/Program.cpp index cbea843..701314d 100644 --- a/libs/hwui/Program.cpp +++ b/libs/hwui/Program.cpp @@ -29,6 +29,7 @@ namespace uirenderer { Program::Program(const ProgramDescription& description, const char* vertex, const char* fragment) { mInitialized = false; mHasColorUniform = false; + mHasSampler = false; mUse = false; // No need to cache compiled shaders, rely instead on Android's @@ -176,6 +177,10 @@ void Program::setColor(const float r, const float g, const float b, const float void Program::use() { glUseProgram(mProgramId); + if (texCoords >= 0 && !mHasSampler) { + glUniform1i(getUniform("sampler"), 0); + mHasSampler = true; + } mUse = true; } diff --git a/libs/hwui/Program.h b/libs/hwui/Program.h index 559c717..eed909d 100644 --- a/libs/hwui/Program.h +++ b/libs/hwui/Program.h @@ -398,6 +398,8 @@ private: bool mHasColorUniform; int mColorUniform; + + bool mHasSampler; }; // class Program }; // namespace uirenderer |