diff options
author | asvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-06 20:13:36 +0000 |
---|---|---|
committer | asvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-06 20:13:36 +0000 |
commit | a5b9cb77a09618a5525ca398c9e2d8ddd9b554b5 (patch) | |
tree | dde927d7a2d95f5c33a98e263bc4cd6fe50cc7a8 /ui/gfx/render_text_win.cc | |
parent | 5ae6c507ee5014f71717166a3005e8396d195216 (diff) | |
download | chromium_src-a5b9cb77a09618a5525ca398c9e2d8ddd9b554b5.zip chromium_src-a5b9cb77a09618a5525ca398c9e2d8ddd9b554b5.tar.gz chromium_src-a5b9cb77a09618a5525ca398c9e2d8ddd9b554b5.tar.bz2 |
Cache a screen compatible DC to avoid re-creating it excessively.
Profiling revealed that creating and deleting the DC carries
a significant cost.
This is an important optimization when you consider the case
of ElideRectangleText(), which calls font.GetStringWidth()
on many substrings of the input string. Each such call
currently creates a temporary DC in RenderTextWin when using
canvas_skia_skia.cc.
Having a global compatible DC allows all those calls to
re-use the same DC instead of creating and deleting them.
This needs to be global because CanvasSkia::SizeStringInt()
is a static function, so we can't just store it e.g. on the canvas.
BUG=105550
TEST=CreateCompatibleDC() and DeleteDC() should disappear
from the profiler output when running with use_canvas_skia_skia=1
and rapidly clicking the SSL bubble on paypal.com
Review URL: http://codereview.chromium.org/9323011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@120594 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/render_text_win.cc')
-rw-r--r-- | ui/gfx/render_text_win.cc | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/ui/gfx/render_text_win.cc b/ui/gfx/render_text_win.cc index 28dcce8..87fa314 100644 --- a/ui/gfx/render_text_win.cc +++ b/ui/gfx/render_text_win.cc @@ -11,7 +11,7 @@ #include "base/stl_util.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" -#include "base/win/scoped_hdc.h" +#include "ui/gfx/screen_compatible_dc_win.h" #include "ui/gfx/canvas.h" #include "ui/gfx/canvas_skia.h" #include "ui/gfx/platform_font.h" @@ -595,7 +595,7 @@ void RenderTextWin::ItemizeLogicalText() { void RenderTextWin::LayoutVisualText() { HRESULT hr = E_FAIL; - base::win::ScopedCreateDC hdc(CreateCompatibleDC(NULL)); + ScopedTemporaryScreenCompatibleDC hdc; std::vector<internal::TextRun*>::const_iterator run_iter; for (run_iter = runs_.begin(); run_iter < runs_.end(); ++run_iter) { internal::TextRun* run = *run_iter; @@ -604,7 +604,7 @@ void RenderTextWin::LayoutVisualText() { bool tried_fallback = false; // Select the font desired for glyph generation. - SelectObject(hdc, run->font.GetNativeFont()); + SelectObject(hdc.get(), run->font.GetNativeFont()); run->logical_clusters.reset(new WORD[run_length]); run->glyph_count = 0; @@ -613,7 +613,7 @@ void RenderTextWin::LayoutVisualText() { while (max_glyphs < kMaxGlyphs) { run->glyphs.reset(new WORD[max_glyphs]); run->visible_attributes.reset(new SCRIPT_VISATTR[max_glyphs]); - hr = ScriptShape(hdc, + hr = ScriptShape(hdc.get(), &run->script_cache, run_text, run_length, @@ -644,10 +644,10 @@ void RenderTextWin::LayoutVisualText() { // The run's font doesn't contain the required glyphs, use an alternate. // TODO(msw): support RenderText's font_list(). - if (ChooseFallbackFont(hdc, run->font, run_text, run_length, + if (ChooseFallbackFont(hdc.get(), run->font, run_text, run_length, &run->font)) { ScriptFreeCache(&run->script_cache); - SelectObject(hdc, run->font.GetNativeFont()); + SelectObject(hdc.get(), run->font.GetNativeFont()); } tried_fallback = true; @@ -660,7 +660,7 @@ void RenderTextWin::LayoutVisualText() { if (run->glyph_count > 0) { run->advance_widths.reset(new int[run->glyph_count]); run->offsets.reset(new GOFFSET[run->glyph_count]); - hr = ScriptPlace(hdc, + hr = ScriptPlace(hdc.get(), &run->script_cache, run->glyphs.get(), run->glyph_count, |