diff options
author | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-10-11 19:32:32 +0000 |
---|---|---|
committer | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-10-11 19:32:32 +0000 |
commit | 5dc26b97366934ba0f896cea02a3fec027d5d5c1 (patch) | |
tree | f9be03e4ed22947191a696269d4d735d0a06a52e /src/core | |
parent | b364eb6c871c88710534c444cc4f075fcb9e3c02 (diff) |
SkTCopyOnFirstWrite
R=reed@google.com
Review URL: https://codereview.appspot.com/6650047
git-svn-id: http://skia.googlecode.com/svn/trunk@5905 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkBlitter.cpp | 31 | ||||
-rw-r--r-- | src/core/SkDraw.cpp | 14 |
2 files changed, 13 insertions, 32 deletions
diff --git a/src/core/SkBlitter.cpp b/src/core/SkBlitter.cpp index 322f91d40d..cdb2b625a7 100644 --- a/src/core/SkBlitter.cpp +++ b/src/core/SkBlitter.cpp @@ -847,17 +847,13 @@ SkBlitter* SkBlitter::Choose(const SkBitmap& device, SkXfermode* mode = origPaint.getXfermode(); Sk3DShader* shader3D = NULL; - SkTLazy<SkPaint> lazyPaint; - // we promise not to mutate paint unless we know we've reassigned it from - // lazyPaint - SkPaint* paint = const_cast<SkPaint*>(&origPaint); + SkTCopyOnFirstWrite<SkPaint> paint(origPaint); if (origPaint.getMaskFilter() != NULL && origPaint.getMaskFilter()->getFormat() == SkMask::k3D_Format) { shader3D = SkNEW_ARGS(Sk3DShader, (shader)); // we know we haven't initialized lazyPaint yet, so just do it - paint = lazyPaint.set(origPaint); - paint->setShader(shader3D)->unref(); + paint.writable()->setShader(shader3D)->unref(); shader = shader3D; } @@ -865,10 +861,7 @@ SkBlitter* SkBlitter::Choose(const SkBitmap& device, switch (interpret_xfermode(*paint, mode, device.config())) { case kSrcOver_XferInterp: mode = NULL; - if (!lazyPaint.isValid()) { - paint = lazyPaint.set(origPaint); - } - paint->setXfermode(NULL); + paint.writable()->setXfermode(NULL); break; case kSkipDrawing_XferInterp: SK_PLACEMENT_NEW(blitter, SkNullBlitter, storage, storageSize); @@ -886,18 +879,13 @@ SkBlitter* SkBlitter::Choose(const SkBitmap& device, #endif // xfermodes (and filters) require shaders for our current blitters shader = SkNEW(SkColorShader); - if (!lazyPaint.isValid()) { - paint = lazyPaint.set(origPaint); - } - paint->setShader(shader)->unref(); + paint.writable()->setShader(shader)->unref(); } else if (cf) { // if no shader && no xfermode, we just apply the colorfilter to // our color and move on. - if (!lazyPaint.isValid()) { - paint = lazyPaint.set(origPaint); - } - paint->setColor(cf->filterColor(paint->getColor())); - paint->setColorFilter(NULL); + SkPaint* writablePaint = paint.writable(); + writablePaint->setColor(cf->filterColor(paint->getColor())); + writablePaint->setColorFilter(NULL); cf = NULL; } } @@ -905,10 +893,7 @@ SkBlitter* SkBlitter::Choose(const SkBitmap& device, if (cf) { SkASSERT(shader); shader = SkNEW_ARGS(SkFilterShader, (shader, cf)); - if (!lazyPaint.isValid()) { - paint = lazyPaint.set(origPaint); - } - paint->setShader(shader)->unref(); + paint.writable()->setShader(shader)->unref(); // blitters should ignore the presence/absence of a filter, since // if there is one, the shader will take care of it. } diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp index cdd59c1cdb..885a810836 100644 --- a/src/core/SkDraw.cpp +++ b/src/core/SkDraw.cpp @@ -931,16 +931,13 @@ void SkDraw::drawPath(const SkPath& origSrcPath, const SkPaint& origPaint, // at this point we're done with prePathMatrix SkDEBUGCODE(prePathMatrix = (const SkMatrix*)0x50FF8001;) - const SkPaint* paint = &origPaint; - SkTLazy<SkPaint> lazyPaint; + SkTCopyOnFirstWrite<SkPaint> paint(origPaint); { SkScalar coverage; if (SkDrawTreatAsHairline(origPaint, *matrix, &coverage)) { if (SK_Scalar1 == coverage) { - lazyPaint.set(origPaint); - lazyPaint.get()->setStrokeWidth(0); - paint = lazyPaint.get(); + paint.writable()->setStrokeWidth(0); } else if (xfermodeSupportsCoverageAsAlpha(origPaint.getXfermode())) { U8CPU newAlpha; #if 0 @@ -953,10 +950,9 @@ void SkDraw::drawPath(const SkPath& origSrcPath, const SkPaint& origPaint, int scale = (int)SkScalarMul(coverage, 256); newAlpha = origPaint.getAlpha() * scale >> 8; #endif - lazyPaint.set(origPaint); - lazyPaint.get()->setStrokeWidth(0); - lazyPaint.get()->setAlpha(newAlpha); - paint = lazyPaint.get(); + SkPaint* writablePaint = paint.writable(); + writablePaint->setStrokeWidth(0); + writablePaint->setAlpha(newAlpha); } } } |