blob: a6e8fbad20603c00ecf8bfd5b049870358c53cf7 [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"
cdalton193d9cf2016-05-12 11:52:02 -070015#include "GrRenderTargetPriv.h"
egdaniel95131432014-12-09 11:15:43 -080016#include "GrXferProcessor.h"
egdaniel3658f382014-09-15 07:01:59 -070017
Brian Salomon89527432016-12-16 09:52:16 -050018#include "ops/GrOp.h"
joshualitt74417822015-08-07 11:42:16 -070019
Brian Salomonbfd18cd2017-08-09 16:27:09 -040020GrPipeline::GrPipeline(const InitArgs& args, GrProcessorSet&& processors,
21 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 fScissorState = appliedClip.scissorState();
29 if (appliedClip.hasStencilClip()) {
30 fFlags |= kHasStencilClip_Flag;
Brian Salomon54d212e2017-03-21 14:22:38 -040031 }
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();
Brian Salomoneec6f7b2017-02-10 14:29:38 -050052 int numTotalProcessors =
Brian Salomon91326c32017-08-09 16:02:19 -040053 fNumColorProcessors + processors.numCoverageFragmentProcessors();
Brian Salomonbfd18cd2017-08-09 16:27:09 -040054 auto clipFP = appliedClip.detachClipCoverageFragmentProcessor();
55 if (clipFP) {
Brian Salomon652ecb52017-01-17 12:39:53 -050056 ++numTotalProcessors;
57 }
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) {
61 const GrFragmentProcessor* fp = processors.colorFragmentProcessor(i);
Brian Salomonb5cb6832017-02-24 11:01:15 -050062 fFragmentProcessors[currFPIdx].reset(fp);
Robert Phillips9bee2e52017-05-29 12:37:20 -040063 if (!fp->instantiate(args.fResourceProvider)) {
Robert Phillipsa91e0b72017-05-01 13:12:20 -040064 this->markAsBad();
65 }
bsalomonae59b772014-11-19 08:23:49 -080066 }
egdaniel95131432014-12-09 11:15:43 -080067
Brian Salomon91326c32017-08-09 16:02:19 -040068 for (int i = 0; i < processors.numCoverageFragmentProcessors(); ++i, ++currFPIdx) {
69 const GrFragmentProcessor* fp = processors.coverageFragmentProcessor(i);
Brian Salomonb5cb6832017-02-24 11:01:15 -050070 fFragmentProcessors[currFPIdx].reset(fp);
Robert Phillips9bee2e52017-05-29 12:37:20 -040071 if (!fp->instantiate(args.fResourceProvider)) {
Robert Phillipsa91e0b72017-05-01 13:12:20 -040072 this->markAsBad();
73 }
egdaniel9cf45bf2014-10-08 06:49:10 -070074 }
Brian Salomonbfd18cd2017-08-09 16:27:09 -040075 if (clipFP) {
76 fFragmentProcessors[currFPIdx].reset(clipFP.get());
77 if (!fFragmentProcessors[currFPIdx]->instantiate(args.fResourceProvider)) {
78 this->markAsBad();
Brian Salomon54d212e2017-03-21 14:22:38 -040079 }
Brian Salomon652ecb52017-01-17 12:39:53 -050080 }
egdanielc0648242014-09-22 13:17:02 -070081}
82
Robert Phillipsd261e102017-06-23 12:37:20 -040083void GrPipeline::addDependenciesTo(GrOpList* opList, const GrCaps& caps) const {
robertphillips498d7ac2015-10-30 10:11:30 -070084 for (int i = 0; i < fFragmentProcessors.count(); ++i) {
Robert Phillipsd261e102017-06-23 12:37:20 -040085 GrFragmentProcessor::TextureAccessIter iter(fFragmentProcessors[i].get());
86 while (const GrResourceIOProcessor::TextureSampler* sampler = iter.next()) {
87 opList->addDependency(sampler->proxy(), caps);
88 }
robertphillips498d7ac2015-10-30 10:11:30 -070089 }
90
Robert Phillipsbb581ce2017-05-29 15:05:15 -040091 if (fDstTextureProxy) {
Robert Phillipsd261e102017-06-23 12:37:20 -040092 opList->addDependency(fDstTextureProxy.get(), caps);
robertphillips498d7ac2015-10-30 10:11:30 -070093 }
Robert Phillipsd261e102017-06-23 12:37:20 -040094
robertphillips498d7ac2015-10-30 10:11:30 -070095}
96
Robert Phillipsc9c06d42017-06-12 10:58:31 -040097GrXferBarrierType GrPipeline::xferBarrierType(const GrCaps& caps) const {
98 if (fDstTextureProxy.get() &&
Robert Phillips2890fbf2017-07-26 15:48:41 -040099 fDstTextureProxy.get()->priv().peekTexture() == fProxy.get()->priv().peekTexture()) {
Robert Phillipsc9c06d42017-06-12 10:58:31 -0400100 return kTexture_GrXferBarrierType;
101 }
102 return this->getXferProcessor().xferBarrierType(caps);
103}
104
Robert Phillips2890fbf2017-07-26 15:48:41 -0400105GrPipeline::GrPipeline(GrRenderTargetProxy* proxy, ScissorState scissorState, SkBlendMode blendmode)
106 : fProxy(proxy)
107 , fScissorState()
108 , fWindowRectsState()
109 , fUserStencilSettings(&GrUserStencilSettings::kUnused)
110 , fFlags()
111 , fXferProcessor(GrPorterDuffXPFactory::MakeNoCoverageXP(blendmode))
112 , fFragmentProcessors()
113 , fNumColorProcessors(0) {
Brian Salomonf3ce7e32017-07-31 16:07:39 -0400114 SkASSERT(proxy);
Chris Dalton46983b72017-06-06 12:27:16 -0600115 if (ScissorState::kEnabled == scissorState) {
116 fScissorState.set({0, 0, 0, 0}); // caller will use the DynamicState struct.
117 }
118}