SkRasterPipeline.cpp revision e1caee1ad884def91b8afb50e5672f1f0ee278f1
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 11SkRasterPipeline::SkRasterPipeline() {} 12 13void SkRasterPipeline::append(StockStage stage, void* ctx) { 14 SkASSERT(stage != from_srgb); 15 fStages.push_back({stage, ctx}); 16} 17 18void SkRasterPipeline::extend(const SkRasterPipeline& src) { 19 fStages.insert(fStages.end(), 20 src.fStages.begin(), src.fStages.end()); 21} 22 23void 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 34std::function<void(size_t, size_t)> SkRasterPipeline::compile() const { 35 return SkOpts::compile_pipeline(fStages.data(), SkToInt(fStages.size())); 36} 37 38void SkRasterPipeline::dump() const { 39 SkDebugf("SkRasterPipeline, %d stages\n", SkToInt(fStages.size())); 40 for (auto&& st : fStages) { 41 const char* name = ""; 42 switch (st.stage) { 43 #define M(x) case x: name = #x; break; 44 SK_RASTER_PIPELINE_STAGES(M) 45 #undef M 46 } 47 SkDebugf("\t%s\n", name); 48 } 49 SkDebugf("\n"); 50} 51 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. 57 58// This is an annoying problem with no known good solution. So apply the clamp hammer. 59 60void SkRasterPipeline::append_from_srgb(SkAlphaType at) { 61 //this->append(from_srgb); 62 fStages.push_back({from_srgb, nullptr}); 63 64 if (at == kPremul_SkAlphaType) { 65 this->append(SkRasterPipeline::clamp_a); 66 } 67} 68