aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/core/SkPaint.h5
-rw-r--r--src/core/SkPaint.cpp9
-rw-r--r--src/views/animated/SkStaticTextView.cpp9
-rw-r--r--tests/PaintTest.cpp19
4 files changed, 25 insertions, 17 deletions
diff --git a/include/core/SkPaint.h b/include/core/SkPaint.h
index ac46760abd..fa0c61e4ea 100644
--- a/include/core/SkPaint.h
+++ b/include/core/SkPaint.h
@@ -67,6 +67,11 @@ public:
SkPaint& operator=(const SkPaint&);
+ SK_API friend bool operator==(const SkPaint& a, const SkPaint& b);
+ friend bool operator!=(const SkPaint& a, const SkPaint& b) {
+ return !(a == b);
+ }
+
void flatten(SkFlattenableWriteBuffer&) const;
void unflatten(SkFlattenableReadBuffer&);
diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp
index 328836624c..372e68051e 100644
--- a/src/core/SkPaint.cpp
+++ b/src/core/SkPaint.cpp
@@ -161,6 +161,15 @@ SkPaint& SkPaint::operator=(const SkPaint& src) {
return *this;
}
+bool operator==(const SkPaint& a, const SkPaint& b) {
+#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));
+#endif
+}
+
void SkPaint::reset() {
SkPaint init;
diff --git a/src/views/animated/SkStaticTextView.cpp b/src/views/animated/SkStaticTextView.cpp
index bbef63dff3..0e4cad63e5 100644
--- a/src/views/animated/SkStaticTextView.cpp
+++ b/src/views/animated/SkStaticTextView.cpp
@@ -125,9 +125,12 @@ void SkStaticTextView::getPaint(SkPaint* paint) const
void SkStaticTextView::setPaint(const SkPaint& paint)
{
- fPaint = paint;
- this->computeSize();
- this->inval(NULL);
+ if (fPaint != paint)
+ {
+ fPaint = paint;
+ this->computeSize();
+ this->inval(NULL);
+ }
}
void SkStaticTextView::onDraw(SkCanvas* canvas)
diff --git a/tests/PaintTest.cpp b/tests/PaintTest.cpp
index d71d12fc74..e25c7c3f08 100644
--- a/tests/PaintTest.cpp
+++ b/tests/PaintTest.cpp
@@ -133,15 +133,6 @@ static void test_filterlevel(skiatest::Reporter* reporter) {
}
}
-// Only useful for test_copy. Checks the fields that are set.
-static bool check_equal(const SkPaint& a, const SkPaint &b) {
- return a.getLooper() == b.getLooper() &&
- a.getMaskFilter() == b.getMaskFilter() &&
- a.getStrokeWidth() == b.getStrokeWidth() &&
- a.getStyle() == b.getStyle() &&
- a.getTextAlign() == b.getTextAlign();
-}
-
static void test_copy(skiatest::Reporter* reporter) {
SkPaint paint;
// set a few member variables
@@ -156,19 +147,19 @@ static void test_copy(skiatest::Reporter* reporter) {
// copy the paint using the copy constructor and check they are the same
SkPaint copiedPaint = paint;
- REPORTER_ASSERT(reporter, check_equal(paint, copiedPaint));
+ REPORTER_ASSERT(reporter, paint == copiedPaint);
#ifdef SK_BUILD_FOR_ANDROID
// the copy constructor should preserve the Generation ID
uint32_t paintGenID = paint.getGenerationID();
uint32_t copiedPaintGenID = copiedPaint.getGenerationID();
REPORTER_ASSERT(reporter, paintGenID == copiedPaintGenID);
- REPORTER_ASSERT(reporter, check_equal(paint, copiedPaint));
+ REPORTER_ASSERT(reporter, !memcmp(&paint, &copiedPaint, sizeof(paint)));
#endif
// copy the paint using the equal operator and check they are the same
copiedPaint = paint;
- REPORTER_ASSERT(reporter, check_equal(paint, copiedPaint));
+ REPORTER_ASSERT(reporter, paint == copiedPaint);
#ifdef SK_BUILD_FOR_ANDROID
// the equals operator should increment the Generation ID
@@ -182,8 +173,8 @@ static void test_copy(skiatest::Reporter* reporter) {
SkPaint cleanPaint;
paint.reset();
copiedPaint.reset();
- REPORTER_ASSERT(reporter, check_equal(cleanPaint, paint));
- REPORTER_ASSERT(reporter, check_equal(cleanPaint, copiedPaint));
+ REPORTER_ASSERT(reporter, cleanPaint == paint);
+ REPORTER_ASSERT(reporter, cleanPaint == copiedPaint);
#ifdef SK_BUILD_FOR_ANDROID
// the reset function should increment the Generation ID