SkRasterPipeline.cpp revision 9a5c47f4effba3b48a9a8c7c144b72b532d06efe
1/*
2 * Copyright 2016 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 */
7
8#include "SkRasterPipeline.h"
9
10SkRasterPipeline::SkRasterPipeline() {}
11
12void SkRasterPipeline::append(SkRasterPipeline::Fn body_fn, const void* body_ctx,
13                              SkRasterPipeline::Fn tail_fn, const void* tail_ctx) {
14    // Each stage holds its own context and the next function to call.
15    // So the pipeline itself has to hold onto the first function that starts the pipeline.
16    (fBody.empty() ? fBodyStart : fBody.back().fNext) = body_fn;
17    (fTail.empty() ? fTailStart : fTail.back().fNext) = tail_fn;
18
19    // Each last stage starts with its next function set to JustReturn as a safety net.
20    // It'll be overwritten by the next call to append().
21    fBody.push_back({ &JustReturn, const_cast<void*>(body_ctx) });
22    fTail.push_back({ &JustReturn, const_cast<void*>(tail_ctx) });
23}
24
25void SkRasterPipeline::extend(const SkRasterPipeline& src) {
26    SkASSERT(src.fBody.count() == src.fTail.count());
27
28    Fn body_fn = src.fBodyStart,
29       tail_fn = src.fTailStart;
30    for (int i = 0; i < src.fBody.count(); i++) {
31        this->append(body_fn, src.fBody[i].fCtx,
32                     tail_fn, src.fTail[i].fCtx);
33        body_fn = src.fBody[i].fNext;
34        tail_fn = src.fTail[i].fNext;
35    }
36}
37
38void SkRasterPipeline::run(size_t x, size_t n) {
39    // It's fastest to start uninitialized if the compilers all let us.  If not, next fastest is 0.
40    Sk4f v;
41
42    while (n >= 4) {
43        fBodyStart(fBody.begin(), x, v,v,v,v, v,v,v,v);
44        x += 4;
45        n -= 4;
46    }
47    while (n > 0) {
48        fTailStart(fTail.begin(), x, v,v,v,v, v,v,v,v);
49        x += 1;
50        n -= 1;
51    }
52}
53
54void SK_VECTORCALL SkRasterPipeline::JustReturn(Stage*, size_t, Sk4f,Sk4f,Sk4f,Sk4f,
55                                                                Sk4f,Sk4f,Sk4f,Sk4f) {}
56