blob: 183a42fb33e17c9153fe64b4c5bf26d21e09e442 [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
bsalomon16b99132015-08-13 14:55:50 -070012#include "batches/GrDrawBatch.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) {
joshualitt56995b52014-12-11 15:44:02 -080020 GrInitInvariantOutput out;
21 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::initUsingInvariantOutput(GrInitInvariantOutput invOutput) {
30 fInOut.reset(invOutput);
31}
32
33void GrProcOptInfo::completeCalculations(const GrFragmentProcessor * const processors[], int cnt) {
cdalton87332102016-02-26 12:22:02 -080034 this->internalCalc(processors, cnt);
ethannicholasff210322015-11-24 12:10:10 -080035}
36
cdalton87332102016-02-26 12:22:02 -080037void GrProcOptInfo::internalCalc(const GrFragmentProcessor* const processors[], int cnt) {
bsalomonac856c92015-08-27 06:30:17 -070038 fFirstEffectiveProcessorIndex = 0;
egdanielb6cbc382014-11-13 11:00:34 -080039 fInputColorIsUsed = true;
joshualitt56995b52014-12-11 15:44:02 -080040 fInputColor = fInOut.color();
egdanielb6cbc382014-11-13 11:00:34 -080041
bsalomonac856c92015-08-27 06:30:17 -070042 for (int i = 0; i < cnt; ++i) {
43 const GrFragmentProcessor* processor = processors[i];
egdanielb6cbc382014-11-13 11:00:34 -080044 fInOut.resetWillUseInputColor();
45 processor->computeInvariantOutput(&fInOut);
joshualitt56995b52014-12-11 15:44:02 -080046 SkDEBUGCODE(fInOut.validate());
egdanielb6cbc382014-11-13 11:00:34 -080047 if (!fInOut.willUseInputColor()) {
bsalomonac856c92015-08-27 06:30:17 -070048 fFirstEffectiveProcessorIndex = i;
egdanielb6cbc382014-11-13 11:00:34 -080049 fInputColorIsUsed = false;
egdaniel95131432014-12-09 11:15:43 -080050 }
egdanielb6cbc382014-11-13 11:00:34 -080051 if (kRGBA_GrColorComponentFlags == fInOut.validFlags()) {
bsalomonac856c92015-08-27 06:30:17 -070052 fFirstEffectiveProcessorIndex = i + 1;
egdanielb6cbc382014-11-13 11:00:34 -080053 fInputColor = fInOut.color();
54 fInputColorIsUsed = true;
egdanielb6cbc382014-11-13 11:00:34 -080055 // Since we are clearing all previous color stages we are in a state where we have found
56 // zero stages that don't multiply the inputColor.
57 fInOut.resetNonMulStageFound();
egdanielb6cbc382014-11-13 11:00:34 -080058 }
59 }
60}