Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(667)

Unified Diff: samplecode/SamplePictFile.cpp

Issue 214953003: split SkPictureRecorder out of SkPicture (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: update to ToT (again) Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: samplecode/SamplePictFile.cpp
===================================================================
--- samplecode/SamplePictFile.cpp (revision 14159)
+++ samplecode/SamplePictFile.cpp (working copy)
@@ -122,19 +122,19 @@
SkSize fTileSize;
SkPicture* LoadPicture(const char path[], BBoxType bbox) {
- SkPicture* pic = NULL;
+ SkAutoTUnref<SkPicture> pic;
SkBitmap bm;
if (SkImageDecoder::DecodeFile(path, &bm)) {
bm.setImmutable();
- pic = SkNEW(SkPicture);
- SkCanvas* can = pic->beginRecording(bm.width(), bm.height());
+ SkPictureRecorder recorder;
+ SkCanvas* can = recorder.beginRecording(bm.width(), bm.height());
can->drawBitmap(bm, 0, 0, NULL);
- pic->endRecording();
+ pic.reset(recorder.endRecording());
} else {
SkFILEStream stream(path);
if (stream.isValid()) {
- pic = SkPicture::CreateFromStream(&stream);
+ pic.reset(SkPicture::CreateFromStream(&stream));
} else {
SkDebugf("coun't load picture at \"path\"\n", path);
}
@@ -145,32 +145,30 @@
surf->unref();
}
if (false) { // re-record
- SkPicture p2;
- pic->draw(p2.beginRecording(pic->width(), pic->height()));
- p2.endRecording();
+ SkPictureRecorder recorder;
+ pic->draw(recorder.beginRecording(pic->width(), pic->height()));
+ SkAutoTUnref<SkPicture> p2(recorder.endRecording());
SkString path2(path);
path2.append(".new.skp");
SkFILEWStream writer(path2.c_str());
- p2.serialize(&writer);
+ p2->serialize(&writer);
}
}
- if (!pic) {
+ if (NULL == pic) {
return NULL;
}
- SkPicture* bboxPicture = NULL;
+ SkAutoTUnref<SkPictureFactory> factory;
switch (bbox) {
case kNo_BBoxType:
// no bbox playback necessary
- break;
+ return pic.detach();
case kRTree_BBoxType:
- bboxPicture = SkNEW(SkPicture);
break;
case kQuadTree_BBoxType:
- bboxPicture = SkNEW_ARGS(SkQuadTreePicture,
- (SkIRect::MakeWH(pic->width(), pic->height())));
+ factory.reset(SkNEW(SkQuadTreePictureFactory));
break;
case kTileGrid_BBoxType: {
SkASSERT(!fTileSize.isEmpty());
@@ -178,21 +176,17 @@
gridInfo.fMargin = SkISize::Make(0, 0);
gridInfo.fOffset = SkIPoint::Make(0, 0);
gridInfo.fTileInterval = fTileSize.toRound();
- bboxPicture = SkNEW_ARGS(SkTileGridPicture, (pic->width(), pic->height(), gridInfo));
- } break;
+ factory.reset(SkNEW_ARGS(SkTileGridPictureFactory, (gridInfo)));
+ break;
+ }
default:
SkASSERT(false);
}
- if (bboxPicture) {
- pic->draw(bboxPicture->beginRecording(pic->width(), pic->height(),
- SkPicture::kOptimizeForClippedPlayback_RecordingFlag));
- bboxPicture->endRecording();
- SkDELETE(pic);
- return bboxPicture;
- }
-
- return pic;
+ SkPictureRecorder recorder(factory);
+ pic->draw(recorder.beginRecording(pic->width(), pic->height(),
+ SkPicture::kOptimizeForClippedPlayback_RecordingFlag));
+ return recorder.endRecording();
}
typedef SampleView INHERITED;

Powered by Google App Engine
This is Rietveld 408576698