Chromium Code Reviews| 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 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 }; | 272 }; |
| 273 | 273 |
| 274 GrInvariantOutput childOut(0x0, kNone_GrColorComponentFlags, false); | 274 GrInvariantOutput childOut(0x0, kNone_GrColorComponentFlags, false); |
| 275 fp->computeInvariantOutput(&childOut); | 275 fp->computeInvariantOutput(&childOut); |
| 276 if (childOut.willUseInputColor()) { | 276 if (childOut.willUseInputColor()) { |
| 277 return new ReplaceInputFragmentProcessor(fp, color); | 277 return new ReplaceInputFragmentProcessor(fp, color); |
| 278 } else { | 278 } else { |
| 279 return SkRef(fp); | 279 return SkRef(fp); |
| 280 } | 280 } |
| 281 } | 281 } |
| 282 | |
| 283 #include "effects/GrConstColorProcessor.h" | |
|
egdaniel
2015/09/29 13:23:52
Do we want this include in middle of file? Usually
bsalomon
2015/09/29 13:31:43
Done.
| |
| 284 | |
| 285 const GrFragmentProcessor* GrFragmentProcessor::RunInSeries(const GrFragmentProc essor* series[], | |
| 286 int cnt) { | |
| 287 class SeriesFragmentProcessor : public GrFragmentProcessor { | |
| 288 public: | |
| 289 SeriesFragmentProcessor(const GrFragmentProcessor* children[], int cnt){ | |
| 290 SkASSERT(cnt > 1); | |
| 291 this->initClassID<SeriesFragmentProcessor>(); | |
| 292 for (int i = 0; i < cnt; ++i) { | |
| 293 this->registerChildProcessor(children[i]); | |
| 294 } | |
| 295 } | |
| 296 | |
| 297 const char* name() const override { return "Series"; } | |
| 298 | |
| 299 GrGLFragmentProcessor* onCreateGLInstance() const override { | |
| 300 class GLFP : public GrGLFragmentProcessor { | |
| 301 public: | |
| 302 GLFP() {} | |
| 303 void emitCode(EmitArgs& args) override { | |
| 304 SkString input(args.fInputColor); | |
| 305 for (int i = 0; i < this->numChildProcessors() - 1; ++i) { | |
| 306 SkString temp; | |
| 307 temp.printf("out%d", i); | |
| 308 this->emitChild(i, input.c_str(), &temp, args); | |
| 309 input = temp; | |
| 310 } | |
| 311 // Last guy writes to our output variable. | |
| 312 this->emitChild(this->numChildProcessors() - 1, input.c_str( ), args); | |
| 313 } | |
| 314 }; | |
| 315 return new GLFP; | |
| 316 } | |
| 317 | |
| 318 private: | |
| 319 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) cons t override {} | |
| 320 | |
| 321 bool onIsEqual(const GrFragmentProcessor&) const override { return true; } | |
| 322 | |
| 323 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { | |
| 324 GrProcOptInfo info; | |
| 325 SkTDArray<const GrFragmentProcessor*> children; | |
| 326 children.setCount(this->numChildProcessors()); | |
| 327 for (int i = 0; i < children.count(); ++i) { | |
| 328 children[i] = &this->childProcessor(i); | |
| 329 } | |
| 330 info.calcWithInitialValues(children.begin(), children.count(), inout ->color(), | |
| 331 inout->validFlags(), false, false); | |
| 332 for (int i = 0; i < this->numChildProcessors(); ++i) { | |
| 333 this->childProcessor(i).computeInvariantOutput(inout); | |
| 334 } | |
| 335 } | |
| 336 }; | |
| 337 | |
| 338 if (!cnt) { | |
| 339 return nullptr; | |
| 340 } | |
| 341 | |
| 342 // Run the through the series, do the invariant output processing, and look for eliminations. | |
| 343 SkTDArray<const GrFragmentProcessor*> replacementSeries; | |
| 344 SkAutoTUnref<const GrFragmentProcessor> colorFP; | |
| 345 GrProcOptInfo info; | |
| 346 | |
| 347 info.calcWithInitialValues(series, cnt, 0x0, kNone_GrColorComponentFlags, fa lse, false); | |
| 348 if (kRGBA_GrColorComponentFlags == info.validFlags()) { | |
| 349 return GrConstColorProcessor::Create(info.color(), | |
| 350 GrConstColorProcessor::kIgnore_Inpu tMode); | |
| 351 } else { | |
| 352 int firstIdx = info.firstEffectiveProcessorIndex(); | |
| 353 cnt -= firstIdx; | |
| 354 if (firstIdx > 0 && info.inputColorIsUsed()) { | |
| 355 colorFP.reset(GrConstColorProcessor::Create(info.inputColorToFirstEf fectiveProccesor(), | |
| 356 GrConstColorProcessor::k Ignore_InputMode)); | |
| 357 cnt += 1; | |
| 358 replacementSeries.setCount(cnt); | |
| 359 replacementSeries[0] = colorFP; | |
| 360 for (int i = 0; i < cnt - 1; ++i) { | |
| 361 replacementSeries[i + 1] = series[firstIdx + i]; | |
| 362 } | |
| 363 series = replacementSeries.begin(); | |
| 364 } else { | |
| 365 series += firstIdx; | |
| 366 cnt -= firstIdx; | |
| 367 } | |
| 368 } | |
| 369 | |
| 370 if (1 == cnt) { | |
| 371 return SkRef(series[0]); | |
| 372 } else { | |
| 373 return new SeriesFragmentProcessor(series, cnt); | |
| 374 } | |
| 375 } | |
| 376 | |
| OLD | NEW |