blob: 5e612546d421485bcc3b462ffbf03c6b5bcf5f96 [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
8#include "GrProcOptInfo.h"
9
egdaniel95131432014-12-09 11:15:43 -080010#include "GrGeometryProcessor.h"
egdanielb6cbc382014-11-13 11:00:34 -080011
Brian Salomon89527432016-12-16 09:52:16 -050012#include "ops/GrDrawOp.h"
joshualitt74417822015-08-07 11:42:16 -070013
bsalomonac856c92015-08-27 06:30:17 -070014void GrProcOptInfo::calcWithInitialValues(const GrFragmentProcessor * const processors[],
15 int cnt,
egdanielb6cbc382014-11-13 11:00:34 -080016 GrColor startColor,
17 GrColorComponentFlags flags,
egdaniel723b0502015-09-15 09:31:40 -070018 bool areCoverageStages,
19 bool isLCD) {
Brian Salomon92aee3d2016-12-21 09:20:25 -050020 GrPipelineInput out;
joshualitt56995b52014-12-11 15:44:02 -080021 out.fIsSingleComponent = areCoverageStages;
22 out.fColor = startColor;
23 out.fValidFlags = flags;
egdaniel723b0502015-09-15 09:31:40 -070024 out.fIsLCDCoverage = isLCD;
joshualitt56995b52014-12-11 15:44:02 -080025 fInOut.reset(out);
cdalton87332102016-02-26 12:22:02 -080026 this->internalCalc(processors, cnt);
joshualitt56995b52014-12-11 15:44:02 -080027}
28
ethannicholasff210322015-11-24 12:10:10 -080029void GrProcOptInfo::completeCalculations(const GrFragmentProcessor * const processors[], int cnt) {
cdalton87332102016-02-26 12:22:02 -080030 this->internalCalc(processors, cnt);
ethannicholasff210322015-11-24 12:10:10 -080031}
32
cdalton87332102016-02-26 12:22:02 -080033void GrProcOptInfo::internalCalc(const GrFragmentProcessor* const processors[], int cnt) {
bsalomonac856c92015-08-27 06:30:17 -070034 fFirstEffectiveProcessorIndex = 0;
egdanielb6cbc382014-11-13 11:00:34 -080035 fInputColorIsUsed = true;
joshualitt56995b52014-12-11 15:44:02 -080036 fInputColor = fInOut.color();
egdanielb6cbc382014-11-13 11:00:34 -080037
bsalomonac856c92015-08-27 06:30:17 -070038 for (int i = 0; i < cnt; ++i) {
39 const GrFragmentProcessor* processor = processors[i];
egdanielb6cbc382014-11-13 11:00:34 -080040 fInOut.resetWillUseInputColor();
41 processor->computeInvariantOutput(&fInOut);
joshualitt56995b52014-12-11 15:44:02 -080042 SkDEBUGCODE(fInOut.validate());
egdanielb6cbc382014-11-13 11:00:34 -080043 if (!fInOut.willUseInputColor()) {
bsalomonac856c92015-08-27 06:30:17 -070044 fFirstEffectiveProcessorIndex = i;
egdanielb6cbc382014-11-13 11:00:34 -080045 fInputColorIsUsed = false;
egdaniel95131432014-12-09 11:15:43 -080046 }
egdanielb6cbc382014-11-13 11:00:34 -080047 if (kRGBA_GrColorComponentFlags == fInOut.validFlags()) {
bsalomonac856c92015-08-27 06:30:17 -070048 fFirstEffectiveProcessorIndex = i + 1;
egdanielb6cbc382014-11-13 11:00:34 -080049 fInputColor = fInOut.color();
50 fInputColorIsUsed = true;
egdanielb6cbc382014-11-13 11:00:34 -080051 // Since we are clearing all previous color stages we are in a state where we have found
52 // zero stages that don't multiply the inputColor.
53 fInOut.resetNonMulStageFound();
egdanielb6cbc382014-11-13 11:00:34 -080054 }
55 }
56}