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(new GrProcessorDataManager), fFlags(0x0), fDrawFace(kBoth
_DrawFace) { | 19 : fProcDataManager(new GrProcessorDataManager), fFlags(0x0), fDrawFace(kBoth
_DrawFace) { |
20 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 20 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
21 } | 21 } |
22 | 22 |
23 GrPipelineBuilder& GrPipelineBuilder::operator=(const GrPipelineBuilder& that) { | |
24 fProcDataManager.reset(new GrProcessorDataManager(*that.processorDataManager
())); | |
25 fRenderTarget.reset(SkSafeRef(that.fRenderTarget.get())); | |
26 fFlags = that.fFlags; | |
27 fStencilSettings = that.fStencilSettings; | |
28 fDrawFace = that.fDrawFace; | |
29 fXPFactory.reset(SkRef(that.getXPFactory())); | |
30 fColorStages = that.fColorStages; | |
31 fCoverageStages = that.fCoverageStages; | |
32 fClip = that.fClip; | |
33 | |
34 return *this; | |
35 } | |
36 | |
37 GrPipelineBuilder::GrPipelineBuilder(const GrPaint& paint, GrRenderTarget* rt, c
onst GrClip& clip) { | 23 GrPipelineBuilder::GrPipelineBuilder(const GrPaint& paint, GrRenderTarget* rt, c
onst GrClip& clip) { |
38 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 24 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
39 | 25 |
40 // TODO keep this logically const using an AutoReset | 26 // TODO keep this logically const using an AutoReset |
41 fProcDataManager.reset( | 27 fProcDataManager.reset( |
42 const_cast<GrProcessorDataManager*>(SkRef(paint.processorDataManager())
)); | 28 const_cast<GrProcessorDataManager*>(SkRef(paint.processorDataManager())
)); |
43 | 29 |
44 fColorStages.reset(); | 30 for (int i = 0; i < paint.numColorFragmentProcessors(); ++i) { |
45 fCoverageStages.reset(); | 31 fColorFragmentProcessors.push_back(SkRef(paint.getColorFragmentProcessor
(i))); |
46 | |
47 for (int i = 0; i < paint.numColorStages(); ++i) { | |
48 fColorStages.push_back(paint.getColorStage(i)); | |
49 } | 32 } |
50 | 33 |
51 for (int i = 0; i < paint.numCoverageStages(); ++i) { | 34 for (int i = 0; i < paint.numCoverageFragmentProcessors(); ++i) { |
52 fCoverageStages.push_back(paint.getCoverageStage(i)); | 35 fCoverageFragmentProcessors.push_back(SkRef(paint.getCoverageFragmentPro
cessor(i))); |
53 } | 36 } |
54 | 37 |
55 fXPFactory.reset(SkRef(paint.getXPFactory())); | 38 fXPFactory.reset(SkRef(paint.getXPFactory())); |
56 | 39 |
57 this->setRenderTarget(rt); | 40 this->setRenderTarget(rt); |
58 | 41 |
59 // These have no equivalent in GrPaint, set them to defaults | 42 // These have no equivalent in GrPaint, set them to defaults |
60 fDrawFace = kBoth_DrawFace; | 43 fDrawFace = kBoth_DrawFace; |
61 fStencilSettings.setDisabled(); | 44 fStencilSettings.setDisabled(); |
62 fFlags = 0; | 45 fFlags = 0; |
(...skipping 10 matching lines...) Expand all Loading... |
73 bool GrPipelineBuilder::willXPNeedDstTexture(const GrCaps& caps, | 56 bool GrPipelineBuilder::willXPNeedDstTexture(const GrCaps& caps, |
74 const GrProcOptInfo& colorPOI, | 57 const GrProcOptInfo& colorPOI, |
75 const GrProcOptInfo& coveragePOI) c
onst { | 58 const GrProcOptInfo& coveragePOI) c
onst { |
76 return this->getXPFactory()->willNeedDstTexture(caps, colorPOI, coveragePOI, | 59 return this->getXPFactory()->willNeedDstTexture(caps, colorPOI, coveragePOI, |
77 this->hasMixedSamples()); | 60 this->hasMixedSamples()); |
78 } | 61 } |
79 | 62 |
80 void GrPipelineBuilder::AutoRestoreFragmentProcessorState::set( | 63 void GrPipelineBuilder::AutoRestoreFragmentProcessorState::set( |
81 const GrPipelineBuilder
* pipelineBuilder) { | 64 const GrPipelineBuilder
* pipelineBuilder) { |
82 if (fPipelineBuilder) { | 65 if (fPipelineBuilder) { |
83 int m = fPipelineBuilder->numColorFragmentStages() - fColorEffectCnt; | 66 int m = fPipelineBuilder->numColorFragmentProcessors() - fColorEffectCnt
; |
84 SkASSERT(m >= 0); | 67 SkASSERT(m >= 0); |
85 fPipelineBuilder->fColorStages.pop_back_n(m); | 68 for (int i = 0; i < m; ++i) { |
| 69 fPipelineBuilder->fColorFragmentProcessors.fromBack(i)->unref(); |
| 70 } |
| 71 fPipelineBuilder->fColorFragmentProcessors.pop_back_n(m); |
86 | 72 |
87 int n = fPipelineBuilder->numCoverageFragmentStages() - fCoverageEffectC
nt; | 73 int n = fPipelineBuilder->numCoverageFragmentProcessors() - fCoverageEff
ectCnt; |
88 SkASSERT(n >= 0); | 74 SkASSERT(n >= 0); |
89 fPipelineBuilder->fCoverageStages.pop_back_n(n); | 75 for (int i = 0; i < n; ++i) { |
90 | 76 fPipelineBuilder->fCoverageFragmentProcessors.fromBack(i)->unref(); |
| 77 } |
| 78 fPipelineBuilder->fCoverageFragmentProcessors.pop_back_n(n); |
91 SkDEBUGCODE(--fPipelineBuilder->fBlockEffectRemovalCnt;) | 79 SkDEBUGCODE(--fPipelineBuilder->fBlockEffectRemovalCnt;) |
92 fPipelineBuilder->getProcessorDataManager()->restoreToSaveMarker(/*fSave
Marker*/); | 80 fPipelineBuilder->getProcessorDataManager()->restoreToSaveMarker(/*fSave
Marker*/); |
93 } | 81 } |
94 fPipelineBuilder = const_cast<GrPipelineBuilder*>(pipelineBuilder); | 82 fPipelineBuilder = const_cast<GrPipelineBuilder*>(pipelineBuilder); |
95 if (NULL != pipelineBuilder) { | 83 if (NULL != pipelineBuilder) { |
96 fColorEffectCnt = pipelineBuilder->numColorFragmentStages(); | 84 fColorEffectCnt = pipelineBuilder->numColorFragmentProcessors(); |
97 fCoverageEffectCnt = pipelineBuilder->numCoverageFragmentStages(); | 85 fCoverageEffectCnt = pipelineBuilder->numCoverageFragmentProcessors(); |
98 SkDEBUGCODE(++pipelineBuilder->fBlockEffectRemovalCnt;) | 86 SkDEBUGCODE(++pipelineBuilder->fBlockEffectRemovalCnt;) |
99 fSaveMarker = pipelineBuilder->processorDataManager()->currentSaveMarker
(); | 87 fSaveMarker = pipelineBuilder->processorDataManager()->currentSaveMarker
(); |
100 } | 88 } |
101 } | 89 } |
102 | 90 |
103 //////////////////////////////////////////////////////////////////////////////// | 91 //////////////////////////////////////////////////////////////////////////////// |
104 | 92 |
105 GrPipelineBuilder::~GrPipelineBuilder() { | 93 GrPipelineBuilder::~GrPipelineBuilder() { |
106 SkASSERT(0 == fBlockEffectRemovalCnt); | 94 SkASSERT(0 == fBlockEffectRemovalCnt); |
| 95 for (int i = 0; i < fColorFragmentProcessors.count(); ++i) { |
| 96 fColorFragmentProcessors[i]->unref(); |
| 97 } |
| 98 for (int i = 0; i < fCoverageFragmentProcessors.count(); ++i) { |
| 99 fCoverageFragmentProcessors[i]->unref(); |
| 100 } |
107 } | 101 } |
108 | 102 |
109 //////////////////////////////////////////////////////////////////////////////// | 103 //////////////////////////////////////////////////////////////////////////////// |
110 | 104 |
111 void GrPipelineBuilder::calcColorInvariantOutput(const GrPrimitiveProcessor* pp)
const { | 105 void GrPipelineBuilder::calcColorInvariantOutput(const GrPrimitiveProcessor* pp)
const { |
112 fColorProcInfo.calcColorWithPrimProc(pp, fColorStages.begin(), this->numColo
rFragmentStages()); | 106 fColorProcInfo.calcColorWithPrimProc(pp, fColorFragmentProcessors.begin(), |
| 107 this->numColorFragmentProcessors()); |
| 108 |
113 } | 109 } |
114 | 110 |
115 void GrPipelineBuilder::calcCoverageInvariantOutput(const GrPrimitiveProcessor*
pp) const { | 111 void GrPipelineBuilder::calcCoverageInvariantOutput(const GrPrimitiveProcessor*
pp) const { |
116 fCoverageProcInfo.calcCoverageWithPrimProc(pp, fCoverageStages.begin(), | 112 fCoverageProcInfo.calcCoverageWithPrimProc(pp, fCoverageFragmentProcessors.b
egin(), |
117 this->numCoverageFragmentStages()); | 113 this->numCoverageFragmentProcesso
rs()); |
118 } | 114 } |
119 | 115 |
120 void GrPipelineBuilder::calcColorInvariantOutput(const GrDrawBatch* batch) const
{ | 116 void GrPipelineBuilder::calcColorInvariantOutput(const GrDrawBatch* batch) const
{ |
121 fColorProcInfo.calcColorWithBatch(batch, fColorStages.begin(), this->numColo
rFragmentStages()); | 117 fColorProcInfo.calcColorWithBatch(batch, fColorFragmentProcessors.begin(), |
| 118 this->numColorFragmentProcessors()); |
122 } | 119 } |
123 | 120 |
124 void GrPipelineBuilder::calcCoverageInvariantOutput(const GrDrawBatch* batch) co
nst { | 121 void GrPipelineBuilder::calcCoverageInvariantOutput(const GrDrawBatch* batch) co
nst { |
125 fCoverageProcInfo.calcCoverageWithBatch(batch, fCoverageStages.begin(), | 122 fCoverageProcInfo.calcCoverageWithBatch(batch, fCoverageFragmentProcessors.b
egin(), |
126 this->numCoverageFragmentStages()); | 123 this->numCoverageFragmentProcessors(
)); |
127 } | 124 } |
128 | |
OLD | NEW |