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