Chromium Code Reviews| 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" |
| (...skipping 1985 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1996 | 1996 |
| 1997 static uint32_t pack_4(unsigned a, unsigned b, unsigned c, unsigned d) { | 1997 static uint32_t pack_4(unsigned a, unsigned b, unsigned c, unsigned d) { |
| 1998 SkASSERT(a == (uint8_t)a); | 1998 SkASSERT(a == (uint8_t)a); |
| 1999 SkASSERT(b == (uint8_t)b); | 1999 SkASSERT(b == (uint8_t)b); |
| 2000 SkASSERT(c == (uint8_t)c); | 2000 SkASSERT(c == (uint8_t)c); |
| 2001 SkASSERT(d == (uint8_t)d); | 2001 SkASSERT(d == (uint8_t)d); |
| 2002 return (a << 24) | (b << 16) | (c << 8) | d; | 2002 return (a << 24) | (b << 16) | (c << 8) | d; |
| 2003 } | 2003 } |
| 2004 | 2004 |
| 2005 enum FlatFlags { | 2005 enum FlatFlags { |
| 2006 kHasTypeface_FlatFlag = 0x01, | 2006 kHasTypeface_FlatFlag = 0x01, |
| 2007 kHasEffects_FlatFlag = 0x02, | 2007 kHasEffects_FlatFlag = 0x02, |
| 2008 kHasPaintOptionsAndroid_FlatFlag = 0x04, | |
| 2008 }; | 2009 }; |
| 2009 | 2010 |
| 2010 // The size of a flat paint's POD fields | 2011 // The size of a flat paint's POD fields |
| 2011 // Include an SkScalar for hinting scale factor whether it is | 2012 // Include an SkScalar for hinting scale factor whether it is |
| 2012 // supported or not so that an SKP is valid whether it was | 2013 // supported or not so that an SKP is valid whether it was |
| 2013 // created with support or not. | 2014 // created with support or not. |
| 2014 | 2015 |
| 2015 static const uint32_t kPODPaintSize = 6 * sizeof(SkScalar) + | 2016 static const uint32_t kPODPaintSize = 6 * sizeof(SkScalar) + |
| 2016 1 * sizeof(SkColor) + | 2017 1 * sizeof(SkColor) + |
| 2017 1 * sizeof(uint16_t) + | 2018 1 * sizeof(uint16_t) + |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 2029 asint(this->getShader()) | | 2030 asint(this->getShader()) | |
| 2030 asint(this->getXfermode()) | | 2031 asint(this->getXfermode()) | |
| 2031 asint(this->getMaskFilter()) | | 2032 asint(this->getMaskFilter()) | |
| 2032 asint(this->getColorFilter()) | | 2033 asint(this->getColorFilter()) | |
| 2033 asint(this->getRasterizer()) | | 2034 asint(this->getRasterizer()) | |
| 2034 asint(this->getLooper()) | | 2035 asint(this->getLooper()) | |
| 2035 asint(this->getAnnotation()) | | 2036 asint(this->getAnnotation()) | |
| 2036 asint(this->getImageFilter())) { | 2037 asint(this->getImageFilter())) { |
| 2037 flatFlags |= kHasEffects_FlatFlag; | 2038 flatFlags |= kHasEffects_FlatFlag; |
| 2038 } | 2039 } |
| 2039 | 2040 #if SK_BUILD_FOR_ANDROID |
| 2041 flatFlags |= kHasPaintOptionsAndroid_FlatFlag; | |
| 2042 #endif | |
| 2040 | 2043 |
| 2041 if (buffer.isOrderedBinaryBuffer()) { | 2044 if (buffer.isOrderedBinaryBuffer()) { |
| 2042 SkASSERT(SkAlign4(kPODPaintSize) == kPODPaintSize); | 2045 SkASSERT(SkAlign4(kPODPaintSize) == kPODPaintSize); |
| 2043 uint32_t* ptr = buffer.getOrderedBinaryBuffer()->reserve(kPODPaintSize); | 2046 uint32_t* ptr = buffer.getOrderedBinaryBuffer()->reserve(kPODPaintSize); |
| 2044 | 2047 |
| 2045 ptr = write_scalar(ptr, this->getTextSize()); | 2048 ptr = write_scalar(ptr, this->getTextSize()); |
| 2046 ptr = write_scalar(ptr, this->getTextScaleX()); | 2049 ptr = write_scalar(ptr, this->getTextScaleX()); |
| 2047 ptr = write_scalar(ptr, this->getTextSkewX()); | 2050 ptr = write_scalar(ptr, this->getTextSkewX()); |
| 2048 // Dummy value for obsolete hinting scale factor. TODO: remove with nex t picture version | 2051 // Dummy value for obsolete hinting scale factor. TODO: remove with nex t picture version |
| 2049 ptr = write_scalar(ptr, SK_Scalar1); | 2052 ptr = write_scalar(ptr, SK_Scalar1); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2088 buffer.writeFlattenable(this->getPathEffect()); | 2091 buffer.writeFlattenable(this->getPathEffect()); |
| 2089 buffer.writeFlattenable(this->getShader()); | 2092 buffer.writeFlattenable(this->getShader()); |
| 2090 buffer.writeFlattenable(this->getXfermode()); | 2093 buffer.writeFlattenable(this->getXfermode()); |
| 2091 buffer.writeFlattenable(this->getMaskFilter()); | 2094 buffer.writeFlattenable(this->getMaskFilter()); |
| 2092 buffer.writeFlattenable(this->getColorFilter()); | 2095 buffer.writeFlattenable(this->getColorFilter()); |
| 2093 buffer.writeFlattenable(this->getRasterizer()); | 2096 buffer.writeFlattenable(this->getRasterizer()); |
| 2094 buffer.writeFlattenable(this->getLooper()); | 2097 buffer.writeFlattenable(this->getLooper()); |
| 2095 buffer.writeFlattenable(this->getImageFilter()); | 2098 buffer.writeFlattenable(this->getImageFilter()); |
| 2096 buffer.writeFlattenable(this->getAnnotation()); | 2099 buffer.writeFlattenable(this->getAnnotation()); |
| 2097 } | 2100 } |
| 2101 #if SK_BUILD_FOR_ANDROID | |
| 2102 this->getPaintOptionsAndroid().flatten(buffer); | |
| 2103 #endif | |
| 2098 } | 2104 } |
| 2099 | 2105 |
| 2100 void SkPaint::unflatten(SkFlattenableReadBuffer& buffer) { | 2106 void SkPaint::unflatten(SkFlattenableReadBuffer& buffer) { |
| 2101 fPrivFlags = 0; | 2107 fPrivFlags = 0; |
| 2102 | 2108 |
| 2103 uint8_t flatFlags = 0; | 2109 uint8_t flatFlags = 0; |
| 2104 if (buffer.isOrderedBinaryBuffer()) { | 2110 if (buffer.isOrderedBinaryBuffer()) { |
| 2105 SkASSERT(SkAlign4(kPODPaintSize) == kPODPaintSize); | 2111 SkASSERT(SkAlign4(kPODPaintSize) == kPODPaintSize); |
| 2106 const void* podData = buffer.getOrderedBinaryBuffer()->skip(kPODPaintSiz e); | 2112 const void* podData = buffer.getOrderedBinaryBuffer()->skip(kPODPaintSiz e); |
| 2107 const uint32_t* pod = reinterpret_cast<const uint32_t*>(podData); | 2113 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 { | 2179 } else { |
| 2174 this->setPathEffect(NULL); | 2180 this->setPathEffect(NULL); |
| 2175 this->setShader(NULL); | 2181 this->setShader(NULL); |
| 2176 this->setXfermode(NULL); | 2182 this->setXfermode(NULL); |
| 2177 this->setMaskFilter(NULL); | 2183 this->setMaskFilter(NULL); |
| 2178 this->setColorFilter(NULL); | 2184 this->setColorFilter(NULL); |
| 2179 this->setRasterizer(NULL); | 2185 this->setRasterizer(NULL); |
| 2180 this->setLooper(NULL); | 2186 this->setLooper(NULL); |
| 2181 this->setImageFilter(NULL); | 2187 this->setImageFilter(NULL); |
| 2182 } | 2188 } |
| 2189 #if SK_BUILD_FOR_ANDROID | |
| 2190 if (flatFlags & kHasPaintOptionsAndroid_FlatFlag) { | |
| 2191 SkPaintOptionsAndroid options; | |
| 2192 options.unflatten(buffer); | |
| 2193 this->setPaintOptionsAndroid(options); | |
| 2194 } | |
| 2195 #endif | |
|
reed1
2013/09/18 18:37:40
need
#else // not android, need to eat these byte
| |
| 2183 } | 2196 } |
| 2184 | 2197 |
| 2185 /////////////////////////////////////////////////////////////////////////////// | 2198 /////////////////////////////////////////////////////////////////////////////// |
| 2186 | 2199 |
| 2187 SkShader* SkPaint::setShader(SkShader* shader) { | 2200 SkShader* SkPaint::setShader(SkShader* shader) { |
| 2188 GEN_ID_INC_EVAL(shader != fShader); | 2201 GEN_ID_INC_EVAL(shader != fShader); |
| 2189 SkRefCnt_SafeAssign(fShader, shader); | 2202 SkRefCnt_SafeAssign(fShader, shader); |
| 2190 return shader; | 2203 return shader; |
| 2191 } | 2204 } |
| 2192 | 2205 |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2573 case SkXfermode::kPlus_Mode: | 2586 case SkXfermode::kPlus_Mode: |
| 2574 return 0 == this->getAlpha(); | 2587 return 0 == this->getAlpha(); |
| 2575 case SkXfermode::kDst_Mode: | 2588 case SkXfermode::kDst_Mode: |
| 2576 return true; | 2589 return true; |
| 2577 default: | 2590 default: |
| 2578 break; | 2591 break; |
| 2579 } | 2592 } |
| 2580 } | 2593 } |
| 2581 return false; | 2594 return false; |
| 2582 } | 2595 } |
| OLD | NEW |