diff options
author | arjanl <arjanl@opera.com> | 2014-09-16 00:14:40 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-16 07:15:37 +0000 |
commit | 88328875c41317c728a20b78308218c176a6ee72 (patch) | |
tree | 2105e227c3adff73618a2c0b2fdd676a1b852415 | |
parent | 41667ab15bb40d84459acf3139f19178bed48778 (diff) | |
download | chromium_src-88328875c41317c728a20b78308218c176a6ee72.zip chromium_src-88328875c41317c728a20b78308218c176a6ee72.tar.gz chromium_src-88328875c41317c728a20b78308218c176a6ee72.tar.bz2 |
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}
-rw-r--r-- | ui/gfx/render_text_pango.cc | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/ui/gfx/render_text_pango.cc b/ui/gfx/render_text_pango.cc index 07cbfb9..27f0046 100644 --- a/ui/gfx/render_text_pango.cc +++ b/ui/gfx/render_text_pango.cc @@ -410,9 +410,12 @@ void RenderTextPango::DrawVisualText(Canvas* canvas) { internal::StyleIterator style(colors(), styles()); 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); int glyph_count = run->glyphs->num_glyphs; - // TODO(msw): Skip painting runs outside the display rect area, like Win. if (glyph_count == 0) continue; @@ -446,9 +449,13 @@ void RenderTextPango::DrawVisualText(Canvas* canvas) { x += pango_units_to_double(glyph.geometry.width); ++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) ? 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 // but can span multiple styles, Pango splits the // styles evenly over the glyph. We can do this too by @@ -470,7 +477,10 @@ void RenderTextPango::DrawVisualText(Canvas* canvas) { style_start_glyph_index = glyph_index; 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(); |