blob: 2bbb54653ac0af13174786441d70d5fbd3f982e0 [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;
20 GrColor color;
21 if ((fKnowOutputColor = input.isConstant(&color))) {
22 fLastKnownOutputColor = GrColor4f::FromGrColor(color);
23 }
bsalomonac856c92015-08-27 06:30:17 -070024 for (int i = 0; i < cnt; ++i) {
Brian Salomon650ced02017-07-20 16:46:46 -040025 if (fUsesLocalCoords && !fKnowOutputColor && !fCompatibleWithCoverageAsAlpha &&
26 !fIsOpaque) {
27 break;
egdanielb6cbc382014-11-13 11:00:34 -080028 }
Brian Salomoneec6f7b2017-02-10 14:29:38 -050029 const GrFragmentProcessor* fp = processors[i];
Brian Salomon650ced02017-07-20 16:46:46 -040030 if (fKnowOutputColor &&
Brian Salomonc0b642c2017-03-27 13:09:36 -040031 fp->hasConstantOutputForConstantInput(fLastKnownOutputColor, &fLastKnownOutputColor)) {
Brian Salomon650ced02017-07-20 16:46:46 -040032 ++fProcessorsToEliminate;
Brian Salomoneec6f7b2017-02-10 14:29:38 -050033 fIsOpaque = fLastKnownOutputColor.isOpaque();
Brian Salomonbfafcba2017-03-02 08:49:19 -050034 // We reset these since the caller is expected to not use the earlier fragment
35 // processors.
Brian Salomon650ced02017-07-20 16:46:46 -040036 fCompatibleWithCoverageAsAlpha = true;
Brian Salomonbfafcba2017-03-02 08:49:19 -050037 fUsesLocalCoords = false;
Brian Salomon28207df2017-06-05 12:25:13 -040038 } else {
Brian Salomon650ced02017-07-20 16:46:46 -040039 fKnowOutputColor = false;
Brian Salomon28207df2017-06-05 12:25:13 -040040 if (fIsOpaque && !fp->preservesOpaqueInput()) {
41 fIsOpaque = false;
42 }
Brian Salomon650ced02017-07-20 16:46:46 -040043 if (fCompatibleWithCoverageAsAlpha && !fp->compatibleWithCoverageAsAlpha()) {
44 fCompatibleWithCoverageAsAlpha = false;
Brian Salomon28207df2017-06-05 12:25:13 -040045 }
46 if (fp->usesLocalCoords()) {
47 fUsesLocalCoords = true;
48 }
Brian Salomonbfafcba2017-03-02 08:49:19 -050049 }
egdanielb6cbc382014-11-13 11:00:34 -080050 }
51}