| OLD | NEW |
| 1 // SkPaints only have an SkPaintOptionsAndroid if SK_BUILD_FOR_ANDROID is true. | 1 // SkPaints only have an SkPaintOptionsAndroid if SK_BUILD_FOR_ANDROID is true. |
| 2 #ifdef SK_BUILD_FOR_ANDROID | 2 #ifdef SK_BUILD_FOR_ANDROID |
| 3 | 3 |
| 4 #include "SkReadBuffer.h" | 4 #include "SkReadBuffer.h" |
| 5 #include "SkWriteBuffer.h" | 5 #include "SkWriteBuffer.h" |
| 6 #include "SkPaint.h" | 6 #include "SkPaint.h" |
| 7 #include "SkPaintOptionsAndroid.h" | 7 #include "SkPaintOptionsAndroid.h" |
| 8 #include "Test.h" | 8 #include "Test.h" |
| 9 | 9 |
| 10 static size_t Reconstruct(const SkPaint& src, SkPaint* dst) { | 10 static size_t Reconstruct(const SkPaint& src, SkPaint* dst) { |
| 11 SkWriteBuffer writer; | 11 SkWriteBuffer writer; |
| 12 src.flatten(writer); | 12 src.flatten(writer); |
| 13 | 13 |
| 14 const size_t size = writer.bytesWritten(); | 14 const size_t size = writer.bytesWritten(); |
| 15 SkAutoMalloc bytes(size); | 15 SkAutoMalloc bytes(size); |
| 16 writer.writeToMemory(bytes.get()); | 16 writer.writeToMemory(bytes.get()); |
| 17 | 17 |
| 18 SkReadBuffer reader(bytes.get(), size); | 18 SkReadBuffer reader(bytes.get(), size); |
| 19 dst->unflatten(reader); | 19 dst->unflatten(reader); |
| 20 | 20 |
| 21 return size; | 21 return size; |
| 22 } | 22 } |
| 23 | 23 |
| 24 DEF_TEST(AndroidOptionsSerialization, reporter) { | 24 DEF_TEST(AndroidOptionsSerialization, reporter) { |
| 25 // We want to make sure that Android's paint options survive a flatten/unfla
tten round trip. | 25 // We want to make sure that Android's paint options survive a flatten/unfla
tten round trip. |
| 26 // These are all non-default options. | 26 // These are all non-default options. |
| 27 SkPaintOptionsAndroid options; | 27 SkPaintOptionsAndroid options; |
| 28 options.setLanguage("ja-JP"); | 28 options.setLanguage("ja-JP"); |
| 29 options.setFontVariant(SkPaintOptionsAndroid::kElegant_Variant); | 29 options.setFontVariant(SkPaintOptionsAndroid::kElegant_Variant); |
| 30 options.setUseFontFallbacks(true); | |
| 31 | 30 |
| 32 SkPaint paint; | 31 SkPaint paint; |
| 33 paint.setPaintOptionsAndroid(options); | 32 paint.setPaintOptionsAndroid(options); |
| 34 | 33 |
| 35 SkPaint reconstructed; | 34 SkPaint reconstructed; |
| 36 Reconstruct(paint, &reconstructed); | 35 Reconstruct(paint, &reconstructed); |
| 37 | 36 |
| 38 REPORTER_ASSERT(reporter, options == reconstructed.getPaintOptionsAndroid())
; | 37 REPORTER_ASSERT(reporter, options == reconstructed.getPaintOptionsAndroid())
; |
| 39 } | 38 } |
| 40 | 39 |
| 41 DEF_TEST(AndroidOptionsSerializationReverse, reporter) { | 40 DEF_TEST(AndroidOptionsSerializationReverse, reporter) { |
| 42 // Opposite test of above: make sure the serialized default values of a pain
t overwrite | 41 // Opposite test of above: make sure the serialized default values of a pain
t overwrite |
| 43 // non-default values on the paint we're unflattening into. | 42 // non-default values on the paint we're unflattening into. |
| 44 const SkPaint defaultOptions; | 43 const SkPaint defaultOptions; |
| 45 | 44 |
| 46 SkPaintOptionsAndroid options; | 45 SkPaintOptionsAndroid options; |
| 47 options.setLanguage("ja-JP"); | 46 options.setLanguage("ja-JP"); |
| 48 options.setFontVariant(SkPaintOptionsAndroid::kElegant_Variant); | 47 options.setFontVariant(SkPaintOptionsAndroid::kElegant_Variant); |
| 49 options.setUseFontFallbacks(true); | |
| 50 SkPaint nonDefaultOptions; | 48 SkPaint nonDefaultOptions; |
| 51 nonDefaultOptions.setPaintOptionsAndroid(options); | 49 nonDefaultOptions.setPaintOptionsAndroid(options); |
| 52 | 50 |
| 53 Reconstruct(defaultOptions, &nonDefaultOptions); | 51 Reconstruct(defaultOptions, &nonDefaultOptions); |
| 54 | 52 |
| 55 REPORTER_ASSERT(reporter, | 53 REPORTER_ASSERT(reporter, |
| 56 defaultOptions.getPaintOptionsAndroid() == | 54 defaultOptions.getPaintOptionsAndroid() == |
| 57 nonDefaultOptions.getPaintOptionsAndroid()); | 55 nonDefaultOptions.getPaintOptionsAndroid()); |
| 58 } | 56 } |
| 59 | 57 |
| 60 DEF_TEST(AndroidOptionsSize, reporter) { | 58 DEF_TEST(AndroidOptionsSize, reporter) { |
| 61 // A paint with default android options should serialize to something smalle
r than | 59 // A paint with default android options should serialize to something smalle
r than |
| 62 // a paint with non-default android options. | 60 // a paint with non-default android options. |
| 63 | 61 |
| 64 SkPaint defaultOptions; | 62 SkPaint defaultOptions; |
| 65 | 63 |
| 66 SkPaintOptionsAndroid options; | 64 SkPaintOptionsAndroid options; |
| 67 options.setUseFontFallbacks(true); | 65 options.setLanguage("ja-JP"); |
| 68 SkPaint nonDefaultOptions; | 66 SkPaint nonDefaultOptions; |
| 69 nonDefaultOptions.setPaintOptionsAndroid(options); | 67 nonDefaultOptions.setPaintOptionsAndroid(options); |
| 70 | 68 |
| 71 SkPaint dummy; | 69 SkPaint dummy; |
| 72 | 70 |
| 73 REPORTER_ASSERT(reporter, | 71 REPORTER_ASSERT(reporter, |
| 74 Reconstruct(defaultOptions, &dummy) < Reconstruct(nonDefault
Options, &dummy)); | 72 Reconstruct(defaultOptions, &dummy) < Reconstruct(nonDefault
Options, &dummy)); |
| 75 } | 73 } |
| 76 | 74 |
| 77 #endif // SK_BUILD_FOR_ANDROID | 75 #endif // SK_BUILD_FOR_ANDROID |
| OLD | NEW |