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 "GrPipelineBuilder.h" | 8 #include "GrPipelineBuilder.h" |
9 | 9 |
10 #include "GrBlend.h" | 10 #include "GrBlend.h" |
11 #include "GrPaint.h" | 11 #include "GrPaint.h" |
12 #include "GrPipeline.h" | 12 #include "GrPipeline.h" |
13 #include "GrProcOptInfo.h" | 13 #include "GrProcOptInfo.h" |
14 #include "GrXferProcessor.h" | 14 #include "GrXferProcessor.h" |
15 #include "batches/GrBatch.h" | 15 #include "batches/GrBatch.h" |
16 #include "effects/GrPorterDuffXferProcessor.h" | 16 #include "effects/GrPorterDuffXferProcessor.h" |
17 | 17 |
18 GrPipelineBuilder::GrPipelineBuilder() | 18 GrPipelineBuilder::GrPipelineBuilder() |
19 : fProcDataManager(SkNEW(GrProcessorDataManager)) | 19 : fProcDataManager(SkNEW(GrProcessorDataManager)) |
20 , fFlags(0x0) | 20 , fFlags(0x0) |
21 , fDrawFace(kBoth_DrawFace) | 21 , fDrawFace(kBoth_DrawFace) { |
22 , fColorProcInfoValid(false) | |
23 , fCoverageProcInfoValid(false) | |
24 , fColorCache(GrColor_ILLEGAL) | |
25 , fCoverageCache(GrColor_ILLEGAL) { | |
26 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 22 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
27 } | 23 } |
28 | 24 |
29 GrPipelineBuilder& GrPipelineBuilder::operator=(const GrPipelineBuilder& that) { | 25 GrPipelineBuilder& GrPipelineBuilder::operator=(const GrPipelineBuilder& that) { |
30 fProcDataManager.reset(SkNEW_ARGS(GrProcessorDataManager, (*that.processorDa
taManager()))); | 26 fProcDataManager.reset(SkNEW_ARGS(GrProcessorDataManager, (*that.processorDa
taManager()))); |
31 fRenderTarget.reset(SkSafeRef(that.fRenderTarget.get())); | 27 fRenderTarget.reset(SkSafeRef(that.fRenderTarget.get())); |
32 fFlags = that.fFlags; | 28 fFlags = that.fFlags; |
33 fStencilSettings = that.fStencilSettings; | 29 fStencilSettings = that.fStencilSettings; |
34 fDrawFace = that.fDrawFace; | 30 fDrawFace = that.fDrawFace; |
35 fXPFactory.reset(SkRef(that.getXPFactory())); | 31 fXPFactory.reset(SkRef(that.getXPFactory())); |
36 fColorStages = that.fColorStages; | 32 fColorStages = that.fColorStages; |
37 fCoverageStages = that.fCoverageStages; | 33 fCoverageStages = that.fCoverageStages; |
38 fClip = that.fClip; | 34 fClip = that.fClip; |
39 | 35 |
40 fColorProcInfoValid = that.fColorProcInfoValid; | |
41 fCoverageProcInfoValid = that.fCoverageProcInfoValid; | |
42 fColorCache = that.fColorCache; | |
43 fCoverageCache = that.fCoverageCache; | |
44 if (fColorProcInfoValid) { | |
45 fColorProcInfo = that.fColorProcInfo; | |
46 } | |
47 if (fCoverageProcInfoValid) { | |
48 fCoverageProcInfo = that.fCoverageProcInfo; | |
49 } | |
50 return *this; | 36 return *this; |
51 } | 37 } |
52 | 38 |
53 GrPipelineBuilder::GrPipelineBuilder(const GrPaint& paint, GrRenderTarget* rt, c
onst GrClip& clip) { | 39 GrPipelineBuilder::GrPipelineBuilder(const GrPaint& paint, GrRenderTarget* rt, c
onst GrClip& clip) { |
54 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 40 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
55 | 41 |
56 // TODO keep this logically const using an AutoReset | 42 // TODO keep this logically const using an AutoReset |
57 fProcDataManager.reset( | 43 fProcDataManager.reset( |
58 const_cast<GrProcessorDataManager*>(SkRef(paint.processorDataManager())
)); | 44 const_cast<GrProcessorDataManager*>(SkRef(paint.processorDataManager())
)); |
59 | 45 |
(...skipping 15 matching lines...) Expand all Loading... |
75 // These have no equivalent in GrPaint, set them to defaults | 61 // These have no equivalent in GrPaint, set them to defaults |
76 fDrawFace = kBoth_DrawFace; | 62 fDrawFace = kBoth_DrawFace; |
77 fStencilSettings.setDisabled(); | 63 fStencilSettings.setDisabled(); |
78 fFlags = 0; | 64 fFlags = 0; |
79 | 65 |
80 fClip = clip; | 66 fClip = clip; |
81 | 67 |
82 this->setState(GrPipelineBuilder::kDither_Flag, paint.isDither()); | 68 this->setState(GrPipelineBuilder::kDither_Flag, paint.isDither()); |
83 this->setState(GrPipelineBuilder::kHWAntialias_Flag, | 69 this->setState(GrPipelineBuilder::kHWAntialias_Flag, |
84 rt->isUnifiedMultisampled() && paint.isAntiAlias()); | 70 rt->isUnifiedMultisampled() && paint.isAntiAlias()); |
85 | |
86 fColorProcInfoValid = false; | |
87 fCoverageProcInfoValid = false; | |
88 | |
89 fColorCache = GrColor_ILLEGAL; | |
90 fCoverageCache = GrColor_ILLEGAL; | |
91 } | 71 } |
92 | 72 |
93 //////////////////////////////////////////////////////////////////////////////s | 73 //////////////////////////////////////////////////////////////////////////////s |
94 | 74 |
95 bool GrPipelineBuilder::willXPNeedDstTexture(const GrCaps& caps, | 75 bool GrPipelineBuilder::willXPNeedDstTexture(const GrCaps& caps, |
96 const GrProcOptInfo& colorPOI, | 76 const GrProcOptInfo& colorPOI, |
97 const GrProcOptInfo& coveragePOI) c
onst { | 77 const GrProcOptInfo& coveragePOI) c
onst { |
98 return this->getXPFactory()->willNeedDstTexture(caps, colorPOI, coveragePOI, | 78 return this->getXPFactory()->willNeedDstTexture(caps, colorPOI, coveragePOI, |
99 this->hasMixedSamples()); | 79 this->hasMixedSamples()); |
100 } | 80 } |
101 | 81 |
102 void GrPipelineBuilder::AutoRestoreFragmentProcessorState::set( | 82 void GrPipelineBuilder::AutoRestoreFragmentProcessorState::set( |
103 const GrPipelineBuilder
* pipelineBuilder) { | 83 const GrPipelineBuilder
* pipelineBuilder) { |
104 if (fPipelineBuilder) { | 84 if (fPipelineBuilder) { |
105 int m = fPipelineBuilder->numColorFragmentStages() - fColorEffectCnt; | 85 int m = fPipelineBuilder->numColorFragmentStages() - fColorEffectCnt; |
106 SkASSERT(m >= 0); | 86 SkASSERT(m >= 0); |
107 fPipelineBuilder->fColorStages.pop_back_n(m); | 87 fPipelineBuilder->fColorStages.pop_back_n(m); |
108 | 88 |
109 int n = fPipelineBuilder->numCoverageFragmentStages() - fCoverageEffectC
nt; | 89 int n = fPipelineBuilder->numCoverageFragmentStages() - fCoverageEffectC
nt; |
110 SkASSERT(n >= 0); | 90 SkASSERT(n >= 0); |
111 fPipelineBuilder->fCoverageStages.pop_back_n(n); | 91 fPipelineBuilder->fCoverageStages.pop_back_n(n); |
112 if (m + n > 0) { | 92 |
113 fPipelineBuilder->fColorProcInfoValid = false; | |
114 fPipelineBuilder->fCoverageProcInfoValid = false; | |
115 } | |
116 SkDEBUGCODE(--fPipelineBuilder->fBlockEffectRemovalCnt;) | 93 SkDEBUGCODE(--fPipelineBuilder->fBlockEffectRemovalCnt;) |
117 fPipelineBuilder->getProcessorDataManager()->restoreToSaveMarker(/*fSave
Marker*/); | 94 fPipelineBuilder->getProcessorDataManager()->restoreToSaveMarker(/*fSave
Marker*/); |
118 } | 95 } |
119 fPipelineBuilder = const_cast<GrPipelineBuilder*>(pipelineBuilder); | 96 fPipelineBuilder = const_cast<GrPipelineBuilder*>(pipelineBuilder); |
120 if (NULL != pipelineBuilder) { | 97 if (NULL != pipelineBuilder) { |
121 fColorEffectCnt = pipelineBuilder->numColorFragmentStages(); | 98 fColorEffectCnt = pipelineBuilder->numColorFragmentStages(); |
122 fCoverageEffectCnt = pipelineBuilder->numCoverageFragmentStages(); | 99 fCoverageEffectCnt = pipelineBuilder->numCoverageFragmentStages(); |
123 SkDEBUGCODE(++pipelineBuilder->fBlockEffectRemovalCnt;) | 100 SkDEBUGCODE(++pipelineBuilder->fBlockEffectRemovalCnt;) |
124 fSaveMarker = pipelineBuilder->processorDataManager()->currentSaveMarker
(); | 101 fSaveMarker = pipelineBuilder->processorDataManager()->currentSaveMarker
(); |
125 } | 102 } |
126 } | 103 } |
127 | 104 |
128 //////////////////////////////////////////////////////////////////////////////// | 105 //////////////////////////////////////////////////////////////////////////////// |
129 | 106 |
130 GrPipelineBuilder::~GrPipelineBuilder() { | 107 GrPipelineBuilder::~GrPipelineBuilder() { |
131 SkASSERT(0 == fBlockEffectRemovalCnt); | 108 SkASSERT(0 == fBlockEffectRemovalCnt); |
132 } | 109 } |
133 | 110 |
134 //////////////////////////////////////////////////////////////////////////////// | 111 //////////////////////////////////////////////////////////////////////////////// |
135 | 112 |
136 void GrPipelineBuilder::calcColorInvariantOutput(const GrPrimitiveProcessor* pp)
const { | 113 void GrPipelineBuilder::calcColorInvariantOutput(const GrPrimitiveProcessor* pp)
const { |
137 fColorProcInfo.calcColorWithPrimProc(pp, fColorStages.begin(), this->numColo
rFragmentStages()); | 114 fColorProcInfo.calcColorWithPrimProc(pp, fColorStages.begin(), this->numColo
rFragmentStages()); |
138 fColorProcInfoValid = false; | |
139 | |
140 } | 115 } |
141 | 116 |
142 void GrPipelineBuilder::calcCoverageInvariantOutput(const GrPrimitiveProcessor*
pp) const { | 117 void GrPipelineBuilder::calcCoverageInvariantOutput(const GrPrimitiveProcessor*
pp) const { |
143 fCoverageProcInfo.calcCoverageWithPrimProc(pp, fCoverageStages.begin(), | 118 fCoverageProcInfo.calcCoverageWithPrimProc(pp, fCoverageStages.begin(), |
144 this->numCoverageFragmentStages()
); | 119 this->numCoverageFragmentStages()); |
145 fCoverageProcInfoValid = false; | |
146 } | 120 } |
147 | 121 |
148 void GrPipelineBuilder::calcColorInvariantOutput(const GrDrawBatch* batch) const
{ | 122 void GrPipelineBuilder::calcColorInvariantOutput(const GrDrawBatch* batch) const
{ |
149 fColorProcInfo.calcColorWithBatch(batch, fColorStages.begin(), this->numColo
rFragmentStages()); | 123 fColorProcInfo.calcColorWithBatch(batch, fColorStages.begin(), this->numColo
rFragmentStages()); |
150 fColorProcInfoValid = false; | |
151 } | 124 } |
152 | 125 |
153 void GrPipelineBuilder::calcCoverageInvariantOutput(const GrDrawBatch* batch) co
nst { | 126 void GrPipelineBuilder::calcCoverageInvariantOutput(const GrDrawBatch* batch) co
nst { |
154 fCoverageProcInfo.calcCoverageWithBatch(batch, fCoverageStages.begin(), | 127 fCoverageProcInfo.calcCoverageWithBatch(batch, fCoverageStages.begin(), |
155 this->numCoverageFragmentStages()); | 128 this->numCoverageFragmentStages()); |
156 fCoverageProcInfoValid = false; | |
157 } | 129 } |
158 | 130 |
159 | |
160 void GrPipelineBuilder::calcColorInvariantOutput(GrColor color) const { | |
161 if (!fColorProcInfoValid || color != fColorCache) { | |
162 GrColorComponentFlags flags = kRGBA_GrColorComponentFlags; | |
163 fColorProcInfo.calcWithInitialValues(fColorStages.begin(),this->numColor
FragmentStages(), | |
164 color, flags, false); | |
165 fColorProcInfoValid = true; | |
166 fColorCache = color; | |
167 } | |
168 } | |
169 | |
170 void GrPipelineBuilder::calcCoverageInvariantOutput(GrColor coverage) const { | |
171 if (!fCoverageProcInfoValid || coverage != fCoverageCache) { | |
172 GrColorComponentFlags flags = kRGBA_GrColorComponentFlags; | |
173 fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), | |
174 this->numCoverageFragmentStages(
), coverage, flags, | |
175 true); | |
176 fCoverageProcInfoValid = true; | |
177 fCoverageCache = coverage; | |
178 } | |
179 } | |
OLD | NEW |