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 "SkOpts.h"
9 #include "SkRasterPipeline.h"
10
SkRasterPipeline()11 SkRasterPipeline::SkRasterPipeline() {}
12
append(StockStage stage,void * ctx)13 void SkRasterPipeline::append(StockStage stage, void* ctx) {
14 SkASSERT(stage != from_srgb);
15 fStages.push_back({stage, ctx});
16 }
17
extend(const SkRasterPipeline & src)18 void SkRasterPipeline::extend(const SkRasterPipeline& src) {
19 fStages.insert(fStages.end(),
20 src.fStages.begin(), src.fStages.end());
21 }
22
run(size_t x,size_t n) const23 void SkRasterPipeline::run(size_t x, size_t n) const {
24 if (!fStages.empty()) {
25 #if defined(SK_JUMPER)
26 if (this->run_with_jumper(x, n)) {
27 return;
28 }
29 #endif
30 SkOpts::run_pipeline(x,n, fStages.data(), SkToInt(fStages.size()));
31 }
32 }
33
dump() const34 void SkRasterPipeline::dump() const {
35 SkDebugf("SkRasterPipeline, %d stages\n", SkToInt(fStages.size()));
36 for (auto&& st : fStages) {
37 const char* name = "";
38 switch (st.stage) {
39 #define M(x) case x: name = #x; break;
40 SK_RASTER_PIPELINE_STAGES(M)
41 #undef M
42 }
43 SkDebugf("\t%s\n", name);
44 }
45 SkDebugf("\n");
46 }
47
48 // It's pretty easy to start with sound premultiplied linear floats, pack those
49 // to sRGB encoded bytes, then read them back to linear floats and find them not
50 // quite premultiplied, with a color channel just a smidge greater than the alpha
51 // channel. This can happen basically any time we have different transfer
52 // functions for alpha and colors... sRGB being the only one we draw into.
53
54 // This is an annoying problem with no known good solution. So apply the clamp hammer.
55
append_from_srgb(SkAlphaType at)56 void SkRasterPipeline::append_from_srgb(SkAlphaType at) {
57 //this->append(from_srgb);
58 fStages.push_back({from_srgb, nullptr});
59
60 if (at == kPremul_SkAlphaType) {
61 this->append(SkRasterPipeline::clamp_a);
62 }
63 }
64