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

View File

@ -26,7 +26,7 @@ struct PictureOverheadBench : public Benchmark {
if (kDraw) {
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;
SkCanvas* pCanvas = recorder.beginRecording(PICTURE_WIDTH, PICTURE_HEIGHT, nullptr, 0);
this->recordCanvas(pCanvas);
SkAutoTUnref<SkPicture> picture(recorder.endRecording());
sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
const SkPoint translateDelta = getTranslateDelta(loops);
@ -182,7 +182,7 @@ public:
paint.setAlpha(0xFF);
canvas->drawRect(SkRect::MakeXYWH(x,y,w,h), paint);
}
fPic.reset(recorder.endRecording());
fPic = recorder.finishRecordingAsPicture();
}
void onDraw(int loops, SkCanvas* canvas) override {
@ -207,10 +207,10 @@ public:
}
private:
BBH fBBH;
Mode fMode;
SkString fName;
SkAutoTUnref<SkPicture> fPic;
BBH fBBH;
Mode fMode;
SkString fName;
sk_sp<SkPicture> fPic;
};
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++) {
SkPictureRecorder recorder;
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));
}
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,
// 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())) {
return false;
return nullptr;
}
SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path));
if (stream.get() == nullptr) {
SkDebugf("Could not read %s.\n", path);
return false;
return nullptr;
}
pic->reset(SkPicture::CreateFromStream(stream.get()));
if (pic->get() == nullptr) {
SkDebugf("Could not read %s as an SkPicture.\n", path);
return false;
}
return true;
return SkPicture::MakeFromStream(stream.get());
}
Benchmark* next() {
@ -672,14 +667,14 @@ public:
// First add all .skps as RecordingBenches.
while (fCurrentRecording < fSKPs.count()) {
const SkString& path = fSKPs[fCurrentRecording++];
SkAutoTUnref<SkPicture> pic;
if (!ReadPicture(path.c_str(), &pic)) {
sk_sp<SkPicture> pic = ReadPicture(path.c_str());
if (!pic) {
continue;
}
SkString name = SkOSPath::Basename(path.c_str());
fSourceType = "skp";
fBenchType = "recording";
fSKPBytes = static_cast<double>(SkPictureUtils::ApproximateBytesUsed(pic));
fSKPBytes = static_cast<double>(SkPictureUtils::ApproximateBytesUsed(pic.get()));
fSKPOps = pic->approximateOpCount();
return new RecordingBench(name.c_str(), pic.get(), FLAGS_bbh);
}
@ -688,8 +683,8 @@ public:
while (fCurrentScale < fScales.count()) {
while (fCurrentSKP < fSKPs.count()) {
const SkString& path = fSKPs[fCurrentSKP];
SkAutoTUnref<SkPicture> pic;
if (!ReadPicture(path.c_str(), &pic)) {
sk_sp<SkPicture> pic = ReadPicture(path.c_str());
if (!pic) {
fCurrentSKP++;
continue;
}
@ -704,7 +699,7 @@ public:
pic->cullRect().height(),
&factory,
fUseMPDs[fCurrentUseMPD] ? kFlags : 0));
pic.reset(recorder.endRecording());
pic = recorder.finishRecordingAsPicture();
}
SkString name = SkOSPath::Basename(path.c_str());
fSourceType = "skp";
@ -723,8 +718,8 @@ public:
if (fZoomMax != 1.0f && fZoomPeriodMs > 0) {
while (fCurrentAnimSKP < fSKPs.count()) {
const SkString& path = fSKPs[fCurrentAnimSKP];
SkAutoTUnref<SkPicture> pic;
if (!ReadPicture(path.c_str(), &pic)) {
sk_sp<SkPicture> pic = ReadPicture(path.c_str());
if (!pic) {
fCurrentAnimSKP++;
continue;
}

View File

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

View File

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

View File

@ -43,13 +43,13 @@ protected:
rec->clipPath(p, SkRegion::kIntersect_Op, true);
rec->drawColor(SK_ColorGREEN);
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.
pict->playback(recorder.beginRecording(pict->cullRect().width(),
pict->cullRect().height(),
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.
canvas->save();

View File

@ -246,17 +246,17 @@ protected:
//-----------
// Paints with a PictureImageFilter as a source
SkAutoTUnref<SkPicture> pic;
sk_sp<SkPicture> pic;
{
SkPictureRecorder rec;
SkCanvas* c = rec.beginRecording(10, 10);
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;
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*)) {
SkPictureRecorder recorder;
draw(recorder.beginRecording(SkRect::MakeIWH(info.width(), info.height())));
SkAutoTUnref<SkPicture> pict(recorder.endRecording());
return SkImage::MakeFromPicture(sk_ref_sp(pict.get()), info.dimensions(), nullptr, nullptr);
return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(),
info.dimensions(), nullptr, nullptr);
}
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) {
SkPictureRecorder recorder;
draw_opaque_contents(recorder.beginRecording(SkRect::MakeIWH(info.width(), info.height())));
SkAutoTUnref<SkPicture> pict(recorder.endRecording());
return SkImageGenerator::NewFromPicture(info.dimensions(), pict, nullptr, nullptr);
sk_sp<SkPicture> pict(recorder.finishRecordingAsPicture());
return SkImageGenerator::NewFromPicture(info.dimensions(), pict.get(), nullptr, nullptr);
}
static SkImageGenerator* gen_png(const SkImageInfo& info) {
@ -476,9 +476,8 @@ DEF_SIMPLE_GM(new_texture_image, canvas, 225, 60) {
SkPictureRecorder recorder;
SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kSize), SkIntToScalar(kSize));
render_image(canvas);
SkAutoTUnref<SkPicture> picture(recorder.endRecording());
return SkImage::MakeFromPicture(sk_ref_sp(picture.get()), SkISize::Make(kSize, kSize),
nullptr, nullptr);
return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(),
SkISize::Make(kSize, kSize), nullptr, nullptr);
},
// Create a texture image
[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.
*/
class ImagePictGM : public skiagm::GM {
SkAutoTUnref<SkPicture> fPicture;
sk_sp<SkPicture> fPicture;
sk_sp<SkImage> fImage0;
sk_sp<SkImage> fImage1;
public:
@ -54,18 +54,18 @@ protected:
const SkRect bounds = SkRect::MakeXYWH(100, 100, 100, 100);
SkPictureRecorder recorder;
draw_something(recorder.beginRecording(bounds), bounds);
fPicture.reset(recorder.endRecording());
fPicture = recorder.finishRecordingAsPicture();
// extract enough just for the oval.
const SkISize size = SkISize::Make(100, 100);
SkMatrix matrix;
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.postRotate(45);
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 {
@ -254,7 +254,7 @@ static SkImageGenerator* make_tex_generator(GrContext* ctx, SkPicture* pic) {
class ImageCacheratorGM : public skiagm::GM {
SkString fName;
SkImageGenerator* (*fFactory)(GrContext*, SkPicture*);
SkAutoTUnref<SkPicture> fPicture;
sk_sp<SkPicture> fPicture;
SkAutoTDelete<SkImageCacherator> fCache;
SkAutoTDelete<SkImageCacherator> fCacheSubset;
@ -278,17 +278,17 @@ protected:
const SkRect bounds = SkRect::MakeXYWH(100, 100, 100, 100);
SkPictureRecorder recorder;
draw_something(recorder.beginRecording(bounds), bounds);
fPicture.reset(recorder.endRecording());
fPicture = recorder.finishRecordingAsPicture();
}
void makeCaches(GrContext* ctx) {
auto gen = fFactory(ctx, fPicture);
auto gen = fFactory(ctx, fPicture.get());
SkDEBUGCODE(const uint32_t genID = gen->uniqueID();)
fCache.reset(SkImageCacherator::NewFromGenerator(gen));
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();)
fCacheSubset.reset(SkImageCacherator::NewFromGenerator(gen, &subset));

View File

@ -72,7 +72,7 @@ const ImageMakerProc gProcs[] = {
* (correctly) when it is inside an image.
*/
class ImageShaderGM : public skiagm::GM {
SkAutoTUnref<SkPicture> fPicture;
sk_sp<SkPicture> fPicture;
public:
ImageShaderGM() {}
@ -90,7 +90,7 @@ protected:
const SkRect bounds = SkRect::MakeWH(100, 100);
SkPictureRecorder recorder;
draw_something(recorder.beginRecording(bounds), bounds);
fPicture.reset(recorder.endRecording());
fPicture = recorder.finishRecordingAsPicture();
}
void testImage(SkCanvas* canvas, SkImage* image) {
@ -113,7 +113,7 @@ protected:
const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100);
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) {
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
// each hexagon is in its own layer. The layers are to exercise Ganesh's
// 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
SkPath hex = make_hex_path(0, 0);
@ -80,14 +80,14 @@ static const SkPicture* make_hex_plane_picture(SkColor fillColor) {
yPos += 2 * kHexSide * kRoot3Over2;
}
return recorder.endRecording();
return recorder.finishRecordingAsPicture();
}
// Create a picture that consists of a single large layer that is tiled
// with hexagons.
// This is intended to exercise the layer hoisting code's clip handling (in
// 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
SkPath hex = make_hex_path(0, 0);
@ -136,7 +136,7 @@ static const SkPicture* make_single_layer_hex_plane_picture() {
canvas->restore();
return recorder.endRecording();
return recorder.finishRecordingAsPicture();
}
// 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;
}
static const SkPicture* make_tri_picture() {
static sk_sp<SkPicture> make_tri_picture() {
SkPath tri = make_tri_path(SkScalarHalf(kTriSide), 0);
SkPaint fill;
@ -176,10 +176,10 @@ static const SkPicture* make_tri_picture() {
canvas->drawPath(tri, stroke);
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;
SkRTreeFactory bbhFactory;
@ -205,15 +205,15 @@ static const SkPicture* make_sub_picture(const SkPicture* tri) {
canvas->drawPicture(tri);
canvas->restore();
return recorder.endRecording();
return recorder.finishRecordingAsPicture();
}
// 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,
// shrinks it and replicates it 3 times then draws and appropriate number of
// copies of it.
static const SkPicture* make_sierpinski_picture() {
SkAutoTUnref<const SkPicture> pic(make_tri_picture());
static sk_sp<SkPicture> make_sierpinski_picture() {
sk_sp<SkPicture> pic(make_tri_picture());
SkPictureRecorder recorder;
SkRTreeFactory bbhFactory;
@ -233,12 +233,12 @@ static const SkPicture* make_sierpinski_picture() {
}
canvas->restore();
pic.reset(make_sub_picture(pic));
pic = make_sub_picture(pic.get());
canvas->translate(0, 1.5f * kTriSide / kRoot3);
}
return recorder.endRecording();
return recorder.finishRecordingAsPicture();
}
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,
const SkPicture* pictures[kNumPictures],
SkCanvas* dest, const SkMatrix& xform) {
SkAutoTUnref<SkPicture> composite;
sk_sp<SkPicture> composite;
{
SkPictureRecorder recorder;
@ -369,10 +369,10 @@ static void create_content(SkMultiPictureDraw* mpd, PFContentMtd pfGen,
(*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,
@ -490,10 +490,10 @@ namespace skiagm {
const SkPicture* fPictures[kNumPictures];
void onOnceBeforeDraw() override {
fPictures[0] = make_hex_plane_picture(SK_ColorWHITE);
fPictures[1] = make_hex_plane_picture(sk_tool_utils::color_to_565(SK_ColorGRAY));
fPictures[2] = make_sierpinski_picture();
fPictures[3] = make_single_layer_hex_plane_picture();
fPictures[0] = make_hex_plane_picture(SK_ColorWHITE).release();
fPictures[1] = make_hex_plane_picture(sk_tool_utils::color_to_565(SK_ColorGRAY)).release();
fPictures[2] = make_sierpinski_picture().release();
fPictures[3] = make_single_layer_hex_plane_picture().release();
}
void onDraw(SkCanvas* canvas) override {

View File

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

View File

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

View File

@ -33,7 +33,7 @@ protected:
paint.setTextSize(SkIntToScalar(96));
const char* str = "e";
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); }
@ -58,16 +58,16 @@ protected:
SkRect emptyRect = SkRect::MakeXYWH(20, 20, 0, 0);
SkRect bounds = SkRect::MakeXYWH(0, 0, 100, 100);
SkAutoTUnref<SkImageFilter> pictureSource(
SkPictureImageFilter::Create(fPicture));
SkPictureImageFilter::Create(fPicture.get()));
SkAutoTUnref<SkImageFilter> pictureSourceSrcRect(
SkPictureImageFilter::Create(fPicture, srcRect));
SkPictureImageFilter::Create(fPicture.get(), srcRect));
SkAutoTUnref<SkImageFilter> pictureSourceEmptyRect(
SkPictureImageFilter::Create(fPicture, emptyRect));
SkPictureImageFilter::Create(fPicture.get(), emptyRect));
SkAutoTUnref<SkImageFilter> pictureSourceResampled(
SkPictureImageFilter::CreateForLocalSpace(fPicture, fPicture->cullRect(),
SkPictureImageFilter::CreateForLocalSpace(fPicture.get(), fPicture->cullRect(),
kLow_SkFilterQuality));
SkAutoTUnref<SkImageFilter> pictureSourcePixelated(
SkPictureImageFilter::CreateForLocalSpace(fPicture, fPicture->cullRect(),
SkPictureImageFilter::CreateForLocalSpace(fPicture.get(), fPicture->cullRect(),
kNone_SkFilterQuality));
canvas->save();
@ -102,7 +102,7 @@ protected:
}
private:
SkAutoTUnref<SkPicture> fPicture;
sk_sp<SkPicture> fPicture;
typedef GM INHERITED;
};

View File

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

View File

@ -35,7 +35,7 @@ public:
SkPictureRecorder recorder;
SkCanvas* pictureCanvas = recorder.beginRecording(fTileSize, fTileSize, nullptr, 0);
this->drawTile(pictureCanvas);
fPicture.reset(recorder.endRecording());
fPicture = recorder.finishRecordingAsPicture();
// Build a reference bitmap.
fBitmap.allocN32Pixels(SkScalarCeilToInt(fTileSize), SkScalarCeilToInt(fTileSize));
@ -193,7 +193,7 @@ DEF_SIMPLE_GM(tiled_picture_shader, canvas, 400, 400) {
p.setStrokeWidth(10);
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,
SkShader::kRepeat_TileMode,
nullptr, nullptr));

View File

@ -95,14 +95,14 @@ protected:
SkPictureRecorder recorder;
SkCanvas* pictureCanvas = recorder.beginRecording(kPictureSize, kPictureSize);
draw_scene(pictureCanvas, kPictureSize);
sk_sp<SkPicture> picture(recorder.endRecording());
sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
SkPoint offset = SkPoint::Make(100, 100);
pictureCanvas = recorder.beginRecording(SkRect::MakeXYWH(offset.x(), offset.y(),
kPictureSize, kPictureSize));
pictureCanvas->translate(offset.x(), offset.y());
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) {
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) {
SkRect targetRect(SkRect::MakeWH(SkIntToScalar(kTestRectSize), SkIntToScalar(kTestRectSize)));
SkAutoTUnref<SkPicture> shape;
sk_sp<SkPicture> shape;
{
SkPictureRecorder recorder;
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;
shapePaint.setColor(shapeColor);
canvas->drawRect(targetRect, shapePaint);
shape.reset(recorder.endRecordingAsPicture());
shape = recorder.finishRecordingAsPicture();
}
SkPaint layerPaint;
@ -117,7 +117,7 @@ static void draw_svg_opacity_and_filter_layer_sequence(SkCanvas* canvas, SkColor
canvas->save();
canvas->clipRect(targetRect);
SkPaint drawPaint;
drawPaint.setImageFilter(SkPictureImageFilter::Create(shape))->unref();
drawPaint.setImageFilter(SkPictureImageFilter::Create(shape.get()))->unref();
installDetector(&drawPaint);
canvas->saveLayer(&targetRect, &drawPaint);
canvas->restore();
@ -161,8 +161,7 @@ DEF_SIMPLE_GM(recordopts, canvas, (kTestRectSize+1)*2, (kTestRectSize+1)*15) {
drawTestSequence(recorder.beginRecording(SkIntToScalar(kTestRectSize),
SkIntToScalar(kTestRectSize)),
shapeColor, no_detector_install);
SkAutoTUnref<SkPicture> optimizedPicture(recorder.endRecordingAsPicture());
optimizedPicture->playback(canvas);
recorder.finishRecordingAsPicture()->playback(canvas);
canvas->flush();
}
canvas->restore();
@ -203,8 +202,7 @@ DEF_SIMPLE_GM(recordopts, canvas, (kTestRectSize+1)*2, (kTestRectSize+1)*15) {
drawTestSequence(recorder.beginRecording(SkIntToScalar(kTestRectSize),
SkIntToScalar(kTestRectSize)),
shapeColor, detectorInstallFunc);
SkAutoTUnref<SkPicture> optimizedPicture(recorder.endRecordingAsPicture());
optimizedPicture->playback(canvas);
recorder.finishRecordingAsPicture()->playback(canvas);
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]) {
SkPictureRecorder recorder;
draw(recorder.beginRecording(SkRect::MakeIWH(width, height)), width, height, colors);
SkAutoTUnref<SkPicture> picture(recorder.endRecording());
return SkImage::MakeFromPicture(sk_ref_sp(picture.get()), SkISize::Make(width, height),
nullptr, nullptr);
return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(),
SkISize::Make(width, height), nullptr, nullptr);
}
typedef sk_sp<SkImage> (*ImageMakerProc)(int width, int height, SkColor colors[2]);

View File

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

View File

@ -24,6 +24,8 @@ class SkTypefacePlayback;
class SkWStream;
struct SkPictInfo;
#define SK_SUPPORT_LEGACY_PICTURE_PTR
/** \class SkPicture
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
* invalid.
*/
static SkPicture* CreateFromStream(SkStream*, InstallPixelRefProc proc);
static sk_sp<SkPicture> MakeFromStream(SkStream*, InstallPixelRefProc proc);
/**
* 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
* 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
@ -76,7 +78,7 @@ public:
* @return A new SkPicture representing the serialized data, or NULL if the buffer is
* invalid.
*/
static SkPicture* CreateFromBuffer(SkReadBuffer&);
static sk_sp<SkPicture> MakeFromBuffer(SkReadBuffer&);
/**
* Subclasses of this can be passed to playback(). During the playback
@ -167,6 +169,18 @@ public:
static void SetPictureIOSecurityPrecautionsEnabled_Dangerous(bool set);
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:
// Subclass whitelist.
SkPicture();
@ -175,9 +189,7 @@ private:
template <typename> friend class SkMiniPicture;
void serialize(SkWStream*, SkPixelSerializer*, SkRefCntSet* typefaces) const;
static SkPicture* CreateFromStream(SkStream*,
InstallPixelRefProc proc,
SkTypefacePlayback*);
static sk_sp<SkPicture> MakeFromStream(SkStream*, InstallPixelRefProc, SkTypefacePlayback*);
friend class SkPictureData;
virtual int numSlowPaths() const = 0;
@ -208,7 +220,7 @@ private:
"Remove SkBitmapSourceDeserializer.");
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;
SkPictureData* backport() const;

View File

@ -72,7 +72,7 @@ public:
* reflect their current state, but will not contain a live reference to the drawables
* 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
@ -83,7 +83,7 @@ public:
* and subsequent culling operations.
* @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
@ -95,10 +95,20 @@ public:
* 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()).
*/
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(); }
#endif
private:
void reset();

View File

@ -27,7 +27,7 @@ public:
bool drawTextBlob(const SkTextBlob*, SkScalar x, SkScalar y, const SkPaint&);
// 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.
// 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);
this->drawPicture(record, 120);
}
SkAutoTUnref<SkPicture> picture(recorder.endRecording());
sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
canvas->translate(0, SkIntToScalar(120));

View File

@ -1389,7 +1389,7 @@ void SampleWindow::afterChildren(SkCanvas* orig) {
}
if (fSaveToSKP) {
SkAutoTUnref<const SkPicture> picture(fRecorder.endRecording());
sk_sp<SkPicture> picture(fRecorder.finishRecordingAsPicture());
SkFILEWStream stream("sample_app.skp");
picture->serialize(&stream);
fSaveToSKP = false;
@ -1398,7 +1398,7 @@ void SampleWindow::afterChildren(SkCanvas* orig) {
}
if (fUsePicture) {
SkAutoTUnref<const SkPicture> picture(fRecorder.endRecording());
sk_sp<SkPicture> picture(fRecorder.finishRecordingAsPicture());
// serialize/deserialize?
if (false) {
@ -1406,9 +1406,9 @@ void SampleWindow::afterChildren(SkCanvas* orig) {
picture->serialize(&wstream);
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

View File

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

View File

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

View File

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

View File

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

View File

@ -54,7 +54,7 @@ static const int gWidth = 32;
static const int gHeight = 32;
class TilingView : public SampleView {
SkAutoTUnref<SkPicture> fTextPicture;
sk_sp<SkPicture> fTextPicture;
SkAutoTUnref<SkDrawLooper> fLooper;
public:
TilingView()
@ -153,11 +153,11 @@ protected:
if (textCanvas) {
SkASSERT(nullptr == fTextPicture);
fTextPicture.reset(recorder.endRecording());
fTextPicture = recorder.finishRecordingAsPicture();
}
SkASSERT(fTextPicture);
canvas->drawPicture(fTextPicture);
canvas->drawPicture(fTextPicture.get());
}
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) {
return ToPicture(AsPictureRecorder(crec)->endRecording());
return ToPicture(AsPictureRecorder(crec)->finishRecordingAsPicture().release());
}
void sk_picture_ref(sk_picture_t* cpic) {

View File

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

View File

@ -62,7 +62,7 @@ SkMiniRecorder::~SkMiniRecorder() {
if (fState != State::kEmpty) {
// We have internal state pending.
// 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);
}
@ -101,14 +101,14 @@ bool SkMiniRecorder::drawTextBlob(const SkTextBlob* b, SkScalar x, SkScalar y, c
#undef TRY_TO_STORE
SkPicture* SkMiniRecorder::detachAsPicture(const SkRect& cull) {
sk_sp<SkPicture> SkMiniRecorder::detachAsPicture(const SkRect& cull) {
#define CASE(Type) \
case State::k##Type: \
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) {
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(DrawPath);
CASE(DrawRect);

View File

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

View File

@ -392,7 +392,7 @@ bool SkPictureData::parseStreamTag(SkStream* stream,
fPictureCount = 0;
fPictureRefs = new const SkPicture* [size];
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]) {
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,
// as SkPicture::CreateFromBuffer() returns SkPicture*
static const SkPicture* create_picture_from_buffer(SkReadBuffer& buffer) {
return SkPicture::CreateFromBuffer(buffer);
return SkPicture::MakeFromBuffer(buffer).release();
}
template <typename T>

View File

@ -50,7 +50,7 @@ SkCanvas* SkPictureRecorder::getRecordingCanvas() {
return fActivelyRecording ? fRecorder.get() : nullptr;
}
SkPicture* SkPictureRecorder::endRecordingAsPicture() {
sk_sp<SkPicture> SkPictureRecorder::finishRecordingAsPicture() {
fActivelyRecording = false;
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++) {
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);
}
SkPicture* SkPictureRecorder::endRecordingAsPicture(const SkRect& cullRect) {
sk_sp<SkPicture> SkPictureRecorder::finishRecordingAsPictureWithCull(const SkRect& cullRect) {
fCullRect = cullRect;
return this->endRecordingAsPicture();
return this->finishRecordingAsPicture();
}
@ -177,7 +177,7 @@ protected:
}
};
SkDrawable* SkPictureRecorder::endRecordingAsDrawable() {
sk_sp<SkDrawable> SkPictureRecorder::finishRecordingAsDrawable() {
fActivelyRecording = false;
fRecorder->flushMiniRecorder();
fRecorder->restoreToCount(1); // If we were missing any restores, add them now.
@ -191,8 +191,8 @@ SkDrawable* SkPictureRecorder::endRecordingAsDrawable() {
fBBH->insert(bounds, fRecord->count());
}
SkDrawable* drawable =
new SkRecordedDrawable(fRecord, fBBH, fRecorder->detachDrawableList(), fCullRect,
sk_sp<SkDrawable> drawable =
sk_make_sp<SkRecordedDrawable>(fRecord, fBBH, fRecorder->detachDrawableList(), fCullRect,
SkToBool(fFlags & kComputeSaveLayerInfo_RecordFlag));
// 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.
if (buffer.isVersionLT(SkReadBuffer::kPictureShaderHasPictureBool_Version) ||
buffer.readBool()) {
picture.reset(SkPicture::CreateFromBuffer(buffer));
picture = SkPicture::MakeFromBuffer(buffer);
}
}
return SkPictureShader::Make(picture, mx, my, &lm, &tile).release();

View File

@ -36,14 +36,14 @@ SkPictureImageFilter::~SkPictureImageFilter() {
}
SkFlattenable* SkPictureImageFilter::CreateProc(SkReadBuffer& buffer) {
SkAutoTUnref<SkPicture> picture;
sk_sp<SkPicture> picture;
SkRect cropRect;
if (buffer.isCrossProcess() && SkPicture::PictureIOSecurityPrecautionsEnabled()) {
buffer.validate(!buffer.readBool());
} else {
if (buffer.readBool()) {
picture.reset(SkPicture::CreateFromBuffer(buffer));
picture = SkPicture::MakeFromBuffer(buffer);
}
}
buffer.readRect(&cropRect);
@ -62,9 +62,9 @@ SkFlattenable* SkPictureImageFilter::CreateProc(SkReadBuffer& buffer) {
} else {
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 {

View File

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

View File

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

View File

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

View File

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

View File

@ -111,8 +111,8 @@ static sk_sp<SkImage> create_picture_image() {
SkPictureRecorder recorder;
SkCanvas* canvas = recorder.beginRecording(10, 10);
canvas->clear(SK_ColorCYAN);
sk_sp<SkPicture> picture(recorder.endRecording());
return SkImage::MakeFromPicture(picture, SkISize::Make(10, 10), nullptr, nullptr);
return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(), SkISize::Make(10, 10),
nullptr, nullptr);
};
#endif
// 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;
SkCanvas* canvas = recorder.beginRecording(100, 100);
canvas->drawImage(image, 0, 0);
SkAutoTUnref<SkPicture> picture(recorder.endRecording());
sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
REPORTER_ASSERT(reporter, picture);
REPORTER_ASSERT(reporter, picture->approximateOpCount() > 0);
@ -247,7 +247,7 @@ DEF_TEST(Image_Serialize_Encoding_Failure, reporter) {
REPORTER_ASSERT(reporter, serializers[i]->didEncode());
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->approximateOpCount() > 0);
}

View File

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

View File

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

View File

@ -31,8 +31,8 @@ DEF_TEST(PictureShader_empty, reporter) {
SkPictureRecorder factory;
factory.beginRecording(0, 0, nullptr, 0);
sk_sp<SkPicture> picture(factory.endRecording());
paint.setShader(SkShader::MakePictureShader(std::move(picture), SkShader::kClamp_TileMode,
paint.setShader(SkShader::MakePictureShader(factory.finishRecordingAsPicture(),
SkShader::kClamp_TileMode,
SkShader::kClamp_TileMode, nullptr, nullptr));
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;
recorder.beginRecording(100,100)->drawImage(image, 0,0);
SkAutoTUnref<SkPicture> picture(recorder.endRecording());
sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
REPORTER_ASSERT(reporter, picture->willPlayBackBitmaps());
}
@ -67,7 +67,7 @@ static void test_analysis(skiatest::Reporter* reporter) {
{
canvas->drawRect(SkRect::MakeWH(10, 10), SkPaint ());
}
SkAutoTUnref<SkPicture> picture(recorder.endRecording());
sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
REPORTER_ASSERT(reporter, !picture->willPlayBackBitmaps());
canvas = recorder.beginRecording(100, 100);
@ -85,8 +85,7 @@ static void test_analysis(skiatest::Reporter* reporter) {
canvas->drawRect(SkRect::MakeWH(10, 10), paint);
}
picture.reset(recorder.endRecording());
REPORTER_ASSERT(reporter, picture->willPlayBackBitmaps());
REPORTER_ASSERT(reporter, recorder.finishRecordingAsPicture()->willPlayBackBitmaps());
}
@ -98,7 +97,7 @@ static void test_deleting_empty_picture() {
// Creates an SkPictureRecord
recorder.beginRecording(0, 0);
// Turns that into an SkPicture
SkAutoTUnref<SkPicture> picture(recorder.endRecording());
sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
// Ceates a new SkPictureRecord
recorder.beginRecording(0, 0);
}
@ -107,7 +106,7 @@ static void test_deleting_empty_picture() {
static void test_serializing_empty_picture() {
SkPictureRecorder recorder;
recorder.beginRecording(0, 0);
SkAutoTUnref<SkPicture> picture(recorder.endRecording());
sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
SkDynamicMemoryWStream stream;
picture->serialize(&stream);
}
@ -155,7 +154,7 @@ static void test_gpu_veto(skiatest::Reporter* reporter) {
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
const char *reason = nullptr;
@ -180,7 +179,7 @@ static void test_gpu_veto(skiatest::Reporter* reporter) {
canvas->drawPath(path, paint);
}
}
picture.reset(recorder.endRecording());
picture = recorder.finishRecordingAsPicture();
// A lot of small AA concave paths should be fine for GPU rendering
REPORTER_ASSERT(reporter, picture->suitableForGpuRasterization(nullptr));
@ -202,7 +201,7 @@ static void test_gpu_veto(skiatest::Reporter* reporter) {
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
REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(nullptr));
@ -226,7 +225,7 @@ static void test_gpu_veto(skiatest::Reporter* reporter) {
canvas->drawPath(path, paint);
}
}
picture.reset(recorder.endRecording());
picture = recorder.finishRecordingAsPicture();
// hairline stroked AA concave paths are fine for GPU rendering
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);
}
}
picture.reset(recorder.endRecording());
picture = recorder.finishRecordingAsPicture();
// fast-path dashed effects are fine for GPU rendering ...
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);
}
}
picture.reset(recorder.endRecording());
picture = recorder.finishRecordingAsPicture();
// ... but only when applied to drawPoint() calls
REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(nullptr));
@ -267,7 +266,7 @@ static void test_gpu_veto(skiatest::Reporter* reporter) {
{
canvas->drawPicture(picture.get());
}
picture.reset(recorder.endRecording());
picture = recorder.finishRecordingAsPicture();
REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(nullptr));
}
@ -287,7 +286,7 @@ static void test_savelayer_extraction(skiatest::Reporter* reporter) {
SkPaint complexPaint;
complexPaint.setImageFilter(filter);
SkAutoTUnref<SkPicture> pict, child;
sk_sp<SkPicture> pict, child;
SkRTreeFactory bbhFactory;
{
@ -300,7 +299,7 @@ static void test_savelayer_extraction(skiatest::Reporter* reporter) {
c->saveLayer(nullptr, &complexPaint);
c->restore();
child.reset(recorder.endRecording());
child = recorder.finishRecordingAsPicture();
}
// create a picture with the structure:
@ -368,7 +367,7 @@ static void test_savelayer_extraction(skiatest::Reporter* reporter) {
c->restore();
}
pict.reset(recorder.endRecording());
pict = recorder.finishRecordingAsPicture();
}
// Now test out the SaveLayer extraction
@ -446,7 +445,7 @@ static void test_savelayer_extraction(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, !info4.fIsNested &&
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() &&
kHeight == info5.fBounds.height());
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 &&
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() &&
kHeight == info7.fBounds.height());
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());
}
SkAutoTUnref<SkPicture> picture(recorder.endRecording());
sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
REPORTER_ASSERT(reporter, !picture->hasText());
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());
}
picture.reset(recorder.endRecording());
picture = recorder.finishRecordingAsPicture();
REPORTER_ASSERT(reporter, picture->hasText());
canvas = recorder.beginRecording(100,100);
{
canvas->drawPosText("Q", 1, &point, SkPaint());
}
picture.reset(recorder.endRecording());
picture = recorder.finishRecordingAsPicture();
REPORTER_ASSERT(reporter, picture->hasText());
canvas = recorder.beginRecording(100,100);
{
canvas->drawPosTextH("Q", 1, &point.fX, point.fY, SkPaint());
}
picture.reset(recorder.endRecording());
picture = recorder.finishRecordingAsPicture();
REPORTER_ASSERT(reporter, picture->hasText());
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());
}
picture.reset(recorder.endRecording());
picture = recorder.finishRecordingAsPicture();
REPORTER_ASSERT(reporter, picture->hasText());
canvas = recorder.beginRecording(100,100);
@ -527,7 +526,7 @@ static void test_has_text(skiatest::Reporter* reporter) {
canvas->drawTextOnPath("Q", 1, path, nullptr, SkPaint());
}
picture.reset(recorder.endRecording());
picture = recorder.finishRecordingAsPicture();
REPORTER_ASSERT(reporter, picture->hasText());
// Nest the previous picture inside a new one.
@ -535,7 +534,7 @@ static void test_has_text(skiatest::Reporter* reporter) {
{
canvas->drawPicture(picture.get());
}
picture.reset(recorder.endRecording());
picture = recorder.finishRecordingAsPicture();
REPORTER_ASSERT(reporter, picture->hasText());
}
@ -604,14 +603,14 @@ void check_save_state(skiatest::Reporter* reporter, SkPicture* picture,
// the 'partialReplay' method.
class SkPictureRecorderReplayTester {
public:
static SkPicture* Copy(SkPictureRecorder* recorder) {
static sk_sp<SkPicture> Copy(SkPictureRecorder* recorder) {
SkPictureRecorder recorder2;
SkCanvas* canvas = recorder2.beginRecording(10, 10);
recorder->partialReplay(canvas);
return recorder2.endRecording();
return recorder2.finishRecordingAsPicture();
}
};
@ -664,19 +663,19 @@ DEF_TEST(PictureRecorder_replay, reporter) {
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.
check_save_state(reporter, copy, 2, 1, 3);
check_save_state(reporter, copy.get(), 2, 1, 3);
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
check_save_state(reporter, copy, 2, 1, 3);
check_save_state(reporter, copy.get(), 2, 1, 3);
}
// (partially) check leakage of draw ops
@ -690,7 +689,7 @@ DEF_TEST(PictureRecorder_replay, reporter) {
canvas->drawRect(r, p);
SkAutoTUnref<SkPicture> copy(SkPictureRecorderReplayTester::Copy(&recorder));
sk_sp<SkPicture> copy(SkPictureRecorderReplayTester::Copy(&recorder));
REPORTER_ASSERT(reporter, !copy->willPlayBackBitmaps());
@ -700,7 +699,7 @@ DEF_TEST(PictureRecorder_replay, reporter) {
r.offset(5.0f, 5.0f);
canvas->drawBitmapRect(bm, r, nullptr);
SkAutoTUnref<SkPicture> final(recorder.endRecording());
sk_sp<SkPicture> final(recorder.finishRecordingAsPicture());
REPORTER_ASSERT(reporter, final->willPlayBackBitmaps());
REPORTER_ASSERT(reporter, copy->uniqueID() != final->uniqueID());
@ -718,14 +717,14 @@ DEF_TEST(PictureRecorder_replay, reporter) {
int expectedSaveCount = canvas->getSaveCount();
SkAutoTUnref<SkPicture> copy(SkPictureRecorderReplayTester::Copy(&recorder));
check_balance(reporter, copy);
sk_sp<SkPicture> copy(SkPictureRecorderReplayTester::Copy(&recorder));
check_balance(reporter, copy.get());
REPORTER_ASSERT(reporter, expectedSaveCount = canvas->getSaveCount());
// End the recording of source to test the picture finalization
// 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->translate(10, 10);
canvas->drawRect(rect, paint);
SkAutoTUnref<SkPicture> extraSavePicture(recorder.endRecording());
sk_sp<SkPicture> extraSavePicture(recorder.finishRecordingAsPicture());
testCanvas.drawPicture(extraSavePicture);
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();
SkAutoTUnref<SkPicture> extraRestorePicture(recorder.endRecording());
sk_sp<SkPicture> extraRestorePicture(recorder.finishRecordingAsPicture());
testCanvas.drawPicture(extraRestorePicture);
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);
canvas->translate(10, 10);
canvas->drawRect(rect, paint);
SkAutoTUnref<SkPicture> noSavePicture(recorder.endRecording());
sk_sp<SkPicture> noSavePicture(recorder.finishRecordingAsPicture());
testCanvas.drawPicture(noSavePicture);
REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount());
@ -803,7 +802,7 @@ static void test_peephole() {
for (int i = 0; i < 1000; ++i) {
rand_op(canvas, rand);
}
SkAutoTUnref<SkPicture> picture(recorder.endRecording());
sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
rand = rand2;
}
@ -819,7 +818,7 @@ static void test_peephole() {
canvas->clipRect(rect);
canvas->restore();
}
SkAutoTUnref<SkPicture> picture(recorder.endRecording());
sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
}
}
@ -834,7 +833,7 @@ static void test_bad_bitmap() {
SkPictureRecorder recorder;
SkCanvas* recordingCanvas = recorder.beginRecording(100, 100);
recordingCanvas->drawBitmap(bm, 0, 0);
SkAutoTUnref<SkPicture> picture(recorder.endRecording());
sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
SkCanvas canvas;
canvas.drawPicture(picture);
@ -846,7 +845,7 @@ static SkData* serialized_picture_from_bitmap(const SkBitmap& bitmap) {
SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(bitmap.width()),
SkIntToScalar(bitmap.height()));
canvas->drawBitmap(bitmap, 0, 0);
SkAutoTUnref<SkPicture> picture(recorder.endRecording());
sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
SkDynamicMemoryWStream wStream;
SkAutoTUnref<SkPixelSerializer> serializer(
@ -911,7 +910,7 @@ DEF_TEST(Picture_EncodedData, reporter) {
SkSetErrorCallback(assert_one_parse_error_cb, &context);
SkMemoryStream pictureStream(picture1);
SkClearLastError();
SkAutoTUnref<SkPicture> pictureFromStream(SkPicture::CreateFromStream(&pictureStream, nullptr));
sk_sp<SkPicture> pictureFromStream(SkPicture::MakeFromStream(&pictureStream, nullptr));
REPORTER_ASSERT(reporter, pictureFromStream.get() != nullptr);
SkClearLastError();
SkSetErrorCallback(nullptr, nullptr);
@ -927,7 +926,7 @@ DEF_TEST(Picture_EncodedData, reporter) {
SkCanvas canvas(dst);
pictureStream.rewind();
pictureFromStream.reset(SkPicture::CreateFromStream(&pictureStream));
pictureFromStream = SkPicture::MakeFromStream(&pictureStream);
canvas.drawPicture(pictureFromStream.get());
SkMD5::Digest digest2;
@ -1032,7 +1031,7 @@ static void test_cull_rect_reset(skiatest::Reporter* reporter) {
SkPaint 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();
REPORTER_ASSERT(reporter, picture);
@ -1106,7 +1105,7 @@ static void test_clip_expansion(skiatest::Reporter* reporter) {
SkPaint p;
p.setColor(SK_ColorBLUE);
canvas->drawPaint(p);
SkAutoTUnref<SkPicture> picture(recorder.endRecording());
sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
ClipCountingCanvas testCanvas(10, 10);
picture->playback(&testCanvas);
@ -1122,37 +1121,37 @@ static void test_hierarchical(skiatest::Reporter* reporter) {
SkPictureRecorder recorder;
recorder.beginRecording(10, 10);
SkAutoTUnref<SkPicture> childPlain(recorder.endRecording());
sk_sp<SkPicture> childPlain(recorder.finishRecordingAsPicture());
REPORTER_ASSERT(reporter, !childPlain->willPlayBackBitmaps()); // 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
{
SkCanvas* canvas = recorder.beginRecording(10, 10);
canvas->drawPicture(childPlain);
SkAutoTUnref<SkPicture> parentPP(recorder.endRecording());
sk_sp<SkPicture> parentPP(recorder.finishRecordingAsPicture());
REPORTER_ASSERT(reporter, !parentPP->willPlayBackBitmaps()); // 0
}
{
SkCanvas* canvas = recorder.beginRecording(10, 10);
canvas->drawPicture(childWithBitmap);
SkAutoTUnref<SkPicture> parentPWB(recorder.endRecording());
sk_sp<SkPicture> parentPWB(recorder.finishRecordingAsPicture());
REPORTER_ASSERT(reporter, parentPWB->willPlayBackBitmaps()); // 1
}
{
SkCanvas* canvas = recorder.beginRecording(10, 10);
canvas->drawBitmap(bm, 0, 0);
canvas->drawPicture(childPlain);
SkAutoTUnref<SkPicture> parentWBP(recorder.endRecording());
sk_sp<SkPicture> parentWBP(recorder.finishRecordingAsPicture());
REPORTER_ASSERT(reporter, parentWBP->willPlayBackBitmaps()); // 1
}
{
SkCanvas* canvas = recorder.beginRecording(10, 10);
canvas->drawBitmap(bm, 0, 0);
canvas->drawPicture(childWithBitmap);
SkAutoTUnref<SkPicture> parentWBWB(recorder.endRecording());
sk_sp<SkPicture> parentWBWB(recorder.finishRecordingAsPicture());
REPORTER_ASSERT(reporter, parentWBWB->willPlayBackBitmaps()); // 2
}
}
@ -1161,14 +1160,14 @@ static void test_gen_id(skiatest::Reporter* reporter) {
SkPictureRecorder recorder;
recorder.beginRecording(0, 0);
SkAutoTUnref<SkPicture> empty(recorder.endRecording());
sk_sp<SkPicture> empty(recorder.finishRecordingAsPicture());
// Empty pictures should still have a valid ID
REPORTER_ASSERT(reporter, empty->uniqueID() != SK_InvalidGenID);
SkCanvas* canvas = recorder.beginRecording(1, 1);
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
REPORTER_ASSERT(reporter, hasData->uniqueID() != SK_InvalidGenID);
@ -1182,7 +1181,7 @@ static void test_typeface(skiatest::Reporter* reporter) {
SkPaint paint;
paint.setTypeface(SkTypeface::CreateFromName("Arial", SkTypeface::kItalic));
canvas->drawText("Q", 1, 0, 10, paint);
SkAutoTUnref<SkPicture> picture(recorder.endRecording());
sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
REPORTER_ASSERT(reporter, picture->hasText());
SkDynamicMemoryWStream stream;
picture->serialize(&stream);
@ -1234,7 +1233,7 @@ static void test_draw_bitmaps(SkCanvas* canvas) {
DEF_TEST(Picture_EmptyBitmap, r) {
SkPictureRecorder recorder;
test_draw_bitmaps(recorder.beginRecording(10, 10));
SkAutoTUnref<SkPicture> picture(recorder.endRecording());
sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
}
DEF_TEST(Canvas_EmptyBitmap, r) {
@ -1277,7 +1276,7 @@ DEF_TEST(DontOptimizeSaveLayerDrawDrawRestore, reporter) {
canvas->drawBitmap(redBM, 50, 50);
canvas->restore();
SkAutoTUnref<SkPicture> picture(recorder.endRecording());
sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
// Now replay the picture back on another canvas
// 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.
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);
@ -1352,7 +1351,7 @@ DEF_TEST(Picture_BitmapLeak, r) {
REPORTER_ASSERT(r, mut.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
// place it inside local braces.
@ -1360,7 +1359,7 @@ DEF_TEST(Picture_BitmapLeak, r) {
SkCanvas* canvas = rec.beginRecording(1920, 1200);
canvas->drawBitmap(mut, 0, 0);
canvas->drawBitmap(immut, 800, 600);
pic.reset(rec.endRecording());
pic = rec.finishRecordingAsPicture();
}
// 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());
// 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, immut.pixelRef()->unique());
}
@ -1380,7 +1379,7 @@ DEF_TEST(Picture_getRecordingCanvas, r) {
for (int i = 0; i < 3; i++) {
rec.beginRecording(100, 100);
REPORTER_ASSERT(r, rec.getRecordingCanvas());
rec.endRecording()->unref();
rec.finishRecordingAsPicture();
REPORTER_ASSERT(r, !rec.getRecordingCanvas());
}
}
@ -1401,12 +1400,12 @@ DEF_TEST(Picture_preserveCullRect, r) {
SkCanvas* c = recorder.beginRecording(SkRect::MakeLTRB(1, 2, 3, 4));
c->clear(SK_ColorCYAN);
SkAutoTUnref<SkPicture> picture(recorder.endRecording());
sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
SkDynamicMemoryWStream wstream;
picture->serialize(&wstream);
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->cullRect().left() == 1);

View File

@ -230,16 +230,16 @@ DEF_TEST(RecordOpts_MergeSvgOpacityAndFilterLayers, r) {
opaqueFilterLayerPaint.setColor(0xFF020202); // Opaque.
SkPaint translucentFilterLayerPaint;
translucentFilterLayerPaint.setColor(0x0F020202); // Not opaque.
SkAutoTUnref<SkPicture> shape;
sk_sp<SkPicture> shape;
{
SkPictureRecorder recorder;
SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(100), SkIntToScalar(100));
SkPaint shapePaint;
shapePaint.setColor(SK_ColorWHITE);
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;

View File

@ -33,7 +33,7 @@ private:
// Make sure the abort callback works
DEF_TEST(RecordReplaceDraw_Abort, r) {
SkAutoTUnref<const SkPicture> pic;
sk_sp<SkPicture> pic;
{
// Record two commands.
@ -43,14 +43,14 @@ DEF_TEST(RecordReplaceDraw_Abort, r) {
canvas->drawRect(SkRect::MakeWH(SkIntToScalar(kWidth), SkIntToScalar(kHeight)), SkPaint());
canvas->clipRect(SkRect::MakeWH(SkIntToScalar(kWidth), SkIntToScalar(kHeight)));
pic.reset(recorder.endRecording());
pic = recorder.finishRecordingAsPicture();
}
SkRecord rerecord;
SkRecorder canvas(&rerecord, kWidth, kHeight);
JustOneDraw callback;
GrRecordReplaceDraw(pic, &canvas, nullptr, SkMatrix::I(), &callback);
GrRecordReplaceDraw(pic.get(), &canvas, nullptr, SkMatrix::I(), &callback);
switch (rerecord.count()) {
case 3:
@ -68,7 +68,7 @@ DEF_TEST(RecordReplaceDraw_Abort, r) {
// Make sure GrRecordReplaceDraw balances unbalanced saves
DEF_TEST(RecordReplaceDraw_Unbalanced, r) {
SkAutoTUnref<const SkPicture> pic;
sk_sp<SkPicture> pic;
{
SkPictureRecorder recorder;
@ -77,13 +77,13 @@ DEF_TEST(RecordReplaceDraw_Unbalanced, r) {
// We won't balance this, but GrRecordReplaceDraw will for us.
canvas->save();
canvas->scale(2, 2);
pic.reset(recorder.endRecording());
pic = recorder.finishRecordingAsPicture();
}
SkRecord rerecord;
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)
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
void test_replacements(skiatest::Reporter* r, GrContext* context, bool doReplace) {
SkAutoTUnref<const SkPicture> pic;
sk_sp<SkPicture> pic;
{
SkPictureRecorder recorder;
@ -102,7 +102,7 @@ void test_replacements(skiatest::Reporter* r, GrContext* context, bool doReplace
canvas->restore();
canvas->drawRect(SkRect::MakeWH(SkIntToScalar(kWidth / 2), SkIntToScalar(kHeight / 2)),
SkPaint());
pic.reset(recorder.endRecording());
pic = recorder.finishRecordingAsPicture();
}
SkAutoTUnref<GrTexture> texture;
@ -131,7 +131,7 @@ void test_replacements(skiatest::Reporter* r, GrContext* context, bool doReplace
SkRecord rerecord;
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);
if (doReplace) {

View File

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

View File

@ -338,13 +338,13 @@ static void serialize_and_compare_typeface(SkTypeface* typeface, const char* tex
nullptr, 0);
canvas->drawColor(SK_ColorWHITE);
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.
SkDynamicMemoryWStream stream;
picture->serialize(&stream);
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.
SkBitmap origBitmap = draw_picture(*picture);
@ -529,7 +529,7 @@ DEF_TEST(Serialization, reporter) {
draw_something(recorder.beginRecording(SkIntToScalar(kBitmapSize),
SkIntToScalar(kBitmapSize),
nullptr, 0));
SkAutoTUnref<SkPicture> pict(recorder.endRecording());
sk_sp<SkPicture> pict(recorder.finishRecordingAsPicture());
// Serialize picture
SkWriteBuffer writer(SkWriteBuffer::kValidation_Flag);
@ -540,8 +540,7 @@ DEF_TEST(Serialization, reporter) {
// Deserialize picture
SkValidatingReadBuffer reader(static_cast<void*>(data.get()), size);
SkAutoTUnref<SkPicture> readPict(
SkPicture::CreateFromBuffer(reader));
sk_sp<SkPicture> readPict(SkPicture::MakeFromBuffer(reader));
REPORTER_ASSERT(reporter, readPict.get());
}
@ -551,11 +550,11 @@ DEF_TEST(Serialization, reporter) {
///////////////////////////////////////////////////////////////////////////////////////////////////
#include "SkAnnotation.h"
static SkPicture* copy_picture_via_serialization(SkPicture* src) {
static sk_sp<SkPicture> copy_picture_via_serialization(SkPicture* src) {
SkDynamicMemoryWStream wstream;
src->serialize(&wstream);
SkAutoTDelete<SkStreamAsset> rstream(wstream.detachAsStream());
return SkPicture::CreateFromStream(rstream);
return SkPicture::MakeFromStream(rstream);
}
struct AnnotationRec {
@ -622,8 +621,8 @@ DEF_TEST(Annotations, reporter) {
{ r2, SkAnnotationKeys::Link_Named_Dest_Key(), d2 },
};
SkAutoTUnref<SkPicture> pict0(recorder.endRecording());
SkAutoTUnref<SkPicture> pict1(copy_picture_via_serialization(pict0));
sk_sp<SkPicture> pict0(recorder.finishRecordingAsPicture());
sk_sp<SkPicture> pict1(copy_picture_via_serialization(pict0.get()));
TestAnnotationCanvas canvas(reporter, recs, SK_ARRAY_COUNT(recs));
canvas.drawPicture(pict1);

View File

@ -322,8 +322,8 @@ DEF_TEST(BitmapCache_discarded_image, reporter) {
SkPictureRecorder recorder;
SkCanvas* canvas = recorder.beginRecording(10, 10);
canvas->clear(SK_ColorCYAN);
sk_sp<SkPicture> picture(recorder.endRecording());
return SkImage::MakeFromPicture(picture, SkISize::Make(10, 10), nullptr, nullptr);
return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(),
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() {
SkPicture* pic = nullptr;
sk_sp<SkPicture> pic;
{
SkString d;
d.printf(" {%d, \"%s\"},", fDirNo, fFilename);
@ -399,7 +399,7 @@ void TestResult::testOne() {
wStream.write(&bytes[0], length);
wStream.flush();
}
pic = SkPicture::CreateFromStream(&stream);
pic = SkPicture::MakeFromStream(&stream);
if (!pic) {
SkDebugf("unable to decode %s\n", fFilename);
goto finish;
@ -436,7 +436,7 @@ void TestResult::testOne() {
if (scale >= 256) {
SkDebugf("unable to allocate bitmap for %s (w=%d h=%d) (sw=%d sh=%d)\n",
fFilename, pWidth, pHeight, dim.fX, dim.fY);
goto finish;
return;
}
SkCanvas skCanvas(bitmap);
drawPict(pic, &skCanvas, fScaleOversized ? scale : 1);
@ -450,11 +450,11 @@ void TestResult::testOne() {
if (!texture) {
SkDebugf("unable to allocate texture for %s (w=%d h=%d)\n", fFilename,
dim.fX, dim.fY);
goto finish;
return;
}
SkGpuDevice grDevice(context, texture.get());
SkCanvas grCanvas(&grDevice);
drawPict(pic, &grCanvas, fScaleOversized ? scale : 1);
drawPict(pic.get(), &grCanvas, fScaleOversized ? scale : 1);
SkBitmap grBitmap;
grBitmap.allocPixels(grCanvas.imageInfo());
@ -472,8 +472,6 @@ void TestResult::testOne() {
writePict(bitmap, outSkDir, pngName);
}
}
finish:
delete pic;
}
static SkString makeStatusString(int dirNo) {

View File

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

View File

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

View File

@ -90,7 +90,7 @@ int main(int argc, char** argv) {
for (SkString file; iter.next(&file); ) {
SkAutoTDelete<SkStream> stream =
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;
Sniffer sniff;

View File

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

View File

@ -104,33 +104,28 @@ public:
}
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,
// but helps to avoid a lot of pointless work if we're going to skip it.
if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) {
return false;
return nullptr;
}
SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path));
if (stream.get() == nullptr) {
SkDebugf("Could not read %s.\n", path);
return false;
return nullptr;
}
pic->reset(SkPicture::CreateFromStream(stream.get()));
if (pic->get() == nullptr) {
SkDebugf("Could not read %s as an SkPicture.\n", path);
return false;
}
return true;
return SkPicture::MakeFromStream(stream.get());
}
Benchmark* innerNext() {
// Render skps
while (fCurrentSKP < fSKPs.count()) {
const SkString& path = fSKPs[fCurrentSKP++];
SkAutoTUnref<SkPicture> pic;
if (!ReadPicture(path.c_str(), &pic)) {
auto pic = ReadPicture(path.c_str());
if (!pic) {
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_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));
SkPicture* pic = nullptr;
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,
@ -143,7 +142,7 @@ int tool_main(int argc, char** argv) {
SkDebugf("scraping %s %s\n", path, moduloStr.c_str());
}
SkAutoTUnref<SkPicture> pic(load_picture(path));
auto pic(load_picture(path));
if (pic.get()) {
SkAutoTUnref<SkLuaCanvas> canvas(
new SkLuaCanvas(SkScalarCeilToInt(pic->cullRect().width()),

View File

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

View File

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

View File

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

View File

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