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