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
diff --git a/samplecode/SampleAll.cpp b/samplecode/SampleAll.cpp
index 48ac24d..90fc5bd 100644
--- a/samplecode/SampleAll.cpp
+++ b/samplecode/SampleAll.cpp
@@ -305,7 +305,7 @@
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));
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp
index 7212223..05d6ce0 100644
--- a/samplecode/SampleApp.cpp
+++ b/samplecode/SampleApp.cpp
@@ -1389,7 +1389,7 @@
}
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 @@
}
if (fUsePicture) {
- SkAutoTUnref<const SkPicture> picture(fRecorder.endRecording());
+ sk_sp<SkPicture> picture(fRecorder.finishRecordingAsPicture());
// serialize/deserialize?
if (false) {
@@ -1406,9 +1406,9 @@
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
diff --git a/samplecode/SampleArc.cpp b/samplecode/SampleArc.cpp
index 3b5288d..f95833e 100644
--- a/samplecode/SampleArc.cpp
+++ b/samplecode/SampleArc.cpp
@@ -81,8 +81,8 @@
public:
SkRect fRect;
- MyDrawable* fAnimatingDrawable;
- SkDrawable* fRootDrawable;
+ sk_sp<MyDrawable> fAnimatingDrawable;
+ sk_sp<SkDrawable> fRootDrawable;
ArcsView() {
testparse();
@@ -91,16 +91,11 @@
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 @@
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 {
diff --git a/samplecode/SampleFilterFuzz.cpp b/samplecode/SampleFilterFuzz.cpp
index 81ea2ea..0dd01e9 100644
--- a/samplecode/SampleFilterFuzz.cpp
+++ b/samplecode/SampleFilterFuzz.cpp
@@ -712,7 +712,7 @@
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;
diff --git a/samplecode/SampleHT.cpp b/samplecode/SampleHT.cpp
index 099adcc..1989c3a 100644
--- a/samplecode/SampleHT.cpp
+++ b/samplecode/SampleHT.cpp
@@ -127,7 +127,7 @@
HTDrawable* fDrawable;
};
Rec fArray[N];
- SkAutoTUnref<SkDrawable> fRoot;
+ sk_sp<SkDrawable> fRoot;
SkMSec fTime;
HTView() {
@@ -140,7 +140,7 @@
canvas->drawDrawable(fArray[i].fDrawable);
fArray[i].fDrawable->unref();
}
- fRoot.reset(recorder.endRecordingAsDrawable());
+ fRoot = recorder.finishRecordingAsDrawable();
}
protected:
@@ -153,7 +153,7 @@
}
void onDrawContent(SkCanvas* canvas) override {
- canvas->drawDrawable(fRoot);
+ canvas->drawDrawable(fRoot.get());
}
bool onAnimate(const SkAnimTimer& timer) override {
diff --git a/samplecode/SamplePictFile.cpp b/samplecode/SamplePictFile.cpp
index 9203cba..ae10796 100644
--- a/samplecode/SamplePictFile.cpp
+++ b/samplecode/SamplePictFile.cpp
@@ -117,7 +117,7 @@
#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 @@
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 @@
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 @@
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 @@
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 @@
pic->playback(recorder.beginRecording(pic->cullRect().width(),
pic->cullRect().height(),
factory.get(), 0));
- return recorder.endRecording();
+ return recorder.finishRecordingAsPicture();
}
typedef SampleView INHERITED;
diff --git a/samplecode/SampleTiling.cpp b/samplecode/SampleTiling.cpp
index 125155e..62f055f 100644
--- a/samplecode/SampleTiling.cpp
+++ b/samplecode/SampleTiling.cpp
@@ -54,7 +54,7 @@
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 @@
if (textCanvas) {
SkASSERT(nullptr == fTextPicture);
- fTextPicture.reset(recorder.endRecording());
+ fTextPicture = recorder.finishRecordingAsPicture();
}
SkASSERT(fTextPicture);
- canvas->drawPicture(fTextPicture);
+ canvas->drawPicture(fTextPicture.get());
}
private: