egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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 GrXferProcessor_DEFINED |
| 9 | #define GrXferProcessor_DEFINED |
| 10 | |
cdalton | ee0175f | 2015-06-12 08:21:26 -0700 | [diff] [blame] | 11 | #include "GrBlend.h" |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 12 | #include "GrColor.h" |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 13 | #include "GrProcessor.h" |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 14 | #include "GrProcessorSet.h" |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 15 | #include "GrTexture.h" |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 16 | #include "GrTypes.h" |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 17 | |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 18 | class GrShaderCaps; |
egdaniel | fa4cc8b | 2015-11-13 08:34:52 -0800 | [diff] [blame] | 19 | class GrGLSLXferProcessor; |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 20 | class GrProcOptInfo; |
| 21 | |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 22 | /** |
cdalton | 9954bc3 | 2015-04-29 14:17:00 -0700 | [diff] [blame] | 23 | * Barriers for blending. When a shader reads the dst directly, an Xfer barrier is sometimes |
| 24 | * required after a pixel has been written, before it can be safely read again. |
| 25 | */ |
| 26 | enum GrXferBarrierType { |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 27 | kNone_GrXferBarrierType = 0, //<! No barrier is required |
| 28 | kTexture_GrXferBarrierType, //<! Required when a shader reads and renders to the same texture. |
| 29 | kBlend_GrXferBarrierType, //<! Required by certain blend extensions. |
cdalton | 9954bc3 | 2015-04-29 14:17:00 -0700 | [diff] [blame] | 30 | }; |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 31 | /** Should be able to treat kNone as false in boolean expressions */ |
| 32 | GR_STATIC_ASSERT(SkToBool(kNone_GrXferBarrierType) == false); |
cdalton | 9954bc3 | 2015-04-29 14:17:00 -0700 | [diff] [blame] | 33 | |
| 34 | /** |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 35 | * GrXferProcessor is responsible for implementing the xfer mode that blends the src color and dst |
cdalton | edbb31f | 2015-06-08 12:14:44 -0700 | [diff] [blame] | 36 | * color, and for applying any coverage. It does this by emitting fragment shader code and |
| 37 | * controlling the fixed-function blend state. When dual-source blending is available, it may also |
| 38 | * write a seconday fragment shader output color. GrXferProcessor has two modes of operation: |
| 39 | * |
| 40 | * Dst read: When allowed by the backend API, or when supplied a texture of the destination, the |
| 41 | * GrXferProcessor may read the destination color. While operating in this mode, the subclass only |
| 42 | * provides shader code that blends the src and dst colors, and the base class applies coverage. |
| 43 | * |
| 44 | * No dst read: When not performing a dst read, the subclass is given full control of the fixed- |
| 45 | * function blend state and/or secondary output, and is responsible to apply coverage on its own. |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 46 | * |
| 47 | * A GrXferProcessor is never installed directly into our draw state, but instead is created from a |
| 48 | * GrXPFactory once we have finalized the state of our draw. |
| 49 | */ |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 50 | class GrXferProcessor : public GrProcessor { |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 51 | public: |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 52 | using FragmentProcessorAnalysis = GrProcessorSet::FragmentProcessorAnalysis; |
| 53 | |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 54 | /** |
bsalomon | 6a44c6a | 2015-05-26 09:49:05 -0700 | [diff] [blame] | 55 | * A texture that contains the dst pixel values and an integer coord offset from device space |
| 56 | * to the space of the texture. Depending on GPU capabilities a DstTexture may be used by a |
| 57 | * GrXferProcessor for blending in the fragment shader. |
| 58 | */ |
| 59 | class DstTexture { |
| 60 | public: |
| 61 | DstTexture() { fOffset.set(0, 0); } |
| 62 | |
| 63 | DstTexture(const DstTexture& other) { |
| 64 | *this = other; |
| 65 | } |
| 66 | |
| 67 | DstTexture(GrTexture* texture, const SkIPoint& offset) |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 68 | : fTexture(SkSafeRef(texture)), fOffset(texture ? offset : SkIPoint{0, 0}) {} |
bsalomon | 6a44c6a | 2015-05-26 09:49:05 -0700 | [diff] [blame] | 69 | |
| 70 | DstTexture& operator=(const DstTexture& other) { |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 71 | fTexture = other.fTexture; |
bsalomon | 6a44c6a | 2015-05-26 09:49:05 -0700 | [diff] [blame] | 72 | fOffset = other.fOffset; |
| 73 | return *this; |
| 74 | } |
| 75 | |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 76 | bool operator==(const DstTexture& that) const { |
| 77 | return fTexture == that.fTexture && fOffset == that.fOffset; |
| 78 | } |
| 79 | bool operator!=(const DstTexture& that) const { return !(*this == that); } |
| 80 | |
bsalomon | 6a44c6a | 2015-05-26 09:49:05 -0700 | [diff] [blame] | 81 | const SkIPoint& offset() const { return fOffset; } |
| 82 | |
| 83 | void setOffset(const SkIPoint& offset) { fOffset = offset; } |
| 84 | void setOffset(int ox, int oy) { fOffset.set(ox, oy); } |
| 85 | |
| 86 | GrTexture* texture() const { return fTexture.get(); } |
| 87 | |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 88 | void setTexture(sk_sp<GrTexture> texture) { |
| 89 | fTexture = std::move(texture); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 90 | if (!fTexture) { |
| 91 | fOffset = {0, 0}; |
| 92 | } |
bsalomon | 6a44c6a | 2015-05-26 09:49:05 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | private: |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 96 | sk_sp<GrTexture> fTexture; |
| 97 | SkIPoint fOffset; |
bsalomon | 6a44c6a | 2015-05-26 09:49:05 -0700 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | /** |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 101 | * Sets a unique key on the GrProcessorKeyBuilder calls onGetGLSLProcessorKey(...) to get the |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 102 | * specific subclass's key. |
| 103 | */ |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 104 | void getGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const; |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 105 | |
| 106 | /** Returns a new instance of the appropriate *GL* implementation class |
| 107 | for the given GrXferProcessor; caller is responsible for deleting |
| 108 | the object. */ |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 109 | virtual GrGLSLXferProcessor* createGLSLInstance() const = 0; |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 110 | |
| 111 | /** |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 112 | * Optimizations for blending / coverage that an OptDrawState should apply to itself. |
| 113 | */ |
| 114 | enum OptFlags { |
| 115 | /** |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 116 | * GrXferProcessor will ignore color, thus no need to provide |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 117 | */ |
Brian Salomon | 02baee9 | 2017-02-24 10:37:15 -0500 | [diff] [blame] | 118 | kIgnoreColor_OptFlag = 0x1, |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 119 | /** |
Brian Salomon | 1c10fdd | 2017-03-03 14:30:15 -0500 | [diff] [blame] | 120 | * Can tweak alpha for coverage. |
egdaniel | 54160f3 | 2014-12-15 12:38:53 -0800 | [diff] [blame] | 121 | */ |
Brian Salomon | 1c10fdd | 2017-03-03 14:30:15 -0500 | [diff] [blame] | 122 | kCanTweakAlphaForCoverage_OptFlag = 0x2, |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 123 | }; |
| 124 | |
bsalomon | 7765a47 | 2015-07-08 11:26:37 -0700 | [diff] [blame] | 125 | static const OptFlags kNone_OptFlags = (OptFlags)0; |
| 126 | |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 127 | GR_DECL_BITFIELD_OPS_FRIENDS(OptFlags); |
| 128 | |
| 129 | /** |
| 130 | * Determines which optimizations (as described by the ptFlags above) can be performed by |
| 131 | * the draw with this xfer processor. If this function is called, the xfer processor may change |
Brian Salomon | 1c10fdd | 2017-03-03 14:30:15 -0500 | [diff] [blame] | 132 | * its state to reflected the given blend optimizations. Callers are required to honor the |
| 133 | * returned OptFlags. |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 134 | */ |
Brian Salomon | 1c10fdd | 2017-03-03 14:30:15 -0500 | [diff] [blame] | 135 | OptFlags getOptimizations(const FragmentProcessorAnalysis&) const; |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 136 | |
cdalton | 9954bc3 | 2015-04-29 14:17:00 -0700 | [diff] [blame] | 137 | /** |
| 138 | * Returns whether this XP will require an Xfer barrier on the given rt. If true, outBarrierType |
| 139 | * is updated to contain the type of barrier needed. |
| 140 | */ |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 141 | GrXferBarrierType xferBarrierType(const GrRenderTarget* rt, const GrCaps& caps) const; |
cdalton | 9954bc3 | 2015-04-29 14:17:00 -0700 | [diff] [blame] | 142 | |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 143 | struct BlendInfo { |
cdalton | f4f2b44 | 2015-04-23 09:40:23 -0700 | [diff] [blame] | 144 | void reset() { |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 145 | fEquation = kAdd_GrBlendEquation; |
cdalton | f4f2b44 | 2015-04-23 09:40:23 -0700 | [diff] [blame] | 146 | fSrcBlend = kOne_GrBlendCoeff; |
| 147 | fDstBlend = kZero_GrBlendCoeff; |
| 148 | fBlendConstant = 0; |
| 149 | fWriteColor = true; |
| 150 | } |
egdaniel | 080e673 | 2014-12-22 07:35:52 -0800 | [diff] [blame] | 151 | |
bsalomon | f7cc877 | 2015-05-11 11:21:14 -0700 | [diff] [blame] | 152 | SkDEBUGCODE(SkString dump() const;) |
| 153 | |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 154 | GrBlendEquation fEquation; |
| 155 | GrBlendCoeff fSrcBlend; |
| 156 | GrBlendCoeff fDstBlend; |
| 157 | GrColor fBlendConstant; |
| 158 | bool fWriteColor; |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 159 | }; |
| 160 | |
cdalton | edbb31f | 2015-06-08 12:14:44 -0700 | [diff] [blame] | 161 | void getBlendInfo(BlendInfo* blendInfo) const; |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 162 | |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 163 | bool willReadDstColor() const { return fWillReadDstColor; } |
| 164 | |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 165 | /** |
| 166 | * Returns the texture to be used as the destination when reading the dst in the fragment |
| 167 | * shader. If the returned texture is NULL then the XP is either not reading the dst or we have |
| 168 | * extentions that support framebuffer fetching and thus don't need a copy of the dst texture. |
| 169 | */ |
Brian Salomon | db4183d | 2016-11-17 12:48:40 -0500 | [diff] [blame] | 170 | const GrTexture* getDstTexture() const { return fDstTexture.texture(); } |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 171 | |
| 172 | /** |
bsalomon | 6a44c6a | 2015-05-26 09:49:05 -0700 | [diff] [blame] | 173 | * Returns the offset in device coords to use when accessing the dst texture to get the dst |
| 174 | * pixel color in the shader. This value is only valid if getDstTexture() != NULL. |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 175 | */ |
bsalomon | 6a44c6a | 2015-05-26 09:49:05 -0700 | [diff] [blame] | 176 | const SkIPoint& dstTextureOffset() const { |
| 177 | SkASSERT(this->getDstTexture()); |
| 178 | return fDstTextureOffset; |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 179 | } |
| 180 | |
egdaniel | c19cdc2 | 2015-05-10 08:45:18 -0700 | [diff] [blame] | 181 | /** |
cdalton | 86ae0a9 | 2015-06-08 15:11:04 -0700 | [diff] [blame] | 182 | * If we are performing a dst read, returns whether the base class will use mixed samples to |
| 183 | * antialias the shader's final output. If not doing a dst read, the subclass is responsible |
| 184 | * for antialiasing and this returns false. |
| 185 | */ |
| 186 | bool dstReadUsesMixedSamples() const { return fDstReadUsesMixedSamples; } |
| 187 | |
| 188 | /** |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 189 | * Returns whether or not this xferProcossor will set a secondary output to be used with dual |
| 190 | * source blending. |
| 191 | */ |
cdalton | edbb31f | 2015-06-08 12:14:44 -0700 | [diff] [blame] | 192 | bool hasSecondaryOutput() const; |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 193 | |
| 194 | /** Returns true if this and other processor conservatively draw identically. It can only return |
| 195 | true when the two processor are of the same subclass (i.e. they return the same object from |
| 196 | from getFactory()). |
| 197 | |
| 198 | A return value of true from isEqual() should not be used to test whether the processor would |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 199 | generate the same shader code. To test for identical code generation use getGLSLProcessorKey |
| 200 | */ |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 201 | |
| 202 | bool isEqual(const GrXferProcessor& that) const { |
| 203 | if (this->classID() != that.classID()) { |
| 204 | return false; |
| 205 | } |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 206 | if (this->fWillReadDstColor != that.fWillReadDstColor) { |
| 207 | return false; |
| 208 | } |
Brian Salomon | db4183d | 2016-11-17 12:48:40 -0500 | [diff] [blame] | 209 | if (this->fDstTexture.texture() != that.fDstTexture.texture()) { |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 210 | return false; |
| 211 | } |
bsalomon | 6a44c6a | 2015-05-26 09:49:05 -0700 | [diff] [blame] | 212 | if (this->fDstTextureOffset != that.fDstTextureOffset) { |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 213 | return false; |
| 214 | } |
cdalton | 86ae0a9 | 2015-06-08 15:11:04 -0700 | [diff] [blame] | 215 | if (this->fDstReadUsesMixedSamples != that.fDstReadUsesMixedSamples) { |
| 216 | return false; |
| 217 | } |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 218 | return this->onIsEqual(that); |
| 219 | } |
Brian Salomon | 92aee3d | 2016-12-21 09:20:25 -0500 | [diff] [blame] | 220 | |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 221 | protected: |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 222 | GrXferProcessor(); |
cdalton | 86ae0a9 | 2015-06-08 15:11:04 -0700 | [diff] [blame] | 223 | GrXferProcessor(const DstTexture*, bool willReadDstColor, bool hasMixedSamples); |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 224 | |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 225 | private: |
bsalomon | 4204800 | 2015-08-27 16:43:48 -0700 | [diff] [blame] | 226 | void notifyRefCntIsZero() const final {} |
| 227 | |
Brian Salomon | 1c10fdd | 2017-03-03 14:30:15 -0500 | [diff] [blame] | 228 | virtual OptFlags onGetOptimizations(const FragmentProcessorAnalysis&) const = 0; |
egdaniel | c19cdc2 | 2015-05-10 08:45:18 -0700 | [diff] [blame] | 229 | |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 230 | /** |
| 231 | * Sets a unique key on the GrProcessorKeyBuilder that is directly associated with this xfer |
| 232 | * processor's GL backend implementation. |
| 233 | */ |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 234 | virtual void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const = 0; |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 235 | |
cdalton | f4f2b44 | 2015-04-23 09:40:23 -0700 | [diff] [blame] | 236 | /** |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 237 | * Determines the type of barrier (if any) required by the subclass. Note that the possibility |
| 238 | * that a kTexture type barrier is required is handled by the base class and need not be |
| 239 | * considered by subclass overrides of this function. |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 240 | */ |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 241 | virtual GrXferBarrierType onXferBarrier(const GrRenderTarget*, const GrCaps&) const { |
| 242 | return kNone_GrXferBarrierType; |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | /** |
cdalton | edbb31f | 2015-06-08 12:14:44 -0700 | [diff] [blame] | 246 | * If we are not performing a dst read, returns whether the subclass will set a secondary |
cdalton | 86ae0a9 | 2015-06-08 15:11:04 -0700 | [diff] [blame] | 247 | * output. When using dst reads, the base class controls the secondary output and this method |
cdalton | edbb31f | 2015-06-08 12:14:44 -0700 | [diff] [blame] | 248 | * will not be called. |
| 249 | */ |
| 250 | virtual bool onHasSecondaryOutput() const { return false; } |
| 251 | |
| 252 | /** |
| 253 | * If we are not performing a dst read, retrieves the fixed-function blend state required by the |
cdalton | 86ae0a9 | 2015-06-08 15:11:04 -0700 | [diff] [blame] | 254 | * subclass. When using dst reads, the base class controls the fixed-function blend state and |
| 255 | * this method will not be called. The BlendInfo struct comes initialized to "no blending". |
cdalton | f4f2b44 | 2015-04-23 09:40:23 -0700 | [diff] [blame] | 256 | */ |
| 257 | virtual void onGetBlendInfo(BlendInfo*) const {} |
| 258 | |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 259 | virtual bool onIsEqual(const GrXferProcessor&) const = 0; |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 260 | |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 261 | bool fWillReadDstColor; |
cdalton | 86ae0a9 | 2015-06-08 15:11:04 -0700 | [diff] [blame] | 262 | bool fDstReadUsesMixedSamples; |
bsalomon | 6a44c6a | 2015-05-26 09:49:05 -0700 | [diff] [blame] | 263 | SkIPoint fDstTextureOffset; |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 264 | TextureSampler fDstTexture; |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 265 | |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 266 | typedef GrFragmentProcessor INHERITED; |
| 267 | }; |
| 268 | |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 269 | GR_MAKE_BITFIELD_OPS(GrXferProcessor::OptFlags); |
| 270 | |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 271 | /////////////////////////////////////////////////////////////////////////////// |
| 272 | |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 273 | /** |
| 274 | * We install a GrXPFactory (XPF) early on in the pipeline before all the final draw information is |
| 275 | * known (e.g. whether there is fractional pixel coverage, will coverage be 1 or 4 channel, is the |
| 276 | * draw opaque, etc.). Once the state of the draw is finalized, we use the XPF along with all the |
| 277 | * draw information to create a GrXferProcessor (XP) which can implement the desired blending for |
| 278 | * the draw. |
| 279 | * |
| 280 | * Before the XP is created, the XPF is able to answer queries about what functionality the XPs it |
| 281 | * creates will have. For example, can it create an XP that supports RGB coverage or will the XP |
| 282 | * blend with the destination color. |
Brian Salomon | a163392 | 2017-01-09 11:46:10 -0500 | [diff] [blame] | 283 | * |
| 284 | * GrXPFactories are intended to be static immutable objects. We pass them around as raw pointers |
| 285 | * and expect the pointers to always be valid and for the factories to be reusable and thread safe. |
| 286 | * Equality is tested for using pointer comparison. GrXPFactory destructors must be no-ops. |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 287 | */ |
Brian Salomon | a163392 | 2017-01-09 11:46:10 -0500 | [diff] [blame] | 288 | |
| 289 | // In order to construct GrXPFactory subclass instances as constexpr the subclass, and therefore |
| 290 | // GrXPFactory, must be a literal type. One requirement is having a trivial destructor. This is ok |
| 291 | // since these objects have no need for destructors. However, GCC and clang throw a warning when a |
| 292 | // class has virtual functions and a non-virtual destructor. We suppress that warning here and |
| 293 | // for the subclasses. |
| 294 | #if defined(__GNUC__) || defined(__clang) |
| 295 | #pragma GCC diagnostic push |
| 296 | #pragma GCC diagnostic ignored "-Wnon-virtual-dtor" |
| 297 | #endif |
| 298 | class GrXPFactory { |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 299 | public: |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 300 | using FragmentProcessorAnalysis = GrProcessorSet::FragmentProcessorAnalysis; |
| 301 | |
bsalomon | 6a44c6a | 2015-05-26 09:49:05 -0700 | [diff] [blame] | 302 | typedef GrXferProcessor::DstTexture DstTexture; |
Brian Salomon | 5be6c95 | 2017-01-20 19:06:29 +0000 | [diff] [blame] | 303 | |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 304 | GrXferProcessor* createXferProcessor(const FragmentProcessorAnalysis&, |
cdalton | 86ae0a9 | 2015-06-08 15:11:04 -0700 | [diff] [blame] | 305 | bool hasMixedSamples, |
bsalomon | 6a44c6a | 2015-05-26 09:49:05 -0700 | [diff] [blame] | 306 | const DstTexture*, |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 307 | const GrCaps& caps) const; |
Brian Salomon | 9a51498 | 2017-02-14 10:28:22 -0500 | [diff] [blame] | 308 | |
cdalton | 1fa4572 | 2015-06-02 10:43:39 -0700 | [diff] [blame] | 309 | /** |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 310 | * This will return true if the xfer processor needs the dst color in the shader and the way |
| 311 | * that the color will be made available to the xfer processor is by sampling a texture. |
| 312 | */ |
| 313 | static bool WillNeedDstTexture(const GrXPFactory*, |
| 314 | const GrCaps&, |
| 315 | const FragmentProcessorAnalysis&); |
egdaniel | 080e673 | 2014-12-22 07:35:52 -0800 | [diff] [blame] | 316 | |
Brian Salomon | 780b41f | 2017-03-13 10:36:40 -0400 | [diff] [blame] | 317 | static bool CompatibleWithCoverageAsAlpha(const GrXPFactory*, bool colorIsOpaque); |
| 318 | |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 319 | /** |
| 320 | * This indicates whether the the xfer processor will produce the same bleneded color result |
| 321 | * if a series of overlapping stencil and cover operations are replaced by a series of stencil |
| 322 | * operations and a single cover. A uniform src color is assumed. |
| 323 | **/ |
| 324 | static bool CanCombineOverlappedStencilAndCover(const GrXPFactory*, bool colorIsOpaque); |
| 325 | |
egdaniel | 915187b | 2014-12-05 12:58:28 -0800 | [diff] [blame] | 326 | protected: |
Brian Salomon | a163392 | 2017-01-09 11:46:10 -0500 | [diff] [blame] | 327 | constexpr GrXPFactory() {} |
egdaniel | 915187b | 2014-12-05 12:58:28 -0800 | [diff] [blame] | 328 | |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 329 | private: |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 330 | virtual GrXferProcessor* onCreateXferProcessor(const GrCaps& caps, |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 331 | const FragmentProcessorAnalysis&, |
cdalton | 86ae0a9 | 2015-06-08 15:11:04 -0700 | [diff] [blame] | 332 | bool hasMixedSamples, |
bsalomon | 6a44c6a | 2015-05-26 09:49:05 -0700 | [diff] [blame] | 333 | const DstTexture*) const = 0; |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 334 | |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 335 | /** |
| 336 | * Returns true if the XP generated by this factory will explicitly read dst in the fragment |
Brian Salomon | 42c456f | 2017-03-06 11:29:48 -0500 | [diff] [blame] | 337 | * shader. |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 338 | */ |
Brian Salomon | 42c456f | 2017-03-06 11:29:48 -0500 | [diff] [blame] | 339 | virtual bool willReadDstInShader(const GrCaps&, const FragmentProcessorAnalysis&) const = 0; |
Brian Salomon | 780b41f | 2017-03-13 10:36:40 -0400 | [diff] [blame] | 340 | |
| 341 | virtual bool compatibleWithCoverageAsAlpha(bool colorIsOpaque) const = 0; |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 342 | virtual bool canCombineOverlappedStencilAndCover(bool colorIsOpaque) const { return false; } |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 343 | }; |
Brian Salomon | a163392 | 2017-01-09 11:46:10 -0500 | [diff] [blame] | 344 | #if defined(__GNUC__) || defined(__clang) |
| 345 | #pragma GCC diagnostic pop |
| 346 | #endif |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 347 | |
| 348 | #endif |
| 349 | |