aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkRasterPipeline.cpp
blob: 72d5b7b96393e9f779c1c5469c0e6f36c39a3ef4 (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
/*
 * Copyright 2016 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "SkOpts.h"
#include "SkRasterPipeline.h"

SkRasterPipeline::SkRasterPipeline() {}

void SkRasterPipeline::append(SkRasterPipeline::Fn body,
                              SkRasterPipeline::Fn tail,
                              void* ctx) {
    // Each stage holds its own context and the next function to call.
    // So the pipeline itself has to hold onto the first function that starts the pipeline.
    (fBody.empty() ? fBodyStart : fBody.back().fNext) = body;
    (fTail.empty() ? fTailStart : fTail.back().fNext) = tail;

    // Each last stage starts with its next function set to JustReturn as a safety net.
    // It'll be overwritten by the next call to append().
    fBody.push_back({ &JustReturn, ctx });
    fTail.push_back({ &JustReturn, ctx });
}

void SkRasterPipeline::append(StockStage stage, void* ctx) {
    this->append(SkOpts::stages_4[stage], SkOpts::stages_1_3[stage], ctx);
}

void SkRasterPipeline::extend(const SkRasterPipeline& src) {
    SkASSERT(src.fBody.count() == src.fTail.count());

    Fn body = src.fBodyStart,
       tail = src.fTailStart;
    for (int i = 0; i < src.fBody.count(); i++) {
        SkASSERT(src.fBody[i].fCtx == src.fTail[i].fCtx);
        this->append(body, tail, src.fBody[i].fCtx);
        body = src.fBody[i].fNext;
        tail = src.fTail[i].fNext;
    }
}

void SkRasterPipeline::run(size_t x, size_t n) {
    // It's fastest to start uninitialized if the compilers all let us.  If not, next fastest is 0.
    Sk4f v;

    while (n >= 4) {
        fBodyStart(fBody.begin(), x,0, v,v,v,v, v,v,v,v);
        x += 4;
        n -= 4;
    }
    if (n > 0) {
        fTailStart(fTail.begin(), x,n, v,v,v,v, v,v,v,v);
    }
}

void SK_VECTORCALL SkRasterPipeline::JustReturn(Stage*, size_t, size_t, Sk4f,Sk4f,Sk4f,Sk4f,
                                                                        Sk4f,Sk4f,Sk4f,Sk4f) {}