egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 1 | /* |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 2 | * Copyright 2015 Google Inc. |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 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 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 8 | #ifndef GrPipeline_DEFINED |
| 9 | #define GrPipeline_DEFINED |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 10 | |
egdaniel | b109ac2 | 2014-10-07 06:45:44 -0700 | [diff] [blame] | 11 | #include "GrColor.h" |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 12 | #include "GrFragmentProcessor.h" |
joshualitt | dbe1e6f | 2015-07-16 08:12:45 -0700 | [diff] [blame] | 13 | #include "GrNonAtomicRef.h" |
Brian Salomon | ae5f953 | 2018-07-31 11:03:40 -0400 | [diff] [blame] | 14 | #include "GrPendingIOResource.h" |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 15 | #include "GrProcessorSet.h" |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 16 | #include "GrProgramDesc.h" |
Brian Salomon | a4677b5 | 2017-05-04 12:39:56 -0400 | [diff] [blame] | 17 | #include "GrRect.h" |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 18 | #include "GrRenderTargetProxy.h" |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 19 | #include "GrScissorState.h" |
csmartdalton | c633abb | 2016-11-01 08:55:55 -0700 | [diff] [blame] | 20 | #include "GrUserStencilSettings.h" |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 21 | #include "GrWindowRectsState.h" |
egdaniel | b109ac2 | 2014-10-07 06:45:44 -0700 | [diff] [blame] | 22 | #include "SkMatrix.h" |
| 23 | #include "SkRefCnt.h" |
robertphillips | 5fa7f30 | 2016-07-21 09:21:04 -0700 | [diff] [blame] | 24 | #include "effects/GrCoverageSetOpXP.h" |
| 25 | #include "effects/GrDisableColorXP.h" |
| 26 | #include "effects/GrPorterDuffXferProcessor.h" |
| 27 | #include "effects/GrSimpleTextureEffect.h" |
| 28 | |
Brian Salomon | 652ecb5 | 2017-01-17 12:39:53 -0500 | [diff] [blame] | 29 | class GrAppliedClip; |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 30 | class GrOp; |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 31 | class GrRenderTargetContext; |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 32 | |
Brian Salomon | 92aee3d | 2016-12-21 09:20:25 -0500 | [diff] [blame] | 33 | /** |
Brian Salomon | e5b399e | 2017-07-19 13:50:54 -0400 | [diff] [blame] | 34 | * This immutable object contains information needed to set build a shader program and set API |
| 35 | * state for a draw. It is used along with a GrPrimitiveProcessor and a source of geometric |
| 36 | * data (GrMesh or GrPath) to draw. |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 37 | */ |
Brian Salomon | 1635146 | 2017-07-19 16:35:31 -0400 | [diff] [blame] | 38 | class GrPipeline { |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 39 | public: |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 40 | /////////////////////////////////////////////////////////////////////////// |
| 41 | /// @name Creation |
| 42 | |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 43 | enum Flags { |
| 44 | /** |
| 45 | * Perform HW anti-aliasing. This means either HW FSAA, if supported by the render target, |
| 46 | * or smooth-line rendering if a line primitive is drawn and line smoothing is supported by |
| 47 | * the 3D API. |
| 48 | */ |
| 49 | kHWAntialias_Flag = 0x1, |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 50 | /** |
| 51 | * Modifies the vertex shader so that vertices will be positioned at pixel centers. |
| 52 | */ |
| 53 | kSnapVerticesToPixelCenters_Flag = 0x2, |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 54 | }; |
| 55 | |
Brian Salomon | b5cb683 | 2017-02-24 11:01:15 -0500 | [diff] [blame] | 56 | struct InitArgs { |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 57 | uint32_t fFlags = 0; |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 58 | const GrUserStencilSettings* fUserStencil = &GrUserStencilSettings::kUnused; |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 59 | GrRenderTargetProxy* fProxy = nullptr; |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 60 | const GrCaps* fCaps = nullptr; |
Robert Phillips | 9bee2e5 | 2017-05-29 12:37:20 -0400 | [diff] [blame] | 61 | GrResourceProvider* fResourceProvider = nullptr; |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 62 | GrXferProcessor::DstProxy fDstProxy; |
bsalomon | a387a11 | 2015-08-11 14:47:42 -0700 | [diff] [blame] | 63 | }; |
| 64 | |
Brian Salomon | b5cb683 | 2017-02-24 11:01:15 -0500 | [diff] [blame] | 65 | /** |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 66 | * Some state can be changed between GrMeshes without changing GrPipelines. This is generally |
| 67 | * less expensive then using multiple pipelines. Such state is called "dynamic state". It can |
| 68 | * be specified in two ways: |
| 69 | * 1) FixedDynamicState - use this to specify state that does not vary between GrMeshes. |
| 70 | * 2) DynamicStateArrays - use this to specify per mesh values for dynamic state. |
Chris Dalton | 46983b7 | 2017-06-06 12:27:16 -0600 | [diff] [blame] | 71 | **/ |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 72 | struct FixedDynamicState { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 73 | explicit FixedDynamicState(const SkIRect& scissorRect) : fScissorRect(scissorRect) {} |
| 74 | FixedDynamicState() = default; |
| 75 | SkIRect fScissorRect = SkIRect::EmptyIRect(); |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 76 | // Must have GrPrimitiveProcessor::numTextureSamplers() entries. Can be null if no samplers |
| 77 | // or textures are passed using DynamicStateArrays. |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 78 | GrTextureProxy** fPrimitiveProcessorTextures = nullptr; |
Chris Dalton | 46983b7 | 2017-06-06 12:27:16 -0600 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | /** |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 82 | * Any non-null array overrides the FixedDynamicState on a mesh-by-mesh basis. Arrays must |
| 83 | * have one entry for each GrMesh. |
| 84 | */ |
| 85 | struct DynamicStateArrays { |
| 86 | const SkIRect* fScissorRects = nullptr; |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 87 | // Must have GrPrimitiveProcessor::numTextureSamplers() * num_meshes entries. |
| 88 | // Can be null if no samplers or to use the same textures for all meshes via' |
| 89 | // FixedDynamicState. |
| 90 | GrTextureProxy** fPrimitiveProcessorTextures = nullptr; |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | /** |
csmartdalton | 119fb2b | 2017-02-08 14:41:05 -0500 | [diff] [blame] | 94 | * Creates a simple pipeline with default settings and no processors. The provided blend mode |
Chris Dalton | 916c498 | 2018-08-15 00:53:25 -0600 | [diff] [blame] | 95 | * must be "Porter Duff" (<= kLastCoeffMode). If using GrScissorTest::kEnabled, the caller must |
Chris Dalton | 46983b7 | 2017-06-06 12:27:16 -0600 | [diff] [blame] | 96 | * specify a scissor rectangle through the DynamicState struct. |
csmartdalton | 119fb2b | 2017-02-08 14:41:05 -0500 | [diff] [blame] | 97 | **/ |
Chris Dalton | 916c498 | 2018-08-15 00:53:25 -0600 | [diff] [blame] | 98 | GrPipeline(GrRenderTargetProxy*, GrScissorTest, SkBlendMode); |
csmartdalton | 119fb2b | 2017-02-08 14:41:05 -0500 | [diff] [blame] | 99 | |
Brian Salomon | bfd18cd | 2017-08-09 16:27:09 -0400 | [diff] [blame] | 100 | GrPipeline(const InitArgs&, GrProcessorSet&&, GrAppliedClip&&); |
Brian Salomon | 6d4b65e | 2017-05-03 17:06:09 -0400 | [diff] [blame] | 101 | |
Brian Salomon | 1635146 | 2017-07-19 16:35:31 -0400 | [diff] [blame] | 102 | GrPipeline(const GrPipeline&) = delete; |
| 103 | GrPipeline& operator=(const GrPipeline&) = delete; |
| 104 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 105 | /// @} |
| 106 | |
| 107 | /////////////////////////////////////////////////////////////////////////// |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 108 | /// @name GrFragmentProcessors |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 109 | |
Robert Phillips | d261e10 | 2017-06-23 12:37:20 -0400 | [diff] [blame] | 110 | // Make the renderTargetContext's GrOpList be dependent on any GrOpLists in this pipeline |
| 111 | void addDependenciesTo(GrOpList* recipient, const GrCaps&) const; |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 112 | |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 113 | int numColorFragmentProcessors() const { return fNumColorProcessors; } |
| 114 | int numCoverageFragmentProcessors() const { |
| 115 | return fFragmentProcessors.count() - fNumColorProcessors; |
| 116 | } |
| 117 | int numFragmentProcessors() const { return fFragmentProcessors.count(); } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 118 | |
bsalomon | 2047b78 | 2015-12-21 13:12:54 -0800 | [diff] [blame] | 119 | const GrXferProcessor& getXferProcessor() const { |
Brian Salomon | d61c9d9 | 2017-04-10 10:54:25 -0400 | [diff] [blame] | 120 | if (fXferProcessor) { |
bsalomon | 2047b78 | 2015-12-21 13:12:54 -0800 | [diff] [blame] | 121 | return *fXferProcessor.get(); |
| 122 | } else { |
| 123 | // A null xp member means the common src-over case. GrXferProcessor's ref'ing |
| 124 | // mechanism is not thread safe so we do not hold a ref on this global. |
| 125 | return GrPorterDuffXPFactory::SimpleSrcOverXP(); |
| 126 | } |
| 127 | } |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 128 | |
Brian Salomon | 18dfa98 | 2017-04-03 16:57:43 -0400 | [diff] [blame] | 129 | /** |
| 130 | * If the GrXferProcessor uses a texture to access the dst color, then this returns that |
| 131 | * texture and the offset to the dst contents within that texture. |
| 132 | */ |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 133 | GrTextureProxy* dstTextureProxy(SkIPoint* offset = nullptr) const { |
Brian Salomon | 18dfa98 | 2017-04-03 16:57:43 -0400 | [diff] [blame] | 134 | if (offset) { |
| 135 | *offset = fDstTextureOffset; |
| 136 | } |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 137 | return fDstTextureProxy.get(); |
| 138 | } |
| 139 | |
| 140 | GrTexture* peekDstTexture(SkIPoint* offset = nullptr) const { |
| 141 | if (GrTextureProxy* dstProxy = this->dstTextureProxy(offset)) { |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 142 | return dstProxy->peekTexture(); |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | return nullptr; |
Brian Salomon | 18dfa98 | 2017-04-03 16:57:43 -0400 | [diff] [blame] | 146 | } |
| 147 | |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 148 | const GrFragmentProcessor& getColorFragmentProcessor(int idx) const { |
| 149 | SkASSERT(idx < this->numColorFragmentProcessors()); |
| 150 | return *fFragmentProcessors[idx].get(); |
egdaniel | d9aa218 | 2014-10-09 13:47:05 -0700 | [diff] [blame] | 151 | } |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 152 | |
| 153 | const GrFragmentProcessor& getCoverageFragmentProcessor(int idx) const { |
| 154 | SkASSERT(idx < this->numCoverageFragmentProcessors()); |
| 155 | return *fFragmentProcessors[fNumColorProcessors + idx].get(); |
egdaniel | d9aa218 | 2014-10-09 13:47:05 -0700 | [diff] [blame] | 156 | } |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 157 | |
| 158 | const GrFragmentProcessor& getFragmentProcessor(int idx) const { |
| 159 | return *fFragmentProcessors[idx].get(); |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 160 | } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 161 | |
| 162 | /// @} |
| 163 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 164 | /** |
| 165 | * Retrieves the currently set render-target. |
| 166 | * |
| 167 | * @return The currently set render target. |
| 168 | */ |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 169 | GrRenderTargetProxy* proxy() const { return fProxy.get(); } |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 170 | GrRenderTarget* renderTarget() const { return fProxy.get()->peekRenderTarget(); } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 171 | |
csmartdalton | c633abb | 2016-11-01 08:55:55 -0700 | [diff] [blame] | 172 | const GrUserStencilSettings* getUserStencil() const { return fUserStencilSettings; } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 173 | |
Chris Dalton | 916c498 | 2018-08-15 00:53:25 -0600 | [diff] [blame] | 174 | bool isScissorEnabled() const { |
| 175 | return SkToBool(fFlags & kScissorEnabled_Flag); |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 176 | } |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 177 | |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 178 | const GrWindowRectsState& getWindowRectsState() const { return fWindowRectsState; } |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 179 | |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 180 | bool isHWAntialiasState() const { return SkToBool(fFlags & kHWAntialias_Flag); } |
| 181 | bool snapVerticesToPixelCenters() const { |
| 182 | return SkToBool(fFlags & kSnapVerticesToPixelCenters_Flag); |
| 183 | } |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 184 | bool hasStencilClip() const { |
| 185 | return SkToBool(fFlags & kHasStencilClip_Flag); |
| 186 | } |
csmartdalton | c633abb | 2016-11-01 08:55:55 -0700 | [diff] [blame] | 187 | bool isStencilEnabled() const { |
| 188 | return SkToBool(fFlags & kStencilEnabled_Flag); |
| 189 | } |
Robert Phillips | a91e0b7 | 2017-05-01 13:12:20 -0400 | [diff] [blame] | 190 | bool isBad() const { return SkToBool(fFlags & kIsBad_Flag); } |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 191 | |
Robert Phillips | c9c06d4 | 2017-06-12 10:58:31 -0400 | [diff] [blame] | 192 | GrXferBarrierType xferBarrierType(const GrCaps& caps) const; |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 193 | |
Brian Salomon | 82dfd3d | 2017-06-14 12:30:35 -0400 | [diff] [blame] | 194 | static SkString DumpFlags(uint32_t flags) { |
| 195 | if (flags) { |
| 196 | SkString result; |
| 197 | if (flags & GrPipeline::kSnapVerticesToPixelCenters_Flag) { |
| 198 | result.append("Snap vertices to pixel center.\n"); |
| 199 | } |
| 200 | if (flags & GrPipeline::kHWAntialias_Flag) { |
| 201 | result.append("HW Antialiasing enabled.\n"); |
| 202 | } |
Brian Salomon | 82dfd3d | 2017-06-14 12:30:35 -0400 | [diff] [blame] | 203 | return result; |
| 204 | } |
| 205 | return SkString("No pipeline flags\n"); |
| 206 | } |
| 207 | |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 208 | private: |
Robert Phillips | a91e0b7 | 2017-05-01 13:12:20 -0400 | [diff] [blame] | 209 | void markAsBad() { fFlags |= kIsBad_Flag; } |
| 210 | |
Brian Salomon | f87e2b9 | 2017-01-19 11:31:50 -0500 | [diff] [blame] | 211 | /** This is a continuation of the public "Flags" enum. */ |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 212 | enum PrivateFlags { |
Brian Salomon | e23bffd | 2017-06-02 11:01:10 -0400 | [diff] [blame] | 213 | kHasStencilClip_Flag = 0x10, |
| 214 | kStencilEnabled_Flag = 0x20, |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 215 | kScissorEnabled_Flag = 0x40, |
| 216 | kIsBad_Flag = 0x80, |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 217 | }; |
| 218 | |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 219 | using RenderTargetProxy = GrPendingIOResource<GrRenderTargetProxy, kWrite_GrIOType>; |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 220 | using DstTextureProxy = GrPendingIOResource<GrTextureProxy, kRead_GrIOType>; |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 221 | using FragmentProcessorArray = SkAutoSTArray<8, std::unique_ptr<const GrFragmentProcessor>>; |
Brian Salomon | 18dfa98 | 2017-04-03 16:57:43 -0400 | [diff] [blame] | 222 | |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 223 | DstTextureProxy fDstTextureProxy; |
Brian Salomon | 18dfa98 | 2017-04-03 16:57:43 -0400 | [diff] [blame] | 224 | SkIPoint fDstTextureOffset; |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 225 | // MDB TODO: do we still need the destination proxy here? |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 226 | RenderTargetProxy fProxy; |
Brian Salomon | 18dfa98 | 2017-04-03 16:57:43 -0400 | [diff] [blame] | 227 | GrWindowRectsState fWindowRectsState; |
| 228 | const GrUserStencilSettings* fUserStencilSettings; |
Brian Salomon | 18dfa98 | 2017-04-03 16:57:43 -0400 | [diff] [blame] | 229 | uint16_t fFlags; |
Brian Salomon | d61c9d9 | 2017-04-10 10:54:25 -0400 | [diff] [blame] | 230 | sk_sp<const GrXferProcessor> fXferProcessor; |
Brian Salomon | 18dfa98 | 2017-04-03 16:57:43 -0400 | [diff] [blame] | 231 | FragmentProcessorArray fFragmentProcessors; |
egdaniel | d9aa218 | 2014-10-09 13:47:05 -0700 | [diff] [blame] | 232 | |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 233 | // This value is also the index in fFragmentProcessors where coverage processors begin. |
Brian Salomon | 18dfa98 | 2017-04-03 16:57:43 -0400 | [diff] [blame] | 234 | int fNumColorProcessors; |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 235 | }; |
| 236 | |
| 237 | #endif |