Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion impeller/aiks/aiks_playground.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ AiksPlayground::AiksPlayground() = default;

AiksPlayground::~AiksPlayground() = default;

bool AiksPlayground::OpenPlaygroundHere(const Picture& picture) {
bool AiksPlayground::OpenPlaygroundHere(const Picture& picture,
double threshold) {
return OpenPlaygroundHere(
[&picture](AiksContext& renderer, RenderTarget& render_target) -> bool {
return renderer.Render(picture, render_target);
Expand Down
2 changes: 1 addition & 1 deletion impeller/aiks/aiks_playground.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class AiksPlayground : public PlaygroundTest {

~AiksPlayground();

bool OpenPlaygroundHere(const Picture& picture);
bool OpenPlaygroundHere(const Picture& picture, double threshold = 0.01);

bool OpenPlaygroundHere(AiksPlaygroundCallback callback);

Expand Down
6 changes: 2 additions & 4 deletions impeller/aiks/aiks_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1317,9 +1317,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, //
Expand All @@ -1330,7 +1327,8 @@ TEST_P(AiksTest, TextRotated) {
GetContext(), canvas, "the quick brown fox jumped over the lazy dog!.?",
"Roboto-Regular.ttf"));

ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
ASSERT_TRUE(
OpenPlaygroundHere(canvas.EndRecordingAsPicture(), /*threshold=*/0.1));
}

TEST_P(AiksTest, CanDrawPaint) {
Expand Down
16 changes: 12 additions & 4 deletions impeller/golden_tests/golden_digest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ GoldenDigest::GoldenDigest() {}
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});
int32_t height,
double threshold) {
entries_.push_back({test_name, filename, width, height, threshold});
}

bool GoldenDigest::Write(WorkingDirectory* working_directory) {
Expand All @@ -46,8 +47,15 @@ bool GoldenDigest::Write(WorkingDirectory* working_directory) {
<< "\"testName\" : \"" << entry.test_name << "\", "
<< "\"filename\" : \"" << entry.filename << "\", "
<< "\"width\" : " << entry.width << ", "
<< "\"height\" : " << entry.height << " "
<< "}";
<< "\"height\" : " << entry.height << ", ";

if (entry.threshold == static_cast<int64_t>(entry.threshold)) {
fout << "\"threshold\" : " << entry.threshold << ".0 ";
} else {
fout << "\"threshold\" : " << entry.threshold << " ";
}

fout << "}";
}
fout << std::endl << "]" << std::endl;

Expand Down
4 changes: 3 additions & 1 deletion impeller/golden_tests/golden_digest.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class GoldenDigest {
void AddImage(const std::string& test_name,
const std::string& filename,
int32_t width,
int32_t height);
int32_t height,
double threshold);

/// Writes a "digest.json" file to `working_directory`.
///
Expand All @@ -36,6 +37,7 @@ class GoldenDigest {
std::string filename;
int32_t width;
int32_t height;
double threshold;
};

static GoldenDigest* instance_;
Expand Down
2 changes: 1 addition & 1 deletion impeller/golden_tests/golden_playground_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class GoldenPlaygroundTest

PlaygroundBackend GetBackend() const;

bool OpenPlaygroundHere(const Picture& picture);
bool OpenPlaygroundHere(const Picture& picture, double threshold = 0.01);

bool OpenPlaygroundHere(const AiksPlaygroundCallback& callback);

Expand Down
11 changes: 7 additions & 4 deletions impeller/golden_tests/golden_playground_test_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ std::string GetGoldenFilename() {
return GetTestName() + ".png";
}

bool SaveScreenshot(std::unique_ptr<testing::MetalScreenshot> screenshot) {
bool SaveScreenshot(std::unique_ptr<testing::MetalScreenshot> screenshot,
double threshold) {
if (!screenshot || !screenshot->GetBytes()) {
return false;
}
std::string test_name = GetTestName();
std::string filename = GetGoldenFilename();
testing::GoldenDigest::Instance()->AddImage(
test_name, filename, screenshot->GetWidth(), screenshot->GetHeight());
test_name, filename, screenshot->GetWidth(), screenshot->GetHeight(),
threshold);
return screenshot->WriteToPNG(
testing::WorkingDirectory::Instance()->GetFilenamePath(filename));
}
Expand Down Expand Up @@ -96,10 +98,11 @@ PlaygroundBackend GoldenPlaygroundTest::GetBackend() const {
return GetParam();
}

bool GoldenPlaygroundTest::OpenPlaygroundHere(const Picture& picture) {
bool GoldenPlaygroundTest::OpenPlaygroundHere(const Picture& picture,
double threshold) {
auto screenshot =
pimpl_->screenshoter_->MakeScreenshot(picture, pimpl_->window_size_);
return SaveScreenshot(std::move(screenshot));
return SaveScreenshot(std::move(screenshot), threshold);
}

bool GoldenPlaygroundTest::OpenPlaygroundHere(
Expand Down
3 changes: 2 additions & 1 deletion impeller/golden_tests/golden_playground_test_stub.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ PlaygroundBackend GoldenPlaygroundTest::GetBackend() const {
return GetParam();
}

bool GoldenPlaygroundTest::OpenPlaygroundHere(const Picture& picture) {
bool GoldenPlaygroundTest::OpenPlaygroundHere(const Picture& picture,
double threshold) {
return false;
}

Expand Down
10 changes: 6 additions & 4 deletions impeller/golden_tests/golden_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ std::string GetGoldenFilename() {
return GetTestName() + ".png";
}

bool SaveScreenshot(std::unique_ptr<MetalScreenshot> screenshot) {
bool SaveScreenshot(std::unique_ptr<MetalScreenshot> screenshot,
double threshold) {
if (!screenshot || !screenshot->GetBytes()) {
return false;
}
std::string test_name = GetTestName();
std::string filename = GetGoldenFilename();
GoldenDigest::Instance()->AddImage(
test_name, filename, screenshot->GetWidth(), screenshot->GetHeight());
GoldenDigest::Instance()->AddImage(test_name, filename,
screenshot->GetWidth(),
screenshot->GetHeight(), threshold);
return screenshot->WriteToPNG(
WorkingDirectory::Instance()->GetFilenamePath(filename));
}
Expand Down Expand Up @@ -73,7 +75,7 @@ TEST_F(GoldenTests, ConicalGradient) {
canvas.DrawRect(Rect(10, 10, 250, 250), paint);
Picture picture = canvas.EndRecordingAsPicture();
auto screenshot = Screenshoter().MakeScreenshot(picture);
ASSERT_TRUE(SaveScreenshot(std::move(screenshot)));
ASSERT_TRUE(SaveScreenshot(std::move(screenshot), 0.01));
}
} // namespace testing
} // namespace impeller
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ 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 threshold = (map['threshold'] as double?)!;
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: threshold)
.catchError((dynamic err) {
Logger.instance.log('skia gold comparison failed: $err');
throw Exception('Failed comparison: $filename');
Expand Down