bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 1 | /* |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 2 | * Copyright 2015 Google Inc. |
bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 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 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 8 | #include "GrPipelineBuilder.h" |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 9 | |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 10 | #include "GrBatch.h" |
egdaniel | b1cff03 | 2014-11-13 06:19:25 -0800 | [diff] [blame] | 11 | #include "GrBlend.h" |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 12 | #include "GrPaint.h" |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 13 | #include "GrPipeline.h" |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 14 | #include "GrProcOptInfo.h" |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 15 | #include "GrXferProcessor.h" |
| 16 | #include "effects/GrPorterDuffXferProcessor.h" |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 17 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 18 | GrPipelineBuilder::GrPipelineBuilder() |
joshualitt | 5b4f05f | 2015-07-10 07:26:21 -0700 | [diff] [blame] | 19 | : fProcDataManager(SkNEW(GrProcessorDataManager)) |
| 20 | , fFlags(0x0) |
joshualitt | 2fdeda0 | 2015-01-22 07:11:44 -0800 | [diff] [blame] | 21 | , fDrawFace(kBoth_DrawFace) |
| 22 | , fColorProcInfoValid(false) |
| 23 | , fCoverageProcInfoValid(false) |
| 24 | , fColorCache(GrColor_ILLEGAL) |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 25 | , fCoverageCache(GrColor_ILLEGAL) { |
joshualitt | 2fdeda0 | 2015-01-22 07:11:44 -0800 | [diff] [blame] | 26 | SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 27 | } |
| 28 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 29 | GrPipelineBuilder& GrPipelineBuilder::operator=(const GrPipelineBuilder& that) { |
joshualitt | 5b4f05f | 2015-07-10 07:26:21 -0700 | [diff] [blame] | 30 | fProcDataManager.reset(SkNEW_ARGS(GrProcessorDataManager, (*that.processorDataManager()))); |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 31 | fRenderTarget.reset(SkSafeRef(that.fRenderTarget.get())); |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 32 | fFlags = that.fFlags; |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 33 | fStencilSettings = that.fStencilSettings; |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 34 | fDrawFace = that.fDrawFace; |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 35 | fXPFactory.reset(SkRef(that.getXPFactory())); |
egdaniel | 8cbf3d5 | 2014-08-21 06:27:22 -0700 | [diff] [blame] | 36 | fColorStages = that.fColorStages; |
| 37 | fCoverageStages = that.fCoverageStages; |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 38 | fClip = that.fClip; |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 39 | |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 40 | fColorProcInfoValid = that.fColorProcInfoValid; |
| 41 | fCoverageProcInfoValid = that.fCoverageProcInfoValid; |
joshualitt | f364b61 | 2014-12-11 06:52:01 -0800 | [diff] [blame] | 42 | fColorCache = that.fColorCache; |
| 43 | fCoverageCache = that.fCoverageCache; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 44 | if (fColorProcInfoValid) { |
| 45 | fColorProcInfo = that.fColorProcInfo; |
| 46 | } |
| 47 | if (fCoverageProcInfoValid) { |
| 48 | fCoverageProcInfo = that.fCoverageProcInfo; |
| 49 | } |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 50 | return *this; |
| 51 | } |
| 52 | |
joshualitt | 7b670db | 2015-07-09 13:25:02 -0700 | [diff] [blame] | 53 | GrPipelineBuilder::GrPipelineBuilder(const GrPaint& paint, GrRenderTarget* rt, const GrClip& clip) { |
| 54 | SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 55 | |
joshualitt | 5b4f05f | 2015-07-10 07:26:21 -0700 | [diff] [blame] | 56 | // TODO keep this logically const using an AutoReset |
| 57 | fProcDataManager.reset( |
| 58 | const_cast<GrProcessorDataManager*>(SkRef(paint.processorDataManager()))); |
| 59 | |
egdaniel | 8cbf3d5 | 2014-08-21 06:27:22 -0700 | [diff] [blame] | 60 | fColorStages.reset(); |
| 61 | fCoverageStages.reset(); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 62 | |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 63 | for (int i = 0; i < paint.numColorStages(); ++i) { |
egdaniel | 8cbf3d5 | 2014-08-21 06:27:22 -0700 | [diff] [blame] | 64 | fColorStages.push_back(paint.getColorStage(i)); |
bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 65 | } |
| 66 | |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 67 | for (int i = 0; i < paint.numCoverageStages(); ++i) { |
egdaniel | 8cbf3d5 | 2014-08-21 06:27:22 -0700 | [diff] [blame] | 68 | fCoverageStages.push_back(paint.getCoverageStage(i)); |
bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 69 | } |
| 70 | |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 71 | fXPFactory.reset(SkRef(paint.getXPFactory())); |
| 72 | |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 73 | this->setRenderTarget(rt); |
bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 74 | |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 75 | // These have no equivalent in GrPaint, set them to defaults |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 76 | fDrawFace = kBoth_DrawFace; |
| 77 | fStencilSettings.setDisabled(); |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 78 | fFlags = 0; |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 79 | |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 80 | fClip = clip; |
bsalomon@google.com | 21c10c5 | 2013-06-13 17:44:07 +0000 | [diff] [blame] | 81 | |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 82 | this->setState(GrPipelineBuilder::kDither_Flag, paint.isDither()); |
| 83 | this->setState(GrPipelineBuilder::kHWAntialias_Flag, |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 84 | rt->isUnifiedMultisampled() && paint.isAntiAlias()); |
bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 85 | |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 86 | fColorProcInfoValid = false; |
| 87 | fCoverageProcInfoValid = false; |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 88 | |
| 89 | fColorCache = GrColor_ILLEGAL; |
| 90 | fCoverageCache = GrColor_ILLEGAL; |
bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 91 | } |
bsalomon@google.com | 5b3e890 | 2012-10-05 20:13:28 +0000 | [diff] [blame] | 92 | |
egdaniel | 21aed57 | 2014-08-26 12:24:06 -0700 | [diff] [blame] | 93 | //////////////////////////////////////////////////////////////////////////////s |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 94 | |
bsalomon | 6a44c6a | 2015-05-26 09:49:05 -0700 | [diff] [blame] | 95 | bool GrPipelineBuilder::willXPNeedDstTexture(const GrCaps& caps, |
| 96 | const GrProcOptInfo& colorPOI, |
| 97 | const GrProcOptInfo& coveragePOI) const { |
cdalton | 86ae0a9 | 2015-06-08 15:11:04 -0700 | [diff] [blame] | 98 | return this->getXPFactory()->willNeedDstTexture(caps, colorPOI, coveragePOI, |
| 99 | this->hasMixedSamples()); |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 100 | } |
| 101 | |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 102 | void GrPipelineBuilder::AutoRestoreFragmentProcessors::set(GrPipelineBuilder* pipelineBuilder) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 103 | if (fPipelineBuilder) { |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 104 | int m = fPipelineBuilder->numColorFragmentStages() - fColorEffectCnt; |
egdaniel | 21aed57 | 2014-08-26 12:24:06 -0700 | [diff] [blame] | 105 | SkASSERT(m >= 0); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 106 | fPipelineBuilder->fColorStages.pop_back_n(m); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 107 | |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 108 | int n = fPipelineBuilder->numCoverageFragmentStages() - fCoverageEffectCnt; |
egdaniel | 21aed57 | 2014-08-26 12:24:06 -0700 | [diff] [blame] | 109 | SkASSERT(n >= 0); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 110 | fPipelineBuilder->fCoverageStages.pop_back_n(n); |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 111 | if (m + n > 0) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 112 | fPipelineBuilder->fColorProcInfoValid = false; |
| 113 | fPipelineBuilder->fCoverageProcInfoValid = false; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 114 | } |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 115 | SkDEBUGCODE(--fPipelineBuilder->fBlockEffectRemovalCnt;) |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 116 | } |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 117 | fPipelineBuilder = pipelineBuilder; |
| 118 | if (NULL != pipelineBuilder) { |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 119 | fColorEffectCnt = pipelineBuilder->numColorFragmentStages(); |
| 120 | fCoverageEffectCnt = pipelineBuilder->numCoverageFragmentStages(); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 121 | SkDEBUGCODE(++pipelineBuilder->fBlockEffectRemovalCnt;) |
egdaniel | 21aed57 | 2014-08-26 12:24:06 -0700 | [diff] [blame] | 122 | } |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 123 | } |
| 124 | |
jvanverth@google.com | cc78238 | 2013-01-28 20:39:48 +0000 | [diff] [blame] | 125 | //////////////////////////////////////////////////////////////////////////////// |
| 126 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 127 | GrPipelineBuilder::~GrPipelineBuilder() { |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame] | 128 | SkASSERT(0 == fBlockEffectRemovalCnt); |
| 129 | } |
| 130 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 131 | //////////////////////////////////////////////////////////////////////////////// |
| 132 | |
cdalton | 1fa4572 | 2015-06-02 10:43:39 -0700 | [diff] [blame] | 133 | bool GrPipelineBuilder::willColorBlendWithDst(const GrPrimitiveProcessor* pp) const { |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 134 | this->calcColorInvariantOutput(pp); |
egdaniel | 9e4ecdc | 2014-12-18 12:44:55 -0800 | [diff] [blame] | 135 | |
cdalton | 1fa4572 | 2015-06-02 10:43:39 -0700 | [diff] [blame] | 136 | GrXPFactory::InvariantBlendedColor blendedColor; |
| 137 | fXPFactory->getInvariantBlendedColor(fColorProcInfo, &blendedColor); |
| 138 | return blendedColor.fWillBlendWithDst; |
egdaniel | cd8b630 | 2014-11-11 14:46:05 -0800 | [diff] [blame] | 139 | } |
| 140 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 141 | void GrPipelineBuilder::calcColorInvariantOutput(const GrPrimitiveProcessor* pp) const { |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 142 | fColorProcInfo.calcColorWithPrimProc(pp, fColorStages.begin(), this->numColorFragmentStages()); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 143 | fColorProcInfoValid = false; |
| 144 | |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 145 | } |
| 146 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 147 | void GrPipelineBuilder::calcCoverageInvariantOutput(const GrPrimitiveProcessor* pp) const { |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 148 | fCoverageProcInfo.calcCoverageWithPrimProc(pp, fCoverageStages.begin(), |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 149 | this->numCoverageFragmentStages()); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 150 | fCoverageProcInfoValid = false; |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 151 | } |
| 152 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 153 | void GrPipelineBuilder::calcColorInvariantOutput(const GrBatch* batch) const { |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 154 | fColorProcInfo.calcColorWithBatch(batch, fColorStages.begin(), this->numColorFragmentStages()); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 155 | fColorProcInfoValid = false; |
| 156 | } |
| 157 | |
| 158 | void GrPipelineBuilder::calcCoverageInvariantOutput(const GrBatch* batch) const { |
| 159 | fCoverageProcInfo.calcCoverageWithBatch(batch, fCoverageStages.begin(), |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 160 | this->numCoverageFragmentStages()); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 161 | fCoverageProcInfoValid = false; |
| 162 | } |
| 163 | |
| 164 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 165 | void GrPipelineBuilder::calcColorInvariantOutput(GrColor color) const { |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 166 | if (!fColorProcInfoValid || color != fColorCache) { |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 167 | GrColorComponentFlags flags = kRGBA_GrColorComponentFlags; |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 168 | fColorProcInfo.calcWithInitialValues(fColorStages.begin(),this->numColorFragmentStages(), |
| 169 | color, flags, false); |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 170 | fColorProcInfoValid = true; |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 171 | fColorCache = color; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 172 | } |
| 173 | } |
| 174 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 175 | void GrPipelineBuilder::calcCoverageInvariantOutput(GrColor coverage) const { |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 176 | if (!fCoverageProcInfoValid || coverage != fCoverageCache) { |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 177 | GrColorComponentFlags flags = kRGBA_GrColorComponentFlags; |
| 178 | fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 179 | this->numCoverageFragmentStages(), coverage, flags, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 180 | true); |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 181 | fCoverageProcInfoValid = true; |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 182 | fCoverageCache = coverage; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 183 | } |
| 184 | } |