return pictures as sk_sp

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1811703002

Review URL: https://codereview.chromium.org/1811703002
This commit is contained in:
reed 2016-03-18 07:25:55 -07:00 committed by Commit bot
parent eb75c7db3a
commit ca2622ba05
67 changed files with 363 additions and 376 deletions

View File

@ -74,8 +74,7 @@ protected:
c->restore(); c->restore();
if (recordPicture) { if (recordPicture) {
SkAutoTUnref<SkPicture> picture(recorder.endRecording()); canvas->drawPicture(recorder.finishRecordingAsPicture());
canvas->drawPicture(picture);
} }
return pics; return pics;
@ -125,7 +124,7 @@ protected:
SkCanvas* c = recorder.beginRecording(SkIntToScalar(canvasSize.x()), SkCanvas* c = recorder.beginRecording(SkIntToScalar(canvasSize.x()),
SkIntToScalar(canvasSize.y())); SkIntToScalar(canvasSize.y()));
this->doDraw(c); this->doDraw(c);
SkAutoTUnref<SkPicture> picture(recorder.endRecording()); (void)recorder.finishRecordingAsPicture();
} }
} }
@ -148,7 +147,7 @@ protected:
SkIntToScalar(canvasSize.y())); SkIntToScalar(canvasSize.y()));
this->doDraw(c); this->doDraw(c);
fPicture.reset(recorder.endRecording()); fPicture = recorder.finishRecordingAsPicture();
} }
void onDraw(int loops, SkCanvas* canvas) override { void onDraw(int loops, SkCanvas* canvas) override {
@ -158,7 +157,7 @@ protected:
} }
private: private:
SkAutoTUnref<SkPicture> fPicture; sk_sp<SkPicture> fPicture;
typedef PictureNesting INHERITED; typedef PictureNesting INHERITED;
}; };

View File

@ -26,7 +26,7 @@ struct PictureOverheadBench : public Benchmark {
if (kDraw) { if (kDraw) {
rec.getRecordingCanvas()->drawRect(SkRect::MakeXYWH(10, 10, 1000, 1000), SkPaint()); rec.getRecordingCanvas()->drawRect(SkRect::MakeXYWH(10, 10, 1000, 1000), SkPaint());
} }
SkAutoTUnref<SkPicture> pic(rec.endRecordingAsPicture()); (void)rec.finishRecordingAsPicture();
} }
} }
}; };

View File

@ -42,7 +42,7 @@ protected:
SkPictureRecorder recorder; SkPictureRecorder recorder;
SkCanvas* pCanvas = recorder.beginRecording(PICTURE_WIDTH, PICTURE_HEIGHT, nullptr, 0); SkCanvas* pCanvas = recorder.beginRecording(PICTURE_WIDTH, PICTURE_HEIGHT, nullptr, 0);
this->recordCanvas(pCanvas); this->recordCanvas(pCanvas);
SkAutoTUnref<SkPicture> picture(recorder.endRecording()); sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
const SkPoint translateDelta = getTranslateDelta(loops); const SkPoint translateDelta = getTranslateDelta(loops);
@ -182,7 +182,7 @@ public:
paint.setAlpha(0xFF); paint.setAlpha(0xFF);
canvas->drawRect(SkRect::MakeXYWH(x,y,w,h), paint); canvas->drawRect(SkRect::MakeXYWH(x,y,w,h), paint);
} }
fPic.reset(recorder.endRecording()); fPic = recorder.finishRecordingAsPicture();
} }
void onDraw(int loops, SkCanvas* canvas) override { void onDraw(int loops, SkCanvas* canvas) override {
@ -207,10 +207,10 @@ public:
} }
private: private:
BBH fBBH; BBH fBBH;
Mode fMode; Mode fMode;
SkString fName; SkString fName;
SkAutoTUnref<SkPicture> fPic; sk_sp<SkPicture> fPic;
}; };
DEF_BENCH( return new TiledPlaybackBench(kNone, kRandom); ) DEF_BENCH( return new TiledPlaybackBench(kNone, kRandom); )

View File

@ -38,6 +38,6 @@ void RecordingBench::onDraw(int loops, SkCanvas*) {
for (int i = 0; i < loops; i++) { for (int i = 0; i < loops; i++) {
SkPictureRecorder recorder; SkPictureRecorder recorder;
fSrc->playback(recorder.beginRecording(w, h, fUseBBH ? &factory : nullptr, flags)); fSrc->playback(recorder.beginRecording(w, h, fUseBBH ? &factory : nullptr, flags));
SkSafeUnref(recorder.endRecording()); (void)recorder.finishRecordingAsPicture();
} }
} }

View File

