2 * Copyright 2016 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "SkRasterPipeline.h"
10 SkRasterPipeline::SkRasterPipeline(SkArenaAlloc* alloc) : fAlloc(alloc) {
13 void SkRasterPipeline::reset() {
15 fSlotsNeeded = 1; // We always need one extra slot for just_return().
18 void SkRasterPipeline::append(StockStage stage, void* ctx) {
19 SkASSERT(stage != from_srgb);
20 this->unchecked_append(stage, ctx);
22 void SkRasterPipeline::unchecked_append(StockStage stage, void* ctx) {
23 fStages = fAlloc->make<StageList>( StageList{fStages, stage, ctx} );
24 fSlotsNeeded += ctx ? 2 : 1;
27 void SkRasterPipeline::extend(const SkRasterPipeline& src) {
28 this->extend(src.fStages);
30 void SkRasterPipeline::extend(const StageList* stages) {
34 this->extend(stages->prev);
35 this->unchecked_append(stages->stage, stages->ctx);
38 void SkRasterPipeline::dump() const {
39 SkDebugf("SkRasterPipeline, (in reverse)\n");
40 for (auto st = fStages; st; st = st->prev) {
41 const char* name = "";
43 #define M(x) case x: name = #x; break;
44 SK_RASTER_PIPELINE_STAGES(M)
47 SkDebugf("\t%s\n", name);
52 // It's pretty easy to start with sound premultiplied linear floats, pack those
53 // to sRGB encoded bytes, then read them back to linear floats and find them not
54 // quite premultiplied, with a color channel just a smidge greater than the alpha
55 // channel. This can happen basically any time we have different transfer
56 // functions for alpha and colors... sRGB being the only one we draw into.
58 // This is an annoying problem with no known good solution. So apply the clamp hammer.
60 void SkRasterPipeline::append_from_srgb(SkAlphaType at) {
61 this->unchecked_append(from_srgb, nullptr);
62 if (at == kPremul_SkAlphaType) {
63 this->append(SkRasterPipeline::clamp_a);