From 34df3d54192aeab2c814c4f11d2d6a94bffabedf Mon Sep 17 00:00:00 2001 From: Harry Terkelsen Date: Fri, 18 Jun 2021 15:24:13 -0700 Subject: [PATCH] [canvaskit] Only check missing glyphs against fallback fonts once per frame (flutter/engine#26776) --- .../src/engine/canvaskit/font_fallbacks.dart | 152 +++++++++++++- .../lib/src/engine/canvaskit/fonts.dart | 17 +- .../lib/src/engine/canvaskit/rasterizer.dart | 7 + .../web_ui/lib/src/engine/canvaskit/text.dart | 186 ++---------------- .../test/canvaskit/canvas_golden_test.dart | 3 + .../canvaskit/fallback_fonts_golden_test.dart | 99 ++++++---- .../canvaskit/skia_objects_cache_test.dart | 19 +- 7 files changed, 257 insertions(+), 226 deletions(-) diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/font_fallbacks.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/font_fallbacks.dart index 8b79933973..d6db2f5c07 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/font_fallbacks.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/font_fallbacks.dart @@ -7,7 +7,7 @@ import 'dart:convert'; import 'dart:html' as html; import 'dart:typed_data'; -import 'package:ui/src/engine.dart' show sendFontChangeMessage; +import 'package:ui/src/engine.dart'; import 'package:ui/ui.dart' as ui; import '../util.dart'; @@ -70,6 +70,151 @@ class FontFallbackData { final Map fontFallbackCounts = {}; + /// A list of code units to check against the global fallback fonts. + final Set _codeUnitsToCheckAgainstFallbackFonts = {}; + + /// This is [true] if we have scheduled a check for missing code units. + /// + /// We only do this once a frame, since checking if a font supports certain + /// code units is very expensive. + bool _scheduledCodeUnitCheck = false; + + /// Determines if the given [text] contains any code points which are not + /// supported by the current set of fonts. + void ensureFontsSupportText(String text, List fontFamilies) { + // TODO(hterkelsen): Make this faster for the common case where the text + // is supported by the given fonts. + + // If the text is ASCII, then skip this check. + bool isAscii = true; + for (int i = 0; i < text.length; i++) { + if (text.codeUnitAt(i) >= 160) { + isAscii = false; + break; + } + } + if (isAscii) { + return; + } + + // We have a cache of code units which are known to be covered by at least + // one of our fallback fonts, and a cache of code units which are known not + // to be covered by any fallback font. From the given text, construct a set + // of code units which need to be checked. + final Set runesToCheck = {}; + for (final int rune in text.runes) { + // Filter out code units which ASCII, known to be covered, or known not + // to be covered. + if (!(rune < 160 || + knownCoveredCodeUnits.contains(rune) || + codeUnitsWithNoKnownFont.contains(rune))) { + runesToCheck.add(rune); + } + } + if (runesToCheck.isEmpty) { + return; + } + + final List codeUnits = runesToCheck.toList(); + + List fonts = []; + for (var font in fontFamilies) { + List? typefacesForFamily = + skiaFontCollection.familyToFontMap[font]; + if (typefacesForFamily != null) { + fonts.addAll(typefacesForFamily); + } + } + List codeUnitsSupported = List.filled(codeUnits.length, false); + String testString = String.fromCharCodes(codeUnits); + for (SkFont font in fonts) { + Uint8List glyphs = font.getGlyphIDs(testString); + assert(glyphs.length == codeUnitsSupported.length); + for (int i = 0; i < glyphs.length; i++) { + codeUnitsSupported[i] |= glyphs[i] != 0 || _isControlCode(codeUnits[i]); + } + } + + if (codeUnitsSupported.any((x) => !x)) { + List missingCodeUnits = []; + for (int i = 0; i < codeUnitsSupported.length; i++) { + if (!codeUnitsSupported[i]) { + missingCodeUnits.add(codeUnits[i]); + } + } + _codeUnitsToCheckAgainstFallbackFonts.addAll(missingCodeUnits); + if (!_scheduledCodeUnitCheck) { + _scheduledCodeUnitCheck = true; + // ignore: invalid_use_of_visible_for_testing_member + EnginePlatformDispatcher.instance.rasterizer! + .addPostFrameCallback(_ensureFallbackFonts); + } + } + } + + /// Returns [true] if [codepoint] is a Unicode control code. + bool _isControlCode(int codepoint) { + return codepoint < 32 || (codepoint > 127 && codepoint < 160); + } + + /// Checks the missing code units against the current set of fallback fonts + /// and starts downloading new fallback fonts if the current set can't cover + /// the code units. + void _ensureFallbackFonts() { + _scheduledCodeUnitCheck = false; + // We don't know if the remaining code units are covered by our fallback + // fonts. Check them and update the cache. + List codeUnits = _codeUnitsToCheckAgainstFallbackFonts.toList(); + _codeUnitsToCheckAgainstFallbackFonts.clear(); + List codeUnitsSupported = List.filled(codeUnits.length, false); + String testString = String.fromCharCodes(codeUnits); + + for (String font in globalFontFallbacks) { + List? fontsForFamily = skiaFontCollection.familyToFontMap[font]; + if (fontsForFamily == null) { + printWarning('A fallback font was registered but we ' + 'cannot retrieve the typeface for it.'); + continue; + } + for (SkFont font in fontsForFamily) { + Uint8List glyphs = font.getGlyphIDs(testString); + assert(glyphs.length == codeUnitsSupported.length); + for (int i = 0; i < glyphs.length; i++) { + bool codeUnitSupported = glyphs[i] != 0; + if (codeUnitSupported) { + knownCoveredCodeUnits.add(codeUnits[i]); + } + codeUnitsSupported[i] |= + codeUnitSupported || _isControlCode(codeUnits[i]); + } + } + + // Once we've checked every typeface for this family, check to see if + // every code unit has been covered in order to avoid unnecessary checks. + bool keepGoing = false; + for (bool supported in codeUnitsSupported) { + if (!supported) { + keepGoing = true; + break; + } + } + + if (!keepGoing) { + return; + } + } + + // If we reached here, then there are some code units which aren't covered + // by the global fallback fonts. Remove the ones which were covered and + // try to find fallback fonts which cover them. + for (int i = codeUnits.length - 1; i >= 0; i--) { + if (codeUnitsSupported[i]) { + codeUnits.removeAt(i); + } + } + findFontsForMissingCodeunits(codeUnits); + } + void registerFallbackFont(String family, Uint8List bytes) { final SkTypeface? typeface = canvasKit.FontMgr.RefDefault().MakeTypefaceFromData(bytes); @@ -89,11 +234,6 @@ class FontFallbackData { Future findFontsForMissingCodeunits(List codeUnits) async { final FontFallbackData data = FontFallbackData.instance; - // If all of the code units are known to have no Noto Font which covers them, - // then just give up. We have already logged a warning. - if (codeUnits.every((u) => data.codeUnitsWithNoKnownFont.contains(u))) { - return; - } Set fonts = {}; Set coveredCodeUnits = {}; Set missingCodeUnits = {}; diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/fonts.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/fonts.dart index c6a094a40d..eedabac2dc 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/fonts.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/fonts.dart @@ -29,8 +29,7 @@ class SkiaFontCollection { /// Fonts which have been registered and loaded. final List _registeredFonts = []; - final Map> familyToTypefaceMap = - >{}; + final Map> familyToFontMap = >{}; Future ensureFontsLoaded() async { await _loadFonts(); @@ -40,20 +39,20 @@ class SkiaFontCollection { fontProvider = null; } fontProvider = canvasKit.TypefaceFontProvider.Make(); - familyToTypefaceMap.clear(); + familyToFontMap.clear(); for (var font in _registeredFonts) { fontProvider!.registerFont(font.bytes, font.family); - familyToTypefaceMap - .putIfAbsent(font.family, () => []) - .add(font.typeface); + familyToFontMap + .putIfAbsent(font.family, () => []) + .add(SkFont(font.typeface)); } for (var font in FontFallbackData.instance.registeredFallbackFonts) { fontProvider!.registerFont(font.bytes, font.family); - familyToTypefaceMap - .putIfAbsent(font.family, () => []) - .add(font.typeface); + familyToFontMap + .putIfAbsent(font.family, () => []) + .add(SkFont(font.typeface)); } } diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/rasterizer.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/rasterizer.dart index ccdac62ed6..d721df5c7d 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/rasterizer.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/rasterizer.dart @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'package:meta/meta.dart'; import 'package:ui/src/engine.dart' show frameReferences; import 'package:ui/ui.dart' as ui; @@ -60,4 +61,10 @@ class Rasterizer { } frameReferences.clear(); } + + /// Forces the post-frame callbacks to run. Useful in tests. + @visibleForTesting + void debugRunPostFrameCallbacks() { + _runPostFrameCallbacks(); + } } diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/text.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/text.dart index a274341d55..711e0bfebe 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/text.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/text.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:typed_data'; - import 'package:meta/meta.dart'; import 'package:ui/ui.dart' as ui; @@ -86,7 +84,8 @@ class CkParagraphStyle implements ui.ParagraphStyle { return skTextStyle; } - static SkStrutStyleProperties toSkStrutStyleProperties(ui.StrutStyle value, ui.TextHeightBehavior? paragraphHeightBehavior) { + static SkStrutStyleProperties toSkStrutStyleProperties( + ui.StrutStyle value, ui.TextHeightBehavior? paragraphHeightBehavior) { CkStrutStyle style = value as CkStrutStyle; final SkStrutStyleProperties skStrutStyle = SkStrutStyleProperties(); skStrutStyle.fontFamilies = @@ -100,7 +99,9 @@ class CkParagraphStyle implements ui.ParagraphStyle { skStrutStyle.heightMultiplier = style._height; } - final ui.TextLeadingDistribution? effectiveLeadingDistribution = style._leadingDistribution ?? paragraphHeightBehavior?.leadingDistribution; + final ui.TextLeadingDistribution? effectiveLeadingDistribution = + style._leadingDistribution ?? + paragraphHeightBehavior?.leadingDistribution; switch (effectiveLeadingDistribution) { case null: break; @@ -172,7 +173,8 @@ class CkParagraphStyle implements ui.ParagraphStyle { } if (strutStyle != null) { - properties.strutStyle = toSkStrutStyleProperties(strutStyle, textHeightBehavior); + properties.strutStyle = + toSkStrutStyleProperties(strutStyle, textHeightBehavior); } properties.textStyle = toSkTextStyleProperties( @@ -536,8 +538,7 @@ SkFontStyle toSkFontStyle(ui.FontWeight? fontWeight, ui.FontStyle? fontStyle) { /// [SynchronousSkiaObjectCache] is used that limits the number of live laid out /// paragraphs at any point in time within or outside the frame. class CkParagraph extends SkiaObject implements ui.Paragraph { - CkParagraph( - this._skParagraph, this._paragraphStyle, this._paragraphCommands); + CkParagraph(this._skParagraph, this._paragraphStyle, this._paragraphCommands); /// The result of calling `build()` on the JS CkParagraphBuilder. /// @@ -609,7 +610,8 @@ class CkParagraph extends SkiaObject implements ui.Paragraph { _maxIntrinsicWidth = paragraph.getMaxIntrinsicWidth(); _minIntrinsicWidth = paragraph.getMinIntrinsicWidth(); _width = paragraph.getMaxWidth(); - _boxesForPlaceholders = skRectsToTextBoxes(paragraph.getRectsForPlaceholders()); + _boxesForPlaceholders = + skRectsToTextBoxes(paragraph.getRectsForPlaceholders()); } catch (e) { printWarning('CanvasKit threw an exception while laying ' 'out the paragraph. The font was "${_paragraphStyle._fontFamily}". ' @@ -633,7 +635,8 @@ class CkParagraph extends SkiaObject implements ui.Paragraph { // lot of paragraphs are laid out _and_ rendered. To support // this use-case without blowing up memory usage we need this: // https://github.com/flutter/flutter/issues/81224 - static SynchronousSkiaObjectCache _paragraphCache = SynchronousSkiaObjectCache(500); + static SynchronousSkiaObjectCache _paragraphCache = + SynchronousSkiaObjectCache(500); /// Marks this paragraph as having been used this frame. /// @@ -902,176 +905,21 @@ class CkParagraphBuilder implements ui.ParagraphBuilder { return properties; } - /// Determines if the given [text] contains any code points which are not - /// supported by the current set of fonts. - void _ensureFontsSupportText(String text) { - // TODO(hterkelsen): Make this faster for the common case where the text - // is supported by the given fonts. - - // A list of unique code units in the text. - final List codeUnits = text.runes.toSet().toList(); - - // First, check if every code unit in the text is known to be covered by one - // of our global fallback fonts. We cache the set of code units covered by - // the global fallback fonts since this set is growing monotonically over - // the lifetime of the app. - if (_checkIfGlobalFallbacksSupport(codeUnits)) { - return; - } - - // Next, check if all of the remaining code units are ones which are known - // to have no global font fallback. This means we know of no font we can - // download which will cover the remaining code units. In this case we can - // just skip the checks below, since we know there's nothing we can do to - // cover the code units. - if (_checkIfNoFallbackFontSupports(codeUnits)) { - return; - } - - // If the text is ASCII, then skip this check. - bool isAscii = true; - for (int i = 0; i < text.length; i++) { - if (text.codeUnitAt(i) >= 160) { - isAscii = false; - break; - } - } - if (isAscii) { - return; - } - - CkTextStyle style = _peekStyle(); + @override + void addText(String text) { List fontFamilies = []; + CkTextStyle style = _peekStyle(); if (style.fontFamily != null) { fontFamilies.add(style.fontFamily!); } if (style.fontFamilyFallback != null) { fontFamilies.addAll(style.fontFamilyFallback!); } - List typefaces = []; - for (var font in fontFamilies) { - List? typefacesForFamily = - skiaFontCollection.familyToTypefaceMap[font]; - if (typefacesForFamily != null) { - typefaces.addAll(typefacesForFamily); - } - } - List codeUnitsSupported = List.filled(codeUnits.length, false); - String testString = String.fromCharCodes(codeUnits); - for (SkTypeface typeface in typefaces) { - SkFont font = SkFont(typeface); - Uint8List glyphs = font.getGlyphIDs(testString); - assert(glyphs.length == codeUnitsSupported.length); - for (int i = 0; i < glyphs.length; i++) { - codeUnitsSupported[i] |= glyphs[i] != 0 || _isControlCode(codeUnits[i]); - } - } - - if (codeUnitsSupported.any((x) => !x)) { - List missingCodeUnits = []; - for (int i = 0; i < codeUnitsSupported.length; i++) { - if (!codeUnitsSupported[i]) { - missingCodeUnits.add(codeUnits[i]); - } - } - findFontsForMissingCodeunits(missingCodeUnits); - } - } - - /// Returns [true] if [codepoint] is a Unicode control code. - bool _isControlCode(int codepoint) { - return codepoint < 32 || (codepoint > 127 && codepoint < 160); - } - - /// Returns `true` if every code unit in [codeUnits] is covered by a global - /// fallback font. - /// - /// Calling this method has 2 side effects: - /// 1. Updating the cache of known covered code units in the - /// [FontFallbackData] instance. - /// 2. Removing known covered code units from [codeUnits]. When the list - /// is used again in [_ensureFontsSupportText] - bool _checkIfGlobalFallbacksSupport(List codeUnits) { - final FontFallbackData fallbackData = FontFallbackData.instance; - codeUnits.removeWhere((int codeUnit) => - fallbackData.knownCoveredCodeUnits.contains(codeUnit)); - if (codeUnits.isEmpty) { - return true; - } - - // We don't know if the remaining code units are covered by our fallback - // fonts. Check them and update the cache. - List codeUnitsSupported = List.filled(codeUnits.length, false); - String testString = String.fromCharCodes(codeUnits); - - for (String font in fallbackData.globalFontFallbacks) { - List? typefacesForFamily = - skiaFontCollection.familyToTypefaceMap[font]; - if (typefacesForFamily == null) { - printWarning('A fallback font was registered but we ' - 'cannot retrieve the typeface for it.'); - continue; - } - for (SkTypeface typeface in typefacesForFamily) { - SkFont font = SkFont(typeface); - Uint8List glyphs = font.getGlyphIDs(testString); - assert(glyphs.length == codeUnitsSupported.length); - for (int i = 0; i < glyphs.length; i++) { - bool codeUnitSupported = glyphs[i] != 0; - if (codeUnitSupported) { - fallbackData.knownCoveredCodeUnits.add(codeUnits[i]); - } - codeUnitsSupported[i] |= - codeUnitSupported || _isControlCode(codeUnits[i]); - } - } - - // Once we've checked every typeface for this family, check to see if - // every code unit has been covered in order to avoid unnecessary checks. - bool keepGoing = false; - for (bool supported in codeUnitsSupported) { - if (!supported) { - keepGoing = true; - break; - } - } - - if (!keepGoing) { - // Every code unit is supported, clear [codeUnits] and return `true`. - codeUnits.clear(); - return true; - } - } - - // If we reached here, then there are some code units which aren't covered - // by the global fallback fonts. Remove the ones which were covered and - // return false. - for (int i = codeUnits.length - 1; i >= 0; i--) { - if (codeUnitsSupported[i]) { - codeUnits.removeAt(i); - } - } - return false; - } - - /// Returns `true` if every code unit in [codeUnits] is known to not have any - /// fallback font which can cover it. - /// - /// This method has a side effect of removing every code unit from [codeUnits] - /// which is known not to have a fallback font which covers it. - bool _checkIfNoFallbackFontSupports(List codeUnits) { - final FontFallbackData fallbackData = FontFallbackData.instance; - codeUnits.removeWhere((int codeUnit) => - fallbackData.codeUnitsWithNoKnownFont.contains(codeUnit)); - return codeUnits.isEmpty; - } - - @override - void addText(String text) { - _ensureFontsSupportText(text); + FontFallbackData.instance.ensureFontsSupportText(text, fontFamilies); _commands.add(_ParagraphCommand.addText(text)); _paragraphBuilder.addText(text); } + @override CkParagraph build() { final builtParagraph = _buildSkParagraph(); diff --git a/engine/src/flutter/lib/web_ui/test/canvaskit/canvas_golden_test.dart b/engine/src/flutter/lib/web_ui/test/canvaskit/canvas_golden_test.dart index 1e313f9f53..e9904ba98e 100644 --- a/engine/src/flutter/lib/web_ui/test/canvaskit/canvas_golden_test.dart +++ b/engine/src/flutter/lib/web_ui/test/canvaskit/canvas_golden_test.dart @@ -1344,6 +1344,8 @@ typedef PictureGenerator = CkPicture Function(); Future generatePictureWhenFontsStable( PictureGenerator generator) async { CkPicture picture = generator(); + // Fallback fonts start downloading as a post-frame callback. + EnginePlatformDispatcher.instance.rasterizer!.debugRunPostFrameCallbacks(); // Font downloading begins asynchronously so we inject a timer before checking the download queue. await Future.delayed(Duration.zero); while (notoDownloadQueue.isPending || @@ -1351,6 +1353,7 @@ Future generatePictureWhenFontsStable( await notoDownloadQueue.debugWhenIdle(); await notoDownloadQueue.downloader.debugWhenIdle(); picture = generator(); + EnginePlatformDispatcher.instance.rasterizer!.debugRunPostFrameCallbacks(); // Dummy timer for the same reason as above. await Future.delayed(Duration.zero); } diff --git a/engine/src/flutter/lib/web_ui/test/canvaskit/fallback_fonts_golden_test.dart b/engine/src/flutter/lib/web_ui/test/canvaskit/fallback_fonts_golden_test.dart index 49c1753b9c..2f23439eda 100644 --- a/engine/src/flutter/lib/web_ui/test/canvaskit/fallback_fonts_golden_test.dart +++ b/engine/src/flutter/lib/web_ui/test/canvaskit/fallback_fonts_golden_test.dart @@ -96,6 +96,8 @@ void testMain() { ); pb.addText('مرحبا'); + EnginePlatformDispatcher.instance.rasterizer! + .debugRunPostFrameCallbacks(); await fontChangeCompleter.future; expect(FontFallbackData.instance.globalFontFallbacks, @@ -160,6 +162,8 @@ void testMain() { ); pb.addText('Hello 😊'); + EnginePlatformDispatcher.instance.rasterizer! + .debugRunPostFrameCallbacks(); await fontChangeCompleter.future; expect(FontFallbackData.instance.globalFontFallbacks, @@ -201,6 +205,8 @@ void testMain() { pb.addText('مرحبا'); // Flush microtasks and test that we didn't start any downloads. + EnginePlatformDispatcher.instance.rasterizer! + .debugRunPostFrameCallbacks(); await Future.delayed(Duration.zero); expect(notoDownloadQueue.isPending, isFalse); @@ -210,12 +216,17 @@ void testMain() { // Regression test for https://github.com/flutter/flutter/issues/75836 // When we had this bug our font fallback resolution logic would end up in an // infinite loop and this test would freeze and time out. - test('Can find fonts for two adjacent unmatched code units from different fonts', () async { - final LoggingDownloader loggingDownloader = LoggingDownloader(NotoDownloader()); + test( + 'Can find fonts for two adjacent unmatched code units from different fonts', + () async { + final LoggingDownloader loggingDownloader = + LoggingDownloader(NotoDownloader()); notoDownloadQueue.downloader = loggingDownloader; // Try rendering text that requires fallback fonts, initially before the fonts are loaded. CkParagraphBuilder(CkParagraphStyle()).addText('ヽಠ'); + EnginePlatformDispatcher.instance.rasterizer! + .debugRunPostFrameCallbacks(); await notoDownloadQueue.downloader.debugWhenIdle(); expect( loggingDownloader.log, @@ -232,64 +243,77 @@ void testMain() { // Do the same thing but this time with loaded fonts. loggingDownloader.log.clear(); CkParagraphBuilder(CkParagraphStyle()).addText('ヽಠ'); + EnginePlatformDispatcher.instance.rasterizer! + .debugRunPostFrameCallbacks(); await notoDownloadQueue.downloader.debugWhenIdle(); expect(loggingDownloader.log, isEmpty); }); test('findMinimumFontsForCodeunits for all supported code units', () async { - final LoggingDownloader loggingDownloader = LoggingDownloader(NotoDownloader()); + final LoggingDownloader loggingDownloader = + LoggingDownloader(NotoDownloader()); notoDownloadQueue.downloader = loggingDownloader; // Collect all supported code units from all fallback fonts in the Noto // font tree. final Set testedFonts = {}; final Set supportedUniqueCodeUnits = {}; - final IntervalTree notoTree = FontFallbackData.instance.notoTree; + final IntervalTree notoTree = + FontFallbackData.instance.notoTree; for (NotoFont font in notoTree.root.enumerateAllElements()) { testedFonts.add(font.name); for (CodeunitRange range in font.approximateUnicodeRanges) { - for (int codeUnit = range.start; codeUnit < range.end; codeUnit += 1) { + for (int codeUnit = range.start; + codeUnit < range.end; + codeUnit += 1) { supportedUniqueCodeUnits.add(codeUnit); } } } - expect(supportedUniqueCodeUnits.length, greaterThan(10000)); // sanity check - expect(testedFonts, unorderedEquals({ - 'Noto Sans', - 'Noto Sans Malayalam UI', - 'Noto Sans Armenian', - 'Noto Sans Georgian', - 'Noto Sans Hebrew', - 'Noto Naskh Arabic UI', - 'Noto Sans Devanagari UI', - 'Noto Sans Telugu UI', - 'Noto Sans Tamil UI', - 'Noto Sans Kannada UI', - 'Noto Sans Sinhala', - 'Noto Sans Gurmukhi UI', - 'Noto Sans Gujarati UI', - 'Noto Sans Bengali UI', - 'Noto Sans Thai UI', - 'Noto Sans Lao UI', - 'Noto Sans Myanmar UI', - 'Noto Sans Ethiopic', - 'Noto Sans Khmer UI', - 'Noto Sans SC', - 'Noto Sans JP', - 'Noto Sans TC', - 'Noto Sans HK', - 'Noto Sans KR', - 'Noto Sans Egyptian Hieroglyphs', - })); + expect( + supportedUniqueCodeUnits.length, greaterThan(10000)); // sanity check + expect( + testedFonts, + unorderedEquals({ + 'Noto Sans', + 'Noto Sans Malayalam UI', + 'Noto Sans Armenian', + 'Noto Sans Georgian', + 'Noto Sans Hebrew', + 'Noto Naskh Arabic UI', + 'Noto Sans Devanagari UI', + 'Noto Sans Telugu UI', + 'Noto Sans Tamil UI', + 'Noto Sans Kannada UI', + 'Noto Sans Sinhala', + 'Noto Sans Gurmukhi UI', + 'Noto Sans Gujarati UI', + 'Noto Sans Bengali UI', + 'Noto Sans Thai UI', + 'Noto Sans Lao UI', + 'Noto Sans Myanmar UI', + 'Noto Sans Ethiopic', + 'Noto Sans Khmer UI', + 'Noto Sans SC', + 'Noto Sans JP', + 'Noto Sans TC', + 'Noto Sans HK', + 'Noto Sans KR', + 'Noto Sans Egyptian Hieroglyphs', + })); // Construct random paragraphs out of supported code units. final math.Random random = math.Random(0); - final List supportedCodeUnits = supportedUniqueCodeUnits.toList()..shuffle(random); + final List supportedCodeUnits = supportedUniqueCodeUnits.toList() + ..shuffle(random); const int paragraphLength = 3; - for (int batchStart = 0; batchStart < supportedCodeUnits.length; batchStart += paragraphLength) { - final int batchEnd = math.min(batchStart + paragraphLength, supportedCodeUnits.length); + for (int batchStart = 0; + batchStart < supportedCodeUnits.length; + batchStart += paragraphLength) { + final int batchEnd = + math.min(batchStart + paragraphLength, supportedCodeUnits.length); final Set codeUnits = {}; for (int i = batchStart; i < batchEnd; i += 1) { codeUnits.add(supportedCodeUnits[i]); @@ -323,7 +347,8 @@ void testMain() { class TestDownloader extends NotoDownloader { static final Map mockDownloads = {}; @override - Future downloadAsString(String url, {String? debugDescription}) async { + Future downloadAsString(String url, + {String? debugDescription}) async { if (mockDownloads.containsKey(url)) { return mockDownloads[url]!; } else { diff --git a/engine/src/flutter/lib/web_ui/test/canvaskit/skia_objects_cache_test.dart b/engine/src/flutter/lib/web_ui/test/canvaskit/skia_objects_cache_test.dart index fe753373a3..b3aa90e695 100644 --- a/engine/src/flutter/lib/web_ui/test/canvaskit/skia_objects_cache_test.dart +++ b/engine/src/flutter/lib/web_ui/test/canvaskit/skia_objects_cache_test.dart @@ -140,8 +140,10 @@ void _tests() { spy.fakeAsync.elapse(const Duration(seconds: 2)); expect( spy.printLog, - ['Engine counters:\n' - ' TestSkDeletable created: 1\n'], + [ + 'Engine counters:\n' + ' TestSkDeletable created: 1\n' + ], ); expect(clone.box.debugGetStackTraces().length, 1); @@ -165,9 +167,11 @@ void _tests() { spy.fakeAsync.elapse(const Duration(seconds: 2)); expect( spy.printLog, - ['Engine counters:\n' - ' TestSkDeletable created: 1\n' - ' TestSkDeletable deleted: 1\n'], + [ + 'Engine counters:\n' + ' TestSkDeletable created: 1\n' + ' TestSkDeletable deleted: 1\n' + ], ); Instrumentation.enabled = false; }); @@ -425,6 +429,11 @@ class FakeRasterizer implements Rasterizer { void setSkiaResourceCacheMaxBytes(int bytes) { throw UnimplementedError(); } + + @override + void debugRunPostFrameCallbacks() { + throw UnimplementedError(); + } } class TestSelfManagedObject extends SkiaObject {