diff options
author | mike@reedtribe.org <mike@reedtribe.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-04-08 02:41:54 +0000 |
---|---|---|
committer | mike@reedtribe.org <mike@reedtribe.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-04-08 02:41:54 +0000 |
commit | 0e2810be95d3f1aa95c341521d3f514eb9e9ebde (patch) | |
tree | e3d2e06e5a95fc3e23d2c861a15a13848be87dfc /src/effects | |
parent | bd36ebe29463c4b70f5c91bb2440cdcf45b22b52 (diff) |
add optional bitflags to control which aspect of each layer's paint is applied
git-svn-id: http://skia.googlecode.com/svn/trunk@1083 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/effects')
-rw-r--r-- | src/effects/SkLayerDrawLooper.cpp | 65 |
1 files changed, 63 insertions, 2 deletions
diff --git a/src/effects/SkLayerDrawLooper.cpp b/src/effects/SkLayerDrawLooper.cpp index 32b56d6948..ee0fc985cc 100644 --- a/src/effects/SkLayerDrawLooper.cpp +++ b/src/effects/SkLayerDrawLooper.cpp @@ -16,12 +16,13 @@ SkLayerDrawLooper::~SkLayerDrawLooper() { } } -SkPaint* SkLayerDrawLooper::addLayer(SkScalar dx, SkScalar dy) { +SkPaint* SkLayerDrawLooper::addLayer(SkScalar dx, SkScalar dy, BitFlags bits) { fCount += 1; Rec* rec = SkNEW(Rec); rec->fNext = fRecs; rec->fOffset.set(dx, dy); + rec->fBits = bits; fRecs = rec; return &rec->fPaint; @@ -32,13 +33,73 @@ void SkLayerDrawLooper::init(SkCanvas* canvas) { canvas->save(SkCanvas::kMatrix_SaveFlag); } +void SkLayerDrawLooper::ApplyBits(SkPaint* dst, const SkPaint& src, + BitFlags bits) { + if (kEntirePaint_Bits == bits) { + *dst = src; + return; + } + + SkColor c = dst->getColor(); + if (bits & kAlpha_Bit) { + c &= 0x00FFFFFF; + c |= src.getColor() & 0xFF000000; + } + if (bits & kColor_Bit) { + c &= 0xFF000000; + c |= src.getColor() & 0x00FFFFFF; + } + dst->setColor(c); + + if (bits & kStyle_Bit) { + dst->setStyle(src.getStyle()); + dst->setStrokeWidth(src.getStrokeWidth()); + dst->setStrokeMiter(src.getStrokeMiter()); + dst->setStrokeCap(src.getStrokeCap()); + dst->setStrokeJoin(src.getStrokeJoin()); + } + + if (bits & kTextSkewX_Bit) { + dst->setTextSkewX(src.getTextSkewX()); + } + + if (bits & kPathEffect_Bit) { + dst->setPathEffect(src.getPathEffect()); + } + if (bits & kMaskFilter_Bit) { + dst->setMaskFilter(src.getMaskFilter()); + } + if (bits & kShader_Bit) { + dst->setShader(src.getShader()); + } + if (bits & kColorFilter_Bit) { + dst->setColorFilter(src.getColorFilter()); + } + if (bits & kXfermode_Bit) { + dst->setXfermode(src.getXfermode()); + } + + // we never copy these +#if 0 + dst->setFlags(src.getFlags()); + dst->setTypeface(src.getTypeface()); + dst->setTextSize(src.getTextSize()); + dst->setTextScaleX(src.getTextScaleX()); + dst->setTextSkewX(src.getTextSkewX()); + dst->setRasterizer(src.getRasterizer()); + dst->setLooper(src.getLooper()); + dst->setTextEncoding(src.getTextEncoding()); + dst->setHinting(src.getHinting()); +#endif +} + bool SkLayerDrawLooper::next(SkCanvas* canvas, SkPaint* paint) { canvas->restore(); if (NULL == fCurrRec) { return false; } - *paint = fCurrRec->fPaint; + ApplyBits(paint, fCurrRec->fPaint, fCurrRec->fBits); canvas->save(SkCanvas::kMatrix_SaveFlag); canvas->translate(fCurrRec->fOffset.fX, fCurrRec->fOffset.fY); fCurrRec = fCurrRec->fNext; |