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 17 matching lines...) Expand all Loading... |
28 #include "SkScalerContext.h" | 28 #include "SkScalerContext.h" |
29 #include "SkShader.h" | 29 #include "SkShader.h" |
30 #include "SkStringUtils.h" | 30 #include "SkStringUtils.h" |
31 #include "SkStroke.h" | 31 #include "SkStroke.h" |
32 #include "SkTextFormatParams.h" | 32 #include "SkTextFormatParams.h" |
33 #include "SkTextToPathIter.h" | 33 #include "SkTextToPathIter.h" |
34 #include "SkTLazy.h" | 34 #include "SkTLazy.h" |
35 #include "SkTypeface.h" | 35 #include "SkTypeface.h" |
36 #include "SkXfermode.h" | 36 #include "SkXfermode.h" |
37 | 37 |
38 enum { | |
39 kColor_DirtyBit = 1 << 0, | |
40 kBitfields_DirtyBit = 1 << 1, | |
41 kTextSize_DirtyBit = 1 << 2, | |
42 kTextScaleX_DirtyBit = 1 << 3, | |
43 kTextSkewX_DirtyBit = 1 << 4, | |
44 kStrokeWidth_DirtyBit = 1 << 5, | |
45 kStrokeMiter_DirtyBit = 1 << 6, | |
46 kPathEffect_DirtyBit = 1 << 7, | |
47 kShader_DirtyBit = 1 << 8, | |
48 kXfermode_DirtyBit = 1 << 9, | |
49 kMaskFilter_DirtyBit = 1 << 10, | |
50 kColorFilter_DirtyBit = 1 << 11, | |
51 kRasterizer_DirtyBit = 1 << 12, | |
52 kLooper_DirtyBit = 1 << 13, | |
53 kImageFilter_DirtyBit = 1 << 14, | |
54 kTypeface_DirtyBit = 1 << 15, | |
55 kAnnotation_DirtyBit = 1 << 16, | |
56 kPaintOptionsAndroid_DirtyBit = 1 << 17, | |
57 }; | |
58 | 38 |
59 // define this to get a printf for out-of-range parameter in setters | 39 // define this to get a printf for out-of-range parameter in setters |
60 // e.g. setTextSize(-1) | 40 // e.g. setTextSize(-1) |
61 //#define SK_REPORT_API_RANGE_CHECK | 41 //#define SK_REPORT_API_RANGE_CHECK |
62 | 42 |
63 #ifdef SK_BUILD_FOR_ANDROID | 43 #ifdef SK_BUILD_FOR_ANDROID |
64 #define GEN_ID_INC fGenerationID++ | 44 #define GEN_ID_INC fGenerationID++ |
65 #define GEN_ID_INC_EVAL(expression) if (expression) { fGenerationID++; } | 45 #define GEN_ID_INC_EVAL(expression) if (expression) { fGenerationID++; } |
66 #else | 46 #else |
67 #define GEN_ID_INC | 47 #define GEN_ID_INC |
68 #define GEN_ID_INC_EVAL(expression) | 48 #define GEN_ID_INC_EVAL(expression) |
69 #endif | 49 #endif |
70 | 50 |
71 SkPaint::SkPaint() { | 51 SkPaint::SkPaint() { |
72 // since we may have padding, we zero everything so that our memcmp() call | 52 // since we may have padding, we zero everything so that our memcmp() call |
73 // in operator== will work correctly. | 53 // in operator== will work correctly. |
74 // with this, we can skip 0 and null individual initializations | 54 // with this, we can skip 0 and null individual initializations |
75 sk_bzero(this, sizeof(*this)); | 55 sk_bzero(this, sizeof(*this)); |
76 | 56 |
77 #if 0 // not needed with the bzero call above | 57 #if 0 // not needed with the bzero call above |
78 fTypeface = NULL; | 58 fTypeface = NULL; |
79 fTextSkewX = 0; | 59 fTextSkewX = 0; |
80 fPathEffect = NULL; | 60 fPathEffect = NULL; |
81 fShader = NULL; | 61 fShader = NULL; |
82 fXfermode = NULL; | 62 fXfermode = NULL; |
83 fMaskFilter = NULL; | 63 fMaskFilter = NULL; |
84 fColorFilter = NULL; | 64 fColorFilter = NULL; |
85 fRasterizer = NULL; | 65 fRasterizer = NULL; |
86 fLooper = NULL; | 66 fLooper = NULL; |
87 fImageFilter = NULL; | 67 fImageFilter = NULL; |
88 fAnnotation = NULL; | 68 fAnnotation = NULL; |
89 fWidth = 0; | 69 fWidth = 0; |
90 fDirtyBits = 0; | |
91 #endif | 70 #endif |
92 | 71 |
93 fTextSize = SkPaintDefaults_TextSize; | 72 fTextSize = SkPaintDefaults_TextSize; |
94 fTextScaleX = SK_Scalar1; | 73 fTextScaleX = SK_Scalar1; |
95 fColor = SK_ColorBLACK; | 74 fColor = SK_ColorBLACK; |
96 fMiterLimit = SkPaintDefaults_MiterLimit; | 75 fMiterLimit = SkPaintDefaults_MiterLimit; |
97 fFlags = SkPaintDefaults_Flags; | 76 fFlags = SkPaintDefaults_Flags; |
98 fCapType = kDefault_Cap; | 77 fCapType = kDefault_Cap; |
99 fJoinType = kDefault_Join; | 78 fJoinType = kDefault_Join; |
100 fTextAlign = kLeft_Align; | 79 fTextAlign = kLeft_Align; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 unsigned SkPaint::getBaseGlyphCount(SkUnichar text) const { | 191 unsigned SkPaint::getBaseGlyphCount(SkUnichar text) const { |
213 SkAutoGlyphCache autoCache(*this, NULL, NULL); | 192 SkAutoGlyphCache autoCache(*this, NULL, NULL); |
214 SkGlyphCache* cache = autoCache.getCache(); | 193 SkGlyphCache* cache = autoCache.getCache(); |
215 return cache->getBaseGlyphCount(text); | 194 return cache->getBaseGlyphCount(text); |
216 } | 195 } |
217 | 196 |
218 void SkPaint::setPaintOptionsAndroid(const SkPaintOptionsAndroid& options) { | 197 void SkPaint::setPaintOptionsAndroid(const SkPaintOptionsAndroid& options) { |
219 if (options != fPaintOptionsAndroid) { | 198 if (options != fPaintOptionsAndroid) { |
220 fPaintOptionsAndroid = options; | 199 fPaintOptionsAndroid = options; |
221 GEN_ID_INC; | 200 GEN_ID_INC; |
222 fDirtyBits |= kPaintOptionsAndroid_DirtyBit; | |
223 } | 201 } |
224 } | 202 } |
225 #endif | 203 #endif |
226 | 204 |
227 SkPaint::FilterLevel SkPaint::getFilterLevel() const { | 205 SkPaint::FilterLevel SkPaint::getFilterLevel() const { |
228 int level = 0; | 206 int level = 0; |
229 if (fFlags & kFilterBitmap_Flag) { | 207 if (fFlags & kFilterBitmap_Flag) { |
230 level |= 1; | 208 level |= 1; |
231 } | 209 } |
232 if (fFlags & kHighQualityFilterBitmap_Flag) { | 210 if (fFlags & kHighQualityFilterBitmap_Flag) { |
(...skipping 10 matching lines...) Expand all Loading... |
243 } | 221 } |
244 if (level & 2) { | 222 if (level & 2) { |
245 flags |= kHighQualityFilterBitmap_Flag; | 223 flags |= kHighQualityFilterBitmap_Flag; |
246 } | 224 } |
247 this->setFlags((fFlags & ~mask) | flags); | 225 this->setFlags((fFlags & ~mask) | flags); |
248 } | 226 } |
249 | 227 |
250 void SkPaint::setHinting(Hinting hintingLevel) { | 228 void SkPaint::setHinting(Hinting hintingLevel) { |
251 GEN_ID_INC_EVAL((unsigned) hintingLevel != fHinting); | 229 GEN_ID_INC_EVAL((unsigned) hintingLevel != fHinting); |
252 fHinting = hintingLevel; | 230 fHinting = hintingLevel; |
253 fDirtyBits |= kBitfields_DirtyBit; | |
254 } | 231 } |
255 | 232 |
256 void SkPaint::setFlags(uint32_t flags) { | 233 void SkPaint::setFlags(uint32_t flags) { |
257 GEN_ID_INC_EVAL(fFlags != flags); | 234 GEN_ID_INC_EVAL(fFlags != flags); |
258 fFlags = flags; | 235 fFlags = flags; |
259 fDirtyBits |= kBitfields_DirtyBit; | |
260 } | 236 } |
261 | 237 |
262 void SkPaint::setAntiAlias(bool doAA) { | 238 void SkPaint::setAntiAlias(bool doAA) { |
263 this->setFlags(SkSetClearMask(fFlags, doAA, kAntiAlias_Flag)); | 239 this->setFlags(SkSetClearMask(fFlags, doAA, kAntiAlias_Flag)); |
264 } | 240 } |
265 | 241 |
266 void SkPaint::setDither(bool doDither) { | 242 void SkPaint::setDither(bool doDither) { |
267 this->setFlags(SkSetClearMask(fFlags, doDither, kDither_Flag)); | 243 this->setFlags(SkSetClearMask(fFlags, doDither, kDither_Flag)); |
268 } | 244 } |
269 | 245 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 } | 280 } |
305 | 281 |
306 void SkPaint::setDevKernText(bool doDevKern) { | 282 void SkPaint::setDevKernText(bool doDevKern) { |
307 this->setFlags(SkSetClearMask(fFlags, doDevKern, kDevKernText_Flag)); | 283 this->setFlags(SkSetClearMask(fFlags, doDevKern, kDevKernText_Flag)); |
308 } | 284 } |
309 | 285 |
310 void SkPaint::setStyle(Style style) { | 286 void SkPaint::setStyle(Style style) { |
311 if ((unsigned)style < kStyleCount) { | 287 if ((unsigned)style < kStyleCount) { |
312 GEN_ID_INC_EVAL((unsigned)style != fStyle); | 288 GEN_ID_INC_EVAL((unsigned)style != fStyle); |
313 fStyle = style; | 289 fStyle = style; |
314 fDirtyBits |= kBitfields_DirtyBit; | |
315 } else { | 290 } else { |
316 #ifdef SK_REPORT_API_RANGE_CHECK | 291 #ifdef SK_REPORT_API_RANGE_CHECK |
317 SkDebugf("SkPaint::setStyle(%d) out of range\n", style); | 292 SkDebugf("SkPaint::setStyle(%d) out of range\n", style); |
318 #endif | 293 #endif |
319 } | 294 } |
320 } | 295 } |
321 | 296 |
322 void SkPaint::setColor(SkColor color) { | 297 void SkPaint::setColor(SkColor color) { |
323 GEN_ID_INC_EVAL(color != fColor); | 298 GEN_ID_INC_EVAL(color != fColor); |
324 fColor = color; | 299 fColor = color; |
325 fDirtyBits |= kColor_DirtyBit; | |
326 } | 300 } |
327 | 301 |
328 void SkPaint::setAlpha(U8CPU a) { | 302 void SkPaint::setAlpha(U8CPU a) { |
329 this->setColor(SkColorSetARGB(a, SkColorGetR(fColor), | 303 this->setColor(SkColorSetARGB(a, SkColorGetR(fColor), |
330 SkColorGetG(fColor), SkColorGetB(fColor))); | 304 SkColorGetG(fColor), SkColorGetB(fColor))); |
331 } | 305 } |
332 | 306 |
333 void SkPaint::setARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) { | 307 void SkPaint::setARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) { |
334 this->setColor(SkColorSetARGB(a, r, g, b)); | 308 this->setColor(SkColorSetARGB(a, r, g, b)); |
335 } | 309 } |
336 | 310 |
337 void SkPaint::setStrokeWidth(SkScalar width) { | 311 void SkPaint::setStrokeWidth(SkScalar width) { |
338 if (width >= 0) { | 312 if (width >= 0) { |
339 GEN_ID_INC_EVAL(width != fWidth); | 313 GEN_ID_INC_EVAL(width != fWidth); |
340 fWidth = width; | 314 fWidth = width; |
341 fDirtyBits |= kStrokeWidth_DirtyBit; | |
342 } else { | 315 } else { |
343 #ifdef SK_REPORT_API_RANGE_CHECK | 316 #ifdef SK_REPORT_API_RANGE_CHECK |
344 SkDebugf("SkPaint::setStrokeWidth() called with negative value\n"); | 317 SkDebugf("SkPaint::setStrokeWidth() called with negative value\n"); |
345 #endif | 318 #endif |
346 } | 319 } |
347 } | 320 } |
348 | 321 |
349 void SkPaint::setStrokeMiter(SkScalar limit) { | 322 void SkPaint::setStrokeMiter(SkScalar limit) { |
350 if (limit >= 0) { | 323 if (limit >= 0) { |
351 GEN_ID_INC_EVAL(limit != fMiterLimit); | 324 GEN_ID_INC_EVAL(limit != fMiterLimit); |
352 fMiterLimit = limit; | 325 fMiterLimit = limit; |
353 fDirtyBits |= kStrokeMiter_DirtyBit; | |
354 } else { | 326 } else { |
355 #ifdef SK_REPORT_API_RANGE_CHECK | 327 #ifdef SK_REPORT_API_RANGE_CHECK |
356 SkDebugf("SkPaint::setStrokeMiter() called with negative value\n"); | 328 SkDebugf("SkPaint::setStrokeMiter() called with negative value\n"); |
357 #endif | 329 #endif |
358 } | 330 } |
359 } | 331 } |
360 | 332 |
361 void SkPaint::setStrokeCap(Cap ct) { | 333 void SkPaint::setStrokeCap(Cap ct) { |
362 if ((unsigned)ct < kCapCount) { | 334 if ((unsigned)ct < kCapCount) { |
363 GEN_ID_INC_EVAL((unsigned)ct != fCapType); | 335 GEN_ID_INC_EVAL((unsigned)ct != fCapType); |
364 fCapType = SkToU8(ct); | 336 fCapType = SkToU8(ct); |
365 fDirtyBits |= kBitfields_DirtyBit; | |
366 } else { | 337 } else { |
367 #ifdef SK_REPORT_API_RANGE_CHECK | 338 #ifdef SK_REPORT_API_RANGE_CHECK |
368 SkDebugf("SkPaint::setStrokeCap(%d) out of range\n", ct); | 339 SkDebugf("SkPaint::setStrokeCap(%d) out of range\n", ct); |
369 #endif | 340 #endif |
370 } | 341 } |
371 } | 342 } |
372 | 343 |
373 void SkPaint::setStrokeJoin(Join jt) { | 344 void SkPaint::setStrokeJoin(Join jt) { |
374 if ((unsigned)jt < kJoinCount) { | 345 if ((unsigned)jt < kJoinCount) { |
375 GEN_ID_INC_EVAL((unsigned)jt != fJoinType); | 346 GEN_ID_INC_EVAL((unsigned)jt != fJoinType); |
376 fJoinType = SkToU8(jt); | 347 fJoinType = SkToU8(jt); |
377 fDirtyBits |= kBitfields_DirtyBit; | |
378 } else { | 348 } else { |
379 #ifdef SK_REPORT_API_RANGE_CHECK | 349 #ifdef SK_REPORT_API_RANGE_CHECK |
380 SkDebugf("SkPaint::setStrokeJoin(%d) out of range\n", jt); | 350 SkDebugf("SkPaint::setStrokeJoin(%d) out of range\n", jt); |
381 #endif | 351 #endif |
382 } | 352 } |
383 } | 353 } |
384 | 354 |
385 /////////////////////////////////////////////////////////////////////////////// | 355 /////////////////////////////////////////////////////////////////////////////// |
386 | 356 |
387 void SkPaint::setTextAlign(Align align) { | 357 void SkPaint::setTextAlign(Align align) { |
388 if ((unsigned)align < kAlignCount) { | 358 if ((unsigned)align < kAlignCount) { |
389 GEN_ID_INC_EVAL((unsigned)align != fTextAlign); | 359 GEN_ID_INC_EVAL((unsigned)align != fTextAlign); |
390 fTextAlign = SkToU8(align); | 360 fTextAlign = SkToU8(align); |
391 fDirtyBits |= kBitfields_DirtyBit; | |
392 } else { | 361 } else { |
393 #ifdef SK_REPORT_API_RANGE_CHECK | 362 #ifdef SK_REPORT_API_RANGE_CHECK |
394 SkDebugf("SkPaint::setTextAlign(%d) out of range\n", align); | 363 SkDebugf("SkPaint::setTextAlign(%d) out of range\n", align); |
395 #endif | 364 #endif |
396 } | 365 } |
397 } | 366 } |
398 | 367 |
399 void SkPaint::setTextSize(SkScalar ts) { | 368 void SkPaint::setTextSize(SkScalar ts) { |
400 if (ts >= 0) { | 369 if (ts >= 0) { |
401 GEN_ID_INC_EVAL(ts != fTextSize); | 370 GEN_ID_INC_EVAL(ts != fTextSize); |
402 fTextSize = ts; | 371 fTextSize = ts; |
403 fDirtyBits |= kTextSize_DirtyBit; | |
404 } else { | 372 } else { |
405 #ifdef SK_REPORT_API_RANGE_CHECK | 373 #ifdef SK_REPORT_API_RANGE_CHECK |
406 SkDebugf("SkPaint::setTextSize() called with negative value\n"); | 374 SkDebugf("SkPaint::setTextSize() called with negative value\n"); |
407 #endif | 375 #endif |
408 } | 376 } |
409 } | 377 } |
410 | 378 |
411 void SkPaint::setTextScaleX(SkScalar scaleX) { | 379 void SkPaint::setTextScaleX(SkScalar scaleX) { |
412 GEN_ID_INC_EVAL(scaleX != fTextScaleX); | 380 GEN_ID_INC_EVAL(scaleX != fTextScaleX); |
413 fTextScaleX = scaleX; | 381 fTextScaleX = scaleX; |
414 fDirtyBits |= kTextScaleX_DirtyBit; | |
415 } | 382 } |
416 | 383 |
417 void SkPaint::setTextSkewX(SkScalar skewX) { | 384 void SkPaint::setTextSkewX(SkScalar skewX) { |
418 GEN_ID_INC_EVAL(skewX != fTextSkewX); | 385 GEN_ID_INC_EVAL(skewX != fTextSkewX); |
419 fTextSkewX = skewX; | 386 fTextSkewX = skewX; |
420 fDirtyBits |= kTextSkewX_DirtyBit; | |
421 } | 387 } |
422 | 388 |
423 void SkPaint::setTextEncoding(TextEncoding encoding) { | 389 void SkPaint::setTextEncoding(TextEncoding encoding) { |
424 if ((unsigned)encoding <= kGlyphID_TextEncoding) { | 390 if ((unsigned)encoding <= kGlyphID_TextEncoding) { |
425 GEN_ID_INC_EVAL((unsigned)encoding != fTextEncoding); | 391 GEN_ID_INC_EVAL((unsigned)encoding != fTextEncoding); |
426 fTextEncoding = encoding; | 392 fTextEncoding = encoding; |
427 fDirtyBits |= kBitfields_DirtyBit; | |
428 } else { | 393 } else { |
429 #ifdef SK_REPORT_API_RANGE_CHECK | 394 #ifdef SK_REPORT_API_RANGE_CHECK |
430 SkDebugf("SkPaint::setTextEncoding(%d) out of range\n", encoding); | 395 SkDebugf("SkPaint::setTextEncoding(%d) out of range\n", encoding); |
431 #endif | 396 #endif |
432 } | 397 } |
433 } | 398 } |
434 | 399 |
435 /////////////////////////////////////////////////////////////////////////////// | 400 /////////////////////////////////////////////////////////////////////////////// |
436 | 401 |
437 // Returns dst with the given bitmask enabled or disabled, depending on value. | |
438 inline static uint32_t set_mask(uint32_t dst, uint32_t bitmask, bool value) { | |
439 return value ? (dst | bitmask) : (dst & ~bitmask); | |
440 } | |
441 | |
442 SkTypeface* SkPaint::setTypeface(SkTypeface* font) { | 402 SkTypeface* SkPaint::setTypeface(SkTypeface* font) { |
443 SkRefCnt_SafeAssign(fTypeface, font); | 403 SkRefCnt_SafeAssign(fTypeface, font); |
444 GEN_ID_INC; | 404 GEN_ID_INC; |
445 fDirtyBits = set_mask(fDirtyBits, kTypeface_DirtyBit, font != NULL); | |
446 return font; | 405 return font; |
447 } | 406 } |
448 | 407 |
449 SkRasterizer* SkPaint::setRasterizer(SkRasterizer* r) { | 408 SkRasterizer* SkPaint::setRasterizer(SkRasterizer* r) { |
450 SkRefCnt_SafeAssign(fRasterizer, r); | 409 SkRefCnt_SafeAssign(fRasterizer, r); |
451 GEN_ID_INC; | 410 GEN_ID_INC; |
452 fDirtyBits = set_mask(fDirtyBits, kRasterizer_DirtyBit, r != NULL); | |
453 return r; | 411 return r; |
454 } | 412 } |
455 | 413 |
456 SkDrawLooper* SkPaint::setLooper(SkDrawLooper* looper) { | 414 SkDrawLooper* SkPaint::setLooper(SkDrawLooper* looper) { |
457 SkRefCnt_SafeAssign(fLooper, looper); | 415 SkRefCnt_SafeAssign(fLooper, looper); |
458 GEN_ID_INC; | 416 GEN_ID_INC; |
459 fDirtyBits = set_mask(fDirtyBits, kLooper_DirtyBit, looper != NULL); | |
460 return looper; | 417 return looper; |
461 } | 418 } |
462 | 419 |
463 SkImageFilter* SkPaint::setImageFilter(SkImageFilter* imageFilter) { | 420 SkImageFilter* SkPaint::setImageFilter(SkImageFilter* imageFilter) { |
464 SkRefCnt_SafeAssign(fImageFilter, imageFilter); | 421 SkRefCnt_SafeAssign(fImageFilter, imageFilter); |
465 GEN_ID_INC; | 422 GEN_ID_INC; |
466 fDirtyBits = set_mask(fDirtyBits, kImageFilter_DirtyBit, imageFilter != NULL
); | |
467 return imageFilter; | 423 return imageFilter; |
468 } | 424 } |
469 | 425 |
470 SkAnnotation* SkPaint::setAnnotation(SkAnnotation* annotation) { | 426 SkAnnotation* SkPaint::setAnnotation(SkAnnotation* annotation) { |
471 SkRefCnt_SafeAssign(fAnnotation, annotation); | 427 SkRefCnt_SafeAssign(fAnnotation, annotation); |
472 GEN_ID_INC; | 428 GEN_ID_INC; |
473 fDirtyBits = set_mask(fDirtyBits, kAnnotation_DirtyBit, annotation != NULL); | |
474 return annotation; | 429 return annotation; |
475 } | 430 } |
476 | 431 |
477 /////////////////////////////////////////////////////////////////////////////// | 432 /////////////////////////////////////////////////////////////////////////////// |
478 | 433 |
479 static SkScalar mag2(SkScalar x, SkScalar y) { | 434 static SkScalar mag2(SkScalar x, SkScalar y) { |
480 return x * x + y * y; | 435 return x * x + y * y; |
481 } | 436 } |
482 | 437 |
483 static bool tooBig(const SkMatrix& m, SkScalar ma2max) { | 438 static bool tooBig(const SkMatrix& m, SkScalar ma2max) { |
(...skipping 1703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2187 this->setPaintOptionsAndroid(options); | 2142 this->setPaintOptionsAndroid(options); |
2188 #endif | 2143 #endif |
2189 } | 2144 } |
2190 } | 2145 } |
2191 | 2146 |
2192 /////////////////////////////////////////////////////////////////////////////// | 2147 /////////////////////////////////////////////////////////////////////////////// |
2193 | 2148 |
2194 SkShader* SkPaint::setShader(SkShader* shader) { | 2149 SkShader* SkPaint::setShader(SkShader* shader) { |
2195 GEN_ID_INC_EVAL(shader != fShader); | 2150 GEN_ID_INC_EVAL(shader != fShader); |
2196 SkRefCnt_SafeAssign(fShader, shader); | 2151 SkRefCnt_SafeAssign(fShader, shader); |
2197 fDirtyBits = set_mask(fDirtyBits, kShader_DirtyBit, shader != NULL); | |
2198 return shader; | 2152 return shader; |
2199 } | 2153 } |
2200 | 2154 |
2201 SkColorFilter* SkPaint::setColorFilter(SkColorFilter* filter) { | 2155 SkColorFilter* SkPaint::setColorFilter(SkColorFilter* filter) { |
2202 GEN_ID_INC_EVAL(filter != fColorFilter); | 2156 GEN_ID_INC_EVAL(filter != fColorFilter); |
2203 SkRefCnt_SafeAssign(fColorFilter, filter); | 2157 SkRefCnt_SafeAssign(fColorFilter, filter); |
2204 fDirtyBits = set_mask(fDirtyBits, kColorFilter_DirtyBit, filter != NULL); | |
2205 return filter; | 2158 return filter; |
2206 } | 2159 } |
2207 | 2160 |
2208 SkXfermode* SkPaint::setXfermode(SkXfermode* mode) { | 2161 SkXfermode* SkPaint::setXfermode(SkXfermode* mode) { |
2209 GEN_ID_INC_EVAL(mode != fXfermode); | 2162 GEN_ID_INC_EVAL(mode != fXfermode); |
2210 SkRefCnt_SafeAssign(fXfermode, mode); | 2163 SkRefCnt_SafeAssign(fXfermode, mode); |
2211 fDirtyBits = set_mask(fDirtyBits, kXfermode_DirtyBit, mode != NULL); | |
2212 return mode; | 2164 return mode; |
2213 } | 2165 } |
2214 | 2166 |
2215 SkXfermode* SkPaint::setXfermodeMode(SkXfermode::Mode mode) { | 2167 SkXfermode* SkPaint::setXfermodeMode(SkXfermode::Mode mode) { |
2216 SkSafeUnref(fXfermode); | 2168 SkSafeUnref(fXfermode); |
2217 fXfermode = SkXfermode::Create(mode); | 2169 fXfermode = SkXfermode::Create(mode); |
2218 GEN_ID_INC; | 2170 GEN_ID_INC; |
2219 fDirtyBits = set_mask(fDirtyBits, kXfermode_DirtyBit, fXfermode != NULL); | |
2220 return fXfermode; | 2171 return fXfermode; |
2221 } | 2172 } |
2222 | 2173 |
2223 SkPathEffect* SkPaint::setPathEffect(SkPathEffect* effect) { | 2174 SkPathEffect* SkPaint::setPathEffect(SkPathEffect* effect) { |
2224 GEN_ID_INC_EVAL(effect != fPathEffect); | 2175 GEN_ID_INC_EVAL(effect != fPathEffect); |
2225 SkRefCnt_SafeAssign(fPathEffect, effect); | 2176 SkRefCnt_SafeAssign(fPathEffect, effect); |
2226 fDirtyBits = set_mask(fDirtyBits, kPathEffect_DirtyBit, effect != NULL); | |
2227 return effect; | 2177 return effect; |
2228 } | 2178 } |
2229 | 2179 |
2230 SkMaskFilter* SkPaint::setMaskFilter(SkMaskFilter* filter) { | 2180 SkMaskFilter* SkPaint::setMaskFilter(SkMaskFilter* filter) { |
2231 GEN_ID_INC_EVAL(filter != fMaskFilter); | 2181 GEN_ID_INC_EVAL(filter != fMaskFilter); |
2232 SkRefCnt_SafeAssign(fMaskFilter, filter); | 2182 SkRefCnt_SafeAssign(fMaskFilter, filter); |
2233 fDirtyBits = set_mask(fDirtyBits, kMaskFilter_DirtyBit, filter != NULL); | |
2234 return filter; | 2183 return filter; |
2235 } | 2184 } |
2236 | 2185 |
2237 /////////////////////////////////////////////////////////////////////////////// | 2186 /////////////////////////////////////////////////////////////////////////////// |
2238 | 2187 |
2239 bool SkPaint::getFillPath(const SkPath& src, SkPath* dst, | 2188 bool SkPaint::getFillPath(const SkPath& src, SkPath* dst, |
2240 const SkRect* cullRect) const { | 2189 const SkRect* cullRect) const { |
2241 SkStrokeRec rec(*this); | 2190 SkStrokeRec rec(*this); |
2242 | 2191 |
2243 const SkPath* srcPtr = &src; | 2192 const SkPath* srcPtr = &src; |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2594 case SkXfermode::kPlus_Mode: | 2543 case SkXfermode::kPlus_Mode: |
2595 return 0 == this->getAlpha(); | 2544 return 0 == this->getAlpha(); |
2596 case SkXfermode::kDst_Mode: | 2545 case SkXfermode::kDst_Mode: |
2597 return true; | 2546 return true; |
2598 default: | 2547 default: |
2599 break; | 2548 break; |
2600 } | 2549 } |
2601 } | 2550 } |
2602 return false; | 2551 return false; |
2603 } | 2552 } |
2604 | |
2605 void SkPaint::setBitfields(uint32_t bitfields) { | |
2606 fBitfields = bitfields; | |
2607 fDirtyBits |= kBitfields_DirtyBit; | |
2608 } | |
2609 | |
2610 inline static unsigned popcount(uint8_t x) { | |
2611 // As in Hacker's delight, adapted for just 8 bits. | |
2612 x = (x & 0x55) + ((x >> 1) & 0x55); // a b c d w x y z -> a+b c+d w+x y+z | |
2613 x = (x & 0x33) + ((x >> 2) & 0x33); // a+b c+d w+x y+z -> a+b+c+d w+x+y+z | |
2614 x = (x & 0x0F) + ((x >> 4) & 0x0F); // a+b+c+d w+x+y+z -> a+b+c+d+w+x+y+z | |
2615 return x; | |
2616 } | |
2617 | |
2618 void SkPaint::FlatteningTraits::Flatten(SkWriteBuffer& buffer, const SkPaint& pa
int) { | |
2619 const uint32_t dirty = paint.fDirtyBits; | |
2620 | |
2621 // Each of the low 7 dirty bits corresponds to a 4-byte flat value, plus one
for the dirty bits. | |
2622 const size_t flatBytes = 4 * (popcount(dirty & 127) + 1); | |
2623 SkASSERT(flatBytes <= 32); | |
2624 uint32_t* u32 = buffer.reserve(flatBytes); | |
2625 *u32++ = dirty; | |
2626 if (dirty == 0) { | |
2627 return; | |
2628 } | |
2629 | |
2630 #define F(dst, field) if (dirty & k##field##_DirtyBit) *dst++ = paint.get##field
() | |
2631 F(u32, Color); | |
2632 F(u32, Bitfields); | |
2633 SkScalar* f32 = reinterpret_cast<SkScalar*>(u32); | |
2634 F(f32, TextSize); | |
2635 F(f32, TextScaleX); | |
2636 F(f32, TextSkewX); | |
2637 F(f32, StrokeWidth); | |
2638 F(f32, StrokeMiter); | |
2639 #undef F | |
2640 #define F(field) if (dirty & k##field##_DirtyBit) buffer.writeFlattenable(paint.
get##field()) | |
2641 F(PathEffect); | |
2642 F(Shader); | |
2643 F(Xfermode); | |
2644 F(MaskFilter); | |
2645 F(ColorFilter); | |
2646 F(Rasterizer); | |
2647 F(Looper); | |
2648 F(ImageFilter); | |
2649 #undef F | |
2650 if (dirty & kTypeface_DirtyBit) buffer.writeTypeface(paint.getTypeface()); | |
2651 if (dirty & kAnnotation_DirtyBit) paint.getAnnotation()->writeToBuffer(buffe
r); | |
2652 #ifdef SK_BUILD_FOR_ANDROID | |
2653 if (dirty & kPaintOptionsAndroid_DirtyBit) paint.getPaintOptionsAndroid().fl
atten(buffer); | |
2654 #endif | |
2655 } | |
2656 | |
2657 void SkPaint::FlatteningTraits::Unflatten(SkReadBuffer& buffer, SkPaint* paint)
{ | |
2658 const uint32_t dirty = buffer.readUInt(); | |
2659 if (dirty == 0) { | |
2660 return; | |
2661 } | |
2662 #define F(field, reader) if (dirty & k##field##_DirtyBit) paint->set##field(buff
er.reader()) | |
2663 F(Color, readUInt); | |
2664 F(Bitfields, readUInt); | |
2665 F(TextSize, readScalar); | |
2666 F(TextScaleX, readScalar); | |
2667 F(TextSkewX, readScalar); | |
2668 F(StrokeWidth, readScalar); | |
2669 F(StrokeMiter, readScalar); | |
2670 F(PathEffect, readPathEffect); | |
2671 F(Shader, readShader); | |
2672 F(Xfermode, readXfermode); | |
2673 F(MaskFilter, readMaskFilter); | |
2674 F(ColorFilter, readColorFilter); | |
2675 F(Rasterizer, readRasterizer); | |
2676 F(Looper, readDrawLooper); | |
2677 F(ImageFilter, readImageFilter); | |
2678 F(Typeface, readTypeface); | |
2679 #undef F | |
2680 if (dirty & kAnnotation_DirtyBit) { | |
2681 paint->setAnnotation(SkNEW_ARGS(SkAnnotation, (buffer)))->unref(); | |
2682 } | |
2683 #ifdef SK_BUILD_FOR_ANDROID | |
2684 if (dirty & kPaintOptionsAndroid_DirtyBit) { | |
2685 SkPaintOptionsAndroid options; | |
2686 options.unflatten(buffer); | |
2687 paint->setPaintOptionsAndroid(options); | |
2688 } | |
2689 #endif | |
2690 SkASSERT(dirty == paint->fDirtyBits); | |
2691 } | |
OLD | NEW |