blob: c671922808914b7dd8e0d8e1cb8810d41a9d214f [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) {
Robert Phillips2890fbf2017-07-26 15:48:41 -040022 SkASSERT(args.fProxy);
Brian Salomon91326c32017-08-09 16:02:19 -040023 SkASSERT(processors.isFinalized());
Brian Salomon92aee3d2016-12-21 09:20:25 -050024
Robert Phillips2890fbf2017-07-26 15:48:41 -040025 fProxy.reset(args.fProxy);
cdalton93a379b2016-05-11 13:58:08 -070026
Brian Salomonb5cb6832017-02-24 11:01:15 -050027 fFlags = args.fFlags;
Brian Salomonbfd18cd2017-08-09 16:27:09 -040028 if (appliedClip.hasStencilClip()) {
29 fFlags |= kHasStencilClip_Flag;
Brian Salomon54d212e2017-03-21 14:22:38 -040030 }
Brian Salomond818ebf2018-07-02 14:08:49 +000031 if (appliedClip.scissorState().enabled()) {
Brian Salomon49348902018-06-26 09:12:38 -040032 fFlags |= kScissorEnabled_Flag;
33 }
34
Brian Salomonbfd18cd2017-08-09 16:27:09 -040035 fWindowRectsState = appliedClip.windowRectsState();
Brian Salomon54d212e2017-03-21 14:22:38 -040036 if (!args.fUserStencil->isDisabled(fFlags & kHasStencilClip_Flag)) {
37 fFlags |= kStencilEnabled_Flag;
38 }
39
40 fUserStencilSettings = args.fUserStencil;
41
Brian Salomon91326c32017-08-09 16:02:19 -040042 fXferProcessor = processors.refXferProcessor();
Brian Salomon189098e72017-01-19 09:55:19 -050043
Robert Phillipsbb581ce2017-05-29 15:05:15 -040044 if (args.fDstProxy.proxy()) {
45 if (!args.fDstProxy.proxy()->instantiate(args.fResourceProvider)) {
46 this->markAsBad();
47 }
48
49 fDstTextureProxy.reset(args.fDstProxy.proxy());
50 fDstTextureOffset = args.fDstProxy.offset();
Brian Salomon18dfa982017-04-03 16:57:43 -040051 }
Brian Salomon31853842017-03-28 16:32:05 -040052
Brian Salomone5b399e2017-07-19 13:50:54 -040053 // Copy GrFragmentProcessors from GrProcessorSet to Pipeline
Brian Salomon91326c32017-08-09 16:02:19 -040054 fNumColorProcessors = processors.numColorFragmentProcessors();
Chris Dalton69824002017-10-31 00:37:52 -060055 int numTotalProcessors = fNumColorProcessors +
56 processors.numCoverageFragmentProcessors() +
57 appliedClip.numClipCoverageFragmentProcessors();
Brian Salomonb5cb6832017-02-24 11:01:15 -050058 fFragmentProcessors.reset(numTotalProcessors);
bsalomonac856c92015-08-27 06:30:17 -070059 int currFPIdx = 0;
Brian Salomon91326c32017-08-09 16:02:19 -040060 for (int i = 0; i < processors.numColorFragmentProcessors(); ++i, ++currFPIdx) {
Brian Salomonaff329b2017-08-11 09:40:37 -040061 fFragmentProcessors[currFPIdx] = processors.detachColorFragmentProcessor(i);
62 if (!fFragmentProcessors[currFPIdx]->instantiate(args.fResourceProvider)) {
Robert Phillipsa91e0b72017-05-01 13:12:20 -040063 this->markAsBad();
64 }
bsalomonae59b772014-11-19 08:23:49 -080065 }
Brian Salomon91326c32017-08-09 16:02:19 -040066 for (int i = 0; i < processors.numCoverageFragmentProcessors(); ++i, ++currFPIdx) {
Brian Salomonaff329b2017-08-11 09:40:37 -040067 fFragmentProcessors[currFPIdx] = processors.detachCoverageFragmentProcessor(i);
68 if (!fFragmentProcessors[currFPIdx]->instantiate(args.fResourceProvider)) {
Robert Phillipsa91e0b72017-05-01 13:12:20 -040069 this->markAsBad();
70 }
egdaniel9cf45bf2014-10-08 06:49:10 -070071 }
Chris Dalton69824002017-10-31 00:37:52 -060072 for (int i = 0; i < appliedClip.numClipCoverageFragmentProcessors(); ++i, ++currFPIdx) {
73 fFragmentProcessors[currFPIdx] = appliedClip.detachClipCoverageFragmentProcessor(i);
Brian Salomonbfd18cd2017-08-09 16:27:09 -040074 if (!fFragmentProcessors[currFPIdx]->instantiate(args.fResourceProvider)) {
75 this->markAsBad();
Brian Salomon54d212e2017-03-21 14:22:38 -040076 }
Brian Salomon652ecb52017-01-17 12:39:53 -050077 }
egdanielc0648242014-09-22 13:17:02 -070078}
79
Robert Phillipsd261e102017-06-23 12:37:20 -040080void GrPipeline::addDependenciesTo(GrOpList* opList, const GrCaps& caps) const {
robertphillips498d7ac2015-10-30 10:11:30 -070081 for (int i = 0; i < fFragmentProcessors.count(); ++i) {
Robert Phillipsd261e102017-06-23 12:37:20 -040082 GrFragmentProcessor::TextureAccessIter iter(fFragmentProcessors[i].get());
Brian Salomone782f842018-07-31 13:53:11 -040083 while (const GrFragmentProcessor::TextureSampler* sampler = iter.next()) {
Robert Phillipsd261e102017-06-23 12:37:20 -040084 opList->addDependency(sampler->proxy(), caps);
85 }
robertphillips498d7ac2015-10-30 10:11:30 -070086 }
87
Robert Phillipsbb581ce2017-05-29 15:05:15 -040088 if (fDstTextureProxy) {
Robert Phillipsd261e102017-06-23 12:37:20 -040089 opList->addDependency(fDstTextureProxy.get(), caps);
robertphillips498d7ac2015-10-30 10:11:30 -070090 }
Robert Phillipsd261e102017-06-23 12:37:20 -040091
robertphillips498d7ac2015-10-30 10:11:30 -070092}
93
Robert Phillipsc9c06d42017-06-12 10:58:31 -040094GrXferBarrierType GrPipeline::xferBarrierType(const GrCaps& caps) const {
95 if (fDstTextureProxy.get() &&
Brian Salomonfd98c2c2018-07-31 17:25:29 -040096 fDstTextureProxy.get()->peekTexture() == fProxy.get()->peekTexture()) {
Robert Phillipsc9c06d42017-06-12 10:58:31 -040097 return kTexture_GrXferBarrierType;
98 }
99 return this->getXferProcessor().xferBarrierType(caps);
100}
101
Chris Dalton916c4982018-08-15 00:53:25 -0600102GrPipeline::GrPipeline(GrRenderTargetProxy* proxy, GrScissorTest scissorTest, SkBlendMode blendmode)
Robert Phillips2890fbf2017-07-26 15:48:41 -0400103 : fProxy(proxy)
Robert Phillips2890fbf2017-07-26 15:48:41 -0400104 , fWindowRectsState()
105 , fUserStencilSettings(&GrUserStencilSettings::kUnused)
106 , fFlags()
107 , fXferProcessor(GrPorterDuffXPFactory::MakeNoCoverageXP(blendmode))
108 , fFragmentProcessors()
109 , fNumColorProcessors(0) {
Brian Salomonf3ce7e32017-07-31 16:07:39 -0400110 SkASSERT(proxy);
Chris Dalton916c4982018-08-15 00:53:25 -0600111 if (GrScissorTest::kEnabled == scissorTest) {
Brian Salomon49348902018-06-26 09:12:38 -0400112 fFlags |= kScissorEnabled_Flag;
Chris Dalton46983b72017-06-06 12:27:16 -0600113 }
114}