Use smart pointers to make SkPictureRecorder lifetimes less manual.
BUG=skia: R=robertphillips@google.com Review URL: https://codereview.chromium.org/344253005
This commit is contained in:
parent
b0203e5b22
commit
f22b6b5883
@ -25,7 +25,7 @@ class SkRecorder;
|
||||
|
||||
class SK_API SkPictureRecorder : SkNoncopyable {
|
||||
public:
|
||||
SkPictureRecorder() : fPictureRecord(NULL), fRecorder(NULL), fRecord(NULL) { }
|
||||
SkPictureRecorder();
|
||||
~SkPictureRecorder();
|
||||
|
||||
/** Returns the canvas that records the drawing commands.
|
||||
@ -77,15 +77,15 @@ private:
|
||||
friend class SkPictureRecorderReplayTester; // for unit testing
|
||||
void partialReplay(SkCanvas* canvas) const;
|
||||
|
||||
int fWidth;
|
||||
int fHeight;
|
||||
int fWidth;
|
||||
int fHeight;
|
||||
|
||||
// Both ref counted. One of these two will be non-null:
|
||||
SkPictureRecord* fPictureRecord; // beginRecording()
|
||||
SkRecorder* fRecorder; // EXPERIMENTAL_beginRecording()
|
||||
// One of these two canvases will be non-NULL.
|
||||
SkAutoTUnref<SkPictureRecord> fPictureRecord; // beginRecording()
|
||||
SkAutoTUnref<SkRecorder> fRecorder; // EXPERIMENTAL_beginRecording()
|
||||
|
||||
// Not refcounted. Used by EXPERIMENTAL_beginRecording().
|
||||
SkRecord* fRecord;
|
||||
// Used by EXPERIMENTAL_beginRecording().
|
||||
SkAutoTDelete<SkRecord> fRecord;
|
||||
|
||||
typedef SkNoncopyable INHERITED;
|
||||
};
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user