blob: a84ac2e17fb45dcfb2a9f556b2a628dd68bcf53f [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
egdaniel7c663422014-12-08 11:20:39 -080010#include "GrFragmentProcessor.h"
bsalomonae59b772014-11-19 08:23:49 -080011#include "GrFragmentStage.h"
egdaniel7c663422014-12-08 11:20:39 -080012#include "GrGeometryProcessor.h"
egdanielb6cbc382014-11-13 11:00:34 -080013
14void GrProcOptInfo::calcWithInitialValues(const GrFragmentStage* stages,
15 int stageCount,
16 GrColor startColor,
17 GrColorComponentFlags flags,
18 bool areCoverageStages,
19 const GrGeometryProcessor* gp) {
20 fInOut.reset(startColor, flags, areCoverageStages);
21 fFirstEffectStageIndex = 0;
22 fInputColorIsUsed = true;
23 fInputColor = startColor;
24 fRemoveVertexAttrib = false;
25 fReadsDst = false;
egdaniel7c663422014-12-08 11:20:39 -080026 fReadsFragPosition = false;
egdanielb6cbc382014-11-13 11:00:34 -080027
28 if (areCoverageStages && gp) {
29 gp->computeInvariantOutput(&fInOut);
30 }
31
32 for (int i = 0; i < stageCount; ++i) {
33 const GrFragmentProcessor* processor = stages[i].getProcessor();
34 fInOut.resetWillUseInputColor();
35 processor->computeInvariantOutput(&fInOut);
egdaniel7c663422014-12-08 11:20:39 -080036#ifdef SK_DEBUG
egdanielb6cbc382014-11-13 11:00:34 -080037 fInOut.validate();
egdaniel7c663422014-12-08 11:20:39 -080038#endif
egdanielb6cbc382014-11-13 11:00:34 -080039 if (!fInOut.willUseInputColor()) {
40 fFirstEffectStageIndex = i;
41 fInputColorIsUsed = false;
egdaniel7c663422014-12-08 11:20:39 -080042 // Reset these since we don't care if previous stages read these values
43 fReadsDst = false;
44 fReadsFragPosition = false;
egdanielb6cbc382014-11-13 11:00:34 -080045 }
46 if (processor->willReadDstColor()) {
47 fReadsDst = true;
48 }
egdaniel7c663422014-12-08 11:20:39 -080049 if (processor->willReadFragmentPosition()) {
50 fReadsFragPosition = true;
51 }
egdanielb6cbc382014-11-13 11:00:34 -080052 if (kRGBA_GrColorComponentFlags == fInOut.validFlags()) {
53 fFirstEffectStageIndex = i + 1;
54 fInputColor = fInOut.color();
55 fInputColorIsUsed = true;
56 fRemoveVertexAttrib = true;
57 // Since we are clearing all previous color stages we are in a state where we have found
58 // zero stages that don't multiply the inputColor.
59 fInOut.resetNonMulStageFound();
egdaniel7c663422014-12-08 11:20:39 -080060 // Reset these since we don't care if previous stages read these values
61 fReadsDst = false;
62 fReadsFragPosition = false;
egdanielb6cbc382014-11-13 11:00:34 -080063 }
64 }
65}
egdaniel7c663422014-12-08 11:20:39 -080066