@ -617,25 +617,20 @@ public:
fColorTypes.reset(colorTypes, SK_ARRAY_COUNT(colorTypes)); fColorTypes.reset(colorTypes, SK_ARRAY_COUNT(colorTypes));
} }
static bool ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic) { static sk_sp<SkPicture> ReadPicture(const char* path) {
// Not strictly necessary, as it will be checked again later, // Not strictly necessary, as it will be checked again later,
// but helps to avoid a lot of pointless work if we're going to skip it. // but helps to avoid a lot of pointless work if we're going to skip it.
if (SkCommandLineFlags::ShouldSkip(FLAGS_match, SkOSPath::Basename(path).c_str())) { if (SkCommandLineFlags::ShouldSkip(FLAGS_match, SkOSPath::Basename(path).c_str())) {
return false; return nullptr;
} }
SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path)); SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path));
if (stream.get() == nullptr) { if (stream.get() == nullptr) {
SkDebugf("Could not read %s.\n", path); SkDebugf("Could not read %s.\n", path);
return false; return nullptr;
} }
pic->reset(SkPicture::CreateFromStream(stream.get())); return SkPicture::MakeFromStream(stream.get());
if (pic->get() == nullptr) {
SkDebugf("Could not read %s as an SkPicture.\n", path);
return false;
}
return true;
} }
Benchmark* next() { Benchmark* next() {
@ -672,14 +667,14 @@ public:
// First add all .skps as RecordingBenches. // First add all .skps as RecordingBenches.
while (fCurrentRecording < fSKPs.count()) { while (fCurrentRecording < fSKPs.count()) {
const SkString& path = fSKPs[fCurrentRecording++]; const SkString& path = fSKPs[fCurrentRecording++];
SkAutoTUnref<SkPicture> pic; sk_sp<SkPicture> pic = ReadPicture(path.c_str());
if (!ReadPicture(path.c_str(), &pic)) { if (!pic) {
continue; continue;
} }
SkString name = SkOSPath::Basename(path.c_str()); SkString name = SkOSPath::Basename(path.c_str());
fSourceType = "skp"; fSourceType = "skp";
fBenchType = "recording"; fBenchType = "recording";
fSKPBytes = static_cast<double>(SkPictureUtils::ApproximateBytesUsed(pic)); fSKPBytes = static_cast<double>(SkPictureUtils::ApproximateBytesUsed(pic.get()));
fSKPOps = pic->approximateOpCount(); fSKPOps = pic->approximateOpCount();
return new RecordingBench(name.c_str(), pic.get(), FLAGS_bbh); return new RecordingBench(name.c_str(), pic.get(), FLAGS_bbh);
} }
@ -688,8 +683,8 @@ public:
while (fCurrentScale < fScales.count()) { while (fCurrentScale < fScales.count()) {
while (fCurrentSKP < fSKPs.count()) { while (fCurrentSKP < fSKPs.count()) {
const SkString& path = fSKPs[fCurrentSKP]; const SkString& path = fSKPs[fCurrentSKP];
SkAutoTUnref<SkPicture> pic; sk_sp<SkPicture> pic = ReadPicture(path.c_str());
if (!ReadPicture(path.c_str(), &pic)) { if (!pic) {
fCurrentSKP++; fCurrentSKP++;
continue; continue;
} }
@ -704,7 +699,7 @@ public:
pic->cullRect().height(), pic->cullRect().height(),
&factory, &factory,
fUseMPDs[fCurrentUseMPD] ? kFlags : 0)); fUseMPDs[fCurrentUseMPD] ? kFlags : 0));
pic.reset(recorder.endRecording()); pic = recorder.finishRecordingAsPicture();
} }
SkString name = SkOSPath::Basename(path.c_str()); SkString name = SkOSPath::Basename(path.c_str());
fSourceType = "skp"; fSourceType = "skp";
@ -723,8 +718,8 @@ public:
if (fZoomMax != 1.0f && fZoomPeriodMs > 0) { if (fZoomMax != 1.0f && fZoomPeriodMs > 0) {
while (fCurrentAnimSKP < fSKPs.count()) { while (fCurrentAnimSKP < fSKPs.count()) {
const SkString& path = fSKPs[fCurrentAnimSKP]; const SkString& path = fSKPs[fCurrentAnimSKP];
SkAutoTUnref<SkPicture> pic; sk_sp<SkPicture> pic = ReadPicture(path.c_str());
if (!ReadPicture(path.c_str(), &pic)) { if (!pic) {
fCurrentAnimSKP++; fCurrentAnimSKP++;
continue; continue;
} }

View File

@ -674,7 +674,7 @@ void SkDebuggerGUI::loadPicture(const SkString& fileName) {
fLoading = true; fLoading = true;
SkAutoTDelete<SkStream> stream(new SkFILEStream(fileName.c_str())); SkAutoTDelete<SkStream> stream(new SkFILEStream(fileName.c_str()));
SkPicture* picture = SkPicture::CreateFromStream(stream); auto picture = SkPicture::MakeFromStream(stream);
if (nullptr == picture) { if (nullptr == picture) {
QMessageBox::critical(this, "Error loading file", "Couldn't read file, sorry."); QMessageBox::critical(this, "Error loading file", "Couldn't read file, sorry.");
@ -682,14 +682,14 @@ void SkDebuggerGUI::loadPicture(const SkString& fileName) {
} }
fCanvasWidget.resetWidgetTransform(); fCanvasWidget.resetWidgetTransform();
fDebugger.loadPicture(picture); fDebugger.loadPicture(picture.get());
fSkipCommands.setCount(fDebugger.getSize()); fSkipCommands.setCount(fDebugger.getSize());
for (int i = 0; i < fSkipCommands.count(); ++i) { for (int i = 0; i < fSkipCommands.count(); ++i) {
fSkipCommands[i] = false; fSkipCommands[i] = false;
} }
SkSafeUnref(picture); picture.reset();
/* fDebugCanvas is reinitialized every load picture. Need it to retain value /* fDebugCanvas is reinitialized every load picture. Need it to retain value
* of the visibility filter. * of the visibility filter.

View File

@ -903,7 +903,7 @@ Error SKPSrc::draw(SkCanvas* canvas) const {
if (!stream) { if (!stream) {
return SkStringPrintf("Couldn't read %s.", fPath.c_str()); return SkStringPrintf("Couldn't read %s.", fPath.c_str());
} }
SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream)); sk_sp<SkPicture> pic(SkPicture::MakeFromStream(stream));
if (!pic) { if (!pic) {
return SkStringPrintf("Couldn't decode %s as a picture.", fPath.c_str()); return SkStringPrintf("Couldn't decode %s as a picture.", fPath.c_str());
} }
@ -1116,8 +1116,7 @@ Error SKPSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const
if (!err.isEmpty()) { if (!err.isEmpty()) {
return err; return err;
} }
SkAutoTUnref<SkPicture> pic(recorder.endRecording()); recorder.finishRecordingAsPicture()->serialize(dst);
pic->serialize(dst);
return ""; return "";
} }
@ -1273,13 +1272,13 @@ Error ViaSerialization::draw(
if (!err.isEmpty()) { if (!err.isEmpty()) {
return err; return err;
} }
SkAutoTUnref<SkPicture> pic(recorder.endRecording()); sk_sp<SkPicture> pic(recorder.finishRecordingAsPicture());
// Serialize it and then deserialize it. // Serialize it and then deserialize it.
SkDynamicMemoryWStream wStream; SkDynamicMemoryWStream wStream;
pic->serialize(&wStream); pic->serialize(&wStream);
SkAutoTDelete<SkStream> rStream(wStream.detachAsStream()); SkAutoTDelete<SkStream> rStream(wStream.detachAsStream());
SkAutoTUnref<SkPicture> deserialized(SkPicture::CreateFromStream(rStream)); sk_sp<SkPicture> deserialized(SkPicture::MakeFromStream(rStream));
return draw_to_canvas(fSink, bitmap, stream, log, size, [&](SkCanvas* canvas) { return draw_to_canvas(fSink, bitmap, stream, log, size, [&](SkCanvas* canvas) {
canvas->drawPicture(deserialized); canvas->drawPicture(deserialized);
@ -1304,7 +1303,7 @@ Error ViaTiles::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkStri
if (!err.isEmpty()) { if (!err.isEmpty()) {
return err; return err;
} }
SkAutoTUnref<SkPicture> pic(recorder.endRecordingAsPicture()); sk_sp<SkPicture> pic(recorder.finishRecordingAsPicture());
return draw_to_canvas(fSink, bitmap, stream, log, src.size(), [&](SkCanvas* canvas) { return draw_to_canvas(fSink, bitmap, stream, log, src.size(), [&](SkCanvas* canvas) {
const int xTiles = (size.width() + fW - 1) / fW, const int xTiles = (size.width() + fW - 1) / fW,
@ -1326,7 +1325,7 @@ Error ViaTiles::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkStri
SkCanvas* c = s->getCanvas(); SkCanvas* c = s->getCanvas();
c->translate(SkIntToScalar(-i * fW), c->translate(SkIntToScalar(-i * fW),
SkIntToScalar(-j * fH)); // Line up the canvas with this tile. SkIntToScalar(-j * fH)); // Line up the canvas with this tile.
mpd.add(c, pic); mpd.add(c, pic.get());
} }
} }
mpd.draw(); mpd.draw();
@ -1347,13 +1346,13 @@ Error ViaPicture::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkSt
auto size = src.size(); auto size = src.size();
return draw_to_canvas(fSink, bitmap, stream, log, size, [&](SkCanvas* canvas) -> Error { return draw_to_canvas(fSink, bitmap, stream, log, size, [&](SkCanvas* canvas) -> Error {
SkPictureRecorder recorder; SkPictureRecorder recorder;
SkAutoTUnref<SkPicture> pic; sk_sp<SkPicture> pic;
Error err = src.draw(recorder.beginRecording(SkIntToScalar(size.width()), Error err = src.draw(recorder.beginRecording(SkIntToScalar(size.width()),
SkIntToScalar(size.height()))); SkIntToScalar(size.height())));
if (!err.isEmpty()) { if (!err.isEmpty()) {
return err; return err;
} }
pic.reset(recorder.endRecordingAsPicture()); pic = recorder.finishRecordingAsPicture();
canvas->drawPicture(pic); canvas->drawPicture(pic);
return check_against_reference(bitmap, src, fSink); return check_against_reference(bitmap, src, fSink);
}); });
@ -1368,14 +1367,14 @@ Error ViaSecondPicture::draw(
auto size = src.size(); auto size = src.size();
return draw_to_canvas(fSink, bitmap, stream, log, size, [&](SkCanvas* canvas) -> Error { return draw_to_canvas(fSink, bitmap, stream, log, size, [&](SkCanvas* canvas) -> Error {
SkPictureRecorder recorder; SkPictureRecorder recorder;
SkAutoTUnref<SkPicture> pic; sk_sp<SkPicture> pic;
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
Error err = src.draw(recorder.beginRecording(SkIntToScalar(size.width()), Error err = src.draw(recorder.beginRecording(SkIntToScalar(size.width()),
SkIntToScalar(size.height()))); SkIntToScalar(size.height())));
if (!err.isEmpty()) { if (!err.isEmpty()) {
return err; return err;
} }
pic.reset(recorder.endRecordingAsPicture()); pic = recorder.finishRecordingAsPicture();
} }
canvas->drawPicture(pic); canvas->drawPicture(pic);
return check_against_reference(bitmap, src, fSink); return check_against_reference(bitmap, src, fSink);
@ -1409,7 +1408,7 @@ Error ViaTwice::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkStri
if (!err.isEmpty()) { if (!err.isEmpty()) {
return err; return err;
} }
SkAutoTUnref<SkPicture> skPicture(recorder.endRecording()); sk_sp<SkPicture> skPicture(recorder.finishRecordingAsPicture());
SkASSERT(skPicture); SkASSERT(skPicture);
SkDynamicMemoryWStream buffer; SkDynamicMemoryWStream buffer;
@ -1434,7 +1433,7 @@ Error ViaTwice::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkStri
} }
SkMemoryStream tmpStream(mojoPicture->data.data(), SkMemoryStream tmpStream(mojoPicture->data.data(),
mojoPicture->data.size()); mojoPicture->data.size());
skPicture.reset(SkPicture::CreateFromStream(&tmpStream)); skPicture = SkPicture::MakeFromStream(&tmpStream);
mojoPicture.reset(); mojoPicture.reset();
auto fn = [&](SkCanvas* canvas) -> Error { auto fn = [&](SkCanvas* canvas) -> Error {
canvas->drawPicture(skPicture.get()); canvas->drawPicture(skPicture.get());
@ -1471,7 +1470,7 @@ struct DrawsAsSingletonPictures {
SK_WHEN(T::kTags & SkRecords::kDraw_Tag, void) operator()(const T& op) { SK_WHEN(T::kTags & SkRecords::kDraw_Tag, void) operator()(const T& op) {
SkPictureRecorder rec; SkPictureRecorder rec;
this->draw(op, rec.beginRecording(SkRect::MakeLargest())); this->draw(op, rec.beginRecording(SkRect::MakeLargest()));
SkAutoTUnref<SkPicture> pic(rec.endRecordingAsPicture()); sk_sp<SkPicture> pic(rec.finishRecordingAsPicture());
fCanvas->drawPicture(pic); fCanvas->drawPicture(pic);
} }
@ -1511,7 +1510,7 @@ Error ViaSingletonPictures::draw(
for (int i = 0; i < skr.count(); i++) { for (int i = 0; i < skr.count(); i++) {
skr.visit<void>(i, drawsAsSingletonPictures); skr.visit<void>(i, drawsAsSingletonPictures);
} }
SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); sk_sp<SkPicture> macroPic(macroRec.finishRecordingAsPicture());
canvas->drawPicture(macroPic); canvas->drawPicture(macroPic);
return check_against_reference(bitmap, src, fSink); return check_against_reference(bitmap, src, fSink);

View File

@ -358,7 +358,7 @@ int fuzz_img(SkData* bytes, uint8_t scale, uint8_t mode) {
int fuzz_skp(SkData* bytes) { int fuzz_skp(SkData* bytes) {
SkMemoryStream stream(bytes); SkMemoryStream stream(bytes);
SkDebugf("Decoding\n"); SkDebugf("Decoding\n");
SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(&stream)); sk_sp<SkPicture> pic(SkPicture::MakeFromStream(&stream));
if (!pic) { if (!pic) {
SkDebugf("[terminated] Couldn't decode as a picture.\n"); SkDebugf("[terminated] Couldn't decode as a picture.\n");
return 3; return 3;

View File

@ -43,13 +43,13 @@ protected:
rec->clipPath(p, SkRegion::kIntersect_Op, true); rec->clipPath(p, SkRegion::kIntersect_Op, true);
rec->drawColor(SK_ColorGREEN); rec->drawColor(SK_ColorGREEN);
rec->restore(); rec->restore();
SkAutoTUnref<SkPicture> pict(recorder.endRecording()); sk_sp<SkPicture> pict(recorder.finishRecordingAsPicture());
// Next we play that picture into another picture of the same size. // Next we play that picture into another picture of the same size.
pict->playback(recorder.beginRecording(pict->cullRect().width(), pict->playback(recorder.beginRecording(pict->cullRect().width(),
pict->cullRect().height(), pict->cullRect().height(),
nullptr, 0)); nullptr, 0));
SkAutoTUnref<SkPicture> pict2(recorder.endRecording()); sk_sp<SkPicture> pict2(recorder.finishRecordingAsPicture());
// Finally we play the part of that second picture that should be green into the canvas. // Finally we play the part of that second picture that should be green into the canvas.
canvas->save(); canvas->save();

View File

@ -246,17 +246,17 @@ protected:
//----------- //-----------
// Paints with a PictureImageFilter as a source // Paints with a PictureImageFilter as a source
SkAutoTUnref<SkPicture> pic; sk_sp<SkPicture> pic;
{ {
SkPictureRecorder rec; SkPictureRecorder rec;
SkCanvas* c = rec.beginRecording(10, 10); SkCanvas* c = rec.beginRecording(10, 10);
c->drawRect(SkRect::MakeWH(10, 10), blackFill); c->drawRect(SkRect::MakeWH(10, 10), blackFill);
pic.reset(rec.endRecording()); pic = rec.finishRecordingAsPicture();
} }
SkAutoTUnref<SkImageFilter> pif(SkPictureImageFilter::Create(pic)); SkAutoTUnref<SkImageFilter> pif(SkPictureImageFilter::Create(pic.get()));
SkTArray<SkPaint> pifPaints; SkTArray<SkPaint> pifPaints;
create_paints(pif, &pifPaints); create_paints(pif, &pifPaints);

View File

@ -246,8 +246,8 @@ static sk_sp<SkImage> make_raster(const SkImageInfo& info, GrContext*, void (*dr
static sk_sp<SkImage> make_picture(const SkImageInfo& info, GrContext*, void (*draw)(SkCanvas*)) { static sk_sp<SkImage> make_picture(const SkImageInfo& info, GrContext*, void (*draw)(SkCanvas*)) {
SkPictureRecorder recorder; SkPictureRecorder recorder;
draw(recorder.beginRecording(SkRect::MakeIWH(info.width(), info.height()))); draw(recorder.beginRecording(SkRect::MakeIWH(info.width(), info.height())));
SkAutoTUnref<SkPicture> pict(recorder.endRecording()); return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(),
return SkImage::MakeFromPicture(sk_ref_sp(pict.get()), info.dimensions(), nullptr, nullptr); info.dimensions(), nullptr, nullptr);
} }
static sk_sp<SkImage> make_codec(const SkImageInfo& info, GrContext*, void (*draw)(SkCanvas*)) { static sk_sp<SkImage> make_codec(const SkImageInfo& info, GrContext*, void (*draw)(SkCanvas*)) {
@ -343,8 +343,8 @@ static SkImageGenerator* gen_raster(const SkImageInfo& info) {
static SkImageGenerator* gen_picture(const SkImageInfo& info) { static SkImageGenerator* gen_picture(const SkImageInfo& info) {
SkPictureRecorder recorder; SkPictureRecorder recorder;
draw_opaque_contents(recorder.beginRecording(SkRect::MakeIWH(info.width(), info.height()))); draw_opaque_contents(recorder.beginRecording(SkRect::MakeIWH(info.width(), info.height())));
SkAutoTUnref<SkPicture> pict(recorder.endRecording()); sk_sp<SkPicture> pict(recorder.finishRecordingAsPicture());
return SkImageGenerator::NewFromPicture(info.dimensions(), pict, nullptr, nullptr); return SkImageGenerator::NewFromPicture(info.dimensions(), pict.get(), nullptr, nullptr);
} }
static SkImageGenerator* gen_png(const SkImageInfo& info) { static SkImageGenerator* gen_png(const SkImageInfo& info) {
@ -476,9 +476,8 @@ DEF_SIMPLE_GM(new_texture_image, canvas, 225, 60) {
SkPictureRecorder recorder; SkPictureRecorder recorder;
SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kSize), SkIntToScalar(kSize)); SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kSize), SkIntToScalar(kSize));
render_image(canvas); render_image(canvas);
SkAutoTUnref<SkPicture> picture(recorder.endRecording()); return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(),
return SkImage::MakeFromPicture(sk_ref_sp(picture.get()), SkISize::Make(kSize, kSize), SkISize::Make(kSize, kSize), nullptr, nullptr);
nullptr, nullptr);
}, },
// Create a texture image // Create a texture image
[context, render_image]() -> sk_sp<SkImage> { [context, render_image]() -> sk_sp<SkImage> {

View File

@ -35,7 +35,7 @@ static void draw_something(SkCanvas* canvas, const SkRect& bounds) {
* (correctly) when it is inside an image. * (correctly) when it is inside an image.
*/ */
class ImagePictGM : public skiagm::GM { class ImagePictGM : public skiagm::GM {
SkAutoTUnref<SkPicture> fPicture; sk_sp<SkPicture> fPicture;
sk_sp<SkImage> fImage0; sk_sp<SkImage> fImage0;
sk_sp<SkImage> fImage1; sk_sp<SkImage> fImage1;
public: public:
@ -54,18 +54,18 @@ protected:
const SkRect bounds = SkRect::MakeXYWH(100, 100, 100, 100); const SkRect bounds = SkRect::MakeXYWH(100, 100, 100, 100);
SkPictureRecorder recorder; SkPictureRecorder recorder;
draw_something(recorder.beginRecording(bounds), bounds); draw_something(recorder.beginRecording(bounds), bounds);
fPicture.reset(recorder.endRecording()); fPicture = recorder.finishRecordingAsPicture();
// extract enough just for the oval. // extract enough just for the oval.
const SkISize size = SkISize::Make(100, 100); const SkISize size = SkISize::Make(100, 100);
SkMatrix matrix; SkMatrix matrix;
matrix.setTranslate(-100, -100); matrix.setTranslate(-100, -100);
fImage0 = SkImage::MakeFromPicture(sk_ref_sp(fPicture.get()), size, &matrix, nullptr); fImage0 = SkImage::MakeFromPicture(fPicture, size, &matrix, nullptr);
matrix.postTranslate(-50, -50); matrix.postTranslate(-50, -50);
matrix.postRotate(45); matrix.postRotate(45);
matrix.postTranslate(50, 50); matrix.postTranslate(50, 50);
fImage1 = SkImage::MakeFromPicture(sk_ref_sp(fPicture.get()), size, &matrix, nullptr); fImage1 = SkImage::MakeFromPicture(fPicture, size, &matrix, nullptr);
} }
void drawSet(SkCanvas* canvas) const { void drawSet(SkCanvas* canvas) const {
@ -254,7 +254,7 @@ static SkImageGenerator* make_tex_generator(GrContext* ctx, SkPicture* pic) {
class ImageCacheratorGM : public skiagm::GM { class ImageCacheratorGM : public skiagm::GM {
SkString fName; SkString fName;
SkImageGenerator* (*fFactory)(GrContext*, SkPicture*); SkImageGenerator* (*fFactory)(GrContext*, SkPicture*);
SkAutoTUnref<SkPicture> fPicture; sk_sp<SkPicture> fPicture;
SkAutoTDelete<SkImageCacherator> fCache; SkAutoTDelete<SkImageCacherator> fCache;
SkAutoTDelete<SkImageCacherator> fCacheSubset; SkAutoTDelete<SkImageCacherator> fCacheSubset;
@ -278,17 +278,17 @@ protected:
const SkRect bounds = SkRect::MakeXYWH(100, 100, 100, 100); const SkRect bounds = SkRect::MakeXYWH(100, 100, 100, 100);
SkPictureRecorder recorder; SkPictureRecorder recorder;
draw_something(recorder.beginRecording(bounds), bounds); draw_something(recorder.beginRecording(bounds), bounds);
fPicture.reset(recorder.endRecording()); fPicture = recorder.finishRecordingAsPicture();
} }
void makeCaches(GrContext* ctx) { void makeCaches(GrContext* ctx) {
auto gen = fFactory(ctx, fPicture); auto gen = fFactory(ctx, fPicture.get());
SkDEBUGCODE(const uint32_t genID = gen->uniqueID();) SkDEBUGCODE(const uint32_t genID = gen->uniqueID();)
fCache.reset(SkImageCacherator::NewFromGenerator(gen)); fCache.reset(SkImageCacherator::NewFromGenerator(gen));
const SkIRect subset = SkIRect::MakeLTRB(50, 50, 100, 100); const SkIRect subset = SkIRect::MakeLTRB(50, 50, 100, 100);
gen = fFactory(ctx, fPicture); gen = fFactory(ctx, fPicture.get());
SkDEBUGCODE(const uint32_t genSubsetID = gen->uniqueID();) SkDEBUGCODE(const uint32_t genSubsetID = gen->uniqueID();)
fCacheSubset.reset(SkImageCacherator::NewFromGenerator(gen, &subset)); fCacheSubset.reset(SkImageCacherator::NewFromGenerator(gen, &subset));

View File

@ -72,7 +72,7 @@ const ImageMakerProc gProcs[] = {
* (correctly) when it is inside an image. * (correctly) when it is inside an image.
*/ */
class ImageShaderGM : public skiagm::GM { class ImageShaderGM : public skiagm::GM {
SkAutoTUnref<SkPicture> fPicture; sk_sp<SkPicture> fPicture;
public: public:
ImageShaderGM() {} ImageShaderGM() {}
@ -90,7 +90,7 @@ protected:
const SkRect bounds = SkRect::MakeWH(100, 100); const SkRect bounds = SkRect::MakeWH(100, 100);
SkPictureRecorder recorder; SkPictureRecorder recorder;
draw_something(recorder.beginRecording(bounds), bounds); draw_something(recorder.beginRecording(bounds), bounds);
fPicture.reset(recorder.endRecording()); fPicture = recorder.finishRecordingAsPicture();
} }
void testImage(SkCanvas* canvas, SkImage* image) { void testImage(SkCanvas* canvas, SkImage* image) {
@ -113,7 +113,7 @@ protected:
const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100);
for (size_t i = 0; i < SK_ARRAY_COUNT(gProcs); ++i) { for (size_t i = 0; i < SK_ARRAY_COUNT(gProcs); ++i) {
sk_sp<SkImage> image(gProcs[i](canvas->getGrContext(), fPicture, info)); sk_sp<SkImage> image(gProcs[i](canvas->getGrContext(), fPicture.get(), info));
if (image) { if (image) {
this->testImage(canvas, image.get()); this->testImage(canvas, image.get());
} }

View File

@ -41,7 +41,7 @@ static SkPath make_hex_path(SkScalar originX, SkScalar originY) {
// Make a picture that is a tiling of the plane with stroked hexagons where // Make a picture that is a tiling of the plane with stroked hexagons where
// each hexagon is in its own layer. The layers are to exercise Ganesh's // each hexagon is in its own layer. The layers are to exercise Ganesh's
// layer hoisting. // layer hoisting.
static const SkPicture* make_hex_plane_picture(SkColor fillColor) { static sk_sp<SkPicture> make_hex_plane_picture(SkColor fillColor) {
// Create a hexagon with its center at the origin // Create a hexagon with its center at the origin
SkPath hex = make_hex_path(0, 0); SkPath hex = make_hex_path(0, 0);
@ -80,14 +80,14 @@ static const SkPicture* make_hex_plane_picture(SkColor fillColor) {
yPos += 2 * kHexSide * kRoot3Over2; yPos += 2 * kHexSide * kRoot3Over2;
} }
return recorder.endRecording(); return recorder.finishRecordingAsPicture();
} }
// Create a picture that consists of a single large layer that is tiled // Create a picture that consists of a single large layer that is tiled
// with hexagons. // with hexagons.
// This is intended to exercise the layer hoisting code's clip handling (in // This is intended to exercise the layer hoisting code's clip handling (in
// tile mode). // tile mode).
static const SkPicture* make_single_layer_hex_plane_picture() { static sk_sp<SkPicture> make_single_layer_hex_plane_picture() {
// Create a hexagon with its center at the origin // Create a hexagon with its center at the origin
SkPath hex = make_hex_path(0, 0); SkPath hex = make_hex_path(0, 0);
@ -136,7 +136,7 @@ static const SkPicture* make_single_layer_hex_plane_picture() {
canvas->restore(); canvas->restore();
return recorder.endRecording(); return recorder.finishRecordingAsPicture();
} }
// Make an equilateral triangle path with its top corner at (originX, originY) // Make an equilateral triangle path with its top corner at (originX, originY)
@ -149,7 +149,7 @@ static SkPath make_tri_path(SkScalar originX, SkScalar originY) {
return tri; return tri;
} }
static const SkPicture* make_tri_picture() { static sk_sp<SkPicture> make_tri_picture() {
SkPath tri = make_tri_path(SkScalarHalf(kTriSide), 0); SkPath tri = make_tri_path(SkScalarHalf(kTriSide), 0);
SkPaint fill; SkPaint fill;
@ -176,10 +176,10 @@ static const SkPicture* make_tri_picture() {
canvas->drawPath(tri, stroke); canvas->drawPath(tri, stroke);
canvas->restore(); canvas->restore();
return recorder.endRecording(); return recorder.finishRecordingAsPicture();
} }
static const SkPicture* make_sub_picture(const SkPicture* tri) { static sk_sp<SkPicture> make_sub_picture(const SkPicture* tri) {
SkPictureRecorder recorder; SkPictureRecorder recorder;
SkRTreeFactory bbhFactory; SkRTreeFactory bbhFactory;
@ -205,15 +205,15 @@ static const SkPicture* make_sub_picture(const SkPicture* tri) {
canvas->drawPicture(tri); canvas->drawPicture(tri);
canvas->restore(); canvas->restore();
return recorder.endRecording(); return recorder.finishRecordingAsPicture();
} }
// Create a Sierpinkski-like picture that starts with a top row with a picture // Create a Sierpinkski-like picture that starts with a top row with a picture
// that just contains a triangle. Subsequent rows take the prior row's picture, // that just contains a triangle. Subsequent rows take the prior row's picture,
// shrinks it and replicates it 3 times then draws and appropriate number of // shrinks it and replicates it 3 times then draws and appropriate number of
// copies of it. // copies of it.
static const SkPicture* make_sierpinski_picture() { static sk_sp<SkPicture> make_sierpinski_picture() {
SkAutoTUnref<const SkPicture> pic(make_tri_picture()); sk_sp<SkPicture> pic(make_tri_picture());
SkPictureRecorder recorder; SkPictureRecorder recorder;
SkRTreeFactory bbhFactory; SkRTreeFactory bbhFactory;
@ -233,12 +233,12 @@ static const SkPicture* make_sierpinski_picture() {
} }
canvas->restore(); canvas->restore();
pic.reset(make_sub_picture(pic)); pic = make_sub_picture(pic.get());
canvas->translate(0, 1.5f * kTriSide / kRoot3); canvas->translate(0, 1.5f * kTriSide / kRoot3);
} }
return recorder.endRecording(); return recorder.finishRecordingAsPicture();
} }
static SkSurface* create_compat_surface(SkCanvas* canvas, int width, int height) { static SkSurface* create_compat_surface(SkCanvas* canvas, int width, int height) {
@ -356,7 +356,7 @@ static const PFContentMtd gContentMthds[] = {
static void create_content(SkMultiPictureDraw* mpd, PFContentMtd pfGen, static void create_content(SkMultiPictureDraw* mpd, PFContentMtd pfGen,
const SkPicture* pictures[kNumPictures], const SkPicture* pictures[kNumPictures],
SkCanvas* dest, const SkMatrix& xform) { SkCanvas* dest, const SkMatrix& xform) {
SkAutoTUnref<SkPicture> composite; sk_sp<SkPicture> composite;
{ {
SkPictureRecorder recorder; SkPictureRecorder recorder;
@ -369,10 +369,10 @@ static void create_content(SkMultiPictureDraw* mpd, PFContentMtd pfGen,
(*pfGen)(pictureCanvas, pictures); (*pfGen)(pictureCanvas, pictures);
composite.reset(recorder.endRecording()); composite = recorder.finishRecordingAsPicture();
} }
mpd->add(dest, composite, &xform); mpd->add(dest, composite.get(), &xform);
} }
typedef void(*PFLayoutMtd)(SkCanvas* finalCanvas, SkMultiPictureDraw* mpd, typedef void(*PFLayoutMtd)(SkCanvas* finalCanvas, SkMultiPictureDraw* mpd,
@ -490,10 +490,10 @@ namespace skiagm {
const SkPicture* fPictures[kNumPictures]; const SkPicture* fPictures[kNumPictures];
void onOnceBeforeDraw() override { void onOnceBeforeDraw() override {
fPictures[0] = make_hex_plane_picture(SK_ColorWHITE); fPictures[0] = make_hex_plane_picture(SK_ColorWHITE).release();
fPictures[1] = make_hex_plane_picture(sk_tool_utils::color_to_565(SK_ColorGRAY)); fPictures[1] = make_hex_plane_picture(sk_tool_utils::color_to_565(SK_ColorGRAY)).release();
fPictures[2] = make_sierpinski_picture(); fPictures[2] = make_sierpinski_picture().release();
fPictures[3] = make_single_layer_hex_plane_picture(); fPictures[3] = make_single_layer_hex_plane_picture().release();
} }
void onDraw(SkCanvas* canvas) override { void onDraw(SkCanvas* canvas) override {

View File

@ -47,7 +47,7 @@ protected:
rec->translate(SkIntToScalar(250), SkIntToScalar(250)); rec->translate(SkIntToScalar(250), SkIntToScalar(250));
rec->clipPath(p, SkRegion::kIntersect_Op, true); rec->clipPath(p, SkRegion::kIntersect_Op, true);
rec->drawColor(0xffff0000); rec->drawColor(0xffff0000);
SkAutoTUnref<SkPicture> pict(recorder.endRecording()); sk_sp<SkPicture> pict(recorder.finishRecordingAsPicture());
canvas->setAllowSimplifyClip(true); canvas->setAllowSimplifyClip(true);
canvas->save(); canvas->save();

View File

@ -9,7 +9,7 @@
#include "SkPaint.h" #include "SkPaint.h"
#include "SkPictureRecorder.h" #include "SkPictureRecorder.h"
static SkPicture* make_picture() { static sk_sp<SkPicture> make_picture() {
SkPictureRecorder rec; SkPictureRecorder rec;
SkCanvas* canvas = rec.beginRecording(100, 100); SkCanvas* canvas = rec.beginRecording(100, 100);
@ -32,7 +32,7 @@ static SkPicture* make_picture() {
paint.setXfermodeMode(SkXfermode::kPlus_Mode); paint.setXfermodeMode(SkXfermode::kPlus_Mode);
canvas->drawRect(SkRect::MakeXYWH(25, 25, 50, 50), paint); canvas->drawRect(SkRect::MakeXYWH(25, 25, 50, 50), paint);
return rec.endRecording(); return rec.finishRecordingAsPicture();
} }
// Exercise the optional arguments to drawPicture // Exercise the optional arguments to drawPicture
@ -45,7 +45,7 @@ public:
protected: protected:
void onOnceBeforeDraw() override { void onOnceBeforeDraw() override {
fPicture.reset(make_picture()); fPicture = make_picture();
} }
SkString onShortName() override { SkString onShortName() override {
@ -76,7 +76,7 @@ protected:
} }
private: private:
SkAutoTUnref<SkPicture> fPicture; sk_sp<SkPicture> fPicture;
typedef skiagm::GM INHERITED; typedef skiagm::GM INHERITED;
}; };

View File

@ -33,7 +33,7 @@ protected:
paint.setTextSize(SkIntToScalar(96)); paint.setTextSize(SkIntToScalar(96));
const char* str = "e"; const char* str = "e";
canvas->drawText(str, strlen(str), SkIntToScalar(20), SkIntToScalar(70), paint); canvas->drawText(str, strlen(str), SkIntToScalar(20), SkIntToScalar(70), paint);
fPicture.reset(recorder.endRecording()); fPicture = recorder.finishRecordingAsPicture();
} }
SkISize onISize() override { return SkISize::Make(600, 300); } SkISize onISize() override { return SkISize::Make(600, 300); }
@ -58,16 +58,16 @@ protected:
SkRect emptyRect = SkRect::MakeXYWH(20, 20, 0, 0); SkRect emptyRect = SkRect::MakeXYWH(20, 20, 0, 0);
SkRect bounds = SkRect::MakeXYWH(0, 0, 100, 100); SkRect bounds = SkRect::MakeXYWH(0, 0, 100, 100);
SkAutoTUnref<SkImageFilter> pictureSource( SkAutoTUnref<SkImageFilter> pictureSource(
SkPictureImageFilter::Create(fPicture)); SkPictureImageFilter::Create(fPicture.get()));
SkAutoTUnref<SkImageFilter> pictureSourceSrcRect( SkAutoTUnref<SkImageFilter> pictureSourceSrcRect(
SkPictureImageFilter::Create(fPicture, srcRect)); SkPictureImageFilter::Create(fPicture.get(), srcRect));
SkAutoTUnref<SkImageFilter> pictureSourceEmptyRect( SkAutoTUnref<SkImageFilter> pictureSourceEmptyRect(
SkPictureImageFilter::Create(fPicture, emptyRect)); SkPictureImageFilter::Create(fPicture.get(), emptyRect));
SkAutoTUnref<SkImageFilter> pictureSourceResampled( SkAutoTUnref<SkImageFilter> pictureSourceResampled(
SkPictureImageFilter::CreateForLocalSpace(fPicture, fPicture->cullRect(), SkPictureImageFilter::CreateForLocalSpace(fPicture.get(), fPicture->cullRect(),
kLow_SkFilterQuality)); kLow_SkFilterQuality));
SkAutoTUnref<SkImageFilter> pictureSourcePixelated( SkAutoTUnref<SkImageFilter> pictureSourcePixelated(
SkPictureImageFilter::CreateForLocalSpace(fPicture, fPicture->cullRect(), SkPictureImageFilter::CreateForLocalSpace(fPicture.get(), fPicture->cullRect(),
kNone_SkFilterQuality)); kNone_SkFilterQuality));
canvas->save(); canvas->save();
@ -102,7 +102,7 @@ protected:
} }
private: private:
SkAutoTUnref<SkPicture> fPicture; sk_sp<SkPicture> fPicture;
typedef GM INHERITED; typedef GM INHERITED;
}; };

View File

@ -108,7 +108,7 @@ protected:
SkPictureRecorder recorder; SkPictureRecorder recorder;
SkCanvas* canvas = recorder.beginRecording(rect); SkCanvas* canvas = recorder.beginRecording(rect);
draw_vector_logo(canvas, rect); draw_vector_logo(canvas, rect);
fPicture.reset(recorder.endRecording()); fPicture = recorder.finishRecordingAsPicture();
} }
void onDraw(SkCanvas* canvas) override { void onDraw(SkCanvas* canvas) override {
@ -171,7 +171,7 @@ protected:
} }
private: private:
SkAutoTUnref<SkPicture> fPicture; sk_sp<SkPicture> fPicture;
const SkScalar kPictureWidth = 200; const SkScalar kPictureWidth = 200;
const SkScalar kPictureHeight = 100; const SkScalar kPictureHeight = 100;

View File

@ -35,7 +35,7 @@ public:
SkPictureRecorder recorder; SkPictureRecorder recorder;
SkCanvas* pictureCanvas = recorder.beginRecording(fTileSize, fTileSize, nullptr, 0); SkCanvas* pictureCanvas = recorder.beginRecording(fTileSize, fTileSize, nullptr, 0);
this->drawTile(pictureCanvas); this->drawTile(pictureCanvas);
fPicture.reset(recorder.endRecording()); fPicture = recorder.finishRecordingAsPicture();
// Build a reference bitmap. // Build a reference bitmap.
fBitmap.allocN32Pixels(SkScalarCeilToInt(fTileSize), SkScalarCeilToInt(fTileSize)); fBitmap.allocN32Pixels(SkScalarCeilToInt(fTileSize), SkScalarCeilToInt(fTileSize));
@ -193,7 +193,7 @@ DEF_SIMPLE_GM(tiled_picture_shader, canvas, 400, 400) {
p.setStrokeWidth(10); p.setStrokeWidth(10);
c->drawLine(20, 20, 80, 80, p); c->drawLine(20, 20, 80, 80, p);
sk_sp<SkPicture> picture(recorder.endRecording()); sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
sk_sp<SkShader> shader(SkShader::MakePictureShader(picture, SkShader::kRepeat_TileMode, sk_sp<SkShader> shader(SkShader::MakePictureShader(picture, SkShader::kRepeat_TileMode,
SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode,
nullptr, nullptr)); nullptr, nullptr));

View File

@ -95,14 +95,14 @@ protected:
SkPictureRecorder recorder; SkPictureRecorder recorder;
SkCanvas* pictureCanvas = recorder.beginRecording(kPictureSize, kPictureSize); SkCanvas* pictureCanvas = recorder.beginRecording(kPictureSize, kPictureSize);
draw_scene(pictureCanvas, kPictureSize); draw_scene(pictureCanvas, kPictureSize);
sk_sp<SkPicture> picture(recorder.endRecording()); sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
SkPoint offset = SkPoint::Make(100, 100); SkPoint offset = SkPoint::Make(100, 100);
pictureCanvas = recorder.beginRecording(SkRect::MakeXYWH(offset.x(), offset.y(), pictureCanvas = recorder.beginRecording(SkRect::MakeXYWH(offset.x(), offset.y(),
kPictureSize, kPictureSize)); kPictureSize, kPictureSize));
pictureCanvas->translate(offset.x(), offset.y()); pictureCanvas->translate(offset.x(), offset.y());
draw_scene(pictureCanvas, kPictureSize); draw_scene(pictureCanvas, kPictureSize);
sk_sp<SkPicture> offsetPicture(recorder.endRecording()); sk_sp<SkPicture> offsetPicture(recorder.finishRecordingAsPicture());
for (unsigned i = 0; i < SK_ARRAY_COUNT(tiles); ++i) { for (unsigned i = 0; i < SK_ARRAY_COUNT(tiles); ++i) {
SkRect tile = SkRect::MakeXYWH(tiles[i].x * kPictureSize, SkRect tile = SkRect::MakeXYWH(tiles[i].x * kPictureSize,

View File

@ -100,7 +100,7 @@ static void draw_svg_opacity_and_filter_layer_sequence(SkCanvas* canvas, SkColor
InstallDetectorFunc installDetector) { InstallDetectorFunc installDetector) {
SkRect targetRect(SkRect::MakeWH(SkIntToScalar(kTestRectSize), SkIntToScalar(kTestRectSize))); SkRect targetRect(SkRect::MakeWH(SkIntToScalar(kTestRectSize), SkIntToScalar(kTestRectSize)));
SkAutoTUnref<SkPicture> shape; sk_sp<SkPicture> shape;
{ {
SkPictureRecorder recorder; SkPictureRecorder recorder;
SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kTestRectSize + 2), SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kTestRectSize + 2),
@ -108,7 +108,7 @@ static void draw_svg_opacity_and_filter_layer_sequence(SkCanvas* canvas, SkColor
SkPaint shapePaint; SkPaint shapePaint;
shapePaint.setColor(shapeColor); shapePaint.setColor(shapeColor);
canvas->drawRect(targetRect, shapePaint); canvas->drawRect(targetRect, shapePaint);
shape.reset(recorder.endRecordingAsPicture()); shape = recorder.finishRecordingAsPicture();
} }
SkPaint layerPaint; SkPaint layerPaint;
@ -117,7 +117,7 @@ static void draw_svg_opacity_and_filter_layer_sequence(SkCanvas* canvas, SkColor
canvas->save(); canvas->save();
canvas->clipRect(targetRect); canvas->clipRect(targetRect);
SkPaint drawPaint; SkPaint drawPaint;
drawPaint.setImageFilter(SkPictureImageFilter::Create(shape))->unref(); drawPaint.setImageFilter(SkPictureImageFilter::Create(shape.get()))->unref();
installDetector(&drawPaint); installDetector(&drawPaint);
canvas->saveLayer(&targetRect, &drawPaint); canvas->saveLayer(&targetRect, &drawPaint);
canvas->restore(); canvas->restore();
@ -161,8 +161,7 @@ DEF_SIMPLE_GM(recordopts, canvas, (kTestRectSize+1)*2, (kTestRectSize+1)*15) {
drawTestSequence(recorder.beginRecording(SkIntToScalar(kTestRectSize), drawTestSequence(recorder.beginRecording(SkIntToScalar(kTestRectSize),
SkIntToScalar(kTestRectSize)), SkIntToScalar(kTestRectSize)),
shapeColor, no_detector_install); shapeColor, no_detector_install);
SkAutoTUnref<SkPicture> optimizedPicture(recorder.endRecordingAsPicture()); recorder.finishRecordingAsPicture()->playback(canvas);
optimizedPicture->playback(canvas);
canvas->flush(); canvas->flush();
} }
canvas->restore(); canvas->restore();
@ -203,8 +202,7 @@ DEF_SIMPLE_GM(recordopts, canvas, (kTestRectSize+1)*2, (kTestRectSize+1)*15) {
drawTestSequence(recorder.beginRecording(SkIntToScalar(kTestRectSize), drawTestSequence(recorder.beginRecording(SkIntToScalar(kTestRectSize),
SkIntToScalar(kTestRectSize)), SkIntToScalar(kTestRectSize)),
shapeColor, detectorInstallFunc); shapeColor, detectorInstallFunc);
SkAutoTUnref<SkPicture> optimizedPicture(recorder.endRecordingAsPicture()); recorder.finishRecordingAsPicture()->playback(canvas);
optimizedPicture->playback(canvas);
canvas->flush(); canvas->flush();
} }

View File

@ -31,9 +31,8 @@ static sk_sp<SkImage> make_raster_image(int width, int height, SkColor colors[2]
static sk_sp<SkImage> make_picture_image(int width, int height, SkColor colors[2]) { static sk_sp<SkImage> make_picture_image(int width, int height, SkColor colors[2]) {
SkPictureRecorder recorder; SkPictureRecorder recorder;
draw(recorder.beginRecording(SkRect::MakeIWH(width, height)), width, height, colors); draw(recorder.beginRecording(SkRect::MakeIWH(width, height)), width, height, colors);
SkAutoTUnref<SkPicture> picture(recorder.endRecording()); return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(),
return SkImage::MakeFromPicture(sk_ref_sp(picture.get()), SkISize::Make(width, height), SkISize::Make(width, height), nullptr, nullptr);
nullptr, nullptr);
} }
typedef sk_sp<SkImage> (*ImageMakerProc)(int width, int height, SkColor colors[2]); typedef sk_sp<SkImage> (*ImageMakerProc)(int width, int height, SkColor colors[2]);

View File

@ -995,7 +995,7 @@ public:
void drawPicture(const SkPicture* picture) { void drawPicture(const SkPicture* picture) {
this->drawPicture(picture, NULL, NULL); this->drawPicture(picture, NULL, NULL);
} }
void drawPicture(sk_sp<SkPicture>& picture) { void drawPicture(const sk_sp<SkPicture>& picture) {
this->drawPicture(picture.get()); this->drawPicture(picture.get());
} }
@ -1012,7 +1012,7 @@ public:
* saveLayer(paint)/drawPicture/restore * saveLayer(paint)/drawPicture/restore
*/ */
void drawPicture(const SkPicture*, const SkMatrix* matrix, const SkPaint* paint); void drawPicture(const SkPicture*, const SkMatrix* matrix, const SkPaint* paint);
void drawPicture(sk_sp<SkPicture>& picture, const SkMatrix* matrix, const SkPaint* paint) { void drawPicture(const sk_sp<SkPicture>& picture, const SkMatrix* matrix, const SkPaint* paint) {
this->drawPicture(picture.get(), matrix, paint); this->drawPicture(picture.get(), matrix, paint);
} }

View File

@ -24,6 +24,8 @@ class SkTypefacePlayback;
class SkWStream; class SkWStream;
struct SkPictInfo; struct SkPictInfo;
#define SK_SUPPORT_LEGACY_PICTURE_PTR
/** \class SkPicture /** \class SkPicture
An SkPicture records drawing commands made to a canvas to be played back at a later time. An SkPicture records drawing commands made to a canvas to be played back at a later time.
@ -54,7 +56,7 @@ public:
* @return A new SkPicture representing the serialized data, or NULL if the stream is * @return A new SkPicture representing the serialized data, or NULL if the stream is
* invalid. * invalid.
*/ */
static SkPicture* CreateFromStream(SkStream*, InstallPixelRefProc proc); static sk_sp<SkPicture> MakeFromStream(SkStream*, InstallPixelRefProc proc);
/** /**
* Recreate a picture that was serialized into a stream. * Recreate a picture that was serialized into a stream.
@ -66,7 +68,7 @@ public:
* @return A new SkPicture representing the serialized data, or NULL if the stream is * @return A new SkPicture representing the serialized data, or NULL if the stream is
* invalid. * invalid.
*/ */
static SkPicture* CreateFromStream(SkStream*); static sk_sp<SkPicture> MakeFromStream(SkStream*);
/** /**
* Recreate a picture that was serialized into a buffer. If the creation requires bitmap * Recreate a picture that was serialized into a buffer. If the creation requires bitmap
@ -76,7 +78,7 @@ public:
* @return A new SkPicture representing the serialized data, or NULL if the buffer is * @return A new SkPicture representing the serialized data, or NULL if the buffer is
* invalid. * invalid.
*/ */
static SkPicture* CreateFromBuffer(SkReadBuffer&); static sk_sp<SkPicture> MakeFromBuffer(SkReadBuffer&);
/** /**
* Subclasses of this can be passed to playback(). During the playback * Subclasses of this can be passed to playback(). During the playback
@ -167,6 +169,18 @@ public:
static void SetPictureIOSecurityPrecautionsEnabled_Dangerous(bool set); static void SetPictureIOSecurityPrecautionsEnabled_Dangerous(bool set);
static bool PictureIOSecurityPrecautionsEnabled(); static bool PictureIOSecurityPrecautionsEnabled();
#ifdef SK_SUPPORT_LEGACY_PICTURE_PTR
static SkPicture* CreateFromStream(SkStream* stream, InstallPixelRefProc proc) {
return MakeFromStream(stream, proc).release();
}
static SkPicture* CreateFromStream(SkStream* stream) {
return MakeFromStream(stream).release();
}
static SkPicture* CreateFromBuffer(SkReadBuffer& rbuf) {
return MakeFromBuffer(rbuf).release();
}
#endif
private: private:
// Subclass whitelist. // Subclass whitelist.
SkPicture(); SkPicture();
@ -175,9 +189,7 @@ private:
template <typename> friend class SkMiniPicture; template <typename> friend class SkMiniPicture;
void serialize(SkWStream*, SkPixelSerializer*, SkRefCntSet* typefaces) const; void serialize(SkWStream*, SkPixelSerializer*, SkRefCntSet* typefaces) const;
static SkPicture* CreateFromStream(SkStream*, static sk_sp<SkPicture> MakeFromStream(SkStream*, InstallPixelRefProc, SkTypefacePlayback*);
InstallPixelRefProc proc,
SkTypefacePlayback*);
friend class SkPictureData; friend class SkPictureData;
virtual int numSlowPaths() const = 0; virtual int numSlowPaths() const = 0;
@ -208,7 +220,7 @@ private:
"Remove SkBitmapSourceDeserializer."); "Remove SkBitmapSourceDeserializer.");
static bool IsValidPictInfo(const SkPictInfo& info); static bool IsValidPictInfo(const SkPictInfo& info);
static SkPicture* Forwardport(const SkPictInfo&, const SkPictureData*); static sk_sp<SkPicture> Forwardport(const SkPictInfo&, const SkPictureData*);
SkPictInfo createHeader() const; SkPictInfo createHeader() const;
SkPictureData* backport() const; SkPictureData* backport() const;

View File

@ -72,7 +72,7 @@ public:
* reflect their current state, but will not contain a live reference to the drawables * reflect their current state, but will not contain a live reference to the drawables
* themselves. * themselves.
*/ */
SkPicture* SK_WARN_UNUSED_RESULT endRecordingAsPicture(); sk_sp<SkPicture> finishRecordingAsPicture();
/** /**
* Signal that the caller is done recording, and update the cull rect to use for bounding * Signal that the caller is done recording, and update the cull rect to use for bounding
@ -83,7 +83,7 @@ public:
* and subsequent culling operations. * and subsequent culling operations.
* @return the picture containing the recorded content. * @return the picture containing the recorded content.
*/ */
SkPicture* SK_WARN_UNUSED_RESULT endRecordingAsPicture(const SkRect& cullRect); sk_sp<SkPicture> finishRecordingAsPictureWithCull(const SkRect& cullRect);
/** /**
* Signal that the caller is done recording. This invalidates the canvas returned by * Signal that the caller is done recording. This invalidates the canvas returned by
@ -95,10 +95,20 @@ public:
* and therefore this drawable will reflect the current state of those nested drawables anytime * and therefore this drawable will reflect the current state of those nested drawables anytime
* it is drawn or a new picture is snapped from it (by calling drawable->newPictureSnapshot()). * it is drawn or a new picture is snapped from it (by calling drawable->newPictureSnapshot()).
*/ */
SkDrawable* SK_WARN_UNUSED_RESULT endRecordingAsDrawable(); sk_sp<SkDrawable> finishRecordingAsDrawable();
// Legacy API -- use endRecordingAsPicture instead. #ifdef SK_SUPPORT_LEGACY_PICTURE_PTR
SkPicture* SK_WARN_UNUSED_RESULT endRecordingAsPicture() {
return this->finishRecordingAsPicture().release();
}
SkPicture* SK_WARN_UNUSED_RESULT endRecordingAsPicture(const SkRect& cullRect) {
return this->finishRecordingAsPictureWithCull(cullRect).release();
}
SkDrawable* SK_WARN_UNUSED_RESULT endRecordingAsDrawable() {
return this->finishRecordingAsDrawable().release();
}
SkPicture* SK_WARN_UNUSED_RESULT endRecording() { return this->endRecordingAsPicture(); } SkPicture* SK_WARN_UNUSED_RESULT endRecording() { return this->endRecordingAsPicture(); }
#endif
private: private:
void reset(); void reset();

View File

@ -27,7 +27,7 @@ public:
bool drawTextBlob(const SkTextBlob*, SkScalar x, SkScalar y, const SkPaint&); bool drawTextBlob(const SkTextBlob*, SkScalar x, SkScalar y, const SkPaint&);
// Detach anything we've recorded as a picture, resetting this SkMiniRecorder. // Detach anything we've recorded as a picture, resetting this SkMiniRecorder.
SkPicture* detachAsPicture(const SkRect& cull); sk_sp<SkPicture> detachAsPicture(const SkRect& cull);
// Flush anything we've recorded to the canvas, resetting this SkMiniRecorder. // Flush anything we've recorded to the canvas, resetting this SkMiniRecorder.
// This is logically the same as but rather more efficient than: // This is logically the same as but rather more efficient than:

View File

@ -305,7 +305,7 @@ protected:
SkCanvas* record = recorder.beginRecording(320, 480, nullptr, 0); SkCanvas* record = recorder.beginRecording(320, 480, nullptr, 0);
this->drawPicture(record, 120); this->drawPicture(record, 120);
} }
SkAutoTUnref<SkPicture> picture(recorder.endRecording()); sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
canvas->translate(0, SkIntToScalar(120)); canvas->translate(0, SkIntToScalar(120));

View File

@ -1389,7 +1389,7 @@ void SampleWindow::afterChildren(SkCanvas* orig) {
} }
if (fSaveToSKP) { if (fSaveToSKP) {
SkAutoTUnref<const SkPicture> picture(fRecorder.endRecording()); sk_sp<SkPicture> picture(fRecorder.finishRecordingAsPicture());
SkFILEWStream stream("sample_app.skp"); SkFILEWStream stream("sample_app.skp");
picture->serialize(&stream); picture->serialize(&stream);
fSaveToSKP = false; fSaveToSKP = false;
@ -1398,7 +1398,7 @@ void SampleWindow::afterChildren(SkCanvas* orig) {
} }
if (fUsePicture) { if (fUsePicture) {
SkAutoTUnref<const SkPicture> picture(fRecorder.endRecording()); sk_sp<SkPicture> picture(fRecorder.finishRecordingAsPicture());
// serialize/deserialize? // serialize/deserialize?
if (false) { if (false) {
@ -1406,9 +1406,9 @@ void SampleWindow::afterChildren(SkCanvas* orig) {
picture->serialize(&wstream); picture->serialize(&wstream);
SkAutoTDelete<SkStream> rstream(wstream.detachAsStream()); SkAutoTDelete<SkStream> rstream(wstream.detachAsStream());
picture.reset(SkPicture::CreateFromStream(rstream)); picture = SkPicture::MakeFromStream(rstream);
} }
orig->drawPicture(picture); orig->drawPicture(picture.get());
} }
// Do this after presentGL and other finishing, rather than in afterChild // Do this after presentGL and other finishing, rather than in afterChild

View File

@ -81,8 +81,8 @@ class ArcsView : public SampleView {
public: public:
SkRect fRect; SkRect fRect;
MyDrawable* fAnimatingDrawable; sk_sp<MyDrawable> fAnimatingDrawable;
SkDrawable* fRootDrawable; sk_sp<SkDrawable> fRootDrawable;
ArcsView() { ArcsView() {
testparse(); testparse();
@ -91,16 +91,11 @@ public:
fRect.set(0, 0, SkIntToScalar(200), SkIntToScalar(200)); fRect.set(0, 0, SkIntToScalar(200), SkIntToScalar(200));
fRect.offset(SkIntToScalar(20), SkIntToScalar(20)); fRect.offset(SkIntToScalar(20), SkIntToScalar(20));
fAnimatingDrawable = new MyDrawable(fRect); fAnimatingDrawable = sk_make_sp<MyDrawable>(fRect);
SkPictureRecorder recorder; SkPictureRecorder recorder;
this->drawRoot(recorder.beginRecording(SkRect::MakeWH(800, 500))); this->drawRoot(recorder.beginRecording(SkRect::MakeWH(800, 500)));
fRootDrawable = recorder.endRecordingAsDrawable(); fRootDrawable = recorder.finishRecordingAsDrawable();
}
~ArcsView() override {
fAnimatingDrawable->unref();
fRootDrawable->unref();
} }
protected: protected:
@ -186,13 +181,13 @@ protected:
DrawRectWithLines(canvas, fRect, paint); DrawRectWithLines(canvas, fRect, paint);
canvas->drawDrawable(fAnimatingDrawable); canvas->drawDrawable(fAnimatingDrawable.get());
DrawArcs(canvas); DrawArcs(canvas);
} }
void onDrawContent(SkCanvas* canvas) override { void onDrawContent(SkCanvas* canvas) override {
canvas->drawDrawable(fRootDrawable); canvas->drawDrawable(fRootDrawable.get());
} }
bool onAnimate(const SkAnimTimer& timer) override { bool onAnimate(const SkAnimTimer& timer) override {

View File

@ -712,7 +712,7 @@ static SkImageFilter* make_image_filter(bool canBeNull) {
SkIntToScalar(kBitmapSize), SkIntToScalar(kBitmapSize),
&factory, 0); &factory, 0);
drawSomething(recordingCanvas); drawSomething(recordingCanvas);
SkAutoTUnref<SkPicture> pict(recorder.endRecording()); sk_sp<SkPicture> pict(recorder.finishRecordingAsPicture());
filter = SkPictureImageFilter::Create(pict.get(), make_rect()); filter = SkPictureImageFilter::Create(pict.get(), make_rect());
} }
break; break;

View File

@ -127,7 +127,7 @@ public:
HTDrawable* fDrawable; HTDrawable* fDrawable;
}; };
Rec fArray[N]; Rec fArray[N];
SkAutoTUnref<SkDrawable> fRoot; sk_sp<SkDrawable> fRoot;
SkMSec fTime; SkMSec fTime;
HTView() { HTView() {
@ -140,7 +140,7 @@ public:
canvas->drawDrawable(fArray[i].fDrawable); canvas->drawDrawable(fArray[i].fDrawable);
fArray[i].fDrawable->unref(); fArray[i].fDrawable->unref();
} }
fRoot.reset(recorder.endRecordingAsDrawable()); fRoot = recorder.finishRecordingAsDrawable();
} }
protected: protected:
@ -153,7 +153,7 @@ protected:
} }
void onDrawContent(SkCanvas* canvas) override { void onDrawContent(SkCanvas* canvas) override {
canvas->drawDrawable(fRoot); canvas->drawDrawable(fRoot.get());
} }
bool onAnimate(const SkAnimTimer& timer) override { bool onAnimate(const SkAnimTimer& timer) override {

View File

@ -117,7 +117,7 @@ protected:
#endif #endif
if (!*picture) { if (!*picture) {
*picture = LoadPicture(fFilename.c_str(), fBBox); *picture = LoadPicture(fFilename.c_str(), fBBox).release();
} }
if (*picture) { if (*picture) {
SkCounterDrawFilter filter(fCount); SkCounterDrawFilter filter(fCount);
@ -149,8 +149,8 @@ private:
SkSize fTileSize; SkSize fTileSize;
int fCount; int fCount;
SkPicture* LoadPicture(const char path[], BBoxType bbox) { sk_sp<SkPicture> LoadPicture(const char path[], BBoxType bbox) {
SkAutoTUnref<SkPicture> pic; sk_sp<SkPicture> pic;
SkBitmap bm; SkBitmap bm;
if (SkImageDecoder::DecodeFile(path, &bm)) { if (SkImageDecoder::DecodeFile(path, &bm)) {
@ -160,11 +160,11 @@ private:
SkIntToScalar(bm.height()), SkIntToScalar(bm.height()),
nullptr, 0); nullptr, 0);
can->drawBitmap(bm, 0, 0, nullptr); can->drawBitmap(bm, 0, 0, nullptr);
pic.reset(recorder.endRecording()); pic = recorder.finishRecordingAsPicture();
} else { } else {
SkFILEStream stream(path); SkFILEStream stream(path);
if (stream.isValid()) { if (stream.isValid()) {
pic.reset(SkPicture::CreateFromStream(&stream)); pic = SkPicture::MakeFromStream(&stream);
} else { } else {
SkDebugf("coun't load picture at \"path\"\n", path); SkDebugf("coun't load picture at \"path\"\n", path);
} }
@ -174,7 +174,7 @@ private:
pic->playback(recorder.beginRecording(pic->cullRect().width(), pic->playback(recorder.beginRecording(pic->cullRect().width(),
pic->cullRect().height(), pic->cullRect().height(),
nullptr, 0)); nullptr, 0));
SkAutoTUnref<SkPicture> p2(recorder.endRecording()); sk_sp<SkPicture> p2(recorder.finishRecordingAsPicture());
SkString path2(path); SkString path2(path);
path2.append(".new.skp"); path2.append(".new.skp");
@ -191,7 +191,7 @@ private:
switch (bbox) { switch (bbox) {
case kNo_BBoxType: case kNo_BBoxType:
// no bbox playback necessary // no bbox playback necessary
return pic.release(); return std::move(pic);
case kRTree_BBoxType: case kRTree_BBoxType:
factory.reset(new SkRTreeFactory); factory.reset(new SkRTreeFactory);
break; break;
@ -203,7 +203,7 @@ private:
pic->playback(recorder.beginRecording(pic->cullRect().width(), pic->playback(recorder.beginRecording(pic->cullRect().width(),
pic->cullRect().height(), pic->cullRect().height(),
factory.get(), 0)); factory.get(), 0));
return recorder.endRecording(); return recorder.finishRecordingAsPicture();
} }
typedef SampleView INHERITED; typedef SampleView INHERITED;

View File

@ -54,7 +54,7 @@ static const int gWidth = 32;
static const int gHeight = 32; static const int gHeight = 32;
class TilingView : public SampleView { class TilingView : public SampleView {
SkAutoTUnref<SkPicture> fTextPicture; sk_sp<SkPicture> fTextPicture;
SkAutoTUnref<SkDrawLooper> fLooper; SkAutoTUnref<SkDrawLooper> fLooper;
public: public:
TilingView() TilingView()
@ -153,11 +153,11 @@ protected:
if (textCanvas) { if (textCanvas) {
SkASSERT(nullptr == fTextPicture); SkASSERT(nullptr == fTextPicture);
fTextPicture.reset(recorder.endRecording()); fTextPicture = recorder.finishRecordingAsPicture();
} }
SkASSERT(fTextPicture); SkASSERT(fTextPicture);
canvas->drawPicture(fTextPicture); canvas->drawPicture(fTextPicture.get());
} }
private: private:

View File

@ -482,7 +482,7 @@ sk_canvas_t* sk_picture_recorder_begin_recording(sk_picture_recorder_t* crec,
} }
sk_picture_t* sk_picture_recorder_end_recording(sk_picture_recorder_t* crec) { sk_picture_t* sk_picture_recorder_end_recording(sk_picture_recorder_t* crec) {
return ToPicture(AsPictureRecorder(crec)->endRecording()); return ToPicture(AsPictureRecorder(crec)->finishRecordingAsPicture().release());
} }
void sk_picture_ref(sk_picture_t* cpic) { void sk_picture_ref(sk_picture_t* cpic) {

View File

@ -81,5 +81,5 @@ SkPicture* SkDrawable::onNewPictureSnapshot() {
if (false) { if (false) {
draw_bbox(canvas, bounds); draw_bbox(canvas, bounds);
} }
return recorder.endRecording(); return recorder.finishRecordingAsPicture().release();
} }

View File

@ -62,7 +62,7 @@ SkMiniRecorder::~SkMiniRecorder() {
if (fState != State::kEmpty) { if (fState != State::kEmpty) {
// We have internal state pending. // We have internal state pending.
// Detaching then deleting a picture is an easy way to clean up. // Detaching then deleting a picture is an easy way to clean up.
delete this->detachAsPicture(SkRect::MakeEmpty()); (void)this->detachAsPicture(SkRect::MakeEmpty());
} }
SkASSERT(fState == State::kEmpty); SkASSERT(fState == State::kEmpty);
} }
@ -101,14 +101,14 @@ bool SkMiniRecorder::drawTextBlob(const SkTextBlob* b, SkScalar x, SkScalar y, c
#undef TRY_TO_STORE #undef TRY_TO_STORE
SkPicture* SkMiniRecorder::detachAsPicture(const SkRect& cull) { sk_sp<SkPicture> SkMiniRecorder::detachAsPicture(const SkRect& cull) {
#define CASE(Type) \ #define CASE(Type) \
case State::k##Type: \ case State::k##Type: \
fState = State::kEmpty; \ fState = State::kEmpty; \
return new SkMiniPicture<Type>(cull, reinterpret_cast<Type*>(fBuffer.get())) return sk_make_sp<SkMiniPicture<Type>>(cull, reinterpret_cast<Type*>(fBuffer.get()))
switch (fState) { switch (fState) {
case State::kEmpty: return SkRef(gEmptyPicture.get([]{ return new SkEmptyPicture; })); case State::kEmpty: return sk_ref_sp(gEmptyPicture.get([]{ return new SkEmptyPicture; }));
CASE(DrawBitmapRectFixedSize); CASE(DrawBitmapRectFixedSize);
CASE(DrawPath); CASE(DrawPath);
CASE(DrawRect); CASE(DrawRect);

View File

@ -129,14 +129,14 @@ bool SkPicture::InternalOnly_BufferIsSKP(SkReadBuffer* buffer, SkPictInfo* pInfo
return false; return false;
} }
SkPicture* SkPicture::Forwardport(const SkPictInfo& info, const SkPictureData* data) { sk_sp<SkPicture> SkPicture::Forwardport(const SkPictInfo& info, const SkPictureData* data) {
if (!data) { if (!data) {
return nullptr; return nullptr;
} }
SkPicturePlayback playback(data); SkPicturePlayback playback(data);
SkPictureRecorder r; SkPictureRecorder r;
playback.draw(r.beginRecording(info.fCullRect), nullptr/*no callback*/); playback.draw(r.beginRecording(info.fCullRect), nullptr/*no callback*/);
return r.endRecording(); return r.finishRecordingAsPicture();
} }
static bool default_install(const void* src, size_t length, SkBitmap* dst) { static bool default_install(const void* src, size_t length, SkBitmap* dst) {
@ -145,17 +145,16 @@ static bool default_install(const void* src, size_t length, SkBitmap* dst) {
SkImageGenerator::NewFromEncoded(encoded.get()), dst); SkImageGenerator::NewFromEncoded(encoded.get()), dst);
} }
SkPicture* SkPicture::CreateFromStream(SkStream* stream) { sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream) {
return CreateFromStream(stream, &default_install, nullptr); return MakeFromStream(stream, &default_install, nullptr);
} }
SkPicture* SkPicture::CreateFromStream(SkStream* stream, InstallPixelRefProc proc) { sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream, InstallPixelRefProc proc) {
return CreateFromStream(stream, proc, nullptr); return MakeFromStream(stream, proc, nullptr);
} }
SkPicture* SkPicture::CreateFromStream(SkStream* stream, sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream, InstallPixelRefProc proc,
InstallPixelRefProc proc, SkTypefacePlayback* typefaces) {
SkTypefacePlayback* typefaces) {
SkPictInfo info; SkPictInfo info;
if (!InternalOnly_StreamIsSKP(stream, &info) || !stream->readBool()) { if (!InternalOnly_StreamIsSKP(stream, &info) || !stream->readBool()) {
return nullptr; return nullptr;
@ -165,7 +164,7 @@ SkPicture* SkPicture::CreateFromStream(SkStream* stream,
return Forwardport(info, data); return Forwardport(info, data);
} }
SkPicture* SkPicture::CreateFromBuffer(SkReadBuffer& buffer) { sk_sp<SkPicture> SkPicture::MakeFromBuffer(SkReadBuffer& buffer) {
SkPictInfo info; SkPictInfo info;
if (!InternalOnly_BufferIsSKP(&buffer, &info) || !buffer.readBool()) { if (!InternalOnly_BufferIsSKP(&buffer, &info) || !buffer.readBool()) {
return nullptr; return nullptr;

View File

@ -392,7 +392,7 @@ bool SkPictureData::parseStreamTag(SkStream* stream,
fPictureCount = 0; fPictureCount = 0;
fPictureRefs = new const SkPicture* [size]; fPictureRefs = new const SkPicture* [size];
for (uint32_t i = 0; i < size; i++) { for (uint32_t i = 0; i < size; i++) {
fPictureRefs[i] = SkPicture::CreateFromStream(stream, proc, topLevelTFPlayback); fPictureRefs[i] = SkPicture::MakeFromStream(stream, proc, topLevelTFPlayback).release();
if (!fPictureRefs[i]) { if (!fPictureRefs[i]) {
return false; return false;
} }
@ -447,7 +447,7 @@ static const SkImage* create_image_from_buffer(SkReadBuffer& buffer) {
// Need a shallow wrapper to return const SkPicture* to match the other factories, // Need a shallow wrapper to return const SkPicture* to match the other factories,
// as SkPicture::CreateFromBuffer() returns SkPicture* // as SkPicture::CreateFromBuffer() returns SkPicture*
static const SkPicture* create_picture_from_buffer(SkReadBuffer& buffer) { static const SkPicture* create_picture_from_buffer(SkReadBuffer& buffer) {
return SkPicture::CreateFromBuffer(buffer); return SkPicture::MakeFromBuffer(buffer).release();
} }
template <typename T> template <typename T>

View File

@ -50,7 +50,7 @@ SkCanvas* SkPictureRecorder::getRecordingCanvas() {
return fActivelyRecording ? fRecorder.get() : nullptr; return fActivelyRecording ? fRecorder.get() : nullptr;
} }
SkPicture* SkPictureRecorder::endRecordingAsPicture() { sk_sp<SkPicture> SkPictureRecorder::finishRecordingAsPicture() {
fActivelyRecording = false; fActivelyRecording = false;
fRecorder->restoreToCount(1); // If we were missing any restores, add them now. fRecorder->restoreToCount(1); // If we were missing any restores, add them now.
@ -92,13 +92,13 @@ SkPicture* SkPictureRecorder::endRecordingAsPicture() {
for (int i = 0; pictList && i < pictList->count(); i++) { for (int i = 0; pictList && i < pictList->count(); i++) {
subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->begin()[i]); subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->begin()[i]);
} }
return new SkBigPicture(fCullRect, fRecord.release(), pictList, fBBH.release(), return sk_make_sp<SkBigPicture>(fCullRect, fRecord.release(), pictList, fBBH.release(),
saveLayerData.release(), subPictureBytes); saveLayerData.release(), subPictureBytes);
} }
SkPicture* SkPictureRecorder::endRecordingAsPicture(const SkRect& cullRect) { sk_sp<SkPicture> SkPictureRecorder::finishRecordingAsPictureWithCull(const SkRect& cullRect) {
fCullRect = cullRect; fCullRect = cullRect;
return this->endRecordingAsPicture(); return this->finishRecordingAsPicture();
} }
@ -177,7 +177,7 @@ protected:
} }
}; };
SkDrawable* SkPictureRecorder::endRecordingAsDrawable() { sk_sp<SkDrawable> SkPictureRecorder::finishRecordingAsDrawable() {
fActivelyRecording = false; fActivelyRecording = false;
fRecorder->flushMiniRecorder(); fRecorder->flushMiniRecorder();
fRecorder->restoreToCount(1); // If we were missing any restores, add them now. fRecorder->restoreToCount(1); // If we were missing any restores, add them now.
@ -191,8 +191,8 @@ SkDrawable* SkPictureRecorder::endRecordingAsDrawable() {
fBBH->insert(bounds, fRecord->count()); fBBH->insert(bounds, fRecord->count());
} }
SkDrawable* drawable = sk_sp<SkDrawable> drawable =
new SkRecordedDrawable(fRecord, fBBH, fRecorder->detachDrawableList(), fCullRect, sk_make_sp<SkRecordedDrawable>(fRecord, fBBH, fRecorder->detachDrawableList(), fCullRect,
SkToBool(fFlags & kComputeSaveLayerInfo_RecordFlag)); SkToBool(fFlags & kComputeSaveLayerInfo_RecordFlag));
// release our refs now, so only the drawable will be the owner. // release our refs now, so only the drawable will be the owner.

View File

@ -133,7 +133,7 @@ SkFlattenable* SkPictureShader::CreateProc(SkReadBuffer& buffer) {
// Old code always serialized the picture. New code writes a 'true' first if it did. // Old code always serialized the picture. New code writes a 'true' first if it did.
if (buffer.isVersionLT(SkReadBuffer::kPictureShaderHasPictureBool_Version) || if (buffer.isVersionLT(SkReadBuffer::kPictureShaderHasPictureBool_Version) ||
buffer.readBool()) { buffer.readBool()) {
picture.reset(SkPicture::CreateFromBuffer(buffer)); picture = SkPicture::MakeFromBuffer(buffer);
} }
} }
return SkPictureShader::Make(picture, mx, my, &lm, &tile).release(); return SkPictureShader::Make(picture, mx, my, &lm, &tile).release();

View File

@ -36,14 +36,14 @@ SkPictureImageFilter::~SkPictureImageFilter() {
} }
SkFlattenable* SkPictureImageFilter::CreateProc(SkReadBuffer& buffer) { SkFlattenable* SkPictureImageFilter::CreateProc(SkReadBuffer& buffer) {
SkAutoTUnref<SkPicture> picture; sk_sp<SkPicture> picture;
SkRect cropRect; SkRect cropRect;
if (buffer.isCrossProcess() && SkPicture::PictureIOSecurityPrecautionsEnabled()) { if (buffer.isCrossProcess() && SkPicture::PictureIOSecurityPrecautionsEnabled()) {
buffer.validate(!buffer.readBool()); buffer.validate(!buffer.readBool());
} else { } else {
if (buffer.readBool()) { if (buffer.readBool()) {
picture.reset(SkPicture::CreateFromBuffer(buffer)); picture = SkPicture::MakeFromBuffer(buffer);
} }
} }
buffer.readRect(&cropRect); buffer.readRect(&cropRect);
@ -62,9 +62,9 @@ SkFlattenable* SkPictureImageFilter::CreateProc(SkReadBuffer& buffer) {
} else { } else {
filterQuality = (SkFilterQuality)buffer.readInt(); filterQuality = (SkFilterQuality)buffer.readInt();
} }
return CreateForLocalSpace(picture, cropRect, filterQuality); return CreateForLocalSpace(picture.get(), cropRect, filterQuality);
} }
return Create(picture, cropRect); return Create(picture.get(), cropRect);
} }
void SkPictureImageFilter::flatten(SkWriteBuffer& buffer) const { void SkPictureImageFilter::flatten(SkWriteBuffer& buffer) const {

View File

@ -1824,12 +1824,12 @@ static int lpicturerecorder_getCanvas(lua_State* L) {
} }
static int lpicturerecorder_endRecording(lua_State* L) { static int lpicturerecorder_endRecording(lua_State* L) {
SkPicture* pic = get_obj<SkPictureRecorder>(L, 1)->endRecording(); sk_sp<SkPicture> pic = get_obj<SkPictureRecorder>(L, 1)->finishRecordingAsPicture();
if (nullptr == pic) { if (!pic) {
lua_pushnil(L); lua_pushnil(L);
return 1; return 1;
} }
push_ref(L, pic)->unref(); push_ref(L, std::move(pic));
return 1; return 1;
} }

View File

@ -431,9 +431,8 @@ static void DrawPictureTestStep(SkCanvas* canvas, const TestData& d,
testCanvas->scale(SkIntToScalar(2), SkIntToScalar(1)); testCanvas->scale(SkIntToScalar(2), SkIntToScalar(1));
testCanvas->clipRect(d.fRect); testCanvas->clipRect(d.fRect);
testCanvas->drawRect(d.fRect, d.fPaint); testCanvas->drawRect(d.fRect, d.fPaint);
SkAutoTUnref<SkPicture> testPicture(recorder.endRecording());
canvas->drawPicture(testPicture); canvas->drawPicture(recorder.finishRecordingAsPicture());
} }
TEST_STEP(DrawPicture, DrawPictureTestStep); TEST_STEP(DrawPicture, DrawPictureTestStep);

View File

@ -115,7 +115,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GpuLayerCache, reporter, context) {
GrResourceCache::Stats stats; GrResourceCache::Stats stats;
#endif #endif
SkAutoTUnref<const SkPicture> picture; sk_sp<SkPicture> picture;
{ {
SkPictureRecorder recorder; SkPictureRecorder recorder;
@ -123,7 +123,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GpuLayerCache, reporter, context) {
// Draw something, anything, to prevent an empty-picture optimization, // Draw something, anything, to prevent an empty-picture optimization,
// which is a singleton and never purged. // which is a singleton and never purged.
c->drawRect(SkRect::MakeWH(1,1), SkPaint()); c->drawRect(SkRect::MakeWH(1,1), SkPaint());
picture.reset(recorder.endRecording()); picture = recorder.finishRecordingAsPicture();
} }
GrResourceCache* resourceCache = context->getResourceCache(); GrResourceCache* resourceCache = context->getResourceCache();

View File

@ -590,7 +590,7 @@ DEF_TEST(ImageFilterDrawTiled, reporter) {
SkPaint greenPaint; SkPaint greenPaint;
greenPaint.setColor(SK_ColorGREEN); greenPaint.setColor(SK_ColorGREEN);
recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeXYWH(10, 10, 30, 20)), greenPaint); recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeXYWH(10, 10, 30, 20)), greenPaint);
SkAutoTUnref<SkPicture> picture(recorder.endRecording()); sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
SkAutoTUnref<SkImageFilter> pictureFilter(SkPictureImageFilter::Create(picture.get())); SkAutoTUnref<SkImageFilter> pictureFilter(SkPictureImageFilter::Create(picture.get()));
SkAutoTUnref<SkShader> shader(SkPerlinNoiseShader::CreateTurbulence(SK_Scalar1, SK_Scalar1, 1, 0)); SkAutoTUnref<SkShader> shader(SkPerlinNoiseShader::CreateTurbulence(SK_Scalar1, SK_Scalar1, 1, 0));
SkPaint noisePaint; SkPaint noisePaint;
@ -707,7 +707,7 @@ static void draw_saveLayer_picture(int width, int height, int tileSize,
recordingCanvas->translate(-55, 0); recordingCanvas->translate(-55, 0);
recordingCanvas->saveLayer(&bounds, &paint); recordingCanvas->saveLayer(&bounds, &paint);
recordingCanvas->restore(); recordingCanvas->restore();
SkAutoTUnref<SkPicture> picture1(recorder.endRecording()); sk_sp<SkPicture> picture1(recorder.finishRecordingAsPicture());
result->allocN32Pixels(width, height); result->allocN32Pixels(width, height);
SkCanvas canvas(*result); SkCanvas canvas(*result);
@ -900,13 +900,13 @@ DEF_TEST(ImageFilterDrawTiledBlurRTree, reporter) {
&factory, 0); &factory, 0);
draw_blurred_rect(recordingCanvas1); draw_blurred_rect(recordingCanvas1);
draw_blurred_rect(recordingCanvas2); draw_blurred_rect(recordingCanvas2);
SkAutoTUnref<SkPicture> picture1(recorder1.endRecording()); sk_sp<SkPicture> picture1(recorder1.finishRecordingAsPicture());
SkAutoTUnref<SkPicture> picture2(recorder2.endRecording()); sk_sp<SkPicture> picture2(recorder2.finishRecordingAsPicture());
for (int y = 0; y < height; y += tileSize) { for (int y = 0; y < height; y += tileSize) {
for (int x = 0; x < width; x += tileSize) { for (int x = 0; x < width; x += tileSize) {
SkRect tileRect = SkRect::Make(SkIRect::MakeXYWH(x, y, tileSize, tileSize)); SkRect tileRect = SkRect::Make(SkIRect::MakeXYWH(x, y, tileSize, tileSize));
draw_picture_clipped(&canvas1, tileRect, picture1); draw_picture_clipped(&canvas1, tileRect, picture1.get());
draw_picture_clipped(&canvas2, tileRect, picture2); draw_picture_clipped(&canvas2, tileRect, picture2.get());
} }
} }
for (int y = 0; y < height; y++) { for (int y = 0; y < height; y++) {
@ -1010,9 +1010,8 @@ DEF_TEST(ImageFilterMatrix, reporter) {
recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(100, 100)), solidPaint); recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(100, 100)), solidPaint);
recordingCanvas->restore(); // scale recordingCanvas->restore(); // scale
recordingCanvas->restore(); // saveLayer recordingCanvas->restore(); // saveLayer
SkAutoTUnref<SkPicture> picture(recorder.endRecording());
canvas.drawPicture(picture); canvas.drawPicture(recorder.finishRecordingAsPicture());
} }
DEF_TEST(ImageFilterCrossProcessPictureImageFilter, reporter) { DEF_TEST(ImageFilterCrossProcessPictureImageFilter, reporter) {
@ -1024,7 +1023,7 @@ DEF_TEST(ImageFilterCrossProcessPictureImageFilter, reporter) {
SkPaint greenPaint; SkPaint greenPaint;
greenPaint.setColor(SK_ColorGREEN); greenPaint.setColor(SK_ColorGREEN);
recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(1, 1)), greenPaint); recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(1, 1)), greenPaint);
SkAutoTUnref<SkPicture> picture(recorder.endRecording()); sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
// Wrap that SkPicture in an SkPictureImageFilter. // Wrap that SkPicture in an SkPictureImageFilter.
SkAutoTUnref<SkImageFilter> imageFilter( SkAutoTUnref<SkImageFilter> imageFilter(
@ -1040,7 +1039,7 @@ DEF_TEST(ImageFilterCrossProcessPictureImageFilter, reporter) {
redPaintWithFilter.setColor(SK_ColorRED); redPaintWithFilter.setColor(SK_ColorRED);
redPaintWithFilter.setImageFilter(imageFilter.get()); redPaintWithFilter.setImageFilter(imageFilter.get());
outerCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(1, 1)), redPaintWithFilter); outerCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(1, 1)), redPaintWithFilter);
SkAutoTUnref<SkPicture> outerPicture(outerRecorder.endRecording()); sk_sp<SkPicture> outerPicture(outerRecorder.finishRecordingAsPicture());
SkBitmap bitmap; SkBitmap bitmap;
bitmap.allocN32Pixels(1, 1); bitmap.allocN32Pixels(1, 1);
@ -1064,7 +1063,7 @@ DEF_TEST(ImageFilterCrossProcessPictureImageFilter, reporter) {
SkPictureRecorder crossProcessRecorder; SkPictureRecorder crossProcessRecorder;
SkCanvas* crossProcessCanvas = crossProcessRecorder.beginRecording(1, 1, &factory, 0); SkCanvas* crossProcessCanvas = crossProcessRecorder.beginRecording(1, 1, &factory, 0);
crossProcessCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(1, 1)), redPaintWithFilter); crossProcessCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(1, 1)), redPaintWithFilter);
SkAutoTUnref<SkPicture> crossProcessPicture(crossProcessRecorder.endRecording()); sk_sp<SkPicture> crossProcessPicture(crossProcessRecorder.finishRecordingAsPicture());
canvas.clear(0x0); canvas.clear(0x0);
canvas.drawPicture(crossProcessPicture); canvas.drawPicture(crossProcessPicture);
@ -1078,7 +1077,7 @@ DEF_TEST(ImageFilterCrossProcessPictureImageFilter, reporter) {
static void test_clipped_picture_imagefilter(SkImageFilter::Proxy* proxy, static void test_clipped_picture_imagefilter(SkImageFilter::Proxy* proxy,
skiatest::Reporter* reporter, skiatest::Reporter* reporter,
GrContext* context) { GrContext* context) {
SkAutoTUnref<SkPicture> picture; sk_sp<SkPicture> picture;
{ {
SkRTreeFactory factory; SkRTreeFactory factory;
@ -1089,7 +1088,7 @@ static void test_clipped_picture_imagefilter(SkImageFilter::Proxy* proxy,
SkPaint greenPaint; SkPaint greenPaint;
greenPaint.setColor(SK_ColorGREEN); greenPaint.setColor(SK_ColorGREEN);
recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(1, 1)), greenPaint); recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(1, 1)), greenPaint);
picture.reset(recorder.endRecording()); picture = recorder.finishRecordingAsPicture();
} }
sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, proxy, 2)); sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, proxy, 2));
@ -1138,7 +1137,7 @@ DEF_TEST(ImageFilterEmptySaveLayer, reporter) {
SkCanvas* recordingCanvas = recorder.beginRecording(10, 10, &factory, 0); SkCanvas* recordingCanvas = recorder.beginRecording(10, 10, &factory, 0);
recordingCanvas->saveLayer(&bounds, &imageFilterPaint); recordingCanvas->saveLayer(&bounds, &imageFilterPaint);
recordingCanvas->restore(); recordingCanvas->restore();
SkAutoTUnref<SkPicture> picture(recorder.endRecording()); sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
canvas.clear(0); canvas.clear(0);
canvas.drawPicture(picture); canvas.drawPicture(picture);
@ -1148,7 +1147,7 @@ DEF_TEST(ImageFilterEmptySaveLayer, reporter) {
recordingCanvas = recorder.beginRecording(10, 10, &factory, 0); recordingCanvas = recorder.beginRecording(10, 10, &factory, 0);
recordingCanvas->saveLayer(nullptr, &imageFilterPaint); recordingCanvas->saveLayer(nullptr, &imageFilterPaint);
recordingCanvas->restore(); recordingCanvas->restore();
SkAutoTUnref<SkPicture> picture2(recorder.endRecording()); sk_sp<SkPicture> picture2(recorder.finishRecordingAsPicture());
canvas.clear(0); canvas.clear(0);
canvas.drawPicture(picture2); canvas.drawPicture(picture2);
@ -1158,7 +1157,7 @@ DEF_TEST(ImageFilterEmptySaveLayer, reporter) {
recordingCanvas = recorder.beginRecording(10, 10, &factory, 0); recordingCanvas = recorder.beginRecording(10, 10, &factory, 0);
recordingCanvas->saveLayer(&bounds, &colorFilterPaint); recordingCanvas->saveLayer(&bounds, &colorFilterPaint);
recordingCanvas->restore(); recordingCanvas->restore();
SkAutoTUnref<SkPicture> picture3(recorder.endRecording()); sk_sp<SkPicture> picture3(recorder.finishRecordingAsPicture());
canvas.clear(0); canvas.clear(0);
canvas.drawPicture(picture3); canvas.drawPicture(picture3);

View File

@ -111,8 +111,8 @@ static sk_sp<SkImage> create_picture_image() {
SkPictureRecorder recorder; SkPictureRecorder recorder;
SkCanvas* canvas = recorder.beginRecording(10, 10); SkCanvas* canvas = recorder.beginRecording(10, 10);
canvas->clear(SK_ColorCYAN); canvas->clear(SK_ColorCYAN);
sk_sp<SkPicture> picture(recorder.endRecording()); return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(), SkISize::Make(10, 10),
return SkImage::MakeFromPicture(picture, SkISize::Make(10, 10), nullptr, nullptr); nullptr, nullptr);
}; };
#endif #endif
// Want to ensure that our Release is called when the owning image is destroyed // Want to ensure that our Release is called when the owning image is destroyed
@ -232,7 +232,7 @@ DEF_TEST(Image_Serialize_Encoding_Failure, reporter) {
SkPictureRecorder recorder; SkPictureRecorder recorder;
SkCanvas* canvas = recorder.beginRecording(100, 100); SkCanvas* canvas = recorder.beginRecording(100, 100);
canvas->drawImage(image, 0, 0); canvas->drawImage(image, 0, 0);
SkAutoTUnref<SkPicture> picture(recorder.endRecording()); sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
REPORTER_ASSERT(reporter, picture); REPORTER_ASSERT(reporter, picture);
REPORTER_ASSERT(reporter, picture->approximateOpCount() > 0); REPORTER_ASSERT(reporter, picture->approximateOpCount() > 0);
@ -247,7 +247,7 @@ DEF_TEST(Image_Serialize_Encoding_Failure, reporter) {
REPORTER_ASSERT(reporter, serializers[i]->didEncode()); REPORTER_ASSERT(reporter, serializers[i]->didEncode());
SkAutoTDelete<SkStream> rstream(wstream.detachAsStream()); SkAutoTDelete<SkStream> rstream(wstream.detachAsStream());
SkAutoTUnref<SkPicture> deserialized(SkPicture::CreateFromStream(rstream)); sk_sp<SkPicture> deserialized(SkPicture::MakeFromStream(rstream));
REPORTER_ASSERT(reporter, deserialized); REPORTER_ASSERT(reporter, deserialized);
REPORTER_ASSERT(reporter, deserialized->approximateOpCount() > 0); REPORTER_ASSERT(reporter, deserialized->approximateOpCount() > 0);
} }

View File

@ -437,7 +437,7 @@ static void writePict(const SkBitmap& bitmap, const char* outDir, const char* pn
} }
void TestResult::testOne() { void TestResult::testOne() {
SkPicture* pic = nullptr; sk_sp<SkPicture> pic;
{ {
#if DEBUG_SHOW_TEST_NAME #if DEBUG_SHOW_TEST_NAME
if (fTestStep == kCompareBits) { if (fTestStep == kCompareBits) {
@ -465,12 +465,12 @@ void TestResult::testOne() {
SkFILEStream stream(path.c_str()); SkFILEStream stream(path.c_str());
if (!stream.isValid()) { if (!stream.isValid()) {
SkDebugf("invalid stream %s\n", path.c_str()); SkDebugf("invalid stream %s\n", path.c_str());
goto finish; return;
} }
pic = SkPicture::CreateFromStream(&stream); pic = SkPicture::MakeFromStream(&stream);
if (!pic) { if (!pic) {
SkDebugf("unable to decode %s\n", fFilename); SkDebugf("unable to decode %s\n", fFilename);
goto finish; return;
} }
SkScalar width = pic->cullRect().width(); SkScalar width = pic->cullRect().width();
SkScalar height = pic->cullRect().height(); SkScalar height = pic->cullRect().height();
@ -490,7 +490,7 @@ void TestResult::testOne() {
if (fScale >= 256) { if (fScale >= 256) {
SkDebugf("unable to allocate bitmap for %s (w=%f h=%f)\n", fFilename, SkDebugf("unable to allocate bitmap for %s (w=%f h=%f)\n", fFilename,
width, height); width, height);
goto finish; return;
} }
oldBitmap.eraseColor(SK_ColorWHITE); oldBitmap.eraseColor(SK_ColorWHITE);
SkCanvas oldCanvas(oldBitmap); SkCanvas oldCanvas(oldBitmap);
@ -498,12 +498,12 @@ void TestResult::testOne() {
opBitmap.eraseColor(SK_ColorWHITE); opBitmap.eraseColor(SK_ColorWHITE);
SkCanvas opCanvas(opBitmap); SkCanvas opCanvas(opBitmap);
opCanvas.setAllowSimplifyClip(true); opCanvas.setAllowSimplifyClip(true);
drawPict(pic, &oldCanvas, fScale); drawPict(pic.get(), &oldCanvas, fScale);
drawPict(pic, &opCanvas, fScale); drawPict(pic.get(), &opCanvas, fScale);
if (fTestStep == kCompareBits) { if (fTestStep == kCompareBits) {
fPixelError = similarBits(oldBitmap, opBitmap); fPixelError = similarBits(oldBitmap, opBitmap);
int oldTime = timePict(pic, &oldCanvas); int oldTime = timePict(pic.get(), &oldCanvas);
int opTime = timePict(pic, &opCanvas); int opTime = timePict(pic.get(), &opCanvas);
fTime = SkTMax(0, oldTime - opTime); fTime = SkTMax(0, oldTime - opTime);
} else if (fTestStep == kEncodeFiles) { } else if (fTestStep == kEncodeFiles) {
SkString pngStr = make_png_name(fFilename); SkString pngStr = make_png_name(fFilename);
@ -512,10 +512,6 @@ void TestResult::testOne() {
writePict(opBitmap, outOpDir, pngName); writePict(opBitmap, outOpDir, pngName);
} }
} }
finish:
if (pic) {
pic->unref();
}
} }
DEFINE_string2(match, m, "PathOpsSkpClipThreaded", DEFINE_string2(match, m, "PathOpsSkpClipThreaded",

View File

@ -45,7 +45,7 @@ private:
SkIntToScalar(fPictureHeight), SkIntToScalar(fPictureHeight),
factory); factory);
this->doTest(playbackCanvas, *recordCanvas); this->doTest(playbackCanvas, *recordCanvas);
SkAutoTUnref<SkPicture> picture(recorder.endRecording()); sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
playbackCanvas.drawPicture(picture); playbackCanvas.drawPicture(picture);
REPORTER_ASSERT(reporter, SK_ColorGREEN == fResultBitmap.getColor(0, 0)); REPORTER_ASSERT(reporter, SK_ColorGREEN == fResultBitmap.getColor(0, 0));
} }

View File

@ -31,8 +31,8 @@ DEF_TEST(PictureShader_empty, reporter) {
SkPictureRecorder factory; SkPictureRecorder factory;
factory.beginRecording(0, 0, nullptr, 0); factory.beginRecording(0, 0, nullptr, 0);
sk_sp<SkPicture> picture(factory.endRecording()); paint.setShader(SkShader::MakePictureShader(factory.finishRecordingAsPicture(),
paint.setShader(SkShader::MakePictureShader(std::move(picture), SkShader::kClamp_TileMode, SkShader::kClamp_TileMode,
SkShader::kClamp_TileMode, nullptr, nullptr)); SkShader::kClamp_TileMode, nullptr, nullptr));
canvas.drawRect(SkRect::MakeWH(1,1), paint); canvas.drawRect(SkRect::MakeWH(1,1), paint);

View File

@ -54,7 +54,7 @@ static void test_images_are_found_by_willPlayBackBitmaps(skiatest::Reporter* rep
SkPictureRecorder recorder; SkPictureRecorder recorder;
recorder.beginRecording(100,100)->drawImage(image, 0,0); recorder.beginRecording(100,100)->drawImage(image, 0,0);
SkAutoTUnref<SkPicture> picture(recorder.endRecording()); sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
REPORTER_ASSERT(reporter, picture->willPlayBackBitmaps()); REPORTER_ASSERT(reporter, picture->willPlayBackBitmaps());
} }
@ -67,7 +67,7 @@ static void test_analysis(skiatest::Reporter* reporter) {
{ {
canvas->drawRect(SkRect::MakeWH(10, 10), SkPaint ()); canvas->drawRect(SkRect::MakeWH(10, 10), SkPaint ());
} }
SkAutoTUnref<SkPicture> picture(recorder.endRecording()); sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
REPORTER_ASSERT(reporter, !picture->willPlayBackBitmaps()); REPORTER_ASSERT(reporter, !picture->willPlayBackBitmaps());
canvas = recorder.beginRecording(100, 100); canvas = recorder.beginRecording(100, 100);
@ -85,8 +85,7 @@ static void test_analysis(skiatest::Reporter* reporter) {
canvas->drawRect(SkRect::MakeWH(10, 10), paint); canvas->drawRect(SkRect::MakeWH(10, 10), paint);
} }
picture.reset(recorder.endRecording()); REPORTER_ASSERT(reporter, recorder.finishRecordingAsPicture()->willPlayBackBitmaps());
REPORTER_ASSERT(reporter, picture->willPlayBackBitmaps());
} }
@ -98,7 +97,7 @@ static void test_deleting_empty_picture() {
// Creates an SkPictureRecord // Creates an SkPictureRecord
recorder.beginRecording(0, 0); recorder.beginRecording(0, 0);
// Turns that into an SkPicture // Turns that into an SkPicture
SkAutoTUnref<SkPicture> picture(recorder.endRecording()); sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
// Ceates a new SkPictureRecord // Ceates a new SkPictureRecord
recorder.beginRecording(0, 0); recorder.beginRecording(0, 0);
} }
@ -107,7 +106,7 @@ static void test_deleting_empty_picture() {
static void test_serializing_empty_picture() { static void test_serializing_empty_picture() {
SkPictureRecorder recorder; SkPictureRecorder recorder;
recorder.beginRecording(0, 0); recorder.beginRecording(0, 0);
SkAutoTUnref<SkPicture> picture(recorder.endRecording()); sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
SkDynamicMemoryWStream stream; SkDynamicMemoryWStream stream;
picture->serialize(&stream); picture->serialize(&stream);
} }
@ -155,7 +154,7 @@ static void test_gpu_veto(skiatest::Reporter* reporter) {
canvas->drawPath(path, paint); canvas->drawPath(path, paint);
} }
} }
SkAutoTUnref<SkPicture> picture(recorder.endRecording()); sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
// path effects currently render an SkPicture undesireable for GPU rendering // path effects currently render an SkPicture undesireable for GPU rendering
const char *reason = nullptr; const char *reason = nullptr;
@ -180,7 +179,7 @@ static void test_gpu_veto(skiatest::Reporter* reporter) {
canvas->drawPath(path, paint); canvas->drawPath(path, paint);
} }
} }
picture.reset(recorder.endRecording()); picture = recorder.finishRecordingAsPicture();
// A lot of small AA concave paths should be fine for GPU rendering // A lot of small AA concave paths should be fine for GPU rendering
REPORTER_ASSERT(reporter, picture->suitableForGpuRasterization(nullptr)); REPORTER_ASSERT(reporter, picture->suitableForGpuRasterization(nullptr));
@ -202,7 +201,7 @@ static void test_gpu_veto(skiatest::Reporter* reporter) {
canvas->drawPath(path, paint); canvas->drawPath(path, paint);
} }
} }
picture.reset(recorder.endRecording()); picture = recorder.finishRecordingAsPicture();
// A lot of large AA concave paths currently render an SkPicture undesireable for GPU rendering // A lot of large AA concave paths currently render an SkPicture undesireable for GPU rendering
REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(nullptr)); REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(nullptr));
@ -226,7 +225,7 @@ static void test_gpu_veto(skiatest::Reporter* reporter) {
canvas->drawPath(path, paint); canvas->drawPath(path, paint);
} }
} }
picture.reset(recorder.endRecording()); picture = recorder.finishRecordingAsPicture();
// hairline stroked AA concave paths are fine for GPU rendering // hairline stroked AA concave paths are fine for GPU rendering
REPORTER_ASSERT(reporter, picture->suitableForGpuRasterization(nullptr)); REPORTER_ASSERT(reporter, picture->suitableForGpuRasterization(nullptr));
@ -243,7 +242,7 @@ static void test_gpu_veto(skiatest::Reporter* reporter) {
canvas->drawPoints(SkCanvas::kLines_PointMode, 2, points, paint); canvas->drawPoints(SkCanvas::kLines_PointMode, 2, points, paint);
} }
} }
picture.reset(recorder.endRecording()); picture = recorder.finishRecordingAsPicture();
// fast-path dashed effects are fine for GPU rendering ... // fast-path dashed effects are fine for GPU rendering ...
REPORTER_ASSERT(reporter, picture->suitableForGpuRasterization(nullptr)); REPORTER_ASSERT(reporter, picture->suitableForGpuRasterization(nullptr));
@ -258,7 +257,7 @@ static void test_gpu_veto(skiatest::Reporter* reporter) {
canvas->drawRect(SkRect::MakeWH(10, 10), paint); canvas->drawRect(SkRect::MakeWH(10, 10), paint);
} }
} }
picture.reset(recorder.endRecording()); picture = recorder.finishRecordingAsPicture();
// ... but only when applied to drawPoint() calls // ... but only when applied to drawPoint() calls
REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(nullptr)); REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(nullptr));
@ -267,7 +266,7 @@ static void test_gpu_veto(skiatest::Reporter* reporter) {
{ {
canvas->drawPicture(picture.get()); canvas->drawPicture(picture.get());
} }
picture.reset(recorder.endRecording()); picture = recorder.finishRecordingAsPicture();
REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(nullptr)); REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(nullptr));
} }
@ -287,7 +286,7 @@ static void test_savelayer_extraction(skiatest::Reporter* reporter) {
SkPaint complexPaint; SkPaint complexPaint;
complexPaint.setImageFilter(filter); complexPaint.setImageFilter(filter);
SkAutoTUnref<SkPicture> pict, child; sk_sp<SkPicture> pict, child;
SkRTreeFactory bbhFactory; SkRTreeFactory bbhFactory;
{ {
@ -300,7 +299,7 @@ static void test_savelayer_extraction(skiatest::Reporter* reporter) {
c->saveLayer(nullptr, &complexPaint); c->saveLayer(nullptr, &complexPaint);
c->restore(); c->restore();
child.reset(recorder.endRecording()); child = recorder.finishRecordingAsPicture();
} }
// create a picture with the structure: // create a picture with the structure:
@ -368,7 +367,7 @@ static void test_savelayer_extraction(skiatest::Reporter* reporter) {
c->restore(); c->restore();
} }
pict.reset(recorder.endRecording()); pict = recorder.finishRecordingAsPicture();
} }
// Now test out the SaveLayer extraction // Now test out the SaveLayer extraction
@ -446,7 +445,7 @@ static void test_savelayer_extraction(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, !info4.fIsNested && REPORTER_ASSERT(reporter, !info4.fIsNested &&
info4.fHasNestedLayers); // has a nested SL info4.fHasNestedLayers); // has a nested SL
REPORTER_ASSERT(reporter, child == info5.fPicture); // in a child picture REPORTER_ASSERT(reporter, child.get() == info5.fPicture); // in a child picture
REPORTER_ASSERT(reporter, kWidth == info5.fBounds.width() && REPORTER_ASSERT(reporter, kWidth == info5.fBounds.width() &&
kHeight == info5.fBounds.height()); kHeight == info5.fBounds.height());
REPORTER_ASSERT(reporter, 0 == info5.fBounds.fLeft && 0 == info5.fBounds.fTop); REPORTER_ASSERT(reporter, 0 == info5.fBounds.fLeft && 0 == info5.fBounds.fTop);
@ -465,7 +464,7 @@ static void test_savelayer_extraction(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, !info6.fIsNested && REPORTER_ASSERT(reporter, !info6.fIsNested &&
info6.fHasNestedLayers); // has a nested SL info6.fHasNestedLayers); // has a nested SL
REPORTER_ASSERT(reporter, child == info7.fPicture); // in a child picture REPORTER_ASSERT(reporter, child.get() == info7.fPicture); // in a child picture
REPORTER_ASSERT(reporter, kWidth == info7.fBounds.width() && REPORTER_ASSERT(reporter, kWidth == info7.fBounds.width() &&
kHeight == info7.fBounds.height()); kHeight == info7.fBounds.height());
REPORTER_ASSERT(reporter, 0 == info7.fBounds.fLeft && 0 == info7.fBounds.fTop); REPORTER_ASSERT(reporter, 0 == info7.fBounds.fLeft && 0 == info7.fBounds.fTop);
@ -483,7 +482,7 @@ static void test_has_text(skiatest::Reporter* reporter) {
{ {
canvas->drawRect(SkRect::MakeWH(20, 20), SkPaint()); canvas->drawRect(SkRect::MakeWH(20, 20), SkPaint());
} }
SkAutoTUnref<SkPicture> picture(recorder.endRecording()); sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
REPORTER_ASSERT(reporter, !picture->hasText()); REPORTER_ASSERT(reporter, !picture->hasText());
SkPoint point = SkPoint::Make(10, 10); SkPoint point = SkPoint::Make(10, 10);
@ -491,21 +490,21 @@ static void test_has_text(skiatest::Reporter* reporter) {
{ {
canvas->drawText("Q", 1, point.fX, point.fY, SkPaint()); canvas->drawText("Q", 1, point.fX, point.fY, SkPaint());
} }
picture.reset(recorder.endRecording()); picture = recorder.finishRecordingAsPicture();
REPORTER_ASSERT(reporter, picture->hasText()); REPORTER_ASSERT(reporter, picture->hasText());
canvas = recorder.beginRecording(100,100); canvas = recorder.beginRecording(100,100);
{ {
canvas->drawPosText("Q", 1, &point, SkPaint()); canvas->drawPosText("Q", 1, &point, SkPaint());
} }
picture.reset(recorder.endRecording()); picture = recorder.finishRecordingAsPicture();
REPORTER_ASSERT(reporter, picture->hasText()); REPORTER_ASSERT(reporter, picture->hasText());
canvas = recorder.beginRecording(100,100); canvas = recorder.beginRecording(100,100);
{ {
canvas->drawPosTextH("Q", 1, &point.fX, point.fY, SkPaint()); canvas->drawPosTextH("Q", 1, &point.fX, point.fY, SkPaint());
} }
picture.reset(recorder.endRecording()); picture = recorder.finishRecordingAsPicture();
REPORTER_ASSERT(reporter, picture->hasText()); REPORTER_ASSERT(reporter, picture->hasText());
canvas = recorder.beginRecording(100,100); canvas = recorder.beginRecording(100,100);
@ -516,7 +515,7 @@ static void test_has_text(skiatest::Reporter* reporter) {
canvas->drawTextOnPathHV("Q", 1, path, point.fX, point.fY, SkPaint()); canvas->drawTextOnPathHV("Q", 1, path, point.fX, point.fY, SkPaint());
} }
picture.reset(recorder.endRecording()); picture = recorder.finishRecordingAsPicture();
REPORTER_ASSERT(reporter, picture->hasText()); REPORTER_ASSERT(reporter, picture->hasText());
canvas = recorder.beginRecording(100,100); canvas = recorder.beginRecording(100,100);
@ -527,7 +526,7 @@ static void test_has_text(skiatest::Reporter* reporter) {
canvas->drawTextOnPath("Q", 1, path, nullptr, SkPaint()); canvas->drawTextOnPath("Q", 1, path, nullptr, SkPaint());
} }
picture.reset(recorder.endRecording()); picture = recorder.finishRecordingAsPicture();
REPORTER_ASSERT(reporter, picture->hasText()); REPORTER_ASSERT(reporter, picture->hasText());
// Nest the previous picture inside a new one. // Nest the previous picture inside a new one.
@ -535,7 +534,7 @@ static void test_has_text(skiatest::Reporter* reporter) {
{ {
canvas->drawPicture(picture.get()); canvas->drawPicture(picture.get());
} }
picture.reset(recorder.endRecording()); picture = recorder.finishRecordingAsPicture();
REPORTER_ASSERT(reporter, picture->hasText()); REPORTER_ASSERT(reporter, picture->hasText());
} }
@ -604,14 +603,14 @@ void check_save_state(skiatest::Reporter* reporter, SkPicture* picture,
// the 'partialReplay' method. // the 'partialReplay' method.
class SkPictureRecorderReplayTester { class SkPictureRecorderReplayTester {
public: public:
static SkPicture* Copy(SkPictureRecorder* recorder) { static sk_sp<SkPicture> Copy(SkPictureRecorder* recorder) {
SkPictureRecorder recorder2; SkPictureRecorder recorder2;
SkCanvas* canvas = recorder2.beginRecording(10, 10); SkCanvas* canvas = recorder2.beginRecording(10, 10);
recorder->partialReplay(canvas); recorder->partialReplay(canvas);
return recorder2.endRecording(); return recorder2.finishRecordingAsPicture();
} }
}; };
@ -664,19 +663,19 @@ DEF_TEST(PictureRecorder_replay, reporter) {
canvas->saveLayer(nullptr, nullptr); canvas->saveLayer(nullptr, nullptr);
SkAutoTUnref<SkPicture> copy(SkPictureRecorderReplayTester::Copy(&recorder)); sk_sp<SkPicture> copy(SkPictureRecorderReplayTester::Copy(&recorder));
// The extra save and restore comes from the Copy process. // The extra save and restore comes from the Copy process.
check_save_state(reporter, copy, 2, 1, 3); check_save_state(reporter, copy.get(), 2, 1, 3);
canvas->saveLayer(nullptr, nullptr); canvas->saveLayer(nullptr, nullptr);
SkAutoTUnref<SkPicture> final(recorder.endRecording()); sk_sp<SkPicture> final(recorder.finishRecordingAsPicture());
check_save_state(reporter, final, 1, 2, 3); check_save_state(reporter, final.get(), 1, 2, 3);
// The copy shouldn't pick up any operations added after it was made // The copy shouldn't pick up any operations added after it was made
check_save_state(reporter, copy, 2, 1, 3); check_save_state(reporter, copy.get(), 2, 1, 3);
} }
// (partially) check leakage of draw ops // (partially) check leakage of draw ops
@ -690,7 +689,7 @@ DEF_TEST(PictureRecorder_replay, reporter) {
canvas->drawRect(r, p); canvas->drawRect(r, p);
SkAutoTUnref<SkPicture> copy(SkPictureRecorderReplayTester::Copy(&recorder)); sk_sp<SkPicture> copy(SkPictureRecorderReplayTester::Copy(&recorder));
REPORTER_ASSERT(reporter, !copy->willPlayBackBitmaps()); REPORTER_ASSERT(reporter, !copy->willPlayBackBitmaps());
@ -700,7 +699,7 @@ DEF_TEST(PictureRecorder_replay, reporter) {
r.offset(5.0f, 5.0f); r.offset(5.0f, 5.0f);
canvas->drawBitmapRect(bm, r, nullptr); canvas->drawBitmapRect(bm, r, nullptr);
SkAutoTUnref<SkPicture> final(recorder.endRecording()); sk_sp<SkPicture> final(recorder.finishRecordingAsPicture());
REPORTER_ASSERT(reporter, final->willPlayBackBitmaps()); REPORTER_ASSERT(reporter, final->willPlayBackBitmaps());
REPORTER_ASSERT(reporter, copy->uniqueID() != final->uniqueID()); REPORTER_ASSERT(reporter, copy->uniqueID() != final->uniqueID());
@ -718,14 +717,14 @@ DEF_TEST(PictureRecorder_replay, reporter) {
int expectedSaveCount = canvas->getSaveCount(); int expectedSaveCount = canvas->getSaveCount();
SkAutoTUnref<SkPicture> copy(SkPictureRecorderReplayTester::Copy(&recorder)); sk_sp<SkPicture> copy(SkPictureRecorderReplayTester::Copy(&recorder));
check_balance(reporter, copy); check_balance(reporter, copy.get());
REPORTER_ASSERT(reporter, expectedSaveCount = canvas->getSaveCount()); REPORTER_ASSERT(reporter, expectedSaveCount = canvas->getSaveCount());
// End the recording of source to test the picture finalization // End the recording of source to test the picture finalization
// process isn't complicated by the partialReplay step // process isn't complicated by the partialReplay step
SkAutoTUnref<SkPicture> final(recorder.endRecording()); sk_sp<SkPicture> final(recorder.finishRecordingAsPicture());
} }
} }
@ -749,7 +748,7 @@ static void test_unbalanced_save_restores(skiatest::Reporter* reporter) {
canvas->save(); canvas->save();
canvas->translate(10, 10); canvas->translate(10, 10);
canvas->drawRect(rect, paint); canvas->drawRect(rect, paint);
SkAutoTUnref<SkPicture> extraSavePicture(recorder.endRecording()); sk_sp<SkPicture> extraSavePicture(recorder.finishRecordingAsPicture());
testCanvas.drawPicture(extraSavePicture); testCanvas.drawPicture(extraSavePicture);
REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount());
@ -770,7 +769,7 @@ static void test_unbalanced_save_restores(skiatest::Reporter* reporter) {
canvas->restore(); canvas->restore();
canvas->restore(); canvas->restore();
canvas->restore(); canvas->restore();
SkAutoTUnref<SkPicture> extraRestorePicture(recorder.endRecording()); sk_sp<SkPicture> extraRestorePicture(recorder.finishRecordingAsPicture());
testCanvas.drawPicture(extraRestorePicture); testCanvas.drawPicture(extraRestorePicture);
REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount());
@ -782,7 +781,7 @@ static void test_unbalanced_save_restores(skiatest::Reporter* reporter) {
SkCanvas* canvas = recorder.beginRecording(100, 100); SkCanvas* canvas = recorder.beginRecording(100, 100);
canvas->translate(10, 10); canvas->translate(10, 10);
canvas->drawRect(rect, paint); canvas->drawRect(rect, paint);
SkAutoTUnref<SkPicture> noSavePicture(recorder.endRecording()); sk_sp<SkPicture> noSavePicture(recorder.finishRecordingAsPicture());
testCanvas.drawPicture(noSavePicture); testCanvas.drawPicture(noSavePicture);
REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount());
@ -803,7 +802,7 @@ static void test_peephole() {
for (int i = 0; i < 1000; ++i) { for (int i = 0; i < 1000; ++i) {
rand_op(canvas, rand); rand_op(canvas, rand);
} }
SkAutoTUnref<SkPicture> picture(recorder.endRecording()); sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
rand = rand2; rand = rand2;
} }
@ -819,7 +818,7 @@ static void test_peephole() {
canvas->clipRect(rect); canvas->clipRect(rect);
canvas->restore(); canvas->restore();
} }
SkAutoTUnref<SkPicture> picture(recorder.endRecording()); sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
} }
} }
@ -834,7 +833,7 @@ static void test_bad_bitmap() {
SkPictureRecorder recorder; SkPictureRecorder recorder;
SkCanvas* recordingCanvas = recorder.beginRecording(100, 100); SkCanvas* recordingCanvas = recorder.beginRecording(100, 100);
recordingCanvas->drawBitmap(bm, 0, 0); recordingCanvas->drawBitmap(bm, 0, 0);
SkAutoTUnref<SkPicture> picture(recorder.endRecording()); sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
SkCanvas canvas; SkCanvas canvas;
canvas.drawPicture(picture); canvas.drawPicture(picture);
@ -846,7 +845,7 @@ static SkData* serialized_picture_from_bitmap(const SkBitmap& bitmap) {
SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(bitmap.width()), SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(bitmap.width()),
SkIntToScalar(bitmap.height())); SkIntToScalar(bitmap.height()));
canvas->drawBitmap(bitmap, 0, 0); canvas->drawBitmap(bitmap, 0, 0);
SkAutoTUnref<SkPicture> picture(recorder.endRecording()); sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
SkDynamicMemoryWStream wStream; SkDynamicMemoryWStream wStream;
SkAutoTUnref<SkPixelSerializer> serializer( SkAutoTUnref<SkPixelSerializer> serializer(
@ -911,7 +910,7 @@ DEF_TEST(Picture_EncodedData, reporter) {
SkSetErrorCallback(assert_one_parse_error_cb, &context); SkSetErrorCallback(assert_one_parse_error_cb, &context);
SkMemoryStream pictureStream(picture1); SkMemoryStream pictureStream(picture1);
SkClearLastError(); SkClearLastError();
SkAutoTUnref<SkPicture> pictureFromStream(SkPicture::CreateFromStream(&pictureStream, nullptr)); sk_sp<SkPicture> pictureFromStream(SkPicture::MakeFromStream(&pictureStream, nullptr));
REPORTER_ASSERT(reporter, pictureFromStream.get() != nullptr); REPORTER_ASSERT(reporter, pictureFromStream.get() != nullptr);
SkClearLastError(); SkClearLastError();
SkSetErrorCallback(nullptr, nullptr); SkSetErrorCallback(nullptr, nullptr);
@ -927,7 +926,7 @@ DEF_TEST(Picture_EncodedData, reporter) {
SkCanvas canvas(dst); SkCanvas canvas(dst);
pictureStream.rewind(); pictureStream.rewind();
pictureFromStream.reset(SkPicture::CreateFromStream(&pictureStream)); pictureFromStream = SkPicture::MakeFromStream(&pictureStream);
canvas.drawPicture(pictureFromStream.get()); canvas.drawPicture(pictureFromStream.get());
SkMD5::Digest digest2; SkMD5::Digest digest2;
@ -1032,7 +1031,7 @@ static void test_cull_rect_reset(skiatest::Reporter* reporter) {
SkPaint paint; SkPaint paint;
canvas->drawRect(bounds, paint); canvas->drawRect(bounds, paint);
canvas->drawRect(bounds, paint); canvas->drawRect(bounds, paint);
SkAutoTUnref<const SkPicture> p(recorder.endRecordingAsPicture(bounds)); sk_sp<SkPicture> p(recorder.finishRecordingAsPictureWithCull(bounds));
const SkBigPicture* picture = p->asSkBigPicture(); const SkBigPicture* picture = p->asSkBigPicture();
REPORTER_ASSERT(reporter, picture); REPORTER_ASSERT(reporter, picture);
@ -1106,7 +1105,7 @@ static void test_clip_expansion(skiatest::Reporter* reporter) {
SkPaint p; SkPaint p;
p.setColor(SK_ColorBLUE); p.setColor(SK_ColorBLUE);
canvas->drawPaint(p); canvas->drawPaint(p);
SkAutoTUnref<SkPicture> picture(recorder.endRecording()); sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
ClipCountingCanvas testCanvas(10, 10); ClipCountingCanvas testCanvas(10, 10);
picture->playback(&testCanvas); picture->playback(&testCanvas);
@ -1122,37 +1121,37 @@ static void test_hierarchical(skiatest::Reporter* reporter) {
SkPictureRecorder recorder; SkPictureRecorder recorder;
recorder.beginRecording(10, 10); recorder.beginRecording(10, 10);
SkAutoTUnref<SkPicture> childPlain(recorder.endRecording()); sk_sp<SkPicture> childPlain(recorder.finishRecordingAsPicture());
REPORTER_ASSERT(reporter, !childPlain->willPlayBackBitmaps()); // 0 REPORTER_ASSERT(reporter, !childPlain->willPlayBackBitmaps()); // 0
recorder.beginRecording(10, 10)->drawBitmap(bm, 0, 0); recorder.beginRecording(10, 10)->drawBitmap(bm, 0, 0);
SkAutoTUnref<SkPicture> childWithBitmap(recorder.endRecording()); sk_sp<SkPicture> childWithBitmap(recorder.finishRecordingAsPicture());
REPORTER_ASSERT(reporter, childWithBitmap->willPlayBackBitmaps()); // 1 REPORTER_ASSERT(reporter, childWithBitmap->willPlayBackBitmaps()); // 1
{ {
SkCanvas* canvas = recorder.beginRecording(10, 10); SkCanvas* canvas = recorder.beginRecording(10, 10);
canvas->drawPicture(childPlain); canvas->drawPicture(childPlain);
SkAutoTUnref<SkPicture> parentPP(recorder.endRecording()); sk_sp<SkPicture> parentPP(recorder.finishRecordingAsPicture());
REPORTER_ASSERT(reporter, !parentPP->willPlayBackBitmaps()); // 0 REPORTER_ASSERT(reporter, !parentPP->willPlayBackBitmaps()); // 0
} }
{ {
SkCanvas* canvas = recorder.beginRecording(10, 10); SkCanvas* canvas = recorder.beginRecording(10, 10);
canvas->drawPicture(childWithBitmap); canvas->drawPicture(childWithBitmap);
SkAutoTUnref<SkPicture> parentPWB(recorder.endRecording()); sk_sp<SkPicture> parentPWB(recorder.finishRecordingAsPicture());
REPORTER_ASSERT(reporter, parentPWB->willPlayBackBitmaps()); // 1 REPORTER_ASSERT(reporter, parentPWB->willPlayBackBitmaps()); // 1
} }
{ {
SkCanvas* canvas = recorder.beginRecording(10, 10); SkCanvas* canvas = recorder.beginRecording(10, 10);
canvas->drawBitmap(bm, 0, 0); canvas->drawBitmap(bm, 0, 0);
canvas->drawPicture(childPlain); canvas->drawPicture(childPlain);
SkAutoTUnref<SkPicture> parentWBP(recorder.endRecording()); sk_sp<SkPicture> parentWBP(recorder.finishRecordingAsPicture());
REPORTER_ASSERT(reporter, parentWBP->willPlayBackBitmaps()); // 1 REPORTER_ASSERT(reporter, parentWBP->willPlayBackBitmaps()); // 1
} }
{ {
SkCanvas* canvas = recorder.beginRecording(10, 10); SkCanvas* canvas = recorder.beginRecording(10, 10);
canvas->drawBitmap(bm, 0, 0); canvas->drawBitmap(bm, 0, 0);
canvas->drawPicture(childWithBitmap); canvas->drawPicture(childWithBitmap);
SkAutoTUnref<SkPicture> parentWBWB(recorder.endRecording()); sk_sp<SkPicture> parentWBWB(recorder.finishRecordingAsPicture());
REPORTER_ASSERT(reporter, parentWBWB->willPlayBackBitmaps()); // 2 REPORTER_ASSERT(reporter, parentWBWB->willPlayBackBitmaps()); // 2
} }
} }
@ -1161,14 +1160,14 @@ static void test_gen_id(skiatest::Reporter* reporter) {
SkPictureRecorder recorder; SkPictureRecorder recorder;
recorder.beginRecording(0, 0); recorder.beginRecording(0, 0);
SkAutoTUnref<SkPicture> empty(recorder.endRecording()); sk_sp<SkPicture> empty(recorder.finishRecordingAsPicture());
// Empty pictures should still have a valid ID // Empty pictures should still have a valid ID
REPORTER_ASSERT(reporter, empty->uniqueID() != SK_InvalidGenID); REPORTER_ASSERT(reporter, empty->uniqueID() != SK_InvalidGenID);
SkCanvas* canvas = recorder.beginRecording(1, 1); SkCanvas* canvas = recorder.beginRecording(1, 1);
canvas->drawARGB(255, 255, 255, 255); canvas->drawARGB(255, 255, 255, 255);
SkAutoTUnref<SkPicture> hasData(recorder.endRecording()); sk_sp<SkPicture> hasData(recorder.finishRecordingAsPicture());
// picture should have a non-zero id after recording // picture should have a non-zero id after recording
REPORTER_ASSERT(reporter, hasData->uniqueID() != SK_InvalidGenID); REPORTER_ASSERT(reporter, hasData->uniqueID() != SK_InvalidGenID);
@ -1182,7 +1181,7 @@ static void test_typeface(skiatest::Reporter* reporter) {
SkPaint paint; SkPaint paint;
paint.setTypeface(SkTypeface::CreateFromName("Arial", SkTypeface::kItalic)); paint.setTypeface(SkTypeface::CreateFromName("Arial", SkTypeface::kItalic));
canvas->drawText("Q", 1, 0, 10, paint); canvas->drawText("Q", 1, 0, 10, paint);
SkAutoTUnref<SkPicture> picture(recorder.endRecording()); sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
REPORTER_ASSERT(reporter, picture->hasText()); REPORTER_ASSERT(reporter, picture->hasText());
SkDynamicMemoryWStream stream; SkDynamicMemoryWStream stream;
picture->serialize(&stream); picture->serialize(&stream);
@ -1234,7 +1233,7 @@ static void test_draw_bitmaps(SkCanvas* canvas) {
DEF_TEST(Picture_EmptyBitmap, r) { DEF_TEST(Picture_EmptyBitmap, r) {
SkPictureRecorder recorder; SkPictureRecorder recorder;
test_draw_bitmaps(recorder.beginRecording(10, 10)); test_draw_bitmaps(recorder.beginRecording(10, 10));
SkAutoTUnref<SkPicture> picture(recorder.endRecording()); sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
} }
DEF_TEST(Canvas_EmptyBitmap, r) { DEF_TEST(Canvas_EmptyBitmap, r) {
@ -1277,7 +1276,7 @@ DEF_TEST(DontOptimizeSaveLayerDrawDrawRestore, reporter) {
canvas->drawBitmap(redBM, 50, 50); canvas->drawBitmap(redBM, 50, 50);
canvas->restore(); canvas->restore();
SkAutoTUnref<SkPicture> picture(recorder.endRecording()); sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
// Now replay the picture back on another canvas // Now replay the picture back on another canvas
// and check a couple of its pixels. // and check a couple of its pixels.
@ -1329,7 +1328,7 @@ DEF_TEST(Picture_SkipBBH, r) {
// Record a few ops so we don't hit a small- or empty- picture optimization. // Record a few ops so we don't hit a small- or empty- picture optimization.
c->drawRect(bound, SkPaint()); c->drawRect(bound, SkPaint());
c->drawRect(bound, SkPaint()); c->drawRect(bound, SkPaint());
SkAutoTUnref<const SkPicture> picture(recorder.endRecording()); sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
SkCanvas big(640, 480), small(300, 200); SkCanvas big(640, 480), small(300, 200);
@ -1352,7 +1351,7 @@ DEF_TEST(Picture_BitmapLeak, r) {
REPORTER_ASSERT(r, mut.pixelRef()->unique()); REPORTER_ASSERT(r, mut.pixelRef()->unique());
REPORTER_ASSERT(r, immut.pixelRef()->unique()); REPORTER_ASSERT(r, immut.pixelRef()->unique());
SkAutoTUnref<const SkPicture> pic; sk_sp<SkPicture> pic;
{ {
// we want the recorder to go out of scope before our subsequent checks, so we // we want the recorder to go out of scope before our subsequent checks, so we
// place it inside local braces. // place it inside local braces.
@ -1360,7 +1359,7 @@ DEF_TEST(Picture_BitmapLeak, r) {
SkCanvas* canvas = rec.beginRecording(1920, 1200); SkCanvas* canvas = rec.beginRecording(1920, 1200);
canvas->drawBitmap(mut, 0, 0); canvas->drawBitmap(mut, 0, 0);
canvas->drawBitmap(immut, 800, 600); canvas->drawBitmap(immut, 800, 600);
pic.reset(rec.endRecording()); pic = rec.finishRecordingAsPicture();
} }
// The picture shares the immutable pixels but copies the mutable ones. // The picture shares the immutable pixels but copies the mutable ones.
@ -1368,7 +1367,7 @@ DEF_TEST(Picture_BitmapLeak, r) {
REPORTER_ASSERT(r, !immut.pixelRef()->unique()); REPORTER_ASSERT(r, !immut.pixelRef()->unique());
// When the picture goes away, it's just our bitmaps holding the refs. // When the picture goes away, it's just our bitmaps holding the refs.
pic.reset(nullptr); pic = nullptr;
REPORTER_ASSERT(r, mut.pixelRef()->unique()); REPORTER_ASSERT(r, mut.pixelRef()->unique());
REPORTER_ASSERT(r, immut.pixelRef()->unique()); REPORTER_ASSERT(r, immut.pixelRef()->unique());
} }
@ -1380,7 +1379,7 @@ DEF_TEST(Picture_getRecordingCanvas, r) {
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
rec.beginRecording(100, 100); rec.beginRecording(100, 100);
REPORTER_ASSERT(r, rec.getRecordingCanvas()); REPORTER_ASSERT(r, rec.getRecordingCanvas());
rec.endRecording()->unref(); rec.finishRecordingAsPicture();
REPORTER_ASSERT(r, !rec.getRecordingCanvas()); REPORTER_ASSERT(r, !rec.getRecordingCanvas());
} }
} }
@ -1401,12 +1400,12 @@ DEF_TEST(Picture_preserveCullRect, r) {
SkCanvas* c = recorder.beginRecording(SkRect::MakeLTRB(1, 2, 3, 4)); SkCanvas* c = recorder.beginRecording(SkRect::MakeLTRB(1, 2, 3, 4));
c->clear(SK_ColorCYAN); c->clear(SK_ColorCYAN);
SkAutoTUnref<SkPicture> picture(recorder.endRecording()); sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
SkDynamicMemoryWStream wstream; SkDynamicMemoryWStream wstream;
picture->serialize(&wstream); picture->serialize(&wstream);
SkAutoTDelete<SkStream> rstream(wstream.detachAsStream()); SkAutoTDelete<SkStream> rstream(wstream.detachAsStream());
SkAutoTUnref<SkPicture> deserializedPicture(SkPicture::CreateFromStream(rstream)); sk_sp<SkPicture> deserializedPicture(SkPicture::MakeFromStream(rstream));
REPORTER_ASSERT(r, deserializedPicture != nullptr); REPORTER_ASSERT(r, deserializedPicture != nullptr);
REPORTER_ASSERT(r, deserializedPicture->cullRect().left() == 1); REPORTER_ASSERT(r, deserializedPicture->cullRect().left() == 1);

View File

@ -230,16 +230,16 @@ DEF_TEST(RecordOpts_MergeSvgOpacityAndFilterLayers, r) {
opaqueFilterLayerPaint.setColor(0xFF020202); // Opaque. opaqueFilterLayerPaint.setColor(0xFF020202); // Opaque.
SkPaint translucentFilterLayerPaint; SkPaint translucentFilterLayerPaint;
translucentFilterLayerPaint.setColor(0x0F020202); // Not opaque. translucentFilterLayerPaint.setColor(0x0F020202); // Not opaque.
SkAutoTUnref<SkPicture> shape; sk_sp<SkPicture> shape;
{ {
SkPictureRecorder recorder; SkPictureRecorder recorder;
SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(100), SkIntToScalar(100)); SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(100), SkIntToScalar(100));
SkPaint shapePaint; SkPaint shapePaint;
shapePaint.setColor(SK_ColorWHITE); shapePaint.setColor(SK_ColorWHITE);
canvas->drawRect(SkRect::MakeWH(SkIntToScalar(50), SkIntToScalar(50)), shapePaint); canvas->drawRect(SkRect::MakeWH(SkIntToScalar(50), SkIntToScalar(50)), shapePaint);
shape.reset(recorder.endRecordingAsPicture()); shape = recorder.finishRecordingAsPicture();
} }
translucentFilterLayerPaint.setImageFilter(SkPictureImageFilter::Create(shape))->unref(); translucentFilterLayerPaint.setImageFilter(SkPictureImageFilter::Create(shape.get()))->unref();
int index = 0; int index = 0;

View File

@ -33,7 +33,7 @@ private:
// Make sure the abort callback works // Make sure the abort callback works
DEF_TEST(RecordReplaceDraw_Abort, r) { DEF_TEST(RecordReplaceDraw_Abort, r) {
SkAutoTUnref<const SkPicture> pic; sk_sp<SkPicture> pic;
{ {
// Record two commands. // Record two commands.
@ -43,14 +43,14 @@ DEF_TEST(RecordReplaceDraw_Abort, r) {
canvas->drawRect(SkRect::MakeWH(SkIntToScalar(kWidth), SkIntToScalar(kHeight)), SkPaint()); canvas->drawRect(SkRect::MakeWH(SkIntToScalar(kWidth), SkIntToScalar(kHeight)), SkPaint());
canvas->clipRect(SkRect::MakeWH(SkIntToScalar(kWidth), SkIntToScalar(kHeight))); canvas->clipRect(SkRect::MakeWH(SkIntToScalar(kWidth), SkIntToScalar(kHeight)));
pic.reset(recorder.endRecording()); pic = recorder.finishRecordingAsPicture();
} }
SkRecord rerecord; SkRecord rerecord;
SkRecorder canvas(&rerecord, kWidth, kHeight); SkRecorder canvas(&rerecord, kWidth, kHeight);
JustOneDraw callback; JustOneDraw callback;
GrRecordReplaceDraw(pic, &canvas, nullptr, SkMatrix::I(), &callback); GrRecordReplaceDraw(pic.get(), &canvas, nullptr, SkMatrix::I(), &callback);
switch (rerecord.count()) { switch (rerecord.count()) {
case 3: case 3:
@ -68,7 +68,7 @@ DEF_TEST(RecordReplaceDraw_Abort, r) {
// Make sure GrRecordReplaceDraw balances unbalanced saves // Make sure GrRecordReplaceDraw balances unbalanced saves
DEF_TEST(RecordReplaceDraw_Unbalanced, r) { DEF_TEST(RecordReplaceDraw_Unbalanced, r) {
SkAutoTUnref<const SkPicture> pic; sk_sp<SkPicture> pic;
{ {
SkPictureRecorder recorder; SkPictureRecorder recorder;
@ -77,13 +77,13 @@ DEF_TEST(RecordReplaceDraw_Unbalanced, r) {
// We won't balance this, but GrRecordReplaceDraw will for us. // We won't balance this, but GrRecordReplaceDraw will for us.
canvas->save(); canvas->save();
canvas->scale(2, 2); canvas->scale(2, 2);
pic.reset(recorder.endRecording()); pic = recorder.finishRecordingAsPicture();
} }
SkRecord rerecord; SkRecord rerecord;
SkRecorder canvas(&rerecord, kWidth, kHeight); SkRecorder canvas(&rerecord, kWidth, kHeight);
GrRecordReplaceDraw(pic, &canvas, nullptr, SkMatrix::I(), nullptr/*callback*/); GrRecordReplaceDraw(pic.get(), &canvas, nullptr, SkMatrix::I(), nullptr/*callback*/);
// ensure rerecord is balanced (in this case by checking that the count is odd) // ensure rerecord is balanced (in this case by checking that the count is odd)
REPORTER_ASSERT(r, (rerecord.count() & 1) == 1); REPORTER_ASSERT(r, (rerecord.count() & 1) == 1);
@ -91,7 +91,7 @@ DEF_TEST(RecordReplaceDraw_Unbalanced, r) {
// Test out the layer replacement functionality with and w/o a BBH // Test out the layer replacement functionality with and w/o a BBH
void test_replacements(skiatest::Reporter* r, GrContext* context, bool doReplace) { void test_replacements(skiatest::Reporter* r, GrContext* context, bool doReplace) {
SkAutoTUnref<const SkPicture> pic; sk_sp<SkPicture> pic;
{ {
SkPictureRecorder recorder; SkPictureRecorder recorder;
@ -102,7 +102,7 @@ void test_replacements(skiatest::Reporter* r, GrContext* context, bool doReplace
canvas->restore(); canvas->restore();
canvas->drawRect(SkRect::MakeWH(SkIntToScalar(kWidth / 2), SkIntToScalar(kHeight / 2)), canvas->drawRect(SkRect::MakeWH(SkIntToScalar(kWidth / 2), SkIntToScalar(kHeight / 2)),
SkPaint()); SkPaint());
pic.reset(recorder.endRecording()); pic = recorder.finishRecordingAsPicture();
} }
SkAutoTUnref<GrTexture> texture; SkAutoTUnref<GrTexture> texture;
@ -131,7 +131,7 @@ void test_replacements(skiatest::Reporter* r, GrContext* context, bool doReplace
SkRecord rerecord; SkRecord rerecord;
SkRecorder canvas(&rerecord, kWidth, kHeight); SkRecorder canvas(&rerecord, kWidth, kHeight);
GrRecordReplaceDraw(pic, &canvas, layerCache, SkMatrix::I(), nullptr/*callback*/); GrRecordReplaceDraw(pic.get(), &canvas, layerCache, SkMatrix::I(), nullptr/*callback*/);
int numLayers = count_instances_of_type<SkRecords::SaveLayer>(rerecord); int numLayers = count_instances_of_type<SkRecords::SaveLayer>(rerecord);
if (doReplace) { if (doReplace) {

View File

@ -114,7 +114,7 @@ class PictureStrategy : public RecordingStrategy {
SkIntToScalar(fHeight), SkIntToScalar(fHeight),
&factory); &factory);
drawer.draw(canvas, canvasRect, mode); drawer.draw(canvas, canvasRect, mode);
SkAutoTUnref<SkPicture> picture(recorder.endRecording()); sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
SkCanvas replayCanvas(fBitmap); SkCanvas replayCanvas(fBitmap);
replayCanvas.clear(0xffffffff); replayCanvas.clear(0xffffffff);

View File

@ -338,13 +338,13 @@ static void serialize_and_compare_typeface(SkTypeface* typeface, const char* tex
nullptr, 0); nullptr, 0);
canvas->drawColor(SK_ColorWHITE); canvas->drawColor(SK_ColorWHITE);
canvas->drawText(text, 2, 24, 32, paint); canvas->drawText(text, 2, 24, 32, paint);
SkAutoTUnref<SkPicture> picture(recorder.endRecording()); sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
// Serlialize picture and create its clone from stream. // Serlialize picture and create its clone from stream.
SkDynamicMemoryWStream stream; SkDynamicMemoryWStream stream;
picture->serialize(&stream); picture->serialize(&stream);
SkAutoTDelete<SkStream> inputStream(stream.detachAsStream()); SkAutoTDelete<SkStream> inputStream(stream.detachAsStream());
SkAutoTUnref<SkPicture> loadedPicture(SkPicture::CreateFromStream(inputStream.get())); sk_sp<SkPicture> loadedPicture(SkPicture::MakeFromStream(inputStream.get()));
// Draw both original and clone picture and compare bitmaps -- they should be identical. // Draw both original and clone picture and compare bitmaps -- they should be identical.
SkBitmap origBitmap = draw_picture(*picture); SkBitmap origBitmap = draw_picture(*picture);
@ -529,7 +529,7 @@ DEF_TEST(Serialization, reporter) {
draw_something(recorder.beginRecording(SkIntToScalar(kBitmapSize), draw_something(recorder.beginRecording(SkIntToScalar(kBitmapSize),
SkIntToScalar(kBitmapSize), SkIntToScalar(kBitmapSize),
nullptr, 0)); nullptr, 0));
SkAutoTUnref<SkPicture> pict(recorder.endRecording()); sk_sp<SkPicture> pict(recorder.finishRecordingAsPicture());
// Serialize picture // Serialize picture
SkWriteBuffer writer(SkWriteBuffer::kValidation_Flag); SkWriteBuffer writer(SkWriteBuffer::kValidation_Flag);
@ -540,8 +540,7 @@ DEF_TEST(Serialization, reporter) {
// Deserialize picture // Deserialize picture
SkValidatingReadBuffer reader(static_cast<void*>(data.get()), size); SkValidatingReadBuffer reader(static_cast<void*>(data.get()), size);
SkAutoTUnref<SkPicture> readPict( sk_sp<SkPicture> readPict(SkPicture::MakeFromBuffer(reader));
SkPicture::CreateFromBuffer(reader));
REPORTER_ASSERT(reporter, readPict.get()); REPORTER_ASSERT(reporter, readPict.get());
} }
@ -551,11 +550,11 @@ DEF_TEST(Serialization, reporter) {
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
#include "SkAnnotation.h" #include "SkAnnotation.h"
static SkPicture* copy_picture_via_serialization(SkPicture* src) { static sk_sp<SkPicture> copy_picture_via_serialization(SkPicture* src) {
SkDynamicMemoryWStream wstream; SkDynamicMemoryWStream wstream;
src->serialize(&wstream); src->serialize(&wstream);
SkAutoTDelete<SkStreamAsset> rstream(wstream.detachAsStream()); SkAutoTDelete<SkStreamAsset> rstream(wstream.detachAsStream());
return SkPicture::CreateFromStream(rstream); return SkPicture::MakeFromStream(rstream);
} }
struct AnnotationRec { struct AnnotationRec {
@ -622,8 +621,8 @@ DEF_TEST(Annotations, reporter) {
{ r2, SkAnnotationKeys::Link_Named_Dest_Key(), d2 }, { r2, SkAnnotationKeys::Link_Named_Dest_Key(), d2 },
}; };
SkAutoTUnref<SkPicture> pict0(recorder.endRecording()); sk_sp<SkPicture> pict0(recorder.finishRecordingAsPicture());
SkAutoTUnref<SkPicture> pict1(copy_picture_via_serialization(pict0)); sk_sp<SkPicture> pict1(copy_picture_via_serialization(pict0.get()));
TestAnnotationCanvas canvas(reporter, recs, SK_ARRAY_COUNT(recs)); TestAnnotationCanvas canvas(reporter, recs, SK_ARRAY_COUNT(recs));
canvas.drawPicture(pict1); canvas.drawPicture(pict1);

View File

@ -322,8 +322,8 @@ DEF_TEST(BitmapCache_discarded_image, reporter) {
SkPictureRecorder recorder; SkPictureRecorder recorder;
SkCanvas* canvas = recorder.beginRecording(10, 10); SkCanvas* canvas = recorder.beginRecording(10, 10);
canvas->clear(SK_ColorCYAN); canvas->clear(SK_ColorCYAN);
sk_sp<SkPicture> picture(recorder.endRecording()); return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(),
return SkImage::MakeFromPicture(picture, SkISize::Make(10, 10), nullptr, nullptr); SkISize::Make(10, 10), nullptr, nullptr);
}); });
} }
} }

View File

@ -378,7 +378,7 @@ static void writePict(const SkBitmap& bitmap, const char* outDir, const char* pn
} }
void TestResult::testOne() { void TestResult::testOne() {
SkPicture* pic = nullptr; sk_sp<SkPicture> pic;
{ {
SkString d; SkString d;
d.printf(" {%d, \"%s\"},", fDirNo, fFilename); d.printf(" {%d, \"%s\"},", fDirNo, fFilename);
@ -399,7 +399,7 @@ void TestResult::testOne() {
wStream.write(&bytes[0], length); wStream.write(&bytes[0], length);
wStream.flush(); wStream.flush();
} }
pic = SkPicture::CreateFromStream(&stream); pic = SkPicture::MakeFromStream(&stream);
if (!pic) { if (!pic) {
SkDebugf("unable to decode %s\n", fFilename); SkDebugf("unable to decode %s\n", fFilename);
goto finish; goto finish;
@ -436,7 +436,7 @@ void TestResult::testOne() {
if (scale >= 256) { if (scale >= 256) {
SkDebugf("unable to allocate bitmap for %s (w=%d h=%d) (sw=%d sh=%d)\n", SkDebugf("unable to allocate bitmap for %s (w=%d h=%d) (sw=%d sh=%d)\n",
fFilename, pWidth, pHeight, dim.fX, dim.fY); fFilename, pWidth, pHeight, dim.fX, dim.fY);
goto finish; return;
} }
SkCanvas skCanvas(bitmap); SkCanvas skCanvas(bitmap);
drawPict(pic, &skCanvas, fScaleOversized ? scale : 1); drawPict(pic, &skCanvas, fScaleOversized ? scale : 1);
@ -450,11 +450,11 @@ void TestResult::testOne() {
if (!texture) { if (!texture) {
SkDebugf("unable to allocate texture for %s (w=%d h=%d)\n", fFilename, SkDebugf("unable to allocate texture for %s (w=%d h=%d)\n", fFilename,
dim.fX, dim.fY); dim.fX, dim.fY);
goto finish; return;
} }
SkGpuDevice grDevice(context, texture.get()); SkGpuDevice grDevice(context, texture.get());
SkCanvas grCanvas(&grDevice); SkCanvas grCanvas(&grDevice);
drawPict(pic, &grCanvas, fScaleOversized ? scale : 1); drawPict(pic.get(), &grCanvas, fScaleOversized ? scale : 1);
SkBitmap grBitmap; SkBitmap grBitmap;
grBitmap.allocPixels(grCanvas.imageInfo()); grBitmap.allocPixels(grCanvas.imageInfo());
@ -472,8 +472,6 @@ void TestResult::testOne() {
writePict(bitmap, outSkDir, pngName); writePict(bitmap, outSkDir, pngName);
} }
} }
finish:
delete pic;
} }
static SkString makeStatusString(int dirNo) { static SkString makeStatusString(int dirNo) {

View File

@ -104,25 +104,24 @@ VisualBenchmarkStream::VisualBenchmarkStream(const SkSurfaceProps& surfaceProps,
this->next(); this->next();
} }
bool VisualBenchmarkStream::ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic) { sk_sp<SkPicture> VisualBenchmarkStream::ReadPicture(const char path[]) {
// Not strictly necessary, as it will be checked again later, // Not strictly necessary, as it will be checked again later,
// but helps to avoid a lot of pointless work if we're going to skip it. // but helps to avoid a lot of pointless work if we're going to skip it.
if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) { if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) {
return false; return nullptr;
} }
SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path)); SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path));
if (stream.get() == nullptr) { if (stream.get() == nullptr) {
SkDebugf("Could not read %s.\n", path); SkDebugf("Could not read %s.\n", path);
return false; return nullptr;
} }
pic->reset(SkPicture::CreateFromStream(stream.get())); auto pic = SkPicture::MakeFromStream(stream.get());
if (pic->get() == nullptr) { if (!pic) {
SkDebugf("Could not read %s as an SkPicture.\n", path); SkDebugf("Could not read %s as an SkPicture.\n", path);
return false;
} }
return true; return pic;
} }
Benchmark* VisualBenchmarkStream::next() { Benchmark* VisualBenchmarkStream::next() {
@ -175,8 +174,8 @@ Benchmark* VisualBenchmarkStream::innerNext() {
// Render skps // Render skps
while (fCurrentSKP < fSKPs.count()) { while (fCurrentSKP < fSKPs.count()) {
const SkString& path = fSKPs[fCurrentSKP++]; const SkString& path = fSKPs[fCurrentSKP++];
SkAutoTUnref<SkPicture> pic; sk_sp<SkPicture> pic = ReadPicture(path.c_str());
if (!ReadPicture(path.c_str(), &pic)) { if (!pic) {
continue; continue;
} }

View File

@ -20,7 +20,7 @@ class VisualBenchmarkStream {
public: public:
VisualBenchmarkStream(const SkSurfaceProps&, bool justSKP = false); VisualBenchmarkStream(const SkSurfaceProps&, bool justSKP = false);
static bool ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic); static sk_sp<SkPicture> ReadPicture(const char* path);
Benchmark* next(); Benchmark* next();
Benchmark* current() { return fBenchmark.get(); } Benchmark* current() { return fBenchmark.get(); }

View File

@ -49,7 +49,7 @@ int tool_main(int argc, char** argv) {
SkDebugf("Could not read %s.\n", FLAGS_skps[i]); SkDebugf("Could not read %s.\n", FLAGS_skps[i]);
return 1; return 1;
} }
SkAutoTUnref<SkPicture> src(SkPicture::CreateFromStream(stream)); sk_sp<SkPicture> src(SkPicture::MakeFromStream(stream));
if (!src) { if (!src) {
SkDebugf("Could not read %s as an SkPicture.\n", FLAGS_skps[i]); SkDebugf("Could not read %s as an SkPicture.\n", FLAGS_skps[i]);
return 1; return 1;
@ -79,7 +79,7 @@ int tool_main(int argc, char** argv) {
0, 0,
nullptr, nullptr,
nullptr); nullptr);
SkAutoTUnref<SkPicture> dst(r.endRecording()); sk_sp<SkPicture> dst(r.finishRecordingAsPicture());
SkFILEWStream ostream(FLAGS_write[0]); SkFILEWStream ostream(FLAGS_write[0]);
dst->serialize(&ostream); dst->serialize(&ostream);
} }

View File

@ -90,7 +90,7 @@ int main(int argc, char** argv) {
for (SkString file; iter.next(&file); ) { for (SkString file; iter.next(&file); ) {
SkAutoTDelete<SkStream> stream = SkAutoTDelete<SkStream> stream =
SkStream::NewFromFile(SkOSPath::Join(inputs, file.c_str()).c_str()); SkStream::NewFromFile(SkOSPath::Join(inputs, file.c_str()).c_str());
SkAutoTUnref<SkPicture> picture(SkPicture::CreateFromStream(stream)); sk_sp<SkPicture> picture(SkPicture::MakeFromStream(stream));
SkDynamicMemoryWStream scratch; SkDynamicMemoryWStream scratch;
Sniffer sniff; Sniffer sniff;

View File

@ -41,8 +41,8 @@ int tool_main(int argc, char** argv) {
return kError; return kError;
} }
SkAutoTUnref<SkPicture> picture(SkPicture::CreateFromStream(&inputStream)); sk_sp<SkPicture> picture(SkPicture::MakeFromStream(&inputStream));
if (nullptr == picture.get()) { if (nullptr == picture) {
if (!FLAGS_quiet) { if (!FLAGS_quiet) {
SkDebugf("Could not read the SkPicture\n"); SkDebugf("Could not read the SkPicture\n");
} }
@ -55,7 +55,7 @@ int tool_main(int argc, char** argv) {
picture->playback(recorder.beginRecording(picture->cullRect().width(), picture->playback(recorder.beginRecording(picture->cullRect().width(),
picture->cullRect().height(), picture->cullRect().height(),
nullptr, 0)); nullptr, 0));
SkAutoTUnref<SkPicture> recorded(recorder.endRecording()); sk_sp<SkPicture> recorded(recorder.finishRecordingAsPicture());
if (recorded->suitableForGpuRasterization(nullptr)) { if (recorded->suitableForGpuRasterization(nullptr)) {
SkDebugf("suitable\n"); SkDebugf("suitable\n");

View File

@ -104,33 +104,28 @@ public:
} }
private: private:
static bool ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic) { static sk_sp<SkPicture> ReadPicture(const char path[]) {
// Not strictly necessary, as it will be checked again later, // Not strictly necessary, as it will be checked again later,
// but helps to avoid a lot of pointless work if we're going to skip it. // but helps to avoid a lot of pointless work if we're going to skip it.
if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) { if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) {
return false; return nullptr;
} }
SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path)); SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path));
if (stream.get() == nullptr) { if (stream.get() == nullptr) {
SkDebugf("Could not read %s.\n", path); SkDebugf("Could not read %s.\n", path);
return false; return nullptr;
} }
pic->reset(SkPicture::CreateFromStream(stream.get())); return SkPicture::MakeFromStream(stream.get());
if (pic->get() == nullptr) {
SkDebugf("Could not read %s as an SkPicture.\n", path);
return false;
}
return true;
} }
Benchmark* innerNext() { Benchmark* innerNext() {
// Render skps // Render skps
while (fCurrentSKP < fSKPs.count()) { while (fCurrentSKP < fSKPs.count()) {
const SkString& path = fSKPs[fCurrentSKP++]; const SkString& path = fSKPs[fCurrentSKP++];
SkAutoTUnref<SkPicture> pic; auto pic = ReadPicture(path.c_str());
if (!ReadPicture(path.c_str(), &pic)) { if (!pic) {
continue; continue;
} }

View File

@ -38,13 +38,12 @@ DEFINE_string2(headCode, s, "", "Optional lua code to call at beginning");
DEFINE_string2(tailFunc, s, "", "Optional lua function to call at end"); DEFINE_string2(tailFunc, s, "", "Optional lua function to call at end");
DEFINE_bool2(quiet, q, false, "Silence all non-error related output"); DEFINE_bool2(quiet, q, false, "Silence all non-error related output");
static SkPicture* load_picture(const char path[]) { static sk_sp<SkPicture> load_picture(const char path[]) {
SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path)); SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path));
SkPicture* pic = nullptr;
if (stream.get()) { if (stream.get()) {
pic = SkPicture::CreateFromStream(stream.get()); return SkPicture::MakeFromStream(stream.get());
} }
return pic; return nullptr;
} }
static void call_canvas(lua_State* L, SkLuaCanvas* canvas, static void call_canvas(lua_State* L, SkLuaCanvas* canvas,
@ -143,7 +142,7 @@ int tool_main(int argc, char** argv) {
SkDebugf("scraping %s %s\n", path, moduloStr.c_str()); SkDebugf("scraping %s %s\n", path, moduloStr.c_str());
} }
SkAutoTUnref<SkPicture> pic(load_picture(path)); auto pic(load_picture(path));
if (pic.get()) { if (pic.get()) {
SkAutoTUnref<SkLuaCanvas> canvas( SkAutoTUnref<SkLuaCanvas> canvas(
new SkLuaCanvas(SkScalarCeilToInt(pic->cullRect().width()), new SkLuaCanvas(SkScalarCeilToInt(pic->cullRect().width()),

View File

@ -14,7 +14,7 @@
#include "SkString.h" #include "SkString.h"
#include "SkDumpCanvas.h" #include "SkDumpCanvas.h"
static SkPicture* inspect(const char path[]) { static sk_sp<SkPicture> inspect(const char path[]) {
SkFILEStream stream(path); SkFILEStream stream(path);
if (!stream.isValid()) { if (!stream.isValid()) {
printf("-- Can't open '%s'\n", path); printf("-- Can't open '%s'\n", path);
@ -33,7 +33,7 @@ static SkPicture* inspect(const char path[]) {
} }
stream.rewind(); stream.rewind();
SkPicture* pic = SkPicture::CreateFromStream(&stream); auto pic = SkPicture::MakeFromStream(&stream);
if (nullptr == pic) { if (nullptr == pic) {
SkDebugf("Could not create SkPicture: %s\n", path); SkDebugf("Could not create SkPicture: %s\n", path);
return nullptr; return nullptr;
@ -71,9 +71,9 @@ int tool_main(int argc, char** argv) {
} }
for (; index < argc; ++index) { for (; index < argc; ++index) {
SkAutoTUnref<SkPicture> pic(inspect(argv[index])); auto pic(inspect(argv[index]));
if (doDumpOps) { if (doDumpOps) {
dumpOps(pic); dumpOps(pic.get());
} }
if (index < argc - 1) { if (index < argc - 1) {
printf("\n"); printf("\n");

View File

@ -131,7 +131,7 @@ SkData* Request::writeOutSkp() {
fDebugCanvas->draw(canvas); fDebugCanvas->draw(canvas);
SkAutoTUnref<SkPicture> picture(recorder.endRecording()); sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
SkDynamicMemoryWStream outStream; SkDynamicMemoryWStream outStream;
@ -215,8 +215,8 @@ bool Request::enableGPU(bool enable) {
bool Request::initPictureFromStream(SkStream* stream) { bool Request::initPictureFromStream(SkStream* stream) {
// parse picture from stream // parse picture from stream
fPicture.reset(SkPicture::CreateFromStream(stream)); fPicture = SkPicture::MakeFromStream(stream);
if (!fPicture.get()) { if (!fPicture) {
fprintf(stderr, "Could not create picture from stream.\n"); fprintf(stderr, "Could not create picture from stream.\n");
return false; return false;
} }

View File

@ -68,7 +68,7 @@ private:
SkIRect getBounds(); SkIRect getBounds();
GrContext* getContext(); GrContext* getContext();
SkAutoTUnref<SkPicture> fPicture; sk_sp<SkPicture> fPicture;
GrContextFactory* fContextFactory; GrContextFactory* fContextFactory;
SkAutoTUnref<SkSurface> fSurface; SkAutoTUnref<SkSurface> fSurface;
bool fGPUEnabled; bool fGPUEnabled;

View File

@ -41,9 +41,8 @@ static void make_skp(SkScalar width, SkScalar height, SkScalar border, SkColor c
paint.setColor(color); paint.setColor(color);
r.inset(border, border); r.inset(border, border);
canvas->drawRect(r, paint); canvas->drawRect(r, paint);
SkAutoTUnref<SkPicture> pict(recorder.endRecording());
SkFILEWStream stream(writePath); SkFILEWStream stream(writePath);
pict->serialize(&stream); recorder.finishRecordingAsPicture()->serialize(&stream);
} }
int tool_main(int argc, char** argv); int tool_main(int argc, char** argv);