Add comparison of rendered SkPictures to Serialization unit test

This identifies a possible bug with font serialization (changing the
typeface on line 444 causes the test to fail).

Change-Id: I4e2c9d21cd03586e043b8d82eeff6607bb02b380
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/226510
Auto-Submit: Ben Wagner aka dogben <benjaminwagner@google.com>
Reviewed-by: Mike Reed <reed@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Ben Wagner aka dogben <benjaminwagner@google.com>
This commit is contained in:
Ben Wagner 2019-07-10 16:27:34 -04:00 committed by Skia Commit-Bot
parent e877dce203
commit 7825d4983f

View File

@ -446,6 +446,17 @@ static void draw_something(SkCanvas* canvas) {
canvas->drawString("Picture", SkIntToScalar(kBitmapSize/2), SkIntToScalar(kBitmapSize/4), font, paint);
}
static sk_sp<SkImage> render(const SkPicture& p) {
auto surf = SkSurface::MakeRasterN32Premul(SkScalarRoundToInt(p.cullRect().width()),
SkScalarRoundToInt(p.cullRect().height()));
if (!surf) {
return nullptr; // bounds are empty?
}
surf->getCanvas()->clear(SK_ColorWHITE);
p.playback(surf->getCanvas());
return surf->makeImageSnapshot();
}
DEF_TEST(Serialization, reporter) {
// Test matrix serialization
{
@ -572,6 +583,11 @@ DEF_TEST(Serialization, reporter) {
sk_sp<SkPicture> readPict(SkPicturePriv::MakeFromBuffer(reader));
REPORTER_ASSERT(reporter, reader.isValid());
REPORTER_ASSERT(reporter, readPict.get());
sk_sp<SkImage> img0 = render(*pict);
sk_sp<SkImage> img1 = render(*readPict);
if (img0 && img1) {
REPORTER_ASSERT(reporter, ToolUtils::equal_pixels(img0.get(), img1.get()));
}
}
TestPictureTypefaceSerialization(reporter);