• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "src/gpu/GrPipeline.h"
9 
10 #include "src/gpu/GrAppliedClip.h"
11 #include "src/gpu/GrCaps.h"
12 #include "src/gpu/GrGpu.h"
13 #include "src/gpu/GrRenderTargetContext.h"
14 #include "src/gpu/GrRenderTargetOpList.h"
15 #include "src/gpu/GrXferProcessor.h"
16 
17 #include "src/gpu/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         : fOutputSwizzle(args.fOutputSwizzle) {
23     SkASSERT(processors.isFinalized());
24 
25     fFlags = (Flags)args.fInputFlags;
26     if (appliedClip.hasStencilClip()) {
27         fFlags |= Flags::kHasStencilClip;
28     }
29     if (appliedClip.scissorState().enabled()) {
30         fFlags |= Flags::kScissorEnabled;
31     }
32 
33     fWindowRectsState = appliedClip.windowRectsState();
34     if (!args.fUserStencil->isDisabled(fFlags & Flags::kHasStencilClip)) {
35         fFlags |= Flags::kStencilEnabled;
36     }
37 
38     fUserStencilSettings = args.fUserStencil;
39 
40     fXferProcessor = processors.refXferProcessor();
41 
42     if (args.fDstProxy.proxy()) {
43         SkASSERT(args.fDstProxy.proxy()->isInstantiated());
44 
45         fDstTextureProxy.reset(args.fDstProxy.proxy());
46         fDstTextureOffset = args.fDstProxy.offset();
47     }
48 
49     // Copy GrFragmentProcessors from GrProcessorSet to Pipeline
50     fNumColorProcessors = processors.numColorFragmentProcessors();
51     int numTotalProcessors = fNumColorProcessors +
52                              processors.numCoverageFragmentProcessors() +
53                              appliedClip.numClipCoverageFragmentProcessors();
54     fFragmentProcessors.reset(numTotalProcessors);
55 
56     int currFPIdx = 0;
57     for (int i = 0; i < processors.numColorFragmentProcessors(); ++i, ++currFPIdx) {
58         fFragmentProcessors[currFPIdx] = processors.detachColorFragmentProcessor(i);
59     }
60     for (int i = 0; i < processors.numCoverageFragmentProcessors(); ++i, ++currFPIdx) {
61         fFragmentProcessors[currFPIdx] = processors.detachCoverageFragmentProcessor(i);
62     }
63     for (int i = 0; i < appliedClip.numClipCoverageFragmentProcessors(); ++i, ++currFPIdx) {
64         fFragmentProcessors[currFPIdx] = appliedClip.detachClipCoverageFragmentProcessor(i);
65     }
66 
67 #ifdef SK_DEBUG
68     for (int i = 0; i < numTotalProcessors; ++i) {
69         if (!fFragmentProcessors[i]->isInstantiated()) {
70             this->markAsBad();
71             break;
72         }
73     }
74 #endif
75 }
76 
xferBarrierType(GrTexture * texture,const GrCaps & caps) const77 GrXferBarrierType GrPipeline::xferBarrierType(GrTexture* texture, const GrCaps& caps) const {
78     if (fDstTextureProxy.get() && fDstTextureProxy.get()->peekTexture() == texture) {
79         return kTexture_GrXferBarrierType;
80     }
81     return this->getXferProcessor().xferBarrierType(caps);
82 }
83 
GrPipeline(GrScissorTest scissorTest,sk_sp<const GrXferProcessor> xp,const GrSwizzle & outputSwizzle,InputFlags inputFlags,const GrUserStencilSettings * userStencil)84 GrPipeline::GrPipeline(GrScissorTest scissorTest, sk_sp<const GrXferProcessor> xp,
85                        const GrSwizzle& outputSwizzle, InputFlags inputFlags,
86                        const GrUserStencilSettings* userStencil)
87         : fWindowRectsState()
88         , fUserStencilSettings(userStencil)
89         , fFlags((Flags)inputFlags)
90         , fXferProcessor(std::move(xp))
91         , fFragmentProcessors()
92         , fNumColorProcessors(0)
93         , fOutputSwizzle(outputSwizzle) {
94     if (GrScissorTest::kEnabled == scissorTest) {
95         fFlags |= Flags::kScissorEnabled;
96     }
97     if (!userStencil->isDisabled(false)) {
98         fFlags |= Flags::kStencilEnabled;
99     }
100 }
101 
getBlendInfoKey() const102 uint32_t GrPipeline::getBlendInfoKey() const {
103     const GrXferProcessor::BlendInfo& blendInfo = this->getXferProcessor().getBlendInfo();
104 
105     static const uint32_t kBlendWriteShift = 1;
106     static const uint32_t kBlendCoeffShift = 5;
107     GR_STATIC_ASSERT(kLast_GrBlendCoeff < (1 << kBlendCoeffShift));
108     GR_STATIC_ASSERT(kFirstAdvancedGrBlendEquation - 1 < 4);
109 
110     uint32_t key = blendInfo.fWriteColor;
111     key |= (blendInfo.fSrcBlend << kBlendWriteShift);
112     key |= (blendInfo.fDstBlend << (kBlendWriteShift + kBlendCoeffShift));
113     key |= (blendInfo.fEquation << (kBlendWriteShift + 2 * kBlendCoeffShift));
114 
115     return key;
116 }
117