Merge "Faster text clipping"
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user