diff options
author | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-03-12 09:42:01 +0000 |
---|---|---|
committer | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-03-12 09:42:01 +0000 |
commit | 79fbb40bca9d815ef79b896b31ba6ee736817e0f (patch) | |
tree | e68a9d73abf9bdbef00d5facf6ca406a395527f7 /src/effects | |
parent | ad07e69d4cbd4924678f923d744dc01517bd6a78 (diff) |
[WIP] Add Context to SkDrawLooper.
SkDrawLooper carries some state during draws. This CL extracts this state into
a separate class Context, which is then passed by the users of SkDrawLooper
into the appropriate methods.
This is a step towards making SkDrawLooper immutable.
BUG=skia:2141
R=scroggo@google.com, reed@google.com, sugoi@google.com
Author: dominikg@chromium.org
Review URL: https://codereview.chromium.org/155513012
git-svn-id: http://skia.googlecode.com/svn/trunk@13760 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/effects')
-rw-r--r-- | src/effects/SkBlurDrawLooper.cpp | 26 | ||||
-rw-r--r-- | src/effects/SkLayerDrawLooper.cpp | 20 |
2 files changed, 27 insertions, 19 deletions
diff --git a/src/effects/SkBlurDrawLooper.cpp b/src/effects/SkBlurDrawLooper.cpp index 3a5c697371..0bbc184049 100644 --- a/src/effects/SkBlurDrawLooper.cpp +++ b/src/effects/SkBlurDrawLooper.cpp @@ -33,7 +33,6 @@ void SkBlurDrawLooper::init(SkScalar sigma, SkScalar dx, SkScalar dy, fDy = dy; fBlurColor = color; fBlurFlags = flags; - fState = kDone; SkASSERT(flags <= kAll_BlurFlag); if (sigma > 0) { @@ -90,11 +89,16 @@ void SkBlurDrawLooper::flatten(SkWriteBuffer& buffer) const { buffer.writeUInt(fBlurFlags); } -void SkBlurDrawLooper::init(SkCanvas*) { - fState = kBeforeEdge; +SkDrawLooper::Context* SkBlurDrawLooper::createContext(SkCanvas*, void* storage) const { + return SkNEW_PLACEMENT_ARGS(storage, BlurDrawLooperContext, (this)); } -bool SkBlurDrawLooper::next(SkCanvas* canvas, SkPaint* paint) { +SkBlurDrawLooper::BlurDrawLooperContext::BlurDrawLooperContext( + const SkBlurDrawLooper* looper) + : fLooper(looper), fState(SkBlurDrawLooper::kBeforeEdge) {} + +bool SkBlurDrawLooper::BlurDrawLooperContext::next(SkCanvas* canvas, + SkPaint* paint) { switch (fState) { case kBeforeEdge: // we do nothing if a maskfilter is already installed @@ -104,23 +108,23 @@ bool SkBlurDrawLooper::next(SkCanvas* canvas, SkPaint* paint) { } #ifdef SK_BUILD_FOR_ANDROID SkColor blurColor; - blurColor = fBlurColor; + blurColor = fLooper->fBlurColor; if (SkColorGetA(blurColor) == 255) { blurColor = SkColorSetA(blurColor, paint->getAlpha()); } paint->setColor(blurColor); #else - paint->setColor(fBlurColor); + paint->setColor(fLooper->fBlurColor); #endif - paint->setMaskFilter(fBlur); - paint->setColorFilter(fColorFilter); + paint->setMaskFilter(fLooper->fBlur); + paint->setColorFilter(fLooper->fColorFilter); canvas->save(SkCanvas::kMatrix_SaveFlag); - if (fBlurFlags & kIgnoreTransform_BlurFlag) { + if (fLooper->fBlurFlags & kIgnoreTransform_BlurFlag) { SkMatrix transform(canvas->getTotalMatrix()); - transform.postTranslate(fDx, fDy); + transform.postTranslate(fLooper->fDx, fLooper->fDy); canvas->setMatrix(transform); } else { - canvas->translate(fDx, fDy); + canvas->translate(fLooper->fDx, fLooper->fDy); } fState = kAfterEdge; return true; diff --git a/src/effects/SkLayerDrawLooper.cpp b/src/effects/SkLayerDrawLooper.cpp index cfe673db92..6d31c23a06 100644 --- a/src/effects/SkLayerDrawLooper.cpp +++ b/src/effects/SkLayerDrawLooper.cpp @@ -24,8 +24,7 @@ SkLayerDrawLooper::LayerInfo::LayerInfo() { SkLayerDrawLooper::SkLayerDrawLooper() : fRecs(NULL), fTopRec(NULL), - fCount(0), - fCurrRec(NULL) { + fCount(0) { } SkLayerDrawLooper::~SkLayerDrawLooper() { @@ -75,9 +74,9 @@ SkPaint* SkLayerDrawLooper::addLayerOnTop(const LayerInfo& info) { return &rec->fPaint; } -void SkLayerDrawLooper::init(SkCanvas* canvas) { - fCurrRec = fRecs; +SkLayerDrawLooper::Context* SkLayerDrawLooper::createContext(SkCanvas* canvas, void* storage) const { canvas->save(SkCanvas::kMatrix_SaveFlag); + return SkNEW_PLACEMENT_ARGS(storage, LayerDrawLooperContext, (this)); } static SkColor xferColor(SkColor src, SkColor dst, SkXfermode::Mode mode) { @@ -98,8 +97,8 @@ static SkColor xferColor(SkColor src, SkColor dst, SkXfermode::Mode mode) { // Even with kEntirePaint_Bits, we always ensure that the master paint's // text-encoding is respected, since that controls how we interpret the // text/length parameters of a draw[Pos]Text call. -void SkLayerDrawLooper::ApplyInfo(SkPaint* dst, const SkPaint& src, - const LayerInfo& info) { +void SkLayerDrawLooper::LayerDrawLooperContext::ApplyInfo( + SkPaint* dst, const SkPaint& src, const LayerInfo& info) { dst->setColor(xferColor(src.getColor(), dst->getColor(), info.fColorMode)); @@ -167,7 +166,11 @@ static void postTranslate(SkCanvas* canvas, SkScalar dx, SkScalar dy) { canvas->setMatrix(m); } -bool SkLayerDrawLooper::next(SkCanvas* canvas, SkPaint* paint) { +SkLayerDrawLooper::LayerDrawLooperContext::LayerDrawLooperContext( + const SkLayerDrawLooper* looper) : fCurrRec(looper->fRecs) {} + +bool SkLayerDrawLooper::LayerDrawLooperContext::next(SkCanvas* canvas, + SkPaint* paint) { canvas->restore(); if (NULL == fCurrRec) { return false; @@ -180,7 +183,8 @@ bool SkLayerDrawLooper::next(SkCanvas* canvas, SkPaint* paint) { postTranslate(canvas, fCurrRec->fInfo.fOffset.fX, fCurrRec->fInfo.fOffset.fY); } else { - canvas->translate(fCurrRec->fInfo.fOffset.fX, fCurrRec->fInfo.fOffset.fY); + canvas->translate(fCurrRec->fInfo.fOffset.fX, + fCurrRec->fInfo.fOffset.fY); } fCurrRec = fCurrRec->fNext; |