blob: 537c5439dcec9b9d2f6be3ceeefdf0e7e64ff701 [file] [log] [blame]
egdaniel3658f382014-09-15 07:01:59 -07001/*
egdaniel8dd688b2015-01-22 10:16:09 -08002 * Copyright 2015 Google Inc.
egdaniel3658f382014-09-15 07:01:59 -07003 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
egdaniel8dd688b2015-01-22 10:16:09 -08008#include "GrPipeline.h"
egdaniel3658f382014-09-15 07:01:59 -07009
Brian Salomon652ecb52017-01-17 12:39:53 -050010#include "GrAppliedClip.h"
bsalomoneb1cb5c2015-05-22 08:01:09 -070011#include "GrCaps.h"
joshualitt4973d9d2014-11-08 09:24:25 -080012#include "GrGpu.h"
Brian Salomon652ecb52017-01-17 12:39:53 -050013#include "GrRenderTargetContext.h"
Robert Phillipsf2361d22016-10-25 14:20:06 -040014#include "GrRenderTargetOpList.h"
egdaniel95131432014-12-09 11:15:43 -080015#include "GrXferProcessor.h"
egdaniel3658f382014-09-15 07:01:59 -070016
Brian Salomon89527432016-12-16 09:52:16 -050017#include "ops/GrOp.h"
joshualitt74417822015-08-07 11:42:16 -070018
Brian Salomon49348902018-06-26 09:12:38 -040019GrPipeline::GrPipeline(const InitArgs& args,
20 GrProcessorSet&& processors,
Brian Salomonbfd18cd2017-08-09 16:27:09 -040021 GrAppliedClip&& appliedClip) {
Brian Salomon91326c32017-08-09 16:02:19 -040022 SkASSERT(processors.isFinalized());
Brian Salomon92aee3d2016-12-21 09:20:25 -050023
Brian Salomonb5cb6832017-02-24 11:01:15 -050024 fFlags = args.fFlags;
Brian Salomonbfd18cd2017-08-09 16:27:09 -040025 if (appliedClip.hasStencilClip()) {
26 fFlags |= kHasStencilClip_Flag;
Brian Salomon54d212e2017-03-21 14:22:38 -040027 }
Brian Salomond818ebf2018-07-02 14:08:49 +000028 if (appliedClip.scissorState().enabled()) {
Brian Salomon49348902018-06-26 09:12:38 -040029 fFlags |= kScissorEnabled_Flag;
30 }
31
Brian Salomonbfd18cd2017-08-09 16:27:09 -040032 fWindowRectsState = appliedClip.windowRectsState();
Brian Salomon54d212e2017-03-21 14:22:38 -040033 if (!args.fUserStencil->isDisabled(fFlags & kHasStencilClip_Flag)) {
34 fFlags |= kStencilEnabled_Flag;
35 }
36
37 fUserStencilSettings = args.fUserStencil;
38
Brian Salomon91326c32017-08-09 16:02:19 -040039 fXferProcessor = processors.refXferProcessor();
Brian Salomon189098e72017-01-19 09:55:19 -050040
Robert Phillipsbb581ce2017-05-29 15:05:15 -040041 if (args.fDstProxy.proxy()) {
42 if (!args.fDstProxy.proxy()->instantiate(args.fResourceProvider)) {
43 this->markAsBad();
44 }
45
46 fDstTextureProxy.reset(args.fDstProxy.proxy());
47 fDstTextureOffset = args.fDstProxy.offset();
Brian Salomon18dfa982017-04-03 16:57:43 -040048 }
Brian Salomon31853842017-03-28 16:32:05 -040049
Brian Salomone5b399e2017-07-19 13:50:54 -040050 // Copy GrFragmentProcessors from GrProcessorSet to Pipeline
Brian Salomon91326c32017-08-09 16:02:19 -040051 fNumColorProcessors = processors.numColorFragmentProcessors();
Chris Dalton69824002017-10-31 00:37:52 -060052 int numTotalProcessors = fNumColorProcessors +
53 processors.numCoverageFragmentProcessors() +
54 appliedClip.numClipCoverageFragmentProcessors();
Brian Salomonb5cb6832017-02-24 11:01:15 -050055 fFragmentProcessors.reset(numTotalProcessors);
bsalomonac856c92015-08-27 06:30:17 -070056 int currFPIdx = 0;
Brian Salomon91326c32017-08-09 16:02:19 -040057 for (int i = 0; i < processors.numColorFragmentProcessors(); ++i, ++currFPIdx) {
Brian Salomonaff329b2017-08-11 09:40:37 -040058 fFragmentProcessors[currFPIdx] = processors.detachColorFragmentProcessor(i);
59 if (!fFragmentProcessors[currFPIdx]->instantiate(args.fResourceProvider)) {
Robert Phillipsa91e0b72017-05-01 13:12:20 -040060 this->markAsBad();
61 }
bsalomonae59b772014-11-19 08:23:49 -080062 }
Brian Salomon91326c32017-08-09 16:02:19 -040063 for (int i = 0; i < processors.numCoverageFragmentProcessors(); ++i, ++currFPIdx) {
Brian Salomonaff329b2017-08-11 09:40:37 -040064 fFragmentProcessors[currFPIdx] = processors.detachCoverageFragmentProcessor(i);
65 if (!fFragmentProcessors[currFPIdx]->instantiate(args.fResourceProvider)) {
Robert Phillipsa91e0b72017-05-01 13:12:20 -040066 this->markAsBad();
67 }
egdaniel9cf45bf2014-10-08 06:49:10 -070068 }
Chris Dalton69824002017-10-31 00:37:52 -060069 for (int i = 0; i < appliedClip.numClipCoverageFragmentProcessors(); ++i, ++currFPIdx) {
70 fFragmentProcessors[currFPIdx] = appliedClip.detachClipCoverageFragmentProcessor(i);
Brian Salomonbfd18cd2017-08-09 16:27:09 -040071 if (!fFragmentProcessors[currFPIdx]->instantiate(args.fResourceProvider)) {
72 this->markAsBad();
Brian Salomon54d212e2017-03-21 14:22:38 -040073 }
Brian Salomon652ecb52017-01-17 12:39:53 -050074 }
egdanielc0648242014-09-22 13:17:02 -070075}
76
Robert Phillipsd261e102017-06-23 12:37:20 -040077void GrPipeline::addDependenciesTo(GrOpList* opList, const GrCaps& caps) const {
robertphillips498d7ac2015-10-30 10:11:30 -070078 for (int i = 0; i < fFragmentProcessors.count(); ++i) {
Robert Phillipsd261e102017-06-23 12:37:20 -040079 GrFragmentProcessor::TextureAccessIter iter(fFragmentProcessors[i].get());
Brian Salomone782f842018-07-31 13:53:11 -040080 while (const GrFragmentProcessor::TextureSampler* sampler = iter.next()) {
Robert Phillipsd261e102017-06-23 12:37:20 -040081 opList->addDependency(sampler->proxy(), caps);
82 }
robertphillips498d7ac2015-10-30 10:11:30 -070083 }
84
Robert Phillipsbb581ce2017-05-29 15:05:15 -040085 if (fDstTextureProxy) {
Robert Phillipsd261e102017-06-23 12:37:20 -040086 opList->addDependency(fDstTextureProxy.get(), caps);
robertphillips498d7ac2015-10-30 10:11:30 -070087 }
Robert Phillipsd261e102017-06-23 12:37:20 -040088
robertphillips498d7ac2015-10-30 10:11:30 -070089}
90
Robert Phillipsd0fe8752019-01-31 14:13:59 -050091GrXferBarrierType GrPipeline::xferBarrierType(GrTexture* texture, const GrCaps& caps) const {
92 if (fDstTextureProxy.get() && fDstTextureProxy.get()->peekTexture() == texture) {
Robert Phillipsc9c06d42017-06-12 10:58:31 -040093 return kTexture_GrXferBarrierType;
94 }
95 return this->getXferProcessor().xferBarrierType(caps);
96}
97
Robert Phillipsd0fe8752019-01-31 14:13:59 -050098GrPipeline::GrPipeline(GrScissorTest scissorTest, SkBlendMode blendmode)
99 : fWindowRectsState()
Robert Phillips2890fbf2017-07-26 15:48:41 -0400100 , fUserStencilSettings(&GrUserStencilSettings::kUnused)
101 , fFlags()
102 , fXferProcessor(GrPorterDuffXPFactory::MakeNoCoverageXP(blendmode))
103 , fFragmentProcessors()
104 , fNumColorProcessors(0) {
Chris Dalton916c4982018-08-15 00:53:25 -0600105 if (GrScissorTest::kEnabled == scissorTest) {
Brian Salomon49348902018-06-26 09:12:38 -0400106 fFlags |= kScissorEnabled_Flag;
Chris Dalton46983b72017-06-06 12:27:16 -0600107 }
108}