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 {
|
class SK_API SkPictureRecorder : SkNoncopyable {
|
||||||
public:
|
public:
|
||||||
SkPictureRecorder() : fPictureRecord(NULL), fRecorder(NULL), fRecord(NULL) { }
|
SkPictureRecorder();
|
||||||
~SkPictureRecorder();
|
~SkPictureRecorder();
|
||||||
|
|
||||||
/** Returns the canvas that records the drawing commands.
|
/** Returns the canvas that records the drawing commands.
|
||||||
@ -77,15 +77,15 @@ private:
|
|||||||
friend class SkPictureRecorderReplayTester; // for unit testing
|
friend class SkPictureRecorderReplayTester; // for unit testing
|
||||||
void partialReplay(SkCanvas* canvas) const;
|
void partialReplay(SkCanvas* canvas) const;
|
||||||
|
|
||||||
int fWidth;
|
int fWidth;
|
||||||
int fHeight;
|
int fHeight;
|
||||||
|
|
||||||
// Both ref counted. One of these two will be non-null:
|
// One of these two canvases will be non-NULL.
|
||||||
SkPictureRecord* fPictureRecord; // beginRecording()
|
SkAutoTUnref<SkPictureRecord> fPictureRecord; // beginRecording()
|
||||||
SkRecorder* fRecorder; // EXPERIMENTAL_beginRecording()
|
SkAutoTUnref<SkRecorder> fRecorder; // EXPERIMENTAL_beginRecording()
|
||||||
|
|
||||||
// Not refcounted. Used by EXPERIMENTAL_beginRecording().
|
// Used by EXPERIMENTAL_beginRecording().
|
||||||
SkRecord* fRecord;
|
SkAutoTDelete<SkRecord> fRecord;
|
||||||
|
|
||||||
typedef SkNoncopyable INHERITED;
|
typedef SkNoncopyable INHERITED;
|
||||||
};
|
};
|
||||||
|
@ -14,21 +14,13 @@
|
|||||||
#include "SkRecorder.h"
|
#include "SkRecorder.h"
|
||||||
#include "SkTypes.h"
|
#include "SkTypes.h"
|
||||||
|
|
||||||
SkPictureRecorder::~SkPictureRecorder() {
|
SkPictureRecorder::SkPictureRecorder() {}
|
||||||
this->reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SkPictureRecorder::reset() {
|
SkPictureRecorder::~SkPictureRecorder() {}
|
||||||
SkSafeSetNull(fPictureRecord);
|
|
||||||
SkSafeSetNull(fRecorder);
|
|
||||||
SkDELETE(fRecord);
|
|
||||||
fRecord = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
SkCanvas* SkPictureRecorder::beginRecording(int width, int height,
|
SkCanvas* SkPictureRecorder::beginRecording(int width, int height,
|
||||||
SkBBHFactory* bbhFactory /* = NULL */,
|
SkBBHFactory* bbhFactory /* = NULL */,
|
||||||
uint32_t recordFlags /* = 0 */) {
|
uint32_t recordFlags /* = 0 */) {
|
||||||
this->reset(); // terminate any prior recording(s)
|
|
||||||
fWidth = width;
|
fWidth = width;
|
||||||
fHeight = height;
|
fHeight = height;
|
||||||
|
|
||||||
@ -37,9 +29,9 @@ SkCanvas* SkPictureRecorder::beginRecording(int width, int height,
|
|||||||
if (NULL != bbhFactory) {
|
if (NULL != bbhFactory) {
|
||||||
SkAutoTUnref<SkBBoxHierarchy> tree((*bbhFactory)(width, height));
|
SkAutoTUnref<SkBBoxHierarchy> tree((*bbhFactory)(width, height));
|
||||||
SkASSERT(NULL != tree);
|
SkASSERT(NULL != tree);
|
||||||
fPictureRecord = SkNEW_ARGS(SkBBoxHierarchyRecord, (size, recordFlags, tree.get()));
|
fPictureRecord.reset(SkNEW_ARGS(SkBBoxHierarchyRecord, (size, recordFlags, tree.get())));
|
||||||
} else {
|
} else {
|
||||||
fPictureRecord = SkNEW_ARGS(SkPictureRecord, (size, recordFlags));
|
fPictureRecord.reset(SkNEW_ARGS(SkPictureRecord, (size, recordFlags)));
|
||||||
}
|
}
|
||||||
|
|
||||||
fPictureRecord->beginRecording();
|
fPictureRecord->beginRecording();
|
||||||
@ -48,43 +40,40 @@ SkCanvas* SkPictureRecorder::beginRecording(int width, int height,
|
|||||||
|
|
||||||
SkCanvas* SkPictureRecorder::EXPERIMENTAL_beginRecording(int width, int height,
|
SkCanvas* SkPictureRecorder::EXPERIMENTAL_beginRecording(int width, int height,
|
||||||
SkBBHFactory* bbhFactory /* = NULL */) {
|
SkBBHFactory* bbhFactory /* = NULL */) {
|
||||||
this->reset();
|
|
||||||
fWidth = width;
|
fWidth = width;
|
||||||
fHeight = height;
|
fHeight = height;
|
||||||
|
|
||||||
// TODO: plumb bbhFactory through
|
// TODO: plumb bbhFactory through
|
||||||
fRecord = SkNEW(SkRecord);
|
fRecord.reset(SkNEW(SkRecord));
|
||||||
fRecorder = SkNEW_ARGS(SkRecorder, (fRecord, width, height));
|
fRecorder.reset(SkNEW_ARGS(SkRecorder, (fRecord.get(), width, height)));
|
||||||
return this->getRecordingCanvas();
|
return this->getRecordingCanvas();
|
||||||
}
|
}
|
||||||
|
|
||||||
SkCanvas* SkPictureRecorder::getRecordingCanvas() {
|
SkCanvas* SkPictureRecorder::getRecordingCanvas() {
|
||||||
if (NULL != fRecorder) {
|
if (NULL != fRecorder.get()) {
|
||||||
return fRecorder;
|
return fRecorder.get();
|
||||||
}
|
}
|
||||||
return fPictureRecord;
|
return fPictureRecord.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
SkPicture* SkPictureRecorder::endRecording() {
|
SkPicture* SkPictureRecorder::endRecording() {
|
||||||
SkPicture* picture = NULL;
|
SkPicture* picture = NULL;
|
||||||
|
|
||||||
if (NULL != fRecorder) {
|
if (NULL != fRecord.get()) {
|
||||||
// TODO: picture = SkNEW_ARGS(SkPicture, (fWidth, fHeight, fRecord));
|
// TODO: picture = SkNEW_ARGS(SkPicture, (fWidth, fHeight, fRecord.detach()));
|
||||||
// fRecord = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NULL != fPictureRecord) {
|
if (NULL != fPictureRecord.get()) {
|
||||||
fPictureRecord->endRecording();
|
fPictureRecord->endRecording();
|
||||||
const bool deepCopyOps = false;
|
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;
|
return picture;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkPictureRecorder::internalOnly_EnableOpts(bool enableOpts) {
|
void SkPictureRecorder::internalOnly_EnableOpts(bool enableOpts) {
|
||||||
if (NULL != fPictureRecord) {
|
if (NULL != fPictureRecord.get()) {
|
||||||
fPictureRecord->internalOnly_EnableOpts(enableOpts);
|
fPictureRecord->internalOnly_EnableOpts(enableOpts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -94,13 +83,13 @@ void SkPictureRecorder::partialReplay(SkCanvas* canvas) const {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NULL != fRecorder) {
|
if (NULL != fRecord.get()) {
|
||||||
SkRecordDraw(*fRecord, canvas);
|
SkRecordDraw(*fRecord, canvas);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NULL != fPictureRecord) {
|
if (NULL != fPictureRecord.get()) {
|
||||||
const bool deepCopyOps = true;
|
const bool deepCopyOps = true;
|
||||||
SkPicture picture(fWidth, fHeight, *fPictureRecord, deepCopyOps);
|
SkPicture picture(fWidth, fHeight, *fPictureRecord.get(), deepCopyOps);
|
||||||
picture.draw(canvas);
|
picture.draw(canvas);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user