aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkPaint.cpp
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-03-24 23:03:11 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-03-24 23:03:11 +0000
commite8807f49ed24be3933acf84c9ffa840a03fa43dc (patch)
treeb9c4a437bd0132a5e5636c900d4db50809e43632 /src/core/SkPaint.cpp
parenta2b44dc5882856b6ed3670f370819ab39998ada8 (diff)
SkPaint: eliminate some dead bytes in 64-bit build.
+ memcpy-based copy constructor was hiding this gap -> manual copy constructor. + Split tests for finer-grained failures. BUG=skia: Committed: http://code.google.com/p/skia/source/detail?r=13856 Committed: http://code.google.com/p/skia/source/detail?r=13887 R=reed@google.com, mtklein@google.com Author: mtklein@chromium.org Review URL: https://codereview.chromium.org/203203003 git-svn-id: http://skia.googlecode.com/svn/trunk@13927 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core/SkPaint.cpp')
-rw-r--r--src/core/SkPaint.cpp155
1 files changed, 91 insertions, 64 deletions
diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp
index 2449ed6793..9cb61bd9d1 100644
--- a/src/core/SkPaint.cpp
+++ b/src/core/SkPaint.cpp
@@ -69,14 +69,7 @@ enum {
#endif
SkPaint::SkPaint() {
- // since we may have padding, we zero everything so that our memcmp() call
- // in operator== will work correctly.
- // with this, we can skip 0 and null individual initializations
- sk_bzero(this, sizeof(*this));
-
-#if 0 // not needed with the bzero call above
fTypeface = NULL;
- fTextSkewX = 0;
fPathEffect = NULL;
fShader = NULL;
fXfermode = NULL;
@@ -86,21 +79,25 @@ SkPaint::SkPaint() {
fLooper = NULL;
fImageFilter = NULL;
fAnnotation = NULL;
- fWidth = 0;
- fDirtyBits = 0;
-#endif
- fTextSize = SkPaintDefaults_TextSize;
- fTextScaleX = SK_Scalar1;
- fColor = SK_ColorBLACK;
- fMiterLimit = SkPaintDefaults_MiterLimit;
- fFlags = SkPaintDefaults_Flags;
- fCapType = kDefault_Cap;
- fJoinType = kDefault_Join;
- fTextAlign = kLeft_Align;
- fStyle = kFill_Style;
+ fTextSize = SkPaintDefaults_TextSize;
+ fTextScaleX = SK_Scalar1;
+ fTextSkewX = 0;
+ fColor = SK_ColorBLACK;
+ fWidth = 0;
+ fMiterLimit = SkPaintDefaults_MiterLimit;
+
+ // Zero all bitfields, then set some non-zero defaults.
+ fBitfields = 0;
+ fFlags = SkPaintDefaults_Flags;
+ fCapType = kDefault_Cap;
+ fJoinType = kDefault_Join;
+ fTextAlign = kLeft_Align;
+ fStyle = kFill_Style;
fTextEncoding = kUTF8_TextEncoding;
- fHinting = SkPaintDefaults_Hinting;
+ fHinting = SkPaintDefaults_Hinting;
+
+ fDirtyBits = 0;
#ifdef SK_BUILD_FOR_ANDROID
new (&fPaintOptionsAndroid) SkPaintOptionsAndroid;
fGenerationID = 0;
@@ -108,22 +105,36 @@ SkPaint::SkPaint() {
}
SkPaint::SkPaint(const SkPaint& src) {
- memcpy(this, &src, sizeof(src));
-
- SkSafeRef(fTypeface);
- SkSafeRef(fPathEffect);
- SkSafeRef(fShader);
- SkSafeRef(fXfermode);
- SkSafeRef(fMaskFilter);
- SkSafeRef(fColorFilter);
- SkSafeRef(fRasterizer);
- SkSafeRef(fLooper);
- SkSafeRef(fImageFilter);
- SkSafeRef(fAnnotation);
+#define COPY(field) field = src.field
+#define REF_COPY(field) field = SkSafeRef(src.field)
+
+ REF_COPY(fTypeface);
+ REF_COPY(fPathEffect);
+ REF_COPY(fShader);
+ REF_COPY(fXfermode);
+ REF_COPY(fMaskFilter);
+ REF_COPY(fColorFilter);
+ REF_COPY(fRasterizer);
+ REF_COPY(fLooper);
+ REF_COPY(fImageFilter);
+ REF_COPY(fAnnotation);
+
+ COPY(fTextSize);
+ COPY(fTextScaleX);
+ COPY(fTextSkewX);
+ COPY(fColor);
+ COPY(fWidth);
+ COPY(fMiterLimit);
+ COPY(fBitfields);
+ COPY(fDirtyBits);
#ifdef SK_BUILD_FOR_ANDROID
new (&fPaintOptionsAndroid) SkPaintOptionsAndroid(src.fPaintOptionsAndroid);
+ COPY(fGenerationID);
#endif
+
+#undef COPY
+#undef REF_COPY
}
SkPaint::~SkPaint() {
@@ -140,52 +151,68 @@ SkPaint::~SkPaint() {
}
SkPaint& SkPaint::operator=(const SkPaint& src) {
- SkASSERT(&src);
+#define COPY(field) field = src.field
+#define REF_COPY(field) SkSafeUnref(field); field = SkSafeRef(src.field)
- SkSafeRef(src.fTypeface);
- SkSafeRef(src.fPathEffect);
- SkSafeRef(src.fShader);
- SkSafeRef(src.fXfermode);
- SkSafeRef(src.fMaskFilter);
- SkSafeRef(src.fColorFilter);
- SkSafeRef(src.fRasterizer);
- SkSafeRef(src.fLooper);
- SkSafeRef(src.fImageFilter);
- SkSafeRef(src.fAnnotation);
+ SkASSERT(&src);
- SkSafeUnref(fTypeface);
- SkSafeUnref(fPathEffect);
- SkSafeUnref(fShader);
- SkSafeUnref(fXfermode);
- SkSafeUnref(fMaskFilter);
- SkSafeUnref(fColorFilter);
- SkSafeUnref(fRasterizer);
- SkSafeUnref(fLooper);
- SkSafeUnref(fImageFilter);
- SkSafeUnref(fAnnotation);
+ REF_COPY(fTypeface);
+ REF_COPY(fPathEffect);
+ REF_COPY(fShader);
+ REF_COPY(fXfermode);
+ REF_COPY(fMaskFilter);
+ REF_COPY(fColorFilter);
+ REF_COPY(fRasterizer);
+ REF_COPY(fLooper);
+ REF_COPY(fImageFilter);
+ REF_COPY(fAnnotation);
+
+ COPY(fTextSize);
+ COPY(fTextScaleX);
+ COPY(fTextSkewX);
+ COPY(fColor);
+ COPY(fWidth);
+ COPY(fMiterLimit);
+ COPY(fBitfields);
+ COPY(fDirtyBits);
#ifdef SK_BUILD_FOR_ANDROID
fPaintOptionsAndroid.~SkPaintOptionsAndroid();
-
- uint32_t oldGenerationID = fGenerationID;
-#endif
- memcpy(this, &src, sizeof(src));
-#ifdef SK_BUILD_FOR_ANDROID
- fGenerationID = oldGenerationID + 1;
-
new (&fPaintOptionsAndroid) SkPaintOptionsAndroid(src.fPaintOptionsAndroid);
+ ++fGenerationID;
#endif
return *this;
+
+#undef COPY
+#undef REF_COPY
}
bool operator==(const SkPaint& a, const SkPaint& b) {
+#define EQUAL(field) (a.field == b.field)
+ // Don't check fGenerationID or fDirtyBits, which can be different for logically equal paints.
+ return EQUAL(fTypeface)
+ && EQUAL(fPathEffect)
+ && EQUAL(fShader)
+ && EQUAL(fXfermode)
+ && EQUAL(fMaskFilter)
+ && EQUAL(fColorFilter)
+ && EQUAL(fRasterizer)
+ && EQUAL(fLooper)
+ && EQUAL(fImageFilter)
+ && EQUAL(fAnnotation)
+ && EQUAL(fTextSize)
+ && EQUAL(fTextScaleX)
+ && EQUAL(fTextSkewX)
+ && EQUAL(fColor)
+ && EQUAL(fWidth)
+ && EQUAL(fMiterLimit)
+ && EQUAL(fBitfields)
#ifdef SK_BUILD_FOR_ANDROID
- //assumes that fGenerationID is the last field in the struct
- return !memcmp(&a, &b, SK_OFFSETOF(SkPaint, fGenerationID));
-#else
- return !memcmp(&a, &b, sizeof(a));
+ && EQUAL(fPaintOptionsAndroid)
#endif
+ ;
+#undef EQUAL
}
void SkPaint::reset() {