OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "SkPaint.h" | 9 #include "SkPaint.h" |
10 #include "SkAnnotation.h" | 10 #include "SkAnnotation.h" |
11 #include "SkAutoKern.h" | 11 #include "SkAutoKern.h" |
12 #include "SkColorFilter.h" | 12 #include "SkColorFilter.h" |
13 #include "SkData.h" | 13 #include "SkData.h" |
14 #include "SkDeviceProperties.h" | 14 #include "SkDeviceProperties.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 "SkOrderedReadBuffer.h" | 21 #include "SkOrderedReadBuffer.h" |
22 #include "SkOrderedWriteBuffer.h" | 22 #include "SkOrderedWriteBuffer.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 1962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1996 | 1997 |
1997 static uint32_t pack_4(unsigned a, unsigned b, unsigned c, unsigned d) { | 1998 static uint32_t pack_4(unsigned a, unsigned b, unsigned c, unsigned d) { |
1998 SkASSERT(a == (uint8_t)a); | 1999 SkASSERT(a == (uint8_t)a); |
1999 SkASSERT(b == (uint8_t)b); | 2000 SkASSERT(b == (uint8_t)b); |
2000 SkASSERT(c == (uint8_t)c); | 2001 SkASSERT(c == (uint8_t)c); |
2001 SkASSERT(d == (uint8_t)d); | 2002 SkASSERT(d == (uint8_t)d); |
2002 return (a << 24) | (b << 16) | (c << 8) | d; | 2003 return (a << 24) | (b << 16) | (c << 8) | d; |
2003 } | 2004 } |
2004 | 2005 |
2005 enum FlatFlags { | 2006 enum FlatFlags { |
2006 kHasTypeface_FlatFlag = 0x01, | 2007 kHasTypeface_FlatFlag = 0x01, |
2007 kHasEffects_FlatFlag = 0x02, | 2008 kHasEffects_FlatFlag = 0x02, |
| 2009 kHasNonDefaultPaintOptionsAndroid_FlatFlag = 0x04, |
2008 }; | 2010 }; |
2009 | 2011 |
2010 // The size of a flat paint's POD fields | 2012 // The size of a flat paint's POD fields |
2011 // Include an SkScalar for hinting scale factor whether it is | 2013 // Include an SkScalar for hinting scale factor whether it is |
2012 // supported or not so that an SKP is valid whether it was | 2014 // supported or not so that an SKP is valid whether it was |
2013 // created with support or not. | 2015 // created with support or not. |
2014 | 2016 |
2015 static const uint32_t kPODPaintSize = 6 * sizeof(SkScalar) + | 2017 static const uint32_t kPODPaintSize = 6 * sizeof(SkScalar) + |
2016 1 * sizeof(SkColor) + | 2018 1 * sizeof(SkColor) + |
2017 1 * sizeof(uint16_t) + | 2019 1 * sizeof(uint16_t) + |
(...skipping 11 matching lines...) Expand all Loading... |
2029 asint(this->getShader()) | | 2031 asint(this->getShader()) | |
2030 asint(this->getXfermode()) | | 2032 asint(this->getXfermode()) | |
2031 asint(this->getMaskFilter()) | | 2033 asint(this->getMaskFilter()) | |
2032 asint(this->getColorFilter()) | | 2034 asint(this->getColorFilter()) | |
2033 asint(this->getRasterizer()) | | 2035 asint(this->getRasterizer()) | |
2034 asint(this->getLooper()) | | 2036 asint(this->getLooper()) | |
2035 asint(this->getAnnotation()) | | 2037 asint(this->getAnnotation()) | |
2036 asint(this->getImageFilter())) { | 2038 asint(this->getImageFilter())) { |
2037 flatFlags |= kHasEffects_FlatFlag; | 2039 flatFlags |= kHasEffects_FlatFlag; |
2038 } | 2040 } |
2039 | 2041 #if SK_BUILD_FOR_ANDROID |
| 2042 if (this->getPaintOptionsAndroid() != SkPaintOptionsAndroid()) { |
| 2043 flatFlags |= kHasNonDefaultPaintOptionsAndroid_FlatFlag; |
| 2044 } |
| 2045 #endif |
2040 | 2046 |
2041 if (buffer.isOrderedBinaryBuffer()) { | 2047 if (buffer.isOrderedBinaryBuffer()) { |
2042 SkASSERT(SkAlign4(kPODPaintSize) == kPODPaintSize); | 2048 SkASSERT(SkAlign4(kPODPaintSize) == kPODPaintSize); |
2043 uint32_t* ptr = buffer.getOrderedBinaryBuffer()->reserve(kPODPaintSize); | 2049 uint32_t* ptr = buffer.getOrderedBinaryBuffer()->reserve(kPODPaintSize); |
2044 | 2050 |
2045 ptr = write_scalar(ptr, this->getTextSize()); | 2051 ptr = write_scalar(ptr, this->getTextSize()); |
2046 ptr = write_scalar(ptr, this->getTextScaleX()); | 2052 ptr = write_scalar(ptr, this->getTextScaleX()); |
2047 ptr = write_scalar(ptr, this->getTextSkewX()); | 2053 ptr = write_scalar(ptr, this->getTextSkewX()); |
2048 // Dummy value for obsolete hinting scale factor. TODO: remove with nex
t picture version | 2054 // Dummy value for obsolete hinting scale factor. TODO: remove with nex
t picture version |
2049 ptr = write_scalar(ptr, SK_Scalar1); | 2055 ptr = write_scalar(ptr, SK_Scalar1); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2088 buffer.writeFlattenable(this->getPathEffect()); | 2094 buffer.writeFlattenable(this->getPathEffect()); |
2089 buffer.writeFlattenable(this->getShader()); | 2095 buffer.writeFlattenable(this->getShader()); |
2090 buffer.writeFlattenable(this->getXfermode()); | 2096 buffer.writeFlattenable(this->getXfermode()); |
2091 buffer.writeFlattenable(this->getMaskFilter()); | 2097 buffer.writeFlattenable(this->getMaskFilter()); |
2092 buffer.writeFlattenable(this->getColorFilter()); | 2098 buffer.writeFlattenable(this->getColorFilter()); |
2093 buffer.writeFlattenable(this->getRasterizer()); | 2099 buffer.writeFlattenable(this->getRasterizer()); |
2094 buffer.writeFlattenable(this->getLooper()); | 2100 buffer.writeFlattenable(this->getLooper()); |
2095 buffer.writeFlattenable(this->getImageFilter()); | 2101 buffer.writeFlattenable(this->getImageFilter()); |
2096 buffer.writeFlattenable(this->getAnnotation()); | 2102 buffer.writeFlattenable(this->getAnnotation()); |
2097 } | 2103 } |
| 2104 #if SK_BUILD_FOR_ANDROID |
| 2105 if (flatFlags & kHasNonDefaultPaintOptionsAndroid_FlatFlag) { |
| 2106 this->getPaintOptionsAndroid().flatten(buffer); |
| 2107 } |
| 2108 #endif |
2098 } | 2109 } |
2099 | 2110 |
2100 void SkPaint::unflatten(SkFlattenableReadBuffer& buffer) { | 2111 void SkPaint::unflatten(SkFlattenableReadBuffer& buffer) { |
2101 fPrivFlags = 0; | 2112 fPrivFlags = 0; |
2102 | 2113 |
2103 uint8_t flatFlags = 0; | 2114 uint8_t flatFlags = 0; |
2104 if (buffer.isOrderedBinaryBuffer()) { | 2115 if (buffer.isOrderedBinaryBuffer()) { |
2105 SkASSERT(SkAlign4(kPODPaintSize) == kPODPaintSize); | 2116 SkASSERT(SkAlign4(kPODPaintSize) == kPODPaintSize); |
2106 const void* podData = buffer.getOrderedBinaryBuffer()->skip(kPODPaintSiz
e); | 2117 const void* podData = buffer.getOrderedBinaryBuffer()->skip(kPODPaintSiz
e); |
2107 const uint32_t* pod = reinterpret_cast<const uint32_t*>(podData); | 2118 const uint32_t* pod = reinterpret_cast<const uint32_t*>(podData); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2173 } else { | 2184 } else { |
2174 this->setPathEffect(NULL); | 2185 this->setPathEffect(NULL); |
2175 this->setShader(NULL); | 2186 this->setShader(NULL); |
2176 this->setXfermode(NULL); | 2187 this->setXfermode(NULL); |
2177 this->setMaskFilter(NULL); | 2188 this->setMaskFilter(NULL); |
2178 this->setColorFilter(NULL); | 2189 this->setColorFilter(NULL); |
2179 this->setRasterizer(NULL); | 2190 this->setRasterizer(NULL); |
2180 this->setLooper(NULL); | 2191 this->setLooper(NULL); |
2181 this->setImageFilter(NULL); | 2192 this->setImageFilter(NULL); |
2182 } | 2193 } |
| 2194 |
| 2195 #if SK_BUILD_FOR_ANDROID |
| 2196 this->setPaintOptionsAndroid(SkPaintOptionsAndroid()); |
| 2197 #endif |
| 2198 if (flatFlags & kHasNonDefaultPaintOptionsAndroid_FlatFlag) { |
| 2199 SkPaintOptionsAndroid options; |
| 2200 options.unflatten(buffer); |
| 2201 #if SK_BUILD_FOR_ANDROID |
| 2202 this->setPaintOptionsAndroid(options); |
| 2203 #endif |
| 2204 } |
2183 } | 2205 } |
2184 | 2206 |
2185 /////////////////////////////////////////////////////////////////////////////// | 2207 /////////////////////////////////////////////////////////////////////////////// |
2186 | 2208 |
2187 SkShader* SkPaint::setShader(SkShader* shader) { | 2209 SkShader* SkPaint::setShader(SkShader* shader) { |
2188 GEN_ID_INC_EVAL(shader != fShader); | 2210 GEN_ID_INC_EVAL(shader != fShader); |
2189 SkRefCnt_SafeAssign(fShader, shader); | 2211 SkRefCnt_SafeAssign(fShader, shader); |
2190 return shader; | 2212 return shader; |
2191 } | 2213 } |
2192 | 2214 |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2573 case SkXfermode::kPlus_Mode: | 2595 case SkXfermode::kPlus_Mode: |
2574 return 0 == this->getAlpha(); | 2596 return 0 == this->getAlpha(); |
2575 case SkXfermode::kDst_Mode: | 2597 case SkXfermode::kDst_Mode: |
2576 return true; | 2598 return true; |
2577 default: | 2599 default: |
2578 break; | 2600 break; |
2579 } | 2601 } |
2580 } | 2602 } |
2581 return false; | 2603 return false; |
2582 } | 2604 } |
OLD | NEW |