aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkDraw_vertices.cpp
blob: ff33d5df2ed00002fb827d577f0d2367d443f0d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
/*
 * Copyright 2017 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "SkArenaAlloc.h"
#include "SkAutoBlitterChoose.h"
#include "SkColorShader.h"
#include "SkDraw.h"
#include "SkNx.h"
#include "SkPM4fPriv.h"
#include "SkRasterClip.h"
#include "SkScan.h"
#include "SkShader.h"
#include "SkString.h"
#include "SkVertState.h"

#include "SkRasterPipeline.h"
#include "SkArenaAlloc.h"
#include "SkCoreBlitters.h"
#include "SkColorSpaceXform.h"
#include "SkColorSpace_Base.h"

struct Matrix43 {
    float fMat[12];    // column major

    Sk4f map(float x, float y) const {
        return Sk4f::Load(&fMat[0]) * x + Sk4f::Load(&fMat[4]) * y + Sk4f::Load(&fMat[8]);
    }

    void setConcat(const Matrix43& a, const SkMatrix& b) {
        fMat[ 0] = a.dot(0, b.getScaleX(), b.getSkewY());
        fMat[ 1] = a.dot(1, b.getScaleX(), b.getSkewY());
        fMat[ 2] = a.dot(2, b.getScaleX(), b.getSkewY());
        fMat[ 3] = a.dot(3, b.getScaleX(), b.getSkewY());

        fMat[ 4] = a.dot(0, b.getSkewX(), b.getScaleY());
        fMat[ 5] = a.dot(1, b.getSkewX(), b.getScaleY());
        fMat[ 6] = a.dot(2, b.getSkewX(), b.getScaleY());
        fMat[ 7] = a.dot(3, b.getSkewX(), b.getScaleY());

        fMat[ 8] = a.dot(0, b.getTranslateX(), b.getTranslateY()) + a.fMat[ 8];
        fMat[ 9] = a.dot(1, b.getTranslateX(), b.getTranslateY()) + a.fMat[ 9];
        fMat[10] = a.dot(2, b.getTranslateX(), b.getTranslateY()) + a.fMat[10];
        fMat[11] = a.dot(3, b.getTranslateX(), b.getTranslateY()) + a.fMat[11];
    }

private:
    float dot(int index, float x, float y) const {
        return fMat[index + 0] * x + fMat[index + 4] * y;
    }
};

static SkScan::HairRCProc ChooseHairProc(bool doAntiAlias) {
    return doAntiAlias ? SkScan::AntiHairLine : SkScan::HairLine;
}

static bool texture_to_matrix(const VertState& state, const SkPoint verts[],
                              const SkPoint texs[], SkMatrix* matrix) {
    SkPoint src[3], dst[3];

    src[0] = texs[state.f0];
    src[1] = texs[state.f1];
    src[2] = texs[state.f2];
    dst[0] = verts[state.f0];
    dst[1] = verts[state.f1];
    dst[2] = verts[state.f2];
    return matrix->setPolyToPoly(src, dst, 3);
}

class SkTriColorShader : public SkShader {
public:
    SkTriColorShader();

    class TriColorShaderContext : public SkShader::Context {
    public:
        TriColorShaderContext(const SkTriColorShader& shader, const ContextRec&);
        ~TriColorShaderContext() override;
        void shadeSpan(int x, int y, SkPMColor dstC[], int count) override;
        void shadeSpan4f(int x, int y, SkPM4f dstC[], int count) override;

    private:
        bool setup(const SkPoint pts[], const SkColor colors[], int, int, int);

        SkMatrix    fDstToUnit;
        SkPMColor   fColors[3];
        bool fSetup;

        Matrix43 fM43;

        typedef SkShader::Context INHERITED;
    };

    struct TriColorShaderData {
        const SkPoint* pts;
        const SkColor* colors;
        const VertState *state;
    };

    SK_TO_STRING_OVERRIDE()

    // For serialization.  This will never be called.
    Factory getFactory() const override { sk_throw(); return nullptr; }

    // Supply setup data to context from drawing setup
    void bindSetupData(TriColorShaderData* setupData) { fSetupData = setupData; }

    // Take the setup data from context when needed.
    TriColorShaderData* takeSetupData() {
        TriColorShaderData *data = fSetupData;
        fSetupData = NULL;
        return data;
    }

protected:
    Context* onMakeContext(const ContextRec& rec, SkArenaAlloc* alloc) const override {
        return alloc->make<TriColorShaderContext>(*this, rec);
    }

private:
    TriColorShaderData *fSetupData;

    typedef SkShader INHERITED;
};

bool SkTriColorShader::TriColorShaderContext::setup(const SkPoint pts[], const SkColor colors[],
                                                    int index0, int index1, int index2) {

    fColors[0] = SkPreMultiplyColor(colors[index0]);
    fColors[1] = SkPreMultiplyColor(colors[index1]);
    fColors[2] = SkPreMultiplyColor(colors[index2]);

    SkMatrix m, im;
    m.reset();
    m.set(0, pts[index1].fX - pts[index0].fX);
    m.set(1, pts[index2].fX - pts[index0].fX);
    m.set(2, pts[index0].fX);
    m.set(3, pts[index1].fY - pts[index0].fY);
    m.set(4, pts[index2].fY - pts[index0].fY);
    m.set(5, pts[index0].fY);
    if (!m.invert(&im)) {
        return false;
    }
    // We can't call getTotalInverse(), because we explicitly don't want to look at the localmatrix
    // as our interators are intrinsically tied to the vertices, and nothing else.
    SkMatrix ctmInv;
    if (!this->getCTM().invert(&ctmInv)) {
        return false;
    }
    // TODO replace INV(m) * INV(ctm) with INV(ctm * m)
    fDstToUnit.setConcat(im, ctmInv);

    Sk4f alpha(this->getPaintAlpha() * (1.0f / 255)),
    c0 = SkPM4f::FromPMColor(fColors[0]).to4f() * alpha,
    c1 = SkPM4f::FromPMColor(fColors[1]).to4f() * alpha,
    c2 = SkPM4f::FromPMColor(fColors[2]).to4f() * alpha;

    Matrix43 colorm;
    (c1 - c0).store(&colorm.fMat[0]);
    (c2 - c0).store(&colorm.fMat[4]);
    c0.store(&colorm.fMat[8]);
    fM43.setConcat(colorm, fDstToUnit);

    return true;
}

#include "SkColorPriv.h"
#include "SkComposeShader.h"

static int ScalarTo256(SkScalar v) {
    return static_cast<int>(SkScalarPin(v, 0, 1) * 256 + 0.5);
}

SkTriColorShader::SkTriColorShader()
: INHERITED(NULL)
, fSetupData(NULL) {}

SkTriColorShader::TriColorShaderContext::TriColorShaderContext(const SkTriColorShader& shader,
                                                               const ContextRec& rec)
: INHERITED(shader, rec)
, fSetup(false) {}

SkTriColorShader::TriColorShaderContext::~TriColorShaderContext() {}

void SkTriColorShader::TriColorShaderContext::shadeSpan(int x, int y, SkPMColor dstC[], int count) {
    SkTriColorShader* parent = static_cast<SkTriColorShader*>(const_cast<SkShader*>(&fShader));
    TriColorShaderData* set = parent->takeSetupData();
    if (set) {
        fSetup = setup(set->pts, set->colors, set->state->f0, set->state->f1, set->state->f2);
    }

    if (!fSetup) {
        // Invalid matrices. Not checked before so no need to assert.
        return;
    }

    const int alphaScale = Sk255To256(this->getPaintAlpha());

    SkPoint src;

    fDstToUnit.mapXY(SkIntToScalar(x) + 0.5, SkIntToScalar(y) + 0.5, &src);
    for (int i = 0; i < count; i++) {
        int scale1 = ScalarTo256(src.fX);
        int scale2 = ScalarTo256(src.fY);
        int scale0 = 256 - scale1 - scale2;
        if (scale0 < 0) {
            if (scale1 > scale2) {
                scale2 = 256 - scale1;
            } else {
                scale1 = 256 - scale2;
            }
            scale0 = 0;
        }

        if (256 != alphaScale) {
            scale0 = SkAlphaMul(scale0, alphaScale);
            scale1 = SkAlphaMul(scale1, alphaScale);
            scale2 = SkAlphaMul(scale2, alphaScale);
        }

        dstC[i] = SkAlphaMulQ(fColors[0], scale0) +
        SkAlphaMulQ(fColors[1], scale1) +
        SkAlphaMulQ(fColors[2], scale2);

        src.fX += fDstToUnit.getScaleX();
        src.fY += fDstToUnit.getSkewY();
    }
}

void SkTriColorShader::TriColorShaderContext::shadeSpan4f(int x, int y, SkPM4f dstC[], int count) {
    SkTriColorShader* parent = static_cast<SkTriColorShader*>(const_cast<SkShader*>(&fShader));
    TriColorShaderData* set = parent->takeSetupData();
    if (set) {
        fSetup = setup(set->pts, set->colors, set->state->f0, set->state->f1, set->state->f2);
    }

    if (!fSetup) {
        // Invalid matrices. Not checked before so no need to assert.
        return;
    }

    Sk4f c  = fM43.map(SkIntToScalar(x) + 0.5, SkIntToScalar(y) + 0.5),
    dc = Sk4f::Load(&fM43.fMat[0]),
    zero(0.0f),
    one(1.0f);

    for (int i = 0; i < count; i++) {
        // We don't expect to be wildly out of 0...1, but we pin just because of minor
        // numerical imprecision.
        Sk4f::Min(Sk4f::Max(c, zero), Sk4f::Min(c[3], one)).store(dstC + i);
        c += dc;
    }
}

#ifndef SK_IGNORE_TO_STRING
void SkTriColorShader::toString(SkString* str) const {
    str->append("SkTriColorShader: (");

    this->INHERITED::toString(str);

    str->append(")");
}
#endif


namespace {

    // Similar to SkLocalMatrixShader, but composes the local matrix with the CTM (instead
    // of composing with the inherited local matrix):
    //
    //   rec' = {rec.ctm x localMatrix, rec.localMatrix}
    //
    // (as opposed to rec' = {rec.ctm, rec.localMatrix x localMatrix})
    //
    class SkLocalInnerMatrixShader final : public SkShader {
    public:
        SkLocalInnerMatrixShader(sk_sp<SkShader> proxy, const SkMatrix& localMatrix)
        : INHERITED(&localMatrix)
        , fProxyShader(std::move(proxy)) {}

        Factory getFactory() const override {
            SkASSERT(false);
            return nullptr;
        }

    protected:
        void flatten(SkWriteBuffer&) const override {
            SkASSERT(false);
        }

        Context* onMakeContext(const ContextRec& rec, SkArenaAlloc* alloc) const override {
            SkMatrix adjustedCTM = SkMatrix::Concat(*rec.fMatrix, this->getLocalMatrix());
            ContextRec newRec(rec);
            newRec.fMatrix = &adjustedCTM;
            return fProxyShader->makeContext(newRec, alloc);
        }

        bool onAppendStages(SkRasterPipeline* p, SkColorSpace* cs, SkArenaAlloc* alloc,
                            const SkMatrix& ctm, const SkPaint& paint,
                            const SkMatrix* localM) const override {
            // We control the shader graph ancestors, so we know there's no local matrix being
            // injected before this.
            SkASSERT(!localM);

            SkMatrix adjustedCTM = SkMatrix::Concat(ctm, this->getLocalMatrix());
            return fProxyShader->appendStages(p, cs, alloc, adjustedCTM, paint);
        }

    private:
        sk_sp<SkShader> fProxyShader;

        typedef SkShader INHERITED;
    };

    sk_sp<SkShader> MakeTextureShader(const VertState& state, const SkPoint verts[],
                                      const SkPoint texs[], const SkPaint& paint,
                                      SkColorSpace* dstColorSpace,
                                      SkArenaAlloc* alloc) {
        SkASSERT(paint.getShader());

        const auto& p0 = texs[state.f0],
        p1 = texs[state.f1],
        p2 = texs[state.f2];

        if (p0 != p1 || p0 != p2) {
            // Common case (non-collapsed texture coordinates).
            // Map the texture to vertices using a local transform.

            // We cannot use a plain SkLocalMatrix shader, because we need the texture matrix
            // to compose next to the CTM.
            SkMatrix localMatrix;
            return texture_to_matrix(state, verts, texs, &localMatrix)
            ? alloc->makeSkSp<SkLocalInnerMatrixShader>(paint.refShader(), localMatrix)
            : nullptr;
        }

        // Collapsed texture coordinates special case.
        // The texture is a solid color, sampled at the given point.
        SkMatrix shaderInvLocalMatrix;
        SkAssertResult(paint.getShader()->getLocalMatrix().invert(&shaderInvLocalMatrix));

        const auto sample       = SkPoint::Make(0.5f, 0.5f);
        const auto mappedSample = shaderInvLocalMatrix.mapXY(sample.x(), sample.y()),
        mappedPoint  = shaderInvLocalMatrix.mapXY(p0.x(), p0.y());
        const auto localMatrix  = SkMatrix::MakeTrans(mappedSample.x() - mappedPoint.x(),
                                                      mappedSample.y() - mappedPoint.y());

        SkShader::ContextRec rec(paint, SkMatrix::I(), &localMatrix,
                                 SkShader::ContextRec::kPMColor_DstType, dstColorSpace);
        auto* ctx = paint.getShader()->makeContext(rec, alloc);
        if (!ctx) {
            return nullptr;
        }

        SkPMColor pmColor;
        ctx->shadeSpan(SkScalarFloorToInt(sample.x()), SkScalarFloorToInt(sample.y()), &pmColor, 1);

        // no need to keep this temp context around.
        alloc->reset();

        return alloc->makeSkSp<SkColorShader>(SkUnPreMultiply::PMColorToColor(pmColor));
    }
} // anonymous ns

static bool update_tricolor_matrix(const SkMatrix& ctmInv,
                                   const SkPoint pts[], const SkPM4f colors[],
                                   int index0, int index1, int index2, Matrix43* result) {
    SkMatrix m, im;
    m.reset();
    m.set(0, pts[index1].fX - pts[index0].fX);
    m.set(1, pts[index2].fX - pts[index0].fX);
    m.set(2, pts[index0].fX);
    m.set(3, pts[index1].fY - pts[index0].fY);
    m.set(4, pts[index2].fY - pts[index0].fY);
    m.set(5, pts[index0].fY);
    if (!m.invert(&im)) {
        return false;
    }

    SkMatrix dstToUnit;
    dstToUnit.setConcat(im, ctmInv);

    Sk4f c0 = colors[index0].to4f(),
         c1 = colors[index1].to4f(),
         c2 = colors[index2].to4f();

    Matrix43 colorm;
    (c1 - c0).store(&colorm.fMat[0]);
    (c2 - c0).store(&colorm.fMat[4]);
    c0.store(&colorm.fMat[8]);
    result->setConcat(colorm, dstToUnit);
    return true;
}

static SkPM4f* convert_colors(const SkColor src[], int count, SkColorSpace* deviceCS,
                              SkArenaAlloc* alloc) {
    SkPM4f* dst = alloc->makeArray<SkPM4f>(count);
    if (!deviceCS) {
        for (int i = 0; i < count; ++i) {
            dst[i] = SkPM4f_from_SkColor(src[i], nullptr);
        }
    } else {
        auto srcCS = SkColorSpace::MakeSRGB();
        auto dstCS = as_CSB(deviceCS)->makeLinearGamma();
        SkColorSpaceXform::Apply(dstCS.get(), SkColorSpaceXform::kRGBA_F32_ColorFormat, dst,
                                 srcCS.get(), SkColorSpaceXform::kBGRA_8888_ColorFormat, src,
                                 count, SkColorSpaceXform::kPremul_AlphaOp);
    }
    return dst;
}

static bool compute_is_opaque(const SkColor colors[], int count) {
    uint32_t c = ~0;
    for (int i = 0; i < count; ++i) {
        c &= colors[i];
    }
    return SkColorGetA(c) == 0xFF;
}

void SkDraw::drawVertices(SkVertices::VertexMode vmode, int count,
                          const SkPoint vertices[], const SkPoint textures[],
                          const SkColor colors[], SkBlendMode bmode,
                          const uint16_t indices[], int indexCount,
                          const SkPaint& paint) const {
    SkASSERT(0 == count || vertices);

    // abort early if there is nothing to draw
    if (count < 3 || (indices && indexCount < 3) || fRC->isEmpty()) {
        return;
    }
    SkMatrix ctmInv;
    if (!fMatrix->invert(&ctmInv)) {
        return;
    }

    // transform out vertices into device coordinates
    SkAutoSTMalloc<16, SkPoint> storage(count);
    SkPoint* devVerts = storage.get();
    fMatrix->mapPoints(devVerts, vertices, count);

    /*
     We can draw the vertices in 1 of 4 ways:

     - solid color (no shader/texture[], no colors[])
     - just colors (no shader/texture[], has colors[])
     - just texture (has shader/texture[], no colors[])
     - colors * texture (has shader/texture[], has colors[])

     Thus for texture drawing, we need both texture[] and a shader.
     */

    if (colors && !textures) {
        char             arenaStorage[4096];
        SkArenaAlloc     alloc(arenaStorage, sizeof(storage));
        Matrix43         matrix43;
        SkRasterPipeline shaderPipeline;

        // Convert the SkColors into float colors. The conversion depends on some conditions:
        // - If the pixmap has a dst colorspace, we have to be "color-correct".
        //   Do we map into dst-colorspace before or after we interpolate?
        // - We have to decide when to apply per-color alpha (before or after we interpolate)
        //
        // For now, we will take a simple approach, but recognize this is just a start:
        // - convert colors into dst colorspace before interpolation (matches gradients)
        // - apply per-color alpha before interpolation (matches old version of vertices)
        //
        SkPM4f* dstColors = convert_colors(colors, count, fDst.colorSpace(), &alloc);

        bool is_opaque;
        if (paint.getAlpha() == 0xff) {
            is_opaque = compute_is_opaque(colors, count);
        } else {
            is_opaque = false;
            Sk4f alpha = paint.getAlpha() * (1/255.0f);
            for (int i = 0; i < count; i++) {
                (dstColors[i].to4f() * alpha).store(dstColors + i);
            }
        }

        shaderPipeline.append(SkRasterPipeline::matrix_4x3, &matrix43);
        // In theory we should never need to clamp. However, either due to imprecision in our
        // matrix43, or the scan converter passing us pixel centers that in fact are not within
        // the triangle, we do see occasional (slightly) out-of-range values, so we add these
        // clamp stages. It would be nice to find a way to detect when these are not needed.
        shaderPipeline.append(SkRasterPipeline::clamp_0);
        shaderPipeline.append(SkRasterPipeline::clamp_a);

        bool wants_dither = paint.isDither();
        auto blitter = SkCreateRasterPipelineBlitter(fDst, paint, shaderPipeline,
                                                     is_opaque, wants_dither, &alloc);
        SkASSERT(!blitter->isNullBlitter());

        // setup our state and function pointer for iterating triangles
        VertState       state(count, indices, indexCount);
        VertState::Proc vertProc = state.chooseProc(vmode);

        while (vertProc(&state)) {
            SkPoint tmp[] = {
                devVerts[state.f0], devVerts[state.f1], devVerts[state.f2]
            };
            if (update_tricolor_matrix(ctmInv, vertices, dstColors, state.f0, state.f1, state.f2,
                                       &matrix43)) {
                SkScan::FillTriangle(tmp, *fRC, blitter);
            }
        }
        return;
    }

    auto triShader = sk_make_sp<SkTriColorShader>();
    SkPaint p(paint);

    SkShader* shader = p.getShader();
    if (nullptr == shader) {
        // if we have no shader, we ignore the texture coordinates
        textures = nullptr;
    } else if (nullptr == textures) {
        // if we don't have texture coordinates, ignore the shader
        p.setShader(nullptr);
        shader = nullptr;
    }

    // setup the custom shader (if needed)
    if (colors) {
        if (nullptr == textures) {
            // just colors (no texture)
            p.setShader(triShader);
        } else {
            // colors * texture
            SkASSERT(shader);
            p.setShader(SkShader::MakeComposeShader(triShader, sk_ref_sp(shader), bmode));
        }
    }

    SkAutoBlitterChoose blitter(fDst, *fMatrix, p);
    // Abort early if we failed to create a shader context.
    if (blitter->isNullBlitter()) {
        return;
    }

    // setup our state and function pointer for iterating triangles
    VertState       state(count, indices, indexCount);
    VertState::Proc vertProc = state.chooseProc(vmode);

    if (textures || colors) {
        SkTriColorShader::TriColorShaderData verticesSetup = { vertices, colors, &state };

        while (vertProc(&state)) {
            auto* blitterPtr = blitter.get();

            // We're going to allocate at most
            //
            //   * one SkLocalMatrixShader OR one SkColorShader
            //   * one SkComposeShader
            //   * one SkAutoBlitterChoose
            //
            static constexpr size_t kAllocSize =
            sizeof(SkAutoBlitterChoose) + sizeof(SkComposeShader) +
            SkTMax(sizeof(SkLocalInnerMatrixShader), sizeof(SkColorShader));
            char allocBuffer[kAllocSize];
            SkArenaAlloc alloc(allocBuffer);

            if (textures) {
                sk_sp<SkShader> texShader = MakeTextureShader(state, vertices, textures, paint,
                                                              fDst.colorSpace(), &alloc);
                if (texShader) {
                    SkPaint localPaint(p);
                    localPaint.setShader(colors
                                         ? alloc.makeSkSp<SkComposeShader>(triShader, std::move(texShader), bmode)
                                         : std::move(texShader));

                    blitterPtr = alloc.make<SkAutoBlitterChoose>(fDst, *fMatrix, localPaint)->get();
                    if (blitterPtr->isNullBlitter()) {
                        continue;
                    }
                }
            }
            if (colors) {
                triShader->bindSetupData(&verticesSetup);
            }

            SkPoint tmp[] = {
                devVerts[state.f0], devVerts[state.f1], devVerts[state.f2]
            };
            SkScan::FillTriangle(tmp, *fRC, blitterPtr);
            triShader->bindSetupData(nullptr);
        }
    } else {
        // no colors[] and no texture, stroke hairlines with paint's color.
        SkScan::HairRCProc hairProc = ChooseHairProc(paint.isAntiAlias());
        const SkRasterClip& clip = *fRC;
        while (vertProc(&state)) {
            SkPoint array[] = {
                devVerts[state.f0], devVerts[state.f1], devVerts[state.f2], devVerts[state.f0]
            };
            hairProc(array, 4, clip, blitter.get());
        }
    }
}