1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "GrPipeline.h"
9
10 #include "GrAppliedClip.h"
11 #include "GrCaps.h"
12 #include "GrGpu.h"
13 #include "GrRenderTargetContext.h"
14 #include "GrRenderTargetOpList.h"
15 #include "GrXferProcessor.h"
16
17 #include "ops/GrOp.h"
18
GrPipeline(const InitArgs & args,GrProcessorSet && processors,GrAppliedClip && appliedClip)19 GrPipeline::GrPipeline(const InitArgs& args,
20 GrProcessorSet&& processors,
21 GrAppliedClip&& appliedClip) {
22 SkASSERT(processors.isFinalized());
23
24 fFlags = args.fFlags;
25 if (appliedClip.hasStencilClip()) {
26 fFlags |= kHasStencilClip_Flag;
27 }
28 if (appliedClip.scissorState().enabled()) {
29 fFlags |= kScissorEnabled_Flag;
30 }
31
32 fWindowRectsState = appliedClip.windowRectsState();
33 if (!args.fUserStencil->isDisabled(fFlags & kHasStencilClip_Flag)) {
34 fFlags |= kStencilEnabled_Flag;
35 }
36
37 fUserStencilSettings = args.fUserStencil;
38
39 fXferProcessor = processors.refXferProcessor();
40
41 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();
48 }
49
50 // Copy GrFragmentProcessors from GrProcessorSet to Pipeline
51 fNumColorProcessors = processors.numColorFragmentProcessors();
52 int numTotalProcessors = fNumColorProcessors +
53 processors.numCoverageFragmentProcessors() +
54 appliedClip.numClipCoverageFragmentProcessors();
55 fFragmentProcessors.reset(numTotalProcessors);
56 int currFPIdx = 0;
57 for (int i = 0; i < processors.numColorFragmentProcessors(); ++i, ++currFPIdx) {
58 fFragmentProcessors[currFPIdx] = processors.detachColorFragmentProcessor(i);
59 if (!fFragmentProcessors[currFPIdx]->instantiate(args.fResourceProvider)) {
60 this->markAsBad();
61 }
62 }
63 for (int i = 0; i < processors.numCoverageFragmentProcessors(); ++i, ++currFPIdx) {
64 fFragmentProcessors[currFPIdx] = processors.detachCoverageFragmentProcessor(i);
65 if (!fFragmentProcessors[currFPIdx]->instantiate(args.fResourceProvider)) {
66 this->markAsBad();
67 }
68 }
69 for (int i = 0; i < appliedClip.numClipCoverageFragmentProcessors(); ++i, ++currFPIdx) {
70 fFragmentProcessors[currFPIdx] = appliedClip.detachClipCoverageFragmentProcessor(i);
71 if (!fFragmentProcessors[currFPIdx]->instantiate(args.fResourceProvider)) {
72 this->markAsBad();
73 }
74 }
75 }
76
addDependenciesTo(GrOpList * opList,const GrCaps & caps) const77 void GrPipeline::addDependenciesTo(GrOpList* opList, const GrCaps& caps) const {
78 for (int i = 0; i < fFragmentProcessors.count(); ++i) {
79 GrFragmentProcessor::TextureAccessIter iter(fFragmentProcessors[i].get());
80 while (const GrFragmentProcessor::TextureSampler* sampler = iter.next()) {
81 opList->addDependency(sampler->proxy(), caps);
82 }
83 }
84
85 if (fDstTextureProxy) {
86 opList->addDependency(fDstTextureProxy.get(), caps);
87 }
88
89 }
90
xferBarrierType(GrTexture * texture,const GrCaps & caps) const91 GrXferBarrierType GrPipeline::xferBarrierType(GrTexture* texture, const GrCaps& caps) const {
92 if (fDstTextureProxy.get() && fDstTextureProxy.get()->peekTexture() == texture) {
93 return kTexture_GrXferBarrierType;
94 }
95 return this->getXferProcessor().xferBarrierType(caps);
96 }
97
GrPipeline(GrScissorTest scissorTest,SkBlendMode blendmode)98 GrPipeline::GrPipeline(GrScissorTest scissorTest, SkBlendMode blendmode)
99 : fWindowRectsState()
100 , fUserStencilSettings(&GrUserStencilSettings::kUnused)
101 , fFlags()
102 , fXferProcessor(GrPorterDuffXPFactory::MakeNoCoverageXP(blendmode))
103 , fFragmentProcessors()
104 , fNumColorProcessors(0) {
105 if (GrScissorTest::kEnabled == scissorTest) {
106 fFlags |= kScissorEnabled_Flag;
107 }
108 }
109