OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkPaint.h" | 8 #include "SkPaint.h" |
9 #include "SkAnnotation.h" | 9 #include "SkAnnotation.h" |
10 #include "SkAutoKern.h" | 10 #include "SkAutoKern.h" |
11 #include "SkColorFilter.h" | 11 #include "SkColorFilter.h" |
12 #include "SkData.h" | 12 #include "SkData.h" |
13 #include "SkDeviceProperties.h" | 13 #include "SkDeviceProperties.h" |
14 #include "SkDraw.h" | 14 #include "SkDraw.h" |
15 #include "SkFontDescriptor.h" | 15 #include "SkFontDescriptor.h" |
16 #include "SkFontHost.h" | 16 #include "SkFontHost.h" |
17 #include "SkGlyphCache.h" | 17 #include "SkGlyphCache.h" |
18 #include "SkImageFilter.h" | 18 #include "SkImageFilter.h" |
19 #include "SkMaskFilter.h" | 19 #include "SkMaskFilter.h" |
20 #include "SkMaskGamma.h" | 20 #include "SkMaskGamma.h" |
21 #include "SkReadBuffer.h" | 21 #include "SkReadBuffer.h" |
22 #include "SkWriteBuffer.h" | 22 #include "SkWriteBuffer.h" |
23 #include "SkPaintDefaults.h" | 23 #include "SkPaintDefaults.h" |
| 24 #include "SkPaintOptionsAndroid.h" |
24 #include "SkPathEffect.h" | 25 #include "SkPathEffect.h" |
25 #include "SkRasterizer.h" | 26 #include "SkRasterizer.h" |
26 #include "SkScalar.h" | 27 #include "SkScalar.h" |
27 #include "SkScalerContext.h" | 28 #include "SkScalerContext.h" |
28 #include "SkShader.h" | 29 #include "SkShader.h" |
29 #include "SkStringUtils.h" | 30 #include "SkStringUtils.h" |
30 #include "SkStroke.h" | 31 #include "SkStroke.h" |
31 #include "SkTextFormatParams.h" | 32 #include "SkTextFormatParams.h" |
32 #include "SkTextToPathIter.h" | 33 #include "SkTextToPathIter.h" |
33 #include "SkTLazy.h" | 34 #include "SkTLazy.h" |
(...skipping 13 matching lines...) Expand all Loading... |
47 kPathEffect_DirtyBit = 1 << 6, | 48 kPathEffect_DirtyBit = 1 << 6, |
48 kShader_DirtyBit = 1 << 7, | 49 kShader_DirtyBit = 1 << 7, |
49 kXfermode_DirtyBit = 1 << 8, | 50 kXfermode_DirtyBit = 1 << 8, |
50 kMaskFilter_DirtyBit = 1 << 9, | 51 kMaskFilter_DirtyBit = 1 << 9, |
51 kColorFilter_DirtyBit = 1 << 10, | 52 kColorFilter_DirtyBit = 1 << 10, |
52 kRasterizer_DirtyBit = 1 << 11, | 53 kRasterizer_DirtyBit = 1 << 11, |
53 kLooper_DirtyBit = 1 << 12, | 54 kLooper_DirtyBit = 1 << 12, |
54 kImageFilter_DirtyBit = 1 << 13, | 55 kImageFilter_DirtyBit = 1 << 13, |
55 kTypeface_DirtyBit = 1 << 14, | 56 kTypeface_DirtyBit = 1 << 14, |
56 kAnnotation_DirtyBit = 1 << 15, | 57 kAnnotation_DirtyBit = 1 << 15, |
| 58 kPaintOptionsAndroid_DirtyBit = 1 << 16, |
57 }; | 59 }; |
58 | 60 |
59 // define this to get a printf for out-of-range parameter in setters | 61 // define this to get a printf for out-of-range parameter in setters |
60 // e.g. setTextSize(-1) | 62 // e.g. setTextSize(-1) |
61 //#define SK_REPORT_API_RANGE_CHECK | 63 //#define SK_REPORT_API_RANGE_CHECK |
62 | 64 |
63 #ifdef SK_BUILD_FOR_ANDROID | 65 #ifdef SK_BUILD_FOR_ANDROID |
64 #define GEN_ID_INC fGenerationID++ | 66 #define GEN_ID_INC fGenerationID++ |
65 #define GEN_ID_INC_EVAL(expression) if (expression) { fGenerationID++; } | 67 #define GEN_ID_INC_EVAL(expression) if (expression) { fGenerationID++; } |
66 #else | 68 #else |
(...skipping 25 matching lines...) Expand all Loading... |
92 fBitfields.fFlags = SkPaintDefaults_Flags; | 94 fBitfields.fFlags = SkPaintDefaults_Flags; |
93 fBitfields.fCapType = kDefault_Cap; | 95 fBitfields.fCapType = kDefault_Cap; |
94 fBitfields.fJoinType = kDefault_Join; | 96 fBitfields.fJoinType = kDefault_Join; |
95 fBitfields.fTextAlign = kLeft_Align; | 97 fBitfields.fTextAlign = kLeft_Align; |
96 fBitfields.fStyle = kFill_Style; | 98 fBitfields.fStyle = kFill_Style; |
97 fBitfields.fTextEncoding = kUTF8_TextEncoding; | 99 fBitfields.fTextEncoding = kUTF8_TextEncoding; |
98 fBitfields.fHinting = SkPaintDefaults_Hinting; | 100 fBitfields.fHinting = SkPaintDefaults_Hinting; |
99 | 101 |
100 fDirtyBits = 0; | 102 fDirtyBits = 0; |
101 #ifdef SK_BUILD_FOR_ANDROID | 103 #ifdef SK_BUILD_FOR_ANDROID |
| 104 new (&fPaintOptionsAndroid) SkPaintOptionsAndroid; |
102 fGenerationID = 0; | 105 fGenerationID = 0; |
103 #endif | 106 #endif |
104 } | 107 } |
105 | 108 |
106 SkPaint::SkPaint(const SkPaint& src) { | 109 SkPaint::SkPaint(const SkPaint& src) { |
107 #define COPY(field) field = src.field | 110 #define COPY(field) field = src.field |
108 #define REF_COPY(field) field = SkSafeRef(src.field) | 111 #define REF_COPY(field) field = SkSafeRef(src.field) |
109 | 112 |
110 REF_COPY(fTypeface); | 113 REF_COPY(fTypeface); |
111 REF_COPY(fPathEffect); | 114 REF_COPY(fPathEffect); |
112 REF_COPY(fShader); | 115 REF_COPY(fShader); |
113 REF_COPY(fXfermode); | 116 REF_COPY(fXfermode); |
114 REF_COPY(fMaskFilter); | 117 REF_COPY(fMaskFilter); |
115 REF_COPY(fColorFilter); | 118 REF_COPY(fColorFilter); |
116 REF_COPY(fRasterizer); | 119 REF_COPY(fRasterizer); |
117 REF_COPY(fLooper); | 120 REF_COPY(fLooper); |
118 REF_COPY(fImageFilter); | 121 REF_COPY(fImageFilter); |
119 REF_COPY(fAnnotation); | 122 REF_COPY(fAnnotation); |
120 | 123 |
121 COPY(fTextSize); | 124 COPY(fTextSize); |
122 COPY(fTextScaleX); | 125 COPY(fTextScaleX); |
123 COPY(fTextSkewX); | 126 COPY(fTextSkewX); |
124 COPY(fColor); | 127 COPY(fColor); |
125 COPY(fWidth); | 128 COPY(fWidth); |
126 COPY(fMiterLimit); | 129 COPY(fMiterLimit); |
127 COPY(fBitfields); | 130 COPY(fBitfields); |
128 COPY(fDirtyBits); | 131 COPY(fDirtyBits); |
129 | 132 |
130 #ifdef SK_BUILD_FOR_ANDROID | 133 #ifdef SK_BUILD_FOR_ANDROID |
| 134 new (&fPaintOptionsAndroid) SkPaintOptionsAndroid(src.fPaintOptionsAndroid); |
131 COPY(fGenerationID); | 135 COPY(fGenerationID); |
132 #endif | 136 #endif |
133 | 137 |
134 #undef COPY | 138 #undef COPY |
135 #undef REF_COPY | 139 #undef REF_COPY |
136 } | 140 } |
137 | 141 |
138 SkPaint::~SkPaint() { | 142 SkPaint::~SkPaint() { |
139 SkSafeUnref(fTypeface); | 143 SkSafeUnref(fTypeface); |
140 SkSafeUnref(fPathEffect); | 144 SkSafeUnref(fPathEffect); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 COPY(fTextSize); | 176 COPY(fTextSize); |
173 COPY(fTextScaleX); | 177 COPY(fTextScaleX); |
174 COPY(fTextSkewX); | 178 COPY(fTextSkewX); |
175 COPY(fColor); | 179 COPY(fColor); |
176 COPY(fWidth); | 180 COPY(fWidth); |
177 COPY(fMiterLimit); | 181 COPY(fMiterLimit); |
178 COPY(fBitfields); | 182 COPY(fBitfields); |
179 COPY(fDirtyBits); | 183 COPY(fDirtyBits); |
180 | 184 |
181 #ifdef SK_BUILD_FOR_ANDROID | 185 #ifdef SK_BUILD_FOR_ANDROID |
| 186 fPaintOptionsAndroid.~SkPaintOptionsAndroid(); |
| 187 new (&fPaintOptionsAndroid) SkPaintOptionsAndroid(src.fPaintOptionsAndroid); |
182 ++fGenerationID; | 188 ++fGenerationID; |
183 #endif | 189 #endif |
184 | 190 |
185 return *this; | 191 return *this; |
186 | 192 |
187 #undef COPY | 193 #undef COPY |
188 #undef REF_COPY | 194 #undef REF_COPY |
189 } | 195 } |
190 | 196 |
191 bool operator==(const SkPaint& a, const SkPaint& b) { | 197 bool operator==(const SkPaint& a, const SkPaint& b) { |
192 #define EQUAL(field) (a.field == b.field) | 198 #define EQUAL(field) (a.field == b.field) |
193 // Don't check fGenerationID or fDirtyBits, which can be different for logic
ally equal paints. | 199 // Don't check fGenerationID or fDirtyBits, which can be different for logic
ally equal paints. |
194 return EQUAL(fTypeface) | 200 return EQUAL(fTypeface) |
195 && EQUAL(fPathEffect) | 201 && EQUAL(fPathEffect) |
196 && EQUAL(fShader) | 202 && EQUAL(fShader) |
197 && EQUAL(fXfermode) | 203 && EQUAL(fXfermode) |
198 && EQUAL(fMaskFilter) | 204 && EQUAL(fMaskFilter) |
199 && EQUAL(fColorFilter) | 205 && EQUAL(fColorFilter) |
200 && EQUAL(fRasterizer) | 206 && EQUAL(fRasterizer) |
201 && EQUAL(fLooper) | 207 && EQUAL(fLooper) |
202 && EQUAL(fImageFilter) | 208 && EQUAL(fImageFilter) |
203 && EQUAL(fAnnotation) | 209 && EQUAL(fAnnotation) |
204 && EQUAL(fTextSize) | 210 && EQUAL(fTextSize) |
205 && EQUAL(fTextScaleX) | 211 && EQUAL(fTextScaleX) |
206 && EQUAL(fTextSkewX) | 212 && EQUAL(fTextSkewX) |
207 && EQUAL(fColor) | 213 && EQUAL(fColor) |
208 && EQUAL(fWidth) | 214 && EQUAL(fWidth) |
209 && EQUAL(fMiterLimit) | 215 && EQUAL(fMiterLimit) |
210 && EQUAL(fBitfieldsUInt) | 216 && EQUAL(fBitfieldsUInt) |
| 217 #ifdef SK_BUILD_FOR_ANDROID |
| 218 && EQUAL(fPaintOptionsAndroid) |
| 219 #endif |
211 ; | 220 ; |
212 #undef EQUAL | 221 #undef EQUAL |
213 } | 222 } |
214 | 223 |
215 void SkPaint::reset() { | 224 void SkPaint::reset() { |
216 SkPaint init; | 225 SkPaint init; |
217 | 226 |
218 #ifdef SK_BUILD_FOR_ANDROID | 227 #ifdef SK_BUILD_FOR_ANDROID |
219 uint32_t oldGenerationID = fGenerationID; | 228 uint32_t oldGenerationID = fGenerationID; |
220 #endif | 229 #endif |
221 *this = init; | 230 *this = init; |
222 #ifdef SK_BUILD_FOR_ANDROID | 231 #ifdef SK_BUILD_FOR_ANDROID |
223 fGenerationID = oldGenerationID + 1; | 232 fGenerationID = oldGenerationID + 1; |
224 #endif | 233 #endif |
225 } | 234 } |
226 | 235 |
227 #ifdef SK_BUILD_FOR_ANDROID | 236 #ifdef SK_BUILD_FOR_ANDROID |
228 uint32_t SkPaint::getGenerationID() const { | 237 uint32_t SkPaint::getGenerationID() const { |
229 return fGenerationID; | 238 return fGenerationID; |
230 } | 239 } |
231 | 240 |
232 void SkPaint::setGenerationID(uint32_t generationID) { | 241 void SkPaint::setGenerationID(uint32_t generationID) { |
233 fGenerationID = generationID; | 242 fGenerationID = generationID; |
234 } | 243 } |
| 244 |
| 245 void SkPaint::setPaintOptionsAndroid(const SkPaintOptionsAndroid& options) { |
| 246 if (options != fPaintOptionsAndroid) { |
| 247 fPaintOptionsAndroid = options; |
| 248 GEN_ID_INC; |
| 249 fDirtyBits |= kPaintOptionsAndroid_DirtyBit; |
| 250 } |
| 251 } |
235 #endif | 252 #endif |
236 | 253 |
237 void SkPaint::setFilterLevel(FilterLevel level) { | 254 void SkPaint::setFilterLevel(FilterLevel level) { |
238 GEN_ID_INC_EVAL((unsigned) level != fBitfields.fFilterLevel); | 255 GEN_ID_INC_EVAL((unsigned) level != fBitfields.fFilterLevel); |
239 fBitfields.fFilterLevel = level; | 256 fBitfields.fFilterLevel = level; |
240 } | 257 } |
241 | 258 |
242 void SkPaint::setHinting(Hinting hintingLevel) { | 259 void SkPaint::setHinting(Hinting hintingLevel) { |
243 GEN_ID_INC_EVAL((unsigned) hintingLevel != fBitfields.fHinting); | 260 GEN_ID_INC_EVAL((unsigned) hintingLevel != fBitfields.fHinting); |
244 fBitfields.fHinting = hintingLevel; | 261 fBitfields.fHinting = hintingLevel; |
(...skipping 1574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1819 Also, all existing users of blur have calibrated for linear. */ | 1836 Also, all existing users of blur have calibrated for linear. */ |
1820 rec.ignorePreBlend(); | 1837 rec.ignorePreBlend(); |
1821 } | 1838 } |
1822 if (ra) { | 1839 if (ra) { |
1823 raBuffer.writeFlattenable(ra); | 1840 raBuffer.writeFlattenable(ra); |
1824 descSize += raBuffer.bytesWritten(); | 1841 descSize += raBuffer.bytesWritten(); |
1825 entryCount += 1; | 1842 entryCount += 1; |
1826 rec.fMaskFormat = SkMask::kA8_Format; // force antialiasing when we do
the scan conversion | 1843 rec.fMaskFormat = SkMask::kA8_Format; // force antialiasing when we do
the scan conversion |
1827 } | 1844 } |
1828 | 1845 |
| 1846 #ifdef SK_BUILD_FOR_ANDROID |
| 1847 char buffer[128]; |
| 1848 SkWriteBuffer androidBuffer(buffer, sizeof(buffer)); |
| 1849 fPaintOptionsAndroid.flatten(androidBuffer); |
| 1850 descSize += androidBuffer.bytesWritten(); |
| 1851 entryCount += 1; |
| 1852 #endif |
| 1853 |
1829 /////////////////////////////////////////////////////////////////////////// | 1854 /////////////////////////////////////////////////////////////////////////// |
1830 // Now that we're done tweaking the rec, call the PostMakeRec cleanup | 1855 // Now that we're done tweaking the rec, call the PostMakeRec cleanup |
1831 SkScalerContext::PostMakeRec(*this, &rec); | 1856 SkScalerContext::PostMakeRec(*this, &rec); |
1832 | 1857 |
1833 descSize += SkDescriptor::ComputeOverhead(entryCount); | 1858 descSize += SkDescriptor::ComputeOverhead(entryCount); |
1834 | 1859 |
1835 SkAutoDescriptor ad(descSize); | 1860 SkAutoDescriptor ad(descSize); |
1836 SkDescriptor* desc = ad.getDesc(); | 1861 SkDescriptor* desc = ad.getDesc(); |
1837 | 1862 |
1838 desc->init(); | 1863 desc->init(); |
1839 desc->addEntry(kRec_SkDescriptorTag, sizeof(rec), &rec); | 1864 desc->addEntry(kRec_SkDescriptorTag, sizeof(rec), &rec); |
1840 | 1865 |
| 1866 #ifdef SK_BUILD_FOR_ANDROID |
| 1867 add_flattenable(desc, kAndroidOpts_SkDescriptorTag, &androidBuffer); |
| 1868 #endif |
| 1869 |
1841 if (pe) { | 1870 if (pe) { |
1842 add_flattenable(desc, kPathEffect_SkDescriptorTag, &peBuffer); | 1871 add_flattenable(desc, kPathEffect_SkDescriptorTag, &peBuffer); |
1843 } | 1872 } |
1844 if (mf) { | 1873 if (mf) { |
1845 add_flattenable(desc, kMaskFilter_SkDescriptorTag, &mfBuffer); | 1874 add_flattenable(desc, kMaskFilter_SkDescriptorTag, &mfBuffer); |
1846 } | 1875 } |
1847 if (ra) { | 1876 if (ra) { |
1848 add_flattenable(desc, kRasterizer_SkDescriptorTag, &raBuffer); | 1877 add_flattenable(desc, kRasterizer_SkDescriptorTag, &raBuffer); |
1849 } | 1878 } |
1850 | 1879 |
(...skipping 14 matching lines...) Expand all Loading... |
1865 SkDescriptor* desc2 = ad2.getDesc(); | 1894 SkDescriptor* desc2 = ad2.getDesc(); |
1866 | 1895 |
1867 memset(desc1, 0x00, descSize); | 1896 memset(desc1, 0x00, descSize); |
1868 memset(desc2, 0xFF, descSize); | 1897 memset(desc2, 0xFF, descSize); |
1869 | 1898 |
1870 desc1->init(); | 1899 desc1->init(); |
1871 desc2->init(); | 1900 desc2->init(); |
1872 desc1->addEntry(kRec_SkDescriptorTag, sizeof(rec), &rec); | 1901 desc1->addEntry(kRec_SkDescriptorTag, sizeof(rec), &rec); |
1873 desc2->addEntry(kRec_SkDescriptorTag, sizeof(rec), &rec); | 1902 desc2->addEntry(kRec_SkDescriptorTag, sizeof(rec), &rec); |
1874 | 1903 |
| 1904 #ifdef SK_BUILD_FOR_ANDROID |
| 1905 add_flattenable(desc1, kAndroidOpts_SkDescriptorTag, &androidBuffer); |
| 1906 add_flattenable(desc2, kAndroidOpts_SkDescriptorTag, &androidBuffer); |
| 1907 #endif |
| 1908 |
1875 if (pe) { | 1909 if (pe) { |
1876 add_flattenable(desc1, kPathEffect_SkDescriptorTag, &peBuffer); | 1910 add_flattenable(desc1, kPathEffect_SkDescriptorTag, &peBuffer); |
1877 add_flattenable(desc2, kPathEffect_SkDescriptorTag, &peBuffer); | 1911 add_flattenable(desc2, kPathEffect_SkDescriptorTag, &peBuffer); |
1878 } | 1912 } |
1879 if (mf) { | 1913 if (mf) { |
1880 add_flattenable(desc1, kMaskFilter_SkDescriptorTag, &mfBuffer); | 1914 add_flattenable(desc1, kMaskFilter_SkDescriptorTag, &mfBuffer); |
1881 add_flattenable(desc2, kMaskFilter_SkDescriptorTag, &mfBuffer); | 1915 add_flattenable(desc2, kMaskFilter_SkDescriptorTag, &mfBuffer); |
1882 } | 1916 } |
1883 if (ra) { | 1917 if (ra) { |
1884 add_flattenable(desc1, kRasterizer_SkDescriptorTag, &raBuffer); | 1918 add_flattenable(desc1, kRasterizer_SkDescriptorTag, &raBuffer); |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2081 asint(this->getShader()) | | 2115 asint(this->getShader()) | |
2082 asint(this->getXfermode()) | | 2116 asint(this->getXfermode()) | |
2083 asint(this->getMaskFilter()) | | 2117 asint(this->getMaskFilter()) | |
2084 asint(this->getColorFilter()) | | 2118 asint(this->getColorFilter()) | |
2085 asint(this->getRasterizer()) | | 2119 asint(this->getRasterizer()) | |
2086 asint(this->getLooper()) | | 2120 asint(this->getLooper()) | |
2087 asint(this->getAnnotation()) | | 2121 asint(this->getAnnotation()) | |
2088 asint(this->getImageFilter())) { | 2122 asint(this->getImageFilter())) { |
2089 flatFlags |= kHasEffects_FlatFlag; | 2123 flatFlags |= kHasEffects_FlatFlag; |
2090 } | 2124 } |
| 2125 #ifdef SK_BUILD_FOR_ANDROID |
| 2126 if (this->getPaintOptionsAndroid() != SkPaintOptionsAndroid()) { |
| 2127 flatFlags |= kHasNonDefaultPaintOptionsAndroid_FlatFlag; |
| 2128 } |
| 2129 #endif |
2091 | 2130 |
2092 SkASSERT(SkAlign4(kPODPaintSize) == kPODPaintSize); | 2131 SkASSERT(SkAlign4(kPODPaintSize) == kPODPaintSize); |
2093 uint32_t* ptr = buffer.reserve(kPODPaintSize); | 2132 uint32_t* ptr = buffer.reserve(kPODPaintSize); |
2094 | 2133 |
2095 ptr = write_scalar(ptr, this->getTextSize()); | 2134 ptr = write_scalar(ptr, this->getTextSize()); |
2096 ptr = write_scalar(ptr, this->getTextScaleX()); | 2135 ptr = write_scalar(ptr, this->getTextScaleX()); |
2097 ptr = write_scalar(ptr, this->getTextSkewX()); | 2136 ptr = write_scalar(ptr, this->getTextSkewX()); |
2098 ptr = write_scalar(ptr, this->getStrokeWidth()); | 2137 ptr = write_scalar(ptr, this->getStrokeWidth()); |
2099 ptr = write_scalar(ptr, this->getStrokeMiter()); | 2138 ptr = write_scalar(ptr, this->getStrokeMiter()); |
2100 *ptr++ = this->getColor(); | 2139 *ptr++ = this->getColor(); |
(...skipping 18 matching lines...) Expand all Loading... |
2119 buffer.writeFlattenable(this->getLooper()); | 2158 buffer.writeFlattenable(this->getLooper()); |
2120 buffer.writeFlattenable(this->getImageFilter()); | 2159 buffer.writeFlattenable(this->getImageFilter()); |
2121 | 2160 |
2122 if (fAnnotation) { | 2161 if (fAnnotation) { |
2123 buffer.writeBool(true); | 2162 buffer.writeBool(true); |
2124 fAnnotation->writeToBuffer(buffer); | 2163 fAnnotation->writeToBuffer(buffer); |
2125 } else { | 2164 } else { |
2126 buffer.writeBool(false); | 2165 buffer.writeBool(false); |
2127 } | 2166 } |
2128 } | 2167 } |
| 2168 #ifdef SK_BUILD_FOR_ANDROID |
| 2169 if (flatFlags & kHasNonDefaultPaintOptionsAndroid_FlatFlag) { |
| 2170 this->getPaintOptionsAndroid().flatten(buffer); |
| 2171 } |
| 2172 #endif |
2129 } | 2173 } |
2130 | 2174 |
2131 void SkPaint::unflatten(SkReadBuffer& buffer) { | 2175 void SkPaint::unflatten(SkReadBuffer& buffer) { |
2132 SkASSERT(SkAlign4(kPODPaintSize) == kPODPaintSize); | 2176 SkASSERT(SkAlign4(kPODPaintSize) == kPODPaintSize); |
2133 const void* podData = buffer.skip(kPODPaintSize); | 2177 const void* podData = buffer.skip(kPODPaintSize); |
2134 const uint32_t* pod = reinterpret_cast<const uint32_t*>(podData); | 2178 const uint32_t* pod = reinterpret_cast<const uint32_t*>(podData); |
2135 | 2179 |
2136 // the order we read must match the order we wrote in flatten() | 2180 // the order we read must match the order we wrote in flatten() |
2137 this->setTextSize(read_scalar(pod)); | 2181 this->setTextSize(read_scalar(pod)); |
2138 this->setTextScaleX(read_scalar(pod)); | 2182 this->setTextScaleX(read_scalar(pod)); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2177 this->setPathEffect(NULL); | 2221 this->setPathEffect(NULL); |
2178 this->setShader(NULL); | 2222 this->setShader(NULL); |
2179 this->setXfermode(NULL); | 2223 this->setXfermode(NULL); |
2180 this->setMaskFilter(NULL); | 2224 this->setMaskFilter(NULL); |
2181 this->setColorFilter(NULL); | 2225 this->setColorFilter(NULL); |
2182 this->setRasterizer(NULL); | 2226 this->setRasterizer(NULL); |
2183 this->setLooper(NULL); | 2227 this->setLooper(NULL); |
2184 this->setImageFilter(NULL); | 2228 this->setImageFilter(NULL); |
2185 } | 2229 } |
2186 | 2230 |
2187 if (buffer.isVersionLT(SkReadBuffer::kRemoveAndroidPaintOpts_Version) && | 2231 #ifdef SK_BUILD_FOR_ANDROID |
2188 flatFlags & kHasNonDefaultPaintOptionsAndroid_FlatFlag) { | 2232 this->setPaintOptionsAndroid(SkPaintOptionsAndroid()); |
2189 SkString tag; | 2233 #endif |
2190 buffer.readUInt(); | 2234 if (flatFlags & kHasNonDefaultPaintOptionsAndroid_FlatFlag) { |
2191 buffer.readString(&tag); | 2235 SkPaintOptionsAndroid options; |
2192 buffer.readBool(); | 2236 options.unflatten(buffer); |
| 2237 #ifdef SK_BUILD_FOR_ANDROID |
| 2238 this->setPaintOptionsAndroid(options); |
| 2239 #endif |
2193 } | 2240 } |
2194 } | 2241 } |
2195 | 2242 |
2196 /////////////////////////////////////////////////////////////////////////////// | 2243 /////////////////////////////////////////////////////////////////////////////// |
2197 | 2244 |
2198 SkShader* SkPaint::setShader(SkShader* shader) { | 2245 SkShader* SkPaint::setShader(SkShader* shader) { |
2199 GEN_ID_INC_EVAL(shader != fShader); | 2246 GEN_ID_INC_EVAL(shader != fShader); |
2200 SkRefCnt_SafeAssign(fShader, shader); | 2247 SkRefCnt_SafeAssign(fShader, shader); |
2201 fDirtyBits = set_mask(fDirtyBits, kShader_DirtyBit, shader != NULL); | 2248 fDirtyBits = set_mask(fDirtyBits, kShader_DirtyBit, shader != NULL); |
2202 return shader; | 2249 return shader; |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2641 F(Shader); | 2688 F(Shader); |
2642 F(Xfermode); | 2689 F(Xfermode); |
2643 F(MaskFilter); | 2690 F(MaskFilter); |
2644 F(ColorFilter); | 2691 F(ColorFilter); |
2645 F(Rasterizer); | 2692 F(Rasterizer); |
2646 F(Looper); | 2693 F(Looper); |
2647 F(ImageFilter); | 2694 F(ImageFilter); |
2648 #undef F | 2695 #undef F |
2649 if (dirty & kTypeface_DirtyBit) buffer.writeTypeface(paint.getTypeface()); | 2696 if (dirty & kTypeface_DirtyBit) buffer.writeTypeface(paint.getTypeface()); |
2650 if (dirty & kAnnotation_DirtyBit) paint.getAnnotation()->writeToBuffer(buffe
r); | 2697 if (dirty & kAnnotation_DirtyBit) paint.getAnnotation()->writeToBuffer(buffe
r); |
| 2698 #ifdef SK_BUILD_FOR_ANDROID |
| 2699 if (dirty & kPaintOptionsAndroid_DirtyBit) paint.getPaintOptionsAndroid().fl
atten(buffer); |
| 2700 #endif |
2651 } | 2701 } |
2652 | 2702 |
2653 void SkPaint::FlatteningTraits::Unflatten(SkReadBuffer& buffer, SkPaint* paint)
{ | 2703 void SkPaint::FlatteningTraits::Unflatten(SkReadBuffer& buffer, SkPaint* paint)
{ |
2654 const uint32_t dirty = buffer.readUInt(); | 2704 const uint32_t dirty = buffer.readUInt(); |
2655 paint->fBitfieldsUInt = buffer.readUInt(); | 2705 paint->fBitfieldsUInt = buffer.readUInt(); |
2656 if (dirty == 0) { | 2706 if (dirty == 0) { |
2657 return; | 2707 return; |
2658 } | 2708 } |
2659 #define F(field, reader) if (dirty & k##field##_DirtyBit) paint->set##field(buff
er.reader()) | 2709 #define F(field, reader) if (dirty & k##field##_DirtyBit) paint->set##field(buff
er.reader()) |
2660 // Same function, except it unrefs the object newly set on the paint: | 2710 // Same function, except it unrefs the object newly set on the paint: |
(...skipping 14 matching lines...) Expand all Loading... |
2675 F_UNREF(ColorFilter, readColorFilter); | 2725 F_UNREF(ColorFilter, readColorFilter); |
2676 F_UNREF(Rasterizer, readRasterizer); | 2726 F_UNREF(Rasterizer, readRasterizer); |
2677 F_UNREF(Looper, readDrawLooper); | 2727 F_UNREF(Looper, readDrawLooper); |
2678 F_UNREF(ImageFilter, readImageFilter); | 2728 F_UNREF(ImageFilter, readImageFilter); |
2679 F(Typeface, readTypeface); | 2729 F(Typeface, readTypeface); |
2680 #undef F | 2730 #undef F |
2681 #undef F_UNREF | 2731 #undef F_UNREF |
2682 if (dirty & kAnnotation_DirtyBit) { | 2732 if (dirty & kAnnotation_DirtyBit) { |
2683 paint->setAnnotation(SkAnnotation::Create(buffer))->unref(); | 2733 paint->setAnnotation(SkAnnotation::Create(buffer))->unref(); |
2684 } | 2734 } |
| 2735 #ifdef SK_BUILD_FOR_ANDROID |
| 2736 if (dirty & kPaintOptionsAndroid_DirtyBit) { |
| 2737 SkPaintOptionsAndroid options; |
| 2738 options.unflatten(buffer); |
| 2739 paint->setPaintOptionsAndroid(options); |
| 2740 } |
| 2741 #endif |
2685 SkASSERT(dirty == paint->fDirtyBits); | 2742 SkASSERT(dirty == paint->fDirtyBits); |
2686 } | 2743 } |
OLD | NEW |