blob: 72285e6c227913a18e4ae156b8b9f1b7b90b8e1f [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
John Stilese69f25f2021-06-03 12:23:33 -04008#include "src/gpu/GrCaps.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -05009#include "src/gpu/GrGeometryProcessor.h"
10#include "src/gpu/GrProcessorAnalysis.h"
11#include "src/gpu/ops/GrDrawOp.h"
joshualitt74417822015-08-07 11:42:16 -070012
Brian Salomon650ced02017-07-20 16:46:46 -040013GrColorFragmentProcessorAnalysis::GrColorFragmentProcessorAnalysis(
14 const GrProcessorAnalysisColor& input,
Brian Salomon64f42062020-02-14 10:42:45 -050015 std::unique_ptr<GrFragmentProcessor> const fps[],
John Stiles053eb1b2021-06-03 12:19:39 -040016 int count) {
Brian Salomon650ced02017-07-20 16:46:46 -040017 fCompatibleWithCoverageAsAlpha = true;
18 fIsOpaque = input.isOpaque();
19 fUsesLocalCoords = false;
John Stilese69f25f2021-06-03 12:23:33 -040020 fWillReadDstColor = false;
Brian Salomon650ced02017-07-20 16:46:46 -040021 fProcessorsToEliminate = 0;
John Stiles053eb1b2021-06-03 12:19:39 -040022 fOutputColorKnown = input.isConstant(&fLastKnownOutputColor);
23 for (int i = 0; i < count; ++i) {
24 const GrFragmentProcessor* fp = fps[i].get();
25 if (fOutputColorKnown && fp->hasConstantOutputForConstantInput(fLastKnownOutputColor,
26 &fLastKnownOutputColor)) {
Brian Salomon650ced02017-07-20 16:46:46 -040027 ++fProcessorsToEliminate;
Brian Osmanf28e55d2018-10-03 16:35:54 -040028 fIsOpaque = fLastKnownOutputColor.isOpaque();
John Stiles053eb1b2021-06-03 12:19:39 -040029 // We reset these flags since the earlier fragment processors are being eliminated.
Brian Salomon650ced02017-07-20 16:46:46 -040030 fCompatibleWithCoverageAsAlpha = true;
Brian Salomonbfafcba2017-03-02 08:49:19 -050031 fUsesLocalCoords = false;
John Stilese69f25f2021-06-03 12:23:33 -040032 fWillReadDstColor = false;
John Stiles053eb1b2021-06-03 12:19:39 -040033 continue;
34 }
35
36 fOutputColorKnown = false;
37 if (fIsOpaque && !fp->preservesOpaqueInput()) {
38 fIsOpaque = false;
39 }
40 if (fCompatibleWithCoverageAsAlpha && !fp->compatibleWithCoverageAsAlpha()) {
41 fCompatibleWithCoverageAsAlpha = false;
42 }
43 if (fp->usesVaryingCoords()) {
44 fUsesLocalCoords = true;
Brian Salomonbfafcba2017-03-02 08:49:19 -050045 }
John Stilese69f25f2021-06-03 12:23:33 -040046 if (fp->willReadDstColor()) {
47 fWillReadDstColor = true;
48 }
egdanielb6cbc382014-11-13 11:00:34 -080049 }
50}
John Stilese69f25f2021-06-03 12:23:33 -040051
52bool GrColorFragmentProcessorAnalysis::requiresDstTexture(const GrCaps& caps) const {
53 return this->willReadDstColor() && !caps.shaderCaps()->dstReadInShaderSupport();
54}