This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] Skia gold for flutter_tester dart tests. #47066
Merged
Merged
Changes from 25 commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
907d101
Skia gold for dart tests
dnfield a363fd1
analysis
dnfield cac8ef6
merge
dnfield adbf750
package locations
dnfield 8b9b14f
more
dnfield 4d97460
syntax...
dnfield f90fa53
smp 1
dnfield 003d82a
more
dnfield de6c217
more print
dnfield 1f536fc
sadness
dnfield 696f55a
reversions
dnfield 61294eb
delete file
dnfield 9a56340
Merge remote-tracking branch 'upstream/main' into gold
dnfield 7bcd6da
Try less multiprocessing?
dnfield a2a199d
merge
dnfield 7baf8fd
reduce cases, avoid collisions for SMP
dnfield dd5207f
oops
dnfield f22b78d
fix test suite name
dnfield 008fc30
unique
dnfield 41c5b4b
verbose
dnfield 5775f31
actually verbose
dnfield 4bb2cba
fix
dnfield 4e00412
missing file
dnfield b87ff9d
ok
dnfield 85efbb3
simplify
dnfield 2795751
Merge remote-tracking branch 'upstream/main' into gold
dnfield 0dca473
merge
dnfield e9ac142
verbose true
dnfield e3aebc4
no fuzzy?
dnfield be22658
more
dnfield 6856c53
debug
dnfield 633260b
littest?
dnfield fc2ff4f
?
dnfield 31598d3
wut
dnfield da8e777
more debug
dnfield b335c07
try this
dnfield e792bb6
fix async?
dnfield 268af9a
ok
dnfield 1f6c3a2
...
dnfield 3d47777
Engine checkout path var name
dnfield 678b8a9
see if we can live without litetest changes
dnfield 48f28b5
unused import
dnfield 557980b
Merge remote-tracking branch 'upstream/main' into gold
dnfield ab92d49
zanderso review
dnfield 7de9ca7
override for harvester
dnfield 65d8433
more
dnfield f0ed06b
last one
dnfield 6180f24
fix web_ui
dnfield 8db70f3
...one more for web
dnfield File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| // 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'; | ||
| import 'dart:typed_data'; | ||
| import 'dart:ui'; | ||
|
|
||
| import 'package:path/path.dart' as path; | ||
| import 'package:skia_gold_client/skia_gold_client.dart'; | ||
|
|
||
| import 'impeller_enabled.dart'; | ||
|
|
||
| const String _kSkiaGoldWorkDirectoryKey = 'kSkiaGoldWorkDirectory'; | ||
|
|
||
| /// A helper for doing image comparison (golden) tests. | ||
| /// | ||
| /// Contains utilities for comparing two images in memory that are expected to | ||
| /// be identical, or for adding images to Skia gold for comparison. | ||
| class ImageComparer { | ||
| ImageComparer._({ | ||
| required SkiaGoldClient client, | ||
| }) : _client = client; | ||
|
|
||
| // Avoid talking to Skia gold for the force-multithreading variants. | ||
| static bool get _useSkiaGold => | ||
| !Platform.executableArguments.contains('--force-multithreading'); | ||
|
|
||
| /// Creates an image comparer and authorizes. | ||
| static Future<ImageComparer> create({ | ||
| bool verbose = false, | ||
| }) async { | ||
| const String workDirectoryPath = | ||
| String.fromEnvironment(_kSkiaGoldWorkDirectoryKey); | ||
| if (workDirectoryPath.isEmpty) { | ||
| throw UnsupportedError( | ||
| 'Using ImageComparer requries defining kSkiaGoldWorkDirectoryKey.'); | ||
| } | ||
|
|
||
| final Directory workDirectory = Directory( | ||
| impellerEnabled ? '${workDirectoryPath}_iplr' : workDirectoryPath, | ||
| )..createSync(); | ||
| final Map<String, String> dimensions = <String, String>{ | ||
| 'impeller_enabled': impellerEnabled.toString(), | ||
| }; | ||
| final SkiaGoldClient client = isSkiaGoldClientAvailable && _useSkiaGold | ||
| ? SkiaGoldClient(workDirectory, | ||
| dimensions: dimensions, verbose: verbose) | ||
| : _FakeSkiaGoldClient(workDirectory, dimensions, verbose: verbose); | ||
|
|
||
| await client.auth(); | ||
| return ImageComparer._(client: client); | ||
| } | ||
|
|
||
| final SkiaGoldClient _client; | ||
|
|
||
| /// Adds an [Image] to Skia Gold for comparison. | ||
| /// | ||
| /// The [fileName] must be unique. | ||
| Future<void> addGoldenImage(Image image, String fileName) async { | ||
| final ByteData data = | ||
| (await image.toByteData(format: ImageByteFormat.png))!; | ||
|
|
||
| final File file = File(path.join(_client.workDirectory.path, fileName)) | ||
| ..writeAsBytesSync(data.buffer.asUint8List()); | ||
| await _client.addImg( | ||
| fileName, | ||
| file, | ||
| screenshotSize: image.width * image.height, | ||
| ).catchError((dynamic error) { | ||
| print('Skia gold comparison failed: $error'); | ||
| throw Exception('Failed comparison: $fileName'); | ||
| }); | ||
| } | ||
|
|
||
| Future<bool> fuzzyCompareImages(Image golden, Image testImage) async { | ||
| if (golden.width != testImage.width || golden.height != testImage.height) { | ||
| return false; | ||
| } | ||
| int getPixel(ByteData data, int x, int y) => | ||
| data.getUint32((x + y * golden.width) * 4); | ||
| final ByteData goldenData = (await golden.toByteData())!; | ||
| final ByteData testImageData = (await testImage.toByteData())!; | ||
| for (int y = 0; y < golden.height; y++) { | ||
| for (int x = 0; x < golden.width; x++) { | ||
| if (getPixel(goldenData, x, y) != getPixel(testImageData, x, y)) { | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| // TODO(dnfield): add local comparison against baseline, | ||
| // https://github.com/flutter/flutter/issues/136831 | ||
| class _FakeSkiaGoldClient implements SkiaGoldClient { | ||
| _FakeSkiaGoldClient( | ||
| this.workDirectory, | ||
| this.dimensions, { | ||
| this.verbose = false, | ||
| }); | ||
|
|
||
| @override | ||
| final Directory workDirectory; | ||
|
|
||
| @override | ||
| final Map<String, String> dimensions; | ||
|
|
||
| @override | ||
| final bool verbose; | ||
|
|
||
| @override | ||
| Future<void> auth() async {} | ||
|
|
||
| @override | ||
| Future<void> addImg( | ||
| String testName, | ||
| File goldenFile, { | ||
| double differentPixelsRate = 0.01, | ||
| int pixelColorDelta = 0, | ||
| required int screenshotSize, | ||
| }) async {} | ||
|
|
||
| @override | ||
| dynamic noSuchMethod(Invocation invocation) { | ||
| throw UnimplementedError(invocation.memberName.toString().split('"')[1]); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-5.86 KB
testing/resources/dotted_path_effect_mixed_with_stroked_geometry.png
Binary file not shown.
Binary file not shown.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, this is getting bumped in #47391 to 720a542f6fe4f92922c3b8f0fdcc4d2ac6bb83cd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the Linux one also be the same hash?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked at the PR and see that it should be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!