epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 8 | #include "SkCanvas.h" |
reed@google.com | 0716c63 | 2011-04-12 18:32:06 +0000 | [diff] [blame] | 9 | #include "SkColor.h" |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 10 | #include "SkReadBuffer.h" |
| 11 | #include "SkWriteBuffer.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 12 | #include "SkLayerDrawLooper.h" |
robertphillips@google.com | 4991b8f | 2013-01-28 20:21:59 +0000 | [diff] [blame] | 13 | #include "SkString.h" |
| 14 | #include "SkStringUtils.h" |
reed@google.com | 0716c63 | 2011-04-12 18:32:06 +0000 | [diff] [blame] | 15 | #include "SkUnPreMultiply.h" |
| 16 | |
| 17 | SkLayerDrawLooper::LayerInfo::LayerInfo() { |
mike@reedtribe.org | a8282ef | 2011-04-14 01:22:45 +0000 | [diff] [blame] | 18 | fPaintBits = 0; // ignore our paint fields |
reed@google.com | 0716c63 | 2011-04-12 18:32:06 +0000 | [diff] [blame] | 19 | fColorMode = SkXfermode::kDst_Mode; // ignore our color |
| 20 | fOffset.set(0, 0); |
| 21 | fPostTranslate = false; |
| 22 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 23 | |
vandebo@chromium.org | 3c89818 | 2011-06-22 05:01:28 +0000 | [diff] [blame] | 24 | SkLayerDrawLooper::SkLayerDrawLooper() |
| 25 | : fRecs(NULL), |
commit-bot@chromium.org | 8f83825 | 2013-05-22 12:35:50 +0000 | [diff] [blame] | 26 | fTopRec(NULL), |
commit-bot@chromium.org | 79fbb40 | 2014-03-12 09:42:01 +0000 | [diff] [blame] | 27 | fCount(0) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | SkLayerDrawLooper::~SkLayerDrawLooper() { |
| 31 | Rec* rec = fRecs; |
| 32 | while (rec) { |
| 33 | Rec* next = rec->fNext; |
| 34 | SkDELETE(rec); |
| 35 | rec = next; |
| 36 | } |
| 37 | } |
reed@google.com | 0716c63 | 2011-04-12 18:32:06 +0000 | [diff] [blame] | 38 | |
commit-bot@chromium.org | 79fbb40 | 2014-03-12 09:42:01 +0000 | [diff] [blame] | 39 | SkLayerDrawLooper::Context* SkLayerDrawLooper::createContext(SkCanvas* canvas, void* storage) const { |
commit-bot@chromium.org | 091a594 | 2014-04-18 14:19:31 +0000 | [diff] [blame] | 40 | canvas->save(); |
commit-bot@chromium.org | 79fbb40 | 2014-03-12 09:42:01 +0000 | [diff] [blame] | 41 | return SkNEW_PLACEMENT_ARGS(storage, LayerDrawLooperContext, (this)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 42 | } |
| 43 | |
reed@google.com | 0716c63 | 2011-04-12 18:32:06 +0000 | [diff] [blame] | 44 | static SkColor xferColor(SkColor src, SkColor dst, SkXfermode::Mode mode) { |
| 45 | switch (mode) { |
| 46 | case SkXfermode::kSrc_Mode: |
| 47 | return src; |
| 48 | case SkXfermode::kDst_Mode: |
| 49 | return dst; |
| 50 | default: { |
| 51 | SkPMColor pmS = SkPreMultiplyColor(src); |
| 52 | SkPMColor pmD = SkPreMultiplyColor(dst); |
| 53 | SkPMColor result = SkXfermode::GetProc(mode)(pmS, pmD); |
| 54 | return SkUnPreMultiply::PMColorToColor(result); |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
reed@google.com | 8426058 | 2011-11-21 16:42:10 +0000 | [diff] [blame] | 59 | // Even with kEntirePaint_Bits, we always ensure that the master paint's |
| 60 | // text-encoding is respected, since that controls how we interpret the |
| 61 | // text/length parameters of a draw[Pos]Text call. |
commit-bot@chromium.org | 79fbb40 | 2014-03-12 09:42:01 +0000 | [diff] [blame] | 62 | void SkLayerDrawLooper::LayerDrawLooperContext::ApplyInfo( |
| 63 | SkPaint* dst, const SkPaint& src, const LayerInfo& info) { |
mike@reedtribe.org | a8282ef | 2011-04-14 01:22:45 +0000 | [diff] [blame] | 64 | |
mike@reedtribe.org | a8282ef | 2011-04-14 01:22:45 +0000 | [diff] [blame] | 65 | dst->setColor(xferColor(src.getColor(), dst->getColor(), info.fColorMode)); |
| 66 | |
| 67 | BitFlags bits = info.fPaintBits; |
reed@google.com | 8426058 | 2011-11-21 16:42:10 +0000 | [diff] [blame] | 68 | SkPaint::TextEncoding encoding = dst->getTextEncoding(); |
reed@google.com | 0716c63 | 2011-04-12 18:32:06 +0000 | [diff] [blame] | 69 | |
mike@reedtribe.org | 3c1225b | 2011-04-09 18:54:08 +0000 | [diff] [blame] | 70 | if (0 == bits) { |
| 71 | return; |
| 72 | } |
mike@reedtribe.org | 0e2810b | 2011-04-08 02:41:54 +0000 | [diff] [blame] | 73 | if (kEntirePaint_Bits == bits) { |
mike@reedtribe.org | a8282ef | 2011-04-14 01:22:45 +0000 | [diff] [blame] | 74 | // we've already computed these, so save it from the assignment |
| 75 | uint32_t f = dst->getFlags(); |
reed@google.com | 0716c63 | 2011-04-12 18:32:06 +0000 | [diff] [blame] | 76 | SkColor c = dst->getColor(); |
mike@reedtribe.org | 0e2810b | 2011-04-08 02:41:54 +0000 | [diff] [blame] | 77 | *dst = src; |
mike@reedtribe.org | a8282ef | 2011-04-14 01:22:45 +0000 | [diff] [blame] | 78 | dst->setFlags(f); |
reed@google.com | 0716c63 | 2011-04-12 18:32:06 +0000 | [diff] [blame] | 79 | dst->setColor(c); |
reed@google.com | 8426058 | 2011-11-21 16:42:10 +0000 | [diff] [blame] | 80 | dst->setTextEncoding(encoding); |
mike@reedtribe.org | 0e2810b | 2011-04-08 02:41:54 +0000 | [diff] [blame] | 81 | return; |
| 82 | } |
| 83 | |
mike@reedtribe.org | 0e2810b | 2011-04-08 02:41:54 +0000 | [diff] [blame] | 84 | if (bits & kStyle_Bit) { |
| 85 | dst->setStyle(src.getStyle()); |
| 86 | dst->setStrokeWidth(src.getStrokeWidth()); |
| 87 | dst->setStrokeMiter(src.getStrokeMiter()); |
| 88 | dst->setStrokeCap(src.getStrokeCap()); |
| 89 | dst->setStrokeJoin(src.getStrokeJoin()); |
| 90 | } |
| 91 | |
| 92 | if (bits & kTextSkewX_Bit) { |
| 93 | dst->setTextSkewX(src.getTextSkewX()); |
| 94 | } |
| 95 | |
| 96 | if (bits & kPathEffect_Bit) { |
| 97 | dst->setPathEffect(src.getPathEffect()); |
| 98 | } |
| 99 | if (bits & kMaskFilter_Bit) { |
| 100 | dst->setMaskFilter(src.getMaskFilter()); |
| 101 | } |
| 102 | if (bits & kShader_Bit) { |
| 103 | dst->setShader(src.getShader()); |
| 104 | } |
| 105 | if (bits & kColorFilter_Bit) { |
| 106 | dst->setColorFilter(src.getColorFilter()); |
| 107 | } |
| 108 | if (bits & kXfermode_Bit) { |
| 109 | dst->setXfermode(src.getXfermode()); |
| 110 | } |
| 111 | |
reed@google.com | 8426058 | 2011-11-21 16:42:10 +0000 | [diff] [blame] | 112 | // we don't override these |
mike@reedtribe.org | 0e2810b | 2011-04-08 02:41:54 +0000 | [diff] [blame] | 113 | #if 0 |
mike@reedtribe.org | 0e2810b | 2011-04-08 02:41:54 +0000 | [diff] [blame] | 114 | dst->setTypeface(src.getTypeface()); |
| 115 | dst->setTextSize(src.getTextSize()); |
| 116 | dst->setTextScaleX(src.getTextScaleX()); |
mike@reedtribe.org | 0e2810b | 2011-04-08 02:41:54 +0000 | [diff] [blame] | 117 | dst->setRasterizer(src.getRasterizer()); |
| 118 | dst->setLooper(src.getLooper()); |
| 119 | dst->setTextEncoding(src.getTextEncoding()); |
| 120 | dst->setHinting(src.getHinting()); |
| 121 | #endif |
| 122 | } |
| 123 | |
reed@google.com | 0716c63 | 2011-04-12 18:32:06 +0000 | [diff] [blame] | 124 | // Should we add this to canvas? |
| 125 | static void postTranslate(SkCanvas* canvas, SkScalar dx, SkScalar dy) { |
| 126 | SkMatrix m = canvas->getTotalMatrix(); |
| 127 | m.postTranslate(dx, dy); |
| 128 | canvas->setMatrix(m); |
| 129 | } |
| 130 | |
commit-bot@chromium.org | 79fbb40 | 2014-03-12 09:42:01 +0000 | [diff] [blame] | 131 | SkLayerDrawLooper::LayerDrawLooperContext::LayerDrawLooperContext( |
| 132 | const SkLayerDrawLooper* looper) : fCurrRec(looper->fRecs) {} |
| 133 | |
| 134 | bool SkLayerDrawLooper::LayerDrawLooperContext::next(SkCanvas* canvas, |
| 135 | SkPaint* paint) { |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 136 | canvas->restore(); |
| 137 | if (NULL == fCurrRec) { |
| 138 | return false; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 139 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 140 | |
mike@reedtribe.org | a8282ef | 2011-04-14 01:22:45 +0000 | [diff] [blame] | 141 | ApplyInfo(paint, fCurrRec->fPaint, fCurrRec->fInfo); |
reed@google.com | 0716c63 | 2011-04-12 18:32:06 +0000 | [diff] [blame] | 142 | |
commit-bot@chromium.org | 091a594 | 2014-04-18 14:19:31 +0000 | [diff] [blame] | 143 | canvas->save(); |
reed@google.com | 0716c63 | 2011-04-12 18:32:06 +0000 | [diff] [blame] | 144 | if (fCurrRec->fInfo.fPostTranslate) { |
| 145 | postTranslate(canvas, fCurrRec->fInfo.fOffset.fX, |
| 146 | fCurrRec->fInfo.fOffset.fY); |
| 147 | } else { |
commit-bot@chromium.org | 79fbb40 | 2014-03-12 09:42:01 +0000 | [diff] [blame] | 148 | canvas->translate(fCurrRec->fInfo.fOffset.fX, |
| 149 | fCurrRec->fInfo.fOffset.fY); |
reed@google.com | 0716c63 | 2011-04-12 18:32:06 +0000 | [diff] [blame] | 150 | } |
mike@reedtribe.org | e5d0def | 2011-04-08 00:53:48 +0000 | [diff] [blame] | 151 | fCurrRec = fCurrRec->fNext; |
| 152 | |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 153 | return true; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 154 | } |
| 155 | |
reed@google.com | daaafa6 | 2014-04-29 15:20:16 +0000 | [diff] [blame] | 156 | bool SkLayerDrawLooper::asABlurShadow(BlurShadowRec* bsRec) const { |
| 157 | if (fCount != 2) { |
| 158 | return false; |
| 159 | } |
| 160 | const Rec* rec = fRecs; |
| 161 | |
| 162 | // bottom layer needs to be just blur(maskfilter) |
| 163 | if ((rec->fInfo.fPaintBits & ~kMaskFilter_Bit)) { |
| 164 | return false; |
| 165 | } |
| 166 | if (SkXfermode::kSrc_Mode != rec->fInfo.fColorMode) { |
| 167 | return false; |
| 168 | } |
| 169 | const SkMaskFilter* mf = rec->fPaint.getMaskFilter(); |
| 170 | if (NULL == mf) { |
| 171 | return false; |
| 172 | } |
| 173 | SkMaskFilter::BlurRec maskBlur; |
| 174 | if (!mf->asABlur(&maskBlur)) { |
| 175 | return false; |
| 176 | } |
| 177 | |
| 178 | rec = rec->fNext; |
| 179 | // top layer needs to be "plain" |
| 180 | if (rec->fInfo.fPaintBits) { |
| 181 | return false; |
| 182 | } |
| 183 | if (SkXfermode::kDst_Mode != rec->fInfo.fColorMode) { |
| 184 | return false; |
| 185 | } |
| 186 | if (!rec->fInfo.fOffset.equals(0, 0)) { |
| 187 | return false; |
| 188 | } |
| 189 | |
| 190 | if (bsRec) { |
| 191 | bsRec->fSigma = maskBlur.fSigma; |
| 192 | bsRec->fOffset = fRecs->fInfo.fOffset; |
| 193 | bsRec->fColor = fRecs->fPaint.getColor(); |
| 194 | bsRec->fStyle = maskBlur.fStyle; |
| 195 | bsRec->fQuality = maskBlur.fQuality; |
| 196 | } |
| 197 | return true; |
| 198 | } |
| 199 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 200 | /////////////////////////////////////////////////////////////////////////////// |
| 201 | |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 202 | void SkLayerDrawLooper::flatten(SkWriteBuffer& buffer) const { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 203 | buffer.writeInt(fCount); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 204 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 205 | Rec* rec = fRecs; |
| 206 | for (int i = 0; i < fCount; i++) { |
reed@google.com | 842292f | 2014-02-28 15:38:22 +0000 | [diff] [blame] | 207 | // Legacy "flagsmask" field -- now ignored, remove when we bump version |
| 208 | buffer.writeInt(0); |
| 209 | |
reed@google.com | 0716c63 | 2011-04-12 18:32:06 +0000 | [diff] [blame] | 210 | buffer.writeInt(rec->fInfo.fPaintBits); |
| 211 | buffer.writeInt(rec->fInfo.fColorMode); |
djsollen@google.com | c73dd5c | 2012-08-07 15:54:32 +0000 | [diff] [blame] | 212 | buffer.writePoint(rec->fInfo.fOffset); |
reed@google.com | 0716c63 | 2011-04-12 18:32:06 +0000 | [diff] [blame] | 213 | buffer.writeBool(rec->fInfo.fPostTranslate); |
djsollen@google.com | c73dd5c | 2012-08-07 15:54:32 +0000 | [diff] [blame] | 214 | buffer.writePaint(rec->fPaint); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 215 | rec = rec->fNext; |
| 216 | } |
| 217 | } |
| 218 | |
commit-bot@chromium.org | 74ba2f6 | 2014-02-14 10:06:42 +0000 | [diff] [blame] | 219 | SkFlattenable* SkLayerDrawLooper::CreateProc(SkReadBuffer& buffer) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 220 | int count = buffer.readInt(); |
| 221 | |
commit-bot@chromium.org | 74ba2f6 | 2014-02-14 10:06:42 +0000 | [diff] [blame] | 222 | Builder builder; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 223 | for (int i = 0; i < count; i++) { |
reed@google.com | 0716c63 | 2011-04-12 18:32:06 +0000 | [diff] [blame] | 224 | LayerInfo info; |
reed@google.com | 842292f | 2014-02-28 15:38:22 +0000 | [diff] [blame] | 225 | // Legacy "flagsmask" field -- now ignored, remove when we bump version |
reed@google.com | 48f31bd | 2014-02-27 14:27:44 +0000 | [diff] [blame] | 226 | (void)buffer.readInt(); |
reed@google.com | 842292f | 2014-02-28 15:38:22 +0000 | [diff] [blame] | 227 | |
reed@google.com | 0716c63 | 2011-04-12 18:32:06 +0000 | [diff] [blame] | 228 | info.fPaintBits = buffer.readInt(); |
| 229 | info.fColorMode = (SkXfermode::Mode)buffer.readInt(); |
djsollen@google.com | c73dd5c | 2012-08-07 15:54:32 +0000 | [diff] [blame] | 230 | buffer.readPoint(&info.fOffset); |
reed@google.com | 0716c63 | 2011-04-12 18:32:06 +0000 | [diff] [blame] | 231 | info.fPostTranslate = buffer.readBool(); |
commit-bot@chromium.org | 74ba2f6 | 2014-02-14 10:06:42 +0000 | [diff] [blame] | 232 | buffer.readPaint(builder.addLayerOnTop(info)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 233 | } |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 234 | return builder.detachLooper(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 235 | } |
robertphillips@google.com | 4991b8f | 2013-01-28 20:21:59 +0000 | [diff] [blame] | 236 | |
commit-bot@chromium.org | 0f10f7b | 2014-03-13 18:02:17 +0000 | [diff] [blame] | 237 | #ifndef SK_IGNORE_TO_STRING |
robertphillips@google.com | 4991b8f | 2013-01-28 20:21:59 +0000 | [diff] [blame] | 238 | void SkLayerDrawLooper::toString(SkString* str) const { |
| 239 | str->appendf("SkLayerDrawLooper (%d): ", fCount); |
| 240 | |
| 241 | Rec* rec = fRecs; |
| 242 | for (int i = 0; i < fCount; i++) { |
reed@google.com | 842292f | 2014-02-28 15:38:22 +0000 | [diff] [blame] | 243 | str->appendf("%d: paintBits: (", i); |
robertphillips@google.com | 4991b8f | 2013-01-28 20:21:59 +0000 | [diff] [blame] | 244 | if (0 == rec->fInfo.fPaintBits) { |
| 245 | str->append("None"); |
| 246 | } else if (kEntirePaint_Bits == rec->fInfo.fPaintBits) { |
| 247 | str->append("EntirePaint"); |
| 248 | } else { |
| 249 | bool needSeparator = false; |
| 250 | SkAddFlagToString(str, SkToBool(kStyle_Bit & rec->fInfo.fPaintBits), "Style", |
| 251 | &needSeparator); |
skia.committer@gmail.com | cdcb2ce | 2013-01-29 07:05:52 +0000 | [diff] [blame] | 252 | SkAddFlagToString(str, SkToBool(kTextSkewX_Bit & rec->fInfo.fPaintBits), "TextSkewX", |
robertphillips@google.com | 4991b8f | 2013-01-28 20:21:59 +0000 | [diff] [blame] | 253 | &needSeparator); |
| 254 | SkAddFlagToString(str, SkToBool(kPathEffect_Bit & rec->fInfo.fPaintBits), "PathEffect", |
| 255 | &needSeparator); |
| 256 | SkAddFlagToString(str, SkToBool(kMaskFilter_Bit & rec->fInfo.fPaintBits), "MaskFilter", |
| 257 | &needSeparator); |
skia.committer@gmail.com | cdcb2ce | 2013-01-29 07:05:52 +0000 | [diff] [blame] | 258 | SkAddFlagToString(str, SkToBool(kShader_Bit & rec->fInfo.fPaintBits), "Shader", |
robertphillips@google.com | 4991b8f | 2013-01-28 20:21:59 +0000 | [diff] [blame] | 259 | &needSeparator); |
skia.committer@gmail.com | cdcb2ce | 2013-01-29 07:05:52 +0000 | [diff] [blame] | 260 | SkAddFlagToString(str, SkToBool(kColorFilter_Bit & rec->fInfo.fPaintBits), "ColorFilter", |
robertphillips@google.com | 4991b8f | 2013-01-28 20:21:59 +0000 | [diff] [blame] | 261 | &needSeparator); |
skia.committer@gmail.com | cdcb2ce | 2013-01-29 07:05:52 +0000 | [diff] [blame] | 262 | SkAddFlagToString(str, SkToBool(kXfermode_Bit & rec->fInfo.fPaintBits), "Xfermode", |
robertphillips@google.com | 4991b8f | 2013-01-28 20:21:59 +0000 | [diff] [blame] | 263 | &needSeparator); |
| 264 | } |
| 265 | str->append(") "); |
| 266 | |
| 267 | static const char* gModeStrings[SkXfermode::kLastMode+1] = { |
| 268 | "kClear", "kSrc", "kDst", "kSrcOver", "kDstOver", "kSrcIn", "kDstIn", |
| 269 | "kSrcOut", "kDstOut", "kSrcATop", "kDstATop", "kXor", "kPlus", |
| 270 | "kMultiply", "kScreen", "kOverlay", "kDarken", "kLighten", "kColorDodge", |
| 271 | "kColorBurn", "kHardLight", "kSoftLight", "kDifference", "kExclusion" |
| 272 | }; |
| 273 | |
| 274 | str->appendf("mode: %s ", gModeStrings[rec->fInfo.fColorMode]); |
| 275 | |
| 276 | str->append("offset: ("); |
| 277 | str->appendScalar(rec->fInfo.fOffset.fX); |
| 278 | str->append(", "); |
| 279 | str->appendScalar(rec->fInfo.fOffset.fY); |
| 280 | str->append(") "); |
| 281 | |
| 282 | str->append("postTranslate: "); |
| 283 | if (rec->fInfo.fPostTranslate) { |
| 284 | str->append("true "); |
| 285 | } else { |
| 286 | str->append("false "); |
| 287 | } |
| 288 | |
robertphillips@google.com | 791f12e | 2013-02-14 13:53:53 +0000 | [diff] [blame] | 289 | rec->fPaint.toString(str); |
robertphillips@google.com | 4991b8f | 2013-01-28 20:21:59 +0000 | [diff] [blame] | 290 | rec = rec->fNext; |
| 291 | } |
| 292 | } |
| 293 | #endif |
commit-bot@chromium.org | 74ba2f6 | 2014-02-14 10:06:42 +0000 | [diff] [blame] | 294 | |
| 295 | SkLayerDrawLooper::Builder::Builder() |
| 296 | : fRecs(NULL), |
| 297 | fTopRec(NULL), |
| 298 | fCount(0) { |
| 299 | } |
| 300 | |
| 301 | SkLayerDrawLooper::Builder::~Builder() { |
| 302 | Rec* rec = fRecs; |
| 303 | while (rec) { |
| 304 | Rec* next = rec->fNext; |
| 305 | SkDELETE(rec); |
| 306 | rec = next; |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | SkPaint* SkLayerDrawLooper::Builder::addLayer(const LayerInfo& info) { |
| 311 | fCount += 1; |
| 312 | |
| 313 | Rec* rec = SkNEW(Rec); |
| 314 | rec->fNext = fRecs; |
| 315 | rec->fInfo = info; |
| 316 | fRecs = rec; |
| 317 | if (NULL == fTopRec) { |
| 318 | fTopRec = rec; |
| 319 | } |
| 320 | |
| 321 | return &rec->fPaint; |
| 322 | } |
| 323 | |
| 324 | void SkLayerDrawLooper::Builder::addLayer(SkScalar dx, SkScalar dy) { |
| 325 | LayerInfo info; |
| 326 | |
| 327 | info.fOffset.set(dx, dy); |
| 328 | (void)this->addLayer(info); |
| 329 | } |
| 330 | |
| 331 | SkPaint* SkLayerDrawLooper::Builder::addLayerOnTop(const LayerInfo& info) { |
| 332 | fCount += 1; |
| 333 | |
| 334 | Rec* rec = SkNEW(Rec); |
| 335 | rec->fNext = NULL; |
| 336 | rec->fInfo = info; |
| 337 | if (NULL == fRecs) { |
| 338 | fRecs = rec; |
| 339 | } else { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 340 | SkASSERT(fTopRec); |
commit-bot@chromium.org | 74ba2f6 | 2014-02-14 10:06:42 +0000 | [diff] [blame] | 341 | fTopRec->fNext = rec; |
| 342 | } |
| 343 | fTopRec = rec; |
| 344 | |
| 345 | return &rec->fPaint; |
| 346 | } |
| 347 | |
| 348 | SkLayerDrawLooper* SkLayerDrawLooper::Builder::detachLooper() { |
| 349 | SkLayerDrawLooper* looper = SkNEW(SkLayerDrawLooper); |
| 350 | looper->fCount = fCount; |
| 351 | looper->fRecs = fRecs; |
| 352 | |
| 353 | fCount = 0; |
| 354 | fRecs = NULL; |
| 355 | fTopRec = NULL; |
| 356 | |
| 357 | return looper; |
| 358 | } |