|
|
Created:
6 years, 11 months ago by Yuki Modified:
6 years, 11 months ago CC:
chromium-reviews Base URL:
svn://svn.chromium.org/chrome/trunk/src Visibility:
Public. |
DescriptionMakes the default ctor of gfx::FontList copy the pre-calculated metrics.
Every instance of default-constructed FontList has been calling CacheCommonFontHeightAndBaseline() and CacheFontStyleAndSize(), and it's inefficient. This CL creates an instance of FontList which holds pre-calculated metrics, and copy the pre-calculated metrics in the default ctor. This change improves the performance very much.
BUG=330975
TEST=Run unit_tests, views_unittests, ui_unittests.
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=244446
Patch Set 1 #Patch Set 2 : #
Total comments: 6
Patch Set 3 : Addressed Mike's comments. #Patch Set 4 : Synced. #Patch Set 5 : Synced. #Patch Set 6 : Moved the creation of |g_default_font_list| into the default ctor. #
Total comments: 2
Patch Set 7 : Added a comment. #Patch Set 8 : Synced. #
Total comments: 2
Messages
Total messages: 28 (0 generated)
Could you guys review this CL? tony@ as the owner of /ui/base/resource/resource_bundle.cc asvitkine@ and msw@ as the main reviewers
ui/base/resource LGTM
LGTM with nits. https://codereview.chromium.org/124693003/diff/20001/ui/gfx/font_list.cc File ui/gfx/font_list.cc (right): https://codereview.chromium.org/124693003/diff/20001/ui/gfx/font_list.cc#newc... ui/gfx/font_list.cc:88: // Copy the default font list specification as well as the pre-calculated nit: s/as well as the/and its/ https://codereview.chromium.org/124693003/diff/20001/ui/gfx/font_list.cc#newc... ui/gfx/font_list.cc:147: static FontList default_font_list((Font())); nit: remove extra parens around Font(). https://codereview.chromium.org/124693003/diff/20001/ui/gfx/font_list.cc#newc... ui/gfx/font_list.cc:150: default_font_list = font_description.empty() ? nit: make this if (!font_description.empty()) default_font_list = FontList(font_description);
lgtm
Thanks for the reviews. If you have more comments, let me address them in a follow-up CL. I'll submit this CL. https://codereview.chromium.org/124693003/diff/20001/ui/gfx/font_list.cc File ui/gfx/font_list.cc (right): https://codereview.chromium.org/124693003/diff/20001/ui/gfx/font_list.cc#newc... ui/gfx/font_list.cc:88: // Copy the default font list specification as well as the pre-calculated On 2014/01/07 17:51:38, msw wrote: > nit: s/as well as the/and its/ Done. https://codereview.chromium.org/124693003/diff/20001/ui/gfx/font_list.cc#newc... ui/gfx/font_list.cc:147: static FontList default_font_list((Font())); On 2014/01/07 17:51:38, msw wrote: > nit: remove extra parens around Font(). This is necessary. Without them, it's ambiguous if it's a function declaration or a variable declaration. default_font_list may look like a function which returns a FontList and takes a Font. https://codereview.chromium.org/124693003/diff/20001/ui/gfx/font_list.cc#newc... ui/gfx/font_list.cc:150: default_font_list = font_description.empty() ? On 2014/01/07 17:51:38, msw wrote: > nit: make this if (!font_description.empty()) default_font_list = > FontList(font_description); When ui::ResourceBundle reloads the resources including fonts, SetDefaultFontDescription() was called twice and more. So we have to reset |default_font_list| according to the given |font_description|. If font_description.empty(), we should reset |default_font_list| with a font list which has a default Font.
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/yukishiino@chromium.org/124693003/90001
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/yukishiino@chromium.org/124693003/90001
Retried try job too often on linux_rel for step(s) base_unittests, browser_tests, content_browsertests, interactive_ui_tests, nacl_integration, net_unittests, sync_integration_tests, unit_tests http://build.chromium.org/p/tryserver.chromium/buildstatus?builder=linux_rel&...
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/yukishiino@chromium.org/124693003/390001
Retried try job too often on linux_rel for step(s) sync_integration_tests http://build.chromium.org/p/tryserver.chromium/buildstatus?builder=linux_rel&...
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/yukishiino@chromium.org/124693003/390001
Retried try job too often on linux_rel for step(s) browser_tests http://build.chromium.org/p/tryserver.chromium/buildstatus?builder=linux_rel&...
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/yukishiino@chromium.org/124693003/390001
Retried try job too often on linux_rel for step(s) browser_tests http://build.chromium.org/p/tryserver.chromium/buildstatus?builder=linux_rel&...
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/yukishiino@chromium.org/124693003/810001
Retried try job too often on linux_rel for step(s) interactive_ui_tests http://build.chromium.org/p/tryserver.chromium/buildstatus?builder=linux_rel&...
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/yukishiino@chromium.org/124693003/810001
Retried try job too often on linux_rel for step(s) browser_tests http://build.chromium.org/p/tryserver.chromium/buildstatus?builder=linux_rel&...
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/yukishiino@chromium.org/124693003/1210001
Retried try job too often on linux_rel for step(s) interactive_ui_tests http://build.chromium.org/p/tryserver.chromium/buildstatus?builder=linux_rel&...
I found that some of unittests don't expect that FontList::SetDefaultFontDescription() creates a new Font. Also Linux on GTK doesn't expect it. So I moved the creation of the default FontList into the default ctor of FontList. If you guys find any issues, please let me know. I'll address them. Otherwise, I'll commit this change tomorrow.
On 2014/01/09 18:02:12, Yuki wrote: > I found that some of unittests don't expect that > FontList::SetDefaultFontDescription() creates a new Font. Also Linux on GTK > doesn't expect it. Can you elaborate on what happens in those cases? I'm not sure what "don't expect" means and it seems surprising to me that it would cause problems. https://codereview.chromium.org/124693003/diff/1430001/ui/gfx/font_list.cc File ui/gfx/font_list.cc (right): https://codereview.chromium.org/124693003/diff/1430001/ui/gfx/font_list.cc#ne... ui/gfx/font_list.cc:101: if (default_font_list.GetPrimaryFont().platform_font()) { Can you add a comment explaining this if statement?
I found the following two cases that matter. There could be more. On Linux GTK, PlatformFontPango::GetDefaultFont() depends on GTK+ APIs, so GTK+ must have been initialized in advance. However, GTK+ seems not yet initialized at the time that SetDefaultFontDescription() is called. We cannot get "gtk-font-name" at the time, so we cannot create the default Font. Some of unittests don't have a resource pack, so they cannot get a proper default font description. It's okay as long as they don't use Font. However, some of unittests depends on ui::ResourceBundle (though a resource pack is not built), so SetDefaultFontDescription() is called from ui::ResourceBundle without a resource pack despite that they actually don't use Font. On CrOS, the empty default font description string makes PlatformFontPango crash. Unlike other OSs, CrOS doesn't have a way to get the OS's default font. CrOS assumes that a non-empty default font description is always supplied. In summary from my point of view, SetDefaultFontDescription() was designed just to specify a font description string, not to create an instance of Font or FontList. It's too early to create a Font when SetDefaultFontDescription() is called. https://codereview.chromium.org/124693003/diff/1430001/ui/gfx/font_list.cc File ui/gfx/font_list.cc (right): https://codereview.chromium.org/124693003/diff/1430001/ui/gfx/font_list.cc#ne... ui/gfx/font_list.cc:101: if (default_font_list.GetPrimaryFont().platform_font()) { On 2014/01/09 20:58:13, Alexei Svitkine wrote: > Can you add a comment explaining this if statement? Added a comment. Android and Linux + Ozone don't support PlatformFont for now. We cannot get any font metrics on those platforms.
https://codereview.chromium.org/124693003/diff/1590001/ui/gfx/font_list.cc File ui/gfx/font_list.cc (right): https://codereview.chromium.org/124693003/diff/1590001/ui/gfx/font_list.cc#ne... ui/gfx/font_list.cc:101: // Note that not all the platforms support PlatformFont. What happens when the metics caching functions run in those scenarios? Is it unsafe to run them and they should check this themselves, otherwise, why not just run them here?
https://codereview.chromium.org/124693003/diff/1590001/ui/gfx/font_list.cc File ui/gfx/font_list.cc (right): https://codereview.chromium.org/124693003/diff/1590001/ui/gfx/font_list.cc#ne... ui/gfx/font_list.cc:101: // Note that not all the platforms support PlatformFont. On 2014/01/10 17:54:51, msw wrote: > What happens when the metics caching functions run in those scenarios? Is it > unsafe to run them and they should check this themselves, otherwise, why not > just run them here? If PlatformFont::CreateDefault() returns NULL, all metrics getter functions are unsafe. For example, Font::GetHeight(), Font::GetExpectedTextWidth(), etc. It's not only the metrics caching functions or FontList, but also Font. Having said that, in that case, the metrics getter functions always crash because of null pointer access and it's easy to detect. So I don't think we need to check the availability of PlatformFont every time.
On 2014/01/11 09:29:06, Yuki wrote: > https://codereview.chromium.org/124693003/diff/1590001/ui/gfx/font_list.cc > File ui/gfx/font_list.cc (right): > > https://codereview.chromium.org/124693003/diff/1590001/ui/gfx/font_list.cc#ne... > ui/gfx/font_list.cc:101: // Note that not all the platforms support > PlatformFont. > On 2014/01/10 17:54:51, msw wrote: > > What happens when the metics caching functions run in those scenarios? Is it > > unsafe to run them and they should check this themselves, otherwise, why not > > just run them here? > > If PlatformFont::CreateDefault() returns NULL, all metrics getter functions are > unsafe. For example, Font::GetHeight(), Font::GetExpectedTextWidth(), etc. > It's not only the metrics caching functions or FontList, but also Font. > > Having said that, in that case, the metrics getter functions always crash > because of null pointer access and it's easy to detect. So I don't think we > need to check the availability of PlatformFont every time. Ok, lgtm
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/yukishiino@chromium.org/124693003/1590001
Message was sent while issue was closed.
Change committed as 244446 |