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" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 | 63 |
64 #ifdef SK_BUILD_FOR_ANDROID | 64 #ifdef SK_BUILD_FOR_ANDROID |
65 #define GEN_ID_INC fGenerationID++ | 65 #define GEN_ID_INC fGenerationID++ |
66 #define GEN_ID_INC_EVAL(expression) if (expression) { fGenerationID++; } | 66 #define GEN_ID_INC_EVAL(expression) if (expression) { fGenerationID++; } |
67 #else | 67 #else |
68 #define GEN_ID_INC | 68 #define GEN_ID_INC |
69 #define GEN_ID_INC_EVAL(expression) | 69 #define GEN_ID_INC_EVAL(expression) |
70 #endif | 70 #endif |
71 | 71 |
72 SkPaint::SkPaint() { | 72 SkPaint::SkPaint() { |
| 73 fCachedFont = NULL; |
| 74 |
73 fTypeface = NULL; | 75 fTypeface = NULL; |
74 fPathEffect = NULL; | 76 fPathEffect = NULL; |
75 fShader = NULL; | 77 fShader = NULL; |
76 fXfermode = NULL; | 78 fXfermode = NULL; |
77 fMaskFilter = NULL; | 79 fMaskFilter = NULL; |
78 fColorFilter = NULL; | 80 fColorFilter = NULL; |
79 fRasterizer = NULL; | 81 fRasterizer = NULL; |
80 fLooper = NULL; | 82 fLooper = NULL; |
81 fImageFilter = NULL; | 83 fImageFilter = NULL; |
82 fAnnotation = NULL; | 84 fAnnotation = NULL; |
(...skipping 24 matching lines...) Expand all Loading... |
107 | 109 |
108 SkPaint::SkPaint(const SkPaint& src) { | 110 SkPaint::SkPaint(const SkPaint& src) { |
109 // Diagnoistic. May remove later. See crbug.com/364224 | 111 // Diagnoistic. May remove later. See crbug.com/364224 |
110 if (NULL == &src) { | 112 if (NULL == &src) { |
111 sk_throw(); | 113 sk_throw(); |
112 } | 114 } |
113 | 115 |
114 #define COPY(field) field = src.field | 116 #define COPY(field) field = src.field |
115 #define REF_COPY(field) field = SkSafeRef(src.field) | 117 #define REF_COPY(field) field = SkSafeRef(src.field) |
116 | 118 |
| 119 REF_COPY(fCachedFont); |
| 120 |
117 REF_COPY(fTypeface); | 121 REF_COPY(fTypeface); |
118 REF_COPY(fPathEffect); | 122 REF_COPY(fPathEffect); |
119 REF_COPY(fShader); | 123 REF_COPY(fShader); |
120 REF_COPY(fXfermode); | 124 REF_COPY(fXfermode); |
121 REF_COPY(fMaskFilter); | 125 REF_COPY(fMaskFilter); |
122 REF_COPY(fColorFilter); | 126 REF_COPY(fColorFilter); |
123 REF_COPY(fRasterizer); | 127 REF_COPY(fRasterizer); |
124 REF_COPY(fLooper); | 128 REF_COPY(fLooper); |
125 REF_COPY(fImageFilter); | 129 REF_COPY(fImageFilter); |
126 REF_COPY(fAnnotation); | 130 REF_COPY(fAnnotation); |
(...skipping 10 matching lines...) Expand all Loading... |
137 #ifdef SK_BUILD_FOR_ANDROID | 141 #ifdef SK_BUILD_FOR_ANDROID |
138 new (&fPaintOptionsAndroid) SkPaintOptionsAndroid(src.fPaintOptionsAndroid); | 142 new (&fPaintOptionsAndroid) SkPaintOptionsAndroid(src.fPaintOptionsAndroid); |
139 COPY(fGenerationID); | 143 COPY(fGenerationID); |
140 #endif | 144 #endif |
141 | 145 |
142 #undef COPY | 146 #undef COPY |
143 #undef REF_COPY | 147 #undef REF_COPY |
144 } | 148 } |
145 | 149 |
146 SkPaint::~SkPaint() { | 150 SkPaint::~SkPaint() { |
| 151 SkSafeUnref(fCachedFont); |
147 SkSafeUnref(fTypeface); | 152 SkSafeUnref(fTypeface); |
148 SkSafeUnref(fPathEffect); | 153 SkSafeUnref(fPathEffect); |
149 SkSafeUnref(fShader); | 154 SkSafeUnref(fShader); |
150 SkSafeUnref(fXfermode); | 155 SkSafeUnref(fXfermode); |
151 SkSafeUnref(fMaskFilter); | 156 SkSafeUnref(fMaskFilter); |
152 SkSafeUnref(fColorFilter); | 157 SkSafeUnref(fColorFilter); |
153 SkSafeUnref(fRasterizer); | 158 SkSafeUnref(fRasterizer); |
154 SkSafeUnref(fLooper); | 159 SkSafeUnref(fLooper); |
155 SkSafeUnref(fImageFilter); | 160 SkSafeUnref(fImageFilter); |
156 SkSafeUnref(fAnnotation); | 161 SkSafeUnref(fAnnotation); |
157 } | 162 } |
158 | 163 |
159 SkPaint& SkPaint::operator=(const SkPaint& src) { | 164 SkPaint& SkPaint::operator=(const SkPaint& src) { |
160 if (this == &src) { | 165 if (this == &src) { |
161 return *this; | 166 return *this; |
162 } | 167 } |
163 | 168 |
164 #define COPY(field) field = src.field | 169 #define COPY(field) field = src.field |
165 #define REF_COPY(field) SkSafeUnref(field); field = SkSafeRef(src.field) | 170 #define REF_COPY(field) SkSafeUnref(field); field = SkSafeRef(src.field) |
166 | 171 |
167 SkASSERT(&src); | 172 SkASSERT(&src); |
168 | 173 |
| 174 REF_COPY(fCachedFont); |
| 175 |
169 REF_COPY(fTypeface); | 176 REF_COPY(fTypeface); |
170 REF_COPY(fPathEffect); | 177 REF_COPY(fPathEffect); |
171 REF_COPY(fShader); | 178 REF_COPY(fShader); |
172 REF_COPY(fXfermode); | 179 REF_COPY(fXfermode); |
173 REF_COPY(fMaskFilter); | 180 REF_COPY(fMaskFilter); |
174 REF_COPY(fColorFilter); | 181 REF_COPY(fColorFilter); |
175 REF_COPY(fRasterizer); | 182 REF_COPY(fRasterizer); |
176 REF_COPY(fLooper); | 183 REF_COPY(fLooper); |
177 REF_COPY(fImageFilter); | 184 REF_COPY(fImageFilter); |
178 REF_COPY(fAnnotation); | 185 REF_COPY(fAnnotation); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 } | 267 } |
261 } | 268 } |
262 #endif | 269 #endif |
263 | 270 |
264 void SkPaint::setFilterLevel(FilterLevel level) { | 271 void SkPaint::setFilterLevel(FilterLevel level) { |
265 GEN_ID_INC_EVAL((unsigned) level != fFilterLevel); | 272 GEN_ID_INC_EVAL((unsigned) level != fFilterLevel); |
266 fFilterLevel = level; | 273 fFilterLevel = level; |
267 } | 274 } |
268 | 275 |
269 void SkPaint::setHinting(Hinting hintingLevel) { | 276 void SkPaint::setHinting(Hinting hintingLevel) { |
| 277 this->dirtyCachedFont(hintingLevel != fHinting); |
270 GEN_ID_INC_EVAL((unsigned) hintingLevel != fHinting); | 278 GEN_ID_INC_EVAL((unsigned) hintingLevel != fHinting); |
271 fHinting = hintingLevel; | 279 fHinting = hintingLevel; |
272 } | 280 } |
273 | 281 |
274 void SkPaint::setFlags(uint32_t flags) { | 282 void SkPaint::setFlags(uint32_t flags) { |
| 283 this->dirtyCachedFont(fFlags != flags); |
275 GEN_ID_INC_EVAL(fFlags != flags); | 284 GEN_ID_INC_EVAL(fFlags != flags); |
276 fFlags = flags; | 285 fFlags = flags; |
277 } | 286 } |
278 | 287 |
279 void SkPaint::setAntiAlias(bool doAA) { | 288 void SkPaint::setAntiAlias(bool doAA) { |
280 this->setFlags(SkSetClearMask(fFlags, doAA, kAntiAlias_Flag)); | 289 this->setFlags(SkSetClearMask(fFlags, doAA, kAntiAlias_Flag)); |
281 } | 290 } |
282 | 291 |
283 void SkPaint::setDither(bool doDither) { | 292 void SkPaint::setDither(bool doDither) { |
284 this->setFlags(SkSetClearMask(fFlags, doDither, kDither_Flag)); | 293 this->setFlags(SkSetClearMask(fFlags, doDither, kDither_Flag)); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 fTextAlign = SkToU8(align); | 417 fTextAlign = SkToU8(align); |
409 } else { | 418 } else { |
410 #ifdef SK_REPORT_API_RANGE_CHECK | 419 #ifdef SK_REPORT_API_RANGE_CHECK |
411 SkDebugf("SkPaint::setTextAlign(%d) out of range\n", align); | 420 SkDebugf("SkPaint::setTextAlign(%d) out of range\n", align); |
412 #endif | 421 #endif |
413 } | 422 } |
414 } | 423 } |
415 | 424 |
416 void SkPaint::setTextSize(SkScalar ts) { | 425 void SkPaint::setTextSize(SkScalar ts) { |
417 if (ts >= 0) { | 426 if (ts >= 0) { |
| 427 this->dirtyCachedFont(ts != fTextSize); |
418 GEN_ID_INC_EVAL(ts != fTextSize); | 428 GEN_ID_INC_EVAL(ts != fTextSize); |
419 fTextSize = ts; | 429 fTextSize = ts; |
420 fDirtyBits |= kTextSize_DirtyBit; | 430 fDirtyBits |= kTextSize_DirtyBit; |
421 } else { | 431 } else { |
422 #ifdef SK_REPORT_API_RANGE_CHECK | 432 #ifdef SK_REPORT_API_RANGE_CHECK |
423 SkDebugf("SkPaint::setTextSize() called with negative value\n"); | 433 SkDebugf("SkPaint::setTextSize() called with negative value\n"); |
424 #endif | 434 #endif |
425 } | 435 } |
426 } | 436 } |
427 | 437 |
428 void SkPaint::setTextScaleX(SkScalar scaleX) { | 438 void SkPaint::setTextScaleX(SkScalar scaleX) { |
| 439 this->dirtyCachedFont(scaleX != fTextScaleX); |
429 GEN_ID_INC_EVAL(scaleX != fTextScaleX); | 440 GEN_ID_INC_EVAL(scaleX != fTextScaleX); |
430 fTextScaleX = scaleX; | 441 fTextScaleX = scaleX; |
431 fDirtyBits |= kTextScaleX_DirtyBit; | 442 fDirtyBits |= kTextScaleX_DirtyBit; |
432 } | 443 } |
433 | 444 |
434 void SkPaint::setTextSkewX(SkScalar skewX) { | 445 void SkPaint::setTextSkewX(SkScalar skewX) { |
| 446 this->dirtyCachedFont(skewX != fTextSkewX); |
435 GEN_ID_INC_EVAL(skewX != fTextSkewX); | 447 GEN_ID_INC_EVAL(skewX != fTextSkewX); |
436 fTextSkewX = skewX; | 448 fTextSkewX = skewX; |
437 fDirtyBits |= kTextSkewX_DirtyBit; | 449 fDirtyBits |= kTextSkewX_DirtyBit; |
438 } | 450 } |
439 | 451 |
440 void SkPaint::setTextEncoding(TextEncoding encoding) { | 452 void SkPaint::setTextEncoding(TextEncoding encoding) { |
441 if ((unsigned)encoding <= kGlyphID_TextEncoding) { | 453 if ((unsigned)encoding <= kGlyphID_TextEncoding) { |
442 GEN_ID_INC_EVAL((unsigned)encoding != fTextEncoding); | 454 GEN_ID_INC_EVAL((unsigned)encoding != fTextEncoding); |
443 fTextEncoding = encoding; | 455 fTextEncoding = encoding; |
444 } else { | 456 } else { |
445 #ifdef SK_REPORT_API_RANGE_CHECK | 457 #ifdef SK_REPORT_API_RANGE_CHECK |
446 SkDebugf("SkPaint::setTextEncoding(%d) out of range\n", encoding); | 458 SkDebugf("SkPaint::setTextEncoding(%d) out of range\n", encoding); |
447 #endif | 459 #endif |
448 } | 460 } |
449 } | 461 } |
450 | 462 |
451 /////////////////////////////////////////////////////////////////////////////// | 463 /////////////////////////////////////////////////////////////////////////////// |
452 | 464 |
453 // Returns dst with the given bitmask enabled or disabled, depending on value. | 465 // Returns dst with the given bitmask enabled or disabled, depending on value. |
454 inline static uint32_t set_mask(uint32_t dst, uint32_t bitmask, bool value) { | 466 inline static uint32_t set_mask(uint32_t dst, uint32_t bitmask, bool value) { |
455 return value ? (dst | bitmask) : (dst & ~bitmask); | 467 return value ? (dst | bitmask) : (dst & ~bitmask); |
456 } | 468 } |
457 | 469 |
458 SkTypeface* SkPaint::setTypeface(SkTypeface* font) { | 470 SkTypeface* SkPaint::setTypeface(SkTypeface* typeface) { |
459 SkRefCnt_SafeAssign(fTypeface, font); | 471 this->dirtyCachedFont(typeface != fTypeface); |
| 472 SkRefCnt_SafeAssign(fTypeface, typeface); |
460 GEN_ID_INC; | 473 GEN_ID_INC; |
461 fDirtyBits = set_mask(fDirtyBits, kTypeface_DirtyBit, font != NULL); | 474 fDirtyBits = set_mask(fDirtyBits, kTypeface_DirtyBit, typeface != NULL); |
462 return font; | 475 return typeface; |
463 } | 476 } |
464 | 477 |
465 SkRasterizer* SkPaint::setRasterizer(SkRasterizer* r) { | 478 SkRasterizer* SkPaint::setRasterizer(SkRasterizer* r) { |
466 SkRefCnt_SafeAssign(fRasterizer, r); | 479 SkRefCnt_SafeAssign(fRasterizer, r); |
467 GEN_ID_INC; | 480 GEN_ID_INC; |
468 fDirtyBits = set_mask(fDirtyBits, kRasterizer_DirtyBit, r != NULL); | 481 fDirtyBits = set_mask(fDirtyBits, kRasterizer_DirtyBit, r != NULL); |
469 return r; | 482 return r; |
470 } | 483 } |
471 | 484 |
472 SkDrawLooper* SkPaint::setLooper(SkDrawLooper* looper) { | 485 SkDrawLooper* SkPaint::setLooper(SkDrawLooper* looper) { |
(...skipping 2261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2734 } | 2747 } |
2735 #ifdef SK_BUILD_FOR_ANDROID | 2748 #ifdef SK_BUILD_FOR_ANDROID |
2736 if (dirty & kPaintOptionsAndroid_DirtyBit) { | 2749 if (dirty & kPaintOptionsAndroid_DirtyBit) { |
2737 SkPaintOptionsAndroid options; | 2750 SkPaintOptionsAndroid options; |
2738 options.unflatten(buffer); | 2751 options.unflatten(buffer); |
2739 paint->setPaintOptionsAndroid(options); | 2752 paint->setPaintOptionsAndroid(options); |
2740 } | 2753 } |
2741 #endif | 2754 #endif |
2742 SkASSERT(dirty == paint->fDirtyBits); | 2755 SkASSERT(dirty == paint->fDirtyBits); |
2743 } | 2756 } |
OLD | NEW |