egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 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 | |
Brian Salomon | a811b12 | 2017-03-30 08:21:32 -0400 | [diff] [blame] | 8 | #include "GrProcessorAnalysis.h" |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 9 | #include "GrGeometryProcessor.h" |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 10 | #include "ops/GrDrawOp.h" |
joshualitt | 7441782 | 2015-08-07 11:42:16 -0700 | [diff] [blame] | 11 | |
Brian Salomon | 650ced0 | 2017-07-20 16:46:46 -0400 | [diff] [blame] | 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 | } |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 24 | for (int i = 0; i < cnt; ++i) { |
Brian Salomon | 650ced0 | 2017-07-20 16:46:46 -0400 | [diff] [blame] | 25 | if (fUsesLocalCoords && !fKnowOutputColor && !fCompatibleWithCoverageAsAlpha && |
| 26 | !fIsOpaque) { |
| 27 | break; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 28 | } |
Brian Salomon | eec6f7b | 2017-02-10 14:29:38 -0500 | [diff] [blame] | 29 | const GrFragmentProcessor* fp = processors[i]; |
Brian Salomon | 650ced0 | 2017-07-20 16:46:46 -0400 | [diff] [blame] | 30 | if (fKnowOutputColor && |
Brian Salomon | c0b642c | 2017-03-27 13:09:36 -0400 | [diff] [blame] | 31 | fp->hasConstantOutputForConstantInput(fLastKnownOutputColor, &fLastKnownOutputColor)) { |
Brian Salomon | 650ced0 | 2017-07-20 16:46:46 -0400 | [diff] [blame] | 32 | ++fProcessorsToEliminate; |
Brian Salomon | eec6f7b | 2017-02-10 14:29:38 -0500 | [diff] [blame] | 33 | fIsOpaque = fLastKnownOutputColor.isOpaque(); |
Brian Salomon | bfafcba | 2017-03-02 08:49:19 -0500 | [diff] [blame] | 34 | // We reset these since the caller is expected to not use the earlier fragment |
| 35 | // processors. |
Brian Salomon | 650ced0 | 2017-07-20 16:46:46 -0400 | [diff] [blame] | 36 | fCompatibleWithCoverageAsAlpha = true; |
Brian Salomon | bfafcba | 2017-03-02 08:49:19 -0500 | [diff] [blame] | 37 | fUsesLocalCoords = false; |
Brian Salomon | 28207df | 2017-06-05 12:25:13 -0400 | [diff] [blame] | 38 | } else { |
Brian Salomon | 650ced0 | 2017-07-20 16:46:46 -0400 | [diff] [blame] | 39 | fKnowOutputColor = false; |
Brian Salomon | 28207df | 2017-06-05 12:25:13 -0400 | [diff] [blame] | 40 | if (fIsOpaque && !fp->preservesOpaqueInput()) { |
| 41 | fIsOpaque = false; |
| 42 | } |
Brian Salomon | 650ced0 | 2017-07-20 16:46:46 -0400 | [diff] [blame] | 43 | if (fCompatibleWithCoverageAsAlpha && !fp->compatibleWithCoverageAsAlpha()) { |
| 44 | fCompatibleWithCoverageAsAlpha = false; |
Brian Salomon | 28207df | 2017-06-05 12:25:13 -0400 | [diff] [blame] | 45 | } |
| 46 | if (fp->usesLocalCoords()) { |
| 47 | fUsesLocalCoords = true; |
| 48 | } |
Brian Salomon | bfafcba | 2017-03-02 08:49:19 -0500 | [diff] [blame] | 49 | } |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 50 | } |
| 51 | } |