diff --git a/engine/src/flutter/lib/web_ui/dev/common.dart b/engine/src/flutter/lib/web_ui/dev/common.dart index b73dc7908c..89c3dcfe93 100644 --- a/engine/src/flutter/lib/web_ui/dev/common.dart +++ b/engine/src/flutter/lib/web_ui/dev/common.dart @@ -17,7 +17,6 @@ import 'safari_macos.dart'; const int kDevtoolsPort = 12345; const int kMaxScreenshotWidth = 1024; const int kMaxScreenshotHeight = 1024; -const double kMaxDiffRateFailure = 0.28 / 100; // 0.28% abstract class PlatformBinding { static PlatformBinding get instance { diff --git a/engine/src/flutter/lib/web_ui/dev/test_platform.dart b/engine/src/flutter/lib/web_ui/dev/test_platform.dart index 895df0008d..ac84a6f749 100644 --- a/engine/src/flutter/lib/web_ui/dev/test_platform.dart +++ b/engine/src/flutter/lib/web_ui/dev/test_platform.dart @@ -34,11 +34,9 @@ import 'package:test_core/src/util/io.dart'; import 'package:test_core/src/util/stack_trace_mapper.dart'; import 'package:web_socket_channel/web_socket_channel.dart'; -import 'package:web_test_utils/goldens.dart'; import 'package:web_test_utils/image_compare.dart'; import 'browser.dart'; -import 'common.dart'; import 'environment.dart' as env; /// Custom test platform that serves web engine unit tests. @@ -329,26 +327,16 @@ class BrowserPlatform extends PlatformPlugin { return shelf.Response.ok(json.encode('OK')); } - final double maxDiffRate = requestData.containsKey('maxdiffrate') - ? (requestData['maxdiffrate'] as num) - .toDouble() // can be parsed as either int or double - : kMaxDiffRateFailure; final Map region = requestData['region'] as Map; - final PixelComparison pixelComparison = PixelComparison.values.firstWhere( - (PixelComparison value) => - value.toString() == requestData['pixelComparison']); final bool isCanvaskitTest = requestData['isCanvaskitTest'] as bool; - final String result = await _diffScreenshot( - filename, maxDiffRate, region, pixelComparison, isCanvaskitTest); + final String result = await _diffScreenshot(filename, region, isCanvaskitTest); return shelf.Response.ok(json.encode(result)); } Future _diffScreenshot( String filename, - double maxDiffRateFailure, Map region, - PixelComparison pixelComparison, bool isCanvaskitTest, ) async { final Rectangle regionAsRectange = Rectangle( @@ -366,8 +354,6 @@ class BrowserPlatform extends PlatformPlugin { screenshot, doUpdateScreenshotGoldens, filename, - pixelComparison, - maxDiffRateFailure, skiaClient, isCanvaskitTest: isCanvaskitTest, ); diff --git a/engine/src/flutter/lib/web_ui/test/canvaskit/canvaskit_api_test.dart b/engine/src/flutter/lib/web_ui/test/canvaskit/canvaskit_api_test.dart index 999098e704..301da66d03 100644 --- a/engine/src/flutter/lib/web_ui/test/canvaskit/canvaskit_api_test.dart +++ b/engine/src/flutter/lib/web_ui/test/canvaskit/canvaskit_api_test.dart @@ -1570,7 +1570,6 @@ void _paragraphTests() { await matchGoldenFile( 'paragraph_kitchen_sink.png', region: const ui.Rect.fromLTRB(0, 0, 400, 160), - maxDiffRatePercent: 0.0, ); } diff --git a/engine/src/flutter/lib/web_ui/test/canvaskit/common.dart b/engine/src/flutter/lib/web_ui/test/canvaskit/common.dart index de9a299df4..8bcd58c806 100644 --- a/engine/src/flutter/lib/web_ui/test/canvaskit/common.dart +++ b/engine/src/flutter/lib/web_ui/test/canvaskit/common.dart @@ -192,7 +192,7 @@ Future matchPictureGolden(String goldenFile, CkPicture picture, sb.pushOffset(0, 0); sb.addPicture(ui.Offset.zero, picture); CanvasKitRenderer.instance.rasterizer.draw(sb.build().layerTree); - await matchGoldenFile(goldenFile, region: region, maxDiffRatePercent: 0.0); + await matchGoldenFile(goldenFile, region: region); } /// Sends a platform message to create a Platform View with the given id and viewType. diff --git a/engine/src/flutter/lib/web_ui/test/canvaskit/image_golden_test.dart b/engine/src/flutter/lib/web_ui/test/canvaskit/image_golden_test.dart index 215af2fceb..117e38dfec 100644 --- a/engine/src/flutter/lib/web_ui/test/canvaskit/image_golden_test.dart +++ b/engine/src/flutter/lib/web_ui/test/canvaskit/image_golden_test.dart @@ -514,7 +514,6 @@ void _testForImageCodecs({required bool useBrowserImageDecoder}) { await matchGoldenFile( 'canvaskit_read_back_decoded_image_$mode.png', region: const ui.Rect.fromLTRB(0, 0, 150, 150), - maxDiffRatePercent: 0, ); } @@ -566,7 +565,6 @@ void _testForImageCodecs({required bool useBrowserImageDecoder}) { await matchGoldenFile( 'canvaskit_cross_gl_context_image_$mode.png', region: const ui.Rect.fromLTRB(0, 0, 100, 100), - maxDiffRatePercent: 0, ); await disposePlatformView(0); @@ -611,7 +609,6 @@ void _testForImageCodecs({required bool useBrowserImageDecoder}) { await matchGoldenFile( 'canvaskit_picture_texture_toimage', region: const ui.Rect.fromLTRB(0, 0, 128, 128), - maxDiffRatePercent: 0, ); mandrill.dispose(); codec.dispose(); diff --git a/engine/src/flutter/lib/web_ui/test/html/bitmap_canvas_golden_test.dart b/engine/src/flutter/lib/web_ui/test/html/bitmap_canvas_golden_test.dart index ed45f6c9af..211bf44878 100644 --- a/engine/src/flutter/lib/web_ui/test/html/bitmap_canvas_golden_test.dart +++ b/engine/src/flutter/lib/web_ui/test/html/bitmap_canvas_golden_test.dart @@ -103,8 +103,7 @@ Future testMain() async { appendToScene(); - await matchGoldenFile('misaligned_canvas_test.png', region: region, - maxDiffRatePercent: 1.0); + await matchGoldenFile('misaligned_canvas_test.png', region: region); }); test('fill the whole canvas with color even when transformed', () async { @@ -117,8 +116,7 @@ Future testMain() async { appendToScene(); await matchGoldenFile('bitmap_canvas_fills_color_when_transformed.png', - region: region, - maxDiffRatePercent: 5.0); + region: region); }); test('fill the whole canvas with paint even when transformed', () async { @@ -133,8 +131,7 @@ Future testMain() async { appendToScene(); await matchGoldenFile('bitmap_canvas_fills_paint_when_transformed.png', - region: region, - maxDiffRatePercent: 5.0); + region: region); }); // This test reproduces text blurriness when two pieces of text appear inside @@ -186,8 +183,6 @@ Future testMain() async { await matchGoldenFile( 'bitmap_canvas_draws_high_quality_text.png', region: canvasSize, - maxDiffRatePercent: 0.0, - pixelComparison: PixelComparison.precise, ); }, testOn: 'chrome'); @@ -264,8 +259,6 @@ Future testMain() async { await matchGoldenFile( 'bitmap_canvas_draws_text_on_top_of_canvas.png', region: canvasSize, - maxDiffRatePercent: 1.0, - pixelComparison: PixelComparison.precise, ); }); diff --git a/engine/src/flutter/lib/web_ui/test/html/compositing/canvas_blend_golden_test.dart b/engine/src/flutter/lib/web_ui/test/html/compositing/canvas_blend_golden_test.dart index e259cfb168..537e476059 100644 --- a/engine/src/flutter/lib/web_ui/test/html/compositing/canvas_blend_golden_test.dart +++ b/engine/src/flutter/lib/web_ui/test/html/compositing/canvas_blend_golden_test.dart @@ -57,9 +57,7 @@ Future testMain() async { ..color = const Color.fromARGB(128, 255, 0, 0)); rc.restore(); - await canvasScreenshot(rc, 'canvas_blend_circle_diff_color', - maxDiffRatePercent: operatingSystem == OperatingSystem.macOs ? 2.95 : - operatingSystem == OperatingSystem.iOs ? 1.0 : 0); + await canvasScreenshot(rc, 'canvas_blend_circle_diff_color'); }); test('Blend circle and text with multiply', () async { @@ -95,9 +93,7 @@ Future testMain() async { rc.drawImage(createTestImage(), const Offset(135.0, 130.0), SurfacePaint()..blendMode = BlendMode.multiply); rc.restore(); - await canvasScreenshot(rc, 'canvas_blend_image_multiply', - maxDiffRatePercent: operatingSystem == OperatingSystem.macOs ? 2.95 : - operatingSystem == OperatingSystem.iOs ? 2.0 : 0); + await canvasScreenshot(rc, 'canvas_blend_image_multiply'); }); } diff --git a/engine/src/flutter/lib/web_ui/test/html/compositing/canvas_image_blend_mode_golden_test.dart b/engine/src/flutter/lib/web_ui/test/html/compositing/canvas_image_blend_mode_golden_test.dart index 97040dbfa7..6883fff2d3 100644 --- a/engine/src/flutter/lib/web_ui/test/html/compositing/canvas_image_blend_mode_golden_test.dart +++ b/engine/src/flutter/lib/web_ui/test/html/compositing/canvas_image_blend_mode_golden_test.dart @@ -85,8 +85,7 @@ Future testMain() async { ..colorFilter = EngineColorFilter.mode(black, blendMode)); } rc.restore(); - await canvasScreenshot(rc, 'canvas_image_blend_group$blendGroup', - maxDiffRatePercent: 8.0); + await canvasScreenshot(rc, 'canvas_image_blend_group$blendGroup'); }, skip: isSafari); } @@ -110,8 +109,7 @@ Future testMain() async { rc.drawParagraph(paragraph, const Offset(textLeft, textTop)); rc.restore(); - await canvasScreenshot(rc, 'canvas_image_blend_and_text', - maxDiffRatePercent: 8.0); + await canvasScreenshot(rc, 'canvas_image_blend_and_text'); }); } diff --git a/engine/src/flutter/lib/web_ui/test/html/compositing/color_filter_golden_test.dart b/engine/src/flutter/lib/web_ui/test/html/compositing/color_filter_golden_test.dart index 094d06a768..9d57be6d66 100644 --- a/engine/src/flutter/lib/web_ui/test/html/compositing/color_filter_golden_test.dart +++ b/engine/src/flutter/lib/web_ui/test/html/compositing/color_filter_golden_test.dart @@ -45,8 +45,7 @@ Future testMain() async { // TODO(ferhat): update golden for this test after canvas sandwich detection is // added to RecordingCanvas. - await matchGoldenFile('color_filter_blendMode_color.png', region: region, - maxDiffRatePercent: 12.0); + await matchGoldenFile('color_filter_blendMode_color.png', region: region); }); test('Should apply matrix color filter to image', () async { @@ -65,8 +64,7 @@ Future testMain() async { builder.addPicture(Offset.zero, circles1); builder.pop(); domDocument.body!.append(builder.build().webOnlyRootElement!); - await matchGoldenFile('color_filter_matrix.png', region: region, - maxDiffRatePercent: 12.0); + await matchGoldenFile('color_filter_matrix.png', region: region); }); /// Regression test for https://github.com/flutter/flutter/issues/85733 @@ -83,8 +81,7 @@ Future testMain() async { builder.addPicture(Offset.zero, circles1); builder.pop(); domDocument.body!.append(builder.build().webOnlyRootElement!); - await matchGoldenFile('color_filter_mode.png', region: region, - maxDiffRatePercent: 12.0); + await matchGoldenFile('color_filter_mode.png', region: region); }); /// Regression test for https://github.com/flutter/flutter/issues/59451. @@ -113,8 +110,7 @@ Future testMain() async { domDocument.body!.append(builder2.build().webOnlyRootElement!); await matchGoldenFile('color_filter_blendMode_overlay.png', - region: region, - maxDiffRatePercent: 12.0); + region: region); }); } diff --git a/engine/src/flutter/lib/web_ui/test/html/compositing/compositing_golden_test.dart b/engine/src/flutter/lib/web_ui/test/html/compositing/compositing_golden_test.dart index 5f81799bdf..7856d063b8 100644 --- a/engine/src/flutter/lib/web_ui/test/html/compositing/compositing_golden_test.dart +++ b/engine/src/flutter/lib/web_ui/test/html/compositing/compositing_golden_test.dart @@ -302,7 +302,7 @@ Future testMain() async { final DomElement viewElement3 = builder3.build().webOnlyRootElement!; domDocument.body!.append(viewElement3); await matchGoldenFile('compositing_physical_update_3.png', - region: region, maxDiffRatePercent: 0.8); + region: region); viewElement3.remove(); /// Update shape from arbitrary path to rect. @@ -337,8 +337,7 @@ Future testMain() async { final DomElement viewElement5 = builder5.build().webOnlyRootElement!; domDocument.body!.append(viewElement5); await matchGoldenFile('compositing_physical_update_3.png', - region: region, - maxDiffRatePercent: browserEngine == BrowserEngine.webkit ? 0.6 : 0.4); + region: region); viewElement5.remove(); /// Update shadow color. @@ -883,8 +882,6 @@ void _testCullRectComputation() { await matchGoldenFile( 'compositing_draw_high_quality_text.png', region: canvasSize, - maxDiffRatePercent: 0.0, - pixelComparison: PixelComparison.precise, ); }, testOn: 'chrome', diff --git a/engine/src/flutter/lib/web_ui/test/html/compositing/dom_mask_filter_golden_test.dart b/engine/src/flutter/lib/web_ui/test/html/compositing/dom_mask_filter_golden_test.dart index 93fa3e4fe1..17ada251ff 100644 --- a/engine/src/flutter/lib/web_ui/test/html/compositing/dom_mask_filter_golden_test.dart +++ b/engine/src/flutter/lib/web_ui/test/html/compositing/dom_mask_filter_golden_test.dart @@ -29,7 +29,6 @@ Future testMain() async { ..maskFilter = MaskFilter.blur(BlurStyle.normal, blurSigma.toDouble()); rc.drawRect(Rect.fromLTWH(15.0, 15.0 + blurSigma * 40, 200, 20), paint); } - await canvasScreenshot(rc, 'dom_mask_filter_blur', - maxDiffRatePercent: 0.01); + await canvasScreenshot(rc, 'dom_mask_filter_blur'); }); } diff --git a/engine/src/flutter/lib/web_ui/test/html/drawing/canvas_draw_image_golden_test.dart b/engine/src/flutter/lib/web_ui/test/html/drawing/canvas_draw_image_golden_test.dart index a63043778d..ad86f7ad77 100644 --- a/engine/src/flutter/lib/web_ui/test/html/drawing/canvas_draw_image_golden_test.dart +++ b/engine/src/flutter/lib/web_ui/test/html/drawing/canvas_draw_image_golden_test.dart @@ -350,7 +350,6 @@ Future testMain() async { await canvasScreenshot( rc, 'draw_text_composite_order_below', - maxDiffRatePercent: 1.1, region: const Rect.fromLTWH(0, 0, 350, 300), ); }); @@ -381,7 +380,7 @@ Future testMain() async { sceneElement.append(builder.build().webOnlyRootElement!); domDocument.body!.append(sceneElement); await matchGoldenFile('draw_nine_slice.png', - region: region, maxDiffRatePercent: 0); + region: region); } finally { // The page is reused across tests, so remove the element after taking the // Scuba screenshot. @@ -420,7 +419,7 @@ Future testMain() async { sceneElement.append(builder.build().webOnlyRootElement!); domDocument.body!.append(sceneElement); await matchGoldenFile('draw_nine_slice_empty_center.png', - region: region, maxDiffRatePercent: 0); + region: region); } finally { // The page is reused across tests, so remove the element after taking the // Scuba screenshot. @@ -446,7 +445,7 @@ Future testMain() async { ..close()); canvas.drawImage(createNineSliceImage(), Offset.zero, SurfacePaint()); await canvasScreenshot(canvas, 'draw_clipped_and_transformed_image', - region: region, maxDiffRatePercent: 1.0); + region: region); }); /// Regression test for https://github.com/flutter/flutter/issues/61245 @@ -462,7 +461,6 @@ Future testMain() async { canvas.drawImage(createTestImage(), const Offset(0, 100), SurfacePaint()); await canvasScreenshot(canvas, 'draw_3d_image', region: region, - maxDiffRatePercent: 6.0, setupPerspective: true); }); @@ -483,7 +481,6 @@ Future testMain() async { canvas.drawRect(const Rect.fromLTWH(50, 150, 50, 20), SurfacePaint()..color = const Color(0x80000000)); await canvasScreenshot(canvas, 'draw_3d_image_clipped', region: region, - maxDiffRatePercent: 5.0, setupPerspective: true); }); @@ -507,7 +504,6 @@ Future testMain() async { SurfacePaint()..color = const Color(0x80E010E0)); await canvasScreenshot(canvas, 'draw_3d_rect_clipped', region: region, - maxDiffRatePercent: 1.0, setupPerspective: true); }); @@ -532,7 +528,6 @@ Future testMain() async { canvas.drawCircle(const Offset(360, 370), 30, SurfacePaint()..color = const Color(0x80E010E0)); await canvasScreenshot(canvas, 'draw_3d_oval_clipped', region: region, - maxDiffRatePercent: 1.0, setupPerspective: true); }); @@ -564,7 +559,6 @@ Future testMain() async { canvas.drawCircle(const Offset(100, 50), 4, SurfacePaint()..color = const Color(0xFF000000)); await canvasScreenshot(canvas, 'draw_3d_path', region: region, - maxDiffRatePercent: 1.0, setupPerspective: true); }); @@ -597,7 +591,6 @@ Future testMain() async { canvas.drawCircle(const Offset(100, 50), 4, SurfacePaint()..color = const Color(0xFF000000)); await canvasScreenshot(canvas, 'draw_3d_path_clipped', region: region, - maxDiffRatePercent: 1.0, setupPerspective: true); }); } diff --git a/engine/src/flutter/lib/web_ui/test/html/paragraph/general_golden_test.dart b/engine/src/flutter/lib/web_ui/test/html/paragraph/general_golden_test.dart index 833ea835ac..4ad87aea5c 100644 --- a/engine/src/flutter/lib/web_ui/test/html/paragraph/general_golden_test.dart +++ b/engine/src/flutter/lib/web_ui/test/html/paragraph/general_golden_test.dart @@ -150,7 +150,7 @@ Future testMain() async { canvas.drawParagraph(paragraph, offset); offset = offset.translate(0, paragraph.height + 10); - return takeScreenshot(canvas, bounds, 'canvas_paragraph_align_dom', maxDiffRatePercent: 0.3); + return takeScreenshot(canvas, bounds, 'canvas_paragraph_align_dom'); }); void testAlignAndTransform(EngineCanvas canvas) { diff --git a/engine/src/flutter/lib/web_ui/test/html/paragraph/helper.dart b/engine/src/flutter/lib/web_ui/test/html/paragraph/helper.dart index bccb3a9344..05f85e63ea 100644 --- a/engine/src/flutter/lib/web_ui/test/html/paragraph/helper.dart +++ b/engine/src/flutter/lib/web_ui/test/html/paragraph/helper.dart @@ -45,9 +45,8 @@ CanvasParagraph rich( Future takeScreenshot( EngineCanvas canvas, Rect region, - String fileName, { - double? maxDiffRatePercent, -}) async { + String fileName, +) async { final DomElement sceneElement = createDomElement('flt-scene'); if (isIosSafari) { // Shrink to fit on the iPhone screen. @@ -61,7 +60,6 @@ Future takeScreenshot( await matchGoldenFile( '$fileName.png', region: region, - maxDiffRatePercent: maxDiffRatePercent, ); } finally { // The page is reused across tests, so remove the element after taking the diff --git a/engine/src/flutter/lib/web_ui/test/html/paragraph/text_scuba.dart b/engine/src/flutter/lib/web_ui/test/html/paragraph/text_scuba.dart index d84dae6c14..9bd21d7cc3 100644 --- a/engine/src/flutter/lib/web_ui/test/html/paragraph/text_scuba.dart +++ b/engine/src/flutter/lib/web_ui/test/html/paragraph/text_scuba.dart @@ -42,12 +42,10 @@ class EngineScubaTester { Future diffScreenshot( String fileName, { ui.Rect? region, - double? maxDiffRatePercent, }) async { await matchGoldenFile( '$fileName.png', region: region ?? viewportRegion, - maxDiffRatePercent: maxDiffRatePercent, ); } @@ -59,7 +57,6 @@ class EngineScubaTester { EngineCanvas canvas, String fileName, { ui.Rect? region, - double? maxDiffRatePercent, }) async { // Wrap in so that our CSS selectors kick in. final DomElement sceneElement = createDomElement('flt-scene'); @@ -79,7 +76,6 @@ class EngineScubaTester { await diffScreenshot( screenshotName, region: region, - maxDiffRatePercent: maxDiffRatePercent, ); } finally { // The page is reused across tests, so remove the element after taking the @@ -92,8 +88,7 @@ class EngineScubaTester { typedef CanvasTest = FutureOr Function(EngineCanvas canvas); /// Runs the given test [body] with each type of canvas. -void testEachCanvas(String description, CanvasTest body, - {double? maxDiffRate}) { +void testEachCanvas(String description, CanvasTest body) { const ui.Rect bounds = ui.Rect.fromLTWH(0, 0, 600, 800); test('$description (bitmap + canvas measurement)', () async { return body(BitmapCanvas(bounds, RenderStrategy())); diff --git a/engine/src/flutter/lib/web_ui/test/html/path_to_svg_golden_test.dart b/engine/src/flutter/lib/web_ui/test/html/path_to_svg_golden_test.dart index 48f321bf9d..0356f1f1d3 100644 --- a/engine/src/flutter/lib/web_ui/test/html/path_to_svg_golden_test.dart +++ b/engine/src/flutter/lib/web_ui/test/html/path_to_svg_golden_test.dart @@ -26,7 +26,6 @@ Future testMain() async { Future testPath(Path path, String scubaFileName, {SurfacePaint? paint, - double? maxDiffRatePercent, PaintMode mode = PaintMode.kStrokeAndFill}) async { const Rect canvasBounds = Rect.fromLTWH(0, 0, 600, 400); final BitmapCanvas bitmapCanvas = @@ -74,7 +73,7 @@ Future testMain() async { sceneElement.append(svgElement); await matchGoldenFile('$scubaFileName.png', - region: region, maxDiffRatePercent: maxDiffRatePercent); + region: region); bitmapCanvas.rootElement.remove(); svgElement.remove(); @@ -136,7 +135,7 @@ Future testMain() async { final Path path = Path(); path.addRect(const Rect.fromLTRB(15, 15, 60, 20)); path.addRect(const Rect.fromLTRB(35, 160, 15, 100)); - await testPath(path, 'svg_rect', maxDiffRatePercent: 1.0); + await testPath(path, 'svg_rect'); }); test('render notch', () async { diff --git a/engine/src/flutter/lib/web_ui/test/html/recording_canvas_golden_test.dart b/engine/src/flutter/lib/web_ui/test/html/recording_canvas_golden_test.dart index 747dd8eecb..98368fb836 100644 --- a/engine/src/flutter/lib/web_ui/test/html/recording_canvas_golden_test.dart +++ b/engine/src/flutter/lib/web_ui/test/html/recording_canvas_golden_test.dart @@ -701,8 +701,6 @@ Future testMain() async { await matchGoldenFile( 'paint_spread_bounds.png', region: const Rect.fromLTRB(0, 0, 250, 600), - maxDiffRatePercent: 0.21, - pixelComparison: PixelComparison.precise, ); } finally { sceneElement.remove(); diff --git a/engine/src/flutter/lib/web_ui/test/html/screenshot.dart b/engine/src/flutter/lib/web_ui/test/html/screenshot.dart index c942e876cc..cbeb620635 100644 --- a/engine/src/flutter/lib/web_ui/test/html/screenshot.dart +++ b/engine/src/flutter/lib/web_ui/test/html/screenshot.dart @@ -19,7 +19,6 @@ Future canvasScreenshot( String fileName, { ui.Rect region = const ui.Rect.fromLTWH(0, 0, 500, 500), ui.Rect? canvasRect, - double maxDiffRatePercent = 0.0, bool setupPerspective = false, }) async { canvasRect ??= region; @@ -47,7 +46,7 @@ Future canvasScreenshot( sceneElement.append(engineCanvas.rootElement); domDocument.body!.append(sceneElement); await matchGoldenFile('$fileName.png', - region: region, maxDiffRatePercent: maxDiffRatePercent); + region: region); } finally { // The page is reused across tests, so remove the element after taking the // Scuba screenshot. @@ -56,8 +55,7 @@ Future canvasScreenshot( } Future sceneScreenshot(SurfaceSceneBuilder sceneBuilder, String fileName, - {ui.Rect region = const ui.Rect.fromLTWH(0, 0, 600, 800), - double maxDiffRatePercent = 0.0}) async { + {ui.Rect region = const ui.Rect.fromLTWH(0, 0, 600, 800)}) async { DomElement? sceneElement; try { sceneElement = sceneBuilder @@ -65,7 +63,7 @@ Future sceneScreenshot(SurfaceSceneBuilder sceneBuilder, String fileName, .webOnlyRootElement; domDocument.body!.append(sceneElement!); await matchGoldenFile('$fileName.png', - region: region, maxDiffRatePercent: maxDiffRatePercent); + region: region); } finally { // The page is reused across tests, so remove the element after taking the // Scuba screenshot. diff --git a/engine/src/flutter/lib/web_ui/test/html/shaders/image_shader_golden_test.dart b/engine/src/flutter/lib/web_ui/test/html/shaders/image_shader_golden_test.dart index 55a5276c82..959f17c742 100644 --- a/engine/src/flutter/lib/web_ui/test/html/shaders/image_shader_golden_test.dart +++ b/engine/src/flutter/lib/web_ui/test/html/shaders/image_shader_golden_test.dart @@ -65,8 +65,7 @@ Future testMain() async { } Future testImageShader( - TileMode tmx, TileMode tmy, String fileName, - {double maxDiffRatePercent = 0.0}) async { + TileMode tmx, TileMode tmy, String fileName) async { final RecordingCanvas rc = RecordingCanvas(const Rect.fromLTRB(0, 0, screenWidth, screenHeight)); //Rect shaderRect = const Rect.fromLTRB(20, 20, 100, 100); @@ -80,49 +79,42 @@ Future testMain() async { expect(rc.renderStrategy.hasArbitraryPaint, isTrue); await canvasScreenshot(rc, fileName, - region: screenRect, maxDiffRatePercent: maxDiffRatePercent); + region: screenRect); } test('Should draw with tiled imageshader.', () async { await testImageShader( - TileMode.repeated, TileMode.repeated, 'image_shader_tiled', - maxDiffRatePercent: 5.0); + TileMode.repeated, TileMode.repeated, 'image_shader_tiled'); }); test('Should draw with horizontally mirrored imageshader.', () async { await testImageShader( - TileMode.mirror, TileMode.repeated, 'image_shader_horiz_mirror', - maxDiffRatePercent: 6.0); + TileMode.mirror, TileMode.repeated, 'image_shader_horiz_mirror'); }); test('Should draw with vertically mirrored imageshader.', () async { await testImageShader( - TileMode.repeated, TileMode.mirror, 'image_shader_vert_mirror', - maxDiffRatePercent: 5.0); + TileMode.repeated, TileMode.mirror, 'image_shader_vert_mirror'); }); test('Should draw with mirrored imageshader.', () async { await testImageShader( - TileMode.mirror, TileMode.mirror, 'image_shader_mirror', - maxDiffRatePercent: 6.0); + TileMode.mirror, TileMode.mirror, 'image_shader_mirror'); }); test('Should draw with horizontal clamp imageshader.', () async { await testImageShader( - TileMode.clamp, TileMode.repeated, 'image_shader_clamp_horiz', - maxDiffRatePercent: 13.0); + TileMode.clamp, TileMode.repeated, 'image_shader_clamp_horiz'); }, skip: isFirefox); test('Should draw with vertical clamp imageshader.', () async { await testImageShader( - TileMode.repeated, TileMode.clamp, 'image_shader_clamp_vertical', - maxDiffRatePercent: 1.0); + TileMode.repeated, TileMode.clamp, 'image_shader_clamp_vertical'); }, skip: isFirefox); test('Should draw with clamp imageshader.', () async { await testImageShader( - TileMode.clamp, TileMode.clamp, 'image_shader_clamp', - maxDiffRatePercent: 1.0); + TileMode.clamp, TileMode.clamp, 'image_shader_clamp'); }, skip: isFirefox); } diff --git a/engine/src/flutter/lib/web_ui/test/html/shaders/linear_gradient_golden_test.dart b/engine/src/flutter/lib/web_ui/test/html/shaders/linear_gradient_golden_test.dart index 8e22f03c85..8b0a8534eb 100644 --- a/engine/src/flutter/lib/web_ui/test/html/shaders/linear_gradient_golden_test.dart +++ b/engine/src/flutter/lib/web_ui/test/html/shaders/linear_gradient_golden_test.dart @@ -35,8 +35,7 @@ Future testMain() async { const [Color(0xFFcfdfd2), Color(0xFF042a85)]); rc.drawRect(shaderRect, paint); expect(rc.renderStrategy.hasArbitraryPaint, isTrue); - await canvasScreenshot(rc, 'linear_gradient_rect', - maxDiffRatePercent: 0.01); + await canvasScreenshot(rc, 'linear_gradient_rect'); }); test('Should blend linear gradient with alpha channel correctly.', () async { @@ -55,8 +54,7 @@ Future testMain() async { const [Color(0x00000000), Color(0xFF0000FF)]); rc.drawRect(shaderRect, paint); expect(rc.renderStrategy.hasArbitraryPaint, isTrue); - await canvasScreenshot(rc, 'linear_gradient_rect_alpha', - maxDiffRatePercent: 0.01); + await canvasScreenshot(rc, 'linear_gradient_rect_alpha'); }); test('Should draw linear gradient with transform.', () async { @@ -87,8 +85,7 @@ Future testMain() async { yOffset += 120; } expect(rc.renderStrategy.hasArbitraryPaint, isTrue); - await canvasScreenshot(rc, 'linear_gradient_oval_matrix', - maxDiffRatePercent: 0.2); + await canvasScreenshot(rc, 'linear_gradient_oval_matrix'); }); // Regression test for https://github.com/flutter/flutter/issues/50010 @@ -102,8 +99,7 @@ Future testMain() async { const [Color(0xFFcfdfd2), Color(0xFF042a85)]); rc.drawRRect(RRect.fromRectAndRadius(shaderRect, const Radius.circular(16)), paint); expect(rc.renderStrategy.hasArbitraryPaint, isTrue); - await canvasScreenshot(rc, 'linear_gradient_rounded_rect', - maxDiffRatePercent: 0.1); + await canvasScreenshot(rc, 'linear_gradient_rounded_rect'); }); test('Should draw tiled repeated linear gradient with transform.', () async { diff --git a/engine/src/flutter/lib/web_ui/test/html/shaders/radial_gradient_golden_test.dart b/engine/src/flutter/lib/web_ui/test/html/shaders/radial_gradient_golden_test.dart index 0a7aab1309..bedc35f59e 100644 --- a/engine/src/flutter/lib/web_ui/test/html/shaders/radial_gradient_golden_test.dart +++ b/engine/src/flutter/lib/web_ui/test/html/shaders/radial_gradient_golden_test.dart @@ -24,15 +24,13 @@ Future testMain() async { Future testGradient(String fileName, Shader shader, {Rect paintRect = const Rect.fromLTRB(50, 50, 300, 300), Rect shaderRect = const Rect.fromLTRB(50, 50, 300, 300), - double maxDiffRatePercent = 0, Rect region = const Rect.fromLTWH(0, 0, 500, 500)}) async { final RecordingCanvas rc = RecordingCanvas(region); final SurfacePaint paint = SurfacePaint()..shader = shader; final Path path = Path(); path.addRect(paintRect); rc.drawPath(path, paint); - await canvasScreenshot(rc, fileName, region: region, - maxDiffRatePercent: maxDiffRatePercent); + await canvasScreenshot(rc, fileName, region: region); } test('Should draw centered radial gradient.', () async { @@ -46,8 +44,7 @@ Future testMain() async { [ const Color.fromARGB(255, 0, 0, 0), const Color.fromARGB(255, 0, 0, 255) - ]), - maxDiffRatePercent: 0.2); + ])); }); test('Should draw right bottom centered radial gradient.', () async { @@ -62,7 +59,6 @@ Future testMain() async { const Color.fromARGB(255, 0, 0, 255) ], ), - maxDiffRatePercent: 0.3, ); }); @@ -81,7 +77,6 @@ Future testMain() async { [0.0, 1.0], ), shaderRect: shaderRect, - maxDiffRatePercent: 0.2, ); }); diff --git a/engine/src/flutter/lib/web_ui/test/html/shaders/shader_mask_golden_test.dart b/engine/src/flutter/lib/web_ui/test/html/shaders/shader_mask_golden_test.dart index 2fcceba1fc..20065ddef2 100644 --- a/engine/src/flutter/lib/web_ui/test/html/shaders/shader_mask_golden_test.dart +++ b/engine/src/flutter/lib/web_ui/test/html/shaders/shader_mask_golden_test.dart @@ -100,7 +100,7 @@ Future testMain() async { test('Renders text with linear gradient shader mask', () async { _renderTextScene(BlendMode.srcIn); await matchGoldenFile('shadermask_linear_text.png', - region: const Rect.fromLTWH(0, 0, 360, 200), maxDiffRatePercent: 2.0); + region: const Rect.fromLTWH(0, 0, 360, 200)); }, skip: isSafari || isFirefox); } diff --git a/engine/src/flutter/lib/web_ui/test/html/shadow_golden_test.dart b/engine/src/flutter/lib/web_ui/test/html/shadow_golden_test.dart index ddb0d2ef5e..4ca020c030 100644 --- a/engine/src/flutter/lib/web_ui/test/html/shadow_golden_test.dart +++ b/engine/src/flutter/lib/web_ui/test/html/shadow_golden_test.dart @@ -160,8 +160,6 @@ Future testMain() async { await matchGoldenFile( 'shadows.png', region: region, - maxDiffRatePercent: 0.23, - pixelComparison: PixelComparison.precise, ); }, testOn: 'chrome', diff --git a/engine/src/flutter/web_sdk/web_engine_tester/lib/golden_tester.dart b/engine/src/flutter/web_sdk/web_engine_tester/lib/golden_tester.dart index 6fe7f804e2..a03c64b15d 100644 --- a/engine/src/flutter/web_sdk/web_engine_tester/lib/golden_tester.dart +++ b/engine/src/flutter/web_sdk/web_engine_tester/lib/golden_tester.dart @@ -7,7 +7,7 @@ import 'dart:convert'; import 'package:test/test.dart'; // ignore: implementation_imports -import 'package:ui/src/engine.dart' show OperatingSystem, operatingSystem, renderer; +import 'package:ui/src/engine.dart' show renderer; // ignore: implementation_imports import 'package:ui/src/engine/dom.dart'; import 'package:ui/ui.dart'; @@ -47,8 +47,7 @@ enum PixelComparison { /// /// [pixelComparison] determines the algorithm used to compare pixels. Uses /// fuzzy comparison by default. -Future matchGoldenFile(String filename, - {Rect? region, double? maxDiffRatePercent, PixelComparison pixelComparison = PixelComparison.fuzzy}) async { +Future matchGoldenFile(String filename, {Rect? region}) async { final Map serverParams = { 'filename': filename, 'region': region == null @@ -59,7 +58,6 @@ Future matchGoldenFile(String filename, 'width': region.width, 'height': region.height }, - 'pixelComparison': pixelComparison.toString(), // We use the renderer tag here rather than `renderer is CanvasKitRenderer` // because these unit tests operate on the post-transformed (sdk_rewriter) // sdk where the internal classes like `CanvasKitRenderer` are no longer @@ -67,16 +65,6 @@ Future matchGoldenFile(String filename, 'isCanvaskitTest': renderer.rendererTag == 'canvaskit', }; - // Chrome on macOS renders slightly differently from Linux, so allow it an - // extra 1% to deviate from the golden files. - if (maxDiffRatePercent != null) { - if (operatingSystem == OperatingSystem.macOs) { - maxDiffRatePercent += 1.0; - } - serverParams['maxdiffrate'] = maxDiffRatePercent / 100; - } else if (operatingSystem == OperatingSystem.macOs) { - serverParams['maxdiffrate'] = 0.01; - } final String response = await _callScreenshotServer(serverParams) as String; if (response == 'OK') { // Pass diff --git a/engine/src/flutter/web_sdk/web_test_utils/lib/goldens.dart b/engine/src/flutter/web_sdk/web_test_utils/lib/goldens.dart deleted file mode 100644 index e39e1f7fa4..0000000000 --- a/engine/src/flutter/web_sdk/web_test_utils/lib/goldens.dart +++ /dev/null @@ -1,186 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'dart:io' as io; -import 'package:image/image.dart'; - -/// How to compares pixels within the image. -/// -/// Keep this enum in sync with the one defined in `golden_tester.dart`. -enum PixelComparison { - /// Allows minor blur and anti-aliasing differences by comparing a 3x3 grid - /// surrounding the pixel rather than direct 1:1 comparison. - fuzzy, - - /// Compares one pixel at a time. - /// - /// Anti-aliasing or blur will result in higher diff rate. - precise, -} - -void main(List args) { - final io.File fileA = io.File(args[0]); - final io.File fileB = io.File(args[1]); - final Image imageA = decodeNamedImage(fileA.readAsBytesSync(), 'a.png')!; - final Image imageB = decodeNamedImage(fileB.readAsBytesSync(), 'b.png')!; - final ImageDiff diff = ImageDiff( - golden: imageA, other: imageB, pixelComparison: PixelComparison.fuzzy); - print('Diff: ${(diff.rate * 100).toStringAsFixed(4)}%'); // ignore: avoid_print -} - -/// This class encapsulates visually diffing an Image with any other. -/// Both images need to be the exact same size. -class ImageDiff { - /// Image diff constructor which requires two [Image]s to compare and - /// [PixelComparison] algorithm. - ImageDiff({ - required this.golden, - required this.other, - required this.pixelComparison, - }) { - _computeDiff(); - } - - /// The image to match - final Image golden; - - /// The image being compared - final Image other; - - /// Algorithm used for comparing pixels. - final PixelComparison pixelComparison; - - /// The output of the comparison - /// Pixels in the output image can have 3 different colors depending on the comparison - /// between golden pixels and other pixels: - /// * white: when both pixels are the same - /// * red: when a pixel is found in other, but not in golden - /// * green: when a pixel is found in golden, but not in other - late Image diff; - - /// The ratio of wrong pixels to all pixels in golden (between 0 and 1) - /// This gets set to 1 (100% difference) when golden and other aren't the same size. - double get rate => _wrongPixels / _pixelCount; - - int _pixelCount = 0; - int _wrongPixels = 0; - - /// That would be the distance between black and white. - static final double _maxTheoreticalColorDistance = Color.distance( - [255, 255, 255], // white - [0, 0, 0], // black - false, - ).toDouble(); - - // If the normalized color difference of a pixel is greater than this number, - // we consider it a wrong pixel. - static const double _kColorDistanceThreshold = 0.1; - - final int _colorOk = Color.fromRgb(255, 255, 255); - final int _colorBadPixel = Color.fromRgb(255, 0, 0); - final int _colorExpectedPixel = Color.fromRgb(0, 255, 0); - - /// Reads a pixel value out of [image] at [x] and [y]. - /// - /// If the pixel is out of bounds, reflects the [x] and [y] coordinates off - /// the border back into the image treating the border like a mirror. - static int _reflectedPixel(Image image, int x, int y) { - x = x.abs(); - if (x == image.width) { - x = image.width - 2; - } - - y = y.abs(); - if (y == image.height) { - y = image.height - 2; - } - - return image.getPixel(x, y); - } - - static int _average(Iterable values) { - return values.reduce((int a, int b) => a + b) ~/ values.length; - } - - /// The value of the pixel at [x] and [y] coordinates. - /// - /// If [pixelComparison] is [PixelComparison.precise], reads the RGB value of - /// the pixel. - /// - /// If [pixelComparison] is [PixelComparison.fuzzy], reads the RGB values of - /// the average of the 3x3 box of pixels centered at [x] and [y]. - List _getPixelRgbForComparison(Image image, int x, int y) { - switch (pixelComparison) { - case PixelComparison.fuzzy: - final List pixels = [ - _reflectedPixel(image, x - 1, y - 1), - _reflectedPixel(image, x - 1, y), - _reflectedPixel(image, x - 1, y + 1), - _reflectedPixel(image, x, y - 1), - _reflectedPixel(image, x, y), - _reflectedPixel(image, x, y + 1), - _reflectedPixel(image, x + 1, y - 1), - _reflectedPixel(image, x + 1, y), - _reflectedPixel(image, x + 1, y + 1), - ]; - return [ - _average(pixels.map((int p) => getRed(p))), - _average(pixels.map((int p) => getGreen(p))), - _average(pixels.map((int p) => getBlue(p))), - ]; - case PixelComparison.precise: - final int pixel = image.getPixel(x, y); - return [ - getRed(pixel), - getGreen(pixel), - getBlue(pixel), - ]; - } - } - - void _computeDiff() { - final int goldenWidth = golden.width; - final int goldenHeight = golden.height; - - _pixelCount = goldenWidth * goldenHeight; - diff = Image(goldenWidth, goldenHeight); - - if (goldenWidth == other.width && goldenHeight == other.height) { - for (int y = 0; y < goldenHeight; y++) { - for (int x = 0; x < goldenWidth; x++) { - final bool isExactlySame = - golden.getPixel(x, y) == other.getPixel(x, y); - final List goldenPixel = _getPixelRgbForComparison(golden, x, y); - final List otherPixel = _getPixelRgbForComparison(other, x, y); - final double colorDistance = - Color.distance(goldenPixel, otherPixel, false) / - _maxTheoreticalColorDistance; - final bool isFuzzySame = colorDistance < _kColorDistanceThreshold; - if (isExactlySame || isFuzzySame) { - diff.setPixel(x, y, _colorOk); - } else { - final int goldenLuminance = - getLuminanceRgb(goldenPixel[0], goldenPixel[1], goldenPixel[2]); - final int otherLuminance = - getLuminanceRgb(otherPixel[0], otherPixel[1], otherPixel[2]); - if (goldenLuminance < otherLuminance) { - diff.setPixel(x, y, _colorExpectedPixel); - } else { - diff.setPixel(x, y, _colorBadPixel); - } - _wrongPixels++; - } - } - } - } else { - // Images are completely different resolutions. Bail out big time. - _wrongPixels = _pixelCount; - } - } -} - -/// Returns text explaining pixel difference rate. -String getPrintableDiffFilesInfo(double diffRate, double maxRate) => - '(${(diffRate * 100).toStringAsFixed(4)}% of pixels were different. ' - 'Maximum allowed rate is: ${(maxRate * 100).toStringAsFixed(4)}%).'; diff --git a/engine/src/flutter/web_sdk/web_test_utils/lib/image_compare.dart b/engine/src/flutter/web_sdk/web_test_utils/lib/image_compare.dart index aeadee1863..c2ac523552 100644 --- a/engine/src/flutter/web_sdk/web_test_utils/lib/image_compare.dart +++ b/engine/src/flutter/web_sdk/web_test_utils/lib/image_compare.dart @@ -9,7 +9,6 @@ import 'package:path/path.dart' as p; import 'package:skia_gold_client/skia_gold_client.dart'; import 'environment.dart'; -import 'goldens.dart'; /// Compares a screenshot taken through a test with its golden. /// @@ -23,8 +22,6 @@ Future compareImage( Image screenshot, bool doUpdateScreenshotGoldens, String filename, - PixelComparison pixelComparison, - double maxDiffRateFailure, SkiaGoldClient? skiaClient, { required bool isCanvaskitTest, }) async { @@ -76,75 +73,8 @@ Future compareImage( return 'OK'; } - // Compare screenshots. - final ImageDiff diff = ImageDiff( - golden: golden, - other: screenshot, - pixelComparison: pixelComparison, - ); + // TODO(mdebbar): Use the Gold tool to locally diff the golden. - if (diff.rate > 0) { - final String testResultsPath = environment.webUiTestResultsDirectory.path; - Directory(testResultsPath).createSync(recursive: true); - final String basename = p.basenameWithoutExtension(filename); - - final File actualFile = - File(p.join(testResultsPath, '$basename.actual.png')); - actualFile.writeAsBytesSync(encodePng(screenshot), flush: true); - - final File diffFile = File(p.join(testResultsPath, '$basename.diff.png')); - diffFile.writeAsBytesSync(encodePng(diff.diff), flush: true); - - final File expectedFile = - File(p.join(testResultsPath, '$basename.expected.png')); - screenshotFile.copySync(expectedFile.path); - - final File reportFile = - File(p.join(testResultsPath, '$basename.report.html')); - reportFile.writeAsStringSync(''' -Golden file $filename did not match the image generated by the test. - - - - - - - - - - - - -
ExpectedDiffActual
- - - - - -
-'''); - - final StringBuffer message = StringBuffer(); - message.writeln( - 'Golden file $filename did not match the image generated by the test.'); - message.writeln(getPrintableDiffFilesInfo(diff.rate, maxDiffRateFailure)); - message.writeln('You can view the test report in your browser by opening:'); - - final String localReportPath = '$testResultsPath/$basename.report.html'; - message.writeln(localReportPath); - message.writeln('Golden file: ${expectedFile.path}'); - message.writeln('Actual file: ${actualFile.path}'); - - if (diff.rate < maxDiffRateFailure) { - // Issue a warning but do not fail the test. - print('WARNING:'); // ignore: avoid_print - print(message); // ignore: avoid_print - return 'OK'; - } else { - // Fail test - return '$message'; - } - } return 'OK'; }