1 /*
2  * Copyright 2014 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 
8 #include "GrProcOptInfo.h"
9 
10 #include "GrGeometryProcessor.h"
11 
12 #include "batches/GrDrawBatch.h"
13 
calcWithInitialValues(const GrFragmentProcessor * const processors[],int cnt,GrColor startColor,GrColorComponentFlags flags,bool areCoverageStages,bool isLCD)14 void GrProcOptInfo::calcWithInitialValues(const GrFragmentProcessor * const processors[],
15                                           int cnt,
16                                           GrColor startColor,
17                                           GrColorComponentFlags flags,
18                                           bool areCoverageStages,
19                                           bool isLCD) {
20     GrInitInvariantOutput out;
21     out.fIsSingleComponent = areCoverageStages;
22     out.fColor = startColor;
23     out.fValidFlags = flags;
24     out.fIsLCDCoverage = isLCD;
25     fInOut.reset(out);
26     this->internalCalc(processors, cnt);
27 }
28 
initUsingInvariantOutput(GrInitInvariantOutput invOutput)29 void GrProcOptInfo::initUsingInvariantOutput(GrInitInvariantOutput invOutput) {
30     fInOut.reset(invOutput);
31 }
32 
completeCalculations(const GrFragmentProcessor * const processors[],int cnt)33 void GrProcOptInfo::completeCalculations(const GrFragmentProcessor * const processors[], int cnt) {
34     this->internalCalc(processors, cnt);
35 }
36 
internalCalc(const GrFragmentProcessor * const processors[],int cnt)37 void GrProcOptInfo::internalCalc(const GrFragmentProcessor* const processors[], int cnt) {
38     fFirstEffectiveProcessorIndex = 0;
39     fInputColorIsUsed = true;
40     fInputColor = fInOut.color();
41 
42     for (int i = 0; i < cnt; ++i) {
43         const GrFragmentProcessor* processor = processors[i];
44         fInOut.resetWillUseInputColor();
45         processor->computeInvariantOutput(&fInOut);
46         SkDEBUGCODE(fInOut.validate());
47         if (!fInOut.willUseInputColor()) {
48             fFirstEffectiveProcessorIndex = i;
49             fInputColorIsUsed = false;
50         }
51         if (kRGBA_GrColorComponentFlags == fInOut.validFlags()) {
52             fFirstEffectiveProcessorIndex = i + 1;
53             fInputColor = fInOut.color();
54             fInputColorIsUsed = true;
55             // Since we are clearing all previous color stages we are in a state where we have found
56             // zero stages that don't multiply the inputColor.
57             fInOut.resetNonMulStageFound();
58         }
59     }
60 }
61