OLD | NEW |
(Empty) | |
| 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 |
| 10 SkRasterPipeline::SkRasterPipeline() {} |
| 11 |
| 12 void SkRasterPipeline::append(SkRasterPipeline::Fn body, const void* body_ctx, |
| 13 SkRasterPipeline::Fn tail, const void* tail_ctx) { |
| 14 // We can't add more stages after being rewired to run(). |
| 15 SkASSERT(!fReadyToRun); |
| 16 |
| 17 // For now, just stash the stage's function in its own fNext slot. |
| 18 // We'll rewire our stages before running the pipeline so fNext makes sense. |
| 19 fBody.push_back({ body, const_cast<void*>(body_ctx) }); |
| 20 fTail.push_back({ tail, const_cast<void*>(tail_ctx) }); |
| 21 } |
| 22 |
| 23 void SkRasterPipeline::run(size_t n) { |
| 24 if (fBody.empty() || fTail.empty()) { |
| 25 return; |
| 26 } |
| 27 |
| 28 if (!fReadyToRun) { |
| 29 auto rewire = [](Stages* stages) { |
| 30 SkASSERT(!stages->empty()); |
| 31 |
| 32 // Rotate the fNext pointers so they point to the next function to |
| 33 // call, not function we're currently calling as set by append(). |
| 34 auto start = stages->front().fNext; |
| 35 for (int i = 0; i < stages->count() - 1; i++) { |
| 36 (*stages)[i].fNext = (*stages)[i+1].fNext; |
| 37 } |
| 38 stages->back().fNext = start; // This is a pretty handy place to st
ash this. |
| 39 }; |
| 40 rewire(&fBody); |
| 41 rewire(&fTail); |
| 42 fReadyToRun = true; |
| 43 } |
| 44 |
| 45 // It's fastest to start uninitialized if the compilers all let us. If not,
next fastest is 0. |
| 46 Sk4f v; |
| 47 |
| 48 auto start_body = fBody.back().fNext, // See rewire(). |
| 49 start_tail = fTail.back().fNext; |
| 50 |
| 51 auto body = fBody.begin(), |
| 52 tail = fTail.begin(); |
| 53 |
| 54 size_t x = 0; |
| 55 while (n >= 4) { |
| 56 start_body(body, x, v,v,v,v, v,v,v,v); |
| 57 x += 4; |
| 58 n -= 4; |
| 59 } |
| 60 while (n > 0) { |
| 61 start_tail(tail, x, v,v,v,v, v,v,v,v); |
| 62 x += 1; |
| 63 n -= 1; |
| 64 } |
| 65 } |
OLD | NEW |