Commit 88328875 authored by arjanl's avatar arjanl Committed by Commit bot

Don't paint text outside display area

When rendering text, we don't have to render glyphs that fall outside of
the display area. This change stops processing glyps when we're outside
the display area, and stops processing further style ranges if those are
outside the display area. Note that the equivalent functionality is
already in place for Windows text rendering.

This fixes an issue where text rendering would become very slow when
rendering big strings.

BUG=413540

Review URL: https://codereview.chromium.org/543073002

Cr-Commit-Position: refs/heads/master@{#295023}
parent 41667ab1
...@@ -410,9 +410,12 @@ void RenderTextPango::DrawVisualText(Canvas* canvas) { ...@@ -410,9 +410,12 @@ void RenderTextPango::DrawVisualText(Canvas* canvas) {
internal::StyleIterator style(colors(), styles()); internal::StyleIterator style(colors(), styles());
for (GSList* it = current_line_->runs; it; it = it->next) { for (GSList* it = current_line_->runs; it; it = it->next) {
// Skip painting runs outside the display area.
if (SkScalarTruncToInt(x) >= display_rect().right())
break;
PangoLayoutRun* run = reinterpret_cast<PangoLayoutRun*>(it->data); PangoLayoutRun* run = reinterpret_cast<PangoLayoutRun*>(it->data);
int glyph_count = run->glyphs->num_glyphs; int glyph_count = run->glyphs->num_glyphs;
// TODO(msw): Skip painting runs outside the display rect area, like Win.
if (glyph_count == 0) if (glyph_count == 0)
continue; continue;
...@@ -446,9 +449,13 @@ void RenderTextPango::DrawVisualText(Canvas* canvas) { ...@@ -446,9 +449,13 @@ void RenderTextPango::DrawVisualText(Canvas* canvas) {
x += pango_units_to_double(glyph.geometry.width); x += pango_units_to_double(glyph.geometry.width);
++glyph_index; ++glyph_index;
// If this is the last glyph of the range or the last glyph inside the
// display area (which would cause early termination of the loop), paint
// the range.
const size_t glyph_text_index = (glyph_index == glyph_count) ? const size_t glyph_text_index = (glyph_index == glyph_count) ?
style_range.end() : GetGlyphTextIndex(run, glyph_index); style_range.end() : GetGlyphTextIndex(run, glyph_index);
if (!IndexInRange(style_range, glyph_text_index)) { if (!IndexInRange(style_range, glyph_text_index) ||
SkScalarTruncToInt(x) >= display_rect().right()) {
// TODO(asvitkine): For cases like "fi", where "fi" is a single glyph // TODO(asvitkine): For cases like "fi", where "fi" is a single glyph
// but can span multiple styles, Pango splits the // but can span multiple styles, Pango splits the
// styles evenly over the glyph. We can do this too by // styles evenly over the glyph. We can do this too by
...@@ -470,7 +477,10 @@ void RenderTextPango::DrawVisualText(Canvas* canvas) { ...@@ -470,7 +477,10 @@ void RenderTextPango::DrawVisualText(Canvas* canvas) {
style_start_glyph_index = glyph_index; style_start_glyph_index = glyph_index;
style_start_x = x; style_start_x = x;
} }
} while (glyph_index < glyph_count); // Terminates loop when the end of the range has been reached or the next
// glyph falls outside the display area.
} while (glyph_index < glyph_count &&
SkScalarTruncToInt(x) < display_rect().right());
} }
renderer.EndDiagonalStrike(); renderer.EndDiagonalStrike();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment