blob: 6760aa7fe7a1b3894a719a4717b7da70f79a413c [file] [log] [blame]
bsalomonbf877302015-09-22 09:06:13 -07001/*
2* Copyright 2015 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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "src/gpu/GrCoordTransform.h"
9#include "src/gpu/GrFragmentProcessor.h"
10#include "src/gpu/GrPipeline.h"
11#include "src/gpu/GrProcessorAnalysis.h"
12#include "src/gpu/effects/GrXfermodeFragmentProcessor.h"
13#include "src/gpu/effects/generated/GrConstColorProcessor.h"
14#include "src/gpu/effects/generated/GrOverrideInputFragmentProcessor.h"
15#include "src/gpu/effects/generated/GrPremulInputFragmentProcessor.h"
16#include "src/gpu/glsl/GrGLSLFragmentProcessor.h"
17#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
18#include "src/gpu/glsl/GrGLSLProgramDataManager.h"
19#include "src/gpu/glsl/GrGLSLUniformHandler.h"
bsalomonbf877302015-09-22 09:06:13 -070020
bsalomon7312ff82016-09-12 08:55:38 -070021bool GrFragmentProcessor::isEqual(const GrFragmentProcessor& that) const {
Brian Salomone782f842018-07-31 13:53:11 -040022 if (this->classID() != that.classID()) {
bsalomonbf877302015-09-22 09:06:13 -070023 return false;
24 }
Brian Salomone782f842018-07-31 13:53:11 -040025 if (this->numTextureSamplers() != that.numTextureSamplers()) {
26 return false;
27 }
28 for (int i = 0; i < this->numTextureSamplers(); ++i) {
29 if (this->textureSampler(i) != that.textureSampler(i)) {
30 return false;
31 }
32 }
bsalomon7312ff82016-09-12 08:55:38 -070033 if (!this->hasSameTransforms(that)) {
bsalomonbf877302015-09-22 09:06:13 -070034 return false;
35 }
36 if (!this->onIsEqual(that)) {
37 return false;
38 }
39 if (this->numChildProcessors() != that.numChildProcessors()) {
40 return false;
41 }
42 for (int i = 0; i < this->numChildProcessors(); ++i) {
bsalomon7312ff82016-09-12 08:55:38 -070043 if (!this->childProcessor(i).isEqual(that.childProcessor(i))) {
bsalomonbf877302015-09-22 09:06:13 -070044 return false;
45 }
46 }
47 return true;
48}
49
Chris Dalton7eb5c0f2019-05-23 15:15:47 -060050void GrFragmentProcessor::visitProxies(const GrOp::VisitProxyFunc& func) {
Brian Salomonc241b582019-11-27 08:57:17 -050051 for (auto [sampler, fp] : FPTextureSamplerRange(*this)) {
52 bool mipped = (GrSamplerState::Filter::kMipMap == sampler.samplerState().filter());
Robert Phillipsbd99c0c2019-12-12 13:26:58 +000053 func(sampler.view().proxy(), GrMipMapped(mipped));
Brian Salomone782f842018-07-31 13:53:11 -040054 }
55}
56
egdaniel57d3b032015-11-13 11:57:27 -080057GrGLSLFragmentProcessor* GrFragmentProcessor::createGLSLInstance() const {
58 GrGLSLFragmentProcessor* glFragProc = this->onCreateGLSLInstance();
bsalomonbf877302015-09-22 09:06:13 -070059 glFragProc->fChildProcessors.push_back_n(fChildProcessors.count());
60 for (int i = 0; i < fChildProcessors.count(); ++i) {
egdaniel57d3b032015-11-13 11:57:27 -080061 glFragProc->fChildProcessors[i] = fChildProcessors[i]->createGLSLInstance();
bsalomonbf877302015-09-22 09:06:13 -070062 }
63 return glFragProc;
64}
65
Brian Salomone782f842018-07-31 13:53:11 -040066const GrFragmentProcessor::TextureSampler& GrFragmentProcessor::textureSampler(int i) const {
67 SkASSERT(i >= 0 && i < fTextureSamplerCnt);
68 return this->onTextureSampler(i);
69}
70
Ethan Nicholasd4efe682019-08-29 16:10:13 -040071void GrFragmentProcessor::addCoordTransform(GrCoordTransform* transform) {
bsalomonbf877302015-09-22 09:06:13 -070072 fCoordTransforms.push_back(transform);
Brian Salomon7d8b3972019-11-26 22:34:44 -050073 fFlags |= kHasCoordTranforms_Flag;
bsalomonbf877302015-09-22 09:06:13 -070074}
75
Robert Phillips82774f82019-06-20 14:38:27 -040076#ifdef SK_DEBUG
77bool GrFragmentProcessor::isInstantiated() const {
Brian Salomone782f842018-07-31 13:53:11 -040078 for (int i = 0; i < fTextureSamplerCnt; ++i) {
Robert Phillips82774f82019-06-20 14:38:27 -040079 if (!this->textureSampler(i).isInstantiated()) {
Brian Salomone782f842018-07-31 13:53:11 -040080 return false;
81 }
Robert Phillipsa91e0b72017-05-01 13:12:20 -040082 }
83
Robert Phillips9bee2e52017-05-29 12:37:20 -040084 for (int i = 0; i < this->numChildProcessors(); ++i) {
Robert Phillips82774f82019-06-20 14:38:27 -040085 if (!this->childProcessor(i).isInstantiated()) {
Robert Phillips9bee2e52017-05-29 12:37:20 -040086 return false;
87 }
88 }
89
90 return true;
91}
Robert Phillips82774f82019-06-20 14:38:27 -040092#endif
Robert Phillips9bee2e52017-05-29 12:37:20 -040093
Brian Salomonaff329b2017-08-11 09:40:37 -040094int GrFragmentProcessor::registerChildProcessor(std::unique_ptr<GrFragmentProcessor> child) {
Brian Salomon7d8b3972019-11-26 22:34:44 -050095 if (child->fFlags & kHasCoordTranforms_Flag) {
96 fFlags |= kHasCoordTranforms_Flag;
bsalomonbf877302015-09-22 09:06:13 -070097 }
Chris Daltond7291ba2019-03-07 14:17:03 -070098 fRequestedFeatures |= child->fRequestedFeatures;
bsalomonbf877302015-09-22 09:06:13 -070099
bungeman06ca8ec2016-06-09 08:01:03 -0700100 int index = fChildProcessors.count();
Brian Salomonaff329b2017-08-11 09:40:37 -0400101 fChildProcessors.push_back(std::move(child));
bungeman06ca8ec2016-06-09 08:01:03 -0700102
bsalomonbf877302015-09-22 09:06:13 -0700103 return index;
104}
105
bsalomonbf877302015-09-22 09:06:13 -0700106bool GrFragmentProcessor::hasSameTransforms(const GrFragmentProcessor& that) const {
bsalomona624bf32016-09-20 09:12:47 -0700107 if (this->numCoordTransforms() != that.numCoordTransforms()) {
bsalomonbf877302015-09-22 09:06:13 -0700108 return false;
109 }
bsalomona624bf32016-09-20 09:12:47 -0700110 int count = this->numCoordTransforms();
bsalomonbf877302015-09-22 09:06:13 -0700111 for (int i = 0; i < count; ++i) {
Brian Salomon7d8b3972019-11-26 22:34:44 -0500112 if (!this->coordTransform(i).hasSameEffectiveMatrix(that.coordTransform(i))) {
bsalomonbf877302015-09-22 09:06:13 -0700113 return false;
114 }
115 }
116 return true;
117}
118
Mike Reed28eaed22018-02-01 11:24:53 -0500119std::unique_ptr<GrFragmentProcessor> GrFragmentProcessor::MulChildByInputAlpha(
Brian Salomonaff329b2017-08-11 09:40:37 -0400120 std::unique_ptr<GrFragmentProcessor> fp) {
bsalomonf1b7a1d2015-09-28 06:26:28 -0700121 if (!fp) {
122 return nullptr;
123 }
Mike Reed7d954ad2016-10-28 15:42:34 -0400124 return GrXfermodeFragmentProcessor::MakeFromDstProcessor(std::move(fp), SkBlendMode::kDstIn);
bsalomonbf877302015-09-22 09:06:13 -0700125}
126
Mike Reed28eaed22018-02-01 11:24:53 -0500127std::unique_ptr<GrFragmentProcessor> GrFragmentProcessor::MulInputByChildAlpha(
128 std::unique_ptr<GrFragmentProcessor> fp) {
129 if (!fp) {
130 return nullptr;
131 }
132 return GrXfermodeFragmentProcessor::MakeFromDstProcessor(std::move(fp), SkBlendMode::kSrcIn);
133}
134
Brian Salomonaff329b2017-08-11 09:40:37 -0400135std::unique_ptr<GrFragmentProcessor> GrFragmentProcessor::PremulInput(
136 std::unique_ptr<GrFragmentProcessor> fp) {
dvonbeckc526da92016-07-20 11:20:30 -0700137 if (!fp) {
138 return nullptr;
139 }
Ethan Nicholasbe0a0422017-11-17 13:44:05 -0500140 std::unique_ptr<GrFragmentProcessor> fpPipeline[] = { GrPremulInputFragmentProcessor::Make(),
Brian Salomonaff329b2017-08-11 09:40:37 -0400141 std::move(fp) };
dvonbeckc526da92016-07-20 11:20:30 -0700142 return GrFragmentProcessor::RunInSeries(fpPipeline, 2);
143}
144
Brian Salomonaff329b2017-08-11 09:40:37 -0400145std::unique_ptr<GrFragmentProcessor> GrFragmentProcessor::SwizzleOutput(
146 std::unique_ptr<GrFragmentProcessor> fp, const GrSwizzle& swizzle) {
Brian Osmance425512017-03-22 14:37:50 -0400147 class SwizzleFragmentProcessor : public GrFragmentProcessor {
148 public:
Brian Salomonaff329b2017-08-11 09:40:37 -0400149 static std::unique_ptr<GrFragmentProcessor> Make(const GrSwizzle& swizzle) {
150 return std::unique_ptr<GrFragmentProcessor>(new SwizzleFragmentProcessor(swizzle));
Brian Osmance425512017-03-22 14:37:50 -0400151 }
152
153 const char* name() const override { return "Swizzle"; }
154 const GrSwizzle& swizzle() const { return fSwizzle; }
155
Brian Salomonaff329b2017-08-11 09:40:37 -0400156 std::unique_ptr<GrFragmentProcessor> clone() const override { return Make(fSwizzle); }
Brian Salomon216f2e02017-07-25 15:52:51 -0400157
Brian Osmance425512017-03-22 14:37:50 -0400158 private:
Robert Phillips1c9686b2017-06-30 08:40:28 -0400159 SwizzleFragmentProcessor(const GrSwizzle& swizzle)
Ethan Nicholasabff9562017-10-09 10:54:08 -0400160 : INHERITED(kSwizzleFragmentProcessor_ClassID, kAll_OptimizationFlags)
Brian Salomonf7dcd762018-07-30 14:48:15 -0400161 , fSwizzle(swizzle) {}
Robert Phillips1c9686b2017-06-30 08:40:28 -0400162
Brian Osmance425512017-03-22 14:37:50 -0400163 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override {
164 class GLFP : public GrGLSLFragmentProcessor {
165 public:
166 void emitCode(EmitArgs& args) override {
167 const SwizzleFragmentProcessor& sfp = args.fFp.cast<SwizzleFragmentProcessor>();
168 const GrSwizzle& swizzle = sfp.swizzle();
169 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
170
171 fragBuilder->codeAppendf("%s = %s.%s;",
Greg Daniel369ee6b2019-12-02 15:30:02 -0500172 args.fOutputColor, args.fInputColor, swizzle.asString().c_str());
Brian Osmance425512017-03-22 14:37:50 -0400173 }
174 };
175 return new GLFP;
176 }
177
178 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder* b) const override {
179 b->add32(fSwizzle.asKey());
180 }
181
182 bool onIsEqual(const GrFragmentProcessor& other) const override {
183 const SwizzleFragmentProcessor& sfp = other.cast<SwizzleFragmentProcessor>();
184 return fSwizzle == sfp.fSwizzle;
185 }
186
Brian Osman1d5b5982018-10-01 13:41:39 -0400187 SkPMColor4f constantOutputForConstantInput(const SkPMColor4f& input) const override {
Brian Osmance425512017-03-22 14:37:50 -0400188 return fSwizzle.applyTo(input);
189 }
190
191 GrSwizzle fSwizzle;
192
193 typedef GrFragmentProcessor INHERITED;
194 };
195
196 if (!fp) {
197 return nullptr;
198 }
199 if (GrSwizzle::RGBA() == swizzle) {
200 return fp;
201 }
Brian Salomonaff329b2017-08-11 09:40:37 -0400202 std::unique_ptr<GrFragmentProcessor> fpPipeline[] = { std::move(fp),
203 SwizzleFragmentProcessor::Make(swizzle) };
Brian Osmance425512017-03-22 14:37:50 -0400204 return GrFragmentProcessor::RunInSeries(fpPipeline, 2);
205}
206
Brian Salomonaff329b2017-08-11 09:40:37 -0400207std::unique_ptr<GrFragmentProcessor> GrFragmentProcessor::MakeInputPremulAndMulByOutput(
208 std::unique_ptr<GrFragmentProcessor> fp) {
bsalomonf1b7a1d2015-09-28 06:26:28 -0700209 class PremulFragmentProcessor : public GrFragmentProcessor {
210 public:
Brian Salomonaff329b2017-08-11 09:40:37 -0400211 static std::unique_ptr<GrFragmentProcessor> Make(
212 std::unique_ptr<GrFragmentProcessor> processor) {
213 return std::unique_ptr<GrFragmentProcessor>(
214 new PremulFragmentProcessor(std::move(processor)));
Robert Phillips1c9686b2017-06-30 08:40:28 -0400215 }
216
217 const char* name() const override { return "Premultiply"; }
218
Brian Salomonaff329b2017-08-11 09:40:37 -0400219 std::unique_ptr<GrFragmentProcessor> clone() const override {
Brian Salomon96271cd2017-07-31 16:27:23 -0400220 return Make(this->childProcessor(0).clone());
Brian Salomon216f2e02017-07-25 15:52:51 -0400221 }
222
Robert Phillips1c9686b2017-06-30 08:40:28 -0400223 private:
Brian Salomonaff329b2017-08-11 09:40:37 -0400224 PremulFragmentProcessor(std::unique_ptr<GrFragmentProcessor> processor)
Ethan Nicholasabff9562017-10-09 10:54:08 -0400225 : INHERITED(kPremulFragmentProcessor_ClassID, OptFlags(processor.get())) {
Brian Salomonaff329b2017-08-11 09:40:37 -0400226 this->registerChildProcessor(std::move(processor));
bsalomonf1b7a1d2015-09-28 06:26:28 -0700227 }
228
egdaniel57d3b032015-11-13 11:57:27 -0800229 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override {
egdaniel64c47282015-11-13 06:54:19 -0800230 class GLFP : public GrGLSLFragmentProcessor {
bsalomonf1b7a1d2015-09-28 06:26:28 -0700231 public:
bsalomonf1b7a1d2015-09-28 06:26:28 -0700232 void emitCode(EmitArgs& args) override {
cdalton85285412016-02-18 12:37:07 -0800233 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
Ethan Nicholasc6dce5a2019-07-24 16:51:36 -0400234 this->invokeChild(0, args);
egdaniel4ca2e602015-11-18 08:01:26 -0800235 fragBuilder->codeAppendf("%s.rgb *= %s.rgb;", args.fOutputColor,
bsalomonf1b7a1d2015-09-28 06:26:28 -0700236 args.fInputColor);
egdaniel4ca2e602015-11-18 08:01:26 -0800237 fragBuilder->codeAppendf("%s *= %s.a;", args.fOutputColor, args.fInputColor);
bsalomonf1b7a1d2015-09-28 06:26:28 -0700238 }
239 };
240 return new GLFP;
241 }
242
Brian Salomon94efbf52016-11-29 13:43:05 -0500243 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {}
bsalomonf1b7a1d2015-09-28 06:26:28 -0700244
245 bool onIsEqual(const GrFragmentProcessor&) const override { return true; }
246
Brian Salomon587e08f2017-01-27 10:59:27 -0500247 static OptimizationFlags OptFlags(const GrFragmentProcessor* inner) {
248 OptimizationFlags flags = kNone_OptimizationFlags;
249 if (inner->preservesOpaqueInput()) {
250 flags |= kPreservesOpaqueInput_OptimizationFlag;
251 }
252 if (inner->hasConstantOutputForConstantInput()) {
253 flags |= kConstantOutputForConstantInput_OptimizationFlag;
254 }
255 return flags;
256 }
bsalomonf1b7a1d2015-09-28 06:26:28 -0700257
Brian Osman1d5b5982018-10-01 13:41:39 -0400258 SkPMColor4f constantOutputForConstantInput(const SkPMColor4f& input) const override {
259 SkPMColor4f childColor = ConstantOutputForConstantInput(this->childProcessor(0),
Brian Osmanf28e55d2018-10-03 16:35:54 -0400260 SK_PMColor4fWHITE);
Brian Osman1d5b5982018-10-01 13:41:39 -0400261 SkPMColor4f premulInput = SkColor4f{ input.fR, input.fG, input.fB, input.fA }.premul();
262 return premulInput * childColor;
Brian Salomon587e08f2017-01-27 10:59:27 -0500263 }
264
265 typedef GrFragmentProcessor INHERITED;
bsalomonf1b7a1d2015-09-28 06:26:28 -0700266 };
267 if (!fp) {
268 return nullptr;
269 }
Robert Phillips1c9686b2017-06-30 08:40:28 -0400270 return PremulFragmentProcessor::Make(std::move(fp));
bsalomonf1b7a1d2015-09-28 06:26:28 -0700271}
272
273//////////////////////////////////////////////////////////////////////////////
274
Brian Salomonaff329b2017-08-11 09:40:37 -0400275std::unique_ptr<GrFragmentProcessor> GrFragmentProcessor::OverrideInput(
Brian Salomonc0d79e52019-04-10 15:02:11 -0400276 std::unique_ptr<GrFragmentProcessor> fp, const SkPMColor4f& color, bool useUniform) {
Robert Phillips1c9686b2017-06-30 08:40:28 -0400277 if (!fp) {
278 return nullptr;
279 }
Brian Salomonc0d79e52019-04-10 15:02:11 -0400280 return GrOverrideInputFragmentProcessor::Make(std::move(fp), color, useUniform);
bsalomonf1b7a1d2015-09-28 06:26:28 -0700281}
bsalomone25eea42015-09-29 06:38:55 -0700282
Brian Salomonaff329b2017-08-11 09:40:37 -0400283std::unique_ptr<GrFragmentProcessor> GrFragmentProcessor::RunInSeries(
284 std::unique_ptr<GrFragmentProcessor>* series, int cnt) {
bsalomone25eea42015-09-29 06:38:55 -0700285 class SeriesFragmentProcessor : public GrFragmentProcessor {
286 public:
Brian Salomonaff329b2017-08-11 09:40:37 -0400287 static std::unique_ptr<GrFragmentProcessor> Make(
288 std::unique_ptr<GrFragmentProcessor>* children, int cnt) {
289 return std::unique_ptr<GrFragmentProcessor>(new SeriesFragmentProcessor(children, cnt));
bsalomone25eea42015-09-29 06:38:55 -0700290 }
291
292 const char* name() const override { return "Series"; }
293
Brian Salomonaff329b2017-08-11 09:40:37 -0400294 std::unique_ptr<GrFragmentProcessor> clone() const override {
295 SkSTArray<4, std::unique_ptr<GrFragmentProcessor>> children(this->numChildProcessors());
Brian Salomon216f2e02017-07-25 15:52:51 -0400296 for (int i = 0; i < this->numChildProcessors(); ++i) {
297 if (!children.push_back(this->childProcessor(i).clone())) {
298 return nullptr;
299 }
300 }
301 return Make(children.begin(), this->numChildProcessors());
302 }
303
304 private:
egdaniel57d3b032015-11-13 11:57:27 -0800305 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override {
egdaniel64c47282015-11-13 06:54:19 -0800306 class GLFP : public GrGLSLFragmentProcessor {
bsalomone25eea42015-09-29 06:38:55 -0700307 public:
bsalomone25eea42015-09-29 06:38:55 -0700308 void emitCode(EmitArgs& args) override {
dvonbeckca9eeab2016-07-06 12:00:06 -0700309 // First guy's input might be nil.
310 SkString temp("out0");
Ethan Nicholasc6dce5a2019-07-24 16:51:36 -0400311 this->invokeChild(0, args.fInputColor, &temp, args);
dvonbeckca9eeab2016-07-06 12:00:06 -0700312 SkString input = temp;
313 for (int i = 1; i < this->numChildProcessors() - 1; ++i) {
bsalomone25eea42015-09-29 06:38:55 -0700314 temp.printf("out%d", i);
Ethan Nicholasc6dce5a2019-07-24 16:51:36 -0400315 this->invokeChild(i, input.c_str(), &temp, args);
bsalomone25eea42015-09-29 06:38:55 -0700316 input = temp;
317 }
318 // Last guy writes to our output variable.
Ethan Nicholasc6dce5a2019-07-24 16:51:36 -0400319 this->invokeChild(this->numChildProcessors() - 1, input.c_str(), args);
bsalomone25eea42015-09-29 06:38:55 -0700320 }
321 };
322 return new GLFP;
323 }
Brian Salomon216f2e02017-07-25 15:52:51 -0400324
Brian Salomonaff329b2017-08-11 09:40:37 -0400325 SeriesFragmentProcessor(std::unique_ptr<GrFragmentProcessor>* children, int cnt)
Ethan Nicholasabff9562017-10-09 10:54:08 -0400326 : INHERITED(kSeriesFragmentProcessor_ClassID, OptFlags(children, cnt)) {
Robert Phillips1c9686b2017-06-30 08:40:28 -0400327 SkASSERT(cnt > 1);
Robert Phillips1c9686b2017-06-30 08:40:28 -0400328 for (int i = 0; i < cnt; ++i) {
329 this->registerChildProcessor(std::move(children[i]));
330 }
331 }
332
Brian Salomonaff329b2017-08-11 09:40:37 -0400333 static OptimizationFlags OptFlags(std::unique_ptr<GrFragmentProcessor>* children, int cnt) {
Brian Salomon587e08f2017-01-27 10:59:27 -0500334 OptimizationFlags flags = kAll_OptimizationFlags;
335 for (int i = 0; i < cnt && flags != kNone_OptimizationFlags; ++i) {
336 flags &= children[i]->optimizationFlags();
337 }
338 return flags;
339 }
Brian Salomon94efbf52016-11-29 13:43:05 -0500340 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {}
bsalomone25eea42015-09-29 06:38:55 -0700341
342 bool onIsEqual(const GrFragmentProcessor&) const override { return true; }
343
Brian Osman1d5b5982018-10-01 13:41:39 -0400344 SkPMColor4f constantOutputForConstantInput(const SkPMColor4f& inColor) const override {
345 SkPMColor4f color = inColor;
Brian Salomon587e08f2017-01-27 10:59:27 -0500346 int childCnt = this->numChildProcessors();
347 for (int i = 0; i < childCnt; ++i) {
348 color = ConstantOutputForConstantInput(this->childProcessor(i), color);
349 }
350 return color;
351 }
352
353 typedef GrFragmentProcessor INHERITED;
bsalomone25eea42015-09-29 06:38:55 -0700354 };
355
356 if (!cnt) {
357 return nullptr;
358 }
Brian Salomoneec6f7b2017-02-10 14:29:38 -0500359 if (1 == cnt) {
Brian Salomonaff329b2017-08-11 09:40:37 -0400360 return std::move(series[0]);
Brian Salomoneec6f7b2017-02-10 14:29:38 -0500361 }
bsalomone25eea42015-09-29 06:38:55 -0700362 // Run the through the series, do the invariant output processing, and look for eliminations.
Brian Salomon650ced02017-07-20 16:46:46 -0400363 GrProcessorAnalysisColor inputColor;
364 inputColor.setToUnknown();
Brian Salomonaff329b2017-08-11 09:40:37 -0400365 GrColorFragmentProcessorAnalysis info(inputColor, unique_ptr_address_as_pointer_address(series),
Brian Salomon650ced02017-07-20 16:46:46 -0400366 cnt);
Brian Salomonaff329b2017-08-11 09:40:37 -0400367 SkTArray<std::unique_ptr<GrFragmentProcessor>> replacementSeries;
Brian Osmanf28e55d2018-10-03 16:35:54 -0400368 SkPMColor4f knownColor;
Brian Salomoneec6f7b2017-02-10 14:29:38 -0500369 int leadingFPsToEliminate = info.initialProcessorsToEliminate(&knownColor);
370 if (leadingFPsToEliminate) {
Brian Salomonaff329b2017-08-11 09:40:37 -0400371 std::unique_ptr<GrFragmentProcessor> colorFP(
Ethan Nicholase9d172a2017-11-20 12:12:24 -0500372 GrConstColorProcessor::Make(knownColor, GrConstColorProcessor::InputMode::kIgnore));
Brian Salomoneec6f7b2017-02-10 14:29:38 -0500373 if (leadingFPsToEliminate == cnt) {
374 return colorFP;
375 }
376 cnt = cnt - leadingFPsToEliminate + 1;
bungeman06ca8ec2016-06-09 08:01:03 -0700377 replacementSeries.reserve(cnt);
378 replacementSeries.emplace_back(std::move(colorFP));
379 for (int i = 0; i < cnt - 1; ++i) {
Brian Salomoneec6f7b2017-02-10 14:29:38 -0500380 replacementSeries.emplace_back(std::move(series[leadingFPsToEliminate + i]));
bsalomone25eea42015-09-29 06:38:55 -0700381 }
bungeman06ca8ec2016-06-09 08:01:03 -0700382 series = replacementSeries.begin();
bsalomone25eea42015-09-29 06:38:55 -0700383 }
Robert Phillips1c9686b2017-06-30 08:40:28 -0400384 return SeriesFragmentProcessor::Make(series, cnt);
bsalomone25eea42015-09-29 06:38:55 -0700385}
bsalomona624bf32016-09-20 09:12:47 -0700386
387//////////////////////////////////////////////////////////////////////////////
388
Brian Salomon7eabfe82019-12-02 14:20:20 -0500389GrFragmentProcessor::CIter::CIter(const GrPaint& paint) {
Chris Dalton1c548942018-05-22 13:09:48 -0600390 for (int i = paint.numCoverageFragmentProcessors() - 1; i >= 0; --i) {
391 fFPStack.push_back(paint.getCoverageFragmentProcessor(i));
392 }
393 for (int i = paint.numColorFragmentProcessors() - 1; i >= 0; --i) {
394 fFPStack.push_back(paint.getColorFragmentProcessor(i));
395 }
396}
397
Brian Salomon7eabfe82019-12-02 14:20:20 -0500398GrFragmentProcessor::CIter::CIter(const GrProcessorSet& set) {
Brian Salomonc241b582019-11-27 08:57:17 -0500399 for (int i = set.numCoverageFragmentProcessors() - 1; i >= 0; --i) {
400 fFPStack.push_back(set.coverageFragmentProcessor(i));
bsalomona624bf32016-09-20 09:12:47 -0700401 }
Brian Salomonc241b582019-11-27 08:57:17 -0500402 for (int i = set.numColorFragmentProcessors() - 1; i >= 0; --i) {
403 fFPStack.push_back(set.colorFragmentProcessor(i));
404 }
405}
406
Brian Salomon7eabfe82019-12-02 14:20:20 -0500407GrFragmentProcessor::CIter::CIter(const GrPipeline& pipeline) {
Brian Salomonc241b582019-11-27 08:57:17 -0500408 for (int i = pipeline.numFragmentProcessors() - 1; i >= 0; --i) {
409 fFPStack.push_back(&pipeline.getFragmentProcessor(i));
410 }
411}
412
Brian Salomone782f842018-07-31 13:53:11 -0400413///////////////////////////////////////////////////////////////////////////////////////////////////
414
Robert Phillipsbd99c0c2019-12-12 13:26:58 +0000415GrFragmentProcessor::TextureSampler::TextureSampler(GrSurfaceProxyView view,
416 const GrSamplerState& samplerState)
417 : fView(std::move(view))
418 , fSamplerState(samplerState) {
419 GrSurfaceProxy* proxy = this->proxy();
Greg Danielacf59292019-12-11 13:45:17 -0500420 fSamplerState.setFilterMode(
421 SkTMin(samplerState.filter(),
Robert Phillipsbd99c0c2019-12-12 13:26:58 +0000422 GrTextureProxy::HighestFilterMode(proxy->backendFormat().textureType())));
Greg Danielacf59292019-12-11 13:45:17 -0500423}
Robert Phillipsbd99c0c2019-12-12 13:26:58 +0000424
425GrFragmentProcessor::TextureSampler::TextureSampler(sk_sp<GrSurfaceProxy> proxy,
426 const GrSamplerState& samplerState) {
427 SkASSERT(proxy->asTextureProxy());
428 GrSurfaceOrigin origin = proxy->origin();
429 GrSwizzle swizzle = proxy->textureSwizzle();
430 fView = GrSurfaceProxyView(std::move(proxy), origin, swizzle);
431
432 fSamplerState = samplerState;
433 GrSurfaceProxy* surfProxy = this->proxy();
434 fSamplerState.setFilterMode(
435 SkTMin(samplerState.filter(),
436 GrTextureProxy::HighestFilterMode(surfProxy->backendFormat().textureType())));
437}
438
439#if GR_TEST_UTILS
440void GrFragmentProcessor::TextureSampler::set(GrSurfaceProxyView view,
441 const GrSamplerState& samplerState) {
442 SkASSERT(view.proxy()->asTextureProxy());
443 fView = std::move(view);
444 fSamplerState = samplerState;
445
446 fSamplerState.setFilterMode(
447 SkTMin(samplerState.filter(),
448 GrTextureProxy::HighestFilterMode(this->proxy()->backendFormat().textureType())));
449}
450#endif