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" |
Brian Salomon | 652ecb5 | 2017-01-17 12:39:53 -0500 | [diff] [blame] | 13 | #include "GrRenderTargetContext.h" |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 14 | #include "GrRenderTargetOpList.h" |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 15 | #include "GrXferProcessor.h" |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 16 | |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 17 | #include "ops/GrOp.h" |
joshualitt | 7441782 | 2015-08-07 11:42:16 -0700 | [diff] [blame] | 18 | |
Brian Salomon | bfd18cd | 2017-08-09 16:27:09 -0400 | [diff] [blame] | 19 | GrPipeline::GrPipeline(const InitArgs& args, GrProcessorSet&& processors, |
| 20 | GrAppliedClip&& appliedClip) { |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 21 | SkASSERT(args.fProxy); |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 22 | SkASSERT(processors.isFinalized()); |
Brian Salomon | 92aee3d | 2016-12-21 09:20:25 -0500 | [diff] [blame] | 23 | |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 24 | fProxy.reset(args.fProxy); |
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 | bfd18cd | 2017-08-09 16:27:09 -0400 | [diff] [blame] | 27 | fScissorState = appliedClip.scissorState(); |
| 28 | if (appliedClip.hasStencilClip()) { |
| 29 | fFlags |= kHasStencilClip_Flag; |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 30 | } |
Brian Salomon | bfd18cd | 2017-08-09 16:27:09 -0400 | [diff] [blame] | 31 | fWindowRectsState = appliedClip.windowRectsState(); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 32 | if (!args.fUserStencil->isDisabled(fFlags & kHasStencilClip_Flag)) { |
| 33 | fFlags |= kStencilEnabled_Flag; |
| 34 | } |
| 35 | |
| 36 | fUserStencilSettings = args.fUserStencil; |
| 37 | |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 38 | fXferProcessor = processors.refXferProcessor(); |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 39 | |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 40 | if (args.fDstProxy.proxy()) { |
| 41 | if (!args.fDstProxy.proxy()->instantiate(args.fResourceProvider)) { |
| 42 | this->markAsBad(); |
| 43 | } |
| 44 | |
| 45 | fDstTextureProxy.reset(args.fDstProxy.proxy()); |
| 46 | fDstTextureOffset = args.fDstProxy.offset(); |
Brian Salomon | 18dfa98 | 2017-04-03 16:57:43 -0400 | [diff] [blame] | 47 | } |
Brian Salomon | 3185384 | 2017-03-28 16:32:05 -0400 | [diff] [blame] | 48 | |
Brian Salomon | e5b399e | 2017-07-19 13:50:54 -0400 | [diff] [blame] | 49 | // Copy GrFragmentProcessors from GrProcessorSet to Pipeline |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 50 | fNumColorProcessors = processors.numColorFragmentProcessors(); |
Chris Dalton | 6982400 | 2017-10-31 00:37:52 -0600 | [diff] [blame] | 51 | int numTotalProcessors = fNumColorProcessors + |
| 52 | processors.numCoverageFragmentProcessors() + |
| 53 | appliedClip.numClipCoverageFragmentProcessors(); |
Brian Salomon | b5cb683 | 2017-02-24 11:01:15 -0500 | [diff] [blame] | 54 | fFragmentProcessors.reset(numTotalProcessors); |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 55 | int currFPIdx = 0; |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 56 | for (int i = 0; i < processors.numColorFragmentProcessors(); ++i, ++currFPIdx) { |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 57 | fFragmentProcessors[currFPIdx] = processors.detachColorFragmentProcessor(i); |
| 58 | if (!fFragmentProcessors[currFPIdx]->instantiate(args.fResourceProvider)) { |
Robert Phillips | a91e0b7 | 2017-05-01 13:12:20 -0400 | [diff] [blame] | 59 | this->markAsBad(); |
| 60 | } |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 61 | } |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 62 | for (int i = 0; i < processors.numCoverageFragmentProcessors(); ++i, ++currFPIdx) { |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 63 | fFragmentProcessors[currFPIdx] = processors.detachCoverageFragmentProcessor(i); |
| 64 | if (!fFragmentProcessors[currFPIdx]->instantiate(args.fResourceProvider)) { |
Robert Phillips | a91e0b7 | 2017-05-01 13:12:20 -0400 | [diff] [blame] | 65 | this->markAsBad(); |
| 66 | } |
egdaniel | 9cf45bf | 2014-10-08 06:49:10 -0700 | [diff] [blame] | 67 | } |
Chris Dalton | 6982400 | 2017-10-31 00:37:52 -0600 | [diff] [blame] | 68 | for (int i = 0; i < appliedClip.numClipCoverageFragmentProcessors(); ++i, ++currFPIdx) { |
| 69 | fFragmentProcessors[currFPIdx] = appliedClip.detachClipCoverageFragmentProcessor(i); |
Brian Salomon | bfd18cd | 2017-08-09 16:27:09 -0400 | [diff] [blame] | 70 | if (!fFragmentProcessors[currFPIdx]->instantiate(args.fResourceProvider)) { |
| 71 | this->markAsBad(); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 72 | } |
Brian Salomon | 652ecb5 | 2017-01-17 12:39:53 -0500 | [diff] [blame] | 73 | } |
egdaniel | c064824 | 2014-09-22 13:17:02 -0700 | [diff] [blame] | 74 | } |
| 75 | |
Robert Phillips | d261e10 | 2017-06-23 12:37:20 -0400 | [diff] [blame] | 76 | void GrPipeline::addDependenciesTo(GrOpList* opList, const GrCaps& caps) const { |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 77 | for (int i = 0; i < fFragmentProcessors.count(); ++i) { |
Robert Phillips | d261e10 | 2017-06-23 12:37:20 -0400 | [diff] [blame] | 78 | GrFragmentProcessor::TextureAccessIter iter(fFragmentProcessors[i].get()); |
| 79 | while (const GrResourceIOProcessor::TextureSampler* sampler = iter.next()) { |
| 80 | opList->addDependency(sampler->proxy(), caps); |
| 81 | } |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 84 | if (fDstTextureProxy) { |
Robert Phillips | d261e10 | 2017-06-23 12:37:20 -0400 | [diff] [blame] | 85 | opList->addDependency(fDstTextureProxy.get(), caps); |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 86 | } |
Robert Phillips | d261e10 | 2017-06-23 12:37:20 -0400 | [diff] [blame] | 87 | |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Robert Phillips | c9c06d4 | 2017-06-12 10:58:31 -0400 | [diff] [blame] | 90 | GrXferBarrierType GrPipeline::xferBarrierType(const GrCaps& caps) const { |
| 91 | if (fDstTextureProxy.get() && |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 92 | fDstTextureProxy.get()->priv().peekTexture() == fProxy.get()->priv().peekTexture()) { |
Robert Phillips | c9c06d4 | 2017-06-12 10:58:31 -0400 | [diff] [blame] | 93 | return kTexture_GrXferBarrierType; |
| 94 | } |
| 95 | return this->getXferProcessor().xferBarrierType(caps); |
| 96 | } |
| 97 | |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 98 | GrPipeline::GrPipeline(GrRenderTargetProxy* proxy, ScissorState scissorState, SkBlendMode blendmode) |
| 99 | : fProxy(proxy) |
| 100 | , fScissorState() |
| 101 | , fWindowRectsState() |
| 102 | , fUserStencilSettings(&GrUserStencilSettings::kUnused) |
| 103 | , fFlags() |
| 104 | , fXferProcessor(GrPorterDuffXPFactory::MakeNoCoverageXP(blendmode)) |
| 105 | , fFragmentProcessors() |
| 106 | , fNumColorProcessors(0) { |
Brian Salomon | f3ce7e3 | 2017-07-31 16:07:39 -0400 | [diff] [blame] | 107 | SkASSERT(proxy); |
Chris Dalton | 46983b7 | 2017-06-06 12:27:16 -0600 | [diff] [blame] | 108 | if (ScissorState::kEnabled == scissorState) { |
| 109 | fScissorState.set({0, 0, 0, 0}); // caller will use the DynamicState struct. |
| 110 | } |
| 111 | } |