blob: a350ef783dbe9fbe37c2437b394c8784c003f345 [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 "GrFragmentProcessor.h"
egdaniel8d95ffa2014-12-08 13:26:43 -080011#include "GrFragmentStage.h"
egdaniel95131432014-12-09 11:15:43 -080012#include "GrGeometryProcessor.h"
egdanielb6cbc382014-11-13 11:00:34 -080013
joshualitt56995b52014-12-11 15:44:02 -080014void GrProcOptInfo::calcColorWithPrimProc(const GrPrimitiveProcessor* primProc,
15 const GrFragmentStage* stages,
16 int stageCount) {
17 GrInitInvariantOutput out;
18 primProc->getInvariantOutputColor(&out);
19 fInOut.reset(out);
20 this->internalCalc(stages, stageCount, primProc->willReadFragmentPosition());
21}
22
23void GrProcOptInfo::calcCoverageWithPrimProc(const GrPrimitiveProcessor* primProc,
24 const GrFragmentStage* stages,
25 int stageCount) {
26 GrInitInvariantOutput out;
27 primProc->getInvariantOutputCoverage(&out);
28 fInOut.reset(out);
29 this->internalCalc(stages, stageCount, primProc->willReadFragmentPosition());
30}
31
egdanielb6cbc382014-11-13 11:00:34 -080032void GrProcOptInfo::calcWithInitialValues(const GrFragmentStage* stages,
33 int stageCount,
34 GrColor startColor,
35 GrColorComponentFlags flags,
joshualitt56995b52014-12-11 15:44:02 -080036 bool areCoverageStages) {
37 GrInitInvariantOutput out;
38 out.fIsSingleComponent = areCoverageStages;
39 out.fColor = startColor;
40 out.fValidFlags = flags;
41 fInOut.reset(out);
42 this->internalCalc(stages, stageCount, false);
43}
44
45void GrProcOptInfo::internalCalc(const GrFragmentStage* stages,
46 int stageCount,
47 bool initWillReadFragmentPosition) {
egdanielb6cbc382014-11-13 11:00:34 -080048 fFirstEffectStageIndex = 0;
49 fInputColorIsUsed = true;
joshualitt56995b52014-12-11 15:44:02 -080050 fInputColor = fInOut.color();
joshualitt56995b52014-12-11 15:44:02 -080051 fReadsFragPosition = initWillReadFragmentPosition;
egdanielb6cbc382014-11-13 11:00:34 -080052
53 for (int i = 0; i < stageCount; ++i) {
joshualitt40d4bd82014-12-29 09:04:40 -080054 const GrFragmentProcessor* processor = stages[i].processor();
egdanielb6cbc382014-11-13 11:00:34 -080055 fInOut.resetWillUseInputColor();
56 processor->computeInvariantOutput(&fInOut);
joshualitt56995b52014-12-11 15:44:02 -080057 SkDEBUGCODE(fInOut.validate());
egdanielb6cbc382014-11-13 11:00:34 -080058 if (!fInOut.willUseInputColor()) {
59 fFirstEffectStageIndex = i;
60 fInputColorIsUsed = false;
egdaniel95131432014-12-09 11:15:43 -080061 // Reset these since we don't care if previous stages read these values
joshualitt56995b52014-12-11 15:44:02 -080062 fReadsFragPosition = initWillReadFragmentPosition;
egdanielb6cbc382014-11-13 11:00:34 -080063 }
egdaniel95131432014-12-09 11:15:43 -080064 if (processor->willReadFragmentPosition()) {
65 fReadsFragPosition = true;
66 }
egdanielb6cbc382014-11-13 11:00:34 -080067 if (kRGBA_GrColorComponentFlags == fInOut.validFlags()) {
68 fFirstEffectStageIndex = i + 1;
69 fInputColor = fInOut.color();
70 fInputColorIsUsed = true;
egdanielb6cbc382014-11-13 11:00:34 -080071 // Since we are clearing all previous color stages we are in a state where we have found
72 // zero stages that don't multiply the inputColor.
73 fInOut.resetNonMulStageFound();
egdaniel95131432014-12-09 11:15:43 -080074 // Reset these since we don't care if previous stages read these values
joshualitt56995b52014-12-11 15:44:02 -080075 fReadsFragPosition = initWillReadFragmentPosition;
egdanielb6cbc382014-11-13 11:00:34 -080076 }
77 }
78}