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 "GrProcessorAnalysis.h"
9 #include "GrGeometryProcessor.h"
10 #include "ops/GrDrawOp.h"
11 
12 GrColorFragmentProcessorAnalysis::GrColorFragmentProcessorAnalysis(
13         const GrProcessorAnalysisColor& input,
14         const GrFragmentProcessor* const* processors,
15         int cnt) {
16     fCompatibleWithCoverageAsAlpha = true;
17     fIsOpaque = input.isOpaque();
18     fUsesLocalCoords = false;
19     fProcessorsToEliminate = 0;
20     GrColor color;
21     if ((fKnowOutputColor = input.isConstant(&color))) {
22         fLastKnownOutputColor = GrColor4f::FromGrColor(color);
23     }
24     for (int i = 0; i < cnt; ++i) {
25         if (fUsesLocalCoords && !fKnowOutputColor && !fCompatibleWithCoverageAsAlpha &&
26             !fIsOpaque) {
27             break;
28         }
29         const GrFragmentProcessor* fp = processors[i];
30         if (fKnowOutputColor &&
31             fp->hasConstantOutputForConstantInput(fLastKnownOutputColor, &fLastKnownOutputColor)) {
32             ++fProcessorsToEliminate;
33             fIsOpaque = fLastKnownOutputColor.isOpaque();
34             // We reset these since the caller is expected to not use the earlier fragment
35             // processors.
36             fCompatibleWithCoverageAsAlpha = true;
37             fUsesLocalCoords = false;
38         } else {
39             fKnowOutputColor = false;
40             if (fIsOpaque && !fp->preservesOpaqueInput()) {
41                 fIsOpaque = false;
42             }
43             if (fCompatibleWithCoverageAsAlpha && !fp->compatibleWithCoverageAsAlpha()) {
44                 fCompatibleWithCoverageAsAlpha = false;
45             }
46             if (fp->usesLocalCoords()) {
47                 fUsesLocalCoords = true;
48             }
49         }
50     }
51 }
52