summaryrefslogtreecommitdiffstats
path: root/libs/hwui
diff options
context:
space:
mode:
authorRomain Guy <romainguy@google.com>2011-12-01 20:08:50 -0800
committerRomain Guy <romainguy@google.com>2011-12-01 20:08:50 -0800
commitcac5fd3e09e9dc918753d4aff624bf29a367ade3 (patch)
tree6d1db0b5ed0cf9ce616f7e8d969da81f7f606b66 /libs/hwui
parentd21b6e1fe337b35f62cf2028e9bd0637fd009a75 (diff)
downloadframeworks_base-cac5fd3e09e9dc918753d4aff624bf29a367ade3.zip
frameworks_base-cac5fd3e09e9dc918753d4aff624bf29a367ade3.tar.gz
frameworks_base-cac5fd3e09e9dc918753d4aff624bf29a367ade3.tar.bz2
Faster text clipping
Change-Id: I03a00c4261d81a416b1ad7b86ce2d432c71908b4
Diffstat (limited to 'libs/hwui')
-rw-r--r--libs/hwui/DisplayListRenderer.cpp15
-rw-r--r--libs/hwui/DisplayListRenderer.h2
-rw-r--r--libs/hwui/OpenGLRenderer.cpp14
-rw-r--r--libs/hwui/OpenGLRenderer.h2
4 files changed, 21 insertions, 12 deletions
diff --git a/libs/hwui/DisplayListRenderer.cpp b/libs/hwui/DisplayListRenderer.cpp
index 3372d1c..ae7a3b5 100644
--- a/libs/hwui/DisplayListRenderer.cpp
+++ b/libs/hwui/DisplayListRenderer.cpp
@@ -477,8 +477,9 @@ void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) {
float x = getFloat();
float y = getFloat();
SkPaint* paint = getPaint();
- LOGD("%s%s %s, %d, %d, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
- text.text(), text.length(), count, x, y, paint);
+ float length = getFloat();
+ LOGD("%s%s %s, %d, %d, %.2f, %.2f, %p, %.2f", (char*) indent, OP_NAMES[op],
+ text.text(), text.length(), count, x, y, paint, length);
}
break;
case ResetShader: {
@@ -837,9 +838,10 @@ bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level)
float x = getFloat();
float y = getFloat();
SkPaint* paint = getPaint();
- DISPLAY_LIST_LOGD("%s%s %s, %d, %d, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
- text.text(), text.length(), count, x, y, paint);
- renderer.drawText(text.text(), text.length(), count, x, y, paint);
+ float length = getFloat();
+ DISPLAY_LIST_LOGD("%s%s %s, %d, %d, %.2f, %.2f, %p, %.2f", (char*) indent,
+ OP_NAMES[op], text.text(), text.length(), count, x, y, paint, length);
+ renderer.drawText(text.text(), text.length(), count, x, y, paint, length);
}
break;
case ResetShader: {
@@ -1196,13 +1198,14 @@ void DisplayListRenderer::drawPoints(float* points, int count, SkPaint* paint) {
}
void DisplayListRenderer::drawText(const char* text, int bytesCount, int count,
- float x, float y, SkPaint* paint) {
+ float x, float y, SkPaint* paint, float length) {
if (count <= 0) return;
addOp(DisplayList::DrawText);
addText(text, bytesCount);
addInt(count);
addPoint(x, y);
addPaint(paint);
+ addFloat(length < 0.0f ? paint->measureText(text, bytesCount) : length);
}
void DisplayListRenderer::resetShader() {
diff --git a/libs/hwui/DisplayListRenderer.h b/libs/hwui/DisplayListRenderer.h
index ab475bf..ab483fb 100644
--- a/libs/hwui/DisplayListRenderer.h
+++ b/libs/hwui/DisplayListRenderer.h
@@ -290,7 +290,7 @@ public:
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);
+ SkPaint* paint, float length);
virtual void resetShader();
virtual void setupShader(SkiaShader* shader);
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index 3c838fc..a60ac08 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -2063,7 +2063,7 @@ void OpenGLRenderer::drawRect(float left, float top, float right, float bottom,
}
void OpenGLRenderer::drawText(const char* text, int bytesCount, int count,
- float x, float y, SkPaint* paint) {
+ float x, float y, SkPaint* paint, float length) {
if (text == NULL || count == 0) {
return;
}
@@ -2080,20 +2080,26 @@ void OpenGLRenderer::drawText(const char* text, int bytesCount, int count,
paint->setTextEncoding(SkPaint::kGlyphID_TextEncoding);
#endif
- float length = -1.0f;
switch (paint->getTextAlign()) {
case SkPaint::kCenter_Align:
- length = paint->measureText(text, bytesCount);
+ if (length < 0.0f) length = paint->measureText(text, bytesCount);
x -= length / 2.0f;
break;
case SkPaint::kRight_Align:
- length = paint->measureText(text, bytesCount);
+ if (length < 0.0f) length = paint->measureText(text, bytesCount);
x -= length;
break;
default:
break;
}
+ SkPaint::FontMetrics metrics;
+ paint->getFontMetrics(&metrics, 0.0f);
+ if (quickReject(x, y + metrics.fTop,
+ x + (length >= 0.0f ? length : INT_MAX / 2), y + metrics.fBottom)) {
+ return;
+ }
+
const float oldX = x;
const float oldY = y;
const bool pureTranslate = mSnapshot->transform->isPureTranslate();
diff --git a/libs/hwui/OpenGLRenderer.h b/libs/hwui/OpenGLRenderer.h
index 2fc88e1..cd9ff93 100644
--- a/libs/hwui/OpenGLRenderer.h
+++ b/libs/hwui/OpenGLRenderer.h
@@ -123,7 +123,7 @@ public:
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);
+ SkPaint* paint, float length = -1.0f);
virtual void resetShader();
virtual void setupShader(SkiaShader* shader);