Chromium Code Reviews| Index: src/core/SkRasterPipeline.cpp |
| diff --git a/src/core/SkRasterPipeline.cpp b/src/core/SkRasterPipeline.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8750e03a5726035232baef8a7550b771068e2197 |
| --- /dev/null |
| +++ b/src/core/SkRasterPipeline.cpp |
| @@ -0,0 +1,61 @@ |
| +/* |
| + * 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 "SkRasterPipeline.h" |
| + |
| +SkRasterPipeline::SkRasterPipeline() {} |
| + |
| +void SkRasterPipeline::append(SkRasterPipeline::Fn body, const void* body_ctx, |
| + SkRasterPipeline::Fn tail, const void* tail_ctx) { |
| + // For now, just stash the stage's function in its own fNext slot. |
| + // We'll rewire our stages before running the pipeline so fNext makes sense. |
| + fBody.push_back({ body, const_cast<void*>(body_ctx) }); |
|
herb_g
2016/07/12 18:14:25
SkASSERT(!fReadyToRun)
mtklein_C
2016/07/12 18:24:16
Done.
|
| + fTail.push_back({ tail, const_cast<void*>(tail_ctx) }); |
| +} |
| + |
| +void SkRasterPipeline::Rewire(SkRasterPipeline::Stages* stages) { |
| + SkASSERT(!stages->empty()); |
|
herb_g
2016/07/12 18:14:25
RedayToRun assert here too
mtklein_C
2016/07/12 18:24:16
Done, by inlining Rewire() into run() as a lambda.
|
| + |
| + // Rotate the fNext pointers so they point to the next function to |
| + // call, not function we're currently calling as set by append(). |
| + auto start = stages->front().fNext; |
| + for (int i = 0; i < stages->count() - 1; i++) { |
| + (*stages)[i].fNext = (*stages)[i+1].fNext; |
| + } |
| + stages->back().fNext = start; // This is a pretty handy place to stash this. |
| +} |
| + |
| +void SkRasterPipeline::run(size_t n) { |
| + if (fBody.empty() || fTail.empty()) { |
| + return; |
| + } |
| + |
| + if (!fReadyToRun) { |
| + Rewire(&fBody); |
| + Rewire(&fTail); |
| + fReadyToRun = true; |
| + } |
| + |
| + // It's fastest to start uninitialized if the compilers all let us. If not, next fastest is 0. |
| + Sk4f v; |
| + |
| + size_t x = 0; |
| + while (n >= 4) { |
| + auto start = fBody.back().fNext; // See Rewire(). |
| + start(fBody.begin(), x, v,v,v,v, v,v,v,v); |
| + |
| + x += 4; |
| + n -= 4; |
| + } |
| + while (n > 0) { |
| + auto start = fTail.back().fNext; |
| + start(fTail.begin(), x, v,v,v,v, v,v,v,v); |
| + |
| + x += 1; |
| + n -= 1; |
| + } |
| +} |