blob: bfd9e9ec8ceabd638a3e50179bdfe1aff9216348 [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);
bsalomonac856c92015-08-27 06:30:17 -070026 this->internalCalc(processors, cnt, false);
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) {
34 this->internalCalc(processors, cnt, false);
35}
36
bsalomonac856c92015-08-27 06:30:17 -070037void GrProcOptInfo::internalCalc(const GrFragmentProcessor* const processors[],
38 int cnt,
joshualitt56995b52014-12-11 15:44:02 -080039 bool initWillReadFragmentPosition) {
bsalomonac856c92015-08-27 06:30:17 -070040 fFirstEffectiveProcessorIndex = 0;
egdanielb6cbc382014-11-13 11:00:34 -080041 fInputColorIsUsed = true;
joshualitt56995b52014-12-11 15:44:02 -080042 fInputColor = fInOut.color();
joshualitt56995b52014-12-11 15:44:02 -080043 fReadsFragPosition = initWillReadFragmentPosition;
egdanielb6cbc382014-11-13 11:00:34 -080044
bsalomonac856c92015-08-27 06:30:17 -070045 for (int i = 0; i < cnt; ++i) {
46 const GrFragmentProcessor* processor = processors[i];
egdanielb6cbc382014-11-13 11:00:34 -080047 fInOut.resetWillUseInputColor();
48 processor->computeInvariantOutput(&fInOut);
joshualitt56995b52014-12-11 15:44:02 -080049 SkDEBUGCODE(fInOut.validate());
egdanielb6cbc382014-11-13 11:00:34 -080050 if (!fInOut.willUseInputColor()) {
bsalomonac856c92015-08-27 06:30:17 -070051 fFirstEffectiveProcessorIndex = i;
egdanielb6cbc382014-11-13 11:00:34 -080052 fInputColorIsUsed = false;
egdaniel95131432014-12-09 11:15:43 -080053 // Reset these since we don't care if previous stages read these values
joshualitt56995b52014-12-11 15:44:02 -080054 fReadsFragPosition = initWillReadFragmentPosition;
egdanielb6cbc382014-11-13 11:00:34 -080055 }
egdaniel95131432014-12-09 11:15:43 -080056 if (processor->willReadFragmentPosition()) {
57 fReadsFragPosition = true;
58 }
egdanielb6cbc382014-11-13 11:00:34 -080059 if (kRGBA_GrColorComponentFlags == fInOut.validFlags()) {
bsalomonac856c92015-08-27 06:30:17 -070060 fFirstEffectiveProcessorIndex = i + 1;
egdanielb6cbc382014-11-13 11:00:34 -080061 fInputColor = fInOut.color();
62 fInputColorIsUsed = true;
egdanielb6cbc382014-11-13 11:00:34 -080063 // Since we are clearing all previous color stages we are in a state where we have found
64 // zero stages that don't multiply the inputColor.
65 fInOut.resetNonMulStageFound();
egdaniel95131432014-12-09 11:15:43 -080066 // Reset these since we don't care if previous stages read these values
joshualitt56995b52014-12-11 15:44:02 -080067 fReadsFragPosition = initWillReadFragmentPosition;
egdanielb6cbc382014-11-13 11:00:34 -080068 }
69 }
70}