blob: dc499fa337d2a31e3e1c9b114f8443e49c68519a [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
joshualittd5a7db42015-01-27 15:39:06 -080010#include "GrBatch.h"
egdaniel95131432014-12-09 11:15:43 -080011#include "GrFragmentProcessor.h"
egdaniel8d95ffa2014-12-08 13:26:43 -080012#include "GrFragmentStage.h"
egdaniel95131432014-12-09 11:15:43 -080013#include "GrGeometryProcessor.h"
egdanielb6cbc382014-11-13 11:00:34 -080014
joshualittd5a7db42015-01-27 15:39:06 -080015void GrProcOptInfo::calcColorWithBatch(const GrBatch* batch,
16 const GrFragmentStage* stages,
17 int stageCount) {
18 GrInitInvariantOutput out;
19 batch->getInvariantOutputColor(&out);
20 fInOut.reset(out);
21 this->internalCalc(stages, stageCount, batch->willReadFragmentPosition());
22}
23
24void GrProcOptInfo::calcCoverageWithBatch(const GrBatch* batch,
25 const GrFragmentStage* stages,
26 int stageCount) {
27 GrInitInvariantOutput out;
28 batch->getInvariantOutputCoverage(&out);
29 fInOut.reset(out);
30 this->internalCalc(stages, stageCount, batch->willReadFragmentPosition());
31}
32
joshualitt56995b52014-12-11 15:44:02 -080033void GrProcOptInfo::calcColorWithPrimProc(const GrPrimitiveProcessor* primProc,
34 const GrFragmentStage* stages,
35 int stageCount) {
36 GrInitInvariantOutput out;
37 primProc->getInvariantOutputColor(&out);
38 fInOut.reset(out);
39 this->internalCalc(stages, stageCount, primProc->willReadFragmentPosition());
40}
41
42void GrProcOptInfo::calcCoverageWithPrimProc(const GrPrimitiveProcessor* primProc,
43 const GrFragmentStage* stages,
44 int stageCount) {
45 GrInitInvariantOutput out;
46 primProc->getInvariantOutputCoverage(&out);
47 fInOut.reset(out);
48 this->internalCalc(stages, stageCount, primProc->willReadFragmentPosition());
49}
50
egdanielb6cbc382014-11-13 11:00:34 -080051void GrProcOptInfo::calcWithInitialValues(const GrFragmentStage* stages,
52 int stageCount,
53 GrColor startColor,
54 GrColorComponentFlags flags,
joshualitt56995b52014-12-11 15:44:02 -080055 bool areCoverageStages) {
56 GrInitInvariantOutput out;
57 out.fIsSingleComponent = areCoverageStages;
58 out.fColor = startColor;
59 out.fValidFlags = flags;
60 fInOut.reset(out);
61 this->internalCalc(stages, stageCount, false);
62}
63
64void GrProcOptInfo::internalCalc(const GrFragmentStage* stages,
65 int stageCount,
66 bool initWillReadFragmentPosition) {
egdanielb6cbc382014-11-13 11:00:34 -080067 fFirstEffectStageIndex = 0;
68 fInputColorIsUsed = true;
joshualitt56995b52014-12-11 15:44:02 -080069 fInputColor = fInOut.color();
joshualitt56995b52014-12-11 15:44:02 -080070 fReadsFragPosition = initWillReadFragmentPosition;
egdanielb6cbc382014-11-13 11:00:34 -080071
72 for (int i = 0; i < stageCount; ++i) {
joshualitt40d4bd82014-12-29 09:04:40 -080073 const GrFragmentProcessor* processor = stages[i].processor();
egdanielb6cbc382014-11-13 11:00:34 -080074 fInOut.resetWillUseInputColor();
75 processor->computeInvariantOutput(&fInOut);
joshualitt56995b52014-12-11 15:44:02 -080076 SkDEBUGCODE(fInOut.validate());
egdanielb6cbc382014-11-13 11:00:34 -080077 if (!fInOut.willUseInputColor()) {
78 fFirstEffectStageIndex = i;
79 fInputColorIsUsed = false;
egdaniel95131432014-12-09 11:15:43 -080080 // Reset these since we don't care if previous stages read these values
joshualitt56995b52014-12-11 15:44:02 -080081 fReadsFragPosition = initWillReadFragmentPosition;
egdanielb6cbc382014-11-13 11:00:34 -080082 }
egdaniel95131432014-12-09 11:15:43 -080083 if (processor->willReadFragmentPosition()) {
84 fReadsFragPosition = true;
85 }
egdanielb6cbc382014-11-13 11:00:34 -080086 if (kRGBA_GrColorComponentFlags == fInOut.validFlags()) {
87 fFirstEffectStageIndex = i + 1;
88 fInputColor = fInOut.color();
89 fInputColorIsUsed = true;
egdanielb6cbc382014-11-13 11:00:34 -080090 // Since we are clearing all previous color stages we are in a state where we have found
91 // zero stages that don't multiply the inputColor.
92 fInOut.resetNonMulStageFound();
egdaniel95131432014-12-09 11:15:43 -080093 // Reset these since we don't care if previous stages read these values
joshualitt56995b52014-12-11 15:44:02 -080094 fReadsFragPosition = initWillReadFragmentPosition;
egdanielb6cbc382014-11-13 11:00:34 -080095 }
96 }
97}