blob: 8e91d8133be5f2c85ba5a52a4499abab1b612154 [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 Salomon972b2f62017-07-31 12:37:02 -040020GrPipeline::GrPipeline(const InitArgs& args) {
Robert Phillips2890fbf2017-07-26 15:48:41 -040021 SkASSERT(args.fProxy);
Brian Salomon48d1b4c2017-04-08 07:38:53 -040022 SkASSERT(args.fProcessors);
23 SkASSERT(args.fProcessors->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 Salomon54d212e2017-03-21 14:22:38 -040028 if (args.fAppliedClip) {
29 fScissorState = args.fAppliedClip->scissorState();
30 if (args.fAppliedClip->hasStencilClip()) {
31 fFlags |= kHasStencilClip_Flag;
32 }
33 fWindowRectsState = args.fAppliedClip->windowRectsState();
34 }
Brian Salomon54d212e2017-03-21 14:22:38 -040035 if (!args.fUserStencil->isDisabled(fFlags & kHasStencilClip_Flag)) {
36 fFlags |= kStencilEnabled_Flag;
37 }
38
39 fUserStencilSettings = args.fUserStencil;
40
Brian Salomond61c9d92017-04-10 10:54:25 -040041 fXferProcessor = args.fProcessors->refXferProcessor();
Brian Salomon189098e72017-01-19 09:55:19 -050042
Robert Phillipsbb581ce2017-05-29 15:05:15 -040043 if (args.fDstProxy.proxy()) {
44 if (!args.fDstProxy.proxy()->instantiate(args.fResourceProvider)) {
45 this->markAsBad();
46 }
47
48 fDstTextureProxy.reset(args.fDstProxy.proxy());
49 fDstTextureOffset = args.fDstProxy.offset();
Brian Salomon18dfa982017-04-03 16:57:43 -040050 }
Brian Salomon31853842017-03-28 16:32:05 -040051
Brian Salomone5b399e2017-07-19 13:50:54 -040052 // Copy GrFragmentProcessors from GrProcessorSet to Pipeline
Brian Salomone14bd802017-04-04 15:13:25 -040053 fNumColorProcessors = args.fProcessors->numColorFragmentProcessors();
Brian Salomoneec6f7b2017-02-10 14:29:38 -050054 int numTotalProcessors =
Brian Salomonb5cb6832017-02-24 11:01:15 -050055 fNumColorProcessors + args.fProcessors->numCoverageFragmentProcessors();
Brian Salomon54d212e2017-03-21 14:22:38 -040056 if (args.fAppliedClip && args.fAppliedClip->clipCoverageFragmentProcessor()) {
Brian Salomon652ecb52017-01-17 12:39:53 -050057 ++numTotalProcessors;
58 }
Brian Salomonb5cb6832017-02-24 11:01:15 -050059 fFragmentProcessors.reset(numTotalProcessors);
bsalomonac856c92015-08-27 06:30:17 -070060 int currFPIdx = 0;
Brian Salomone14bd802017-04-04 15:13:25 -040061 for (int i = 0; i < args.fProcessors->numColorFragmentProcessors(); ++i, ++currFPIdx) {
Brian Salomon189098e72017-01-19 09:55:19 -050062 const GrFragmentProcessor* fp = args.fProcessors->colorFragmentProcessor(i);
Brian Salomonb5cb6832017-02-24 11:01:15 -050063 fFragmentProcessors[currFPIdx].reset(fp);
Robert Phillips9bee2e52017-05-29 12:37:20 -040064 if (!fp->instantiate(args.fResourceProvider)) {
Robert Phillipsa91e0b72017-05-01 13:12:20 -040065 this->markAsBad();
66 }
bsalomonae59b772014-11-19 08:23:49 -080067 }
egdaniel95131432014-12-09 11:15:43 -080068
Brian Salomoneec6f7b2017-02-10 14:29:38 -050069 for (int i = 0; i < args.fProcessors->numCoverageFragmentProcessors(); ++i, ++currFPIdx) {
Brian Salomon189098e72017-01-19 09:55:19 -050070 const GrFragmentProcessor* fp = args.fProcessors->coverageFragmentProcessor(i);
Brian Salomonb5cb6832017-02-24 11:01:15 -050071 fFragmentProcessors[currFPIdx].reset(fp);
Robert Phillips9bee2e52017-05-29 12:37:20 -040072 if (!fp->instantiate(args.fResourceProvider)) {
Robert Phillipsa91e0b72017-05-01 13:12:20 -040073 this->markAsBad();
74 }
egdaniel9cf45bf2014-10-08 06:49:10 -070075 }
Brian Salomon54d212e2017-03-21 14:22:38 -040076 if (args.fAppliedClip) {
77 if (const GrFragmentProcessor* fp = args.fAppliedClip->clipCoverageFragmentProcessor()) {
78 fFragmentProcessors[currFPIdx].reset(fp);
Robert Phillips9bee2e52017-05-29 12:37:20 -040079 if (!fp->instantiate(args.fResourceProvider)) {
Robert Phillipsa91e0b72017-05-01 13:12:20 -040080 this->markAsBad();
81 }
Brian Salomon54d212e2017-03-21 14:22:38 -040082 }
Brian Salomon652ecb52017-01-17 12:39:53 -050083 }
egdanielc0648242014-09-22 13:17:02 -070084}
85
Robert Phillipsd261e102017-06-23 12:37:20 -040086void GrPipeline::addDependenciesTo(GrOpList* opList, const GrCaps& caps) const {
robertphillips498d7ac2015-10-30 10:11:30 -070087 for (int i = 0; i < fFragmentProcessors.count(); ++i) {
Robert Phillipsd261e102017-06-23 12:37:20 -040088 GrFragmentProcessor::TextureAccessIter iter(fFragmentProcessors[i].get());
89 while (const GrResourceIOProcessor::TextureSampler* sampler = iter.next()) {
90 opList->addDependency(sampler->proxy(), caps);
91 }
robertphillips498d7ac2015-10-30 10:11:30 -070092 }
93
Robert Phillipsbb581ce2017-05-29 15:05:15 -040094 if (fDstTextureProxy) {
Robert Phillipsd261e102017-06-23 12:37:20 -040095 opList->addDependency(fDstTextureProxy.get(), caps);
robertphillips498d7ac2015-10-30 10:11:30 -070096 }
Robert Phillipsd261e102017-06-23 12:37:20 -040097
robertphillips498d7ac2015-10-30 10:11:30 -070098}
99
Robert Phillipsc9c06d42017-06-12 10:58:31 -0400100GrXferBarrierType GrPipeline::xferBarrierType(const GrCaps& caps) const {
101 if (fDstTextureProxy.get() &&
Robert Phillips2890fbf2017-07-26 15:48:41 -0400102 fDstTextureProxy.get()->priv().peekTexture() == fProxy.get()->priv().peekTexture()) {
Robert Phillipsc9c06d42017-06-12 10:58:31 -0400103 return kTexture_GrXferBarrierType;
104 }
105 return this->getXferProcessor().xferBarrierType(caps);
106}
107
Robert Phillips2890fbf2017-07-26 15:48:41 -0400108GrPipeline::GrPipeline(GrRenderTargetProxy* proxy, ScissorState scissorState, SkBlendMode blendmode)
109 : fProxy(proxy)
110 , fScissorState()
111 , fWindowRectsState()
112 , fUserStencilSettings(&GrUserStencilSettings::kUnused)
113 , fFlags()
114 , fXferProcessor(GrPorterDuffXPFactory::MakeNoCoverageXP(blendmode))
115 , fFragmentProcessors()
116 , fNumColorProcessors(0) {
Brian Salomonf3ce7e32017-07-31 16:07:39 -0400117 SkASSERT(proxy);
Chris Dalton46983b72017-06-06 12:27:16 -0600118 if (ScissorState::kEnabled == scissorState) {
119 fScissorState.set({0, 0, 0, 0}); // caller will use the DynamicState struct.
120 }
121}