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

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: 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
« include/core/SkPaint.h ('K') | « include/core/SkPaint.h ('k') | no next file » | 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 ASSEERT_FITS_IN(uint32_t value, int bitCount) {
mtklein 2014/04/15 16:40:15 ASSEERT?
reed1 2014/04/15 18:57:46 Done.
2014 SkASSERT(bitCount > 0 && bitCount <= 32);
2015 uint32_t mask = ~0U;
2016 mask >>= (32 - bitCount);
2017 SkASSERT(0 == (value & ~mask));
mtklein 2014/04/15 16:40:15 Is there any reason to prefer this to SkASSERT(val
reed1 2014/04/15 18:57:46 half dozen. I can change it.
2018 }
2019 #else
2020 #define ASSEERT_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,
2033 }; 2027 };
2034 2028
2029 static uint32_t pack_paint_flags(unsigned flags, unsigned hint, unsigned align,
2030 unsigned filter, unsigned flatFlags) {
2031 ASSEERT_FITS_IN(flags, 16);
2032 ASSEERT_FITS_IN(hint, 2);
2033 ASSEERT_FITS_IN(align, 2);
2034 ASSEERT_FITS_IN(filter, 2);
2035 ASSEERT_FITS_IN(flatFlags, 32 - (16 + 2 + 2 + 2));
2036
2037 // left-align the fields of "known" size, and right-align the last (flatFlag s) so it can easly
2038 // add more bits in the future.
2039 return (flags << 16) | (hint << 14) | (align << 12) | (filter << 10) | flatF lags;
2040 }
2041
2042 static unsigned unpack_paint_flags(SkPaint* paint, uint32_t packed) {
mtklein 2014/04/15 16:40:15 // Returns FlatFlags ?
reed1 2014/04/15 18:57:46 Done.
2043 paint->setFlags(packed >> 16);
2044 paint->setHinting((SkPaint::Hinting)((packed >> 14) & 0x3));
2045 paint->setTextAlign((SkPaint::Align)((packed >> 12) & 0x3));
2046 paint->setFilterLevel((SkPaint::FilterLevel)((packed >> 10) & 0x3));
2047 return packed & 0x7;
2048 }
2049
2050 static unsigned unpack_paint_flags_v22(SkPaint* paint, uint32_t packed) {
2051 enum {
2052 kFilterBitmap_Flag = 0x02,
2053 kHighQualityFilterBitmap_Flag = 0x4000,
2054 kHighQualityDownsampleBitmap_Flag = 0x8000,
2055
2056 kAll_Flags = kFilterBitmap_Flag | kHighQualityFilterBitmap_Flag | kHighQ ualityDownsampleBitmap_Flag
2057 };
2058
2059 // previously flags:16, textAlign:8, flatFlags:8
2060 // now flags:16, hinting:4, textAlign:4, flatFlags:8
2061 unsigned flags = packed >> 16;
2062 SkPaint::FilterLevel filter = SkPaint::kNone_FilterLevel;
2063 if (kHighQualityFilterBitmap_Flag & flags) {
2064 filter = SkPaint::kHigh_FilterLevel;
2065 } else if (kHighQualityDownsampleBitmap_Flag & flags) {
2066 filter = SkPaint::kMedium_FilterLevel;
2067 } else if (kFilterBitmap_Flag & flags) {
2068 filter = SkPaint::kLow_FilterLevel;
2069 }
2070 paint->setFilterLevel(filter);
2071 flags &= ~kAll_Flags;
2072
2073 paint->setFlags(packed >> 16);
2074
2075 // hinting added later. 0 in this nibble means use the default.
2076 uint32_t hinting = (packed >> 12) & 0xF;
2077 paint->setHinting(0 == hinting ? SkPaint::kNormal_Hinting : static_cast<SkPa int::Hinting>(hinting-1));
2078 paint->setTextAlign(static_cast<SkPaint::Align>((packed >> 8) & 0xF));
2079 return packed & 0x7;
2080 }
2081
2035 // The size of a flat paint's POD fields 2082 // The size of a flat paint's POD fields
2036 static const uint32_t kPODPaintSize = 5 * sizeof(SkScalar) + 2083 static const uint32_t kPODPaintSize = 5 * sizeof(SkScalar) +
2037 1 * sizeof(SkColor) + 2084 1 * sizeof(SkColor) +
2038 1 * sizeof(uint16_t) + 2085 1 * sizeof(uint16_t) +
2039 6 * sizeof(uint8_t); 2086 6 * sizeof(uint8_t);
2040 2087
2041 /* To save space/time, we analyze the paint, and write a truncated version of 2088 /* 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. 2089 it if there are not tricky elements like shaders, etc.
2043 */ 2090 */
2044 void SkPaint::flatten(SkWriteBuffer& buffer) const { 2091 void SkPaint::flatten(SkWriteBuffer& buffer) const {
(...skipping 20 matching lines...) Expand all
2065 2112
2066 SkASSERT(SkAlign4(kPODPaintSize) == kPODPaintSize); 2113 SkASSERT(SkAlign4(kPODPaintSize) == kPODPaintSize);
2067 uint32_t* ptr = buffer.reserve(kPODPaintSize); 2114 uint32_t* ptr = buffer.reserve(kPODPaintSize);
2068 2115
2069 ptr = write_scalar(ptr, this->getTextSize()); 2116 ptr = write_scalar(ptr, this->getTextSize());
2070 ptr = write_scalar(ptr, this->getTextScaleX()); 2117 ptr = write_scalar(ptr, this->getTextScaleX());
2071 ptr = write_scalar(ptr, this->getTextSkewX()); 2118 ptr = write_scalar(ptr, this->getTextSkewX());
2072 ptr = write_scalar(ptr, this->getStrokeWidth()); 2119 ptr = write_scalar(ptr, this->getStrokeWidth());
2073 ptr = write_scalar(ptr, this->getStrokeMiter()); 2120 ptr = write_scalar(ptr, this->getStrokeMiter());
2074 *ptr++ = this->getColor(); 2121 *ptr++ = this->getColor();
2122
2123 #if 0
2075 // previously flags:16, textAlign:8, flatFlags:8 2124 // previously flags:16, textAlign:8, flatFlags:8
mtklein 2014/04/15 16:40:15 Delete this now?
reed1 2014/04/15 18:57:46 Done.
2076 // now flags:16, hinting:4, textAlign:4, flatFlags:8 2125 // now flags:16, hinting:4, textAlign:4, flatFlags:8
2077 *ptr++ = (this->getFlags() << 16) | 2126 *ptr++ = (this->getFlags() << 16) |
2078 // hinting added later. 0 in this nibble means use the default. 2127 // hinting added later. 0 in this nibble means use the default.
2079 ((this->getHinting()+1) << 12) | 2128 ((this->getHinting()+1) << 12) |
2080 (this->getTextAlign() << 8) | 2129 (this->getTextAlign() << 8) |
2081 flatFlags; 2130 flatFlags;
2131 #else
2132 *ptr++ = pack_paint_flags(this->getFlags(), this->getHinting(), this->getTex tAlign(),
2133 this->getFilterLevel(), flatFlags);
2134 #endif
2082 *ptr++ = pack_4(this->getStrokeCap(), this->getStrokeJoin(), 2135 *ptr++ = pack_4(this->getStrokeCap(), this->getStrokeJoin(),
2083 this->getStyle(), this->getTextEncoding()); 2136 this->getStyle(), this->getTextEncoding());
2084 2137
2085 // now we're done with ptr and the (pre)reserved space. If we need to write 2138 // now we're done with ptr and the (pre)reserved space. If we need to write
2086 // additional fields, use the buffer directly 2139 // additional fields, use the buffer directly
2087 if (flatFlags & kHasTypeface_FlatFlag) { 2140 if (flatFlags & kHasTypeface_FlatFlag) {
2088 buffer.writeTypeface(this->getTypeface()); 2141 buffer.writeTypeface(this->getTypeface());
2089 } 2142 }
2090 if (flatFlags & kHasEffects_FlatFlag) { 2143 if (flatFlags & kHasEffects_FlatFlag) {
2091 buffer.writeFlattenable(this->getPathEffect()); 2144 buffer.writeFlattenable(this->getPathEffect());
(...skipping 13 matching lines...) Expand all
2105 } 2158 }
2106 } 2159 }
2107 #ifdef SK_BUILD_FOR_ANDROID 2160 #ifdef SK_BUILD_FOR_ANDROID
2108 if (flatFlags & kHasNonDefaultPaintOptionsAndroid_FlatFlag) { 2161 if (flatFlags & kHasNonDefaultPaintOptionsAndroid_FlatFlag) {
2109 this->getPaintOptionsAndroid().flatten(buffer); 2162 this->getPaintOptionsAndroid().flatten(buffer);
2110 } 2163 }
2111 #endif 2164 #endif
2112 } 2165 }
2113 2166
2114 void SkPaint::unflatten(SkReadBuffer& buffer) { 2167 void SkPaint::unflatten(SkReadBuffer& buffer) {
2115 uint8_t flatFlags = 0;
2116 SkASSERT(SkAlign4(kPODPaintSize) == kPODPaintSize); 2168 SkASSERT(SkAlign4(kPODPaintSize) == kPODPaintSize);
2117 const void* podData = buffer.skip(kPODPaintSize); 2169 const void* podData = buffer.skip(kPODPaintSize);
2118 const uint32_t* pod = reinterpret_cast<const uint32_t*>(podData); 2170 const uint32_t* pod = reinterpret_cast<const uint32_t*>(podData);
2119 2171
2120 // the order we read must match the order we wrote in flatten() 2172 // the order we read must match the order we wrote in flatten()
2121 this->setTextSize(read_scalar(pod)); 2173 this->setTextSize(read_scalar(pod));
2122 this->setTextScaleX(read_scalar(pod)); 2174 this->setTextScaleX(read_scalar(pod));
2123 this->setTextSkewX(read_scalar(pod)); 2175 this->setTextSkewX(read_scalar(pod));
2124 this->setStrokeWidth(read_scalar(pod)); 2176 this->setStrokeWidth(read_scalar(pod));
2125 this->setStrokeMiter(read_scalar(pod)); 2177 this->setStrokeMiter(read_scalar(pod));
2126 this->setColor(*pod++); 2178 this->setColor(*pod++);
2127 2179
2128 // previously flags:16, textAlign:8, flatFlags:8 2180 const int picVer = buffer.pictureVersion();
2129 // now flags:16, hinting:4, textAlign:4, flatFlags:8 2181 unsigned flatFlags = 0;
2182 if (picVer > 0 && picVer <= 22) {
mtklein 2014/04/15 16:40:15 Don't we need a version bump too?
reed1 2014/04/15 18:57:46 Indeed
2183 flatFlags = unpack_paint_flags_v22(this, *pod++);
2184 } else {
2185 flatFlags = unpack_paint_flags(this, *pod++);
2186 }
2187
2130 uint32_t tmp = *pod++; 2188 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)); 2189 this->setStrokeCap(static_cast<Cap>((tmp >> 24) & 0xFF));
2143 this->setStrokeJoin(static_cast<Join>((tmp >> 16) & 0xFF)); 2190 this->setStrokeJoin(static_cast<Join>((tmp >> 16) & 0xFF));
2144 this->setStyle(static_cast<Style>((tmp >> 8) & 0xFF)); 2191 this->setStyle(static_cast<Style>((tmp >> 8) & 0xFF));
2145 this->setTextEncoding(static_cast<TextEncoding>((tmp >> 0) & 0xFF)); 2192 this->setTextEncoding(static_cast<TextEncoding>((tmp >> 0) & 0xFF));
2146 2193
2147 if (flatFlags & kHasTypeface_FlatFlag) { 2194 if (flatFlags & kHasTypeface_FlatFlag) {
2148 this->setTypeface(buffer.readTypeface()); 2195 this->setTypeface(buffer.readTypeface());
2149 } else { 2196 } else {
2150 this->setTypeface(NULL); 2197 this->setTypeface(NULL);
2151 } 2198 }
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
2684 } 2731 }
2685 #ifdef SK_BUILD_FOR_ANDROID 2732 #ifdef SK_BUILD_FOR_ANDROID
2686 if (dirty & kPaintOptionsAndroid_DirtyBit) { 2733 if (dirty & kPaintOptionsAndroid_DirtyBit) {
2687 SkPaintOptionsAndroid options; 2734 SkPaintOptionsAndroid options;
2688 options.unflatten(buffer); 2735 options.unflatten(buffer);
2689 paint->setPaintOptionsAndroid(options); 2736 paint->setPaintOptionsAndroid(options);
2690 } 2737 }
2691 #endif 2738 #endif
2692 SkASSERT(dirty == paint->fDirtyBits); 2739 SkASSERT(dirty == paint->fDirtyBits);
2693 } 2740 }
OLDNEW
« include/core/SkPaint.h ('K') | « include/core/SkPaint.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698