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 | |
John Stiles | e69f25f | 2021-06-03 12:23:33 -0400 | [diff] [blame^] | 8 | #include "src/gpu/GrCaps.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 9 | #include "src/gpu/GrGeometryProcessor.h" |
| 10 | #include "src/gpu/GrProcessorAnalysis.h" |
| 11 | #include "src/gpu/ops/GrDrawOp.h" |
joshualitt | 7441782 | 2015-08-07 11:42:16 -0700 | [diff] [blame] | 12 | |
Brian Salomon | 650ced0 | 2017-07-20 16:46:46 -0400 | [diff] [blame] | 13 | GrColorFragmentProcessorAnalysis::GrColorFragmentProcessorAnalysis( |
| 14 | const GrProcessorAnalysisColor& input, |
Brian Salomon | 64f4206 | 2020-02-14 10:42:45 -0500 | [diff] [blame] | 15 | std::unique_ptr<GrFragmentProcessor> const fps[], |
John Stiles | 053eb1b | 2021-06-03 12:19:39 -0400 | [diff] [blame] | 16 | int count) { |
Brian Salomon | 650ced0 | 2017-07-20 16:46:46 -0400 | [diff] [blame] | 17 | fCompatibleWithCoverageAsAlpha = true; |
| 18 | fIsOpaque = input.isOpaque(); |
| 19 | fUsesLocalCoords = false; |
John Stiles | e69f25f | 2021-06-03 12:23:33 -0400 | [diff] [blame^] | 20 | fWillReadDstColor = false; |
Brian Salomon | 650ced0 | 2017-07-20 16:46:46 -0400 | [diff] [blame] | 21 | fProcessorsToEliminate = 0; |
John Stiles | 053eb1b | 2021-06-03 12:19:39 -0400 | [diff] [blame] | 22 | fOutputColorKnown = input.isConstant(&fLastKnownOutputColor); |
| 23 | for (int i = 0; i < count; ++i) { |
| 24 | const GrFragmentProcessor* fp = fps[i].get(); |
| 25 | if (fOutputColorKnown && fp->hasConstantOutputForConstantInput(fLastKnownOutputColor, |
| 26 | &fLastKnownOutputColor)) { |
Brian Salomon | 650ced0 | 2017-07-20 16:46:46 -0400 | [diff] [blame] | 27 | ++fProcessorsToEliminate; |
Brian Osman | f28e55d | 2018-10-03 16:35:54 -0400 | [diff] [blame] | 28 | fIsOpaque = fLastKnownOutputColor.isOpaque(); |
John Stiles | 053eb1b | 2021-06-03 12:19:39 -0400 | [diff] [blame] | 29 | // We reset these flags since the earlier fragment processors are being eliminated. |
Brian Salomon | 650ced0 | 2017-07-20 16:46:46 -0400 | [diff] [blame] | 30 | fCompatibleWithCoverageAsAlpha = true; |
Brian Salomon | bfafcba | 2017-03-02 08:49:19 -0500 | [diff] [blame] | 31 | fUsesLocalCoords = false; |
John Stiles | e69f25f | 2021-06-03 12:23:33 -0400 | [diff] [blame^] | 32 | fWillReadDstColor = false; |
John Stiles | 053eb1b | 2021-06-03 12:19:39 -0400 | [diff] [blame] | 33 | continue; |
| 34 | } |
| 35 | |
| 36 | fOutputColorKnown = false; |
| 37 | if (fIsOpaque && !fp->preservesOpaqueInput()) { |
| 38 | fIsOpaque = false; |
| 39 | } |
| 40 | if (fCompatibleWithCoverageAsAlpha && !fp->compatibleWithCoverageAsAlpha()) { |
| 41 | fCompatibleWithCoverageAsAlpha = false; |
| 42 | } |
| 43 | if (fp->usesVaryingCoords()) { |
| 44 | fUsesLocalCoords = true; |
Brian Salomon | bfafcba | 2017-03-02 08:49:19 -0500 | [diff] [blame] | 45 | } |
John Stiles | e69f25f | 2021-06-03 12:23:33 -0400 | [diff] [blame^] | 46 | if (fp->willReadDstColor()) { |
| 47 | fWillReadDstColor = true; |
| 48 | } |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 49 | } |
| 50 | } |
John Stiles | e69f25f | 2021-06-03 12:23:33 -0400 | [diff] [blame^] | 51 | |
| 52 | bool GrColorFragmentProcessorAnalysis::requiresDstTexture(const GrCaps& caps) const { |
| 53 | return this->willReadDstColor() && !caps.shaderCaps()->dstReadInShaderSupport(); |
| 54 | } |