| 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" |
| 11 #include "GrGpu.h" | 11 #include "GrGpu.h" |
| 12 #include "GrPipelineBuilder.h" | 12 #include "GrPipelineBuilder.h" |
| 13 #include "GrProcOptInfo.h" | 13 #include "GrProcOptInfo.h" |
| 14 #include "GrXferProcessor.h" | 14 #include "GrXferProcessor.h" |
| 15 | 15 |
| 16 #include "batches/GrBatch.h" | 16 #include "batches/GrBatch.h" |
| 17 | 17 |
| 18 GrPipeline::GrPipeline(const GrPipelineBuilder& pipelineBuilder, | 18 GrPipeline* GrPipeline::CreateAt(void* memory, |
| 19 const GrProcOptInfo& colorPOI, | 19 const GrPipelineBuilder& builder, |
| 20 const GrProcOptInfo& coveragePOI, | 20 const GrProcOptInfo& colorPOI, |
| 21 const GrCaps& caps, | 21 const GrProcOptInfo& coveragePOI, |
| 22 const GrScissorState& scissorState, | 22 const GrCaps& caps, |
| 23 const GrXferProcessor::DstTexture* dstTexture) { | 23 const GrScissorState& scissor, |
| 24 const GrXferProcessor::DstTexture* dst, |
| 25 GrPipelineOptimizations* opts) { |
| 26 GrPipeline* pipeline = SkNEW_PLACEMENT(memory, GrPipeline); |
| 27 |
| 24 // Create XferProcessor from DS's XPFactory | 28 // Create XferProcessor from DS's XPFactory |
| 25 SkAutoTUnref<GrXferProcessor> xferProcessor( | 29 SkAutoTUnref<GrXferProcessor> xferProcessor( |
| 26 pipelineBuilder.getXPFactory()->createXferProcessor( | 30 builder.getXPFactory()->createXferProcessor( |
| 27 colorPOI, coveragePOI, pipelineBuilder.hasMixedSamples(), dstTexture
, caps)); | 31 colorPOI, coveragePOI, builder.hasMixedSamples(), dst, caps)); |
| 28 | 32 |
| 29 GrColor overrideColor = GrColor_ILLEGAL; | 33 GrColor overrideColor = GrColor_ILLEGAL; |
| 30 if (colorPOI.firstEffectiveStageIndex() != 0) { | 34 if (colorPOI.firstEffectiveStageIndex() != 0) { |
| 31 overrideColor = colorPOI.inputColorToEffectiveStage(); | 35 overrideColor = colorPOI.inputColorToEffectiveStage(); |
| 32 } | 36 } |
| 33 | 37 |
| 34 GrXferProcessor::OptFlags optFlags = GrXferProcessor::kNone_OptFlags; | 38 GrXferProcessor::OptFlags optFlags = GrXferProcessor::kNone_OptFlags; |
| 35 if (xferProcessor) { | 39 if (xferProcessor) { |
| 36 fXferProcessor.reset(xferProcessor.get()); | 40 pipeline->fXferProcessor.reset(xferProcessor.get()); |
| 37 | 41 |
| 38 optFlags = xferProcessor->getOptimizations(colorPOI, | 42 optFlags = xferProcessor->getOptimizations(colorPOI, |
| 39 coveragePOI, | 43 coveragePOI, |
| 40 pipelineBuilder.getStencil().
doesWrite(), | 44 builder.getStencil().doesWrit
e(), |
| 41 &overrideColor, | 45 &overrideColor, |
| 42 caps); | 46 caps); |
| 43 } | 47 } |
| 44 | 48 |
| 45 // No need to have an override color if it isn't even going to be used. | 49 // No need to have an override color if it isn't even going to be used. |
| 46 if (SkToBool(GrXferProcessor::kIgnoreColor_OptFlag & optFlags)) { | 50 if (SkToBool(GrXferProcessor::kIgnoreColor_OptFlag & optFlags)) { |
| 47 overrideColor = GrColor_ILLEGAL; | 51 overrideColor = GrColor_ILLEGAL; |
| 48 } | 52 } |
| 49 | 53 |
| 50 // When path rendering the stencil settings are not always set on the GrPipe
lineBuilder | 54 // When path rendering the stencil settings are not always set on the GrPipe
lineBuilder |
| 51 // so we must check the draw type. In cases where we will skip drawing we si
mply return a | 55 // so we must check the draw type. In cases where we will skip drawing we si
mply return a |
| 52 // null GrPipeline. | 56 // null GrPipeline. |
| 53 if (!xferProcessor || (GrXferProcessor::kSkipDraw_OptFlag & optFlags)) { | 57 if (!xferProcessor || (GrXferProcessor::kSkipDraw_OptFlag & optFlags)) { |
| 54 // Set the fields that don't default init and return. The lack of a rend
er target will | 58 // Set the fields that don't default init and return. The lack of a rend
er target will |
| 55 // indicate that this can be skipped. | 59 // indicate that this can be skipped. |
| 56 fFlags = 0; | 60 pipeline->fFlags = 0; |
| 57 fDrawFace = GrPipelineBuilder::kInvalid_DrawFace; | 61 pipeline->fDrawFace = GrPipelineBuilder::kInvalid_DrawFace; |
| 58 return; | 62 return pipeline; |
| 59 } | 63 } |
| 60 | 64 |
| 61 fRenderTarget.reset(pipelineBuilder.fRenderTarget.get()); | 65 pipeline->fRenderTarget.reset(builder.fRenderTarget.get()); |
| 62 SkASSERT(fRenderTarget); | 66 SkASSERT(pipeline->fRenderTarget); |
| 63 fScissorState = scissorState; | 67 pipeline->fScissorState = scissor; |
| 64 fStencilSettings = pipelineBuilder.getStencil(); | 68 pipeline->fStencilSettings = builder.getStencil(); |
| 65 fDrawFace = pipelineBuilder.getDrawFace(); | 69 pipeline->fDrawFace = builder.getDrawFace(); |
| 66 | 70 |
| 67 fFlags = 0; | 71 pipeline->fFlags = 0; |
| 68 if (pipelineBuilder.isHWAntialias()) { | 72 if (builder.isHWAntialias()) { |
| 69 fFlags |= kHWAA_Flag; | 73 pipeline->fFlags |= kHWAA_Flag; |
| 70 } | 74 } |
| 71 if (pipelineBuilder.isDither()) { | 75 if (builder.isDither()) { |
| 72 fFlags |= kDither_Flag; | 76 pipeline->fFlags |= kDither_Flag; |
| 73 } | 77 } |
| 74 if (pipelineBuilder.snapVerticesToPixelCenters()) { | 78 if (builder.snapVerticesToPixelCenters()) { |
| 75 fFlags |= kSnapVertices_Flag; | 79 pipeline->fFlags |= kSnapVertices_Flag; |
| 76 } | 80 } |
| 77 | 81 |
| 78 int firstColorStageIdx = colorPOI.firstEffectiveStageIndex(); | 82 int firstColorStageIdx = colorPOI.firstEffectiveStageIndex(); |
| 79 | 83 |
| 80 // TODO: Once we can handle single or four channel input into coverage stage
s then we can use | 84 // TODO: Once we can handle single or four channel input into coverage stage
s then we can use |
| 81 // GrPipelineBuilder's coverageProcInfo (like color above) to set this initi
al information. | 85 // GrPipelineBuilder's coverageProcInfo (like color above) to set this initi
al information. |
| 82 int firstCoverageStageIdx = 0; | 86 int firstCoverageStageIdx = 0; |
| 83 | 87 |
| 84 this->adjustProgramFromOptimizations(pipelineBuilder, optFlags, colorPOI, co
veragePOI, | 88 pipeline->adjustProgramFromOptimizations(builder, optFlags, colorPOI, covera
gePOI, |
| 85 &firstColorStageIdx, &firstCoverageStag
eIdx); | 89 &firstColorStageIdx, &firstCoverage
StageIdx); |
| 86 | 90 |
| 87 bool usesLocalCoords = false; | 91 bool usesLocalCoords = false; |
| 88 | 92 |
| 89 // Copy Stages from PipelineBuilder to Pipeline | 93 // Copy Stages from PipelineBuilder to Pipeline |
| 90 for (int i = firstColorStageIdx; i < pipelineBuilder.numColorFragmentStages(
); ++i) { | 94 for (int i = firstColorStageIdx; i < builder.numColorFragmentStages(); ++i)
{ |
| 91 const GrFragmentStage& fps = pipelineBuilder.fColorStages[i]; | 95 const GrFragmentStage& fps = builder.fColorStages[i]; |
| 92 const GrFragmentProcessor* fp = fps.processor(); | 96 const GrFragmentProcessor* fp = fps.processor(); |
| 93 SkNEW_APPEND_TO_TARRAY(&fFragmentStages, GrPendingFragmentStage, (fps)); | 97 SkNEW_APPEND_TO_TARRAY(&pipeline->fFragmentStages, GrPendingFragmentStag
e, (fps)); |
| 94 usesLocalCoords = usesLocalCoords || fp->usesLocalCoords(); | 98 usesLocalCoords = usesLocalCoords || fp->usesLocalCoords(); |
| 95 fp->gatherCoordTransforms(&fCoordTransforms); | 99 fp->gatherCoordTransforms(&pipeline->fCoordTransforms); |
| 96 } | 100 } |
| 97 | 101 |
| 98 fNumColorStages = fFragmentStages.count(); | 102 pipeline->fNumColorStages = pipeline->fFragmentStages.count(); |
| 99 for (int i = firstCoverageStageIdx; i < pipelineBuilder.numCoverageFragmentS
tages(); ++i) { | 103 for (int i = firstCoverageStageIdx; i < builder.numCoverageFragmentStages();
++i) { |
| 100 const GrFragmentStage& fps = pipelineBuilder.fCoverageStages[i]; | 104 const GrFragmentStage& fps = builder.fCoverageStages[i]; |
| 101 const GrFragmentProcessor* fp = fps.processor(); | 105 const GrFragmentProcessor* fp = fps.processor(); |
| 102 SkNEW_APPEND_TO_TARRAY(&fFragmentStages, GrPendingFragmentStage, (fps)); | 106 SkNEW_APPEND_TO_TARRAY(&pipeline->fFragmentStages, GrPendingFragmentStag
e, (fps)); |
| 103 usesLocalCoords = usesLocalCoords || fp->usesLocalCoords(); | 107 usesLocalCoords = usesLocalCoords || fp->usesLocalCoords(); |
| 104 fp->gatherCoordTransforms(&fCoordTransforms); | 108 fp->gatherCoordTransforms(&pipeline->fCoordTransforms); |
| 105 } | 109 } |
| 106 | 110 |
| 107 // Setup info we need to pass to GrPrimitiveProcessors that are used with th
is GrPipeline. | 111 // Setup info we need to pass to GrPrimitiveProcessors that are used with th
is GrPipeline. |
| 108 fInfoForPrimitiveProcessor.fFlags = 0; | 112 opts->fFlags = 0; |
| 109 if (!SkToBool(optFlags & GrXferProcessor::kIgnoreColor_OptFlag)) { | 113 if (!SkToBool(optFlags & GrXferProcessor::kIgnoreColor_OptFlag)) { |
| 110 fInfoForPrimitiveProcessor.fFlags |= | 114 opts->fFlags |= GrPipelineOptimizations::kReadsColor_Flag; |
| 111 GrPipelineOptimizations::kReadsColor_GrPipelineOptimizationsFlag; | |
| 112 } | 115 } |
| 113 if (GrColor_ILLEGAL != overrideColor) { | 116 if (GrColor_ILLEGAL != overrideColor) { |
| 114 fInfoForPrimitiveProcessor.fFlags |= | 117 opts->fFlags |= GrPipelineOptimizations::kUseOverrideColor_Flag; |
| 115 GrPipelineOptimizations::kUseOverrideColor_GrPipelineOptimizationsFl
ag; | 118 opts->fOverrideColor = overrideColor; |
| 116 fInfoForPrimitiveProcessor.fOverrideColor = overrideColor; | |
| 117 } | 119 } |
| 118 if (!SkToBool(optFlags & GrXferProcessor::kIgnoreCoverage_OptFlag)) { | 120 if (!SkToBool(optFlags & GrXferProcessor::kIgnoreCoverage_OptFlag)) { |
| 119 fInfoForPrimitiveProcessor.fFlags |= | 121 opts->fFlags |= GrPipelineOptimizations::kReadsCoverage_Flag; |
| 120 GrPipelineOptimizations::kReadsCoverage_GrPipelineOptimizationsFlag; | |
| 121 } | 122 } |
| 122 if (usesLocalCoords) { | 123 if (usesLocalCoords) { |
| 123 fInfoForPrimitiveProcessor.fFlags |= | 124 opts->fFlags |= GrPipelineOptimizations::kReadsLocalCoords_Flag; |
| 124 GrPipelineOptimizations::kReadsLocalCoords_GrPipelineOptimizationsFl
ag; | |
| 125 } | 125 } |
| 126 if (SkToBool(optFlags & GrXferProcessor::kCanTweakAlphaForCoverage_OptFlag))
{ | 126 if (SkToBool(optFlags & GrXferProcessor::kCanTweakAlphaForCoverage_OptFlag))
{ |
| 127 fInfoForPrimitiveProcessor.fFlags |= | 127 opts->fFlags |= GrPipelineOptimizations::kCanTweakAlphaForCoverage_Flag;
|
| 128 GrPipelineOptimizations::kCanTweakAlphaForCoverage_GrPipelineOptimiza
tionsFlag; | |
| 129 } | 128 } |
| 129 return pipeline; |
| 130 } | 130 } |
| 131 | 131 |
| 132 void GrPipeline::adjustProgramFromOptimizations(const GrPipelineBuilder& pipelin
eBuilder, | 132 void GrPipeline::adjustProgramFromOptimizations(const GrPipelineBuilder& pipelin
eBuilder, |
| 133 GrXferProcessor::OptFlags flags, | 133 GrXferProcessor::OptFlags flags, |
| 134 const GrProcOptInfo& colorPOI, | 134 const GrProcOptInfo& colorPOI, |
| 135 const GrProcOptInfo& coveragePOI
, | 135 const GrProcOptInfo& coveragePOI
, |
| 136 int* firstColorStageIdx, | 136 int* firstColorStageIdx, |
| 137 int* firstCoverageStageIdx) { | 137 int* firstCoverageStageIdx) { |
| 138 fReadsFragPosition = fXferProcessor->willReadFragmentPosition(); | 138 fReadsFragPosition = fXferProcessor->willReadFragmentPosition(); |
| 139 | 139 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 | 179 |
| 180 for (int i = 0; i < this->numFragmentStages(); i++) { | 180 for (int i = 0; i < this->numFragmentStages(); i++) { |
| 181 if (!this->getFragmentStage(i).processor()->isEqual(*that.getFragmentSta
ge(i).processor(), | 181 if (!this->getFragmentStage(i).processor()->isEqual(*that.getFragmentSta
ge(i).processor(), |
| 182 ignoreCoordTransform
s)) { | 182 ignoreCoordTransform
s)) { |
| 183 return false; | 183 return false; |
| 184 } | 184 } |
| 185 } | 185 } |
| 186 return true; | 186 return true; |
| 187 } | 187 } |
| 188 | 188 |
| OLD | NEW |