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 | |
Brian Salomon | 652ecb5 | 2017-01-17 12:39:53 -0500 | [diff] [blame] | 10 | #include "GrAppliedClip.h" |
bsalomon | eb1cb5c | 2015-05-22 08:01:09 -0700 | [diff] [blame] | 11 | #include "GrCaps.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" |
Brian Salomon | 652ecb5 | 2017-01-17 12:39:53 -0500 | [diff] [blame] | 14 | #include "GrRenderTargetContext.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 | |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 19 | #include "ops/GrOp.h" |
joshualitt | 7441782 | 2015-08-07 11:42:16 -0700 | [diff] [blame] | 20 | |
Brian Salomon | e7d3048 | 2017-03-29 12:09:15 -0400 | [diff] [blame] | 21 | void GrPipeline::init(const InitArgs& args) { |
Brian Salomon | b16e8ac | 2017-02-22 11:52:36 -0500 | [diff] [blame] | 22 | SkASSERT(args.fRenderTarget); |
Brian Salomon | 92aee3d | 2016-12-21 09:20:25 -0500 | [diff] [blame] | 23 | |
Brian Salomon | b5cb683 | 2017-02-24 11:01:15 -0500 | [diff] [blame] | 24 | fRenderTarget.reset(args.fRenderTarget); |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 25 | |
Brian Salomon | b5cb683 | 2017-02-24 11:01:15 -0500 | [diff] [blame] | 26 | fFlags = args.fFlags; |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 27 | if (args.fAppliedClip) { |
| 28 | fScissorState = args.fAppliedClip->scissorState(); |
| 29 | if (args.fAppliedClip->hasStencilClip()) { |
| 30 | fFlags |= kHasStencilClip_Flag; |
| 31 | } |
| 32 | fWindowRectsState = args.fAppliedClip->windowRectsState(); |
| 33 | } |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 34 | if (args.fProcessors->usesDistanceVectorField()) { |
Brian Salomon | b5cb683 | 2017-02-24 11:01:15 -0500 | [diff] [blame] | 35 | fFlags |= kUsesDistanceVectorField_Flag; |
dvonbeck | 9b03e7b | 2016-08-01 11:01:56 -0700 | [diff] [blame] | 36 | } |
Brian Salomon | f87e2b9 | 2017-01-19 11:31:50 -0500 | [diff] [blame] | 37 | if (args.fProcessors->disableOutputConversionToSRGB()) { |
Brian Salomon | b5cb683 | 2017-02-24 11:01:15 -0500 | [diff] [blame] | 38 | fFlags |= kDisableOutputConversionToSRGB_Flag; |
Brian Salomon | f87e2b9 | 2017-01-19 11:31:50 -0500 | [diff] [blame] | 39 | } |
| 40 | if (args.fProcessors->allowSRGBInputs()) { |
Brian Salomon | b5cb683 | 2017-02-24 11:01:15 -0500 | [diff] [blame] | 41 | fFlags |= kAllowSRGBInputs_Flag; |
Brian Salomon | f87e2b9 | 2017-01-19 11:31:50 -0500 | [diff] [blame] | 42 | } |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 43 | if (!args.fUserStencil->isDisabled(fFlags & kHasStencilClip_Flag)) { |
| 44 | fFlags |= kStencilEnabled_Flag; |
| 45 | } |
| 46 | |
| 47 | fUserStencilSettings = args.fUserStencil; |
| 48 | |
| 49 | fDrawFace = static_cast<int16_t>(args.fDrawFace); |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 50 | |
Brian Salomon | 5dac9b3 | 2017-04-08 02:53:30 +0000 | [diff] [blame^] | 51 | bool isHWAA = kHWAntialias_Flag & args.fFlags; |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 52 | |
Brian Salomon | 5dac9b3 | 2017-04-08 02:53:30 +0000 | [diff] [blame^] | 53 | // Create XferProcessor from DS's XPFactory |
| 54 | { |
| 55 | bool hasMixedSamples = |
| 56 | args.fRenderTarget->isMixedSampled() && (isHWAA || this->isStencilEnabled()); |
| 57 | sk_sp<GrXferProcessor> xferProcessor = |
| 58 | GrXPFactory::MakeXferProcessor(args.fProcessors->xpFactory(), args.fXPInputColor, |
| 59 | args.fXPInputCoverage, hasMixedSamples, *args.fCaps); |
| 60 | fXferProcessor.reset(xferProcessor.get()); |
| 61 | } |
Brian Salomon | 18dfa98 | 2017-04-03 16:57:43 -0400 | [diff] [blame] | 62 | if (args.fDstTexture.texture()) { |
| 63 | fDstTexture.reset(args.fDstTexture.texture()); |
| 64 | fDstTextureOffset = args.fDstTexture.offset(); |
| 65 | } |
Brian Salomon | 3185384 | 2017-03-28 16:32:05 -0400 | [diff] [blame] | 66 | |
Brian Salomon | eec6f7b | 2017-02-10 14:29:38 -0500 | [diff] [blame] | 67 | // Copy GrFragmentProcessors from GrPipelineBuilder to Pipeline, possibly removing some of the |
| 68 | // color fragment processors. |
Brian Salomon | e14bd80 | 2017-04-04 15:13:25 -0400 | [diff] [blame] | 69 | fNumColorProcessors = args.fProcessors->numColorFragmentProcessors(); |
Brian Salomon | eec6f7b | 2017-02-10 14:29:38 -0500 | [diff] [blame] | 70 | int numTotalProcessors = |
Brian Salomon | b5cb683 | 2017-02-24 11:01:15 -0500 | [diff] [blame] | 71 | fNumColorProcessors + args.fProcessors->numCoverageFragmentProcessors(); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 72 | if (args.fAppliedClip && args.fAppliedClip->clipCoverageFragmentProcessor()) { |
Brian Salomon | 652ecb5 | 2017-01-17 12:39:53 -0500 | [diff] [blame] | 73 | ++numTotalProcessors; |
| 74 | } |
Brian Salomon | b5cb683 | 2017-02-24 11:01:15 -0500 | [diff] [blame] | 75 | fFragmentProcessors.reset(numTotalProcessors); |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 76 | int currFPIdx = 0; |
Brian Salomon | e14bd80 | 2017-04-04 15:13:25 -0400 | [diff] [blame] | 77 | for (int i = 0; i < args.fProcessors->numColorFragmentProcessors(); ++i, ++currFPIdx) { |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 78 | const GrFragmentProcessor* fp = args.fProcessors->colorFragmentProcessor(i); |
Brian Salomon | b5cb683 | 2017-02-24 11:01:15 -0500 | [diff] [blame] | 79 | fFragmentProcessors[currFPIdx].reset(fp); |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 80 | } |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 81 | |
Brian Salomon | eec6f7b | 2017-02-10 14:29:38 -0500 | [diff] [blame] | 82 | for (int i = 0; i < args.fProcessors->numCoverageFragmentProcessors(); ++i, ++currFPIdx) { |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 83 | const GrFragmentProcessor* fp = args.fProcessors->coverageFragmentProcessor(i); |
Brian Salomon | b5cb683 | 2017-02-24 11:01:15 -0500 | [diff] [blame] | 84 | fFragmentProcessors[currFPIdx].reset(fp); |
egdaniel | 9cf45bf | 2014-10-08 06:49:10 -0700 | [diff] [blame] | 85 | } |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 86 | if (args.fAppliedClip) { |
| 87 | if (const GrFragmentProcessor* fp = args.fAppliedClip->clipCoverageFragmentProcessor()) { |
| 88 | fFragmentProcessors[currFPIdx].reset(fp); |
| 89 | } |
Brian Salomon | 652ecb5 | 2017-01-17 12:39:53 -0500 | [diff] [blame] | 90 | } |
egdaniel | c064824 | 2014-09-22 13:17:02 -0700 | [diff] [blame] | 91 | } |
| 92 | |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 93 | static void add_dependencies_for_processor(const GrFragmentProcessor* proc, GrRenderTarget* rt) { |
bsalomon | b58a2b4 | 2016-09-26 06:55:02 -0700 | [diff] [blame] | 94 | GrFragmentProcessor::TextureAccessIter iter(proc); |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 95 | while (const GrResourceIOProcessor::TextureSampler* sampler = iter.next()) { |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 96 | SkASSERT(rt->getLastOpList()); |
Brian Salomon | db4183d | 2016-11-17 12:48:40 -0500 | [diff] [blame] | 97 | rt->getLastOpList()->addDependency(sampler->texture()); |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 98 | } |
| 99 | } |
| 100 | |
| 101 | void GrPipeline::addDependenciesTo(GrRenderTarget* rt) const { |
| 102 | for (int i = 0; i < fFragmentProcessors.count(); ++i) { |
| 103 | add_dependencies_for_processor(fFragmentProcessors[i].get(), rt); |
| 104 | } |
| 105 | |
Brian Salomon | 18dfa98 | 2017-04-03 16:57:43 -0400 | [diff] [blame] | 106 | if (fDstTexture) { |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 107 | SkASSERT(rt->getLastOpList()); |
Brian Salomon | 18dfa98 | 2017-04-03 16:57:43 -0400 | [diff] [blame] | 108 | rt->getLastOpList()->addDependency(fDstTexture.get()); |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 109 | } |
| 110 | } |
| 111 | |
csmartdalton | 119fb2b | 2017-02-08 14:41:05 -0500 | [diff] [blame] | 112 | GrPipeline::GrPipeline(GrRenderTarget* rt, SkBlendMode blendmode) |
| 113 | : fRenderTarget(rt) |
| 114 | , fScissorState() |
| 115 | , fWindowRectsState() |
| 116 | , fUserStencilSettings(&GrUserStencilSettings::kUnused) |
| 117 | , fDrawFace(static_cast<uint16_t>(GrDrawFace::kBoth)) |
| 118 | , fFlags() |
| 119 | , fXferProcessor(GrPorterDuffXPFactory::CreateNoCoverageXP(blendmode).get()) |
| 120 | , fFragmentProcessors() |
| 121 | , fNumColorProcessors(0) { |
| 122 | } |
| 123 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 124 | //////////////////////////////////////////////////////////////////////////////// |
| 125 | |
bsalomon | 7312ff8 | 2016-09-12 08:55:38 -0700 | [diff] [blame] | 126 | bool GrPipeline::AreEqual(const GrPipeline& a, const GrPipeline& b) { |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 127 | SkASSERT(&a != &b); |
joshualitt | 8cab9a7 | 2015-07-16 09:13:50 -0700 | [diff] [blame] | 128 | |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 129 | if (a.getRenderTarget() != b.getRenderTarget() || |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 130 | a.fFragmentProcessors.count() != b.fFragmentProcessors.count() || |
| 131 | a.fNumColorProcessors != b.fNumColorProcessors || |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 132 | a.fScissorState != b.fScissorState || |
Brian Salomon | 9a76772 | 2017-03-13 17:57:28 -0400 | [diff] [blame] | 133 | a.fWindowRectsState != b.fWindowRectsState || |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 134 | a.fFlags != b.fFlags || |
csmartdalton | c633abb | 2016-11-01 08:55:55 -0700 | [diff] [blame] | 135 | a.fUserStencilSettings != b.fUserStencilSettings || |
Brian Salomon | 8c852be | 2017-01-04 10:44:42 -0500 | [diff] [blame] | 136 | a.fDrawFace != b.fDrawFace) { |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 137 | return false; |
| 138 | } |
| 139 | |
bsalomon | 2047b78 | 2015-12-21 13:12:54 -0800 | [diff] [blame] | 140 | // Most of the time both are nullptr |
| 141 | if (a.fXferProcessor.get() || b.fXferProcessor.get()) { |
| 142 | if (!a.getXferProcessor().isEqual(b.getXferProcessor())) { |
| 143 | return false; |
| 144 | } |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 145 | } |
| 146 | |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 147 | for (int i = 0; i < a.numFragmentProcessors(); i++) { |
bsalomon | 7312ff8 | 2016-09-12 08:55:38 -0700 | [diff] [blame] | 148 | if (!a.getFragmentProcessor(i).isEqual(b.getFragmentProcessor(i))) { |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 149 | return false; |
| 150 | } |
| 151 | } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 152 | return true; |
| 153 | } |