blob: a22506faad814ee444c7bc2844c8254409b39f93 [file] [log] [blame]
egdanielb6cbc382014-11-13 11:00:34 -08001/*
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 Salomona811b122017-03-30 08:21:32 -04008#include "GrProcessorAnalysis.h"
egdaniel95131432014-12-09 11:15:43 -08009#include "GrGeometryProcessor.h"
Brian Salomon89527432016-12-16 09:52:16 -050010#include "ops/GrDrawOp.h"
joshualitt74417822015-08-07 11:42:16 -070011
Brian Salomon650ced02017-07-20 16:46:46 -040012GrColorFragmentProcessorAnalysis::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;
Brian Osmancf860852018-10-31 14:04:39 -040020 fKnowOutputColor = input.isConstant(&fLastKnownOutputColor);
bsalomonac856c92015-08-27 06:30:17 -070021 for (int i = 0; i < cnt; ++i) {
Brian Salomon650ced02017-07-20 16:46:46 -040022 if (fUsesLocalCoords && !fKnowOutputColor && !fCompatibleWithCoverageAsAlpha &&
23 !fIsOpaque) {
24 break;
egdanielb6cbc382014-11-13 11:00:34 -080025 }
Brian Salomoneec6f7b2017-02-10 14:29:38 -050026 const GrFragmentProcessor* fp = processors[i];
Brian Salomon650ced02017-07-20 16:46:46 -040027 if (fKnowOutputColor &&
Brian Salomonc0b642c2017-03-27 13:09:36 -040028 fp->hasConstantOutputForConstantInput(fLastKnownOutputColor, &fLastKnownOutputColor)) {
Brian Salomon650ced02017-07-20 16:46:46 -040029 ++fProcessorsToEliminate;
Brian Osmanf28e55d2018-10-03 16:35:54 -040030 fIsOpaque = fLastKnownOutputColor.isOpaque();
Brian Salomonbfafcba2017-03-02 08:49:19 -050031 // We reset these since the caller is expected to not use the earlier fragment
32 // processors.
Brian Salomon650ced02017-07-20 16:46:46 -040033 fCompatibleWithCoverageAsAlpha = true;
Brian Salomonbfafcba2017-03-02 08:49:19 -050034 fUsesLocalCoords = false;
Brian Salomon28207df2017-06-05 12:25:13 -040035 } else {
Brian Salomon650ced02017-07-20 16:46:46 -040036 fKnowOutputColor = false;
Brian Salomon28207df2017-06-05 12:25:13 -040037 if (fIsOpaque && !fp->preservesOpaqueInput()) {
38 fIsOpaque = false;
39 }
Brian Salomon650ced02017-07-20 16:46:46 -040040 if (fCompatibleWithCoverageAsAlpha && !fp->compatibleWithCoverageAsAlpha()) {
41 fCompatibleWithCoverageAsAlpha = false;
Brian Salomon28207df2017-06-05 12:25:13 -040042 }
43 if (fp->usesLocalCoords()) {
44 fUsesLocalCoords = true;
45 }
Brian Salomonbfafcba2017-03-02 08:49:19 -050046 }
egdanielb6cbc382014-11-13 11:00:34 -080047 }
48}