[fontations] Test to fail to compare gracefully
Avoid crashing in the fontations_compare_ft_* tests when using 16bpp
formats or formats like PDF which don't have pixels in their canvas.
Change-Id: I0f4c84afc60b4710f8dcae7828b75240d54dffd0
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/851777
Commit-Queue: Ben Wagner <bungeman@google.com>
Auto-Submit: Ben Wagner <bungeman@google.com>
Reviewed-by: Florin Malita <fmalita@google.com>
Commit-Queue: Florin Malita <fmalita@google.com>
diff --git a/gm/fontations_ft_compare.cpp b/gm/fontations_ft_compare.cpp
index bfdfbcb..ae2aa9e 100644
--- a/gm/fontations_ft_compare.cpp
+++ b/gm/fontations_ft_compare.cpp
@@ -217,11 +217,23 @@
diffBitmap.allocPixels(copyImageInfo, 0);
highlightDiffBitmap.allocPixels(copyImageInfo, 0);
- canvas->readPixels(
+ // comparePixels only handles 4 bpp
+ if (fontationsBitmap.bytesPerPixel() != 4 ||
+ freetypeBitmap.bytesPerPixel() != 4)
+ {
+ break;
+ }
+
+ const bool fontationsRead = canvas->readPixels(
fontationsBitmap, copyBoxFontations.x(), copyBoxFontations.y());
- canvas->readPixels(
+ const bool freetypeRead = canvas->readPixels(
freetypeBitmap, copyBoxFreetype.x(), copyBoxFreetype.y());
+ // readPixels may fail
+ if (!fontationsRead || !freetypeRead) {
+ break;
+ }
+
comparePixels(fontationsBitmap,
freetypeBitmap,
&diffBitmap,