[Impeller] Adds the ability to specify a golden threshold (flutter/engine#40824)
[Impeller] Adds the ability to specify a golden threshold
This commit is contained in:
@@ -1243,9 +1243,6 @@ TEST_P(AiksTest, CanRenderTextOutsideBoundaries) {
|
||||
}
|
||||
|
||||
TEST_P(AiksTest, TextRotated) {
|
||||
#ifdef IMPELLER_GOLDEN_TESTS
|
||||
GTEST_SKIP() << "Test has small differences on different mac hosts";
|
||||
#endif
|
||||
Canvas canvas;
|
||||
canvas.Transform(Matrix(0.5, -0.3, 0, -0.002, //
|
||||
0, 1, 0, 0, //
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
|
||||
#include <fstream>
|
||||
|
||||
static const double kMaxDiffPixelsPercent = 0.01;
|
||||
static const int32_t kMaxColorDelta = 8;
|
||||
|
||||
namespace impeller {
|
||||
namespace testing {
|
||||
|
||||
@@ -24,7 +27,8 @@ void GoldenDigest::AddImage(const std::string& test_name,
|
||||
const std::string& filename,
|
||||
int32_t width,
|
||||
int32_t height) {
|
||||
entries_.push_back({test_name, filename, width, height});
|
||||
entries_.push_back({test_name, filename, width, height, kMaxDiffPixelsPercent,
|
||||
kMaxColorDelta});
|
||||
}
|
||||
|
||||
bool GoldenDigest::Write(WorkingDirectory* working_directory) {
|
||||
@@ -46,8 +50,19 @@ bool GoldenDigest::Write(WorkingDirectory* working_directory) {
|
||||
<< "\"testName\" : \"" << entry.test_name << "\", "
|
||||
<< "\"filename\" : \"" << entry.filename << "\", "
|
||||
<< "\"width\" : " << entry.width << ", "
|
||||
<< "\"height\" : " << entry.height << " "
|
||||
<< "}";
|
||||
<< "\"height\" : " << entry.height << ", ";
|
||||
|
||||
if (entry.max_diff_pixels_percent ==
|
||||
static_cast<int64_t>(entry.max_diff_pixels_percent)) {
|
||||
fout << "\"maxDiffPixelsPercent\" : " << entry.max_diff_pixels_percent
|
||||
<< ".0, ";
|
||||
} else {
|
||||
fout << "\"maxDiffPixelsPercent\" : " << entry.max_diff_pixels_percent
|
||||
<< ", ";
|
||||
}
|
||||
|
||||
fout << "\"maxColorDelta\":" << entry.max_color_delta << " ";
|
||||
fout << "}";
|
||||
}
|
||||
fout << std::endl << "]" << std::endl;
|
||||
|
||||
|
||||
@@ -36,6 +36,8 @@ class GoldenDigest {
|
||||
std::string filename;
|
||||
int32_t width;
|
||||
int32_t height;
|
||||
double max_diff_pixels_percent;
|
||||
int32_t max_color_delta;
|
||||
};
|
||||
|
||||
static GoldenDigest* instance_;
|
||||
|
||||
@@ -42,10 +42,9 @@ bool SaveScreenshot(std::unique_ptr<testing::MetalScreenshot> screenshot) {
|
||||
} // namespace
|
||||
|
||||
struct GoldenPlaygroundTest::GoldenPlaygroundTestImpl {
|
||||
GoldenPlaygroundTestImpl()
|
||||
: screenshoter_(new testing::MetalScreenshoter()) {}
|
||||
std::unique_ptr<testing::MetalScreenshoter> screenshoter_;
|
||||
ISize window_size_ = ISize{1024, 768};
|
||||
GoldenPlaygroundTestImpl() : screenshoter(new testing::MetalScreenshoter()) {}
|
||||
std::unique_ptr<testing::MetalScreenshoter> screenshoter;
|
||||
ISize window_size = ISize{1024, 768};
|
||||
};
|
||||
|
||||
GoldenPlaygroundTest::GoldenPlaygroundTest()
|
||||
@@ -93,7 +92,7 @@ PlaygroundBackend GoldenPlaygroundTest::GetBackend() const {
|
||||
|
||||
bool GoldenPlaygroundTest::OpenPlaygroundHere(const Picture& picture) {
|
||||
auto screenshot =
|
||||
pimpl_->screenshoter_->MakeScreenshot(picture, pimpl_->window_size_);
|
||||
pimpl_->screenshoter->MakeScreenshot(picture, pimpl_->window_size);
|
||||
return SaveScreenshot(std::move(screenshot));
|
||||
}
|
||||
|
||||
@@ -116,11 +115,11 @@ std::shared_ptr<Texture> GoldenPlaygroundTest::CreateTextureForFixture(
|
||||
}
|
||||
|
||||
std::shared_ptr<Context> GoldenPlaygroundTest::GetContext() const {
|
||||
return pimpl_->screenshoter_->GetContext().GetContext();
|
||||
return pimpl_->screenshoter->GetContext().GetContext();
|
||||
}
|
||||
|
||||
Point GoldenPlaygroundTest::GetContentScale() const {
|
||||
return pimpl_->screenshoter_->GetPlayground().GetContentScale();
|
||||
return pimpl_->screenshoter->GetPlayground().GetContentScale();
|
||||
}
|
||||
|
||||
Scalar GoldenPlaygroundTest::GetSecondsElapsed() const {
|
||||
@@ -128,7 +127,7 @@ Scalar GoldenPlaygroundTest::GetSecondsElapsed() const {
|
||||
}
|
||||
|
||||
ISize GoldenPlaygroundTest::GetWindowSize() const {
|
||||
return pimpl_->window_size_;
|
||||
return pimpl_->window_size;
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -43,6 +43,7 @@ bool SaveScreenshot(std::unique_ptr<MetalScreenshot> screenshot) {
|
||||
return screenshot->WriteToPNG(
|
||||
WorkingDirectory::Instance()->GetFilenamePath(filename));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
class GoldenTests : public ::testing::Test {
|
||||
|
||||
@@ -23,7 +23,7 @@ class FakeSkiaGoldClient implements SkiaGoldClient {
|
||||
{double differentPixelsRate = 0.01,
|
||||
int pixelColorDelta = 0,
|
||||
required int screenshotSize}) async {
|
||||
Logger.instance.log('addImg $testName ${goldenFile.path} $screenshotSize');
|
||||
Logger.instance.log('addImg testName:$testName goldenFile:${goldenFile.path} screenshotSize:$screenshotSize differentPixelsRate:$differentPixelsRate pixelColorDelta:$pixelColorDelta');
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -32,9 +32,12 @@ Future<void> harvest(
|
||||
final String filename = (map['filename'] as String?)!;
|
||||
final int width = (map['width'] as int?)!;
|
||||
final int height = (map['height'] as int?)!;
|
||||
final double maxDiffPixelsPercent = (map['maxDiffPixelsPercent'] as double?)!;
|
||||
final int maxColorDelta = (map['maxColorDelta'] as int?)!;
|
||||
final File goldenImage = File(p.join(workDirectory.path, filename));
|
||||
final Future<void> future = skiaGoldClient
|
||||
.addImg(filename, goldenImage, screenshotSize: width * height)
|
||||
.addImg(filename, goldenImage,
|
||||
screenshotSize: width * height, differentPixelsRate: maxDiffPixelsPercent, pixelColorDelta: maxColorDelta)
|
||||
.catchError((dynamic err) {
|
||||
Logger.instance.log('skia gold comparison failed: $err');
|
||||
throw Exception('Failed comparison: $filename');
|
||||
|
||||
@@ -178,15 +178,21 @@ class SkiaGoldClient {
|
||||
/// The [testName] and [goldenFile] parameters reference the current
|
||||
/// comparison being evaluated.
|
||||
///
|
||||
/// [pixelColorDelta] defines maximum acceptable difference in RGB channels of each pixel,
|
||||
/// such that:
|
||||
/// [pixelColorDelta] defines maximum acceptable difference in RGB channels of
|
||||
/// each pixel, such that:
|
||||
///
|
||||
/// ```
|
||||
/// abs(r(image) - r(golden)) + abs(g(image) - g(golden)) + abs(b(image) - b(golden)) <= pixelDeltaThreshold
|
||||
/// bool isSame(Color image, Color golden, int pixelDeltaThreshold) {
|
||||
/// return abs(image.r - golden.r)
|
||||
/// + abs(image.g - golden.g)
|
||||
/// + abs(image.b - golden.b) <= pixelDeltaThreshold;
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// [differentPixelsRate] is the fraction of accepted pixels to be wrong in the range [0.0, 1.0].
|
||||
/// Defaults to 0.01. A value of 0.01 means that 1% of the pixels are allowed to change.
|
||||
/// [differentPixelsRate] is the fraction of pixels that can differ, as
|
||||
/// determined by the [pixelColorDelta] parameter. It's in the range [0.0,
|
||||
/// 1.0] and defaults to 0.01. A value of 0.01 means that 1% of the pixels are
|
||||
/// allowed to be different.
|
||||
Future<void> addImg(
|
||||
String testName,
|
||||
File goldenFile, {
|
||||
|
||||
Reference in New Issue
Block a user