Factory methods for heap-allocated SkAnnotation objects.

This is part of an effort to ensure that all SkPaint effects can only be
allocated on the heap.

This patch makes the constructors of SkAnnotation non-public and instead
provides factory methods for creating these objects on the heap.

BUG=skia:2187
R=reed@google.com, mtklein@google.com, scroggo@google.com

Author: dominikg@chromium.org

Review URL: https://codereview.chromium.org/181703003

git-svn-id: http://skia.googlecode.com/svn/trunk@13605 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
commit-bot@chromium.org 2014-02-27 11:47:36 +00:00
parent 4472301607
commit d957984c1e
4 changed files with 15 additions and 6 deletions

View File

@ -24,18 +24,27 @@ struct SkPoint;
*/ */
class SkAnnotation : public SkRefCnt { class SkAnnotation : public SkRefCnt {
public: public:
SkAnnotation(const char key[], SkData* value);
virtual ~SkAnnotation(); virtual ~SkAnnotation();
static SkAnnotation* Create(const char key[], SkData* value) {
return SkNEW_ARGS(SkAnnotation, (key, value));
}
static SkAnnotation* Create(SkReadBuffer& buffer) {
return SkNEW_ARGS(SkAnnotation, (buffer));
}
/** /**
* Return the data for the specified key, or NULL. * Return the data for the specified key, or NULL.
*/ */
SkData* find(const char key[]) const; SkData* find(const char key[]) const;
SkAnnotation(SkReadBuffer&);
void writeToBuffer(SkWriteBuffer&) const; void writeToBuffer(SkWriteBuffer&) const;
private: private:
SkAnnotation(const char key[], SkData* value);
SkAnnotation(SkReadBuffer&);
SkString fKey; SkString fKey;
SkData* fData; SkData* fData;

View File

@ -56,7 +56,7 @@ const char* SkAnnotationKeys::Link_Named_Dest_Key() {
#include "SkCanvas.h" #include "SkCanvas.h"
static void annotate_paint(SkPaint& paint, const char* key, SkData* value) { static void annotate_paint(SkPaint& paint, const char* key, SkData* value) {
paint.setAnnotation(SkNEW_ARGS(SkAnnotation, (key, value)))->unref(); paint.setAnnotation(SkAnnotation::Create(key, value))->unref();
} }
void SkAnnotateRectWithURL(SkCanvas* canvas, const SkRect& rect, SkData* value) { void SkAnnotateRectWithURL(SkCanvas* canvas, const SkRect& rect, SkData* value) {

View File

@ -2128,7 +2128,7 @@ void SkPaint::unflatten(SkReadBuffer& buffer) {
SkSafeUnref(this->setImageFilter(buffer.readImageFilter())); SkSafeUnref(this->setImageFilter(buffer.readImageFilter()));
if (buffer.readBool()) { if (buffer.readBool()) {
this->setAnnotation(SkNEW_ARGS(SkAnnotation, (buffer)))->unref(); this->setAnnotation(SkAnnotation::Create(buffer))->unref();
} }
} else { } else {
this->setPathEffect(NULL); this->setPathEffect(NULL);
@ -2648,7 +2648,7 @@ void SkPaint::FlatteningTraits::Unflatten(SkReadBuffer& buffer, SkPaint* paint)
#undef F #undef F
#undef F_UNREF #undef F_UNREF
if (dirty & kAnnotation_DirtyBit) { if (dirty & kAnnotation_DirtyBit) {
paint->setAnnotation(SkNEW_ARGS(SkAnnotation, (buffer)))->unref(); paint->setAnnotation(SkAnnotation::Create(buffer))->unref();
} }
#ifdef SK_BUILD_FOR_ANDROID #ifdef SK_BUILD_FOR_ANDROID
if (dirty & kPaintOptionsAndroid_DirtyBit) { if (dirty & kPaintOptionsAndroid_DirtyBit) {

View File

@ -707,7 +707,7 @@ static void annotation_rp(SkCanvas*, SkReader32* reader, uint32_t op32,
const size_t size = DrawOp_unpackData(op32); const size_t size = DrawOp_unpackData(op32);
if (size > 0) { if (size > 0) {
SkReadBuffer buffer(reader->skip(size), size); SkReadBuffer buffer(reader->skip(size), size);
p->setAnnotation(SkNEW_ARGS(SkAnnotation, (buffer)))->unref(); p->setAnnotation(SkAnnotation::Create(buffer))->unref();
SkASSERT(buffer.offset() == size); SkASSERT(buffer.offset() == size);
} else { } else {
p->setAnnotation(NULL); p->setAnnotation(NULL);