DEF_TEST(Recorder_RefPictures, r) { SkAutoTUnref<SkPicture> pic; { SkPictureRecorder pr; SkCanvas* canvas = pr.beginRecording(100, 100); canvas->drawColor(SK_ColorRED); pic.reset(pr.endRecording()); } REPORTER_ASSERT(r, pic->unique()); { SkRecord record; SkRecorder recorder(&record, 100, 100); recorder.drawPicture(pic); // the recorder should now also be an owner REPORTER_ASSERT(r, !pic->unique()); } // the recorder destructor should have released us (back to unique) REPORTER_ASSERT(r, pic->unique()); }
DEF_TEST(Recorder_drawImage_takeReference, reporter) { SkAutoTUnref<SkImage> image; { SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(100, 100)); surface->getCanvas()->clear(SK_ColorGREEN); image.reset(surface->newImageSnapshot()); } { SkRecord record; SkRecorder recorder(&record, 100, 100); // DrawImage is supposed to take a reference recorder.drawImage(image.get(), 0, 0); REPORTER_ASSERT(reporter, !image->unique()); Tally tally; tally.apply(record); REPORTER_ASSERT(reporter, 1 == tally.count<SkRecords::DrawImage>()); } REPORTER_ASSERT(reporter, image->unique()); { SkRecord record; SkRecorder recorder(&record, 100, 100); // DrawImageRect is supposed to take a reference recorder.drawImageRect(image.get(), 0, SkRect::MakeWH(100, 100)); REPORTER_ASSERT(reporter, !image->unique()); Tally tally; tally.apply(record); REPORTER_ASSERT(reporter, 1 == tally.count<SkRecords::DrawImageRect>()); } REPORTER_ASSERT(reporter, image->unique()); }