After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 478865 - Drastically reduce number of PangoFont objects created for rotating text
Drastically reduce number of PangoFont objects created for rotating text
Status: RESOLVED FIXED
Product: pango
Classification: Platform
Component: general
unspecified
Other Linux
: Normal enhancement
: ---
Assigned To: pango-maint
pango-maint
Depends on:
Blocks:
 
 
Reported: 2007-09-21 07:52 UTC by Behdad Esfahbod
Modified: 2007-10-24 20:58 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch from toshok (1.50 KB, patch)
2007-09-21 07:55 UTC, Behdad Esfahbod
needs-work Details | Review
Committed patch (4.47 KB, patch)
2007-10-24 20:17 UTC, Behdad Esfahbod
committed Details | Review

Description Behdad Esfahbod 2007-09-21 07:52:48 UTC
Currently rotating or resizing text totally breaks down with pango calling FcFontSort() at each rotation/size...

We'll deal with size later.  For rotation, if metrics hinting is off, pangofc-fontmap.c should ignore rotation.  That is, rotate the matrix such that x,0 maps to x',0, and then use that matrix in hash lookup...  The resulting font has the same metrics as the desired font, but a scaled_font with a different ctm.  Fortunately that's not a problem as cairo_set_scaled_font() ignores scaled_font's ctm.

Toshok is telling me that an optimization to this effect has given them a boost from 20fps to 60fps in a rotating-text demo in Moonlight.
Comment 1 Behdad Esfahbod 2007-09-21 07:55:23 UTC
Created attachment 95932 [details] [review]
Patch from toshok

Unfortunately this doesn't work.  With hinted metrics, we cannot use the same font for different angles.  It can be made to work when metrics hinting is off though.  But even then the matrix should not be ignored, it may have a shear, etc...

pango_cairo_font_get_scaled_font() docs need to be updated to say that the ctm in the scaled_font may not match that of user's.
Comment 2 toshok 2007-09-21 19:39:15 UTC
we aren't using the same font, but the same FcPattern.  Those seem to be completely independent of everything in the matrix except for the scale.  I just noticed a potential problem, in that maybe we should make the hash/equal methods use something like:

      double scaled_size = key.size * scale_factor / PANGO_SCALE;

instead of just using scale_factor.

The creation of the fonts themselves still takes place as it should - and you do still get different fonts for different angles of rotations, with their own hinting/etc.  This takes place as usual in pango_fc_font_map_load_fontset (or rather in pango_fc_font_map_new_font - the place where the full matrix is applied to the FcPattern.)

The optimization just keeps us from creating new FcPatterns for each rotation.  The code to create the fontset doesn't use any part of the matrix except the scale, so there's no reason to use more than that in the hash functions.  Note that the font hash functions still use the entire matrix.  Only the fontset ones are changed.
Comment 3 Behdad Esfahbod 2007-10-24 20:15:56 UTC
2007-10-24  Behdad Esfahbod  <behdad@gnome.org>

        Bug 478865 – Drastically reduce number of PangoFont objects created
        for rotating text

        * pango/pangofc-fontmap.c (fontset_hash_key_equal),
        (fontset_hash_key_hash), (fontset_hash_key_copy),
        (get_scaled_size), (pango_fc_font_map_get_patterns):
        Only keep scaled-size in fontset hash, instead of unscaled-size
        and context matrix.

Comment 4 Behdad Esfahbod 2007-10-24 20:17:13 UTC
Created attachment 97796 [details] [review]
Committed patch

Here is what I committed.
Comment 5 Behdad Esfahbod 2007-10-24 20:58:42 UTC
2007-10-24  Behdad Esfahbod  <behdad@gnome.org>

        Bug 478865 – Drastically reduce number of PangoFont objects created
        for rotating text

        * pango/pangofc-fontmap.c (fontset_hash_key_hash),
        (get_scaled_size), (pango_fc_font_map_get_patterns):
        Use a Pango-unit int for scaled-size instead of double.
        Merges even more queries...