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