DEF_TEST(Image_isAlphaOnly, reporter) { SkPMColor pmColors = 0; SkPixmap pmap = { SkImageInfo::MakeN32Premul(1, 1), &pmColors, sizeof(pmColors) }; for (auto& image : { SkImage::MakeRasterCopy(pmap), GetResourceAsImage("mandrill_128.png"), GetResourceAsImage("color_wheel.jpg"), SkImage::MakeFromPicture(make_picture(), { 10, 10 }, nullptr, nullptr), }) { REPORTER_ASSERT(reporter, image->isAlphaOnly() == false); } REPORTER_ASSERT(reporter, SkImage::MakeRasterCopy({ SkImageInfo::MakeA8(1, 1), (uint8_t*)&pmColors, 1})->isAlphaOnly() == true); }
DEF_TEST(serial_typeface, reporter) { auto tf0 = MakeResourceAsTypeface("fonts/hintgasp.ttf"); auto tf1 = MakeResourceAsTypeface("fonts/Roboto2-Regular_NoEmbed.ttf"); if (!tf0 || !tf1 || tf0.get() == tf1.get()) { return; // need two different typefaces for this test to make sense. } auto pic = make_picture(tf0, tf1); int counter = 0; SkSerialProcs procs; procs.fTypefaceProc = [](SkTypeface* tf, void* ctx) -> sk_sp<SkData> { *(int*)ctx += 1; return nullptr; }; procs.fTypefaceCtx = &counter; auto data = pic->serialize(&procs); // The picture has 2 references to each typeface, but we want the serialized picture to // only have written the data 1 time per typeface. REPORTER_ASSERT(reporter, counter == 2); }
void onOnceBeforeDraw() override { fPicture = make_picture(); }