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

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

Issue 595583003: Make a flipped fDirtyBit always mean "this field is not the default". (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « no previous file | tests/PaintTest.cpp » ('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 * 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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 #endif 183 #endif
184 184
185 return *this; 185 return *this;
186 186
187 #undef COPY 187 #undef COPY
188 #undef REF_COPY 188 #undef REF_COPY
189 } 189 }
190 190
191 bool operator==(const SkPaint& a, const SkPaint& b) { 191 bool operator==(const SkPaint& a, const SkPaint& b) {
192 #define EQUAL(field) (a.field == b.field) 192 #define EQUAL(field) (a.field == b.field)
193 // Don't check fGenerationID or fDirtyBits, which can be different for logic ally equal paints. 193 // Don't check fGenerationID, which can be different for logically equal pai nts.
194 return EQUAL(fTypeface) 194 // fDirtyBits is a very quick check for non-equality, so check it first.
195 return EQUAL(fDirtyBits)
196 && EQUAL(fTypeface)
195 && EQUAL(fPathEffect) 197 && EQUAL(fPathEffect)
196 && EQUAL(fShader) 198 && EQUAL(fShader)
197 && EQUAL(fXfermode) 199 && EQUAL(fXfermode)
198 && EQUAL(fMaskFilter) 200 && EQUAL(fMaskFilter)
199 && EQUAL(fColorFilter) 201 && EQUAL(fColorFilter)
200 && EQUAL(fRasterizer) 202 && EQUAL(fRasterizer)
201 && EQUAL(fLooper) 203 && EQUAL(fLooper)
202 && EQUAL(fImageFilter) 204 && EQUAL(fImageFilter)
203 && EQUAL(fAnnotation) 205 && EQUAL(fAnnotation)
204 && EQUAL(fTextSize) 206 && EQUAL(fTextSize)
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 } else { 310 } else {
309 #ifdef SK_REPORT_API_RANGE_CHECK 311 #ifdef SK_REPORT_API_RANGE_CHECK
310 SkDebugf("SkPaint::setStyle(%d) out of range\n", style); 312 SkDebugf("SkPaint::setStyle(%d) out of range\n", style);
311 #endif 313 #endif
312 } 314 }
313 } 315 }
314 316
315 void SkPaint::setColor(SkColor color) { 317 void SkPaint::setColor(SkColor color) {
316 GEN_ID_INC_EVAL(color != fColor); 318 GEN_ID_INC_EVAL(color != fColor);
317 fColor = color; 319 fColor = color;
318 fDirtyBits |= kColor_DirtyBit; 320 fDirtyBits = SkSetClearMask(fDirtyBits, color != SK_ColorBLACK, kColor_Dirty Bit);
319 } 321 }
320 322
321 void SkPaint::setAlpha(U8CPU a) { 323 void SkPaint::setAlpha(U8CPU a) {
322 this->setColor(SkColorSetARGB(a, SkColorGetR(fColor), 324 this->setColor(SkColorSetARGB(a, SkColorGetR(fColor),
323 SkColorGetG(fColor), SkColorGetB(fColor))); 325 SkColorGetG(fColor), SkColorGetB(fColor)));
324 } 326 }
325 327
326 void SkPaint::setARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) { 328 void SkPaint::setARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) {
327 this->setColor(SkColorSetARGB(a, r, g, b)); 329 this->setColor(SkColorSetARGB(a, r, g, b));
328 } 330 }
329 331
330 void SkPaint::setStrokeWidth(SkScalar width) { 332 void SkPaint::setStrokeWidth(SkScalar width) {
331 if (width >= 0) { 333 if (width >= 0) {
332 GEN_ID_INC_EVAL(width != fWidth); 334 GEN_ID_INC_EVAL(width != fWidth);
333 fWidth = width; 335 fWidth = width;
334 fDirtyBits |= kStrokeWidth_DirtyBit; 336 fDirtyBits = SkSetClearMask(fDirtyBits, width != 0, kStrokeWidth_DirtyBi t);
335 } else { 337 } else {
336 #ifdef SK_REPORT_API_RANGE_CHECK 338 #ifdef SK_REPORT_API_RANGE_CHECK
337 SkDebugf("SkPaint::setStrokeWidth() called with negative value\n"); 339 SkDebugf("SkPaint::setStrokeWidth() called with negative value\n");
338 #endif 340 #endif
339 } 341 }
340 } 342 }
341 343
342 void SkPaint::setStrokeMiter(SkScalar limit) { 344 void SkPaint::setStrokeMiter(SkScalar limit) {
343 if (limit >= 0) { 345 if (limit >= 0) {
344 GEN_ID_INC_EVAL(limit != fMiterLimit); 346 GEN_ID_INC_EVAL(limit != fMiterLimit);
345 fMiterLimit = limit; 347 fMiterLimit = limit;
346 fDirtyBits |= kStrokeMiter_DirtyBit; 348 fDirtyBits = SkSetClearMask(fDirtyBits,
349 limit != SkPaintDefaults_MiterLimit,
350 kStrokeMiter_DirtyBit);
347 } else { 351 } else {
348 #ifdef SK_REPORT_API_RANGE_CHECK 352 #ifdef SK_REPORT_API_RANGE_CHECK
349 SkDebugf("SkPaint::setStrokeMiter() called with negative value\n"); 353 SkDebugf("SkPaint::setStrokeMiter() called with negative value\n");
350 #endif 354 #endif
351 } 355 }
352 } 356 }
353 357
354 void SkPaint::setStrokeCap(Cap ct) { 358 void SkPaint::setStrokeCap(Cap ct) {
355 if ((unsigned)ct < kCapCount) { 359 if ((unsigned)ct < kCapCount) {
356 GEN_ID_INC_EVAL((unsigned)ct != fBitfields.fCapType); 360 GEN_ID_INC_EVAL((unsigned)ct != fBitfields.fCapType);
(...skipping 26 matching lines...) Expand all
383 #ifdef SK_REPORT_API_RANGE_CHECK 387 #ifdef SK_REPORT_API_RANGE_CHECK
384 SkDebugf("SkPaint::setTextAlign(%d) out of range\n", align); 388 SkDebugf("SkPaint::setTextAlign(%d) out of range\n", align);
385 #endif 389 #endif
386 } 390 }
387 } 391 }
388 392
389 void SkPaint::setTextSize(SkScalar ts) { 393 void SkPaint::setTextSize(SkScalar ts) {
390 if (ts >= 0) { 394 if (ts >= 0) {
391 GEN_ID_INC_EVAL(ts != fTextSize); 395 GEN_ID_INC_EVAL(ts != fTextSize);
392 fTextSize = ts; 396 fTextSize = ts;
393 fDirtyBits |= kTextSize_DirtyBit; 397 fDirtyBits = SkSetClearMask(fDirtyBits, ts != SkPaintDefaults_TextSize, kTextSize_DirtyBit);
394 } else { 398 } else {
395 #ifdef SK_REPORT_API_RANGE_CHECK 399 #ifdef SK_REPORT_API_RANGE_CHECK
396 SkDebugf("SkPaint::setTextSize() called with negative value\n"); 400 SkDebugf("SkPaint::setTextSize() called with negative value\n");
397 #endif 401 #endif
398 } 402 }
399 } 403 }
400 404
401 void SkPaint::setTextScaleX(SkScalar scaleX) { 405 void SkPaint::setTextScaleX(SkScalar scaleX) {
402 GEN_ID_INC_EVAL(scaleX != fTextScaleX); 406 GEN_ID_INC_EVAL(scaleX != fTextScaleX);
403 fTextScaleX = scaleX; 407 fTextScaleX = scaleX;
404 fDirtyBits |= kTextScaleX_DirtyBit; 408 fDirtyBits = SkSetClearMask(fDirtyBits, scaleX != SK_Scalar1, kTextScaleX_Di rtyBit);
405 } 409 }
406 410
407 void SkPaint::setTextSkewX(SkScalar skewX) { 411 void SkPaint::setTextSkewX(SkScalar skewX) {
408 GEN_ID_INC_EVAL(skewX != fTextSkewX); 412 GEN_ID_INC_EVAL(skewX != fTextSkewX);
409 fTextSkewX = skewX; 413 fTextSkewX = skewX;
410 fDirtyBits |= kTextSkewX_DirtyBit; 414 fDirtyBits = SkSetClearMask(fDirtyBits, skewX != 0, kTextSkewX_DirtyBit);
411 } 415 }
412 416
413 void SkPaint::setTextEncoding(TextEncoding encoding) { 417 void SkPaint::setTextEncoding(TextEncoding encoding) {
414 if ((unsigned)encoding <= kGlyphID_TextEncoding) { 418 if ((unsigned)encoding <= kGlyphID_TextEncoding) {
415 GEN_ID_INC_EVAL((unsigned)encoding != fBitfields.fTextEncoding); 419 GEN_ID_INC_EVAL((unsigned)encoding != fBitfields.fTextEncoding);
416 fBitfields.fTextEncoding = encoding; 420 fBitfields.fTextEncoding = encoding;
417 } else { 421 } else {
418 #ifdef SK_REPORT_API_RANGE_CHECK 422 #ifdef SK_REPORT_API_RANGE_CHECK
419 SkDebugf("SkPaint::setTextEncoding(%d) out of range\n", encoding); 423 SkDebugf("SkPaint::setTextEncoding(%d) out of range\n", encoding);
420 #endif 424 #endif
421 } 425 }
422 } 426 }
423 427
424 /////////////////////////////////////////////////////////////////////////////// 428 ///////////////////////////////////////////////////////////////////////////////
425 429
426 // Returns dst with the given bitmask enabled or disabled, depending on value.
427 inline static uint32_t set_mask(uint32_t dst, uint32_t bitmask, bool value) {
428 return value ? (dst | bitmask) : (dst & ~bitmask);
429 }
430
431 SkTypeface* SkPaint::setTypeface(SkTypeface* font) { 430 SkTypeface* SkPaint::setTypeface(SkTypeface* font) {
432 SkRefCnt_SafeAssign(fTypeface, font); 431 SkRefCnt_SafeAssign(fTypeface, font);
433 GEN_ID_INC; 432 GEN_ID_INC;
434 fDirtyBits = set_mask(fDirtyBits, kTypeface_DirtyBit, font != NULL); 433 fDirtyBits = SkSetClearMask(fDirtyBits, font != NULL, kTypeface_DirtyBit);
435 return font; 434 return font;
436 } 435 }
437 436
438 SkRasterizer* SkPaint::setRasterizer(SkRasterizer* r) { 437 SkRasterizer* SkPaint::setRasterizer(SkRasterizer* r) {
439 SkRefCnt_SafeAssign(fRasterizer, r); 438 SkRefCnt_SafeAssign(fRasterizer, r);
440 GEN_ID_INC; 439 GEN_ID_INC;
441 fDirtyBits = set_mask(fDirtyBits, kRasterizer_DirtyBit, r != NULL); 440 fDirtyBits = SkSetClearMask(fDirtyBits, r != NULL, kRasterizer_DirtyBit);
442 return r; 441 return r;
443 } 442 }
444 443
445 SkDrawLooper* SkPaint::setLooper(SkDrawLooper* looper) { 444 SkDrawLooper* SkPaint::setLooper(SkDrawLooper* looper) {
446 SkRefCnt_SafeAssign(fLooper, looper); 445 SkRefCnt_SafeAssign(fLooper, looper);
447 GEN_ID_INC; 446 GEN_ID_INC;
448 fDirtyBits = set_mask(fDirtyBits, kLooper_DirtyBit, looper != NULL); 447 fDirtyBits = SkSetClearMask(fDirtyBits, looper != NULL, kLooper_DirtyBit);
449 return looper; 448 return looper;
450 } 449 }
451 450
452 SkImageFilter* SkPaint::setImageFilter(SkImageFilter* imageFilter) { 451 SkImageFilter* SkPaint::setImageFilter(SkImageFilter* imageFilter) {
453 SkRefCnt_SafeAssign(fImageFilter, imageFilter); 452 SkRefCnt_SafeAssign(fImageFilter, imageFilter);
454 GEN_ID_INC; 453 GEN_ID_INC;
455 fDirtyBits = set_mask(fDirtyBits, kImageFilter_DirtyBit, imageFilter != NULL ); 454 fDirtyBits = SkSetClearMask(fDirtyBits, imageFilter != NULL, kImageFilter_Di rtyBit);
456 return imageFilter; 455 return imageFilter;
457 } 456 }
458 457
459 SkAnnotation* SkPaint::setAnnotation(SkAnnotation* annotation) { 458 SkAnnotation* SkPaint::setAnnotation(SkAnnotation* annotation) {
460 SkRefCnt_SafeAssign(fAnnotation, annotation); 459 SkRefCnt_SafeAssign(fAnnotation, annotation);
461 GEN_ID_INC; 460 GEN_ID_INC;
462 fDirtyBits = set_mask(fDirtyBits, kAnnotation_DirtyBit, annotation != NULL); 461 fDirtyBits = SkSetClearMask(fDirtyBits, annotation != NULL, kAnnotation_Dirt yBit);
463 return annotation; 462 return annotation;
464 } 463 }
465 464
466 /////////////////////////////////////////////////////////////////////////////// 465 ///////////////////////////////////////////////////////////////////////////////
467 466
468 static SkScalar mag2(SkScalar x, SkScalar y) { 467 static SkScalar mag2(SkScalar x, SkScalar y) {
469 return x * x + y * y; 468 return x * x + y * y;
470 } 469 }
471 470
472 static bool tooBig(const SkMatrix& m, SkScalar ma2max) { 471 static bool tooBig(const SkMatrix& m, SkScalar ma2max) {
(...skipping 1726 matching lines...) Expand 10 before | Expand all | Expand 10 after
2199 buffer.readString(&tag); 2198 buffer.readString(&tag);
2200 buffer.readBool(); 2199 buffer.readBool();
2201 } 2200 }
2202 } 2201 }
2203 2202
2204 /////////////////////////////////////////////////////////////////////////////// 2203 ///////////////////////////////////////////////////////////////////////////////
2205 2204
2206 SkShader* SkPaint::setShader(SkShader* shader) { 2205 SkShader* SkPaint::setShader(SkShader* shader) {
2207 GEN_ID_INC_EVAL(shader != fShader); 2206 GEN_ID_INC_EVAL(shader != fShader);
2208 SkRefCnt_SafeAssign(fShader, shader); 2207 SkRefCnt_SafeAssign(fShader, shader);
2209 fDirtyBits = set_mask(fDirtyBits, kShader_DirtyBit, shader != NULL); 2208 fDirtyBits = SkSetClearMask(fDirtyBits, shader != NULL, kShader_DirtyBit);
2210 return shader; 2209 return shader;
2211 } 2210 }
2212 2211
2213 SkColorFilter* SkPaint::setColorFilter(SkColorFilter* filter) { 2212 SkColorFilter* SkPaint::setColorFilter(SkColorFilter* filter) {
2214 GEN_ID_INC_EVAL(filter != fColorFilter); 2213 GEN_ID_INC_EVAL(filter != fColorFilter);
2215 SkRefCnt_SafeAssign(fColorFilter, filter); 2214 SkRefCnt_SafeAssign(fColorFilter, filter);
2216 fDirtyBits = set_mask(fDirtyBits, kColorFilter_DirtyBit, filter != NULL); 2215 fDirtyBits = SkSetClearMask(fDirtyBits, filter != NULL, kColorFilter_DirtyBi t);
2217 return filter; 2216 return filter;
2218 } 2217 }
2219 2218
2220 SkXfermode* SkPaint::setXfermode(SkXfermode* mode) { 2219 SkXfermode* SkPaint::setXfermode(SkXfermode* mode) {
2221 GEN_ID_INC_EVAL(mode != fXfermode); 2220 GEN_ID_INC_EVAL(mode != fXfermode);
2222 SkRefCnt_SafeAssign(fXfermode, mode); 2221 SkRefCnt_SafeAssign(fXfermode, mode);
2223 fDirtyBits = set_mask(fDirtyBits, kXfermode_DirtyBit, mode != NULL); 2222 fDirtyBits = SkSetClearMask(fDirtyBits, mode != NULL, kXfermode_DirtyBit);
2224 return mode; 2223 return mode;
2225 } 2224 }
2226 2225
2227 SkXfermode* SkPaint::setXfermodeMode(SkXfermode::Mode mode) { 2226 SkXfermode* SkPaint::setXfermodeMode(SkXfermode::Mode mode) {
2228 SkSafeUnref(fXfermode); 2227 SkSafeUnref(fXfermode);
2229 fXfermode = SkXfermode::Create(mode); 2228 fXfermode = SkXfermode::Create(mode);
2230 GEN_ID_INC; 2229 GEN_ID_INC;
2231 fDirtyBits = set_mask(fDirtyBits, kXfermode_DirtyBit, fXfermode != NULL); 2230 fDirtyBits = SkSetClearMask(fDirtyBits, fXfermode != NULL, kXfermode_DirtyBi t);
2232 return fXfermode; 2231 return fXfermode;
2233 } 2232 }
2234 2233
2235 SkPathEffect* SkPaint::setPathEffect(SkPathEffect* effect) { 2234 SkPathEffect* SkPaint::setPathEffect(SkPathEffect* effect) {
2236 GEN_ID_INC_EVAL(effect != fPathEffect); 2235 GEN_ID_INC_EVAL(effect != fPathEffect);
2237 SkRefCnt_SafeAssign(fPathEffect, effect); 2236 SkRefCnt_SafeAssign(fPathEffect, effect);
2238 fDirtyBits = set_mask(fDirtyBits, kPathEffect_DirtyBit, effect != NULL); 2237 fDirtyBits = SkSetClearMask(fDirtyBits, effect != NULL, kPathEffect_DirtyBit );
2239 return effect; 2238 return effect;
2240 } 2239 }
2241 2240
2242 SkMaskFilter* SkPaint::setMaskFilter(SkMaskFilter* filter) { 2241 SkMaskFilter* SkPaint::setMaskFilter(SkMaskFilter* filter) {
2243 GEN_ID_INC_EVAL(filter != fMaskFilter); 2242 GEN_ID_INC_EVAL(filter != fMaskFilter);
2244 SkRefCnt_SafeAssign(fMaskFilter, filter); 2243 SkRefCnt_SafeAssign(fMaskFilter, filter);
2245 fDirtyBits = set_mask(fDirtyBits, kMaskFilter_DirtyBit, filter != NULL); 2244 fDirtyBits = SkSetClearMask(fDirtyBits, filter != NULL, kMaskFilter_DirtyBit );
2246 return filter; 2245 return filter;
2247 } 2246 }
2248 2247
2249 /////////////////////////////////////////////////////////////////////////////// 2248 ///////////////////////////////////////////////////////////////////////////////
2250 2249
2251 bool SkPaint::getFillPath(const SkPath& src, SkPath* dst, 2250 bool SkPaint::getFillPath(const SkPath& src, SkPath* dst,
2252 const SkRect* cullRect) const { 2251 const SkRect* cullRect) const {
2253 SkStrokeRec rec(*this); 2252 SkStrokeRec rec(*this);
2254 2253
2255 const SkPath* srcPtr = &src; 2254 const SkPath* srcPtr = &src;
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
2684 F_UNREF(Looper, readDrawLooper); 2683 F_UNREF(Looper, readDrawLooper);
2685 F_UNREF(ImageFilter, readImageFilter); 2684 F_UNREF(ImageFilter, readImageFilter);
2686 F(Typeface, readTypeface); 2685 F(Typeface, readTypeface);
2687 #undef F 2686 #undef F
2688 #undef F_UNREF 2687 #undef F_UNREF
2689 if (dirty & kAnnotation_DirtyBit) { 2688 if (dirty & kAnnotation_DirtyBit) {
2690 paint->setAnnotation(SkAnnotation::Create(buffer))->unref(); 2689 paint->setAnnotation(SkAnnotation::Create(buffer))->unref();
2691 } 2690 }
2692 SkASSERT(dirty == paint->fDirtyBits); 2691 SkASSERT(dirty == paint->fDirtyBits);
2693 } 2692 }
OLDNEW
« no previous file with comments | « no previous file | tests/PaintTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698