OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "GrPipeline.h" | 8 #include "GrPipeline.h" |
9 | 9 |
10 #include "GrCaps.h" | 10 #include "GrCaps.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 // Create XferProcessor from DS's XPFactory | 22 // Create XferProcessor from DS's XPFactory |
23 SkAutoTUnref<GrXferProcessor> xferProcessor( | 23 SkAutoTUnref<GrXferProcessor> xferProcessor( |
24 builder.getXPFactory()->createXferProcessor(args.fColorPOI, args.fCovera
gePOI, | 24 builder.getXPFactory()->createXferProcessor(args.fColorPOI, args.fCovera
gePOI, |
25 builder.hasMixedSamples(), &
args.fDstTexture, | 25 builder.hasMixedSamples(), &
args.fDstTexture, |
26 *args.fCaps)); | 26 *args.fCaps)); |
27 if (!xferProcessor) { | 27 if (!xferProcessor) { |
28 return nullptr; | 28 return nullptr; |
29 } | 29 } |
30 | 30 |
31 GrColor overrideColor = GrColor_ILLEGAL; | 31 GrColor overrideColor = GrColor_ILLEGAL; |
32 if (args.fColorPOI.firstEffectiveStageIndex() != 0) { | 32 if (args.fColorPOI.firstEffectiveProcessorIndex() != 0) { |
33 overrideColor = args.fColorPOI.inputColorToEffectiveStage(); | 33 overrideColor = args.fColorPOI.inputColorToFirstEffectiveProccesor(); |
34 } | 34 } |
35 | 35 |
36 GrXferProcessor::OptFlags optFlags = GrXferProcessor::kNone_OptFlags; | 36 GrXferProcessor::OptFlags optFlags = GrXferProcessor::kNone_OptFlags; |
37 | 37 |
38 optFlags = xferProcessor->getOptimizations(args.fColorPOI, | 38 optFlags = xferProcessor->getOptimizations(args.fColorPOI, |
39 args.fCoveragePOI, | 39 args.fCoveragePOI, |
40 builder.getStencil().doesWrite()
, | 40 builder.getStencil().doesWrite()
, |
41 &overrideColor, | 41 &overrideColor, |
42 *args.fCaps); | 42 *args.fCaps); |
43 | 43 |
(...skipping 22 matching lines...) Expand all Loading... |
66 if (builder.isHWAntialias()) { | 66 if (builder.isHWAntialias()) { |
67 pipeline->fFlags |= kHWAA_Flag; | 67 pipeline->fFlags |= kHWAA_Flag; |
68 } | 68 } |
69 if (builder.isDither()) { | 69 if (builder.isDither()) { |
70 pipeline->fFlags |= kDither_Flag; | 70 pipeline->fFlags |= kDither_Flag; |
71 } | 71 } |
72 if (builder.snapVerticesToPixelCenters()) { | 72 if (builder.snapVerticesToPixelCenters()) { |
73 pipeline->fFlags |= kSnapVertices_Flag; | 73 pipeline->fFlags |= kSnapVertices_Flag; |
74 } | 74 } |
75 | 75 |
76 int firstColorStageIdx = args.fColorPOI.firstEffectiveStageIndex(); | 76 int firstColorProcessorIdx = args.fColorPOI.firstEffectiveProcessorIndex(); |
77 | 77 |
78 // TODO: Once we can handle single or four channel input into coverage stage
s then we can use | 78 // TODO: Once we can handle single or four channel input into coverage GrFra
gmentProcessors |
79 // GrPipelineBuilder's coverageProcInfo (like color above) to set this initi
al information. | 79 // then we can use GrPipelineBuilder's coverageProcInfo (like color above) t
o set this initial |
80 int firstCoverageStageIdx = 0; | 80 // information. |
| 81 int firstCoverageProcessorIdx = 0; |
81 | 82 |
82 pipeline->adjustProgramFromOptimizations(builder, optFlags, args.fColorPOI,
args.fCoveragePOI, | 83 pipeline->adjustProgramFromOptimizations(builder, optFlags, args.fColorPOI,
args.fCoveragePOI, |
83 &firstColorStageIdx, &firstCoverage
StageIdx); | 84 &firstColorProcessorIdx, &firstCove
rageProcessorIdx); |
84 | 85 |
85 bool usesLocalCoords = false; | 86 bool usesLocalCoords = false; |
86 | 87 |
87 // Copy Stages from PipelineBuilder to Pipeline | 88 // Copy GrFragmentProcessors from GrPipelineBuilder to Pipeline |
88 for (int i = firstColorStageIdx; i < builder.numColorFragmentStages(); ++i)
{ | 89 pipeline->fNumColorProcessors = builder.numColorFragmentProcessors() - first
ColorProcessorIdx; |
89 const GrFragmentStage& fps = builder.fColorStages[i]; | 90 int numTotalProcessors = pipeline->fNumColorProcessors + |
90 const GrFragmentProcessor* fp = fps.processor(); | 91 builder.numCoverageFragmentProcessors() - firstCove
rageProcessorIdx; |
91 SkNEW_APPEND_TO_TARRAY(&pipeline->fFragmentStages, GrPendingFragmentStag
e, (fps)); | 92 pipeline->fFragmentProcessors.reset(numTotalProcessors); |
| 93 int currFPIdx = 0; |
| 94 for (int i = firstColorProcessorIdx; i < builder.numColorFragmentProcessors(
); |
| 95 ++i, ++currFPIdx) { |
| 96 const GrFragmentProcessor* fp = builder.getColorFragmentProcessor(i); |
| 97 pipeline->fFragmentProcessors[currFPIdx].reset(fp); |
92 usesLocalCoords = usesLocalCoords || fp->usesLocalCoords(); | 98 usesLocalCoords = usesLocalCoords || fp->usesLocalCoords(); |
93 fp->gatherCoordTransforms(&pipeline->fCoordTransforms); | 99 fp->gatherCoordTransforms(&pipeline->fCoordTransforms); |
94 } | 100 } |
95 | 101 |
96 pipeline->fNumColorStages = pipeline->fFragmentStages.count(); | 102 for (int i = firstCoverageProcessorIdx; i < builder.numCoverageFragmentProce
ssors(); |
97 for (int i = firstCoverageStageIdx; i < builder.numCoverageFragmentStages();
++i) { | 103 ++i, ++currFPIdx) { |
98 const GrFragmentStage& fps = builder.fCoverageStages[i]; | 104 const GrFragmentProcessor* fp = builder.getCoverageFragmentProcessor(i); |
99 const GrFragmentProcessor* fp = fps.processor(); | 105 pipeline->fFragmentProcessors[currFPIdx].reset(fp); |
100 SkNEW_APPEND_TO_TARRAY(&pipeline->fFragmentStages, GrPendingFragmentStag
e, (fps)); | |
101 usesLocalCoords = usesLocalCoords || fp->usesLocalCoords(); | 106 usesLocalCoords = usesLocalCoords || fp->usesLocalCoords(); |
102 fp->gatherCoordTransforms(&pipeline->fCoordTransforms); | 107 fp->gatherCoordTransforms(&pipeline->fCoordTransforms); |
103 } | 108 } |
104 | 109 |
105 // Setup info we need to pass to GrPrimitiveProcessors that are used with th
is GrPipeline. | 110 // Setup info we need to pass to GrPrimitiveProcessors that are used with th
is GrPipeline. |
106 opts->fFlags = 0; | 111 opts->fFlags = 0; |
107 if (!SkToBool(optFlags & GrXferProcessor::kIgnoreColor_OptFlag)) { | 112 if (!SkToBool(optFlags & GrXferProcessor::kIgnoreColor_OptFlag)) { |
108 opts->fFlags |= GrPipelineOptimizations::kReadsColor_Flag; | 113 opts->fFlags |= GrPipelineOptimizations::kReadsColor_Flag; |
109 } | 114 } |
110 if (GrColor_ILLEGAL != overrideColor) { | 115 if (GrColor_ILLEGAL != overrideColor) { |
(...skipping 16 matching lines...) Expand all Loading... |
127 opts->fFlags |= GrPipelineOptimizations::kWillColorBlendWithDst_Flag; | 132 opts->fFlags |= GrPipelineOptimizations::kWillColorBlendWithDst_Flag; |
128 } | 133 } |
129 | 134 |
130 return pipeline; | 135 return pipeline; |
131 } | 136 } |
132 | 137 |
133 void GrPipeline::adjustProgramFromOptimizations(const GrPipelineBuilder& pipelin
eBuilder, | 138 void GrPipeline::adjustProgramFromOptimizations(const GrPipelineBuilder& pipelin
eBuilder, |
134 GrXferProcessor::OptFlags flags, | 139 GrXferProcessor::OptFlags flags, |
135 const GrProcOptInfo& colorPOI, | 140 const GrProcOptInfo& colorPOI, |
136 const GrProcOptInfo& coveragePOI
, | 141 const GrProcOptInfo& coveragePOI
, |
137 int* firstColorStageIdx, | 142 int* firstColorProcessorIdx, |
138 int* firstCoverageStageIdx) { | 143 int* firstCoverageProcessorIdx)
{ |
139 fReadsFragPosition = fXferProcessor->willReadFragmentPosition(); | 144 fReadsFragPosition = fXferProcessor->willReadFragmentPosition(); |
140 | 145 |
141 if ((flags & GrXferProcessor::kIgnoreColor_OptFlag) || | 146 if ((flags & GrXferProcessor::kIgnoreColor_OptFlag) || |
142 (flags & GrXferProcessor::kOverrideColor_OptFlag)) { | 147 (flags & GrXferProcessor::kOverrideColor_OptFlag)) { |
143 *firstColorStageIdx = pipelineBuilder.numColorFragmentStages(); | 148 *firstColorProcessorIdx = pipelineBuilder.numColorFragmentProcessors(); |
144 } else { | 149 } else { |
145 if (coveragePOI.readsFragPosition()) { | 150 if (coveragePOI.readsFragPosition()) { |
146 fReadsFragPosition = true; | 151 fReadsFragPosition = true; |
147 } | 152 } |
148 } | 153 } |
149 | 154 |
150 if (flags & GrXferProcessor::kIgnoreCoverage_OptFlag) { | 155 if (flags & GrXferProcessor::kIgnoreCoverage_OptFlag) { |
151 *firstCoverageStageIdx = pipelineBuilder.numCoverageFragmentStages(); | 156 *firstCoverageProcessorIdx = pipelineBuilder.numCoverageFragmentProcesso
rs(); |
152 } else { | 157 } else { |
153 if (coveragePOI.readsFragPosition()) { | 158 if (coveragePOI.readsFragPosition()) { |
154 fReadsFragPosition = true; | 159 fReadsFragPosition = true; |
155 } | 160 } |
156 } | 161 } |
157 } | 162 } |
158 | 163 |
159 //////////////////////////////////////////////////////////////////////////////// | 164 //////////////////////////////////////////////////////////////////////////////// |
160 | 165 |
161 bool GrPipeline::AreEqual(const GrPipeline& a, const GrPipeline& b, | 166 bool GrPipeline::AreEqual(const GrPipeline& a, const GrPipeline& b, |
162 bool ignoreCoordTransforms) { | 167 bool ignoreCoordTransforms) { |
163 SkASSERT(&a != &b); | 168 SkASSERT(&a != &b); |
164 | 169 |
165 if (a.getRenderTarget() != b.getRenderTarget() || | 170 if (a.getRenderTarget() != b.getRenderTarget() || |
166 a.fFragmentStages.count() != b.fFragmentStages.count() || | 171 a.fFragmentProcessors.count() != b.fFragmentProcessors.count() || |
167 a.fNumColorStages != b.fNumColorStages || | 172 a.fNumColorProcessors != b.fNumColorProcessors || |
168 a.fScissorState != b.fScissorState || | 173 a.fScissorState != b.fScissorState || |
169 a.fFlags != b.fFlags || | 174 a.fFlags != b.fFlags || |
170 a.fStencilSettings != b.fStencilSettings || | 175 a.fStencilSettings != b.fStencilSettings || |
171 a.fDrawFace != b.fDrawFace) { | 176 a.fDrawFace != b.fDrawFace) { |
172 return false; | 177 return false; |
173 } | 178 } |
174 | 179 |
175 if (!a.getXferProcessor()->isEqual(*b.getXferProcessor())) { | 180 if (!a.getXferProcessor()->isEqual(*b.getXferProcessor())) { |
176 return false; | 181 return false; |
177 } | 182 } |
178 | 183 |
179 for (int i = 0; i < a.numFragmentStages(); i++) { | 184 for (int i = 0; i < a.numFragmentProcessors(); i++) { |
180 if (!a.getFragmentStage(i).processor()->isEqual(*b.getFragmentStage(i).p
rocessor(), | 185 if (!a.getFragmentProcessor(i).isEqual(b.getFragmentProcessor(i), ignore
CoordTransforms)) { |
181 ignoreCoordTransform
s)) { | |
182 return false; | 186 return false; |
183 } | 187 } |
184 } | 188 } |
185 return true; | 189 return true; |
186 } | 190 } |
187 | 191 |
OLD | NEW |