diff --git a/engine/src/flutter/shell/platform/embedder/fixtures/gradient_xform.png b/engine/src/flutter/shell/platform/embedder/fixtures/gradient_xform.png index 714b04e8e8..186b98e87e 100644 Binary files a/engine/src/flutter/shell/platform/embedder/fixtures/gradient_xform.png and b/engine/src/flutter/shell/platform/embedder/fixtures/gradient_xform.png differ diff --git a/engine/src/flutter/shell/platform/embedder/fixtures/scene_without_custom_compositor_with_xform.png b/engine/src/flutter/shell/platform/embedder/fixtures/scene_without_custom_compositor_with_xform.png index c80d8046ce..d406fb6dea 100644 Binary files a/engine/src/flutter/shell/platform/embedder/fixtures/scene_without_custom_compositor_with_xform.png and b/engine/src/flutter/shell/platform/embedder/fixtures/scene_without_custom_compositor_with_xform.png differ diff --git a/engine/src/flutter/shell/platform/embedder/tests/embedder_unittests_util.cc b/engine/src/flutter/shell/platform/embedder/tests/embedder_unittests_util.cc index 59479a808b..89d5fec995 100644 --- a/engine/src/flutter/shell/platform/embedder/tests/embedder_unittests_util.cc +++ b/engine/src/flutter/shell/platform/embedder/tests/embedder_unittests_util.cc @@ -30,61 +30,43 @@ sk_sp CreateRenderSurface(const FlutterLayer& layer, return surface; } -bool RasterImagesAreSame(sk_sp a, sk_sp b) { - FML_CHECK(!a->isTextureBacked()); - FML_CHECK(!b->isTextureBacked()); +// Normalizes the color-space, color-type and alpha-type for comparison. +static sk_sp NormalizeImage(sk_sp image) { + // To avoid clipping, convert to a very wide gamut, and a high bit depth. + sk_sp norm_colorspace = SkColorSpace::MakeRGB( + SkNamedTransferFn::kRec2020, SkNamedGamut::kRec2020); + SkImageInfo norm_image_info = + SkImageInfo::Make(image->width(), image->height(), + SkColorType::kR16G16B16A16_unorm_SkColorType, + SkAlphaType::kUnpremul_SkAlphaType, norm_colorspace); + size_t row_bytes = norm_image_info.minRowBytes(); + size_t size = norm_image_info.computeByteSize(row_bytes); + sk_sp data = SkData::MakeUninitialized(size); + if (!data) { + FML_CHECK(false) << "Unable to allocate data."; + } + bool success = image->readPixels(norm_image_info, data->writable_data(), + row_bytes, 0, 0); + if (!success) { + FML_CHECK(false) << "Unable to read pixels."; + } + + return data; +} + +bool RasterImagesAreSame(sk_sp a, sk_sp b) { if (!a || !b) { return false; } - SkPixmap pixmapA; - SkPixmap pixmapB; + FML_CHECK(!a->isTextureBacked()); + FML_CHECK(!b->isTextureBacked()); - if (!a->peekPixels(&pixmapA)) { - FML_LOG(ERROR) << "Could not peek pixels of image A."; - return false; - } + sk_sp normalized_a = NormalizeImage(a); + sk_sp normalized_b = NormalizeImage(b); - if (!b->peekPixels(&pixmapB)) { - FML_LOG(ERROR) << "Could not peek pixels of image B."; - - return false; - } - - const auto sizeA = pixmapA.rowBytes() * pixmapA.height(); - const auto sizeB = pixmapB.rowBytes() * pixmapB.height(); - - if (sizeA != sizeB) { - FML_LOG(ERROR) << "Pixmap sizes were inconsistent."; - return false; - } - - if (pixmapA.info() != pixmapB.info()) { - // Given that the sizes are equal but the infos aren't equal - // we have a situation where the color-type, color-space and - // alpha type are potentially mismatched. We fallback to compating - // pixel-wise values for alpha and color. - for (int x = 0; x < pixmapA.width(); x++) { - for (int y = 0; y < pixmapA.height(); y++) { - SkColor color_a = pixmapA.getColor(x, y); - SkColor color_b = pixmapB.getColor(x, y); - if (color_a != color_b) { - return false; - } - float alpha_a = pixmapA.getAlphaf(x, y); - float alpha_b = pixmapB.getAlphaf(x, y); - if (std::abs(alpha_a - alpha_b) > - std::numeric_limits::epsilon()) { - return false; - } - } - } - - return true; - } - - return ::memcmp(pixmapA.addr(), pixmapB.addr(), sizeA) == 0; + return normalized_a->equals(normalized_b.get()); } bool WriteImageToDisk(const fml::UniqueFD& directory,