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 #ifndef GrPipelineBuilder_DEFINED 9 #define GrPipelineBuilder_DEFINED 10 11 #include "GrGpuResourceRef.h" 12 #include "GrPipeline.h" 13 #include "GrProcessorSet.h" 14 #include "GrRenderTarget.h" 15 #include "GrUserStencilSettings.h" 16 #include "GrXferProcessor.h" 17 18 class GrCaps; 19 class GrDrawOp; 20 class GrPaint; 21 class GrTexture; 22 23 class GrPipelineBuilder : private SkNoncopyable { 24 public: 25 /** 26 * Initializes the GrPipelineBuilder based on a GrPaint and MSAA availability. Note 27 * that GrPipelineBuilder encompasses more than GrPaint. Aspects of GrPipelineBuilder that have 28 * no GrPaint equivalents are set to default values with the exception of vertex attribute state 29 * which is unmodified by this function and clipping which will be enabled. 30 */ GrPipelineBuilder(GrPaint && paint,GrAAType aaType)31 GrPipelineBuilder(GrPaint&& paint, GrAAType aaType) 32 : fFlags(0x0) 33 , fDrawFace(GrDrawFace::kBoth) 34 , fUserStencilSettings(&GrUserStencilSettings::kUnused) 35 , fProcessors(std::move(paint)) { 36 if (GrAATypeIsHW(aaType)) { 37 fFlags |= GrPipeline::kHWAntialias_Flag; 38 } 39 } 40 41 /////////////////////////////////////////////////////////////////////////// 42 /// @name Fragment Processors 43 /// 44 /// GrFragmentProcessors are used to compute per-pixel color and per-pixel fractional coverage. 45 /// There are two chains of FPs, one for color and one for coverage. The first FP in each 46 /// chain gets the initial color/coverage from the GrPrimitiveProcessor. It computes an output 47 /// color/coverage which is fed to the next FP in the chain. The last color and coverage FPs 48 /// feed their output to the GrXferProcessor which controls blending. 49 //// 50 numColorFragmentProcessors()51 int numColorFragmentProcessors() const { return fProcessors.numColorFragmentProcessors(); } numCoverageFragmentProcessors()52 int numCoverageFragmentProcessors() const { 53 return fProcessors.numCoverageFragmentProcessors(); 54 } numFragmentProcessors()55 int numFragmentProcessors() const { return fProcessors.numFragmentProcessors(); } 56 getColorFragmentProcessor(int idx)57 const GrFragmentProcessor* getColorFragmentProcessor(int idx) const { 58 return fProcessors.colorFragmentProcessor(idx); 59 } getCoverageFragmentProcessor(int idx)60 const GrFragmentProcessor* getCoverageFragmentProcessor(int idx) const { 61 return fProcessors.coverageFragmentProcessor(idx); 62 } 63 processors()64 const GrProcessorSet& processors() const { return fProcessors; } 65 66 /// @} 67 68 /////////////////////////////////////////////////////////////////////////// 69 /// @name Blending 70 //// 71 72 /** 73 * Checks whether the xp will need destination in a texture to correctly blend. 74 */ willXPNeedDstTexture(const GrCaps & caps,const GrProcessorSet::FragmentProcessorAnalysis & analysis)75 bool willXPNeedDstTexture(const GrCaps& caps, 76 const GrProcessorSet::FragmentProcessorAnalysis& analysis) const { 77 return GrXPFactory::WillNeedDstTexture(fProcessors.xpFactory(), caps, analysis); 78 } 79 80 /// @} 81 82 83 /////////////////////////////////////////////////////////////////////////// 84 /// @name Stencil 85 //// 86 hasUserStencilSettings()87 bool hasUserStencilSettings() const { return !fUserStencilSettings->isUnused(); } 88 89 /** 90 * Sets the user stencil settings for the next draw. 91 * This class only stores pointers to stencil settings objects. 92 * The caller guarantees the pointer will remain valid until it 93 * changes or goes out of scope. 94 * @param settings the stencil settings to use. 95 */ setUserStencil(const GrUserStencilSettings * settings)96 void setUserStencil(const GrUserStencilSettings* settings) { fUserStencilSettings = settings; } 97 98 /// @} 99 100 /////////////////////////////////////////////////////////////////////////// 101 /// @name State Flags 102 //// 103 isHWAntialias()104 bool isHWAntialias() const { return SkToBool(fFlags & GrPipeline::kHWAntialias_Flag); } 105 setSnapVerticesToPixelCenters(bool enable)106 void setSnapVerticesToPixelCenters(bool enable) { 107 if (enable) { 108 fFlags |= GrPipeline::kSnapVerticesToPixelCenters_Flag; 109 } else { 110 fFlags &= ~GrPipeline::kSnapVerticesToPixelCenters_Flag; 111 } 112 } 113 114 /// @} 115 116 /////////////////////////////////////////////////////////////////////////// 117 /// @name Face Culling 118 //// 119 120 /** 121 * Controls whether clockwise, counterclockwise, or both faces are drawn. 122 * @param face the face(s) to draw. 123 */ setDrawFace(GrDrawFace face)124 void setDrawFace(GrDrawFace face) { 125 SkASSERT(GrDrawFace::kInvalid != face); 126 fDrawFace = face; 127 } 128 129 /// @} 130 getPipelineInitArgs(GrPipeline::InitArgs * args)131 void getPipelineInitArgs(GrPipeline::InitArgs* args) const { 132 args->fFlags = fFlags; 133 args->fUserStencil = fUserStencilSettings; 134 args->fDrawFace = fDrawFace; 135 args->fProcessors = &fProcessors; 136 } 137 138 private: 139 uint32_t fFlags; 140 GrDrawFace fDrawFace; 141 const GrUserStencilSettings* fUserStencilSettings; 142 GrProcessorSet fProcessors; 143 }; 144 145 #endif 146