SkPaint copiedPaint = paint;
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, paint == copiedPaint);
-#endif
-
// copy the paint using the equal operator and check they are the same
copiedPaint = paint;
REPORTER_ASSERT(reporter, paint == copiedPaint);
-#ifdef SK_BUILD_FOR_ANDROID
- // the equals operator should increment the Generation ID
- REPORTER_ASSERT(reporter, paint.getGenerationID() == paintGenID);
- REPORTER_ASSERT(reporter, copiedPaint.getGenerationID() != copiedPaintGenID);
- copiedPaintGenID = copiedPaint.getGenerationID(); // reset to the new value
- REPORTER_ASSERT(reporter, paint == copiedPaint); // operator== ignores fGenerationID
-#endif
-
// clean the paint and check they are back to their initial states
SkPaint cleanPaint;
paint.reset();
copiedPaint.reset();
REPORTER_ASSERT(reporter, cleanPaint == paint);
REPORTER_ASSERT(reporter, cleanPaint == copiedPaint);
-
-#ifdef SK_BUILD_FOR_ANDROID
- // the reset function should increment the Generation ID
- REPORTER_ASSERT(reporter, paint.getGenerationID() != paintGenID);
- REPORTER_ASSERT(reporter, copiedPaint.getGenerationID() != copiedPaintGenID);
- // operator== ignores fGenerationID
- REPORTER_ASSERT(reporter, cleanPaint == paint);
- REPORTER_ASSERT(reporter, cleanPaint == copiedPaint);
-#endif
}
// found and fixed for webkit: mishandling when we hit recursion limit on
#define ASSERT(expr) REPORTER_ASSERT(r, expr)
-DEF_TEST(Paint_FlatteningTraits, r) {
+DEF_TEST(Paint_MoreFlattening, r) {
SkPaint paint;
paint.setColor(0x00AABBCC);
paint.setTextScaleX(1.0f); // Default value, ignored.
paint.setLooper(NULL); // Default value, ignored.
SkWriteBuffer writer;
- SkPaint::FlatteningTraits::Flatten(writer, paint);
-
- // BEGIN white box asserts: if the impl changes, these asserts may change
- const size_t expectedBytesWritten = sizeof(void*) == 8 ? 32 : 28;
- ASSERT(expectedBytesWritten == writer.bytesWritten());
-
- const uint32_t* written = writer.getWriter32()->contiguousArray();
- SkASSERT(written != NULL);
- ASSERT(*written == ((1<<0) | (1<<1) | (1<<8))); // Dirty bits for our 3.
- // END white box asserts
+ paint.flatten(writer);
- SkReadBuffer reader(written, writer.bytesWritten());
+ SkReadBuffer reader(writer.getWriter32()->contiguousArray(), writer.bytesWritten());
SkPaint other;
- SkPaint::FlatteningTraits::Unflatten(reader, &other);
+ other.unflatten(reader);
ASSERT(reader.offset() == writer.bytesWritten());
// No matter the encoding, these must always hold.
ASSERT(paint.getXfermode()->asMode(&paintMode));
ASSERT(otherMode == paintMode);
}
+
+DEF_TEST(Paint_getHash, r) {
+ // Try not to inspect the actual hash values in here.
+ // We might want to change the hash function.
+
+ SkPaint paint;
+ const uint32_t defaultHash = paint.getHash();
+
+ // Check that some arbitrary field affects the hash.
+ paint.setColor(0xFF00FF00);
+ REPORTER_ASSERT(r, paint.getHash() != defaultHash);
+ paint.setColor(SK_ColorBLACK); // Reset to default value.
+ REPORTER_ASSERT(r, paint.getHash() == defaultHash);
+
+ // SkTypeface is the first field we hash, so test it specially.
+ paint.setTypeface(SkTypeface::RefDefault())->unref();
+ REPORTER_ASSERT(r, paint.getHash() != defaultHash);
+ paint.setTypeface(NULL);
+ REPORTER_ASSERT(r, paint.getHash() == defaultHash);
+
+ // This is part of fBitfields, the last field we hash.
+ paint.setHinting(SkPaint::kSlight_Hinting);
+ REPORTER_ASSERT(r, paint.getHash() != defaultHash);
+ paint.setHinting(SkPaint::kNormal_Hinting);
+ REPORTER_ASSERT(r, paint.getHash() == defaultHash);
+}