Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/core/SkPaint.cpp

Issue 239393002: remove legacy filter-flags, and store FilterLevel directly (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: use DEF_TEST Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « include/core/SkPicture.h ('k') | src/pipe/SkGPipePriv.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 244
245 void SkPaint::setPaintOptionsAndroid(const SkPaintOptionsAndroid& options) { 245 void SkPaint::setPaintOptionsAndroid(const SkPaintOptionsAndroid& options) {
246 if (options != fPaintOptionsAndroid) { 246 if (options != fPaintOptionsAndroid) {
247 fPaintOptionsAndroid = options; 247 fPaintOptionsAndroid = options;
248 GEN_ID_INC; 248 GEN_ID_INC;
249 fDirtyBits |= kPaintOptionsAndroid_DirtyBit; 249 fDirtyBits |= kPaintOptionsAndroid_DirtyBit;
250 } 250 }
251 } 251 }
252 #endif 252 #endif
253 253
254 SkPaint::FilterLevel SkPaint::getFilterLevel() const {
255 int level = 0;
256 if (fFlags & kFilterBitmap_Flag) {
257 level |= 1;
258 }
259 if (fFlags & kHighQualityFilterBitmap_Flag) {
260 level |= 2;
261 }
262 return (FilterLevel)level;
263 }
264
265 void SkPaint::setFilterLevel(FilterLevel level) { 254 void SkPaint::setFilterLevel(FilterLevel level) {
266 unsigned mask = kFilterBitmap_Flag | kHighQualityFilterBitmap_Flag; 255 GEN_ID_INC_EVAL((unsigned) level != fFilterLevel);
267 unsigned flags = 0; 256 fFilterLevel = level;
268 if (level & 1) { 257 fDirtyBits |= kBitfields_DirtyBit;
269 flags |= kFilterBitmap_Flag;
270 }
271 if (level & 2) {
272 flags |= kHighQualityFilterBitmap_Flag;
273 }
274 this->setFlags((fFlags & ~mask) | flags);
275 } 258 }
276 259
277 void SkPaint::setHinting(Hinting hintingLevel) { 260 void SkPaint::setHinting(Hinting hintingLevel) {
278 GEN_ID_INC_EVAL((unsigned) hintingLevel != fHinting); 261 GEN_ID_INC_EVAL((unsigned) hintingLevel != fHinting);
279 fHinting = hintingLevel; 262 fHinting = hintingLevel;
280 fDirtyBits |= kBitfields_DirtyBit; 263 fDirtyBits |= kBitfields_DirtyBit;
281 } 264 }
282 265
283 void SkPaint::setFlags(uint32_t flags) { 266 void SkPaint::setFlags(uint32_t flags) {
284 GEN_ID_INC_EVAL(fFlags != flags); 267 GEN_ID_INC_EVAL(fFlags != flags);
(...skipping 1734 matching lines...) Expand 10 before | Expand all | Expand 10 after
2019 } 2002 }
2020 2003
2021 static uint32_t pack_4(unsigned a, unsigned b, unsigned c, unsigned d) { 2004 static uint32_t pack_4(unsigned a, unsigned b, unsigned c, unsigned d) {
2022 SkASSERT(a == (uint8_t)a); 2005 SkASSERT(a == (uint8_t)a);
2023 SkASSERT(b == (uint8_t)b); 2006 SkASSERT(b == (uint8_t)b);
2024 SkASSERT(c == (uint8_t)c); 2007 SkASSERT(c == (uint8_t)c);
2025 SkASSERT(d == (uint8_t)d); 2008 SkASSERT(d == (uint8_t)d);
2026 return (a << 24) | (b << 16) | (c << 8) | d; 2009 return (a << 24) | (b << 16) | (c << 8) | d;
2027 } 2010 }
2028 2011
2012 #ifdef SK_DEBUG
2013 static void ASSERT_FITS_IN(uint32_t value, int bitCount) {
2014 SkASSERT(bitCount > 0 && bitCount <= 32);
2015 uint32_t mask = ~0U;
2016 mask >>= (32 - bitCount);
2017 SkASSERT(0 == (value & ~mask));
2018 }
2019 #else
2020 #define ASSERT_FITS_IN(value, bitcount)
2021 #endif
2022
2029 enum FlatFlags { 2023 enum FlatFlags {
2030 kHasTypeface_FlatFlag = 0x01, 2024 kHasTypeface_FlatFlag = 0x01,
2031 kHasEffects_FlatFlag = 0x02, 2025 kHasEffects_FlatFlag = 0x02,
2032 kHasNonDefaultPaintOptionsAndroid_FlatFlag = 0x04, 2026 kHasNonDefaultPaintOptionsAndroid_FlatFlag = 0x04,
2027
2028 kFlatFlagMask = 0x7,
2033 }; 2029 };
2034 2030
2031 enum BitsPerField {
2032 kFlags_BPF = 16,
2033 kHint_BPF = 2,
2034 kAlign_BPF = 2,
2035 kFilter_BPF = 2,
2036 kFlatFlags_BPF = 3,
2037 };
2038
2039 static inline int BPF_Mask(int bits) {
2040 return (1 << bits) - 1;
2041 }
2042
2043 static uint32_t pack_paint_flags(unsigned flags, unsigned hint, unsigned align,
2044 unsigned filter, unsigned flatFlags) {
2045 ASSERT_FITS_IN(flags, kFlags_BPF);
2046 ASSERT_FITS_IN(hint, kHint_BPF);
2047 ASSERT_FITS_IN(align, kAlign_BPF);
2048 ASSERT_FITS_IN(filter, kFilter_BPF);
2049 ASSERT_FITS_IN(flatFlags, kFlatFlags_BPF);
2050
2051 // left-align the fields of "known" size, and right-align the last (flatFlag s) so it can easly
2052 // add more bits in the future.
2053 return (flags << 16) | (hint << 14) | (align << 12) | (filter << 10) | flatF lags;
2054 }
2055
2056 static FlatFlags unpack_paint_flags(SkPaint* paint, uint32_t packed) {
2057 paint->setFlags(packed >> 16);
2058 paint->setHinting((SkPaint::Hinting)((packed >> 14) & BPF_Mask(kHint_BPF)));
2059 paint->setTextAlign((SkPaint::Align)((packed >> 12) & BPF_Mask(kAlign_BPF))) ;
2060 paint->setFilterLevel((SkPaint::FilterLevel)((packed >> 10) & BPF_Mask(kFilt er_BPF)));
2061 return (FlatFlags)(packed & kFlatFlagMask);
2062 }
2063
2064 // V22_COMPATIBILITY_CODE
2065 static FlatFlags unpack_paint_flags_v22(SkPaint* paint, uint32_t packed) {
2066 enum {
2067 kFilterBitmap_Flag = 0x02,
2068 kHighQualityFilterBitmap_Flag = 0x4000,
2069
2070 kAll_Flags = kFilterBitmap_Flag | kHighQualityFilterBitmap_Flag
2071 };
2072
2073 // previously flags:16, textAlign:8, flatFlags:8
2074 // now flags:16, hinting:4, textAlign:4, flatFlags:8
2075 unsigned flags = packed >> 16;
2076 int filter = 0;
2077 if (flags & kFilterBitmap_Flag) {
2078 filter |= 1;
2079 }
2080 if (flags & kHighQualityFilterBitmap_Flag) {
2081 filter |= 2;
2082 }
2083 paint->setFilterLevel((SkPaint::FilterLevel)filter);
2084 flags &= ~kAll_Flags; // remove these (now dead) bit flags
2085
2086 paint->setFlags(flags);
2087
2088 // hinting added later. 0 in this nibble means use the default.
2089 uint32_t hinting = (packed >> 12) & 0xF;
2090 paint->setHinting(0 == hinting ? SkPaint::kNormal_Hinting : static_cast<SkPa int::Hinting>(hinting-1));
2091 paint->setTextAlign(static_cast<SkPaint::Align>((packed >> 8) & 0xF));
2092 return (FlatFlags)(packed & kFlatFlagMask);
2093 }
2094
2035 // The size of a flat paint's POD fields 2095 // The size of a flat paint's POD fields
2036 static const uint32_t kPODPaintSize = 5 * sizeof(SkScalar) + 2096 static const uint32_t kPODPaintSize = 5 * sizeof(SkScalar) +
2037 1 * sizeof(SkColor) + 2097 1 * sizeof(SkColor) +
2038 1 * sizeof(uint16_t) + 2098 1 * sizeof(uint16_t) +
2039 6 * sizeof(uint8_t); 2099 6 * sizeof(uint8_t);
2040 2100
2041 /* To save space/time, we analyze the paint, and write a truncated version of 2101 /* To save space/time, we analyze the paint, and write a truncated version of
2042 it if there are not tricky elements like shaders, etc. 2102 it if there are not tricky elements like shaders, etc.
2043 */ 2103 */
2044 void SkPaint::flatten(SkWriteBuffer& buffer) const { 2104 void SkPaint::flatten(SkWriteBuffer& buffer) const {
(...skipping 20 matching lines...) Expand all
2065 2125
2066 SkASSERT(SkAlign4(kPODPaintSize) == kPODPaintSize); 2126 SkASSERT(SkAlign4(kPODPaintSize) == kPODPaintSize);
2067 uint32_t* ptr = buffer.reserve(kPODPaintSize); 2127 uint32_t* ptr = buffer.reserve(kPODPaintSize);
2068 2128
2069 ptr = write_scalar(ptr, this->getTextSize()); 2129 ptr = write_scalar(ptr, this->getTextSize());
2070 ptr = write_scalar(ptr, this->getTextScaleX()); 2130 ptr = write_scalar(ptr, this->getTextScaleX());
2071 ptr = write_scalar(ptr, this->getTextSkewX()); 2131 ptr = write_scalar(ptr, this->getTextSkewX());
2072 ptr = write_scalar(ptr, this->getStrokeWidth()); 2132 ptr = write_scalar(ptr, this->getStrokeWidth());
2073 ptr = write_scalar(ptr, this->getStrokeMiter()); 2133 ptr = write_scalar(ptr, this->getStrokeMiter());
2074 *ptr++ = this->getColor(); 2134 *ptr++ = this->getColor();
2075 // previously flags:16, textAlign:8, flatFlags:8 2135
2076 // now flags:16, hinting:4, textAlign:4, flatFlags:8 2136 *ptr++ = pack_paint_flags(this->getFlags(), this->getHinting(), this->getTex tAlign(),
2077 *ptr++ = (this->getFlags() << 16) | 2137 this->getFilterLevel(), flatFlags);
2078 // hinting added later. 0 in this nibble means use the default.
2079 ((this->getHinting()+1) << 12) |
2080 (this->getTextAlign() << 8) |
2081 flatFlags;
2082 *ptr++ = pack_4(this->getStrokeCap(), this->getStrokeJoin(), 2138 *ptr++ = pack_4(this->getStrokeCap(), this->getStrokeJoin(),
2083 this->getStyle(), this->getTextEncoding()); 2139 this->getStyle(), this->getTextEncoding());
2084 2140
2085 // now we're done with ptr and the (pre)reserved space. If we need to write 2141 // now we're done with ptr and the (pre)reserved space. If we need to write
2086 // additional fields, use the buffer directly 2142 // additional fields, use the buffer directly
2087 if (flatFlags & kHasTypeface_FlatFlag) { 2143 if (flatFlags & kHasTypeface_FlatFlag) {
2088 buffer.writeTypeface(this->getTypeface()); 2144 buffer.writeTypeface(this->getTypeface());
2089 } 2145 }
2090 if (flatFlags & kHasEffects_FlatFlag) { 2146 if (flatFlags & kHasEffects_FlatFlag) {
2091 buffer.writeFlattenable(this->getPathEffect()); 2147 buffer.writeFlattenable(this->getPathEffect());
(...skipping 13 matching lines...) Expand all
2105 } 2161 }
2106 } 2162 }
2107 #ifdef SK_BUILD_FOR_ANDROID 2163 #ifdef SK_BUILD_FOR_ANDROID
2108 if (flatFlags & kHasNonDefaultPaintOptionsAndroid_FlatFlag) { 2164 if (flatFlags & kHasNonDefaultPaintOptionsAndroid_FlatFlag) {
2109 this->getPaintOptionsAndroid().flatten(buffer); 2165 this->getPaintOptionsAndroid().flatten(buffer);
2110 } 2166 }
2111 #endif 2167 #endif
2112 } 2168 }
2113 2169
2114 void SkPaint::unflatten(SkReadBuffer& buffer) { 2170 void SkPaint::unflatten(SkReadBuffer& buffer) {
2115 uint8_t flatFlags = 0;
2116 SkASSERT(SkAlign4(kPODPaintSize) == kPODPaintSize); 2171 SkASSERT(SkAlign4(kPODPaintSize) == kPODPaintSize);
2117 const void* podData = buffer.skip(kPODPaintSize); 2172 const void* podData = buffer.skip(kPODPaintSize);
2118 const uint32_t* pod = reinterpret_cast<const uint32_t*>(podData); 2173 const uint32_t* pod = reinterpret_cast<const uint32_t*>(podData);
2119 2174
2120 // the order we read must match the order we wrote in flatten() 2175 // the order we read must match the order we wrote in flatten()
2121 this->setTextSize(read_scalar(pod)); 2176 this->setTextSize(read_scalar(pod));
2122 this->setTextScaleX(read_scalar(pod)); 2177 this->setTextScaleX(read_scalar(pod));
2123 this->setTextSkewX(read_scalar(pod)); 2178 this->setTextSkewX(read_scalar(pod));
2124 this->setStrokeWidth(read_scalar(pod)); 2179 this->setStrokeWidth(read_scalar(pod));
2125 this->setStrokeMiter(read_scalar(pod)); 2180 this->setStrokeMiter(read_scalar(pod));
2126 this->setColor(*pod++); 2181 this->setColor(*pod++);
2127 2182
2128 // previously flags:16, textAlign:8, flatFlags:8 2183 const int picVer = buffer.pictureVersion();
2129 // now flags:16, hinting:4, textAlign:4, flatFlags:8 2184 unsigned flatFlags = 0;
2185 if (picVer > 0 && picVer <= 22) {
2186 flatFlags = unpack_paint_flags_v22(this, *pod++);
2187 } else {
2188 flatFlags = unpack_paint_flags(this, *pod++);
2189 }
2190
2130 uint32_t tmp = *pod++; 2191 uint32_t tmp = *pod++;
2131 this->setFlags(tmp >> 16);
2132
2133 // hinting added later. 0 in this nibble means use the default.
2134 uint32_t hinting = (tmp >> 12) & 0xF;
2135 this->setHinting(0 == hinting ? kNormal_Hinting : static_cast<Hinting>(hinti ng-1));
2136
2137 this->setTextAlign(static_cast<Align>((tmp >> 8) & 0xF));
2138
2139 flatFlags = tmp & 0xFF;
2140
2141 tmp = *pod++;
2142 this->setStrokeCap(static_cast<Cap>((tmp >> 24) & 0xFF)); 2192 this->setStrokeCap(static_cast<Cap>((tmp >> 24) & 0xFF));
2143 this->setStrokeJoin(static_cast<Join>((tmp >> 16) & 0xFF)); 2193 this->setStrokeJoin(static_cast<Join>((tmp >> 16) & 0xFF));
2144 this->setStyle(static_cast<Style>((tmp >> 8) & 0xFF)); 2194 this->setStyle(static_cast<Style>((tmp >> 8) & 0xFF));
2145 this->setTextEncoding(static_cast<TextEncoding>((tmp >> 0) & 0xFF)); 2195 this->setTextEncoding(static_cast<TextEncoding>((tmp >> 0) & 0xFF));
2146 2196
2147 if (flatFlags & kHasTypeface_FlatFlag) { 2197 if (flatFlags & kHasTypeface_FlatFlag) {
2148 this->setTypeface(buffer.readTypeface()); 2198 this->setTypeface(buffer.readTypeface());
2149 } else { 2199 } else {
2150 this->setTypeface(NULL); 2200 this->setTypeface(NULL);
2151 } 2201 }
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
2684 } 2734 }
2685 #ifdef SK_BUILD_FOR_ANDROID 2735 #ifdef SK_BUILD_FOR_ANDROID
2686 if (dirty & kPaintOptionsAndroid_DirtyBit) { 2736 if (dirty & kPaintOptionsAndroid_DirtyBit) {
2687 SkPaintOptionsAndroid options; 2737 SkPaintOptionsAndroid options;
2688 options.unflatten(buffer); 2738 options.unflatten(buffer);
2689 paint->setPaintOptionsAndroid(options); 2739 paint->setPaintOptionsAndroid(options);
2690 } 2740 }
2691 #endif 2741 #endif
2692 SkASSERT(dirty == paint->fDirtyBits); 2742 SkASSERT(dirty == paint->fDirtyBits);
2693 } 2743 }
OLDNEW
« no previous file with comments | « include/core/SkPicture.h ('k') | src/pipe/SkGPipePriv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698