aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkPaint.cpp
diff options
context:
space:
mode:
authorGravatar Derek Sollenberger <djsollen@google.com>2014-08-06 16:34:40 -0400
committerGravatar Derek Sollenberger <djsollen@google.com>2014-08-06 16:34:40 -0400
commitda7a944e293d27ec5c7be06b224921ae0058d35a (patch)
tree70a6553ab4cc08b0a862e7f68f4510c3d73c06c7 /src/core/SkPaint.cpp
parentc7f069b50184cf786b46e20e3ba8431d8c82472a (diff)
Revert "Remove SkPaintOptionsAndroid"
Diffstat (limited to 'src/core/SkPaint.cpp')
-rw-r--r--src/core/SkPaint.cpp69
1 files changed, 63 insertions, 6 deletions
diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp
index 3dd87b7aa6..9e53d19e2a 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);
}