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 bool Equal(const SkPaintOptionsAndroid& a, const SkPaintOptionsAndroid& b ) { | |
12 return !(a != b); | |
djsollen
2013/09/19 18:36:52
why not just add the operator to SkPaintOptionsAnd
mtklein
2013/09/19 19:04:46
No reason. Done.
| |
13 } | |
14 | |
15 static size_t Reconstruct(const SkPaint& src, SkPaint* dst) { | |
16 SkOrderedWriteBuffer writer(64 /*arbitrary*/); | |
17 src.flatten(writer); | |
18 | |
19 const size_t size = writer.bytesWritten(); | |
20 SkAutoMalloc bytes(size); | |
21 writer.writeToMemory(bytes.get()); | |
22 | |
23 SkOrderedReadBuffer reader(bytes.get(), size); | |
24 dst->unflatten(reader); | |
25 | |
26 return size; | |
27 } | |
28 | |
29 static void android_options_serialization(skiatest::Reporter* reporter) { | |
30 // We want to make sure that Android's paint options survive a flatten/unfla tten round trip. | |
31 // These are all non-default options. | |
32 SkPaintOptionsAndroid options; | |
33 options.setLanguage("ja-JP"); | |
34 options.setFontVariant(SkPaintOptionsAndroid::kElegant_Variant); | |
35 options.setUseFontFallbacks(true); | |
36 | |
37 SkPaint paint; | |
38 paint.setPaintOptionsAndroid(options); | |
39 | |
40 SkPaint reconstructed; | |
41 Reconstruct(paint, &reconstructed); | |
42 | |
43 REPORTER_ASSERT(reporter, Equal(options, reconstructed.getPaintOptionsAndroi d())); | |
44 } | |
45 DEFINE_TESTCLASS_SHORT(android_options_serialization); | |
46 | |
47 static void android_options_serialization_reverse(skiatest::Reporter* reporter) { | |
48 // Opposite test of above: make sure the serialized default values of a pain t overwrite | |
49 // non-default values on the paint we're unflattening into. | |
50 const SkPaint defaultOptions; | |
51 | |
52 SkPaintOptionsAndroid options; | |
53 options.setLanguage("ja-JP"); | |
54 options.setFontVariant(SkPaintOptionsAndroid::kElegant_Variant); | |
55 options.setUseFontFallbacks(true); | |
56 SkPaint nonDefaultOptions; | |
57 nonDefaultOptions.setPaintOptionsAndroid(options); | |
58 | |
59 Reconstruct(defaultOptions, &nonDefaultOptions); | |
60 | |
61 REPORTER_ASSERT(reporter, Equal(defaultOptions.getPaintOptionsAndroid(), | |
62 nonDefaultOptions.getPaintOptionsAndroid())) ; | |
63 } | |
64 DEFINE_TESTCLASS_SHORT(android_options_serialization_reverse); | |
65 | |
66 static void android_options_size(skiatest::Reporter* reporter) { | |
67 // A paint with default android options should serialize to something smalle r than | |
68 // a paint with non-default android options. | |
69 | |
70 SkPaint defaultOptions; | |
71 | |
72 SkPaintOptionsAndroid options; | |
73 options.setUseFontFallbacks(true); | |
74 SkPaint nonDefaultOptions; | |
75 nonDefaultOptions.setPaintOptionsAndroid(options); | |
76 | |
77 SkPaint dummy; | |
78 | |
79 REPORTER_ASSERT(reporter, | |
80 Reconstruct(defaultOptions, &dummy) < Reconstruct(nonDefault Options, &dummy)); | |
81 } | |
82 DEFINE_TESTCLASS_SHORT(android_options_size); | |
83 | |
84 #endif // SK_BUILD_FOR_ANDROID | |
OLD | NEW |