aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkRasterPipeline.cpp
blob: 81b98677b2cf26d107e94768f72c17327a3d26fa (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
60
61
62
63
64
65
66
67
/*
 * 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(StockStage stage, void* ctx) {
    SkASSERT(stage != from_srgb);
    fStages.push_back({stage, ctx});
}

void SkRasterPipeline::extend(const SkRasterPipeline& src) {
    fStages.insert(fStages.end(),
                   src.fStages.begin(), src.fStages.end());
}

void SkRasterPipeline::run(size_t x, size_t n) const {
    if (!fStages.empty()) {
    #if defined(SK_JUMPER)
        if (this->run_with_jumper(x, n)) {
            return;
        }
    #endif
        SkOpts::run_pipeline(x,n, fStages.data(), SkToInt(fStages.size()));
    }
}

std::function<void(size_t, size_t)> SkRasterPipeline::compile() const {
    return SkOpts::compile_pipeline(fStages.data(), SkToInt(fStages.size()));
}

void SkRasterPipeline::dump() const {
    SkDebugf("SkRasterPipeline, %d stages\n", SkToInt(fStages.size()));
    for (auto&& st : fStages) {
        const char* name = "";
        switch (st.stage) {
        #define M(x) case x: name = #x; break;
            SK_RASTER_PIPELINE_STAGES(M)
        #undef M
        }
        SkDebugf("\t%s\n", name);
    }
    SkDebugf("\n");
}

// It's pretty easy to start with sound premultiplied linear floats, pack those
// to sRGB encoded bytes, then read them back to linear floats and find them not
// quite premultiplied, with a color channel just a smidge greater than the alpha
// channel.  This can happen basically any time we have different transfer
// functions for alpha and colors... sRGB being the only one we draw into.

// This is an annoying problem with no known good solution.  So apply the clamp hammer.

void SkRasterPipeline::append_from_srgb(SkAlphaType at) {
    //this->append(from_srgb);
    fStages.push_back({from_srgb, nullptr});

    if (at == kPremul_SkAlphaType) {
        this->append(SkRasterPipeline::clamp_a);
    }
}