Chromium Code Reviews| 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 "GrFragmentProcessor.h" |
| 13 #include "GrTypes.h" | 13 #include "GrTypes.h" |
| 14 #include "SkXfermode.h" | 14 #include "SkXfermode.h" |
| 15 | 15 |
| 16 class GrProcOptInfo; | |
| 17 | |
| 16 /** | 18 /** |
| 17 * GrXferProcessor is responsible for implementing the xfer mode that blends the src color and dst | 19 * GrXferProcessor is responsible for implementing the xfer mode that blends the src color and dst |
| 18 * color. It does this by emitting fragment shader code and controlling the fixe d-function blend | 20 * color. It does this by emitting fragment shader code and controlling the fixe d-function blend |
| 19 * state. The inputs to its shader code are the final computed src color and fra ctional pixel | 21 * state. The inputs to its shader code are the final computed src color and fra ctional pixel |
| 20 * coverage. The GrXferProcessor's shader code writes the fragment shader output color that goes | 22 * coverage. The GrXferProcessor's shader code writes the fragment shader output color that goes |
| 21 * into the fixed-function blend. When dual-source blending is available, it may also write a | 23 * into the fixed-function blend. When dual-source blending is available, it may also write a |
| 22 * seconday fragment shader output color. When allowed by the backend API, the G rXferProcessor may | 24 * seconday fragment shader output color. When allowed by the backend API, the G rXferProcessor may |
| 23 * read the destination color. The GrXferProcessor is responsible for setting th e blend coefficients | 25 * read the destination color. The GrXferProcessor is responsible for setting th e blend coefficients |
| 24 * and blend constant color. | 26 * and blend constant color. |
| 25 * | 27 * |
| 26 * A GrXferProcessor is never installed directly into our draw state, but instea d is created from a | 28 * A GrXferProcessor is never installed directly into our draw state, but instea d is created from a |
| 27 * GrXPFactory once we have finalized the state of our draw. | 29 * GrXPFactory once we have finalized the state of our draw. |
| 28 */ | 30 */ |
| 29 class GrXferProcessor : public GrFragmentProcessor { | 31 class GrXferProcessor : public GrFragmentProcessor { |
| 32 public: | |
| 33 /** | |
| 34 * Optimizations for blending / coverage that an OptDrawState should apply t o itself. | |
| 35 */ | |
| 36 enum BlendOptFlags { | |
|
bsalomon
2014/12/04 21:54:24
Howabout just OptFlags? It's already scoped by GrX
egdaniel
2014/12/08 14:52:06
Done.
| |
| 37 /** | |
| 38 * No optimizations needed | |
| 39 */ | |
| 40 kNone_BlendOpt = 0, | |
| 41 /** | |
| 42 * The draw can be skipped completely. | |
| 43 */ | |
| 44 kSkipDraw_BlendOptFlag = 0x1, | |
| 45 /** | |
| 46 * Clear color stages, remove color vertex attribs, and use input color | |
| 47 */ | |
| 48 kClearColorStages_BlendOptFlag = 0x2, | |
| 49 /** | |
| 50 * Clear coverage stages, remove coverage vertex attribs, and use input coverage | |
| 51 */ | |
| 52 kClearCoverageStages_BlendOptFlag = 0x4, | |
| 53 /** | |
| 54 * Set CoverageDrawing_StateBit | |
| 55 */ | |
| 56 kSetCoverageDrawing_BlendOptFlag = 0x8, | |
| 57 }; | |
| 58 | |
| 59 GR_DECL_BITFIELD_OPS_FRIENDS(BlendOptFlags); | |
| 60 | |
| 61 /** | |
| 62 * Determines which optimizations (as described by the BlendOptFlags above) can be performed by | |
| 63 * the draw with this xfer processor. If this function is called, the xfer p rocessor may change | |
| 64 * its state to reflected the given blend optimizations. It will also set th e output parameters, | |
| 65 * color and coverage, to specific values if it decides to remove all color or coverage stages. | |
| 66 * A caller who calls this function on a XP is required to honor the returne d BlendOptFlags | |
| 67 * and color/coverage values for its draw. | |
| 68 */ | |
| 69 // TODO: remove need for isCoverageDrawing once coverageDrawing is its own X P. | |
| 70 virtual BlendOptFlags getBlendOpts(const GrProcOptInfo& colorPOI, | |
| 71 const GrProcOptInfo& coveragePOI, | |
| 72 bool isCoverageDrawing, | |
| 73 bool colorWriteDisabled, | |
| 74 bool doesStencilWrite, | |
| 75 GrColor* color, | |
| 76 uint8_t* coverage) = 0; | |
| 77 | |
| 78 struct BlendInfo { | |
| 79 GrBlendCoeff fSrcBlend; | |
| 80 GrBlendCoeff fDstBlend; | |
| 81 GrColor fBlendConstant; | |
| 82 }; | |
| 83 | |
| 84 virtual void getBlendInfo(BlendInfo* blendInfo) const { | |
|
bsalomon
2014/12/04 21:54:24
= 0?
egdaniel
2014/12/08 14:52:06
Done.
| |
| 85 SkASSERT(blendInfo); | |
| 86 blendInfo->fSrcBlend = kOne_GrBlendCoeff; | |
| 87 blendInfo->fDstBlend = kZero_GrBlendCoeff; | |
| 88 blendInfo->fBlendConstant = 0; | |
| 89 } | |
| 90 | |
| 91 /** Will this prceossor read the destination pixel value? */ | |
| 92 bool willReadDstColor() const { return fWillReadDstColor; } | |
| 93 | |
| 94 protected: | |
| 95 GrXferProcessor() : fWillReadDstColor(false) {} | |
| 96 | |
| 97 /** | |
| 98 * If the prceossor subclass will read the destination pixel value then it m ust call this | |
| 99 * function from its constructor. Otherwise, when its generated backend-spec ific prceossor class | |
| 100 * attempts to generate code that reads the destination pixel it will fail. | |
| 101 */ | |
| 102 void setWillReadDstColor() { fWillReadDstColor = true; } | |
| 103 | |
| 30 private: | 104 private: |
| 31 | 105 |
| 106 bool fWillReadDstColor; | |
| 107 | |
| 32 typedef GrFragmentProcessor INHERITED; | 108 typedef GrFragmentProcessor INHERITED; |
| 33 }; | 109 }; |
| 34 | 110 |
| 111 GR_MAKE_BITFIELD_OPS(GrXferProcessor::BlendOptFlags); | |
| 112 | |
| 35 /** | 113 /** |
| 36 * We install a GrXPFactory (XPF) early on in the pipeline before all the final draw information is | 114 * We install a GrXPFactory (XPF) early on in the pipeline before all the final draw information is |
| 37 * known (e.g. whether there is fractional pixel coverage, will coverage be 1 or 4 channel, is the | 115 * known (e.g. whether there is fractional pixel coverage, will coverage be 1 or 4 channel, is the |
| 38 * draw opaque, etc.). Once the state of the draw is finalized, we use the XPF a long with all the | 116 * draw opaque, etc.). Once the state of the draw is finalized, we use the XPF a long with all the |
| 39 * draw information to create a GrXferProcessor (XP) which can implement the des ired blending for | 117 * draw information to create a GrXferProcessor (XP) which can implement the des ired blending for |
| 40 * the draw. | 118 * the draw. |
| 41 * | 119 * |
| 42 * Before the XP is created, the XPF is able to answer queries about what functi onality the XPs it | 120 * Before the XP is created, the XPF is able to answer queries about what functi onality the XPs it |
| 43 * creates will have. For example, can it create an XP that supports RGB coverag e or will the XP | 121 * creates will have. For example, can it create an XP that supports RGB coverag e or will the XP |
| 44 * blend with the destination color. | 122 * blend with the destination color. |
| 45 */ | 123 */ |
| 46 class GrXPFactory : public SkRefCnt { | 124 class GrXPFactory : public SkRefCnt { |
| 47 public: | 125 public: |
| 48 virtual const GrXferProcessor* createXferProcessor() const = 0; | 126 virtual GrXferProcessor* createXferProcessor(const GrProcOptInfo& colorPOI, |
| 127 const GrProcOptInfo& coveragePO I) const = 0; | |
| 49 | 128 |
| 50 /** | 129 /** |
| 51 * This function returns true if the GrXferProcessor generated from this fac tory will be able to | 130 * This function returns true if the GrXferProcessor generated from this fac tory will be able to |
| 52 * correctly blend when using RGB coverage. The knownColor and knownColorFla gs represent the | 131 * correctly blend when using RGB coverage. The knownColor and knownColorFla gs represent the |
| 53 * final computed color from the color stages. | 132 * final computed color from the color stages. |
| 54 */ | 133 */ |
| 55 virtual bool supportsRGBCoverage(GrColor knownColor, uint32_t knownColorFlag s) const = 0; | 134 virtual bool supportsRGBCoverage(GrColor knownColor, uint32_t knownColorFlag s) const = 0; |
| 56 | 135 |
| 136 /** | |
| 137 * Depending on color blend mode requested it may or may not be possible to correctly blend with | |
| 138 * fractional pixel coverage generated by the fragment shader. | |
| 139 * | |
| 140 * This function considers the known color and coverage input into the xfer processor and | |
| 141 * certain state information (isCoverageDrawing and colorWriteDisabled) to d etermine whether | |
| 142 * coverage can be handled correctly. | |
| 143 */ | |
| 144 // TODO: remove need for isCoverageDrawing once coverageDrawing is its own X P. | |
|
bsalomon
2014/12/04 21:54:24
Do we need colorWriteDisabled?
Can we just not em
egdaniel
2014/12/08 14:52:06
Nothing changed as of now. But from our previous d
| |
| 145 virtual bool canApplyCoverage(const GrProcOptInfo& colorPOI, const GrProcOpt Info& coveragePOI, | |
| 146 bool isCoverageDrawing, bool colorWriteDisable d) const = 0; | |
| 147 | |
| 148 /** | |
| 149 * This function returns true if the destination pixel values will be read f or blending during | |
| 150 * draw. | |
| 151 */ | |
| 152 // TODO: remove need for isCoverageDrawing once coverageDrawing is its own X P. | |
| 153 // TODO: remove need for colorWriteDisabled once only XP can read dst. | |
| 154 virtual bool willBlendWithDst(const GrProcOptInfo& colorPOI, const GrProcOpt Info& coveragePOI, | |
| 155 bool isCoverageDrawing, bool colorWriteDisable d) const = 0; | |
| 156 | |
| 157 /** | |
| 158 * Determines whether multiplying the computed per-pixel color by the pixel' s fractional | |
| 159 * coverage before the blend will give the correct final destination color. In general it | |
| 160 * will not as coverage is applied after blending. | |
| 161 */ | |
| 162 // TODO: remove need for isCoverageDrawing once coverageDrawing is its own X P. | |
| 163 virtual bool canTweakAlphaForCoverage(bool isCoverageDrawing) const = 0; | |
| 164 | |
| 165 virtual bool getOpaqueAndKnownColor(const GrProcOptInfo& colorPOI, | |
| 166 const GrProcOptInfo& coveragePOI, GrColo r* solidColor, | |
| 167 uint32_t* solidColorKnownComponents) con st = 0; | |
| 168 | |
| 57 private: | 169 private: |
| 58 typedef GrProgramElement INHERITED; | 170 typedef GrProgramElement INHERITED; |
| 59 }; | 171 }; |
| 60 | 172 |
| 61 #endif | 173 #endif |
| 62 | 174 |
| OLD | NEW |