Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e27a07d4 authored by Romain Guy's avatar Romain Guy Committed by Android (Google) Code Review
Browse files

Merge "Faster text clipping"

parents a2a56f82 cac5fd3e
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -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() {
+1 −1
Original line number Diff line number Diff line
@@ -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);
+10 −4
Original line number Diff line number Diff line
@@ -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();
+1 −1
Original line number Diff line number Diff line
@@ -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);