tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 1 | /* |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 2 | * Copyright 2015 Google Inc. |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [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 GrPipelineBuilder_DEFINED |
| 9 | #define GrPipelineBuilder_DEFINED |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 10 | |
bsalomon | f96ba02 | 2014-09-17 08:05:40 -0700 | [diff] [blame] | 11 | #include "GrGpuResourceRef.h" |
Brian Salomon | 92ce594 | 2017-01-18 11:01:10 -0500 | [diff] [blame^] | 12 | #include "GrProcessorSet.h" |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 13 | #include "GrRenderTarget.h" |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 14 | #include "GrUserStencilSettings.h" |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 15 | #include "GrXferProcessor.h" |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 16 | |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 17 | class GrCaps; |
Brian Salomon | 92ce594 | 2017-01-18 11:01:10 -0500 | [diff] [blame^] | 18 | class GrDrawOp; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 19 | class GrPaint; |
Brian Salomon | 92ce594 | 2017-01-18 11:01:10 -0500 | [diff] [blame^] | 20 | struct GrPipelineAnalysis; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 21 | class GrTexture; |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame] | 22 | |
Brian Salomon | 92ce594 | 2017-01-18 11:01:10 -0500 | [diff] [blame^] | 23 | class GrPipelineBuilder : private SkNoncopyable { |
bsalomon@google.com | 2e3d144 | 2012-03-26 20:33:54 +0000 | [diff] [blame] | 24 | public: |
bsalomon@google.com | 52a5dcb | 2012-01-17 16:01:37 +0000 | [diff] [blame] | 25 | /** |
robertphillips | 55fdccc | 2016-06-06 06:16:20 -0700 | [diff] [blame] | 26 | * Initializes the GrPipelineBuilder based on a GrPaint and MSAA availability. Note |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 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. |
bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 30 | */ |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 31 | GrPipelineBuilder(GrPaint&&, GrAAType); |
joshualitt | 7b670db | 2015-07-09 13:25:02 -0700 | [diff] [blame] | 32 | |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 33 | /////////////////////////////////////////////////////////////////////////// |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 34 | /// @name Fragment Processors |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 35 | /// |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 36 | /// GrFragmentProcessors are used to compute per-pixel color and per-pixel fractional coverage. |
| 37 | /// There are two chains of FPs, one for color and one for coverage. The first FP in each |
| 38 | /// chain gets the initial color/coverage from the GrPrimitiveProcessor. It computes an output |
| 39 | /// color/coverage which is fed to the next FP in the chain. The last color and coverage FPs |
| 40 | /// feed their output to the GrXferProcessor which controls blending. |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 41 | //// |
| 42 | |
Brian Salomon | 92ce594 | 2017-01-18 11:01:10 -0500 | [diff] [blame^] | 43 | int numColorFragmentProcessors() const { return fProcessors.numColorFragmentProcessors(); } |
| 44 | int numCoverageFragmentProcessors() const { |
| 45 | return fProcessors.numCoverageFragmentProcessors(); |
| 46 | } |
| 47 | int numFragmentProcessors() const { return fProcessors.numFragmentProcessors(); } |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 48 | |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 49 | const GrFragmentProcessor* getColorFragmentProcessor(int idx) const { |
Brian Salomon | 92ce594 | 2017-01-18 11:01:10 -0500 | [diff] [blame^] | 50 | return fProcessors.colorFragmentProcessor(idx); |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 51 | } |
| 52 | const GrFragmentProcessor* getCoverageFragmentProcessor(int idx) const { |
Brian Salomon | 92ce594 | 2017-01-18 11:01:10 -0500 | [diff] [blame^] | 53 | return fProcessors.coverageFragmentProcessor(idx); |
| 54 | } |
| 55 | |
| 56 | void analyzeFragmentProcessors(GrPipelineAnalysis* analysis) const { |
| 57 | fProcessors.analyzeFragmentProcessors(analysis); |
jvanverth@google.com | 65eb4d5 | 2013-03-19 18:51:02 +0000 | [diff] [blame] | 58 | } |
skia.committer@gmail.com | 01c34ee | 2013-03-20 07:01:02 +0000 | [diff] [blame] | 59 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 60 | /// @} |
| 61 | |
| 62 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 63 | /// @name Blending |
| 64 | //// |
| 65 | |
Brian Salomon | 92ce594 | 2017-01-18 11:01:10 -0500 | [diff] [blame^] | 66 | const GrXPFactory* getXPFactory() const { return fProcessors.xpFactory(); } |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 67 | |
| 68 | /** |
bsalomon | 6a44c6a | 2015-05-26 09:49:05 -0700 | [diff] [blame] | 69 | * Checks whether the xp will need destination in a texture to correctly blend. |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 70 | */ |
Brian Salomon | 92aee3d | 2016-12-21 09:20:25 -0500 | [diff] [blame] | 71 | bool willXPNeedDstTexture(const GrCaps& caps, const GrPipelineAnalysis&) const; |
joshualitt | d27f73e | 2014-12-29 07:43:36 -0800 | [diff] [blame] | 72 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 73 | /// @} |
| 74 | |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 75 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 76 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 77 | /// @name Stencil |
| 78 | //// |
| 79 | |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 80 | bool hasUserStencilSettings() const { return !fUserStencilSettings->isUnused(); } |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 81 | const GrUserStencilSettings* getUserStencil() const { return fUserStencilSettings; } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 82 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 83 | /** |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 84 | * Sets the user stencil settings for the next draw. |
| 85 | * This class only stores pointers to stencil settings objects. |
| 86 | * The caller guarantees the pointer will remain valid until it |
| 87 | * changes or goes out of scope. |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 88 | * @param settings the stencil settings to use. |
| 89 | */ |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 90 | void setUserStencil(const GrUserStencilSettings* settings) { fUserStencilSettings = settings; } |
| 91 | void disableUserStencil() { fUserStencilSettings = &GrUserStencilSettings::kUnused; } |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 92 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 93 | /// @} |
| 94 | |
| 95 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 96 | /// @name State Flags |
| 97 | //// |
tomhudson@google.com | 62b0968 | 2011-11-09 16:39:17 +0000 | [diff] [blame] | 98 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 99 | /** |
| 100 | * Flags that affect rendering. Controlled using enable/disableState(). All |
| 101 | * default to disabled. |
| 102 | */ |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 103 | enum Flags { |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 104 | /** |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 105 | * Perform HW anti-aliasing. This means either HW FSAA, if supported by the render target, |
| 106 | * or smooth-line rendering if a line primitive is drawn and line smoothing is supported by |
| 107 | * the 3D API. |
| 108 | */ |
bsalomon | aca31fe | 2015-09-22 11:38:46 -0700 | [diff] [blame] | 109 | kHWAntialias_Flag = 0x01, |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 110 | |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 111 | /** |
| 112 | * Modifies the vertex shader so that vertices will be positioned at pixel centers. |
| 113 | */ |
bsalomon | aca31fe | 2015-09-22 11:38:46 -0700 | [diff] [blame] | 114 | kSnapVerticesToPixelCenters_Flag = 0x02, |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 115 | |
brianosman | 64d094d | 2016-03-25 06:01:59 -0700 | [diff] [blame] | 116 | /** |
| 117 | * Suppress linear -> sRGB conversion when rendering to sRGB render targets. |
| 118 | */ |
| 119 | kDisableOutputConversionToSRGB_Flag = 0x04, |
| 120 | |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame] | 121 | /** |
| 122 | * Allow sRGB -> linear conversion when reading from sRGB inputs. |
| 123 | */ |
| 124 | kAllowSRGBInputs_Flag = 0x08, |
| 125 | |
dvonbeck | 9b03e7b | 2016-08-01 11:01:56 -0700 | [diff] [blame] | 126 | /** |
| 127 | * Signals that one or more FPs need access to the distance vector field to the nearest |
| 128 | * edge |
| 129 | */ |
| 130 | kUsesDistanceVectorField_Flag = 0x10, |
| 131 | |
| 132 | kLast_Flag = kUsesDistanceVectorField_Flag, |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 133 | }; |
| 134 | |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 135 | bool isHWAntialias() const { return SkToBool(fFlags & kHWAntialias_Flag); } |
| 136 | bool snapVerticesToPixelCenters() const { |
| 137 | return SkToBool(fFlags & kSnapVerticesToPixelCenters_Flag); } |
brianosman | 64d094d | 2016-03-25 06:01:59 -0700 | [diff] [blame] | 138 | bool getDisableOutputConversionToSRGB() const { |
| 139 | return SkToBool(fFlags & kDisableOutputConversionToSRGB_Flag); } |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame] | 140 | bool getAllowSRGBInputs() const { |
| 141 | return SkToBool(fFlags & kAllowSRGBInputs_Flag); } |
dvonbeck | 9b03e7b | 2016-08-01 11:01:56 -0700 | [diff] [blame] | 142 | bool getUsesDistanceVectorField() const { |
| 143 | return SkToBool(fFlags & kUsesDistanceVectorField_Flag); } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 144 | |
| 145 | /** |
| 146 | * Enable render state settings. |
| 147 | * |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 148 | * @param flags bitfield of Flags specifying the states to enable |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 149 | */ |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 150 | void enableState(uint32_t flags) { fFlags |= flags; } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 151 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 152 | /** |
| 153 | * Disable render state settings. |
| 154 | * |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 155 | * @param flags bitfield of Flags specifying the states to disable |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 156 | */ |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 157 | void disableState(uint32_t flags) { fFlags &= ~(flags); } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 158 | |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 159 | /** |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 160 | * Enable or disable flags based on a boolean. |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 161 | * |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 162 | * @param flags bitfield of Flags to enable or disable |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 163 | * @param enable if true enable stateBits, otherwise disable |
| 164 | */ |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 165 | void setState(uint32_t flags, bool enable) { |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 166 | if (enable) { |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 167 | this->enableState(flags); |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 168 | } else { |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 169 | this->disableState(flags); |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 170 | } |
| 171 | } |
| 172 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 173 | /// @} |
| 174 | |
| 175 | /////////////////////////////////////////////////////////////////////////// |
| 176 | /// @name Face Culling |
| 177 | //// |
| 178 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 179 | /** |
| 180 | * Gets whether the target is drawing clockwise, counterclockwise, |
| 181 | * or both faces. |
| 182 | * @return the current draw face(s). |
| 183 | */ |
robertphillips | 5fa7f30 | 2016-07-21 09:21:04 -0700 | [diff] [blame] | 184 | GrDrawFace getDrawFace() const { return fDrawFace; } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 185 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 186 | /** |
| 187 | * Controls whether clockwise, counterclockwise, or both faces are drawn. |
| 188 | * @param face the face(s) to draw. |
| 189 | */ |
robertphillips | 5fa7f30 | 2016-07-21 09:21:04 -0700 | [diff] [blame] | 190 | void setDrawFace(GrDrawFace face) { |
| 191 | SkASSERT(GrDrawFace::kInvalid != face); |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 192 | fDrawFace = face; |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 193 | } |
| 194 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 195 | /// @} |
| 196 | |
| 197 | /////////////////////////////////////////////////////////////////////////// |
tomhudson@google.com | 62b0968 | 2011-11-09 16:39:17 +0000 | [diff] [blame] | 198 | |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 199 | bool usePLSDstRead(const GrDrawOp*) const; |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 200 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 201 | private: |
Brian Salomon | 92ce594 | 2017-01-18 11:01:10 -0500 | [diff] [blame^] | 202 | uint32_t fFlags; |
| 203 | const GrUserStencilSettings* fUserStencilSettings; |
| 204 | GrDrawFace fDrawFace; |
| 205 | GrProcessorSet fProcessors; |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 206 | }; |
| 207 | |
| 208 | #endif |