Index: src/core/SkPaint.cpp |
diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp |
index 3dd87b7aa6f84b4f0214d8137061dda115907e34..9e53d19e2a31575a11879d84f3074567fe38e7f6 100644 |
--- a/src/core/SkPaint.cpp |
+++ b/src/core/SkPaint.cpp |
@@ -21,6 +21,7 @@ |
#include "SkReadBuffer.h" |
#include "SkWriteBuffer.h" |
#include "SkPaintDefaults.h" |
+#include "SkPaintOptionsAndroid.h" |
#include "SkPathEffect.h" |
#include "SkRasterizer.h" |
#include "SkScalar.h" |
@@ -54,6 +55,7 @@ enum { |
kImageFilter_DirtyBit = 1 << 13, |
kTypeface_DirtyBit = 1 << 14, |
kAnnotation_DirtyBit = 1 << 15, |
+ kPaintOptionsAndroid_DirtyBit = 1 << 16, |
}; |
// define this to get a printf for out-of-range parameter in setters |
@@ -99,6 +101,7 @@ SkPaint::SkPaint() { |
fDirtyBits = 0; |
#ifdef SK_BUILD_FOR_ANDROID |
+ new (&fPaintOptionsAndroid) SkPaintOptionsAndroid; |
fGenerationID = 0; |
#endif |
} |
@@ -128,6 +131,7 @@ SkPaint::SkPaint(const SkPaint& src) { |
COPY(fDirtyBits); |
#ifdef SK_BUILD_FOR_ANDROID |
+ new (&fPaintOptionsAndroid) SkPaintOptionsAndroid(src.fPaintOptionsAndroid); |
COPY(fGenerationID); |
#endif |
@@ -179,6 +183,8 @@ SkPaint& SkPaint::operator=(const SkPaint& src) { |
COPY(fDirtyBits); |
#ifdef SK_BUILD_FOR_ANDROID |
+ fPaintOptionsAndroid.~SkPaintOptionsAndroid(); |
+ new (&fPaintOptionsAndroid) SkPaintOptionsAndroid(src.fPaintOptionsAndroid); |
++fGenerationID; |
#endif |
@@ -208,6 +214,9 @@ bool operator==(const SkPaint& a, const SkPaint& b) { |
&& EQUAL(fWidth) |
&& EQUAL(fMiterLimit) |
&& EQUAL(fBitfieldsUInt) |
+#ifdef SK_BUILD_FOR_ANDROID |
+ && EQUAL(fPaintOptionsAndroid) |
+#endif |
; |
#undef EQUAL |
} |
@@ -232,6 +241,14 @@ uint32_t SkPaint::getGenerationID() const { |
void SkPaint::setGenerationID(uint32_t generationID) { |
fGenerationID = generationID; |
} |
+ |
+void SkPaint::setPaintOptionsAndroid(const SkPaintOptionsAndroid& options) { |
+ if (options != fPaintOptionsAndroid) { |
+ fPaintOptionsAndroid = options; |
+ GEN_ID_INC; |
+ fDirtyBits |= kPaintOptionsAndroid_DirtyBit; |
+ } |
+} |
#endif |
void SkPaint::setFilterLevel(FilterLevel level) { |
@@ -1826,6 +1843,14 @@ void SkPaint::descriptorProc(const SkDeviceProperties* deviceProperties, |
rec.fMaskFormat = SkMask::kA8_Format; // force antialiasing when we do the scan conversion |
} |
+#ifdef SK_BUILD_FOR_ANDROID |
+ char buffer[128]; |
+ SkWriteBuffer androidBuffer(buffer, sizeof(buffer)); |
+ fPaintOptionsAndroid.flatten(androidBuffer); |
+ descSize += androidBuffer.bytesWritten(); |
+ entryCount += 1; |
+#endif |
+ |
/////////////////////////////////////////////////////////////////////////// |
// Now that we're done tweaking the rec, call the PostMakeRec cleanup |
SkScalerContext::PostMakeRec(*this, &rec); |
@@ -1838,6 +1863,10 @@ void SkPaint::descriptorProc(const SkDeviceProperties* deviceProperties, |
desc->init(); |
desc->addEntry(kRec_SkDescriptorTag, sizeof(rec), &rec); |
+#ifdef SK_BUILD_FOR_ANDROID |
+ add_flattenable(desc, kAndroidOpts_SkDescriptorTag, &androidBuffer); |
+#endif |
+ |
if (pe) { |
add_flattenable(desc, kPathEffect_SkDescriptorTag, &peBuffer); |
} |
@@ -1872,6 +1901,11 @@ void SkPaint::descriptorProc(const SkDeviceProperties* deviceProperties, |
desc1->addEntry(kRec_SkDescriptorTag, sizeof(rec), &rec); |
desc2->addEntry(kRec_SkDescriptorTag, sizeof(rec), &rec); |
+#ifdef SK_BUILD_FOR_ANDROID |
+ add_flattenable(desc1, kAndroidOpts_SkDescriptorTag, &androidBuffer); |
+ add_flattenable(desc2, kAndroidOpts_SkDescriptorTag, &androidBuffer); |
+#endif |
+ |
if (pe) { |
add_flattenable(desc1, kPathEffect_SkDescriptorTag, &peBuffer); |
add_flattenable(desc2, kPathEffect_SkDescriptorTag, &peBuffer); |
@@ -2088,6 +2122,11 @@ void SkPaint::flatten(SkWriteBuffer& buffer) const { |
asint(this->getImageFilter())) { |
flatFlags |= kHasEffects_FlatFlag; |
} |
+#ifdef SK_BUILD_FOR_ANDROID |
+ if (this->getPaintOptionsAndroid() != SkPaintOptionsAndroid()) { |
+ flatFlags |= kHasNonDefaultPaintOptionsAndroid_FlatFlag; |
+ } |
+#endif |
SkASSERT(SkAlign4(kPODPaintSize) == kPODPaintSize); |
uint32_t* ptr = buffer.reserve(kPODPaintSize); |
@@ -2126,6 +2165,11 @@ void SkPaint::flatten(SkWriteBuffer& buffer) const { |
buffer.writeBool(false); |
} |
} |
+#ifdef SK_BUILD_FOR_ANDROID |
+ if (flatFlags & kHasNonDefaultPaintOptionsAndroid_FlatFlag) { |
+ this->getPaintOptionsAndroid().flatten(buffer); |
+ } |
+#endif |
} |
void SkPaint::unflatten(SkReadBuffer& buffer) { |
@@ -2184,12 +2228,15 @@ void SkPaint::unflatten(SkReadBuffer& buffer) { |
this->setImageFilter(NULL); |
} |
- if (buffer.isVersionLT(SkReadBuffer::kRemoveAndroidPaintOpts_Version) && |
- flatFlags & kHasNonDefaultPaintOptionsAndroid_FlatFlag) { |
- SkString tag; |
- buffer.readUInt(); |
- buffer.readString(&tag); |
- buffer.readBool(); |
+#ifdef SK_BUILD_FOR_ANDROID |
+ this->setPaintOptionsAndroid(SkPaintOptionsAndroid()); |
+#endif |
+ if (flatFlags & kHasNonDefaultPaintOptionsAndroid_FlatFlag) { |
+ SkPaintOptionsAndroid options; |
+ options.unflatten(buffer); |
+#ifdef SK_BUILD_FOR_ANDROID |
+ this->setPaintOptionsAndroid(options); |
+#endif |
} |
} |
@@ -2648,6 +2695,9 @@ void SkPaint::FlatteningTraits::Flatten(SkWriteBuffer& buffer, const SkPaint& pa |
#undef F |
if (dirty & kTypeface_DirtyBit) buffer.writeTypeface(paint.getTypeface()); |
if (dirty & kAnnotation_DirtyBit) paint.getAnnotation()->writeToBuffer(buffer); |
+#ifdef SK_BUILD_FOR_ANDROID |
+ if (dirty & kPaintOptionsAndroid_DirtyBit) paint.getPaintOptionsAndroid().flatten(buffer); |
+#endif |
} |
void SkPaint::FlatteningTraits::Unflatten(SkReadBuffer& buffer, SkPaint* paint) { |
@@ -2682,5 +2732,12 @@ void SkPaint::FlatteningTraits::Unflatten(SkReadBuffer& buffer, SkPaint* paint) |
if (dirty & kAnnotation_DirtyBit) { |
paint->setAnnotation(SkAnnotation::Create(buffer))->unref(); |
} |
+#ifdef SK_BUILD_FOR_ANDROID |
+ if (dirty & kPaintOptionsAndroid_DirtyBit) { |
+ SkPaintOptionsAndroid options; |
+ options.unflatten(buffer); |
+ paint->setPaintOptionsAndroid(options); |
+ } |
+#endif |
SkASSERT(dirty == paint->fDirtyBits); |
} |