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