blob: 317246d247644808bc7bde6f85b04853d81662d7 [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 Salomonc0b642c2017-03-27 13:09:36 -040012void GrColorFragmentProcessorAnalysis::analyzeProcessors(
13 const GrFragmentProcessor* const* processors, int cnt) {
bsalomonac856c92015-08-27 06:30:17 -070014 for (int i = 0; i < cnt; ++i) {
Brian Salomoneec6f7b2017-02-10 14:29:38 -050015 bool knowCurrentOutput = fProcessorsVisitedWithKnownOutput == fTotalProcessorsVisited;
Brian Salomonbfafcba2017-03-02 08:49:19 -050016 if (fUsesLocalCoords && !knowCurrentOutput &&
17 !fAllProcessorsCompatibleWithCoverageAsAlpha && !fIsOpaque) {
Brian Salomoneec6f7b2017-02-10 14:29:38 -050018 fTotalProcessorsVisited += cnt - i;
19 return;
egdanielb6cbc382014-11-13 11:00:34 -080020 }
Brian Salomoneec6f7b2017-02-10 14:29:38 -050021 const GrFragmentProcessor* fp = processors[i];
Brian Salomonc0b642c2017-03-27 13:09:36 -040022 if (knowCurrentOutput &&
23 fp->hasConstantOutputForConstantInput(fLastKnownOutputColor, &fLastKnownOutputColor)) {
Brian Salomoneec6f7b2017-02-10 14:29:38 -050024 ++fProcessorsVisitedWithKnownOutput;
25 fIsOpaque = fLastKnownOutputColor.isOpaque();
Brian Salomonbfafcba2017-03-02 08:49:19 -050026 // We reset these since the caller is expected to not use the earlier fragment
27 // processors.
28 fAllProcessorsCompatibleWithCoverageAsAlpha = true;
29 fUsesLocalCoords = false;
Brian Salomoneec6f7b2017-02-10 14:29:38 -050030 } else if (fIsOpaque && !fp->preservesOpaqueInput()) {
31 fIsOpaque = false;
32 }
Brian Salomonf3b995b2017-02-15 10:22:23 -050033 if (fAllProcessorsCompatibleWithCoverageAsAlpha && !fp->compatibleWithCoverageAsAlpha()) {
34 fAllProcessorsCompatibleWithCoverageAsAlpha = false;
Brian Salomoneec6f7b2017-02-10 14:29:38 -050035 }
Brian Salomonbfafcba2017-03-02 08:49:19 -050036 if (fp->usesLocalCoords()) {
37 fUsesLocalCoords = true;
38 }
Brian Salomoneec6f7b2017-02-10 14:29:38 -050039 ++fTotalProcessorsVisited;
egdanielb6cbc382014-11-13 11:00:34 -080040 }
41}