blob: a0eceb32af0d950363bce8ba1685ec302fa6ed23 [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 Salomonbfd18cd2017-08-09 16:27:09 -040019GrPipeline::GrPipeline(const InitArgs& args, GrProcessorSet&& processors,
20 GrAppliedClip&& appliedClip) {
Robert Phillips2890fbf2017-07-26 15:48:41 -040021 SkASSERT(args.fProxy);
Brian Salomon91326c32017-08-09 16:02:19 -040022 SkASSERT(processors.isFinalized());
Brian Salomon92aee3d2016-12-21 09:20:25 -050023
Robert Phillips2890fbf2017-07-26 15:48:41 -040024 fProxy.reset(args.fProxy);
cdalton93a379b2016-05-11 13:58:08 -070025
Brian Salomonb5cb6832017-02-24 11:01:15 -050026 fFlags = args.fFlags;
Brian Salomonbfd18cd2017-08-09 16:27:09 -040027 fScissorState = appliedClip.scissorState();
28 if (appliedClip.hasStencilClip()) {
29 fFlags |= kHasStencilClip_Flag;
Brian Salomon54d212e2017-03-21 14:22:38 -040030 }
Brian Salomonbfd18cd2017-08-09 16:27:09 -040031 fWindowRectsState = appliedClip.windowRectsState();
Brian Salomon54d212e2017-03-21 14:22:38 -040032 if (!args.fUserStencil->isDisabled(fFlags & kHasStencilClip_Flag)) {
33 fFlags |= kStencilEnabled_Flag;
34 }
35
36 fUserStencilSettings = args.fUserStencil;
37
Brian Salomon91326c32017-08-09 16:02:19 -040038 fXferProcessor = processors.refXferProcessor();
Brian Salomon189098e72017-01-19 09:55:19 -050039
Robert Phillipsbb581ce2017-05-29 15:05:15 -040040 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 Salomon18dfa982017-04-03 16:57:43 -040047 }
Brian Salomon31853842017-03-28 16:32:05 -040048
Brian Salomone5b399e2017-07-19 13:50:54 -040049 // Copy GrFragmentProcessors from GrProcessorSet to Pipeline
Brian Salomon91326c32017-08-09 16:02:19 -040050 fNumColorProcessors = processors.numColorFragmentProcessors();
Chris Dalton69824002017-10-31 00:37:52 -060051 int numTotalProcessors = fNumColorProcessors +
52 processors.numCoverageFragmentProcessors() +
53 appliedClip.numClipCoverageFragmentProcessors();
Brian Salomonb5cb6832017-02-24 11:01:15 -050054 fFragmentProcessors.reset(numTotalProcessors);
bsalomonac856c92015-08-27 06:30:17 -070055 int currFPIdx = 0;
Brian Salomon91326c32017-08-09 16:02:19 -040056 for (int i = 0; i < processors.numColorFragmentProcessors(); ++i, ++currFPIdx) {
Brian Salomonaff329b2017-08-11 09:40:37 -040057 fFragmentProcessors[currFPIdx] = processors.detachColorFragmentProcessor(i);
58 if (!fFragmentProcessors[currFPIdx]->instantiate(args.fResourceProvider)) {
Robert Phillipsa91e0b72017-05-01 13:12:20 -040059 this->markAsBad();
60 }
bsalomonae59b772014-11-19 08:23:49 -080061 }
Brian Salomon91326c32017-08-09 16:02:19 -040062 for (int i = 0; i < processors.numCoverageFragmentProcessors(); ++i, ++currFPIdx) {
Brian Salomonaff329b2017-08-11 09:40:37 -040063 fFragmentProcessors[currFPIdx] = processors.detachCoverageFragmentProcessor(i);
64 if (!fFragmentProcessors[currFPIdx]->instantiate(args.fResourceProvider)) {
Robert Phillipsa91e0b72017-05-01 13:12:20 -040065 this->markAsBad();
66 }
egdaniel9cf45bf2014-10-08 06:49:10 -070067 }
Chris Dalton69824002017-10-31 00:37:52 -060068 for (int i = 0; i < appliedClip.numClipCoverageFragmentProcessors(); ++i, ++currFPIdx) {
69 fFragmentProcessors[currFPIdx] = appliedClip.detachClipCoverageFragmentProcessor(i);
Brian Salomonbfd18cd2017-08-09 16:27:09 -040070 if (!fFragmentProcessors[currFPIdx]->instantiate(args.fResourceProvider)) {
71 this->markAsBad();
Brian Salomon54d212e2017-03-21 14:22:38 -040072 }
Brian Salomon652ecb52017-01-17 12:39:53 -050073 }
egdanielc0648242014-09-22 13:17:02 -070074}
75
Robert Phillipsd261e102017-06-23 12:37:20 -040076void GrPipeline::addDependenciesTo(GrOpList* opList, const GrCaps& caps) const {
robertphillips498d7ac2015-10-30 10:11:30 -070077 for (int i = 0; i < fFragmentProcessors.count(); ++i) {
Robert Phillipsd261e102017-06-23 12:37:20 -040078 GrFragmentProcessor::TextureAccessIter iter(fFragmentProcessors[i].get());
79 while (const GrResourceIOProcessor::TextureSampler* sampler = iter.next()) {
80 opList->addDependency(sampler->proxy(), caps);
81 }
robertphillips498d7ac2015-10-30 10:11:30 -070082 }
83
Robert Phillipsbb581ce2017-05-29 15:05:15 -040084 if (fDstTextureProxy) {
Robert Phillipsd261e102017-06-23 12:37:20 -040085 opList->addDependency(fDstTextureProxy.get(), caps);
robertphillips498d7ac2015-10-30 10:11:30 -070086 }
Robert Phillipsd261e102017-06-23 12:37:20 -040087
robertphillips498d7ac2015-10-30 10:11:30 -070088}
89
Robert Phillipsc9c06d42017-06-12 10:58:31 -040090GrXferBarrierType GrPipeline::xferBarrierType(const GrCaps& caps) const {
91 if (fDstTextureProxy.get() &&
Robert Phillips2890fbf2017-07-26 15:48:41 -040092 fDstTextureProxy.get()->priv().peekTexture() == fProxy.get()->priv().peekTexture()) {
Robert Phillipsc9c06d42017-06-12 10:58:31 -040093 return kTexture_GrXferBarrierType;
94 }
95 return this->getXferProcessor().xferBarrierType(caps);
96}
97
Robert Phillips2890fbf2017-07-26 15:48:41 -040098GrPipeline::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 Salomonf3ce7e32017-07-31 16:07:39 -0400107 SkASSERT(proxy);
Chris Dalton46983b72017-06-06 12:27:16 -0600108 if (ScissorState::kEnabled == scissorState) {
109 fScissorState.set({0, 0, 0, 0}); // caller will use the DynamicState struct.
110 }
111}