minor cleanup to typeface serial test

Bug: skia:
Change-Id: I572fbcbb382a665c4e4e27a7cee718c4eaa7743d
Reviewed-on: https://skia-review.googlesource.com/82801
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2017-12-08 11:46:09 -05:00 committed by Skia Commit-Bot
parent e562f413ea
commit 4bcef3c40a

View File

@ -11,6 +11,7 @@
#include "SkTypeface.h" #include "SkTypeface.h"
#include "Test.h" #include "Test.h"
#include "sk_tool_utils.h"
class TextBlobTester { class TextBlobTester {
public: public:
@ -424,14 +425,15 @@ static sk_sp<SkImage> render(const SkTextBlob* blob) {
* Then draw the new instance and assert it draws the same as the original. * Then draw the new instance and assert it draws the same as the original.
*/ */
DEF_TEST(TextBlob_serialize, reporter) { DEF_TEST(TextBlob_serialize, reporter) {
SkTextBlobBuilder builder; sk_sp<SkTextBlob> blob0 = []() {
sk_sp<SkTypeface> tf0;
sk_sp<SkTypeface> tf1 = SkTypeface::MakeFromName("Times", SkFontStyle());
sk_sp<SkTypeface> tf0; SkTextBlobBuilder builder;
sk_sp<SkTypeface> tf1 = SkTypeface::MakeFromName("Times", SkFontStyle()); add_run(&builder, "Hello", 10, 20, tf0);
add_run(&builder, "World", 10, 40, tf1);
add_run(&builder, "Hello", 10, 20, tf0); return builder.make();
add_run(&builder, "World", 10, 40, tf1); }();
sk_sp<SkTextBlob> blob0 = builder.make();
SkTDArray<SkTypeface*> array; SkTDArray<SkTypeface*> array;
sk_sp<SkData> data = blob0->serialize([](SkTypeface* tf, void* ctx) { sk_sp<SkData> data = blob0->serialize([](SkTypeface* tf, void* ctx) {
@ -457,15 +459,6 @@ DEF_TEST(TextBlob_serialize, reporter) {
sk_sp<SkImage> img0 = render(blob0.get()); sk_sp<SkImage> img0 = render(blob0.get());
sk_sp<SkImage> img1 = render(blob1.get()); sk_sp<SkImage> img1 = render(blob1.get());
if (img0 && img1) { if (img0 && img1) {
REPORTER_ASSERT(reporter, img0->width() == img1->width()); REPORTER_ASSERT(reporter, sk_tool_utils::equal_pixels(img0.get(), img1.get()));
REPORTER_ASSERT(reporter, img0->height() == img1->height());
sk_sp<SkData> enc0 = img0->encodeToData();
sk_sp<SkData> enc1 = img1->encodeToData();
REPORTER_ASSERT(reporter, enc0->equals(enc1.get()));
if (false) { // in case you want to actually see the images...
SkFILEWStream("textblob_serialize_img0.png").write(enc0->data(), enc0->size());
SkFILEWStream("textblob_serialize_img1.png").write(enc1->data(), enc1->size());
}
} }
} }