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

Unified Diff: src/core/SkPictureRecorder.cpp

Issue 344253005: Use smart pointers to make SkPictureRecorder lifetimes less manual. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: record Created 6 years, 6 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
« no previous file with comments | « include/core/SkPictureRecorder.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkPictureRecorder.cpp
diff --git a/src/core/SkPictureRecorder.cpp b/src/core/SkPictureRecorder.cpp
index f1423e3992e35bae425ef4d9c0fe38f3dafb0bce..d0ce0a13834ac2be349e609e486707f35e72da67 100644
--- a/src/core/SkPictureRecorder.cpp
+++ b/src/core/SkPictureRecorder.cpp
@@ -14,21 +14,13 @@
#include "SkRecorder.h"
#include "SkTypes.h"
-SkPictureRecorder::~SkPictureRecorder() {
- this->reset();
-}
+SkPictureRecorder::SkPictureRecorder() {}
-void SkPictureRecorder::reset() {
- SkSafeSetNull(fPictureRecord);
- SkSafeSetNull(fRecorder);
- SkDELETE(fRecord);
- fRecord = NULL;
-}
+SkPictureRecorder::~SkPictureRecorder() {}
SkCanvas* SkPictureRecorder::beginRecording(int width, int height,
SkBBHFactory* bbhFactory /* = NULL */,
uint32_t recordFlags /* = 0 */) {
- this->reset(); // terminate any prior recording(s)
fWidth = width;
fHeight = height;
@@ -37,9 +29,9 @@ SkCanvas* SkPictureRecorder::beginRecording(int width, int height,
if (NULL != bbhFactory) {
SkAutoTUnref<SkBBoxHierarchy> tree((*bbhFactory)(width, height));
SkASSERT(NULL != tree);
- fPictureRecord = SkNEW_ARGS(SkBBoxHierarchyRecord, (size, recordFlags, tree.get()));
+ fPictureRecord.reset(SkNEW_ARGS(SkBBoxHierarchyRecord, (size, recordFlags, tree.get())));
} else {
- fPictureRecord = SkNEW_ARGS(SkPictureRecord, (size, recordFlags));
+ fPictureRecord.reset(SkNEW_ARGS(SkPictureRecord, (size, recordFlags)));
}
fPictureRecord->beginRecording();
@@ -48,43 +40,40 @@ SkCanvas* SkPictureRecorder::beginRecording(int width, int height,
SkCanvas* SkPictureRecorder::EXPERIMENTAL_beginRecording(int width, int height,
SkBBHFactory* bbhFactory /* = NULL */) {
- this->reset();
fWidth = width;
fHeight = height;
// TODO: plumb bbhFactory through
- fRecord = SkNEW(SkRecord);
- fRecorder = SkNEW_ARGS(SkRecorder, (fRecord, width, height));
+ fRecord.reset(SkNEW(SkRecord));
+ fRecorder.reset(SkNEW_ARGS(SkRecorder, (fRecord.get(), width, height)));
return this->getRecordingCanvas();
}
SkCanvas* SkPictureRecorder::getRecordingCanvas() {
- if (NULL != fRecorder) {
- return fRecorder;
+ if (NULL != fRecorder.get()) {
+ return fRecorder.get();
}
- return fPictureRecord;
+ return fPictureRecord.get();
}
SkPicture* SkPictureRecorder::endRecording() {
SkPicture* picture = NULL;
- if (NULL != fRecorder) {
- // TODO: picture = SkNEW_ARGS(SkPicture, (fWidth, fHeight, fRecord));
- // fRecord = NULL;
+ if (NULL != fRecord.get()) {
+ // TODO: picture = SkNEW_ARGS(SkPicture, (fWidth, fHeight, fRecord.detach()));
}
- if (NULL != fPictureRecord) {
+ if (NULL != fPictureRecord.get()) {
fPictureRecord->endRecording();
const bool deepCopyOps = false;
- picture = SkNEW_ARGS(SkPicture, (fWidth, fHeight, *fPictureRecord, deepCopyOps));
+ picture = SkNEW_ARGS(SkPicture, (fWidth, fHeight, *fPictureRecord.get(), deepCopyOps));
}
- this->reset();
return picture;
}
void SkPictureRecorder::internalOnly_EnableOpts(bool enableOpts) {
- if (NULL != fPictureRecord) {
+ if (NULL != fPictureRecord.get()) {
fPictureRecord->internalOnly_EnableOpts(enableOpts);
}
}
@@ -94,13 +83,13 @@ void SkPictureRecorder::partialReplay(SkCanvas* canvas) const {
return;
}
- if (NULL != fRecorder) {
+ if (NULL != fRecord.get()) {
SkRecordDraw(*fRecord, canvas);
}
- if (NULL != fPictureRecord) {
+ if (NULL != fPictureRecord.get()) {
const bool deepCopyOps = true;
- SkPicture picture(fWidth, fHeight, *fPictureRecord, deepCopyOps);
+ SkPicture picture(fWidth, fHeight, *fPictureRecord.get(), deepCopyOps);
picture.draw(canvas);
}
}
« no previous file with comments | « include/core/SkPictureRecorder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698