| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "GrFragmentProcessor.h" | 9 #include "GrFragmentProcessor.h" |
| 10 #include "GrCoordTransform.h" | 10 #include "GrCoordTransform.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 return false; | 43 return false; |
| 44 } | 44 } |
| 45 for (int i = 0; i < this->numChildProcessors(); ++i) { | 45 for (int i = 0; i < this->numChildProcessors(); ++i) { |
| 46 if (!this->childProcessor(i).isEqual(that.childProcessor(i), ignoreCoord
Transforms)) { | 46 if (!this->childProcessor(i).isEqual(that.childProcessor(i), ignoreCoord
Transforms)) { |
| 47 return false; | 47 return false; |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 return true; | 50 return true; |
| 51 } | 51 } |
| 52 | 52 |
| 53 GrGLSLFragmentProcessor* GrFragmentProcessor::createGLInstance() const { | 53 GrGLSLFragmentProcessor* GrFragmentProcessor::createGLSLInstance() const { |
| 54 GrGLSLFragmentProcessor* glFragProc = this->onCreateGLInstance(); | 54 GrGLSLFragmentProcessor* glFragProc = this->onCreateGLSLInstance(); |
| 55 glFragProc->fChildProcessors.push_back_n(fChildProcessors.count()); | 55 glFragProc->fChildProcessors.push_back_n(fChildProcessors.count()); |
| 56 for (int i = 0; i < fChildProcessors.count(); ++i) { | 56 for (int i = 0; i < fChildProcessors.count(); ++i) { |
| 57 glFragProc->fChildProcessors[i] = fChildProcessors[i]->createGLInstance(
); | 57 glFragProc->fChildProcessors[i] = fChildProcessors[i]->createGLSLInstanc
e(); |
| 58 } | 58 } |
| 59 return glFragProc; | 59 return glFragProc; |
| 60 } | 60 } |
| 61 | 61 |
| 62 void GrFragmentProcessor::addTextureAccess(const GrTextureAccess* textureAccess)
{ | 62 void GrFragmentProcessor::addTextureAccess(const GrTextureAccess* textureAccess)
{ |
| 63 // Can't add texture accesses after registering any children since their tex
ture accesses have | 63 // Can't add texture accesses after registering any children since their tex
ture accesses have |
| 64 // already been bubbled up into our fTextureAccesses array | 64 // already been bubbled up into our fTextureAccesses array |
| 65 SkASSERT(fChildProcessors.empty()); | 65 SkASSERT(fChildProcessors.empty()); |
| 66 | 66 |
| 67 INHERITED::addTextureAccess(textureAccess); | 67 INHERITED::addTextureAccess(textureAccess); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 class PremulFragmentProcessor : public GrFragmentProcessor { | 140 class PremulFragmentProcessor : public GrFragmentProcessor { |
| 141 public: | 141 public: |
| 142 PremulFragmentProcessor(const GrFragmentProcessor* processor) { | 142 PremulFragmentProcessor(const GrFragmentProcessor* processor) { |
| 143 this->initClassID<PremulFragmentProcessor>(); | 143 this->initClassID<PremulFragmentProcessor>(); |
| 144 this->registerChildProcessor(processor); | 144 this->registerChildProcessor(processor); |
| 145 } | 145 } |
| 146 | 146 |
| 147 const char* name() const override { return "Premultiply"; } | 147 const char* name() const override { return "Premultiply"; } |
| 148 | 148 |
| 149 private: | 149 private: |
| 150 GrGLSLFragmentProcessor* onCreateGLInstance() const override { | 150 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { |
| 151 class GLFP : public GrGLSLFragmentProcessor { | 151 class GLFP : public GrGLSLFragmentProcessor { |
| 152 public: | 152 public: |
| 153 GLFP() {} | 153 GLFP() {} |
| 154 | 154 |
| 155 void emitCode(EmitArgs& args) override { | 155 void emitCode(EmitArgs& args) override { |
| 156 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmen
tShaderBuilder(); | 156 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmen
tShaderBuilder(); |
| 157 this->emitChild(0, nullptr, args); | 157 this->emitChild(0, nullptr, args); |
| 158 fsBuilder->codeAppendf("%s.rgb *= %s.rgb;", args.fOutputColo
r, | 158 fsBuilder->codeAppendf("%s.rgb *= %s.rgb;", args.fOutputColo
r, |
| 159 args.fInputColor
); | 159 args.fInputColor
); |
| 160 fsBuilder->codeAppendf("%s *= %s.a;", args.fOutputColor, arg
s.fInputColor); | 160 fsBuilder->codeAppendf("%s *= %s.a;", args.fOutputColor, arg
s.fInputColor); |
| 161 } | 161 } |
| 162 }; | 162 }; |
| 163 return new GLFP; | 163 return new GLFP; |
| 164 } | 164 } |
| 165 | 165 |
| 166 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) cons
t override {} | 166 void onGetGLSLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) co
nst override {} |
| 167 | 167 |
| 168 bool onIsEqual(const GrFragmentProcessor&) const override { return true;
} | 168 bool onIsEqual(const GrFragmentProcessor&) const override { return true;
} |
| 169 | 169 |
| 170 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { | 170 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { |
| 171 // TODO: Add a helper to GrInvariantOutput that handles multiplying
by color with flags? | 171 // TODO: Add a helper to GrInvariantOutput that handles multiplying
by color with flags? |
| 172 if (!(inout->validFlags() & kA_GrColorComponentFlag)) { | 172 if (!(inout->validFlags() & kA_GrColorComponentFlag)) { |
| 173 inout->setToUnknown(GrInvariantOutput::kWill_ReadInput); | 173 inout->setToUnknown(GrInvariantOutput::kWill_ReadInput); |
| 174 return; | 174 return; |
| 175 } | 175 } |
| 176 | 176 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 class ReplaceInputFragmentProcessor : public GrFragmentProcessor { | 213 class ReplaceInputFragmentProcessor : public GrFragmentProcessor { |
| 214 public: | 214 public: |
| 215 ReplaceInputFragmentProcessor(const GrFragmentProcessor* child, GrColor
color) | 215 ReplaceInputFragmentProcessor(const GrFragmentProcessor* child, GrColor
color) |
| 216 : fColor(color) { | 216 : fColor(color) { |
| 217 this->initClassID<ReplaceInputFragmentProcessor>(); | 217 this->initClassID<ReplaceInputFragmentProcessor>(); |
| 218 this->registerChildProcessor(child); | 218 this->registerChildProcessor(child); |
| 219 } | 219 } |
| 220 | 220 |
| 221 const char* name() const override { return "Replace Color"; } | 221 const char* name() const override { return "Replace Color"; } |
| 222 | 222 |
| 223 GrGLSLFragmentProcessor* onCreateGLInstance() const override { | 223 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { |
| 224 class GLFP : public GrGLSLFragmentProcessor { | 224 class GLFP : public GrGLSLFragmentProcessor { |
| 225 public: | 225 public: |
| 226 GLFP() : fHaveSetColor(false) {} | 226 GLFP() : fHaveSetColor(false) {} |
| 227 void emitCode(EmitArgs& args) override { | 227 void emitCode(EmitArgs& args) override { |
| 228 const char* colorName; | 228 const char* colorName; |
| 229 fColorUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::
kFragment_Visibility, | 229 fColorUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::
kFragment_Visibility, |
| 230 kVec4f_GrSLType, kDefa
ult_GrSLPrecision, | 230 kVec4f_GrSLType, kDefa
ult_GrSLPrecision, |
| 231 "Color", &colorName); | 231 "Color", &colorName); |
| 232 this->emitChild(0, colorName, args); | 232 this->emitChild(0, colorName, args); |
| 233 } | 233 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 252 | 252 |
| 253 GrGLSLProgramDataManager::UniformHandle fColorUni; | 253 GrGLSLProgramDataManager::UniformHandle fColorUni; |
| 254 bool fHaveSetColor; | 254 bool fHaveSetColor; |
| 255 GrColor fPreviousColor; | 255 GrColor fPreviousColor; |
| 256 }; | 256 }; |
| 257 | 257 |
| 258 return new GLFP; | 258 return new GLFP; |
| 259 } | 259 } |
| 260 | 260 |
| 261 private: | 261 private: |
| 262 void onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder*
b) const override {} | 262 void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder
* b) const override |
| 263 {} |
| 263 | 264 |
| 264 bool onIsEqual(const GrFragmentProcessor& that) const override { | 265 bool onIsEqual(const GrFragmentProcessor& that) const override { |
| 265 return fColor == that.cast<ReplaceInputFragmentProcessor>().fColor; | 266 return fColor == that.cast<ReplaceInputFragmentProcessor>().fColor; |
| 266 } | 267 } |
| 267 | 268 |
| 268 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { | 269 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { |
| 269 inout->setToOther(kRGBA_GrColorComponentFlags, fColor, | 270 inout->setToOther(kRGBA_GrColorComponentFlags, fColor, |
| 270 GrInvariantOutput::kWillNot_ReadInput); | 271 GrInvariantOutput::kWillNot_ReadInput); |
| 271 this->childProcessor(0).computeInvariantOutput(inout); | 272 this->childProcessor(0).computeInvariantOutput(inout); |
| 272 } | 273 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 290 SeriesFragmentProcessor(const GrFragmentProcessor* children[], int cnt){ | 291 SeriesFragmentProcessor(const GrFragmentProcessor* children[], int cnt){ |
| 291 SkASSERT(cnt > 1); | 292 SkASSERT(cnt > 1); |
| 292 this->initClassID<SeriesFragmentProcessor>(); | 293 this->initClassID<SeriesFragmentProcessor>(); |
| 293 for (int i = 0; i < cnt; ++i) { | 294 for (int i = 0; i < cnt; ++i) { |
| 294 this->registerChildProcessor(children[i]); | 295 this->registerChildProcessor(children[i]); |
| 295 } | 296 } |
| 296 } | 297 } |
| 297 | 298 |
| 298 const char* name() const override { return "Series"; } | 299 const char* name() const override { return "Series"; } |
| 299 | 300 |
| 300 GrGLSLFragmentProcessor* onCreateGLInstance() const override { | 301 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { |
| 301 class GLFP : public GrGLSLFragmentProcessor { | 302 class GLFP : public GrGLSLFragmentProcessor { |
| 302 public: | 303 public: |
| 303 GLFP() {} | 304 GLFP() {} |
| 304 void emitCode(EmitArgs& args) override { | 305 void emitCode(EmitArgs& args) override { |
| 305 SkString input(args.fInputColor); | 306 SkString input(args.fInputColor); |
| 306 for (int i = 0; i < this->numChildProcessors() - 1; ++i) { | 307 for (int i = 0; i < this->numChildProcessors() - 1; ++i) { |
| 307 SkString temp; | 308 SkString temp; |
| 308 temp.printf("out%d", i); | 309 temp.printf("out%d", i); |
| 309 this->emitChild(i, input.c_str(), &temp, args); | 310 this->emitChild(i, input.c_str(), &temp, args); |
| 310 input = temp; | 311 input = temp; |
| 311 } | 312 } |
| 312 // Last guy writes to our output variable. | 313 // Last guy writes to our output variable. |
| 313 this->emitChild(this->numChildProcessors() - 1, input.c_str(
), args); | 314 this->emitChild(this->numChildProcessors() - 1, input.c_str(
), args); |
| 314 } | 315 } |
| 315 }; | 316 }; |
| 316 return new GLFP; | 317 return new GLFP; |
| 317 } | 318 } |
| 318 | 319 |
| 319 private: | 320 private: |
| 320 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) cons
t override {} | 321 void onGetGLSLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) co
nst override {} |
| 321 | 322 |
| 322 bool onIsEqual(const GrFragmentProcessor&) const override { return true;
} | 323 bool onIsEqual(const GrFragmentProcessor&) const override { return true;
} |
| 323 | 324 |
| 324 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { | 325 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { |
| 325 GrProcOptInfo info; | 326 GrProcOptInfo info; |
| 326 SkTDArray<const GrFragmentProcessor*> children; | 327 SkTDArray<const GrFragmentProcessor*> children; |
| 327 children.setCount(this->numChildProcessors()); | 328 children.setCount(this->numChildProcessors()); |
| 328 for (int i = 0; i < children.count(); ++i) { | 329 for (int i = 0; i < children.count(); ++i) { |
| 329 children[i] = &this->childProcessor(i); | 330 children[i] = &this->childProcessor(i); |
| 330 } | 331 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 } | 369 } |
| 369 } | 370 } |
| 370 | 371 |
| 371 if (1 == cnt) { | 372 if (1 == cnt) { |
| 372 return SkRef(series[0]); | 373 return SkRef(series[0]); |
| 373 } else { | 374 } else { |
| 374 return new SeriesFragmentProcessor(series, cnt); | 375 return new SeriesFragmentProcessor(series, cnt); |
| 375 } | 376 } |
| 376 } | 377 } |
| 377 | 378 |
| OLD | NEW |