OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "GrFragmentProcessor.h" | 8 #include "GrFragmentProcessor.h" |
9 #include "GrCoordTransform.h" | 9 #include "GrCoordTransform.h" |
10 #include "GrInvariantOutput.h" | 10 #include "GrInvariantOutput.h" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 | 136 |
137 sk_sp<GrFragmentProcessor> GrFragmentProcessor::MulOutputByInputAlpha( | 137 sk_sp<GrFragmentProcessor> GrFragmentProcessor::MulOutputByInputAlpha( |
138 sk_sp<GrFragmentProcessor> fp) { | 138 sk_sp<GrFragmentProcessor> fp) { |
139 if (!fp) { | 139 if (!fp) { |
140 return nullptr; | 140 return nullptr; |
141 } | 141 } |
142 return GrXfermodeFragmentProcessor::MakeFromDstProcessor(std::move(fp), | 142 return GrXfermodeFragmentProcessor::MakeFromDstProcessor(std::move(fp), |
143 SkXfermode::kDstIn_
Mode); | 143 SkXfermode::kDstIn_
Mode); |
144 } | 144 } |
145 | 145 |
| 146 sk_sp<GrFragmentProcessor> GrFragmentProcessor::PremulInput(sk_sp<GrFragmentProc
essor> fp) { |
| 147 |
| 148 class PremulInputFragmentProcessor : public GrFragmentProcessor { |
| 149 public: |
| 150 PremulInputFragmentProcessor() { |
| 151 this->initClassID<PremulInputFragmentProcessor>(); |
| 152 } |
| 153 |
| 154 const char* name() const override { return "PremultiplyInput"; } |
| 155 |
| 156 private: |
| 157 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { |
| 158 class GLFP : public GrGLSLFragmentProcessor { |
| 159 public: |
| 160 void emitCode(EmitArgs& args) override { |
| 161 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 162 |
| 163 fragBuilder->codeAppendf("%s = %s;", args.fOutputColor, args
.fInputColor); |
| 164 fragBuilder->codeAppendf("%s.rgb *= %s.a;", |
| 165 args.fOutputColor, args.fInputColor
); |
| 166 } |
| 167 }; |
| 168 return new GLFP; |
| 169 } |
| 170 |
| 171 void onGetGLSLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) co
nst override {} |
| 172 |
| 173 bool onIsEqual(const GrFragmentProcessor&) const override { return true;
} |
| 174 |
| 175 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { |
| 176 inout->premulFourChannelColor(); |
| 177 } |
| 178 }; |
| 179 if (!fp) { |
| 180 return nullptr; |
| 181 } |
| 182 sk_sp<GrFragmentProcessor> fpPipeline[] = { sk_make_sp<PremulInputFragmentPr
ocessor>(), fp}; |
| 183 return GrFragmentProcessor::RunInSeries(fpPipeline, 2); |
| 184 } |
| 185 |
146 sk_sp<GrFragmentProcessor> GrFragmentProcessor::MulOutputByInputUnpremulColor( | 186 sk_sp<GrFragmentProcessor> GrFragmentProcessor::MulOutputByInputUnpremulColor( |
147 sk_sp<GrFragmentProcessor> fp) { | 187 sk_sp<GrFragmentProcessor> fp) { |
148 | 188 |
149 class PremulFragmentProcessor : public GrFragmentProcessor { | 189 class PremulFragmentProcessor : public GrFragmentProcessor { |
150 public: | 190 public: |
151 PremulFragmentProcessor(sk_sp<GrFragmentProcessor> processor) { | 191 PremulFragmentProcessor(sk_sp<GrFragmentProcessor> processor) { |
152 this->initClassID<PremulFragmentProcessor>(); | 192 this->initClassID<PremulFragmentProcessor>(); |
153 this->registerChildProcessor(processor); | 193 this->registerChildProcessor(processor); |
154 } | 194 } |
155 | 195 |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 } else { | 410 } else { |
371 series += firstIdx; | 411 series += firstIdx; |
372 cnt -= firstIdx; | 412 cnt -= firstIdx; |
373 } | 413 } |
374 | 414 |
375 if (1 == cnt) { | 415 if (1 == cnt) { |
376 return series[0]; | 416 return series[0]; |
377 } | 417 } |
378 return sk_sp<GrFragmentProcessor>(new SeriesFragmentProcessor(series, cnt)); | 418 return sk_sp<GrFragmentProcessor>(new SeriesFragmentProcessor(series, cnt)); |
379 } | 419 } |
OLD | NEW |