Clip text correctly
Bug #5706056
A newly introduced optimization relied on the display list renderer
to properly measure text to perform fast clipping. The paint used
to measure text needs to have AA and glyph id encoding set to return
the correct results. Unfortunately these properties were set by
the GL renderer and not by the display list renderer. This change
simply sets the properties in the display list renderer instead.
This change also improves the error message printed out when the
application attempts to use a bitmap larger than the max texture
size.
Change-Id: I4d84e1c7d194aed9ad476f69434eaa2c8f3836a8
diff --git a/libs/hwui/DisplayListRenderer.cpp b/libs/hwui/DisplayListRenderer.cpp
index ae7a3b5..5a52464 100644
--- a/libs/hwui/DisplayListRenderer.cpp
+++ b/libs/hwui/DisplayListRenderer.cpp
@@ -1204,6 +1204,16 @@
addText(text, bytesCount);
addInt(count);
addPoint(x, y);
+ // TODO: We should probably make a copy of the paint instead of modifying
+ // it; modifying the paint will change its generationID the first
+ // time, which might impact caches. More investigation needed to
+ // see if it matters.
+ // If we make a copy, then drawTextDecorations() should *not* make
+ // its own copy as it does right now.
+ paint->setAntiAlias(true);
+#if RENDER_TEXT_AS_GLYPHS
+ paint->setTextEncoding(SkPaint::kGlyphID_TextEncoding);
+#endif
addPaint(paint);
addFloat(length < 0.0f ? paint->measureText(text, bytesCount) : length);
}
diff --git a/libs/hwui/DisplayListRenderer.h b/libs/hwui/DisplayListRenderer.h
index ab483fb..c09760e 100644
--- a/libs/hwui/DisplayListRenderer.h
+++ b/libs/hwui/DisplayListRenderer.h
@@ -290,7 +290,7 @@
virtual void drawLines(float* points, int count, SkPaint* paint);
virtual void drawPoints(float* points, int count, SkPaint* paint);
virtual void drawText(const char* text, int bytesCount, int count, float x, float y,
- SkPaint* paint, float length);
+ SkPaint* paint, float length = 1.0f);
virtual void resetShader();
virtual void setupShader(SkiaShader* shader);
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index a60ac08..81c053e 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -2069,16 +2069,7 @@
}
if (mSnapshot->isIgnored()) return;
- // TODO: We should probably make a copy of the paint instead of modifying
- // it; modifying the paint will change its generationID the first
- // time, which might impact caches. More investigation needed to
- // see if it matters.
- // If we make a copy, then drawTextDecorations() should *not* make
- // its own copy as it does right now.
- paint->setAntiAlias(true);
-#if RENDER_TEXT_AS_GLYPHS
- paint->setTextEncoding(SkPaint::kGlyphID_TextEncoding);
-#endif
+ // NOTE: AA and glyph id encoding are set in DisplayListRenderer.cpp
switch (paint->getTextAlign()) {
case SkPaint::kCenter_Align:
@@ -2095,6 +2086,7 @@
SkPaint::FontMetrics metrics;
paint->getFontMetrics(&metrics, 0.0f);
+ // If no length was specified, just perform the hit test on the Y axis
if (quickReject(x, y + metrics.fTop,
x + (length >= 0.0f ? length : INT_MAX / 2), y + metrics.fBottom)) {
return;
diff --git a/libs/hwui/ShapeCache.h b/libs/hwui/ShapeCache.h
index 8b88d30..f64c074 100644
--- a/libs/hwui/ShapeCache.h
+++ b/libs/hwui/ShapeCache.h
@@ -503,7 +503,8 @@
const uint32_t height = uint32_t(pathHeight + offset * 2.0 + 0.5);
if (width > mMaxTextureSize || height > mMaxTextureSize) {
- LOGW("Shape %s too large to be rendered into a texture", mName);
+ LOGW("Shape %s too large to be rendered into a texture (%dx%d, max=%dx%d)",
+ mName, width, height, mMaxTextureSize, mMaxTextureSize);
return NULL;
}
diff --git a/libs/hwui/TextureCache.cpp b/libs/hwui/TextureCache.cpp
index 711277a..60f4ca1 100644
--- a/libs/hwui/TextureCache.cpp
+++ b/libs/hwui/TextureCache.cpp
@@ -125,7 +125,8 @@
if (!texture) {
if (bitmap->width() > mMaxTextureSize || bitmap->height() > mMaxTextureSize) {
- LOGW("Bitmap too large to be uploaded into a texture");
+ LOGW("Bitmap too large to be uploaded into a texture (%dx%d, max=%dx%d)",
+ bitmap->width(), bitmap->height(), mMaxTextureSize, mMaxTextureSize);
return NULL;
}