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
8#include "src/gpu/GrGeometryProcessor.h"
9#include "src/gpu/GrProcessorAnalysis.h"
10#include "src/gpu/ops/GrDrawOp.h"
11
12GrColorFragmentProcessorAnalysis::GrColorFragmentProcessorAnalysis(
13 const GrProcessorAnalysisColor& input,
14 std::unique_ptr<GrFragmentProcessor> const fps[],
15 int cnt) {
16 fCompatibleWithCoverageAsAlpha = true;
17 fIsOpaque = input.isOpaque();
18 fUsesLocalCoords = false;
19 fProcessorsToEliminate = 0;
20 fKnowOutputColor = input.isConstant(&fLastKnownOutputColor);
21 for (int i = 0; i < cnt; ++i) {
22 if (fUsesLocalCoords && !fKnowOutputColor && !fCompatibleWithCoverageAsAlpha &&
23 !fIsOpaque) {
24 break;
25 }
26 const auto& fp = fps[i];
27 if (fKnowOutputColor &&
28 fp->hasConstantOutputForConstantInput(fLastKnownOutputColor, &fLastKnownOutputColor)) {
29 ++fProcessorsToEliminate;
30 fIsOpaque = fLastKnownOutputColor.isOpaque();
31 // We reset these since the caller is expected to not use the earlier fragment
32 // processors.
33 fCompatibleWithCoverageAsAlpha = true;
34 fUsesLocalCoords = false;
35 } else {
36 fKnowOutputColor = false;
37 if (fIsOpaque && !fp->preservesOpaqueInput()) {
38 fIsOpaque = false;
39 }
40 if (fCompatibleWithCoverageAsAlpha && !fp->compatibleWithCoverageAsAlpha()) {
41 fCompatibleWithCoverageAsAlpha = false;
42 }
43 if (fp->usesLocalCoords()) {
44 fUsesLocalCoords = true;
45 }
46 }
47 }
48}
49