summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorasvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-03 18:15:49 +0000
committerasvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-03 18:15:49 +0000
commitadd1cca97a1d5de2f096fc8101f04a5026a97266 (patch)
treef5422b0a742dccaaeb7322294f390cf49863d7d4
parent49a67aeca61fe7d6c101e5618a4ad4b090dcc997 (diff)
downloadchromium_src-add1cca97a1d5de2f096fc8101f04a5026a97266.zip
chromium_src-add1cca97a1d5de2f096fc8101f04a5026a97266.tar.gz
chromium_src-add1cca97a1d5de2f096fc8101f04a5026a97266.tar.bz2
Avoid excessive calls to DeriveFont() in RenderTextWin.
This is a performance optimization. PlatformFontWin::DeriveFont() is slow because it calls GetTextMetrics() and GetTextExtentPoint32() from PlatformFontWin::CreateHFontRef(). BUG=105550 TEST=Build Chrome Windows with use_canvas_skia_skia=1. Go to paypal.com and click on the SSL box in the omnibox. The SSL bubble that is brought up should be much less janky. Review URL: http://codereview.chromium.org/9314044 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@120353 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ui/gfx/render_text_win.cc37
-rw-r--r--ui/gfx/render_text_win.h2
2 files changed, 20 insertions, 19 deletions
diff --git a/ui/gfx/render_text_win.cc b/ui/gfx/render_text_win.cc
index 182c9ad..28dcce8 100644
--- a/ui/gfx/render_text_win.cc
+++ b/ui/gfx/render_text_win.cc
@@ -75,10 +75,7 @@ bool ChooseFallbackFont(HDC hdc,
log_font.lfFaceName[0] = 0;
EnumEnhMetaFile(0, meta_file, MetaFileEnumProc, &log_font, NULL);
if (log_font.lfFaceName[0]) {
- int font_style = font.GetStyle();
*result = gfx::Font(UTF16ToUTF8(log_font.lfFaceName), font.GetFontSize());
- if (result->GetStyle() != font_style)
- *result = result->DeriveFont(0, font_style);
found_fallback = true;
}
}
@@ -468,6 +465,7 @@ void RenderTextWin::DrawVisualText(Canvas* canvas) {
}
renderer.SetFont(run->font);
+ renderer.SetFontStyle(run->font_style);
renderer.SetForegroundColor(run->foreground);
renderer.DrawPosText(&pos[0], run->glyphs.get(), run->glyph_count);
// TODO(oshima|msw): Consider refactoring StyleRange into Style
@@ -574,7 +572,8 @@ void RenderTextWin::ItemizeLogicalText() {
for (int run_break = 0; run_break < text_length;) {
internal::TextRun* run = new internal::TextRun();
run->range.set_start(run_break);
- run->font = GetFont().DeriveFont(0, style->font_style);
+ run->font = GetFont();
+ run->font_style = style->font_style;
run->foreground = style->foreground;
run->strike = style->strike;
run->diagonal_strike = style->diagonal_strike;
@@ -627,21 +626,21 @@ void RenderTextWin::LayoutVisualText() {
if (hr == E_OUTOFMEMORY) {
max_glyphs *= 2;
} else if (hr == USP_E_SCRIPT_NOT_IN_FONT) {
- // Only try font fallback if it hasn't yet been attempted for this run.
- if (tried_fallback) {
- // TODO(msw): Don't use SCRIPT_UNDEFINED. Apparently Uniscribe can
- // crash on certain surrogate pairs with SCRIPT_UNDEFINED.
- // See https://bugzilla.mozilla.org/show_bug.cgi?id=341500
- // And http://maxradi.us/documents/uniscribe/
- run->script_analysis.eScript = SCRIPT_UNDEFINED;
- // Reset |hr| to 0 to not trigger the DCHECK() below when a font is
- // not found that can display the text. This is expected behavior
- // under Windows XP without additional language packs installed and
- // may also happen on newer versions when trying to display text in
- // an obscure script that the system doesn't have the right font for.
- hr = 0;
- break;
- }
+ // Only try font fallback if it hasn't yet been attempted for this run.
+ if (tried_fallback) {
+ // TODO(msw): Don't use SCRIPT_UNDEFINED. Apparently Uniscribe can
+ // crash on certain surrogate pairs with SCRIPT_UNDEFINED.
+ // See https://bugzilla.mozilla.org/show_bug.cgi?id=341500
+ // And http://maxradi.us/documents/uniscribe/
+ run->script_analysis.eScript = SCRIPT_UNDEFINED;
+ // Reset |hr| to 0 to not trigger the DCHECK() below when a font is
+ // not found that can display the text. This is expected behavior
+ // under Windows XP without additional language packs installed and
+ // may also happen on newer versions when trying to display text in
+ // an obscure script that the system doesn't have the right font for.
+ hr = 0;
+ break;
+ }
// The run's font doesn't contain the required glyphs, use an alternate.
// TODO(msw): support RenderText's font_list().
diff --git a/ui/gfx/render_text_win.h b/ui/gfx/render_text_win.h
index f2c3d72..1ec862b 100644
--- a/ui/gfx/render_text_win.h
+++ b/ui/gfx/render_text_win.h
@@ -28,6 +28,8 @@ struct TextRun {
// See the example at: http://www.catch22.net/tuts/neatpad/12.
SkColor foreground;
// A gfx::Font::FontStyle flag to specify bold and italic styles.
+ // Supercedes |font.GetFontStyle()|. Stored separately to avoid calling
+ // |font.DeriveFont()|, which is expensive on Windows.
int font_style;
bool strike;
bool diagonal_strike;