aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/SkPaint.cpp69
-rw-r--r--src/core/SkPaintOptionsAndroid.cpp43
-rw-r--r--src/core/SkScalerContext.cpp13
-rw-r--r--src/core/SkScalerContext.h11
4 files changed, 130 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);
}
diff --git a/src/core/SkPaintOptionsAndroid.cpp b/src/core/SkPaintOptionsAndroid.cpp
new file mode 100644
index 0000000000..df71ca87a4
--- /dev/null
+++ b/src/core/SkPaintOptionsAndroid.cpp
@@ -0,0 +1,43 @@
+
+/*
+ * Copyright 2012 The Android Open Source Project
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkPaintOptionsAndroid.h"
+#include "SkReadBuffer.h"
+#include "SkWriteBuffer.h"
+#include "SkTDict.h"
+#include "SkThread.h"
+#include <cstring>
+
+SkLanguage SkLanguage::getParent() const {
+ SkASSERT(!fTag.isEmpty());
+ const char* tag = fTag.c_str();
+
+ // strip off the rightmost "-.*"
+ const char* parentTagEnd = strrchr(tag, '-');
+ if (parentTagEnd == NULL) {
+ return SkLanguage();
+ }
+ size_t parentTagLen = parentTagEnd - tag;
+ return SkLanguage(tag, parentTagLen);
+}
+
+void SkPaintOptionsAndroid::flatten(SkWriteBuffer& buffer) const {
+ buffer.writeUInt(fFontVariant);
+ buffer.writeString(fLanguage.getTag().c_str());
+ // to maintain picture compatibility for the old fUseFontFallbacks variable
+ buffer.writeBool(false);
+}
+
+void SkPaintOptionsAndroid::unflatten(SkReadBuffer& buffer) {
+ fFontVariant = (FontVariant)buffer.readUInt();
+ SkString tag;
+ buffer.readString(&tag);
+ fLanguage = SkLanguage(tag);
+ // to maintain picture compatibility for the old fUseFontFallbacks variable
+ buffer.readBool();
+}
diff --git a/src/core/SkScalerContext.cpp b/src/core/SkScalerContext.cpp
index db3c0fb2f5..11208fec59 100644
--- a/src/core/SkScalerContext.cpp
+++ b/src/core/SkScalerContext.cpp
@@ -23,6 +23,10 @@
#include "SkStroke.h"
#include "SkThread.h"
+#ifdef SK_BUILD_FOR_ANDROID
+ #include "SkTypeface_android.h"
+#endif
+
#define ComputeBWRowBytes(width) (((unsigned)(width) + 7) >> 3)
void SkGlyph::toMask(SkMask* mask) const {
@@ -107,6 +111,15 @@ SkScalerContext::SkScalerContext(SkTypeface* typeface, const SkDescriptor* desc)
desc->findEntry(kPathEffect_SkDescriptorTag, NULL),
desc->findEntry(kMaskFilter_SkDescriptorTag, NULL));
#endif
+#ifdef SK_BUILD_FOR_ANDROID
+ uint32_t len;
+ const void* data = desc->findEntry(kAndroidOpts_SkDescriptorTag, &len);
+ if (data) {
+ SkReadBuffer buffer(data, len);
+ fPaintOptionsAndroid.unflatten(buffer);
+ SkASSERT(buffer.offset() == buffer.size());
+ }
+#endif
}
SkScalerContext::~SkScalerContext() {
diff --git a/src/core/SkScalerContext.h b/src/core/SkScalerContext.h
index 609e9dd673..43b5ebfaf6 100644
--- a/src/core/SkScalerContext.h
+++ b/src/core/SkScalerContext.h
@@ -14,6 +14,10 @@
#include "SkPaint.h"
#include "SkTypeface.h"
+#ifdef SK_BUILD_FOR_ANDROID
+ #include "SkPaintOptionsAndroid.h"
+#endif
+
struct SkGlyph;
class SkDescriptor;
class SkMaskFilter;
@@ -258,6 +262,10 @@ private:
// never null
SkAutoTUnref<SkTypeface> fTypeface;
+#ifdef SK_BUILD_FOR_ANDROID
+ SkPaintOptionsAndroid fPaintOptionsAndroid;
+#endif
+
// optional object, which may be null
SkPathEffect* fPathEffect;
SkMaskFilter* fMaskFilter;
@@ -289,6 +297,9 @@ private:
#define kPathEffect_SkDescriptorTag SkSetFourByteTag('p', 't', 'h', 'e')
#define kMaskFilter_SkDescriptorTag SkSetFourByteTag('m', 's', 'k', 'f')
#define kRasterizer_SkDescriptorTag SkSetFourByteTag('r', 'a', 's', 't')
+#ifdef SK_BUILD_FOR_ANDROID
+#define kAndroidOpts_SkDescriptorTag SkSetFourByteTag('a', 'n', 'd', 'r')
+#endif
///////////////////////////////////////////////////////////////////////////////