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" |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 14 | #include "GrPendingProgramElement.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; |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 30 | class GrDeviceCoordTexture; |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 31 | class GrOp; |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 32 | class GrRenderTargetContext; |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 33 | |
Brian Salomon | 92aee3d | 2016-12-21 09:20:25 -0500 | [diff] [blame] | 34 | /** |
Brian Salomon | e5b399e | 2017-07-19 13:50:54 -0400 | [diff] [blame] | 35 | * This immutable object contains information needed to set build a shader program and set API |
| 36 | * state for a draw. It is used along with a GrPrimitiveProcessor and a source of geometric |
| 37 | * data (GrMesh or GrPath) to draw. |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 38 | */ |
Brian Salomon | 1635146 | 2017-07-19 16:35:31 -0400 | [diff] [blame] | 39 | class GrPipeline { |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 40 | public: |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 41 | /////////////////////////////////////////////////////////////////////////// |
| 42 | /// @name Creation |
| 43 | |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 44 | enum Flags { |
| 45 | /** |
| 46 | * Perform HW anti-aliasing. This means either HW FSAA, if supported by the render target, |
| 47 | * or smooth-line rendering if a line primitive is drawn and line smoothing is supported by |
| 48 | * the 3D API. |
| 49 | */ |
| 50 | kHWAntialias_Flag = 0x1, |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 51 | /** |
| 52 | * Modifies the vertex shader so that vertices will be positioned at pixel centers. |
| 53 | */ |
| 54 | kSnapVerticesToPixelCenters_Flag = 0x2, |
Brian Salomon | 611572c | 2017-04-28 08:57:12 -0400 | [diff] [blame] | 55 | /** Disables conversion to sRGB from linear when writing to a sRGB destination. */ |
| 56 | kDisableOutputConversionToSRGB_Flag = 0x4, |
| 57 | /** Allows conversion from sRGB to linear when reading from processor's sRGB texture. */ |
| 58 | kAllowSRGBInputs_Flag = 0x8, |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 59 | }; |
| 60 | |
Brian Salomon | 611572c | 2017-04-28 08:57:12 -0400 | [diff] [blame] | 61 | static uint32_t SRGBFlagsFromPaint(const GrPaint& paint) { |
| 62 | uint32_t flags = 0; |
| 63 | if (paint.getAllowSRGBInputs()) { |
| 64 | flags |= kAllowSRGBInputs_Flag; |
| 65 | } |
| 66 | if (paint.getDisableOutputConversionToSRGB()) { |
| 67 | flags |= kDisableOutputConversionToSRGB_Flag; |
| 68 | } |
| 69 | return flags; |
| 70 | } |
| 71 | |
Chris Dalton | 46983b7 | 2017-06-06 12:27:16 -0600 | [diff] [blame] | 72 | enum ScissorState : bool { |
| 73 | kEnabled = true, |
| 74 | kDisabled = false |
| 75 | }; |
| 76 | |
Brian Salomon | b5cb683 | 2017-02-24 11:01:15 -0500 | [diff] [blame] | 77 | struct InitArgs { |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 78 | uint32_t fFlags = 0; |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 79 | const GrUserStencilSettings* fUserStencil = &GrUserStencilSettings::kUnused; |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 80 | GrRenderTargetProxy* fProxy = nullptr; |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 81 | const GrCaps* fCaps = nullptr; |
Robert Phillips | 9bee2e5 | 2017-05-29 12:37:20 -0400 | [diff] [blame] | 82 | GrResourceProvider* fResourceProvider = nullptr; |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 83 | GrXferProcessor::DstProxy fDstProxy; |
bsalomon | a387a11 | 2015-08-11 14:47:42 -0700 | [diff] [blame] | 84 | }; |
| 85 | |
Brian Salomon | b5cb683 | 2017-02-24 11:01:15 -0500 | [diff] [blame] | 86 | /** |
Chris Dalton | 46983b7 | 2017-06-06 12:27:16 -0600 | [diff] [blame] | 87 | * Graphics state that can change dynamically without creating a new pipeline. |
| 88 | **/ |
| 89 | struct DynamicState { |
| 90 | // Overrides the scissor rectangle (if scissor is enabled in the pipeline). |
| 91 | // TODO: eventually this should be the only way to specify a scissor rectangle, as is the |
| 92 | // case with the simple constructor. |
| 93 | SkIRect fScissorRect; |
| 94 | }; |
| 95 | |
| 96 | /** |
csmartdalton | 119fb2b | 2017-02-08 14:41:05 -0500 | [diff] [blame] | 97 | * Creates a simple pipeline with default settings and no processors. The provided blend mode |
Chris Dalton | 46983b7 | 2017-06-06 12:27:16 -0600 | [diff] [blame] | 98 | * must be "Porter Duff" (<= kLastCoeffMode). If using ScissorState::kEnabled, the caller must |
| 99 | * specify a scissor rectangle through the DynamicState struct. |
csmartdalton | 119fb2b | 2017-02-08 14:41:05 -0500 | [diff] [blame] | 100 | **/ |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 101 | GrPipeline(GrRenderTargetProxy*, ScissorState, SkBlendMode); |
csmartdalton | 119fb2b | 2017-02-08 14:41:05 -0500 | [diff] [blame] | 102 | |
Brian Salomon | bfd18cd | 2017-08-09 16:27:09 -0400 | [diff] [blame] | 103 | GrPipeline(const InitArgs&, GrProcessorSet&&, GrAppliedClip&&); |
Brian Salomon | 6d4b65e | 2017-05-03 17:06:09 -0400 | [diff] [blame] | 104 | |
Brian Salomon | 1635146 | 2017-07-19 16:35:31 -0400 | [diff] [blame] | 105 | GrPipeline(const GrPipeline&) = delete; |
| 106 | GrPipeline& operator=(const GrPipeline&) = delete; |
| 107 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 108 | /// @} |
| 109 | |
| 110 | /////////////////////////////////////////////////////////////////////////// |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 111 | /// @name GrFragmentProcessors |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 112 | |
Robert Phillips | d261e10 | 2017-06-23 12:37:20 -0400 | [diff] [blame] | 113 | // Make the renderTargetContext's GrOpList be dependent on any GrOpLists in this pipeline |
| 114 | void addDependenciesTo(GrOpList* recipient, const GrCaps&) const; |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 115 | |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 116 | int numColorFragmentProcessors() const { return fNumColorProcessors; } |
| 117 | int numCoverageFragmentProcessors() const { |
| 118 | return fFragmentProcessors.count() - fNumColorProcessors; |
| 119 | } |
| 120 | int numFragmentProcessors() const { return fFragmentProcessors.count(); } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 121 | |
bsalomon | 2047b78 | 2015-12-21 13:12:54 -0800 | [diff] [blame] | 122 | const GrXferProcessor& getXferProcessor() const { |
Brian Salomon | d61c9d9 | 2017-04-10 10:54:25 -0400 | [diff] [blame] | 123 | if (fXferProcessor) { |
bsalomon | 2047b78 | 2015-12-21 13:12:54 -0800 | [diff] [blame] | 124 | return *fXferProcessor.get(); |
| 125 | } else { |
| 126 | // A null xp member means the common src-over case. GrXferProcessor's ref'ing |
| 127 | // mechanism is not thread safe so we do not hold a ref on this global. |
| 128 | return GrPorterDuffXPFactory::SimpleSrcOverXP(); |
| 129 | } |
| 130 | } |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 131 | |
Brian Salomon | 18dfa98 | 2017-04-03 16:57:43 -0400 | [diff] [blame] | 132 | /** |
| 133 | * If the GrXferProcessor uses a texture to access the dst color, then this returns that |
| 134 | * texture and the offset to the dst contents within that texture. |
| 135 | */ |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 136 | GrTextureProxy* dstTextureProxy(SkIPoint* offset = nullptr) const { |
Brian Salomon | 18dfa98 | 2017-04-03 16:57:43 -0400 | [diff] [blame] | 137 | if (offset) { |
| 138 | *offset = fDstTextureOffset; |
| 139 | } |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 140 | return fDstTextureProxy.get(); |
| 141 | } |
| 142 | |
| 143 | GrTexture* peekDstTexture(SkIPoint* offset = nullptr) const { |
| 144 | if (GrTextureProxy* dstProxy = this->dstTextureProxy(offset)) { |
| 145 | return dstProxy->priv().peekTexture(); |
| 146 | } |
| 147 | |
| 148 | return nullptr; |
Brian Salomon | 18dfa98 | 2017-04-03 16:57:43 -0400 | [diff] [blame] | 149 | } |
| 150 | |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 151 | const GrFragmentProcessor& getColorFragmentProcessor(int idx) const { |
| 152 | SkASSERT(idx < this->numColorFragmentProcessors()); |
| 153 | return *fFragmentProcessors[idx].get(); |
egdaniel | d9aa218 | 2014-10-09 13:47:05 -0700 | [diff] [blame] | 154 | } |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 155 | |
| 156 | const GrFragmentProcessor& getCoverageFragmentProcessor(int idx) const { |
| 157 | SkASSERT(idx < this->numCoverageFragmentProcessors()); |
| 158 | return *fFragmentProcessors[fNumColorProcessors + idx].get(); |
egdaniel | d9aa218 | 2014-10-09 13:47:05 -0700 | [diff] [blame] | 159 | } |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 160 | |
| 161 | const GrFragmentProcessor& getFragmentProcessor(int idx) const { |
| 162 | return *fFragmentProcessors[idx].get(); |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 163 | } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 164 | |
| 165 | /// @} |
| 166 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 167 | /** |
| 168 | * Retrieves the currently set render-target. |
| 169 | * |
| 170 | * @return The currently set render target. |
| 171 | */ |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 172 | GrRenderTargetProxy* proxy() const { return fProxy.get(); } |
| 173 | GrRenderTarget* renderTarget() const { return fProxy.get()->priv().peekRenderTarget(); } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 174 | |
csmartdalton | c633abb | 2016-11-01 08:55:55 -0700 | [diff] [blame] | 175 | const GrUserStencilSettings* getUserStencil() const { return fUserStencilSettings; } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 176 | |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 177 | const GrScissorState& getScissorState() const { return fScissorState; } |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 178 | |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 179 | const GrWindowRectsState& getWindowRectsState() const { return fWindowRectsState; } |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 180 | |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 181 | bool isHWAntialiasState() const { return SkToBool(fFlags & kHWAntialias_Flag); } |
| 182 | bool snapVerticesToPixelCenters() const { |
| 183 | return SkToBool(fFlags & kSnapVerticesToPixelCenters_Flag); |
| 184 | } |
brianosman | 64d094d | 2016-03-25 06:01:59 -0700 | [diff] [blame] | 185 | bool getDisableOutputConversionToSRGB() const { |
| 186 | return SkToBool(fFlags & kDisableOutputConversionToSRGB_Flag); |
| 187 | } |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame] | 188 | bool getAllowSRGBInputs() const { |
| 189 | return SkToBool(fFlags & kAllowSRGBInputs_Flag); |
| 190 | } |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 191 | bool hasStencilClip() const { |
| 192 | return SkToBool(fFlags & kHasStencilClip_Flag); |
| 193 | } |
csmartdalton | c633abb | 2016-11-01 08:55:55 -0700 | [diff] [blame] | 194 | bool isStencilEnabled() const { |
| 195 | return SkToBool(fFlags & kStencilEnabled_Flag); |
| 196 | } |
Robert Phillips | a91e0b7 | 2017-05-01 13:12:20 -0400 | [diff] [blame] | 197 | bool isBad() const { return SkToBool(fFlags & kIsBad_Flag); } |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 198 | |
Robert Phillips | c9c06d4 | 2017-06-12 10:58:31 -0400 | [diff] [blame] | 199 | GrXferBarrierType xferBarrierType(const GrCaps& caps) const; |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 200 | |
Brian Salomon | 82dfd3d | 2017-06-14 12:30:35 -0400 | [diff] [blame] | 201 | static SkString DumpFlags(uint32_t flags) { |
| 202 | if (flags) { |
| 203 | SkString result; |
| 204 | if (flags & GrPipeline::kSnapVerticesToPixelCenters_Flag) { |
| 205 | result.append("Snap vertices to pixel center.\n"); |
| 206 | } |
| 207 | if (flags & GrPipeline::kHWAntialias_Flag) { |
| 208 | result.append("HW Antialiasing enabled.\n"); |
| 209 | } |
| 210 | if (flags & GrPipeline::kDisableOutputConversionToSRGB_Flag) { |
| 211 | result.append("Disable output conversion to sRGB.\n"); |
| 212 | } |
| 213 | if (flags & GrPipeline::kAllowSRGBInputs_Flag) { |
| 214 | result.append("Allow sRGB Inputs.\n"); |
| 215 | } |
| 216 | return result; |
| 217 | } |
| 218 | return SkString("No pipeline flags\n"); |
| 219 | } |
| 220 | |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 221 | private: |
Robert Phillips | a91e0b7 | 2017-05-01 13:12:20 -0400 | [diff] [blame] | 222 | void markAsBad() { fFlags |= kIsBad_Flag; } |
| 223 | |
Brian Salomon | f87e2b9 | 2017-01-19 11:31:50 -0500 | [diff] [blame] | 224 | /** This is a continuation of the public "Flags" enum. */ |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 225 | enum PrivateFlags { |
Brian Salomon | e23bffd | 2017-06-02 11:01:10 -0400 | [diff] [blame] | 226 | kHasStencilClip_Flag = 0x10, |
| 227 | kStencilEnabled_Flag = 0x20, |
| 228 | kIsBad_Flag = 0x40, |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 229 | }; |
| 230 | |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 231 | using RenderTargetProxy = GrPendingIOResource<GrRenderTargetProxy, kWrite_GrIOType>; |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 232 | using DstTextureProxy = GrPendingIOResource<GrTextureProxy, kRead_GrIOType>; |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 233 | using FragmentProcessorArray = SkAutoSTArray<8, std::unique_ptr<const GrFragmentProcessor>>; |
Brian Salomon | 18dfa98 | 2017-04-03 16:57:43 -0400 | [diff] [blame] | 234 | |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 235 | DstTextureProxy fDstTextureProxy; |
Brian Salomon | 18dfa98 | 2017-04-03 16:57:43 -0400 | [diff] [blame] | 236 | SkIPoint fDstTextureOffset; |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 237 | // MDB TODO: do we still need the destination proxy here? |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 238 | RenderTargetProxy fProxy; |
Brian Salomon | 18dfa98 | 2017-04-03 16:57:43 -0400 | [diff] [blame] | 239 | GrScissorState fScissorState; |
| 240 | GrWindowRectsState fWindowRectsState; |
| 241 | const GrUserStencilSettings* fUserStencilSettings; |
Brian Salomon | 18dfa98 | 2017-04-03 16:57:43 -0400 | [diff] [blame] | 242 | uint16_t fFlags; |
Brian Salomon | d61c9d9 | 2017-04-10 10:54:25 -0400 | [diff] [blame] | 243 | sk_sp<const GrXferProcessor> fXferProcessor; |
Brian Salomon | 18dfa98 | 2017-04-03 16:57:43 -0400 | [diff] [blame] | 244 | FragmentProcessorArray fFragmentProcessors; |
egdaniel | d9aa218 | 2014-10-09 13:47:05 -0700 | [diff] [blame] | 245 | |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 246 | // This value is also the index in fFragmentProcessors where coverage processors begin. |
Brian Salomon | 18dfa98 | 2017-04-03 16:57:43 -0400 | [diff] [blame] | 247 | int fNumColorProcessors; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 248 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 249 | typedef SkRefCnt INHERITED; |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 250 | }; |
| 251 | |
| 252 | #endif |