egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 1 | /* |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 2 | * Copyright 2015 Google Inc. |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [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 "GrPipeline.h" |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 9 | |
bsalomon | eb1cb5c | 2015-05-22 08:01:09 -0700 | [diff] [blame] | 10 | #include "GrCaps.h" |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 11 | #include "GrRenderTargetContext.h" |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 12 | #include "GrGpu.h" |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 13 | #include "GrPipelineBuilder.h" |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 14 | #include "GrProcOptInfo.h" |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 15 | #include "GrRenderTargetOpList.h" |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 16 | #include "GrRenderTargetPriv.h" |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 17 | #include "GrXferProcessor.h" |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 18 | |
joshualitt | 7441782 | 2015-08-07 11:42:16 -0700 | [diff] [blame] | 19 | #include "batches/GrBatch.h" |
| 20 | |
bsalomon | a387a11 | 2015-08-11 14:47:42 -0700 | [diff] [blame] | 21 | GrPipeline* GrPipeline::CreateAt(void* memory, const CreateArgs& args, |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 22 | GrXPOverridesForBatch* overrides) { |
bsalomon | a387a11 | 2015-08-11 14:47:42 -0700 | [diff] [blame] | 23 | const GrPipelineBuilder& builder = *args.fPipelineBuilder; |
csmartdalton | c633abb | 2016-11-01 08:55:55 -0700 | [diff] [blame] | 24 | const GrUserStencilSettings* userStencil = builder.getUserStencil(); |
| 25 | GrRenderTarget* rt = args.fRenderTargetContext->accessRenderTarget(); |
bsalomon | c699873 | 2015-08-10 12:01:15 -0700 | [diff] [blame] | 26 | |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 27 | GrPipeline* pipeline = new (memory) GrPipeline; |
robertphillips | 55fdccc | 2016-06-06 06:16:20 -0700 | [diff] [blame] | 28 | pipeline->fRenderTarget.reset(rt); |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 29 | SkASSERT(pipeline->fRenderTarget); |
| 30 | pipeline->fScissorState = *args.fScissor; |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 31 | pipeline->fWindowRectsState = *args.fWindowRectsState; |
csmartdalton | c633abb | 2016-11-01 08:55:55 -0700 | [diff] [blame] | 32 | pipeline->fUserStencilSettings = userStencil; |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 33 | pipeline->fDrawFace = builder.getDrawFace(); |
| 34 | |
| 35 | pipeline->fFlags = 0; |
| 36 | if (builder.isHWAntialias()) { |
| 37 | pipeline->fFlags |= kHWAA_Flag; |
| 38 | } |
| 39 | if (builder.snapVerticesToPixelCenters()) { |
| 40 | pipeline->fFlags |= kSnapVertices_Flag; |
| 41 | } |
| 42 | if (builder.getDisableOutputConversionToSRGB()) { |
| 43 | pipeline->fFlags |= kDisableOutputConversionToSRGB_Flag; |
| 44 | } |
| 45 | if (builder.getAllowSRGBInputs()) { |
| 46 | pipeline->fFlags |= kAllowSRGBInputs_Flag; |
| 47 | } |
dvonbeck | 9b03e7b | 2016-08-01 11:01:56 -0700 | [diff] [blame] | 48 | if (builder.getUsesDistanceVectorField()) { |
| 49 | pipeline->fFlags |= kUsesDistanceVectorField_Flag; |
| 50 | } |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 51 | if (args.fHasStencilClip) { |
| 52 | pipeline->fFlags |= kHasStencilClip_Flag; |
| 53 | } |
csmartdalton | c633abb | 2016-11-01 08:55:55 -0700 | [diff] [blame] | 54 | if (!userStencil->isDisabled(args.fHasStencilClip)) { |
| 55 | pipeline->fFlags |= kStencilEnabled_Flag; |
| 56 | } |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 57 | |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 58 | // Create XferProcessor from DS's XPFactory |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 59 | bool hasMixedSamples = args.fRenderTargetContext->hasMixedSamples() && |
csmartdalton | c633abb | 2016-11-01 08:55:55 -0700 | [diff] [blame] | 60 | (builder.isHWAntialias() || pipeline->isStencilEnabled()); |
egdaniel | c4b7272 | 2015-11-23 13:20:41 -0800 | [diff] [blame] | 61 | const GrXPFactory* xpFactory = builder.getXPFactory(); |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame^] | 62 | sk_sp<GrXferProcessor> xferProcessor; |
egdaniel | c4b7272 | 2015-11-23 13:20:41 -0800 | [diff] [blame] | 63 | if (xpFactory) { |
ethannicholas | de4166a | 2015-11-30 08:57:38 -0800 | [diff] [blame] | 64 | xferProcessor.reset(xpFactory->createXferProcessor(args.fOpts, |
cdalton | 3ccf2e7 | 2016-05-06 09:41:16 -0700 | [diff] [blame] | 65 | hasMixedSamples, |
egdaniel | c4b7272 | 2015-11-23 13:20:41 -0800 | [diff] [blame] | 66 | &args.fDstTexture, |
| 67 | *args.fCaps)); |
bsalomon | 2047b78 | 2015-12-21 13:12:54 -0800 | [diff] [blame] | 68 | if (!xferProcessor) { |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 69 | pipeline->~GrPipeline(); |
bsalomon | 2047b78 | 2015-12-21 13:12:54 -0800 | [diff] [blame] | 70 | return nullptr; |
| 71 | } |
egdaniel | c4b7272 | 2015-11-23 13:20:41 -0800 | [diff] [blame] | 72 | } else { |
bsalomon | 2047b78 | 2015-12-21 13:12:54 -0800 | [diff] [blame] | 73 | // This may return nullptr in the common case of src-over implemented using hw blending. |
egdaniel | c4b7272 | 2015-11-23 13:20:41 -0800 | [diff] [blame] | 74 | xferProcessor.reset(GrPorterDuffXPFactory::CreateSrcOverXferProcessor( |
| 75 | *args.fCaps, |
ethannicholas | de4166a | 2015-11-30 08:57:38 -0800 | [diff] [blame] | 76 | args.fOpts, |
cdalton | 3ccf2e7 | 2016-05-06 09:41:16 -0700 | [diff] [blame] | 77 | hasMixedSamples, |
egdaniel | c4b7272 | 2015-11-23 13:20:41 -0800 | [diff] [blame] | 78 | &args.fDstTexture)); |
| 79 | } |
cdalton | 3ccf2e7 | 2016-05-06 09:41:16 -0700 | [diff] [blame] | 80 | GrColor overrideColor = GrColor_ILLEGAL; |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 81 | if (args.fOpts.fColorPOI.firstEffectiveProcessorIndex() != 0) { |
| 82 | overrideColor = args.fOpts.fColorPOI.inputColorToFirstEffectiveProccesor(); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 83 | } |
| 84 | |
bsalomon | 7765a47 | 2015-07-08 11:26:37 -0700 | [diff] [blame] | 85 | GrXferProcessor::OptFlags optFlags = GrXferProcessor::kNone_OptFlags; |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 86 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 87 | const GrXferProcessor* xpForOpts = xferProcessor ? xferProcessor.get() : |
bsalomon | 2047b78 | 2015-12-21 13:12:54 -0800 | [diff] [blame] | 88 | &GrPorterDuffXPFactory::SimpleSrcOverXP(); |
| 89 | optFlags = xpForOpts->getOptimizations(args.fOpts, |
csmartdalton | c633abb | 2016-11-01 08:55:55 -0700 | [diff] [blame] | 90 | userStencil->doesWrite(args.fHasStencilClip), |
bsalomon | 2047b78 | 2015-12-21 13:12:54 -0800 | [diff] [blame] | 91 | &overrideColor, |
| 92 | *args.fCaps); |
bsalomon | c8d3f57 | 2015-08-13 06:44:04 -0700 | [diff] [blame] | 93 | |
| 94 | // When path rendering the stencil settings are not always set on the GrPipelineBuilder |
| 95 | // so we must check the draw type. In cases where we will skip drawing we simply return a |
| 96 | // null GrPipeline. |
| 97 | if (GrXferProcessor::kSkipDraw_OptFlag & optFlags) { |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 98 | pipeline->~GrPipeline(); |
bsalomon | c8d3f57 | 2015-08-13 06:44:04 -0700 | [diff] [blame] | 99 | return nullptr; |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 100 | } |
bsalomon | b03c4a3 | 2014-11-20 09:56:11 -0800 | [diff] [blame] | 101 | |
bsalomon | 7765a47 | 2015-07-08 11:26:37 -0700 | [diff] [blame] | 102 | // No need to have an override color if it isn't even going to be used. |
| 103 | if (SkToBool(GrXferProcessor::kIgnoreColor_OptFlag & optFlags)) { |
| 104 | overrideColor = GrColor_ILLEGAL; |
| 105 | } |
| 106 | |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame^] | 107 | pipeline->fXferProcessor.reset(xferProcessor.get()); |
bsalomon | b03c4a3 | 2014-11-20 09:56:11 -0800 | [diff] [blame] | 108 | |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 109 | int firstColorProcessorIdx = args.fOpts.fColorPOI.firstEffectiveProcessorIndex(); |
egdaniel | 912b3d2 | 2014-11-17 07:45:53 -0800 | [diff] [blame] | 110 | |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 111 | // TODO: Once we can handle single or four channel input into coverage GrFragmentProcessors |
| 112 | // then we can use GrPipelineBuilder's coverageProcInfo (like color above) to set this initial |
| 113 | // information. |
| 114 | int firstCoverageProcessorIdx = 0; |
egdaniel | 912b3d2 | 2014-11-17 07:45:53 -0800 | [diff] [blame] | 115 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 116 | pipeline->adjustProgramFromOptimizations(builder, optFlags, args.fOpts.fColorPOI, |
| 117 | args.fOpts.fCoveragePOI, &firstColorProcessorIdx, |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 118 | &firstCoverageProcessorIdx); |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 119 | |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 120 | bool usesLocalCoords = false; |
| 121 | |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 122 | // Copy GrFragmentProcessors from GrPipelineBuilder to Pipeline |
| 123 | pipeline->fNumColorProcessors = builder.numColorFragmentProcessors() - firstColorProcessorIdx; |
| 124 | int numTotalProcessors = pipeline->fNumColorProcessors + |
| 125 | builder.numCoverageFragmentProcessors() - firstCoverageProcessorIdx; |
| 126 | pipeline->fFragmentProcessors.reset(numTotalProcessors); |
| 127 | int currFPIdx = 0; |
| 128 | for (int i = firstColorProcessorIdx; i < builder.numColorFragmentProcessors(); |
| 129 | ++i, ++currFPIdx) { |
| 130 | const GrFragmentProcessor* fp = builder.getColorFragmentProcessor(i); |
| 131 | pipeline->fFragmentProcessors[currFPIdx].reset(fp); |
joshualitt | 2fe7923 | 2015-08-05 12:02:27 -0700 | [diff] [blame] | 132 | usesLocalCoords = usesLocalCoords || fp->usesLocalCoords(); |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 133 | } |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 134 | |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 135 | for (int i = firstCoverageProcessorIdx; i < builder.numCoverageFragmentProcessors(); |
| 136 | ++i, ++currFPIdx) { |
| 137 | const GrFragmentProcessor* fp = builder.getCoverageFragmentProcessor(i); |
| 138 | pipeline->fFragmentProcessors[currFPIdx].reset(fp); |
joshualitt | 2fe7923 | 2015-08-05 12:02:27 -0700 | [diff] [blame] | 139 | usesLocalCoords = usesLocalCoords || fp->usesLocalCoords(); |
egdaniel | 9cf45bf | 2014-10-08 06:49:10 -0700 | [diff] [blame] | 140 | } |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 141 | |
bsalomon | 7765a47 | 2015-07-08 11:26:37 -0700 | [diff] [blame] | 142 | // Setup info we need to pass to GrPrimitiveProcessors that are used with this GrPipeline. |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 143 | overrides->fFlags = 0; |
bsalomon | 7765a47 | 2015-07-08 11:26:37 -0700 | [diff] [blame] | 144 | if (!SkToBool(optFlags & GrXferProcessor::kIgnoreColor_OptFlag)) { |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 145 | overrides->fFlags |= GrXPOverridesForBatch::kReadsColor_Flag; |
bsalomon | 7765a47 | 2015-07-08 11:26:37 -0700 | [diff] [blame] | 146 | } |
| 147 | if (GrColor_ILLEGAL != overrideColor) { |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 148 | overrides->fFlags |= GrXPOverridesForBatch::kUseOverrideColor_Flag; |
| 149 | overrides->fOverrideColor = overrideColor; |
bsalomon | 7765a47 | 2015-07-08 11:26:37 -0700 | [diff] [blame] | 150 | } |
| 151 | if (!SkToBool(optFlags & GrXferProcessor::kIgnoreCoverage_OptFlag)) { |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 152 | overrides->fFlags |= GrXPOverridesForBatch::kReadsCoverage_Flag; |
bsalomon | 7765a47 | 2015-07-08 11:26:37 -0700 | [diff] [blame] | 153 | } |
| 154 | if (usesLocalCoords) { |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 155 | overrides->fFlags |= GrXPOverridesForBatch::kReadsLocalCoords_Flag; |
bsalomon | 7765a47 | 2015-07-08 11:26:37 -0700 | [diff] [blame] | 156 | } |
| 157 | if (SkToBool(optFlags & GrXferProcessor::kCanTweakAlphaForCoverage_OptFlag)) { |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 158 | overrides->fFlags |= GrXPOverridesForBatch::kCanTweakAlphaForCoverage_Flag; |
bsalomon | 7765a47 | 2015-07-08 11:26:37 -0700 | [diff] [blame] | 159 | } |
bsalomon | 2d56303 | 2015-08-13 07:08:31 -0700 | [diff] [blame] | 160 | |
| 161 | GrXPFactory::InvariantBlendedColor blendedColor; |
egdaniel | c4b7272 | 2015-11-23 13:20:41 -0800 | [diff] [blame] | 162 | if (xpFactory) { |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 163 | xpFactory->getInvariantBlendedColor(args.fOpts.fColorPOI, &blendedColor); |
egdaniel | c4b7272 | 2015-11-23 13:20:41 -0800 | [diff] [blame] | 164 | } else { |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 165 | GrPorterDuffXPFactory::SrcOverInvariantBlendedColor(args.fOpts.fColorPOI.color(), |
| 166 | args.fOpts.fColorPOI.validFlags(), |
| 167 | args.fOpts.fColorPOI.isOpaque(), |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 168 | &blendedColor); |
egdaniel | c4b7272 | 2015-11-23 13:20:41 -0800 | [diff] [blame] | 169 | } |
bsalomon | 2d56303 | 2015-08-13 07:08:31 -0700 | [diff] [blame] | 170 | if (blendedColor.fWillBlendWithDst) { |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 171 | overrides->fFlags |= GrXPOverridesForBatch::kWillColorBlendWithDst_Flag; |
bsalomon | 2d56303 | 2015-08-13 07:08:31 -0700 | [diff] [blame] | 172 | } |
| 173 | |
bsalomon | c699873 | 2015-08-10 12:01:15 -0700 | [diff] [blame] | 174 | return pipeline; |
egdaniel | c064824 | 2014-09-22 13:17:02 -0700 | [diff] [blame] | 175 | } |
| 176 | |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 177 | static void add_dependencies_for_processor(const GrFragmentProcessor* proc, GrRenderTarget* rt) { |
bsalomon | b58a2b4 | 2016-09-26 06:55:02 -0700 | [diff] [blame] | 178 | GrFragmentProcessor::TextureAccessIter iter(proc); |
| 179 | while (const GrTextureAccess* access = iter.next()) { |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 180 | SkASSERT(rt->getLastOpList()); |
| 181 | rt->getLastOpList()->addDependency(access->getTexture()); |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | |
| 185 | void GrPipeline::addDependenciesTo(GrRenderTarget* rt) const { |
| 186 | for (int i = 0; i < fFragmentProcessors.count(); ++i) { |
| 187 | add_dependencies_for_processor(fFragmentProcessors[i].get(), rt); |
| 188 | } |
| 189 | |
bsalomon | 2047b78 | 2015-12-21 13:12:54 -0800 | [diff] [blame] | 190 | const GrXferProcessor& xfer = this->getXferProcessor(); |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 191 | |
bsalomon | 2047b78 | 2015-12-21 13:12:54 -0800 | [diff] [blame] | 192 | for (int i = 0; i < xfer.numTextures(); ++i) { |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 193 | GrTexture* texture = xfer.textureAccess(i).getTexture(); |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 194 | SkASSERT(rt->getLastOpList()); |
| 195 | rt->getLastOpList()->addDependency(texture); |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 196 | } |
| 197 | } |
| 198 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 199 | void GrPipeline::adjustProgramFromOptimizations(const GrPipelineBuilder& pipelineBuilder, |
| 200 | GrXferProcessor::OptFlags flags, |
| 201 | const GrProcOptInfo& colorPOI, |
| 202 | const GrProcOptInfo& coveragePOI, |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 203 | int* firstColorProcessorIdx, |
| 204 | int* firstCoverageProcessorIdx) { |
egdaniel | 56cf6dc | 2015-11-30 10:15:58 -0800 | [diff] [blame] | 205 | fIgnoresCoverage = SkToBool(flags & GrXferProcessor::kIgnoreCoverage_OptFlag); |
egdaniel | a7dc0a8 | 2014-09-17 08:25:05 -0700 | [diff] [blame] | 206 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 207 | if ((flags & GrXferProcessor::kIgnoreColor_OptFlag) || |
| 208 | (flags & GrXferProcessor::kOverrideColor_OptFlag)) { |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 209 | *firstColorProcessorIdx = pipelineBuilder.numColorFragmentProcessors(); |
egdaniel | a7dc0a8 | 2014-09-17 08:25:05 -0700 | [diff] [blame] | 210 | } |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 211 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 212 | if (flags & GrXferProcessor::kIgnoreCoverage_OptFlag) { |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 213 | *firstCoverageProcessorIdx = pipelineBuilder.numCoverageFragmentProcessors(); |
egdaniel | a7dc0a8 | 2014-09-17 08:25:05 -0700 | [diff] [blame] | 214 | } |
| 215 | } |
| 216 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 217 | //////////////////////////////////////////////////////////////////////////////// |
| 218 | |
bsalomon | 7312ff8 | 2016-09-12 08:55:38 -0700 | [diff] [blame] | 219 | bool GrPipeline::AreEqual(const GrPipeline& a, const GrPipeline& b) { |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 220 | SkASSERT(&a != &b); |
joshualitt | 8cab9a7 | 2015-07-16 09:13:50 -0700 | [diff] [blame] | 221 | |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 222 | if (a.getRenderTarget() != b.getRenderTarget() || |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 223 | a.fFragmentProcessors.count() != b.fFragmentProcessors.count() || |
| 224 | a.fNumColorProcessors != b.fNumColorProcessors || |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 225 | a.fScissorState != b.fScissorState || |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 226 | !a.fWindowRectsState.cheapEqualTo(b.fWindowRectsState) || |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 227 | a.fFlags != b.fFlags || |
csmartdalton | c633abb | 2016-11-01 08:55:55 -0700 | [diff] [blame] | 228 | a.fUserStencilSettings != b.fUserStencilSettings || |
csmartdalton | afd6340 | 2016-07-06 09:47:38 -0700 | [diff] [blame] | 229 | a.fDrawFace != b.fDrawFace || |
| 230 | a.fIgnoresCoverage != b.fIgnoresCoverage) { |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 231 | return false; |
| 232 | } |
| 233 | |
bsalomon | 2047b78 | 2015-12-21 13:12:54 -0800 | [diff] [blame] | 234 | // Most of the time both are nullptr |
| 235 | if (a.fXferProcessor.get() || b.fXferProcessor.get()) { |
| 236 | if (!a.getXferProcessor().isEqual(b.getXferProcessor())) { |
| 237 | return false; |
| 238 | } |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 239 | } |
| 240 | |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 241 | for (int i = 0; i < a.numFragmentProcessors(); i++) { |
bsalomon | 7312ff8 | 2016-09-12 08:55:38 -0700 | [diff] [blame] | 242 | if (!a.getFragmentProcessor(i).isEqual(b.getFragmentProcessor(i))) { |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 243 | return false; |
| 244 | } |
| 245 | } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 246 | return true; |
| 247 | } |