diff options
author | Chet Haase <chet@google.com> | 2010-10-25 16:18:59 -0700 |
---|---|---|
committer | Chet Haase <chet@google.com> | 2010-10-25 16:30:37 -0700 |
commit | 95662ea6ee460cc84014c41a8c13e881cd8be8ed (patch) | |
tree | 606231199a01f05621f1612b221ef94b86f8c970 | |
parent | 14496db08e9c54a5012933b8c25a58348627d646 (diff) | |
download | external_skia-95662ea6ee460cc84014c41a8c13e881cd8be8ed.zip external_skia-95662ea6ee460cc84014c41a8c13e881cd8be8ed.tar.gz external_skia-95662ea6ee460cc84014c41a8c13e881cd8be8ed.tar.bz2 |
Added generation ID to SkPaint to easily detect changed object.
This new ID is used by display list objects to detect when the SkPaint object's
properties have changed and the display list needs to copy the paint into
a new object to avoid reusing an obsolete copy of it.
Change-Id: I1fb7034bea63eca247b72b939cb20f0fcece067a
-rw-r--r-- | include/core/SkPaint.h | 3 | ||||
-rw-r--r-- | src/core/SkPaint.cpp | 175 |
2 files changed, 146 insertions, 32 deletions
diff --git a/include/core/SkPaint.h b/include/core/SkPaint.h index dd2c2f4..ea21ceb 100644 --- a/include/core/SkPaint.h +++ b/include/core/SkPaint.h @@ -809,6 +809,8 @@ public: const SkGlyph& getUnicharMetrics(SkUnichar); const void* findImage(const SkGlyph&); + uint32_t getGenerationID() const; + private: SkTypeface* fTypeface; SkScalar fTextSize; @@ -833,6 +835,7 @@ private: unsigned fStyle : 2; unsigned fTextEncoding : 2; // 3 values unsigned fHinting : 2; + uint32_t fGenerationID; SkDrawCacheProc getDrawCacheProc() const; SkMeasureCacheProc getMeasureCacheProc(TextBufferDirection dir, diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp index 251ebf2..40d3ae8 100644 --- a/src/core/SkPaint.cpp +++ b/src/core/SkPaint.cpp @@ -63,6 +63,7 @@ SkPaint::SkPaint() { fStyle = kFill_Style; fTextEncoding = kUTF8_TextEncoding; fHinting = kNormal_Hinting; + fGenerationID = 0; } SkPaint::SkPaint(const SkPaint& src) @@ -114,6 +115,7 @@ SkPaint& SkPaint::operator=(const SkPaint& src) fLooper->safeUnref(); memcpy(this, &src, sizeof(src)); + fGenerationID++; return *this; } @@ -128,72 +130,117 @@ void SkPaint::reset() SkPaint init; *this = init; + fGenerationID++; +} + +uint32_t SkPaint::getGenerationID() const { + return fGenerationID; } void SkPaint::setFlags(uint32_t flags) { - fFlags = flags; + if (fFlags != flags) { + fFlags = flags; + fGenerationID++; + } } void SkPaint::setAntiAlias(bool doAA) { - this->setFlags(SkSetClearMask(fFlags, doAA, kAntiAlias_Flag)); + if (doAA != isAntiAlias()) { + this->setFlags(SkSetClearMask(fFlags, doAA, kAntiAlias_Flag)); + fGenerationID++; + } } void SkPaint::setDither(bool doDither) { - this->setFlags(SkSetClearMask(fFlags, doDither, kDither_Flag)); + if (doDither != isDither()) { + this->setFlags(SkSetClearMask(fFlags, doDither, kDither_Flag)); + fGenerationID++; + } } void SkPaint::setSubpixelText(bool doSubpixel) { - this->setFlags(SkSetClearMask(fFlags, doSubpixel, kSubpixelText_Flag)); + if (doSubpixel != isSubpixelText()) { + this->setFlags(SkSetClearMask(fFlags, doSubpixel, kSubpixelText_Flag)); + fGenerationID++; + } } void SkPaint::setLCDRenderText(bool doLCDRender) { - this->setFlags(SkSetClearMask(fFlags, doLCDRender, kLCDRenderText_Flag)); + if (doLCDRender != isLCDRenderText()) { + this->setFlags(SkSetClearMask(fFlags, doLCDRender, kLCDRenderText_Flag)); + fGenerationID++; + } } void SkPaint::setEmbeddedBitmapText(bool doEmbeddedBitmapText) { - this->setFlags(SkSetClearMask(fFlags, doEmbeddedBitmapText, kEmbeddedBitmapText_Flag)); + if (doEmbeddedBitmapText != isEmbeddedBitmapText()) { + this->setFlags(SkSetClearMask(fFlags, doEmbeddedBitmapText, kEmbeddedBitmapText_Flag)); + fGenerationID++; + } } void SkPaint::setLinearText(bool doLinearText) { - this->setFlags(SkSetClearMask(fFlags, doLinearText, kLinearText_Flag)); + if (doLinearText != isLinearText()) { + this->setFlags(SkSetClearMask(fFlags, doLinearText, kLinearText_Flag)); + fGenerationID++; + } } void SkPaint::setUnderlineText(bool doUnderline) { - this->setFlags(SkSetClearMask(fFlags, doUnderline, kUnderlineText_Flag)); + if (doUnderline != isUnderlineText()) { + this->setFlags(SkSetClearMask(fFlags, doUnderline, kUnderlineText_Flag)); + fGenerationID++; + } } void SkPaint::setStrikeThruText(bool doStrikeThru) { - this->setFlags(SkSetClearMask(fFlags, doStrikeThru, kStrikeThruText_Flag)); + if (doStrikeThru != isStrikeThruText()) { + this->setFlags(SkSetClearMask(fFlags, doStrikeThru, kStrikeThruText_Flag)); + fGenerationID++; + } } void SkPaint::setFakeBoldText(bool doFakeBold) { - this->setFlags(SkSetClearMask(fFlags, doFakeBold, kFakeBoldText_Flag)); + if (doFakeBold != isFakeBoldText()) { + this->setFlags(SkSetClearMask(fFlags, doFakeBold, kFakeBoldText_Flag)); + fGenerationID++; + } } void SkPaint::setDevKernText(bool doDevKern) { - this->setFlags(SkSetClearMask(fFlags, doDevKern, kDevKernText_Flag)); + if (doDevKern != isDevKernText()) { + this->setFlags(SkSetClearMask(fFlags, doDevKern, kDevKernText_Flag)); + fGenerationID++; + } } void SkPaint::setFilterBitmap(bool doFilter) { - this->setFlags(SkSetClearMask(fFlags, doFilter, kFilterBitmap_Flag)); + if (doFilter != isFilterBitmap()) { + this->setFlags(SkSetClearMask(fFlags, doFilter, kFilterBitmap_Flag)); + fGenerationID++; + } } void SkPaint::setStyle(Style style) { - if ((unsigned)style < kStyleCount) - fStyle = style; + if ((unsigned)style < kStyleCount) { + if ((unsigned)style != fStyle) { + fStyle = style; + fGenerationID++; + } + } #ifdef SK_DEBUG else SkDebugf("SkPaint::setStyle(%d) out of range\n", style); @@ -202,23 +249,38 @@ void SkPaint::setStyle(Style style) void SkPaint::setColor(SkColor color) { - fColor = color; + if (color != fColor) { + fColor = color; + fGenerationID++; + } } void SkPaint::setAlpha(U8CPU a) { - fColor = SkColorSetARGB(a, SkColorGetR(fColor), SkColorGetG(fColor), SkColorGetB(fColor)); + U8CPU oldA = SkColorGetA(fColor); + if (a != oldA) { + fColor = SkColorSetARGB(a, SkColorGetR(fColor), SkColorGetG(fColor), SkColorGetB(fColor)); + fGenerationID++; + } } void SkPaint::setARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) { + SkColor oldColor = fColor; fColor = SkColorSetARGB(a, r, g, b); + if (oldColor != fColor) { + fGenerationID++; + } } void SkPaint::setStrokeWidth(SkScalar width) { - if (width >= 0) - fWidth = width; + if (width >= 0) { + if (width != fWidth) { + fWidth = width; + fGenerationID++; + } + } #ifdef SK_DEBUG else SkDebugf("SkPaint::setStrokeWidth() called with negative value\n"); @@ -227,8 +289,12 @@ void SkPaint::setStrokeWidth(SkScalar width) void SkPaint::setStrokeMiter(SkScalar limit) { - if (limit >= 0) - fMiterLimit = limit; + if (limit >= 0) { + if (limit != fMiterLimit) { + fMiterLimit = limit; + fGenerationID++; + } + } #ifdef SK_DEBUG else SkDebugf("SkPaint::setStrokeMiter() called with negative value\n"); @@ -237,8 +303,12 @@ void SkPaint::setStrokeMiter(SkScalar limit) void SkPaint::setStrokeCap(Cap ct) { - if ((unsigned)ct < kCapCount) - fCapType = SkToU8(ct); + if ((unsigned)ct < kCapCount) { + if ((unsigned)ct != fCapType) { + fCapType = SkToU8(ct); + fGenerationID++; + } + } #ifdef SK_DEBUG else SkDebugf("SkPaint::setStrokeCap(%d) out of range\n", ct); @@ -247,8 +317,12 @@ void SkPaint::setStrokeCap(Cap ct) void SkPaint::setStrokeJoin(Join jt) { - if ((unsigned)jt < kJoinCount) - fJoinType = SkToU8(jt); + if ((unsigned)jt < kJoinCount) { + if ((unsigned)jt != fJoinType) { + fJoinType = SkToU8(jt); + fGenerationID++; + } + } #ifdef SK_DEBUG else SkDebugf("SkPaint::setStrokeJoin(%d) out of range\n", jt); @@ -259,8 +333,12 @@ void SkPaint::setStrokeJoin(Join jt) void SkPaint::setTextAlign(Align align) { - if ((unsigned)align < kAlignCount) - fTextAlign = SkToU8(align); + if ((unsigned)align < kAlignCount) { + if ((unsigned)align != fTextAlign) { + fTextAlign = SkToU8(align); + fGenerationID++; + } + } #ifdef SK_DEBUG else SkDebugf("SkPaint::setTextAlign(%d) out of range\n", align); @@ -269,8 +347,12 @@ void SkPaint::setTextAlign(Align align) void SkPaint::setTextSize(SkScalar ts) { - if (ts > 0) - fTextSize = ts; + if (ts > 0) { + if (ts != fTextSize) { + fTextSize = ts; + fGenerationID++; + } + } #ifdef SK_DEBUG else SkDebugf("SkPaint::setTextSize() called with non-positive value\n"); @@ -279,18 +361,28 @@ void SkPaint::setTextSize(SkScalar ts) void SkPaint::setTextScaleX(SkScalar scaleX) { - fTextScaleX = scaleX; + if (scaleX != fTextScaleX) { + fTextScaleX = scaleX; + fGenerationID++; + } } void SkPaint::setTextSkewX(SkScalar skewX) { - fTextSkewX = skewX; + if (skewX != fTextSkewX) { + fTextSkewX = skewX; + fGenerationID++; + } } void SkPaint::setTextEncoding(TextEncoding encoding) { - if ((unsigned)encoding <= kGlyphID_TextEncoding) - fTextEncoding = encoding; + if ((unsigned)encoding <= kGlyphID_TextEncoding) { + if ((unsigned)encoding != fTextEncoding) { + fTextEncoding = encoding; + fGenerationID++; + } + } #ifdef SK_DEBUG else SkDebugf("SkPaint::setTextEncoding(%d) out of range\n", encoding); @@ -302,18 +394,21 @@ void SkPaint::setTextEncoding(TextEncoding encoding) SkTypeface* SkPaint::setTypeface(SkTypeface* font) { SkRefCnt_SafeAssign(fTypeface, font); + fGenerationID++; return font; } SkRasterizer* SkPaint::setRasterizer(SkRasterizer* r) { SkRefCnt_SafeAssign(fRasterizer, r); + fGenerationID++; return r; } SkDrawLooper* SkPaint::setLooper(SkDrawLooper* looper) { SkRefCnt_SafeAssign(fLooper, looper); + fGenerationID++; return looper; } @@ -1570,18 +1665,27 @@ void SkPaint::unflatten(SkFlattenableReadBuffer& buffer) { SkShader* SkPaint::setShader(SkShader* shader) { + if (shader != fShader) { + fGenerationID++; + } SkRefCnt_SafeAssign(fShader, shader); return shader; } SkColorFilter* SkPaint::setColorFilter(SkColorFilter* filter) { + if (filter != fColorFilter) { + fGenerationID++; + } SkRefCnt_SafeAssign(fColorFilter, filter); return filter; } SkXfermode* SkPaint::setXfermode(SkXfermode* mode) { + if (mode != fXfermode) { + fGenerationID++; + } SkRefCnt_SafeAssign(fXfermode, mode); return mode; } @@ -1589,17 +1693,24 @@ SkXfermode* SkPaint::setXfermode(SkXfermode* mode) SkXfermode* SkPaint::setXfermodeMode(SkXfermode::Mode mode) { SkSafeUnref(fXfermode); fXfermode = SkXfermode::Create(mode); + fGenerationID++; return fXfermode; } SkPathEffect* SkPaint::setPathEffect(SkPathEffect* effect) { + if (effect != fPathEffect) { + fGenerationID++; + } SkRefCnt_SafeAssign(fPathEffect, effect); return effect; } SkMaskFilter* SkPaint::setMaskFilter(SkMaskFilter* filter) { + if (filter != fMaskFilter) { + fGenerationID++; + } SkRefCnt_SafeAssign(fMaskFilter, filter); return filter; } |