[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [Git][tpo/applications/tor-browser][tor-browser-140.10.0esr-15.0-1] Bug 2009213 - Use local statics for harfbuzz callback pointers, to ensure...



Title: GitLab

Pier Angelo Vendrame pushed to branch tor-browser-140.10.0esr-15.0-1 at The Tor Project / Applications / Tor Browser

Commits:

  • 1ca1b1fb
    by Jonathan Kew at 2026-04-16T08:41:11+02:00
    Bug 2009213 - Use local statics for harfbuzz callback pointers, to ensure thread-safe initialization. r=gfx-reviewers,lsalzman
    
    Differential Revision: https://phabricator.services.mozilla.com/D278945
    

2 changed files:

Changes:

  • gfx/thebes/gfxHarfBuzzShaper.cpp
    ... ... @@ -1181,9 +1181,6 @@ static void AddOpenTypeFeature(uint32_t aTag, uint32_t aValue, void* aUserArg) {
    1181 1181
      * gfxFontShaper override to initialize the text run using HarfBuzz
    
    1182 1182
      */
    
    1183 1183
     
    
    1184
    -static hb_font_funcs_t* sHBFontFuncs = nullptr;
    
    1185
    -static hb_font_funcs_t* sNominalGlyphFunc = nullptr;
    
    1186
    -static hb_unicode_funcs_t* sHBUnicodeFuncs = nullptr;
    
    1187 1184
     MOZ_RUNINIT static const hb_script_t sMathScript =
    
    1188 1185
         hb_ot_tag_to_script(HB_TAG('m', 'a', 't', 'h'));
    
    1189 1186
     
    
    ... ... @@ -1192,52 +1189,58 @@ bool gfxHarfBuzzShaper::Initialize() {
    1192 1189
       // other thread can yet be using it.
    
    1193 1190
       MOZ_PUSH_IGNORE_THREAD_SAFETY
    
    1194 1191
     
    
    1195
    -  if (!sHBFontFuncs) {
    
    1196
    -    // static function callback pointers, initialized by the first
    
    1197
    -    // harfbuzz shaper used
    
    1198
    -    sHBFontFuncs = hb_font_funcs_create();
    
    1199
    -    hb_font_funcs_set_nominal_glyph_func(sHBFontFuncs, HBGetNominalGlyph,
    
    1200
    -                                         nullptr, nullptr);
    
    1201
    -    hb_font_funcs_set_nominal_glyphs_func(sHBFontFuncs, HBGetNominalGlyphs,
    
    1202
    -                                          nullptr, nullptr);
    
    1203
    -    hb_font_funcs_set_variation_glyph_func(sHBFontFuncs, HBGetVariationGlyph,
    
    1204
    -                                           nullptr, nullptr);
    
    1205
    -    hb_font_funcs_set_glyph_h_advance_func(sHBFontFuncs, HBGetGlyphHAdvance,
    
    1206
    -                                           nullptr, nullptr);
    
    1207
    -    hb_font_funcs_set_glyph_h_advances_func(sHBFontFuncs, HBGetGlyphHAdvances,
    
    1208
    -                                            nullptr, nullptr);
    
    1209
    -    hb_font_funcs_set_glyph_v_advance_func(sHBFontFuncs, HBGetGlyphVAdvance,
    
    1210
    -                                           nullptr, nullptr);
    
    1211
    -    hb_font_funcs_set_glyph_v_origin_func(sHBFontFuncs, HBGetGlyphVOrigin,
    
    1212
    -                                          nullptr, nullptr);
    
    1213
    -    hb_font_funcs_set_glyph_extents_func(sHBFontFuncs, HBGetGlyphExtents,
    
    1214
    -                                         nullptr, nullptr);
    
    1215
    -    hb_font_funcs_set_glyph_contour_point_func(sHBFontFuncs, HBGetContourPoint,
    
    1192
    +  // Function callback pointers; these are local statics to ensure thread-safe
    
    1193
    +  // initialization on first use.
    
    1194
    +  static hb_font_funcs_t* sHBFontFuncs = [] {
    
    1195
    +    auto* funcs = hb_font_funcs_create();
    
    1196
    +    hb_font_funcs_set_nominal_glyph_func(funcs, HBGetNominalGlyph, nullptr,
    
    1197
    +                                         nullptr);
    
    1198
    +    hb_font_funcs_set_nominal_glyphs_func(funcs, HBGetNominalGlyphs, nullptr,
    
    1199
    +                                          nullptr);
    
    1200
    +    hb_font_funcs_set_variation_glyph_func(funcs, HBGetVariationGlyph, nullptr,
    
    1201
    +                                           nullptr);
    
    1202
    +    hb_font_funcs_set_glyph_h_advance_func(funcs, HBGetGlyphHAdvance, nullptr,
    
    1203
    +                                           nullptr);
    
    1204
    +    hb_font_funcs_set_glyph_h_advances_func(funcs, HBGetGlyphHAdvances, nullptr,
    
    1205
    +                                            nullptr);
    
    1206
    +    hb_font_funcs_set_glyph_v_advance_func(funcs, HBGetGlyphVAdvance, nullptr,
    
    1207
    +                                           nullptr);
    
    1208
    +    hb_font_funcs_set_glyph_v_origin_func(funcs, HBGetGlyphVOrigin, nullptr,
    
    1209
    +                                          nullptr);
    
    1210
    +    hb_font_funcs_set_glyph_extents_func(funcs, HBGetGlyphExtents, nullptr,
    
    1211
    +                                         nullptr);
    
    1212
    +    hb_font_funcs_set_glyph_contour_point_func(funcs, HBGetContourPoint,
    
    1216 1213
                                                    nullptr, nullptr);
    
    1217
    -    hb_font_funcs_set_glyph_h_kerning_func(sHBFontFuncs, HBGetHKerning, nullptr,
    
    1214
    +    hb_font_funcs_set_glyph_h_kerning_func(funcs, HBGetHKerning, nullptr,
    
    1218 1215
                                                nullptr);
    
    1219
    -    hb_font_funcs_make_immutable(sHBFontFuncs);
    
    1220
    -
    
    1221
    -    sNominalGlyphFunc = hb_font_funcs_create();
    
    1222
    -    hb_font_funcs_set_nominal_glyph_func(sNominalGlyphFunc, HBGetNominalGlyph,
    
    1223
    -                                         nullptr, nullptr);
    
    1224
    -    hb_font_funcs_make_immutable(sNominalGlyphFunc);
    
    1225
    -
    
    1226
    -    sHBUnicodeFuncs = hb_unicode_funcs_create(hb_unicode_funcs_get_empty());
    
    1227
    -    hb_unicode_funcs_set_mirroring_func(sHBUnicodeFuncs, HBGetMirroring,
    
    1228
    -                                        nullptr, nullptr);
    
    1229
    -    hb_unicode_funcs_set_script_func(sHBUnicodeFuncs, HBGetScript, nullptr,
    
    1230
    -                                     nullptr);
    
    1231
    -    hb_unicode_funcs_set_general_category_func(
    
    1232
    -        sHBUnicodeFuncs, HBGetGeneralCategory, nullptr, nullptr);
    
    1233
    -    hb_unicode_funcs_set_combining_class_func(
    
    1234
    -        sHBUnicodeFuncs, HBGetCombiningClass, nullptr, nullptr);
    
    1235
    -    hb_unicode_funcs_set_compose_func(sHBUnicodeFuncs, HBUnicodeCompose,
    
    1236
    -                                      nullptr, nullptr);
    
    1237
    -    hb_unicode_funcs_set_decompose_func(sHBUnicodeFuncs, HBUnicodeDecompose,
    
    1238
    -                                        nullptr, nullptr);
    
    1239
    -    hb_unicode_funcs_make_immutable(sHBUnicodeFuncs);
    
    1240
    -  }
    
    1216
    +    hb_font_funcs_make_immutable(funcs);
    
    1217
    +    return funcs;
    
    1218
    +  }();
    
    1219
    +
    
    1220
    +  static hb_font_funcs_t* sNominalGlyphFunc = [] {
    
    1221
    +    auto* funcs = hb_font_funcs_create();
    
    1222
    +    hb_font_funcs_set_nominal_glyph_func(funcs, HBGetNominalGlyph, nullptr,
    
    1223
    +                                         nullptr);
    
    1224
    +    hb_font_funcs_make_immutable(funcs);
    
    1225
    +    return funcs;
    
    1226
    +  }();
    
    1227
    +
    
    1228
    +  static hb_unicode_funcs_t* sHBUnicodeFuncs = [] {
    
    1229
    +    auto* funcs = hb_unicode_funcs_create(hb_unicode_funcs_get_empty());
    
    1230
    +    hb_unicode_funcs_set_mirroring_func(funcs, HBGetMirroring, nullptr,
    
    1231
    +                                        nullptr);
    
    1232
    +    hb_unicode_funcs_set_script_func(funcs, HBGetScript, nullptr, nullptr);
    
    1233
    +    hb_unicode_funcs_set_general_category_func(funcs, HBGetGeneralCategory,
    
    1234
    +                                               nullptr, nullptr);
    
    1235
    +    hb_unicode_funcs_set_combining_class_func(funcs, HBGetCombiningClass,
    
    1236
    +                                              nullptr, nullptr);
    
    1237
    +    hb_unicode_funcs_set_compose_func(funcs, HBUnicodeCompose, nullptr,
    
    1238
    +                                      nullptr);
    
    1239
    +    hb_unicode_funcs_set_decompose_func(funcs, HBUnicodeDecompose, nullptr,
    
    1240
    +                                        nullptr);
    
    1241
    +    hb_unicode_funcs_make_immutable(funcs);
    
    1242
    +    return funcs;
    
    1243
    +  }();
    
    1241 1244
     
    
    1242 1245
       gfxFontEntry* entry = mFont->GetFontEntry();
    
    1243 1246
       if (!mUseFontGetGlyph) {
    
    ... ... @@ -1280,11 +1283,10 @@ bool gfxHarfBuzzShaper::Initialize() {
    1280 1283
       hb_buffer_set_cluster_level(mBuffer,
    
    1281 1284
                                   HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS);
    
    1282 1285
     
    
    1283
    -  auto* funcs =
    
    1284
    -      mFont->GetFontEntry()->HasFontTable(TRUETYPE_TAG('C', 'F', 'F', ' '))
    
    1285
    -          ? sNominalGlyphFunc
    
    1286
    -          : sHBFontFuncs;
    
    1287
    -  mHBFont = CreateHBFont(mFont, funcs, this);
    
    1286
    +  bool isCFF =
    
    1287
    +      mFont->GetFontEntry()->HasFontTable(TRUETYPE_TAG('C', 'F', 'F', ' '));
    
    1288
    +  auto* funcs = isCFF ? sNominalGlyphFunc : sHBFontFuncs;
    
    1289
    +  mHBFont = CreateHBFont(mFont, funcs, this, isCFF);
    
    1288 1290
     
    
    1289 1291
       MOZ_POP_THREAD_SAFETY
    
    1290 1292
     
    
    ... ... @@ -1293,12 +1295,13 @@ bool gfxHarfBuzzShaper::Initialize() {
    1293 1295
     
    
    1294 1296
     hb_font_t* gfxHarfBuzzShaper::CreateHBFont(gfxFont* aFont,
    
    1295 1297
                                                hb_font_funcs_t* aFontFuncs,
    
    1296
    -                                           void* aCallbackData) {
    
    1298
    +                                           void* aCallbackData,
    
    1299
    +                                           bool aCreateSubfont) {
    
    1297 1300
       auto face(aFont->GetFontEntry()->GetHBFace());
    
    1298 1301
       hb_font_t* result = hb_font_create(face);
    
    1299 1302
     
    
    1300 1303
       if (aFontFuncs && aCallbackData) {
    
    1301
    -    if (aFontFuncs == sNominalGlyphFunc) {
    
    1304
    +    if (aCreateSubfont) {
    
    1302 1305
           hb_font_t* subfont = hb_font_create_sub_font(result);
    
    1303 1306
           hb_font_destroy(result);
    
    1304 1307
           result = subfont;
    

  • gfx/thebes/gfxHarfBuzzShaper.h
    ... ... @@ -103,7 +103,8 @@ class gfxHarfBuzzShaper : public gfxFontShaper {
    103 103
       // bounds, etc; if not, the built-in hb_ot font functions will be used.
    
    104 104
       static hb_font_t* CreateHBFont(gfxFont* aFont,
    
    105 105
                                      hb_font_funcs_t* aFontFuncs = nullptr,
    
    106
    -                                 void* aCallbackData = nullptr);
    
    106
    +                                 void* aCallbackData = nullptr,
    
    107
    +                                 bool aCreateSubfont = false);
    
    107 108
     
    
    108 109
      protected:
    
    109 110
       // Initializes the shaper and returns whether this was successful.
    

  • _______________________________________________
    tor-commits mailing list -- tor-commits@xxxxxxxxxxxxxxxxxxxx
    To unsubscribe send an email to tor-commits-leave@xxxxxxxxxxxxxxxxxxxx