diff options
| author | 2013-02-28 12:15:35 -0800 | |
|---|---|---|
| committer | 2013-02-28 16:04:48 -0800 | |
| commit | a4adcf0239039eb8f005be252409901c41b28839 (patch) | |
| tree | bb339ae27217db42e4ef0de743b07ca138ef335a /libs/hwui/OpenGLRenderer.cpp | |
| parent | aaa46155ec80f02b37ec858408d7dabbf9bc289a (diff) | |
Support 3D rotations when drawing text
If a perspective transform is set on the Canvas, drawText() should
not attempt to rasterize glyphs in screen space. This change uses
the old behavior instead (i.e. rasterize the glyphs at the native
font size and apply the transform on the resulting mesh.)
This change also adds an optimization: empty glyphs (spaces) do
not generate vertices anymore. This saves a lot of vertices in text
heavy applications such as Gmail.
Change-Id: Ib531384163f5165b5785501612a7b1474f3ff599
Diffstat (limited to 'libs/hwui/OpenGLRenderer.cpp')
| -rw-r--r-- | libs/hwui/OpenGLRenderer.cpp | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp index fb77ef610fd0..7e9734f9e57d 100644 --- a/libs/hwui/OpenGLRenderer.cpp +++ b/libs/hwui/OpenGLRenderer.cpp @@ -2151,17 +2151,17 @@ status_t OpenGLRenderer::drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const alpha *= mSnapshot->alpha; - mCaches.activeTexture(0); - Texture* texture = mCaches.textureCache.get(bitmap); - if (!texture) return DrawGlInfo::kStatusDone; - const AutoTexture autoCleanup(texture); - texture->setWrap(GL_CLAMP_TO_EDGE, true); - texture->setFilter(GL_LINEAR, true); - const Patch* mesh = mCaches.patchCache.get(bitmap->width(), bitmap->height(), right - left, bottom - top, xDivs, yDivs, colors, width, height, numColors); if (CC_LIKELY(mesh && mesh->verticesCount > 0)) { + mCaches.activeTexture(0); + Texture* texture = mCaches.textureCache.get(bitmap); + if (!texture) return DrawGlInfo::kStatusDone; + const AutoTexture autoCleanup(texture); + texture->setWrap(GL_CLAMP_TO_EDGE, true); + texture->setFilter(GL_LINEAR, true); + const bool pureTranslate = mSnapshot->transform->isPureTranslate(); // Mark the current layer dirty where we are going to draw the patch if (hasLayer() && mesh->hasEmptyQuads) { @@ -2666,6 +2666,7 @@ status_t OpenGLRenderer::drawText(const char* text, int bytesCount, int count, const float oldX = x; const float oldY = y; const bool pureTranslate = mSnapshot->transform->isPureTranslate(); + const bool isPerspective = mSnapshot->transform->isPerspective(); if (CC_LIKELY(pureTranslate)) { x = (int) floorf(x + mSnapshot->transform->getTranslateX() + 0.5f); @@ -2687,8 +2688,7 @@ status_t OpenGLRenderer::drawText(const char* text, int bytesCount, int count, fontRenderer.setFont(paint, pureTranslate ? mat4::identity() : *mSnapshot->transform); // Pick the appropriate texture filtering - bool linearFilter = !mSnapshot->transform->isPureTranslate() || - fabs(y - (int) y) > 0.0f || fabs(x - (int) x) > 0.0f; + bool linearFilter = !pureTranslate || fabs(y - (int) y) > 0.0f || fabs(x - (int) x) > 0.0f; // The font renderer will always use texture unit 0 mCaches.activeTexture(0); @@ -2701,13 +2701,13 @@ status_t OpenGLRenderer::drawText(const char* text, int bytesCount, int count, setupDrawShader(); setupDrawBlending(true, mode); setupDrawProgram(); - setupDrawModelView(x, y, x, y, true, true); + setupDrawModelView(x, y, x, y, !isPerspective, true); // See comment above; the font renderer must use texture unit 0 // assert(mTextureUnit == 0) setupDrawTexture(fontRenderer.getTexture(linearFilter)); setupDrawPureColorUniforms(); setupDrawColorFilterUniforms(); - setupDrawShaderUniforms(true); + setupDrawShaderUniforms(!isPerspective); setupDrawTextGammaUniforms(); const Rect* clip = mSnapshot->hasPerspectiveTransform() ? NULL : mSnapshot->clipRect; @@ -2727,6 +2727,9 @@ status_t OpenGLRenderer::drawText(const char* text, int bytesCount, int count, } if (status && hasActiveLayer) { + if (isPerspective) { + mSnapshot->transform->mapRect(bounds); + } dirtyLayerUnchecked(bounds, getRegion()); } |