blob: 274c5305de3b17ef5c8747a5f5bc8caac0a0fed6 [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();
egdanielb6cbc382014-11-13 11:00:34 -080051 fReadsDst = false;
joshualitt56995b52014-12-11 15:44:02 -080052 fReadsFragPosition = initWillReadFragmentPosition;
egdanielb6cbc382014-11-13 11:00:34 -080053
54 for (int i = 0; i < stageCount; ++i) {
joshualitt40d4bd82014-12-29 09:04:40 -080055 const GrFragmentProcessor* processor = stages[i].processor();
egdanielb6cbc382014-11-13 11:00:34 -080056 fInOut.resetWillUseInputColor();
57 processor->computeInvariantOutput(&fInOut);
joshualitt56995b52014-12-11 15:44:02 -080058 SkDEBUGCODE(fInOut.validate());
egdanielb6cbc382014-11-13 11:00:34 -080059 if (!fInOut.willUseInputColor()) {
60 fFirstEffectStageIndex = i;
61 fInputColorIsUsed = false;
egdaniel95131432014-12-09 11:15:43 -080062 // Reset these since we don't care if previous stages read these values
63 fReadsDst = false;
joshualitt56995b52014-12-11 15:44:02 -080064 fReadsFragPosition = initWillReadFragmentPosition;
egdanielb6cbc382014-11-13 11:00:34 -080065 }
66 if (processor->willReadDstColor()) {
67 fReadsDst = true;
68 }
egdaniel95131432014-12-09 11:15:43 -080069 if (processor->willReadFragmentPosition()) {
70 fReadsFragPosition = true;
71 }
egdanielb6cbc382014-11-13 11:00:34 -080072 if (kRGBA_GrColorComponentFlags == fInOut.validFlags()) {
73 fFirstEffectStageIndex = i + 1;
74 fInputColor = fInOut.color();
75 fInputColorIsUsed = true;
egdanielb6cbc382014-11-13 11:00:34 -080076 // Since we are clearing all previous color stages we are in a state where we have found
77 // zero stages that don't multiply the inputColor.
78 fInOut.resetNonMulStageFound();
egdaniel95131432014-12-09 11:15:43 -080079 // Reset these since we don't care if previous stages read these values
80 fReadsDst = false;
joshualitt56995b52014-12-11 15:44:02 -080081 fReadsFragPosition = initWillReadFragmentPosition;
egdanielb6cbc382014-11-13 11:00:34 -080082 }
83 }
84}