blob: 7c0338c77c0323bd7bf18fb009ba21a615112242 [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"
egdaniel8dd688b2015-01-22 10:16:09 -080013#include "GrPipelineBuilder.h"
Brian Salomon652ecb52017-01-17 12:39:53 -050014#include "GrRenderTargetContext.h"
Robert Phillipsf2361d22016-10-25 14:20:06 -040015#include "GrRenderTargetOpList.h"
cdalton193d9cf2016-05-12 11:52:02 -070016#include "GrRenderTargetPriv.h"
egdaniel95131432014-12-09 11:15:43 -080017#include "GrXferProcessor.h"
egdaniel3658f382014-09-15 07:01:59 -070018
Brian Salomon89527432016-12-16 09:52:16 -050019#include "ops/GrOp.h"
joshualitt74417822015-08-07 11:42:16 -070020
Brian Salomone7d30482017-03-29 12:09:15 -040021void GrPipeline::init(const InitArgs& args) {
Brian Salomonb16e8ac2017-02-22 11:52:36 -050022 SkASSERT(args.fRenderTarget);
Brian Salomon48d1b4c2017-04-08 07:38:53 -040023 SkASSERT(args.fProcessors);
24 SkASSERT(args.fProcessors->isFinalized());
Brian Salomon92aee3d2016-12-21 09:20:25 -050025
Brian Salomonb5cb6832017-02-24 11:01:15 -050026 fRenderTarget.reset(args.fRenderTarget);
cdalton93a379b2016-05-11 13:58:08 -070027
Brian Salomonb5cb6832017-02-24 11:01:15 -050028 fFlags = args.fFlags;
Brian Salomon54d212e2017-03-21 14:22:38 -040029 if (args.fAppliedClip) {
30 fScissorState = args.fAppliedClip->scissorState();
31 if (args.fAppliedClip->hasStencilClip()) {
32 fFlags |= kHasStencilClip_Flag;
33 }
34 fWindowRectsState = args.fAppliedClip->windowRectsState();
35 }
Brian Salomon189098e72017-01-19 09:55:19 -050036 if (args.fProcessors->usesDistanceVectorField()) {
Brian Salomonb5cb6832017-02-24 11:01:15 -050037 fFlags |= kUsesDistanceVectorField_Flag;
dvonbeck9b03e7b2016-08-01 11:01:56 -070038 }
Brian Salomon54d212e2017-03-21 14:22:38 -040039 if (!args.fUserStencil->isDisabled(fFlags & kHasStencilClip_Flag)) {
40 fFlags |= kStencilEnabled_Flag;
41 }
42
43 fUserStencilSettings = args.fUserStencil;
44
Brian Salomond61c9d92017-04-10 10:54:25 -040045 fXferProcessor = args.fProcessors->refXferProcessor();
Brian Salomon189098e72017-01-19 09:55:19 -050046
Robert Phillipsc3757042017-05-17 13:00:14 +000047 if (args.fDstTexture.texture()) {
48 fDstTexture.reset(args.fDstTexture.texture());
49 fDstTextureOffset = args.fDstTexture.offset();
Brian Salomon18dfa982017-04-03 16:57:43 -040050 }
Brian Salomon31853842017-03-28 16:32:05 -040051
Brian Salomoneec6f7b2017-02-10 14:29:38 -050052 // Copy GrFragmentProcessors from GrPipelineBuilder to Pipeline, possibly removing some of the
53 // color fragment processors.
Brian Salomone14bd802017-04-04 15:13:25 -040054 fNumColorProcessors = args.fProcessors->numColorFragmentProcessors();
Brian Salomoneec6f7b2017-02-10 14:29:38 -050055 int numTotalProcessors =
Brian Salomonb5cb6832017-02-24 11:01:15 -050056 fNumColorProcessors + args.fProcessors->numCoverageFragmentProcessors();
Brian Salomon54d212e2017-03-21 14:22:38 -040057 if (args.fAppliedClip && args.fAppliedClip->clipCoverageFragmentProcessor()) {
Brian Salomon652ecb52017-01-17 12:39:53 -050058 ++numTotalProcessors;
59 }
Brian Salomonb5cb6832017-02-24 11:01:15 -050060 fFragmentProcessors.reset(numTotalProcessors);
bsalomonac856c92015-08-27 06:30:17 -070061 int currFPIdx = 0;
Brian Salomone14bd802017-04-04 15:13:25 -040062 for (int i = 0; i < args.fProcessors->numColorFragmentProcessors(); ++i, ++currFPIdx) {
Brian Salomon189098e72017-01-19 09:55:19 -050063 const GrFragmentProcessor* fp = args.fProcessors->colorFragmentProcessor(i);
Brian Salomonb5cb6832017-02-24 11:01:15 -050064 fFragmentProcessors[currFPIdx].reset(fp);
Robert Phillipsa91e0b72017-05-01 13:12:20 -040065 if (fp->isBad()) {
66 this->markAsBad();
67 }
bsalomonae59b772014-11-19 08:23:49 -080068 }
egdaniel95131432014-12-09 11:15:43 -080069
Brian Salomoneec6f7b2017-02-10 14:29:38 -050070 for (int i = 0; i < args.fProcessors->numCoverageFragmentProcessors(); ++i, ++currFPIdx) {
Brian Salomon189098e72017-01-19 09:55:19 -050071 const GrFragmentProcessor* fp = args.fProcessors->coverageFragmentProcessor(i);
Brian Salomonb5cb6832017-02-24 11:01:15 -050072 fFragmentProcessors[currFPIdx].reset(fp);
Robert Phillipsa91e0b72017-05-01 13:12:20 -040073 if (fp->isBad()) {
74 this->markAsBad();
75 }
egdaniel9cf45bf2014-10-08 06:49:10 -070076 }
Brian Salomon54d212e2017-03-21 14:22:38 -040077 if (args.fAppliedClip) {
78 if (const GrFragmentProcessor* fp = args.fAppliedClip->clipCoverageFragmentProcessor()) {
79 fFragmentProcessors[currFPIdx].reset(fp);
Robert Phillipsa91e0b72017-05-01 13:12:20 -040080 if (fp->isBad()) {
81 this->markAsBad();
82 }
Brian Salomon54d212e2017-03-21 14:22:38 -040083 }
Brian Salomon652ecb52017-01-17 12:39:53 -050084 }
egdanielc0648242014-09-22 13:17:02 -070085}
86
Robert Phillipsc589b0b2017-04-17 07:53:07 -040087// MDB TODO: re-enable when TextureSamplers store texture proxies
88#if 0
89static void add_dependencies_for_processor(const GrFragmentProcessor* proc,
90 GrRenderTargetProxy* rtp) {
bsalomonb58a2b42016-09-26 06:55:02 -070091 GrFragmentProcessor::TextureAccessIter iter(proc);
Brian Salomonab015ef2017-04-04 10:15:51 -040092 while (const GrResourceIOProcessor::TextureSampler* sampler = iter.next()) {
Robert Phillipsc589b0b2017-04-17 07:53:07 -040093 SkASSERT(rtp->getLastOpList());
Robert Phillipsc3757042017-05-17 13:00:14 +000094 rtp->getLastOpList()->addDependency(sampler->texture());
robertphillips498d7ac2015-10-30 10:11:30 -070095 }
96}
Robert Phillipsc589b0b2017-04-17 07:53:07 -040097#endif
robertphillips498d7ac2015-10-30 10:11:30 -070098
Robert Phillipsc589b0b2017-04-17 07:53:07 -040099void GrPipeline::addDependenciesTo(GrRenderTargetProxy* rtp) const {
100 // MDB TODO: re-enable when TextureSamplers store texture proxies
101#if 0
robertphillips498d7ac2015-10-30 10:11:30 -0700102 for (int i = 0; i < fFragmentProcessors.count(); ++i) {
Robert Phillipsc589b0b2017-04-17 07:53:07 -0400103 add_dependencies_for_processor(fFragmentProcessors[i].get(), rtp);
robertphillips498d7ac2015-10-30 10:11:30 -0700104 }
Robert Phillipsc589b0b2017-04-17 07:53:07 -0400105#endif
robertphillips498d7ac2015-10-30 10:11:30 -0700106
Robert Phillipsc3757042017-05-17 13:00:14 +0000107 if (fDstTexture) {
108 //SkASSERT(rtp->getLastOpList());
Robert Phillipsc589b0b2017-04-17 07:53:07 -0400109 // MDB TODO: re-enable when TextureSamplers store texture proxies
110 //rtp->getLastOpList()->addDependency(fDstTexture.get());
robertphillips498d7ac2015-10-30 10:11:30 -0700111 }
112}
113
csmartdalton119fb2b2017-02-08 14:41:05 -0500114GrPipeline::GrPipeline(GrRenderTarget* rt, SkBlendMode blendmode)
Brian Salomond61c9d92017-04-10 10:54:25 -0400115 : fRenderTarget(rt)
116 , fScissorState()
117 , fWindowRectsState()
118 , fUserStencilSettings(&GrUserStencilSettings::kUnused)
Brian Salomond61c9d92017-04-10 10:54:25 -0400119 , fFlags()
120 , fXferProcessor(GrPorterDuffXPFactory::MakeNoCoverageXP(blendmode))
121 , fFragmentProcessors()
122 , fNumColorProcessors(0) {}
csmartdalton119fb2b2017-02-08 14:41:05 -0500123
egdaniel89af44a2014-09-26 06:15:04 -0700124////////////////////////////////////////////////////////////////////////////////
125
bsalomon7312ff82016-09-12 08:55:38 -0700126bool GrPipeline::AreEqual(const GrPipeline& a, const GrPipeline& b) {
bsalomoncb02b382015-08-12 11:14:50 -0700127 SkASSERT(&a != &b);
joshualitt8cab9a72015-07-16 09:13:50 -0700128
bsalomoncb02b382015-08-12 11:14:50 -0700129 if (a.getRenderTarget() != b.getRenderTarget() ||
bsalomonac856c92015-08-27 06:30:17 -0700130 a.fFragmentProcessors.count() != b.fFragmentProcessors.count() ||
131 a.fNumColorProcessors != b.fNumColorProcessors ||
bsalomoncb02b382015-08-12 11:14:50 -0700132 a.fScissorState != b.fScissorState ||
Brian Salomon9a767722017-03-13 17:57:28 -0400133 a.fWindowRectsState != b.fWindowRectsState ||
bsalomoncb02b382015-08-12 11:14:50 -0700134 a.fFlags != b.fFlags ||
Robert Phillips6410d292017-05-09 08:15:18 -0400135 a.fUserStencilSettings != b.fUserStencilSettings) {
egdaniel89af44a2014-09-26 06:15:04 -0700136 return false;
137 }
138
bsalomon2047b782015-12-21 13:12:54 -0800139 // Most of the time both are nullptr
140 if (a.fXferProcessor.get() || b.fXferProcessor.get()) {
141 if (!a.getXferProcessor().isEqual(b.getXferProcessor())) {
142 return false;
143 }
egdanielc2304142014-12-11 13:15:13 -0800144 }
145
bsalomonac856c92015-08-27 06:30:17 -0700146 for (int i = 0; i < a.numFragmentProcessors(); i++) {
bsalomon7312ff82016-09-12 08:55:38 -0700147 if (!a.getFragmentProcessor(i).isEqual(b.getFragmentProcessor(i))) {
egdaniel89af44a2014-09-26 06:15:04 -0700148 return false;
149 }
150 }
egdaniel89af44a2014-09-26 06:15:04 -0700151 return true;
152}