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