bsalomon | bf87730 | 2015-09-22 09:06:13 -0700 | [diff] [blame] | 1 | /* |
| 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 Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #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" |
Brian Osman | 6f5e940 | 2020-01-22 10:39:31 -0500 | [diff] [blame] | 13 | #include "src/gpu/effects/generated/GrClampFragmentProcessor.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "src/gpu/effects/generated/GrConstColorProcessor.h" |
| 15 | #include "src/gpu/effects/generated/GrOverrideInputFragmentProcessor.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 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" |
bsalomon | bf87730 | 2015-09-22 09:06:13 -0700 | [diff] [blame] | 20 | |
bsalomon | 7312ff8 | 2016-09-12 08:55:38 -0700 | [diff] [blame] | 21 | bool GrFragmentProcessor::isEqual(const GrFragmentProcessor& that) const { |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 22 | if (this->classID() != that.classID()) { |
bsalomon | bf87730 | 2015-09-22 09:06:13 -0700 | [diff] [blame] | 23 | return false; |
| 24 | } |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 25 | 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 | } |
bsalomon | 7312ff8 | 2016-09-12 08:55:38 -0700 | [diff] [blame] | 33 | if (!this->hasSameTransforms(that)) { |
bsalomon | bf87730 | 2015-09-22 09:06:13 -0700 | [diff] [blame] | 34 | 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) { |
bsalomon | 7312ff8 | 2016-09-12 08:55:38 -0700 | [diff] [blame] | 43 | if (!this->childProcessor(i).isEqual(that.childProcessor(i))) { |
bsalomon | bf87730 | 2015-09-22 09:06:13 -0700 | [diff] [blame] | 44 | return false; |
| 45 | } |
| 46 | } |
| 47 | return true; |
| 48 | } |
| 49 | |
Chris Dalton | 7eb5c0f | 2019-05-23 15:15:47 -0600 | [diff] [blame] | 50 | void GrFragmentProcessor::visitProxies(const GrOp::VisitProxyFunc& func) { |
Brian Salomon | c241b58 | 2019-11-27 08:57:17 -0500 | [diff] [blame] | 51 | for (auto [sampler, fp] : FPTextureSamplerRange(*this)) { |
| 52 | bool mipped = (GrSamplerState::Filter::kMipMap == sampler.samplerState().filter()); |
Robert Phillips | bd99c0c | 2019-12-12 13:26:58 +0000 | [diff] [blame] | 53 | func(sampler.view().proxy(), GrMipMapped(mipped)); |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 54 | } |
| 55 | } |
| 56 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 57 | GrGLSLFragmentProcessor* GrFragmentProcessor::createGLSLInstance() const { |
| 58 | GrGLSLFragmentProcessor* glFragProc = this->onCreateGLSLInstance(); |
bsalomon | bf87730 | 2015-09-22 09:06:13 -0700 | [diff] [blame] | 59 | glFragProc->fChildProcessors.push_back_n(fChildProcessors.count()); |
| 60 | for (int i = 0; i < fChildProcessors.count(); ++i) { |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 61 | glFragProc->fChildProcessors[i] = fChildProcessors[i]->createGLSLInstance(); |
bsalomon | bf87730 | 2015-09-22 09:06:13 -0700 | [diff] [blame] | 62 | } |
| 63 | return glFragProc; |
| 64 | } |
| 65 | |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 66 | const GrFragmentProcessor::TextureSampler& GrFragmentProcessor::textureSampler(int i) const { |
| 67 | SkASSERT(i >= 0 && i < fTextureSamplerCnt); |
| 68 | return this->onTextureSampler(i); |
| 69 | } |
| 70 | |
Michael Ludwig | e88320b | 2020-06-24 09:04:56 -0400 | [diff] [blame] | 71 | int GrFragmentProcessor::numCoordTransforms() const { |
| 72 | if (SkToBool(fFlags & kUsesSampleCoordsDirectly_Flag) && fCoordTransforms.empty() && |
| 73 | !this->isSampledWithExplicitCoords()) { |
| 74 | // coordTransform(0) will return an implicitly defined coord transform so that varyings are |
| 75 | // added for this FP in order to support const/uniform sample matrix lifting. |
| 76 | return 1; |
| 77 | } else { |
| 78 | return fCoordTransforms.count(); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | const GrCoordTransform& GrFragmentProcessor::coordTransform(int i) const { |
| 83 | SkASSERT(i >= 0 && i < this->numCoordTransforms()); |
| 84 | if (SkToBool(fFlags & kUsesSampleCoordsDirectly_Flag) && fCoordTransforms.empty() && |
| 85 | !this->isSampledWithExplicitCoords()) { |
| 86 | SkASSERT(i == 0); |
| 87 | |
| 88 | // as things stand, matrices only work when there's a coord transform, so we need to add |
| 89 | // an identity transform to keep the downstream code happy |
| 90 | static const GrCoordTransform kImplicitIdentity; |
| 91 | return kImplicitIdentity; |
| 92 | } else { |
| 93 | return *fCoordTransforms[i]; |
| 94 | } |
| 95 | } |
| 96 | |
Ethan Nicholas | d4efe68 | 2019-08-29 16:10:13 -0400 | [diff] [blame] | 97 | void GrFragmentProcessor::addCoordTransform(GrCoordTransform* transform) { |
bsalomon | bf87730 | 2015-09-22 09:06:13 -0700 | [diff] [blame] | 98 | fCoordTransforms.push_back(transform); |
Ethan Nicholas | 7ef777e | 2020-02-12 13:06:27 -0500 | [diff] [blame] | 99 | fFlags |= kHasCoordTransforms_Flag; |
bsalomon | bf87730 | 2015-09-22 09:06:13 -0700 | [diff] [blame] | 100 | } |
| 101 | |
Ethan Nicholas | d3a95c2 | 2020-06-03 13:24:46 -0400 | [diff] [blame] | 102 | void GrFragmentProcessor::setSampleMatrix(SkSL::SampleMatrix newMatrix) { |
Michael Ludwig | e88320b | 2020-06-24 09:04:56 -0400 | [diff] [blame] | 103 | SkASSERT(!newMatrix.isNoOp()); |
| 104 | SkASSERT(fMatrix.isNoOp()); |
| 105 | |
| 106 | fMatrix = newMatrix; |
| 107 | // When an FP is sampled using variable matrix expressions, it is effectively being sampled |
| 108 | // explicitly, except that the call site will automatically evaluate the matrix expression to |
| 109 | // produce the float2 passed into this FP. |
| 110 | if (fMatrix.isVariable()) { |
| 111 | this->addAndPushFlagToChildren(kSampledWithExplicitCoords_Flag); |
Ethan Nicholas | 5843012 | 2020-04-14 09:54:02 -0400 | [diff] [blame] | 112 | } |
Michael Ludwig | e88320b | 2020-06-24 09:04:56 -0400 | [diff] [blame] | 113 | // Push perspective matrix type to children |
| 114 | if (fMatrix.fHasPerspective) { |
| 115 | this->addAndPushFlagToChildren(kNetTransformHasPerspective_Flag); |
Ethan Nicholas | 5843012 | 2020-04-14 09:54:02 -0400 | [diff] [blame] | 116 | } |
| 117 | } |
| 118 | |
Michael Ludwig | e88320b | 2020-06-24 09:04:56 -0400 | [diff] [blame] | 119 | void GrFragmentProcessor::addAndPushFlagToChildren(PrivateFlags flag) { |
| 120 | // This propagates down, so if we've already marked it, all our children should have it too |
| 121 | if (!(fFlags & flag)) { |
| 122 | fFlags |= flag; |
| 123 | for (auto& child : fChildProcessors) { |
| 124 | child->addAndPushFlagToChildren(flag); |
| 125 | } |
Michael Ludwig | 9aba625 | 2020-06-22 14:46:36 -0400 | [diff] [blame] | 126 | } |
Michael Ludwig | e88320b | 2020-06-24 09:04:56 -0400 | [diff] [blame] | 127 | #ifdef SK_DEBUG |
| 128 | for (auto& child : fChildProcessors) { |
| 129 | SkASSERT(child->fFlags & flag); |
| 130 | } |
| 131 | #endif |
Michael Ludwig | 9aba625 | 2020-06-22 14:46:36 -0400 | [diff] [blame] | 132 | } |
| 133 | |
Robert Phillips | 82774f8 | 2019-06-20 14:38:27 -0400 | [diff] [blame] | 134 | #ifdef SK_DEBUG |
| 135 | bool GrFragmentProcessor::isInstantiated() const { |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 136 | for (int i = 0; i < fTextureSamplerCnt; ++i) { |
Robert Phillips | 82774f8 | 2019-06-20 14:38:27 -0400 | [diff] [blame] | 137 | if (!this->textureSampler(i).isInstantiated()) { |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 138 | return false; |
| 139 | } |
Robert Phillips | a91e0b7 | 2017-05-01 13:12:20 -0400 | [diff] [blame] | 140 | } |
| 141 | |
Robert Phillips | 9bee2e5 | 2017-05-29 12:37:20 -0400 | [diff] [blame] | 142 | for (int i = 0; i < this->numChildProcessors(); ++i) { |
Robert Phillips | 82774f8 | 2019-06-20 14:38:27 -0400 | [diff] [blame] | 143 | if (!this->childProcessor(i).isInstantiated()) { |
Robert Phillips | 9bee2e5 | 2017-05-29 12:37:20 -0400 | [diff] [blame] | 144 | return false; |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | return true; |
| 149 | } |
Robert Phillips | 82774f8 | 2019-06-20 14:38:27 -0400 | [diff] [blame] | 150 | #endif |
Robert Phillips | 9bee2e5 | 2017-05-29 12:37:20 -0400 | [diff] [blame] | 151 | |
Michael Ludwig | 9aba625 | 2020-06-22 14:46:36 -0400 | [diff] [blame] | 152 | int GrFragmentProcessor::registerChild(std::unique_ptr<GrFragmentProcessor> child, |
| 153 | SkSL::SampleMatrix sampleMatrix, |
| 154 | bool explicitlySampled) { |
Michael Ludwig | e88320b | 2020-06-24 09:04:56 -0400 | [diff] [blame] | 155 | // The child should not have been attached to another FP already and not had any sampling |
| 156 | // strategy set on it. |
| 157 | SkASSERT(child && !child->fParent && child->sampleMatrix().isNoOp() && |
| 158 | !child->isSampledWithExplicitCoords() && !child->hasPerspectiveTransform()); |
| 159 | |
Michael Ludwig | 9aba625 | 2020-06-22 14:46:36 -0400 | [diff] [blame] | 160 | // Configure child's sampling state first |
| 161 | if (explicitlySampled) { |
Michael Ludwig | e88320b | 2020-06-24 09:04:56 -0400 | [diff] [blame] | 162 | child->addAndPushFlagToChildren(kSampledWithExplicitCoords_Flag); |
Michael Ludwig | 9aba625 | 2020-06-22 14:46:36 -0400 | [diff] [blame] | 163 | } |
| 164 | if (sampleMatrix.fKind != SkSL::SampleMatrix::Kind::kNone) { |
Michael Ludwig | 9aba625 | 2020-06-22 14:46:36 -0400 | [diff] [blame] | 165 | child->setSampleMatrix(sampleMatrix); |
| 166 | } |
| 167 | |
Ethan Nicholas | 7ef777e | 2020-02-12 13:06:27 -0500 | [diff] [blame] | 168 | if (child->fFlags & kHasCoordTransforms_Flag) { |
| 169 | fFlags |= kHasCoordTransforms_Flag; |
bsalomon | bf87730 | 2015-09-22 09:06:13 -0700 | [diff] [blame] | 170 | } |
Michael Ludwig | e88320b | 2020-06-24 09:04:56 -0400 | [diff] [blame] | 171 | |
| 172 | if (child->sampleMatrix().fKind == SkSL::SampleMatrix::Kind::kVariable) { |
| 173 | // Since the child is sampled with a variable matrix expression, auto-generated code in |
| 174 | // invokeChildWithMatrix() for this FP will refer to the local coordinates. |
| 175 | this->setUsesSampleCoordsDirectly(); |
| 176 | } |
| 177 | |
| 178 | // If the child is not sampled explicitly and not already accessing sample coords directly |
| 179 | // (through reference or variable matrix expansion), then mark that this FP tree relies on |
| 180 | // coordinates at a lower level. If the child is sampled with explicit coordinates and |
| 181 | // there isn't any other direct reference to the sample coords, we halt the upwards propagation |
| 182 | // because it means this FP is determining coordinates on its own. |
| 183 | if (!child->isSampledWithExplicitCoords()) { |
| 184 | if ((child->fFlags & kUsesSampleCoordsDirectly_Flag || |
| 185 | child->fFlags & kUsesSampleCoordsIndirectly_Flag)) { |
| 186 | fFlags |= kUsesSampleCoordsIndirectly_Flag; |
| 187 | } |
| 188 | } |
| 189 | |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 190 | fRequestedFeatures |= child->fRequestedFeatures; |
bsalomon | bf87730 | 2015-09-22 09:06:13 -0700 | [diff] [blame] | 191 | |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 192 | int index = fChildProcessors.count(); |
Michael Ludwig | e88320b | 2020-06-24 09:04:56 -0400 | [diff] [blame] | 193 | // Record that the child is attached to us; this FP is the source of any uniform data needed |
| 194 | // to evaluate the child sample matrix. |
| 195 | child->fParent = this; |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 196 | fChildProcessors.push_back(std::move(child)); |
Michael Ludwig | e88320b | 2020-06-24 09:04:56 -0400 | [diff] [blame] | 197 | |
| 198 | // Sanity check: our sample strategy comes from a parent we shouldn't have yet. |
| 199 | SkASSERT(!this->isSampledWithExplicitCoords() && !this->hasPerspectiveTransform() && |
| 200 | fMatrix.isNoOp() && !fParent); |
bsalomon | bf87730 | 2015-09-22 09:06:13 -0700 | [diff] [blame] | 201 | return index; |
| 202 | } |
| 203 | |
John Stiles | 3779f44 | 2020-06-15 10:48:49 -0400 | [diff] [blame] | 204 | int GrFragmentProcessor::cloneAndRegisterChildProcessor(const GrFragmentProcessor& fp) { |
| 205 | std::unique_ptr<GrFragmentProcessor> clone = fp.clone(); |
Michael Ludwig | 9aba625 | 2020-06-22 14:46:36 -0400 | [diff] [blame] | 206 | return this->registerChild(std::move(clone), fp.sampleMatrix(), |
| 207 | fp.isSampledWithExplicitCoords()); |
John Stiles | 3779f44 | 2020-06-15 10:48:49 -0400 | [diff] [blame] | 208 | } |
| 209 | |
John Stiles | 9ec6b05 | 2020-06-15 12:06:10 -0400 | [diff] [blame] | 210 | void GrFragmentProcessor::cloneAndRegisterAllChildProcessors(const GrFragmentProcessor& src) { |
| 211 | for (int i = 0; i < src.numChildProcessors(); ++i) { |
| 212 | this->cloneAndRegisterChildProcessor(src.childProcessor(i)); |
| 213 | } |
| 214 | } |
| 215 | |
bsalomon | bf87730 | 2015-09-22 09:06:13 -0700 | [diff] [blame] | 216 | bool GrFragmentProcessor::hasSameTransforms(const GrFragmentProcessor& that) const { |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 217 | if (this->numCoordTransforms() != that.numCoordTransforms()) { |
bsalomon | bf87730 | 2015-09-22 09:06:13 -0700 | [diff] [blame] | 218 | return false; |
| 219 | } |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 220 | int count = this->numCoordTransforms(); |
bsalomon | bf87730 | 2015-09-22 09:06:13 -0700 | [diff] [blame] | 221 | for (int i = 0; i < count; ++i) { |
Brian Salomon | 7d8b397 | 2019-11-26 22:34:44 -0500 | [diff] [blame] | 222 | if (!this->coordTransform(i).hasSameEffectiveMatrix(that.coordTransform(i))) { |
bsalomon | bf87730 | 2015-09-22 09:06:13 -0700 | [diff] [blame] | 223 | return false; |
| 224 | } |
| 225 | } |
| 226 | return true; |
| 227 | } |
| 228 | |
Mike Reed | 28eaed2 | 2018-02-01 11:24:53 -0500 | [diff] [blame] | 229 | std::unique_ptr<GrFragmentProcessor> GrFragmentProcessor::MulChildByInputAlpha( |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 230 | std::unique_ptr<GrFragmentProcessor> fp) { |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 231 | if (!fp) { |
| 232 | return nullptr; |
| 233 | } |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 234 | return GrXfermodeFragmentProcessor::MakeFromDstProcessor(std::move(fp), SkBlendMode::kDstIn); |
bsalomon | bf87730 | 2015-09-22 09:06:13 -0700 | [diff] [blame] | 235 | } |
| 236 | |
Mike Reed | 28eaed2 | 2018-02-01 11:24:53 -0500 | [diff] [blame] | 237 | std::unique_ptr<GrFragmentProcessor> GrFragmentProcessor::MulInputByChildAlpha( |
| 238 | std::unique_ptr<GrFragmentProcessor> fp) { |
| 239 | if (!fp) { |
| 240 | return nullptr; |
| 241 | } |
| 242 | return GrXfermodeFragmentProcessor::MakeFromDstProcessor(std::move(fp), SkBlendMode::kSrcIn); |
| 243 | } |
| 244 | |
Brian Osman | 6f5e940 | 2020-01-22 10:39:31 -0500 | [diff] [blame] | 245 | std::unique_ptr<GrFragmentProcessor> GrFragmentProcessor::ClampPremulOutput( |
| 246 | std::unique_ptr<GrFragmentProcessor> fp) { |
| 247 | if (!fp) { |
| 248 | return nullptr; |
| 249 | } |
John Stiles | 5a2a7b3 | 2020-06-04 10:57:21 -0400 | [diff] [blame] | 250 | return GrClampFragmentProcessor::Make(std::move(fp), /*clampToPremul=*/true); |
Brian Osman | 6f5e940 | 2020-01-22 10:39:31 -0500 | [diff] [blame] | 251 | } |
| 252 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 253 | std::unique_ptr<GrFragmentProcessor> GrFragmentProcessor::SwizzleOutput( |
| 254 | std::unique_ptr<GrFragmentProcessor> fp, const GrSwizzle& swizzle) { |
Brian Osman | ce42551 | 2017-03-22 14:37:50 -0400 | [diff] [blame] | 255 | class SwizzleFragmentProcessor : public GrFragmentProcessor { |
| 256 | public: |
John Stiles | eed56f0 | 2020-06-04 13:30:51 -0400 | [diff] [blame] | 257 | static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> fp, |
| 258 | const GrSwizzle& swizzle) { |
| 259 | return std::unique_ptr<GrFragmentProcessor>( |
| 260 | new SwizzleFragmentProcessor(std::move(fp), swizzle)); |
Brian Osman | ce42551 | 2017-03-22 14:37:50 -0400 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | const char* name() const override { return "Swizzle"; } |
| 264 | const GrSwizzle& swizzle() const { return fSwizzle; } |
| 265 | |
John Stiles | eed56f0 | 2020-06-04 13:30:51 -0400 | [diff] [blame] | 266 | std::unique_ptr<GrFragmentProcessor> clone() const override { |
| 267 | return Make(this->childProcessor(0).clone(), fSwizzle); |
| 268 | } |
Brian Salomon | 216f2e0 | 2017-07-25 15:52:51 -0400 | [diff] [blame] | 269 | |
Brian Osman | ce42551 | 2017-03-22 14:37:50 -0400 | [diff] [blame] | 270 | private: |
John Stiles | eed56f0 | 2020-06-04 13:30:51 -0400 | [diff] [blame] | 271 | SwizzleFragmentProcessor(std::unique_ptr<GrFragmentProcessor> fp, const GrSwizzle& swizzle) |
| 272 | : INHERITED(kSwizzleFragmentProcessor_ClassID, ProcessorOptimizationFlags(fp.get())) |
| 273 | , fSwizzle(swizzle) { |
Michael Ludwig | 9aba625 | 2020-06-22 14:46:36 -0400 | [diff] [blame] | 274 | this->registerChild(std::move(fp)); |
John Stiles | eed56f0 | 2020-06-04 13:30:51 -0400 | [diff] [blame] | 275 | } |
Robert Phillips | 1c9686b | 2017-06-30 08:40:28 -0400 | [diff] [blame] | 276 | |
Brian Osman | ce42551 | 2017-03-22 14:37:50 -0400 | [diff] [blame] | 277 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { |
| 278 | class GLFP : public GrGLSLFragmentProcessor { |
| 279 | public: |
| 280 | void emitCode(EmitArgs& args) override { |
John Stiles | 0af87fe | 2020-06-05 13:33:09 -0400 | [diff] [blame] | 281 | SkString childColor = this->invokeChild(0, args.fInputColor, args); |
John Stiles | eed56f0 | 2020-06-04 13:30:51 -0400 | [diff] [blame] | 282 | |
Brian Osman | ce42551 | 2017-03-22 14:37:50 -0400 | [diff] [blame] | 283 | const SwizzleFragmentProcessor& sfp = args.fFp.cast<SwizzleFragmentProcessor>(); |
| 284 | const GrSwizzle& swizzle = sfp.swizzle(); |
| 285 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 286 | |
| 287 | fragBuilder->codeAppendf("%s = %s.%s;", |
John Stiles | eed56f0 | 2020-06-04 13:30:51 -0400 | [diff] [blame] | 288 | args.fOutputColor, childColor.c_str(), swizzle.asString().c_str()); |
Brian Osman | ce42551 | 2017-03-22 14:37:50 -0400 | [diff] [blame] | 289 | } |
| 290 | }; |
| 291 | return new GLFP; |
| 292 | } |
| 293 | |
| 294 | void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder* b) const override { |
| 295 | b->add32(fSwizzle.asKey()); |
| 296 | } |
| 297 | |
| 298 | bool onIsEqual(const GrFragmentProcessor& other) const override { |
| 299 | const SwizzleFragmentProcessor& sfp = other.cast<SwizzleFragmentProcessor>(); |
| 300 | return fSwizzle == sfp.fSwizzle; |
| 301 | } |
| 302 | |
Brian Osman | 1d5b598 | 2018-10-01 13:41:39 -0400 | [diff] [blame] | 303 | SkPMColor4f constantOutputForConstantInput(const SkPMColor4f& input) const override { |
Brian Osman | ce42551 | 2017-03-22 14:37:50 -0400 | [diff] [blame] | 304 | return fSwizzle.applyTo(input); |
| 305 | } |
| 306 | |
| 307 | GrSwizzle fSwizzle; |
| 308 | |
| 309 | typedef GrFragmentProcessor INHERITED; |
| 310 | }; |
| 311 | |
| 312 | if (!fp) { |
| 313 | return nullptr; |
| 314 | } |
| 315 | if (GrSwizzle::RGBA() == swizzle) { |
| 316 | return fp; |
| 317 | } |
John Stiles | eed56f0 | 2020-06-04 13:30:51 -0400 | [diff] [blame] | 318 | return SwizzleFragmentProcessor::Make(std::move(fp), swizzle); |
Brian Osman | ce42551 | 2017-03-22 14:37:50 -0400 | [diff] [blame] | 319 | } |
| 320 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 321 | std::unique_ptr<GrFragmentProcessor> GrFragmentProcessor::MakeInputPremulAndMulByOutput( |
| 322 | std::unique_ptr<GrFragmentProcessor> fp) { |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 323 | class PremulFragmentProcessor : public GrFragmentProcessor { |
| 324 | public: |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 325 | static std::unique_ptr<GrFragmentProcessor> Make( |
| 326 | std::unique_ptr<GrFragmentProcessor> processor) { |
| 327 | return std::unique_ptr<GrFragmentProcessor>( |
| 328 | new PremulFragmentProcessor(std::move(processor))); |
Robert Phillips | 1c9686b | 2017-06-30 08:40:28 -0400 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | const char* name() const override { return "Premultiply"; } |
| 332 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 333 | std::unique_ptr<GrFragmentProcessor> clone() const override { |
Brian Salomon | 96271cd | 2017-07-31 16:27:23 -0400 | [diff] [blame] | 334 | return Make(this->childProcessor(0).clone()); |
Brian Salomon | 216f2e0 | 2017-07-25 15:52:51 -0400 | [diff] [blame] | 335 | } |
| 336 | |
Robert Phillips | 1c9686b | 2017-06-30 08:40:28 -0400 | [diff] [blame] | 337 | private: |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 338 | PremulFragmentProcessor(std::unique_ptr<GrFragmentProcessor> processor) |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 339 | : INHERITED(kPremulFragmentProcessor_ClassID, OptFlags(processor.get())) { |
Michael Ludwig | 9aba625 | 2020-06-22 14:46:36 -0400 | [diff] [blame] | 340 | this->registerChild(std::move(processor)); |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 341 | } |
| 342 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 343 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 344 | class GLFP : public GrGLSLFragmentProcessor { |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 345 | public: |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 346 | void emitCode(EmitArgs& args) override { |
cdalton | 8528541 | 2016-02-18 12:37:07 -0800 | [diff] [blame] | 347 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
Brian Osman | 978693c | 2020-01-24 14:52:10 -0500 | [diff] [blame] | 348 | SkString temp = this->invokeChild(0, args); |
Brian Osman | cddfc5e | 2020-01-24 10:24:27 -0500 | [diff] [blame] | 349 | fragBuilder->codeAppendf("%s = %s;", args.fOutputColor, temp.c_str()); |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 350 | fragBuilder->codeAppendf("%s.rgb *= %s.rgb;", args.fOutputColor, |
Brian Osman | cddfc5e | 2020-01-24 10:24:27 -0500 | [diff] [blame] | 351 | args.fInputColor); |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 352 | fragBuilder->codeAppendf("%s *= %s.a;", args.fOutputColor, args.fInputColor); |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 353 | } |
| 354 | }; |
| 355 | return new GLFP; |
| 356 | } |
| 357 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 358 | void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {} |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 359 | |
| 360 | bool onIsEqual(const GrFragmentProcessor&) const override { return true; } |
| 361 | |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 362 | static OptimizationFlags OptFlags(const GrFragmentProcessor* inner) { |
| 363 | OptimizationFlags flags = kNone_OptimizationFlags; |
| 364 | if (inner->preservesOpaqueInput()) { |
| 365 | flags |= kPreservesOpaqueInput_OptimizationFlag; |
| 366 | } |
| 367 | if (inner->hasConstantOutputForConstantInput()) { |
| 368 | flags |= kConstantOutputForConstantInput_OptimizationFlag; |
| 369 | } |
| 370 | return flags; |
| 371 | } |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 372 | |
Brian Osman | 1d5b598 | 2018-10-01 13:41:39 -0400 | [diff] [blame] | 373 | SkPMColor4f constantOutputForConstantInput(const SkPMColor4f& input) const override { |
| 374 | SkPMColor4f childColor = ConstantOutputForConstantInput(this->childProcessor(0), |
Brian Osman | f28e55d | 2018-10-03 16:35:54 -0400 | [diff] [blame] | 375 | SK_PMColor4fWHITE); |
Brian Osman | 1d5b598 | 2018-10-01 13:41:39 -0400 | [diff] [blame] | 376 | SkPMColor4f premulInput = SkColor4f{ input.fR, input.fG, input.fB, input.fA }.premul(); |
| 377 | return premulInput * childColor; |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | typedef GrFragmentProcessor INHERITED; |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 381 | }; |
| 382 | if (!fp) { |
| 383 | return nullptr; |
| 384 | } |
Robert Phillips | 1c9686b | 2017-06-30 08:40:28 -0400 | [diff] [blame] | 385 | return PremulFragmentProcessor::Make(std::move(fp)); |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | ////////////////////////////////////////////////////////////////////////////// |
| 389 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 390 | std::unique_ptr<GrFragmentProcessor> GrFragmentProcessor::OverrideInput( |
Brian Salomon | c0d79e5 | 2019-04-10 15:02:11 -0400 | [diff] [blame] | 391 | std::unique_ptr<GrFragmentProcessor> fp, const SkPMColor4f& color, bool useUniform) { |
Robert Phillips | 1c9686b | 2017-06-30 08:40:28 -0400 | [diff] [blame] | 392 | if (!fp) { |
| 393 | return nullptr; |
| 394 | } |
Brian Salomon | c0d79e5 | 2019-04-10 15:02:11 -0400 | [diff] [blame] | 395 | return GrOverrideInputFragmentProcessor::Make(std::move(fp), color, useUniform); |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 396 | } |
bsalomon | e25eea4 | 2015-09-29 06:38:55 -0700 | [diff] [blame] | 397 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 398 | std::unique_ptr<GrFragmentProcessor> GrFragmentProcessor::RunInSeries( |
Brian Salomon | 64f4206 | 2020-02-14 10:42:45 -0500 | [diff] [blame] | 399 | std::unique_ptr<GrFragmentProcessor> series[], int cnt) { |
bsalomon | e25eea4 | 2015-09-29 06:38:55 -0700 | [diff] [blame] | 400 | class SeriesFragmentProcessor : public GrFragmentProcessor { |
| 401 | public: |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 402 | static std::unique_ptr<GrFragmentProcessor> Make( |
| 403 | std::unique_ptr<GrFragmentProcessor>* children, int cnt) { |
| 404 | return std::unique_ptr<GrFragmentProcessor>(new SeriesFragmentProcessor(children, cnt)); |
bsalomon | e25eea4 | 2015-09-29 06:38:55 -0700 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | const char* name() const override { return "Series"; } |
| 408 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 409 | std::unique_ptr<GrFragmentProcessor> clone() const override { |
| 410 | SkSTArray<4, std::unique_ptr<GrFragmentProcessor>> children(this->numChildProcessors()); |
Brian Salomon | 216f2e0 | 2017-07-25 15:52:51 -0400 | [diff] [blame] | 411 | for (int i = 0; i < this->numChildProcessors(); ++i) { |
| 412 | if (!children.push_back(this->childProcessor(i).clone())) { |
| 413 | return nullptr; |
| 414 | } |
| 415 | } |
| 416 | return Make(children.begin(), this->numChildProcessors()); |
| 417 | } |
| 418 | |
| 419 | private: |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 420 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 421 | class GLFP : public GrGLSLFragmentProcessor { |
bsalomon | e25eea4 | 2015-09-29 06:38:55 -0700 | [diff] [blame] | 422 | public: |
bsalomon | e25eea4 | 2015-09-29 06:38:55 -0700 | [diff] [blame] | 423 | void emitCode(EmitArgs& args) override { |
dvonbeck | ca9eeab | 2016-07-06 12:00:06 -0700 | [diff] [blame] | 424 | // First guy's input might be nil. |
Brian Osman | 978693c | 2020-01-24 14:52:10 -0500 | [diff] [blame] | 425 | SkString result = this->invokeChild(0, args.fInputColor, args); |
Brian Osman | cddfc5e | 2020-01-24 10:24:27 -0500 | [diff] [blame] | 426 | for (int i = 1; i < this->numChildProcessors(); ++i) { |
Brian Osman | 978693c | 2020-01-24 14:52:10 -0500 | [diff] [blame] | 427 | result = this->invokeChild(i, result.c_str(), args); |
bsalomon | e25eea4 | 2015-09-29 06:38:55 -0700 | [diff] [blame] | 428 | } |
Brian Osman | cddfc5e | 2020-01-24 10:24:27 -0500 | [diff] [blame] | 429 | // Copy last output to our output variable |
Brian Osman | 978693c | 2020-01-24 14:52:10 -0500 | [diff] [blame] | 430 | args.fFragBuilder->codeAppendf("%s = %s;", args.fOutputColor, result.c_str()); |
bsalomon | e25eea4 | 2015-09-29 06:38:55 -0700 | [diff] [blame] | 431 | } |
| 432 | }; |
| 433 | return new GLFP; |
| 434 | } |
Brian Salomon | 216f2e0 | 2017-07-25 15:52:51 -0400 | [diff] [blame] | 435 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 436 | SeriesFragmentProcessor(std::unique_ptr<GrFragmentProcessor>* children, int cnt) |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 437 | : INHERITED(kSeriesFragmentProcessor_ClassID, OptFlags(children, cnt)) { |
Robert Phillips | 1c9686b | 2017-06-30 08:40:28 -0400 | [diff] [blame] | 438 | SkASSERT(cnt > 1); |
Robert Phillips | 1c9686b | 2017-06-30 08:40:28 -0400 | [diff] [blame] | 439 | for (int i = 0; i < cnt; ++i) { |
Michael Ludwig | 9aba625 | 2020-06-22 14:46:36 -0400 | [diff] [blame] | 440 | this->registerChild(std::move(children[i])); |
Robert Phillips | 1c9686b | 2017-06-30 08:40:28 -0400 | [diff] [blame] | 441 | } |
| 442 | } |
| 443 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 444 | static OptimizationFlags OptFlags(std::unique_ptr<GrFragmentProcessor>* children, int cnt) { |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 445 | OptimizationFlags flags = kAll_OptimizationFlags; |
| 446 | for (int i = 0; i < cnt && flags != kNone_OptimizationFlags; ++i) { |
| 447 | flags &= children[i]->optimizationFlags(); |
| 448 | } |
| 449 | return flags; |
| 450 | } |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 451 | void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {} |
bsalomon | e25eea4 | 2015-09-29 06:38:55 -0700 | [diff] [blame] | 452 | |
| 453 | bool onIsEqual(const GrFragmentProcessor&) const override { return true; } |
| 454 | |
Brian Osman | 1d5b598 | 2018-10-01 13:41:39 -0400 | [diff] [blame] | 455 | SkPMColor4f constantOutputForConstantInput(const SkPMColor4f& inColor) const override { |
| 456 | SkPMColor4f color = inColor; |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 457 | int childCnt = this->numChildProcessors(); |
| 458 | for (int i = 0; i < childCnt; ++i) { |
| 459 | color = ConstantOutputForConstantInput(this->childProcessor(i), color); |
| 460 | } |
| 461 | return color; |
| 462 | } |
| 463 | |
| 464 | typedef GrFragmentProcessor INHERITED; |
bsalomon | e25eea4 | 2015-09-29 06:38:55 -0700 | [diff] [blame] | 465 | }; |
| 466 | |
| 467 | if (!cnt) { |
| 468 | return nullptr; |
| 469 | } |
Brian Salomon | eec6f7b | 2017-02-10 14:29:38 -0500 | [diff] [blame] | 470 | if (1 == cnt) { |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 471 | return std::move(series[0]); |
Brian Salomon | eec6f7b | 2017-02-10 14:29:38 -0500 | [diff] [blame] | 472 | } |
bsalomon | e25eea4 | 2015-09-29 06:38:55 -0700 | [diff] [blame] | 473 | // Run the through the series, do the invariant output processing, and look for eliminations. |
Brian Salomon | 650ced0 | 2017-07-20 16:46:46 -0400 | [diff] [blame] | 474 | GrProcessorAnalysisColor inputColor; |
| 475 | inputColor.setToUnknown(); |
Brian Salomon | 64f4206 | 2020-02-14 10:42:45 -0500 | [diff] [blame] | 476 | GrColorFragmentProcessorAnalysis info(inputColor, series, cnt); |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 477 | SkTArray<std::unique_ptr<GrFragmentProcessor>> replacementSeries; |
Brian Osman | f28e55d | 2018-10-03 16:35:54 -0400 | [diff] [blame] | 478 | SkPMColor4f knownColor; |
Brian Salomon | eec6f7b | 2017-02-10 14:29:38 -0500 | [diff] [blame] | 479 | int leadingFPsToEliminate = info.initialProcessorsToEliminate(&knownColor); |
| 480 | if (leadingFPsToEliminate) { |
John Stiles | e3a39f7 | 2020-06-15 13:58:48 -0400 | [diff] [blame] | 481 | std::unique_ptr<GrFragmentProcessor> colorFP = GrConstColorProcessor::Make( |
| 482 | /*inputFP=*/nullptr, knownColor, GrConstColorProcessor::InputMode::kIgnore); |
Brian Salomon | eec6f7b | 2017-02-10 14:29:38 -0500 | [diff] [blame] | 483 | if (leadingFPsToEliminate == cnt) { |
| 484 | return colorFP; |
| 485 | } |
| 486 | cnt = cnt - leadingFPsToEliminate + 1; |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 487 | replacementSeries.reserve(cnt); |
| 488 | replacementSeries.emplace_back(std::move(colorFP)); |
| 489 | for (int i = 0; i < cnt - 1; ++i) { |
Brian Salomon | eec6f7b | 2017-02-10 14:29:38 -0500 | [diff] [blame] | 490 | replacementSeries.emplace_back(std::move(series[leadingFPsToEliminate + i])); |
bsalomon | e25eea4 | 2015-09-29 06:38:55 -0700 | [diff] [blame] | 491 | } |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 492 | series = replacementSeries.begin(); |
bsalomon | e25eea4 | 2015-09-29 06:38:55 -0700 | [diff] [blame] | 493 | } |
Robert Phillips | 1c9686b | 2017-06-30 08:40:28 -0400 | [diff] [blame] | 494 | return SeriesFragmentProcessor::Make(series, cnt); |
bsalomon | e25eea4 | 2015-09-29 06:38:55 -0700 | [diff] [blame] | 495 | } |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 496 | |
| 497 | ////////////////////////////////////////////////////////////////////////////// |
| 498 | |
Brian Salomon | 7eabfe8 | 2019-12-02 14:20:20 -0500 | [diff] [blame] | 499 | GrFragmentProcessor::CIter::CIter(const GrPaint& paint) { |
Chris Dalton | 1c54894 | 2018-05-22 13:09:48 -0600 | [diff] [blame] | 500 | for (int i = paint.numCoverageFragmentProcessors() - 1; i >= 0; --i) { |
| 501 | fFPStack.push_back(paint.getCoverageFragmentProcessor(i)); |
| 502 | } |
| 503 | for (int i = paint.numColorFragmentProcessors() - 1; i >= 0; --i) { |
| 504 | fFPStack.push_back(paint.getColorFragmentProcessor(i)); |
| 505 | } |
| 506 | } |
| 507 | |
Brian Salomon | 7eabfe8 | 2019-12-02 14:20:20 -0500 | [diff] [blame] | 508 | GrFragmentProcessor::CIter::CIter(const GrProcessorSet& set) { |
Brian Salomon | c241b58 | 2019-11-27 08:57:17 -0500 | [diff] [blame] | 509 | for (int i = set.numCoverageFragmentProcessors() - 1; i >= 0; --i) { |
| 510 | fFPStack.push_back(set.coverageFragmentProcessor(i)); |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 511 | } |
Brian Salomon | c241b58 | 2019-11-27 08:57:17 -0500 | [diff] [blame] | 512 | for (int i = set.numColorFragmentProcessors() - 1; i >= 0; --i) { |
| 513 | fFPStack.push_back(set.colorFragmentProcessor(i)); |
| 514 | } |
| 515 | } |
| 516 | |
Brian Salomon | 7eabfe8 | 2019-12-02 14:20:20 -0500 | [diff] [blame] | 517 | GrFragmentProcessor::CIter::CIter(const GrPipeline& pipeline) { |
Brian Salomon | c241b58 | 2019-11-27 08:57:17 -0500 | [diff] [blame] | 518 | for (int i = pipeline.numFragmentProcessors() - 1; i >= 0; --i) { |
| 519 | fFPStack.push_back(&pipeline.getFragmentProcessor(i)); |
| 520 | } |
| 521 | } |
| 522 | |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 523 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 524 | |
Robert Phillips | bd99c0c | 2019-12-12 13:26:58 +0000 | [diff] [blame] | 525 | GrFragmentProcessor::TextureSampler::TextureSampler(GrSurfaceProxyView view, |
Brian Salomon | ccb6142 | 2020-01-09 10:46:36 -0500 | [diff] [blame] | 526 | GrSamplerState samplerState) |
| 527 | : fView(std::move(view)), fSamplerState(samplerState) { |
Robert Phillips | bd99c0c | 2019-12-12 13:26:58 +0000 | [diff] [blame] | 528 | GrSurfaceProxy* proxy = this->proxy(); |
Greg Daniel | acf5929 | 2019-12-11 13:45:17 -0500 | [diff] [blame] | 529 | fSamplerState.setFilterMode( |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 530 | std::min(samplerState.filter(), |
Robert Phillips | bd99c0c | 2019-12-12 13:26:58 +0000 | [diff] [blame] | 531 | GrTextureProxy::HighestFilterMode(proxy->backendFormat().textureType()))); |
Greg Daniel | acf5929 | 2019-12-11 13:45:17 -0500 | [diff] [blame] | 532 | } |
Robert Phillips | bd99c0c | 2019-12-12 13:26:58 +0000 | [diff] [blame] | 533 | |
Robert Phillips | bd99c0c | 2019-12-12 13:26:58 +0000 | [diff] [blame] | 534 | #if GR_TEST_UTILS |
| 535 | void GrFragmentProcessor::TextureSampler::set(GrSurfaceProxyView view, |
Brian Salomon | ccb6142 | 2020-01-09 10:46:36 -0500 | [diff] [blame] | 536 | GrSamplerState samplerState) { |
Robert Phillips | bd99c0c | 2019-12-12 13:26:58 +0000 | [diff] [blame] | 537 | SkASSERT(view.proxy()->asTextureProxy()); |
| 538 | fView = std::move(view); |
| 539 | fSamplerState = samplerState; |
| 540 | |
| 541 | fSamplerState.setFilterMode( |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 542 | std::min(samplerState.filter(), |
Robert Phillips | bd99c0c | 2019-12-12 13:26:58 +0000 | [diff] [blame] | 543 | GrTextureProxy::HighestFilterMode(this->proxy()->backendFormat().textureType()))); |
| 544 | } |
| 545 | #endif |