Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1331)

Side by Side Diff: include/gpu/GrXferProcessor.h

Issue 759713002: Make all blending up to GrOptDrawState be handled by the xp/xp factory. (Closed) Base URL: https://skia.googlesource.com/skia.git@xferFactorySolo
Patch Set: rebase Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/gpu/GrPaint.h ('k') | include/gpu/effects/GrPorterDuffXferProcessor.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 OptFlags {
37 /**
38 * No optimizations needed
39 */
40 kNone_Opt = 0,
41 /**
42 * The draw can be skipped completely.
43 */
44 kSkipDraw_OptFlag = 0x1,
45 /**
46 * Clear color stages, remove color vertex attribs, and use input color
47 */
48 kClearColorStages_OptFlag = 0x2,
49 /**
50 * Clear coverage stages, remove coverage vertex attribs, and use input coverage
51 */
52 kClearCoverageStages_OptFlag = 0x4,
53 /**
54 * Set CoverageDrawing_StateBit
55 */
56 kSetCoverageDrawing_OptFlag = 0x8,
57 };
58
59 GR_DECL_BITFIELD_OPS_FRIENDS(OptFlags);
60
61 /**
62 * Determines which optimizations (as described by the ptFlags 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 OptFlags
67 * and color/coverage values for its draw.
68 */
69 // 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.
71 virtual OptFlags getOptimizations(const GrProcOptInfo& colorPOI,
72 const GrProcOptInfo& coveragePOI,
73 bool isCoverageDrawing,
74 bool colorWriteDisabled,
75 bool doesStencilWrite,
76 GrColor* color,
77 uint8_t* coverage) = 0;
78
79 struct BlendInfo {
80 GrBlendCoeff fSrcBlend;
81 GrBlendCoeff fDstBlend;
82 GrColor fBlendConstant;
83 };
84
85 virtual void getBlendInfo(BlendInfo* blendInfo) const = 0;
86
87 /** Will this prceossor read the destination pixel value? */
88 bool willReadDstColor() const { return fWillReadDstColor; }
89
90 protected:
91 GrXferProcessor() : fWillReadDstColor(false) {}
92
93 /**
94 * 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
96 * attempts to generate code that reads the destination pixel it will fail.
97 */
98 void setWillReadDstColor() { fWillReadDstColor = true; }
99
30 private: 100 private:
31 101
102 bool fWillReadDstColor;
103
32 typedef GrFragmentProcessor INHERITED; 104 typedef GrFragmentProcessor INHERITED;
33 }; 105 };
34 106
107 GR_MAKE_BITFIELD_OPS(GrXferProcessor::OptFlags);
108
35 /** 109 /**
36 * We install a GrXPFactory (XPF) early on in the pipeline before all the final draw information is 110 * 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 111 * 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 112 * 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 113 * draw information to create a GrXferProcessor (XP) which can implement the des ired blending for
40 * the draw. 114 * the draw.
41 * 115 *
42 * Before the XP is created, the XPF is able to answer queries about what functi onality the XPs it 116 * 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 117 * 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. 118 * blend with the destination color.
45 */ 119 */
46 class GrXPFactory : public SkRefCnt { 120 class GrXPFactory : public SkRefCnt {
47 public: 121 public:
48 virtual const GrXferProcessor* createXferProcessor() const = 0; 122 virtual GrXferProcessor* createXferProcessor(const GrProcOptInfo& colorPOI,
123 const GrProcOptInfo& coveragePO I) const = 0;
49 124
50 /** 125 /**
51 * This function returns true if the GrXferProcessor generated from this fac tory will be able to 126 * 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 127 * correctly blend when using RGB coverage. The knownColor and knownColorFla gs represent the
53 * final computed color from the color stages. 128 * final computed color from the color stages.
54 */ 129 */
55 virtual bool supportsRGBCoverage(GrColor knownColor, uint32_t knownColorFlag s) const = 0; 130 virtual bool supportsRGBCoverage(GrColor knownColor, uint32_t knownColorFlag s) const = 0;
56 131
132 /**
133 * Depending on color blend mode requested it may or may not be possible to correctly blend with
134 * fractional pixel coverage generated by the fragment shader.
135 *
136 * This function considers the known color and coverage input into the xfer processor and
137 * certain state information (isCoverageDrawing and colorWriteDisabled) to d etermine whether
138 * coverage can be handled correctly.
139 */
140 // TODO: remove need for isCoverageDrawing once coverageDrawing is its own X P.
141 // TODO: remove need for colorWriteDisabled once colorWriteDisabled is its o wn XP.
142 virtual bool canApplyCoverage(const GrProcOptInfo& colorPOI, const GrProcOpt Info& coveragePOI,
143 bool isCoverageDrawing, bool colorWriteDisable d) const = 0;
144
145 /**
146 * This function returns true if the destination pixel values will be read f or blending during
147 * draw.
148 */
149 // TODO: remove need for isCoverageDrawing once coverageDrawing is its own X P.
150 // TODO: remove need for colorWriteDisabled once only XP can read dst.
151 virtual bool willBlendWithDst(const GrProcOptInfo& colorPOI, const GrProcOpt Info& coveragePOI,
152 bool isCoverageDrawing, bool colorWriteDisable d) const = 0;
153
154 /**
155 * Determines whether multiplying the computed per-pixel color by the pixel' s fractional
156 * coverage before the blend will give the correct final destination color. In general it
157 * will not as coverage is applied after blending.
158 */
159 // TODO: remove need for isCoverageDrawing once coverageDrawing is its own X P.
160 virtual bool canTweakAlphaForCoverage(bool isCoverageDrawing) const = 0;
161
162 virtual bool getOpaqueAndKnownColor(const GrProcOptInfo& colorPOI,
163 const GrProcOptInfo& coveragePOI, GrColo r* solidColor,
164 uint32_t* solidColorKnownComponents) con st = 0;
165
57 bool isEqual(const GrXPFactory& that) const { 166 bool isEqual(const GrXPFactory& that) const {
58 if (this->classID() != that.classID()) { 167 if (this->classID() != that.classID()) {
59 return false; 168 return false;
60 } 169 }
61 return this->onIsEqual(that); 170 return this->onIsEqual(that);
62 } 171 }
63 172
64 /** 173 /**
65 * Helper for down-casting to a GrXPFactory subclass 174 * Helper for down-casting to a GrXPFactory subclass
66 */ 175 */
(...skipping 29 matching lines...) Expand all
96 enum { 205 enum {
97 kIllegalXPFClassID = 0, 206 kIllegalXPFClassID = 0,
98 }; 207 };
99 static int32_t gCurrXPFClassID; 208 static int32_t gCurrXPFClassID;
100 209
101 typedef GrProgramElement INHERITED; 210 typedef GrProgramElement INHERITED;
102 }; 211 };
103 212
104 #endif 213 #endif
105 214
OLDNEW
« no previous file with comments | « include/gpu/GrPaint.h ('k') | include/gpu/effects/GrPorterDuffXferProcessor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698