| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrXferProcessor_DEFINED | 8 #ifndef GrXferProcessor_DEFINED |
| 9 #define GrXferProcessor_DEFINED | 9 #define GrXferProcessor_DEFINED |
| 10 | 10 |
| 11 #include "GrColor.h" | 11 #include "GrColor.h" |
| 12 #include "GrFragmentProcessor.h" | 12 #include "GrProcessor.h" |
| 13 #include "GrTypes.h" | 13 #include "GrTypes.h" |
| 14 #include "SkXfermode.h" | 14 #include "SkXfermode.h" |
| 15 | 15 |
| 16 class GrDrawTargetCaps; |
| 17 class GrGLCaps; |
| 18 class GrGLXferProcessor; |
| 16 class GrProcOptInfo; | 19 class GrProcOptInfo; |
| 17 | 20 |
| 18 /** | 21 /** |
| 19 * GrXferProcessor is responsible for implementing the xfer mode that blends the
src color and dst | 22 * GrXferProcessor is responsible for implementing the xfer mode that blends the
src color and dst |
| 20 * color. It does this by emitting fragment shader code and controlling the fixe
d-function blend | 23 * color. It does this by emitting fragment shader code and controlling the fixe
d-function blend |
| 21 * state. The inputs to its shader code are the final computed src color and fra
ctional pixel | 24 * state. The inputs to its shader code are the final computed src color and fra
ctional pixel |
| 22 * coverage. The GrXferProcessor's shader code writes the fragment shader output
color that goes | 25 * coverage. The GrXferProcessor's shader code writes the fragment shader output
color that goes |
| 23 * into the fixed-function blend. When dual-source blending is available, it may
also write a | 26 * into the fixed-function blend. When dual-source blending is available, it may
also write a |
| 24 * seconday fragment shader output color. When allowed by the backend API, the G
rXferProcessor may | 27 * seconday fragment shader output color. When allowed by the backend API, the G
rXferProcessor may |
| 25 * read the destination color. The GrXferProcessor is responsible for setting th
e blend coefficients | 28 * read the destination color. The GrXferProcessor is responsible for setting th
e blend coefficients |
| 26 * and blend constant color. | 29 * and blend constant color. |
| 27 * | 30 * |
| 28 * A GrXferProcessor is never installed directly into our draw state, but instea
d is created from a | 31 * A GrXferProcessor is never installed directly into our draw state, but instea
d is created from a |
| 29 * GrXPFactory once we have finalized the state of our draw. | 32 * GrXPFactory once we have finalized the state of our draw. |
| 30 */ | 33 */ |
| 31 class GrXferProcessor : public GrFragmentProcessor { | 34 class GrXferProcessor : public GrProcessor { |
| 32 public: | 35 public: |
| 33 /** | 36 /** |
| 37 * Sets a unique key on the GrProcessorKeyBuilder that is directly associate
d with this xfer |
| 38 * processor's GL backend implementation. |
| 39 */ |
| 40 virtual void getGLProcessorKey(const GrGLCaps& caps, |
| 41 GrProcessorKeyBuilder* b) const = 0; |
| 42 |
| 43 /** Returns a new instance of the appropriate *GL* implementation class |
| 44 for the given GrXferProcessor; caller is responsible for deleting |
| 45 the object. */ |
| 46 virtual GrGLXferProcessor* createGLInstance() const = 0; |
| 47 |
| 48 /** |
| 34 * Optimizations for blending / coverage that an OptDrawState should apply t
o itself. | 49 * Optimizations for blending / coverage that an OptDrawState should apply t
o itself. |
| 35 */ | 50 */ |
| 36 enum OptFlags { | 51 enum OptFlags { |
| 37 /** | 52 /** |
| 38 * No optimizations needed | 53 * No optimizations needed |
| 39 */ | 54 */ |
| 40 kNone_Opt = 0, | 55 kNone_Opt = 0, |
| 41 /** | 56 /** |
| 42 * The draw can be skipped completely. | 57 * The draw can be skipped completely. |
| 43 */ | 58 */ |
| (...skipping 23 matching lines...) Expand all Loading... |
| 67 * and color/coverage values for its draw. | 82 * and color/coverage values for its draw. |
| 68 */ | 83 */ |
| 69 // TODO: remove need for isCoverageDrawing once coverageDrawing is its own X
P. | 84 // TODO: remove need for isCoverageDrawing once coverageDrawing is its own X
P. |
| 70 // TODO: remove need for colorWriteDisabled once colorWriteDisabled is its o
wn XP. | 85 // TODO: remove need for colorWriteDisabled once colorWriteDisabled is its o
wn XP. |
| 71 virtual OptFlags getOptimizations(const GrProcOptInfo& colorPOI, | 86 virtual OptFlags getOptimizations(const GrProcOptInfo& colorPOI, |
| 72 const GrProcOptInfo& coveragePOI, | 87 const GrProcOptInfo& coveragePOI, |
| 73 bool isCoverageDrawing, | 88 bool isCoverageDrawing, |
| 74 bool colorWriteDisabled, | 89 bool colorWriteDisabled, |
| 75 bool doesStencilWrite, | 90 bool doesStencilWrite, |
| 76 GrColor* color, | 91 GrColor* color, |
| 77 uint8_t* coverage) = 0; | 92 uint8_t* coverage, |
| 93 const GrDrawTargetCaps& caps) = 0; |
| 78 | 94 |
| 79 struct BlendInfo { | 95 struct BlendInfo { |
| 80 GrBlendCoeff fSrcBlend; | 96 GrBlendCoeff fSrcBlend; |
| 81 GrBlendCoeff fDstBlend; | 97 GrBlendCoeff fDstBlend; |
| 82 GrColor fBlendConstant; | 98 GrColor fBlendConstant; |
| 83 }; | 99 }; |
| 84 | 100 |
| 85 virtual void getBlendInfo(BlendInfo* blendInfo) const = 0; | 101 virtual void getBlendInfo(BlendInfo* blendInfo) const = 0; |
| 86 | 102 |
| 87 /** Will this prceossor read the destination pixel value? */ | 103 /** Will this prceossor read the destination pixel value? */ |
| 88 bool willReadDstColor() const { return fWillReadDstColor; } | 104 bool willReadDstColor() const { return fWillReadDstColor; } |
| 89 | 105 |
| 106 /** |
| 107 * Returns whether or not this xferProcossor will set a secondary output to
be used with dual |
| 108 * source blending. |
| 109 */ |
| 110 virtual bool hasSecondaryOutput() const { return false; } |
| 111 |
| 112 /** Returns true if this and other processor conservatively draw identically
. It can only return |
| 113 true when the two processor are of the same subclass (i.e. they return t
he same object from |
| 114 from getFactory()). |
| 115 |
| 116 A return value of true from isEqual() should not be used to test whether
the processor would |
| 117 generate the same shader code. To test for identical code generation use
getGLProcessorKey*/ |
| 118 |
| 119 bool isEqual(const GrXferProcessor& that) const { |
| 120 if (this->classID() != that.classID()) { |
| 121 return false; |
| 122 } |
| 123 return this->onIsEqual(that); |
| 124 } |
| 125 |
| 126 |
| 90 protected: | 127 protected: |
| 91 GrXferProcessor() : fWillReadDstColor(false) {} | 128 GrXferProcessor() : fWillReadDstColor(false) {} |
| 92 | 129 |
| 93 /** | 130 /** |
| 94 * If the prceossor subclass will read the destination pixel value then it m
ust call this | 131 * If the prceossor subclass will read the destination pixel value then it m
ust call this |
| 95 * function from its constructor. Otherwise, when its generated backend-spec
ific prceossor class | 132 * function from its constructor. Otherwise, when its generated backend-spec
ific prceossor class |
| 96 * attempts to generate code that reads the destination pixel it will fail. | 133 * attempts to generate code that reads the destination pixel it will fail. |
| 97 */ | 134 */ |
| 98 void setWillReadDstColor() { fWillReadDstColor = true; } | 135 void setWillReadDstColor() { fWillReadDstColor = true; } |
| 99 | 136 |
| 100 private: | 137 private: |
| 138 virtual bool onIsEqual(const GrXferProcessor&) const = 0; |
| 101 | 139 |
| 102 bool fWillReadDstColor; | 140 bool fWillReadDstColor; |
| 103 | 141 |
| 104 typedef GrFragmentProcessor INHERITED; | 142 typedef GrFragmentProcessor INHERITED; |
| 105 }; | 143 }; |
| 106 | 144 |
| 107 GR_MAKE_BITFIELD_OPS(GrXferProcessor::OptFlags); | 145 GR_MAKE_BITFIELD_OPS(GrXferProcessor::OptFlags); |
| 108 | 146 |
| 109 /** | 147 /** |
| 110 * We install a GrXPFactory (XPF) early on in the pipeline before all the final
draw information is | 148 * We install a GrXPFactory (XPF) early on in the pipeline before all the final
draw information is |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 enum { | 243 enum { |
| 206 kIllegalXPFClassID = 0, | 244 kIllegalXPFClassID = 0, |
| 207 }; | 245 }; |
| 208 static int32_t gCurrXPFClassID; | 246 static int32_t gCurrXPFClassID; |
| 209 | 247 |
| 210 typedef GrProgramElement INHERITED; | 248 typedef GrProgramElement INHERITED; |
| 211 }; | 249 }; |
| 212 | 250 |
| 213 #endif | 251 #endif |
| 214 | 252 |
| OLD | NEW |