blob: df3f4260e6a698d7b5f1079e5aadba6cac475db0 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "src/gpu/GrGeometryProcessor.h"
9#include "src/gpu/GrProcessorAnalysis.h"
10#include "src/gpu/ops/GrDrawOp.h"
joshualitt74417822015-08-07 11:42:16 -070011
Brian Salomon650ced02017-07-20 16:46:46 -040012GrColorFragmentProcessorAnalysis::GrColorFragmentProcessorAnalysis(
13 const GrProcessorAnalysisColor& input,
Brian Salomon64f42062020-02-14 10:42:45 -050014 std::unique_ptr<GrFragmentProcessor> const fps[],
Brian Salomon650ced02017-07-20 16:46:46 -040015 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 Salomon64f42062020-02-14 10:42:45 -050026 const auto& fp = fps[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 }
Brian Osman9cf98dc2020-07-01 17:21:27 -040043 if (fp->usesVaryingCoords()) {
Brian Salomon28207df2017-06-05 12:25:13 -040044 fUsesLocalCoords = true;
45 }
Brian Salomonbfafcba2017-03-02 08:49:19 -050046 }
egdanielb6cbc382014-11-13 11:00:34 -080047 }
48}