change SkAnnotation to not inherit from SkFlattenable (does not need dynamic factories)
BUG=
R=scroggo@google.com
Review URL: https://codereview.chromium.org/26606004
git-svn-id: http://skia.googlecode.com/svn/trunk/src@11762 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/core/SkAnnotation.cpp b/core/SkAnnotation.cpp
index 1230cb4..f32164c 100644
--- a/core/SkAnnotation.cpp
+++ b/core/SkAnnotation.cpp
@@ -30,13 +30,13 @@
return fKey.equals(key) ? fData : NULL;
}
-SkAnnotation::SkAnnotation(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {
+SkAnnotation::SkAnnotation(SkFlattenableReadBuffer& buffer) {
fFlags = buffer.readUInt();
buffer.readString(&fKey);
fData = buffer.readByteArrayAsData();
}
-void SkAnnotation::flatten(SkFlattenableWriteBuffer& buffer) const {
+void SkAnnotation::writeToBuffer(SkFlattenableWriteBuffer& buffer) const {
buffer.writeUInt(fFlags);
buffer.writeString(fKey.c_str());
buffer.writeDataAsByteArray(fData);
diff --git a/core/SkPaint.cpp b/core/SkPaint.cpp
index ea99ede..4e186ac 100644
--- a/core/SkPaint.cpp
+++ b/core/SkPaint.cpp
@@ -2099,7 +2099,13 @@
buffer.writeFlattenable(this->getRasterizer());
buffer.writeFlattenable(this->getLooper());
buffer.writeFlattenable(this->getImageFilter());
- buffer.writeFlattenable(this->getAnnotation());
+
+ if (fAnnotation) {
+ buffer.writeBool(true);
+ fAnnotation->writeToBuffer(buffer);
+ } else {
+ buffer.writeBool(false);
+ }
}
#ifdef SK_BUILD_FOR_ANDROID
if (flatFlags & kHasNonDefaultPaintOptionsAndroid_FlatFlag) {
@@ -2180,7 +2186,10 @@
SkSafeUnref(this->setRasterizer(buffer.readFlattenableT<SkRasterizer>()));
SkSafeUnref(this->setLooper(buffer.readFlattenableT<SkDrawLooper>()));
SkSafeUnref(this->setImageFilter(buffer.readFlattenableT<SkImageFilter>()));
- SkSafeUnref(this->setAnnotation(buffer.readFlattenableT<SkAnnotation>()));
+
+ if (buffer.readBool()) {
+ this->setAnnotation(SkNEW_ARGS(SkAnnotation, (buffer)))->unref();
+ }
} else {
this->setPathEffect(NULL);
this->setShader(NULL);
diff --git a/pipe/SkGPipePriv.h b/pipe/SkGPipePriv.h
index 0d25b5a..2954ebf 100644
--- a/pipe/SkGPipePriv.h
+++ b/pipe/SkGPipePriv.h
@@ -25,9 +25,8 @@
kShader_PaintFlat,
kImageFilter_PaintFlat,
kXfermode_PaintFlat,
- kAnnotation_PaintFlat,
- kLast_PaintFlat = kAnnotation_PaintFlat
+ kLast_PaintFlat = kXfermode_PaintFlat
};
#define kCount_PaintFlats (kLast_PaintFlat + 1)
@@ -70,6 +69,7 @@
kPaintOp_DrawOp,
kSetTypeface_DrawOp,
+ kSetAnnotation_DrawOp,
kDef_Typeface_DrawOp,
kDef_Flattenable_DrawOp,
@@ -226,7 +226,7 @@
kJoin_PaintOp, // arg inline
kCap_PaintOp, // arg inline
kWidth_PaintOp, // arg scalar
- kMiter_PaintOp,// arg scalar
+ kMiter_PaintOp, // arg scalar
kEncoding_PaintOp, // arg inline - text
kHinting_PaintOp, // arg inline - text
@@ -236,6 +236,8 @@
kTextSkewX_PaintOp, // arg scalar - text
kTypeface_PaintOp, // arg inline (index) - text
+ kAnnotation_PaintOp,// arg SkAnnotation_flat, data=bool-has-size
+
kFlatIndex_PaintOp, // flags=paintflat, data=index
};
diff --git a/pipe/SkGPipeRead.cpp b/pipe/SkGPipeRead.cpp
index a5f7144..6275469 100644
--- a/pipe/SkGPipeRead.cpp
+++ b/pipe/SkGPipeRead.cpp
@@ -15,6 +15,7 @@
#include "SkReader32.h"
#include "SkStream.h"
+#include "SkAnnotation.h"
#include "SkColorFilter.h"
#include "SkDrawLooper.h"
#include "SkMaskFilter.h"
@@ -53,9 +54,6 @@
case kXfermode_PaintFlat:
paint->setXfermode((SkXfermode*)obj);
break;
- case kAnnotation_PaintFlat:
- paint->setAnnotation((SkAnnotation*)obj);
- break;
default:
SkDEBUGFAIL("never gets here");
}
@@ -672,6 +670,22 @@
p->setTypeface(static_cast<SkTypeface*>(reader->readPtr()));
}
+static void annotation_rp(SkCanvas*, SkReader32* reader, uint32_t op32,
+ SkGPipeState* state) {
+ SkPaint* p = state->editPaint();
+
+ if (SkToBool(PaintOp_unpackData(op32))) {
+ const size_t size = reader->readU32();
+ SkAutoMalloc storage(size);
+
+ reader->read(storage.get(), size);
+ SkOrderedReadBuffer buffer(storage.get(), size);
+ p->setAnnotation(SkNEW_ARGS(SkAnnotation, (buffer)))->unref();
+ } else {
+ p->setAnnotation(NULL);
+ }
+}
+
///////////////////////////////////////////////////////////////////////////////
static void def_Typeface_rp(SkCanvas*, SkReader32*, uint32_t, SkGPipeState* state) {
@@ -755,6 +769,8 @@
paintOp_rp,
typeface_rp,
+ annotation_rp,
+
def_Typeface_rp,
def_PaintFlat_rp,
def_Bitmap_rp,
diff --git a/pipe/SkGPipeWrite.cpp b/pipe/SkGPipeWrite.cpp
index 58ba102..05fbb48 100644
--- a/pipe/SkGPipeWrite.cpp
+++ b/pipe/SkGPipeWrite.cpp
@@ -48,7 +48,6 @@
case kShader_PaintFlat: return paint.getShader();
case kImageFilter_PaintFlat: return paint.getImageFilter();
case kXfermode_PaintFlat: return paint.getXfermode();
- case kAnnotation_PaintFlat: return paint.getAnnotation();
}
SkDEBUGFAIL("never gets here");
return NULL;
@@ -1123,6 +1122,26 @@
// SkDebugf("[%d] %08X\n", i, storage[i]);
}
}
+
+ //
+ // Do these after we've written kPaintOp_DrawOp
+
+ if (base.getAnnotation() != paint.getAnnotation()) {
+ if (NULL == paint.getAnnotation()) {
+ this->writeOp(kSetAnnotation_DrawOp, 0, 0);
+ } else {
+ SkOrderedWriteBuffer buffer(1024);
+ paint.getAnnotation()->writeToBuffer(buffer);
+ size = buffer.bytesWritten();
+
+ SkAutoMalloc storage(size);
+ buffer.writeToMemory(storage.get());
+
+ this->writeOp(kSetAnnotation_DrawOp, 0, 1);
+ fWriter.write32(size);
+ fWriter.write(storage.get(), size);
+ }
+ }
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/ports/SkGlobalInitialization_default.cpp b/ports/SkGlobalInitialization_default.cpp
index ab39d3c..82c9680 100644
--- a/ports/SkGlobalInitialization_default.cpp
+++ b/ports/SkGlobalInitialization_default.cpp
@@ -62,7 +62,6 @@
void SkFlattenable::InitializeFlattenables() {
- SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkAnnotation)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkAvoidXfermode)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBicubicImageFilter)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBitmapProcShader)