streamline system font usage across layout/gfx/widget code

NEW
Unassigned

Status

()

Core
Layout: Text
P3
normal
4 years ago
3 years ago

People

(Reporter: jtd, Unassigned)

Tracking

({perf})

Trunk
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

4 years ago
For the CSS 'font' property, there are a set of property values which are used to imply "use the system font for this type of UI element":

  font: caption | icon | menu | message-box | small-caption | status-bar

  http://www.w3.org/TR/css3-fonts/#font-prop

Gecko also supports a small set of additional prefixed values.

Within the style system these are handled as strings, the code in nsRuleNode.cpp calls LookAndFeel::GetFont for a given fontID associated with a style declaration. This is inefficient in some cases because we call the OS repeatedly for the same font type. This often involves creating a font, then assessing it's details (bold? italic? etc), then passing the name string and the style details down to gfx. The code in gfx then looks up that family and activates another copy of the same font (!!!).

I think it would be simpler and more efficient to:

1. Within LookAndFeel::GetFont, look up the system font once and cache the gfxFontStyle details for a particular system font type.

2. Instead of passing around the names, expand the enum for font type used in the FontFamily to include the set of fonts in LookAndFeel::FontID.

3. Within gfx, cache the system fonts for each font type, initializing these on demand. Since system fonts are used a lot for browser chrome, this will hopefully eliminate a lot of repeated lookups of system fonts.

Calls to LookAndFeel::GetFont for a profile with five tabs, all loaded at startup:

  20 font:  4 message-box
  19 font: 13 -moz-button
  17 font: 16 -moz-field
  10 font:  2 icon
   5 font:  3 menu
   1 font: 15 -moz-list

As part of this we should probably dump the use of separate enumerations (NS_STYLE_FONT_* vs. LookAndFeel::FontID) that need to be kept in sync.
(Reporter)

Updated

4 years ago
Priority: -- → P3
(Reporter)

Updated

4 years ago
Keywords: perf
(Reporter)

Updated

3 years ago
Assignee: jd.bugzilla → nobody
You need to log in before you can comment on or make changes to this bug.