diff options
author | Mike Klein <mtklein@google.com> | 2014-06-23 13:29:10 -0400 |
---|---|---|
committer | Mike Klein <mtklein@google.com> | 2014-06-23 13:29:10 -0400 |
commit | f22b6b5883943d7127cd3f77fed822fa65642f1a (patch) | |
tree | 76a05cc2d8c3672e533c6c897471e633d8a78888 /src/core | |
parent | b0203e5b223b3c2381c209898358bdc3e2131ec9 (diff) |
Use smart pointers to make SkPictureRecorder lifetimes less manual.
BUG=skia:
R=robertphillips@google.com
Review URL: https://codereview.chromium.org/344253005
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkPictureRecorder.cpp | 45 |
1 files changed, 17 insertions, 28 deletions
diff --git a/src/core/SkPictureRecorder.cpp b/src/core/SkPictureRecorder.cpp index f1423e3992..d0ce0a1383 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); } } |