| 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" |
| 11 #include "GrPipeline.h" | |
| 12 #include "GrProcOptInfo.h" | 11 #include "GrProcOptInfo.h" |
| 13 #include "glsl/GrGLSLFragmentProcessor.h" | 12 #include "glsl/GrGLSLFragmentProcessor.h" |
| 14 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 13 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 15 #include "glsl/GrGLSLProgramDataManager.h" | 14 #include "glsl/GrGLSLProgramDataManager.h" |
| 16 #include "glsl/GrGLSLUniformHandler.h" | 15 #include "glsl/GrGLSLUniformHandler.h" |
| 17 #include "effects/GrConstColorProcessor.h" | 16 #include "effects/GrConstColorProcessor.h" |
| 18 #include "effects/GrXfermodeFragmentProcessor.h" | 17 #include "effects/GrXfermodeFragmentProcessor.h" |
| 19 | 18 |
| 20 GrFragmentProcessor::~GrFragmentProcessor() { | 19 GrFragmentProcessor::~GrFragmentProcessor() { |
| 21 // If we got here then our ref count must have reached zero, so we will have
converted refs | 20 // If we got here then our ref count must have reached zero, so we will have
converted refs |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 } | 74 } |
| 76 | 75 |
| 77 void GrFragmentProcessor::addCoordTransform(const GrCoordTransform* transform) { | 76 void GrFragmentProcessor::addCoordTransform(const GrCoordTransform* transform) { |
| 78 // Can't add transforms after registering any children since their transform
s have already been | 77 // Can't add transforms after registering any children since their transform
s have already been |
| 79 // bubbled up into our fCoordTransforms array | 78 // bubbled up into our fCoordTransforms array |
| 80 SkASSERT(fChildProcessors.empty()); | 79 SkASSERT(fChildProcessors.empty()); |
| 81 | 80 |
| 82 fCoordTransforms.push_back(transform); | 81 fCoordTransforms.push_back(transform); |
| 83 fUsesLocalCoords = fUsesLocalCoords || transform->sourceCoords() == kLocal_G
rCoordSet; | 82 fUsesLocalCoords = fUsesLocalCoords || transform->sourceCoords() == kLocal_G
rCoordSet; |
| 84 SkDEBUGCODE(transform->setInProcessor();) | 83 SkDEBUGCODE(transform->setInProcessor();) |
| 84 fNumTransformsExclChildren++; |
| 85 } | 85 } |
| 86 | 86 |
| 87 int GrFragmentProcessor::registerChildProcessor(sk_sp<GrFragmentProcessor> child
) { | 87 int GrFragmentProcessor::registerChildProcessor(sk_sp<GrFragmentProcessor> child
) { |
| 88 // Append the child's textures array to our textures array | 88 // Append the child's transforms to our transforms array and the child's tex
tures array to our |
| 89 // textures array |
| 90 if (!child->fCoordTransforms.empty()) { |
| 91 fCoordTransforms.push_back_n(child->fCoordTransforms.count(), |
| 92 child->fCoordTransforms.begin()); |
| 93 } |
| 89 if (!child->fTextureAccesses.empty()) { | 94 if (!child->fTextureAccesses.empty()) { |
| 90 fTextureAccesses.push_back_n(child->fTextureAccesses.count(), | 95 fTextureAccesses.push_back_n(child->fTextureAccesses.count(), |
| 91 child->fTextureAccesses.begin()); | 96 child->fTextureAccesses.begin()); |
| 92 } | 97 } |
| 93 | 98 |
| 94 this->combineRequiredFeatures(*child); | 99 this->combineRequiredFeatures(*child); |
| 95 | 100 |
| 96 if (child->usesLocalCoords()) { | 101 if (child->usesLocalCoords()) { |
| 97 fUsesLocalCoords = true; | 102 fUsesLocalCoords = true; |
| 98 } | 103 } |
| 99 if (child->usesDistanceVectorField()) { | 104 if (child->usesDistanceVectorField()) { |
| 100 fUsesDistanceVectorField = true; | 105 fUsesDistanceVectorField = true; |
| 101 } | 106 } |
| 102 | 107 |
| 103 int index = fChildProcessors.count(); | 108 int index = fChildProcessors.count(); |
| 104 fChildProcessors.push_back(child.release()); | 109 fChildProcessors.push_back(child.release()); |
| 105 | 110 |
| 106 return index; | 111 return index; |
| 107 } | 112 } |
| 108 | 113 |
| 109 void GrFragmentProcessor::notifyRefCntIsZero() const { | 114 void GrFragmentProcessor::notifyRefCntIsZero() const { |
| 110 // See comment above GrProgramElement for a detailed explanation of why we d
o this. | 115 // See comment above GrProgramElement for a detailed explanation of why we d
o this. |
| 111 for (int i = 0; i < fChildProcessors.count(); ++i) { | 116 for (int i = 0; i < fChildProcessors.count(); ++i) { |
| 112 fChildProcessors[i]->addPendingExecution(); | 117 fChildProcessors[i]->addPendingExecution(); |
| 113 fChildProcessors[i]->unref(); | 118 fChildProcessors[i]->unref(); |
| 114 } | 119 } |
| 115 } | 120 } |
| 116 | 121 |
| 117 bool GrFragmentProcessor::hasSameTransforms(const GrFragmentProcessor& that) con
st { | 122 bool GrFragmentProcessor::hasSameTransforms(const GrFragmentProcessor& that) con
st { |
| 118 if (this->numCoordTransforms() != that.numCoordTransforms()) { | 123 if (this->numTransforms() != that.numTransforms()) { |
| 119 return false; | 124 return false; |
| 120 } | 125 } |
| 121 int count = this->numCoordTransforms(); | 126 int count = this->numTransforms(); |
| 122 for (int i = 0; i < count; ++i) { | 127 for (int i = 0; i < count; ++i) { |
| 123 if (this->coordTransform(i) != that.coordTransform(i)) { | 128 if (this->coordTransform(i) != that.coordTransform(i)) { |
| 124 return false; | 129 return false; |
| 125 } | 130 } |
| 126 } | 131 } |
| 127 return true; | 132 return true; |
| 128 } | 133 } |
| 129 | 134 |
| 130 sk_sp<GrFragmentProcessor> GrFragmentProcessor::MulOutputByInputAlpha( | 135 sk_sp<GrFragmentProcessor> GrFragmentProcessor::MulOutputByInputAlpha( |
| 131 sk_sp<GrFragmentProcessor> fp) { | 136 sk_sp<GrFragmentProcessor> fp) { |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 } else { | 401 } else { |
| 397 series += firstIdx; | 402 series += firstIdx; |
| 398 cnt -= firstIdx; | 403 cnt -= firstIdx; |
| 399 } | 404 } |
| 400 | 405 |
| 401 if (1 == cnt) { | 406 if (1 == cnt) { |
| 402 return series[0]; | 407 return series[0]; |
| 403 } | 408 } |
| 404 return sk_sp<GrFragmentProcessor>(new SeriesFragmentProcessor(series, cnt)); | 409 return sk_sp<GrFragmentProcessor>(new SeriesFragmentProcessor(series, cnt)); |
| 405 } | 410 } |
| 406 | |
| 407 ////////////////////////////////////////////////////////////////////////////// | |
| 408 | |
| 409 GrFragmentProcessor::Iter::Iter(const GrPipeline& pipeline) { | |
| 410 for (int i = pipeline.numFragmentProcessors() - 1; i >= 0; --i) { | |
| 411 fFPStack.push_back(&pipeline.getFragmentProcessor(i)); | |
| 412 } | |
| 413 } | |
| 414 | |
| 415 const GrFragmentProcessor* GrFragmentProcessor::Iter::next() { | |
| 416 if (fFPStack.empty()) { | |
| 417 return nullptr; | |
| 418 } | |
| 419 const GrFragmentProcessor* back = fFPStack.back(); | |
| 420 fFPStack.pop_back(); | |
| 421 for (int i = back->numChildProcessors() - 1; i >= 0; --i) { | |
| 422 fFPStack.push_back(&back->childProcessor(i)); | |
| 423 } | |
| 424 return back; | |
| 425 } | |
| 426 | |
| 427 ////////////////////////////////////////////////////////////////////////////// | |
| 428 | |
| 429 const GrCoordTransform* GrFragmentProcessor::CoordTransformIter::next() { | |
| 430 if (!fCurrFP) { | |
| 431 return nullptr; | |
| 432 } | |
| 433 while (fCTIdx == fCurrFP->numCoordTransforms()) { | |
| 434 fCTIdx = 0; | |
| 435 fCurrFP = fFPIter.next(); | |
| 436 if (!fCurrFP) { | |
| 437 return nullptr; | |
| 438 } | |
| 439 } | |
| 440 return &fCurrFP->coordTransform(fCTIdx++); | |
| 441 } | |
| OLD | NEW |