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

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

Issue 766653008: Revert of 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: 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
18 /** 16 /**
19 * GrXferProcessor is responsible for implementing the xfer mode that blends the src color and dst 17 * 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 18 * 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 19 * 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 20 * 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 21 * 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 22 * 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 23 * read the destination color. The GrXferProcessor is responsible for setting th e blend coefficients
26 * and blend constant color. 24 * and blend constant color.
27 * 25 *
28 * A GrXferProcessor is never installed directly into our draw state, but instea d is created from a 26 * 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. 27 * GrXPFactory once we have finalized the state of our draw.
30 */ 28 */
31 class GrXferProcessor : public GrFragmentProcessor { 29 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
100 private: 30 private:
101 31
102 bool fWillReadDstColor;
103
104 typedef GrFragmentProcessor INHERITED; 32 typedef GrFragmentProcessor INHERITED;
105 }; 33 };
106 34
107 GR_MAKE_BITFIELD_OPS(GrXferProcessor::OptFlags);
108
109 /** 35 /**
110 * We install a GrXPFactory (XPF) early on in the pipeline before all the final draw information is 36 * We install a GrXPFactory (XPF) early on in the pipeline before all the final draw information is
111 * known (e.g. whether there is fractional pixel coverage, will coverage be 1 or 4 channel, is the 37 * known (e.g. whether there is fractional pixel coverage, will coverage be 1 or 4 channel, is the
112 * draw opaque, etc.). Once the state of the draw is finalized, we use the XPF a long with all the 38 * draw opaque, etc.). Once the state of the draw is finalized, we use the XPF a long with all the
113 * draw information to create a GrXferProcessor (XP) which can implement the des ired blending for 39 * draw information to create a GrXferProcessor (XP) which can implement the des ired blending for
114 * the draw. 40 * the draw.
115 * 41 *
116 * Before the XP is created, the XPF is able to answer queries about what functi onality the XPs it 42 * Before the XP is created, the XPF is able to answer queries about what functi onality the XPs it
117 * creates will have. For example, can it create an XP that supports RGB coverag e or will the XP 43 * creates will have. For example, can it create an XP that supports RGB coverag e or will the XP
118 * blend with the destination color. 44 * blend with the destination color.
119 */ 45 */
120 class GrXPFactory : public SkRefCnt { 46 class GrXPFactory : public SkRefCnt {
121 public: 47 public:
122 virtual GrXferProcessor* createXferProcessor(const GrProcOptInfo& colorPOI, 48 virtual const GrXferProcessor* createXferProcessor() const = 0;
123 const GrProcOptInfo& coveragePO I) const = 0;
124 49
125 /** 50 /**
126 * This function returns true if the GrXferProcessor generated from this fac tory will be able to 51 * This function returns true if the GrXferProcessor generated from this fac tory will be able to
127 * correctly blend when using RGB coverage. The knownColor and knownColorFla gs represent the 52 * correctly blend when using RGB coverage. The knownColor and knownColorFla gs represent the
128 * final computed color from the color stages. 53 * final computed color from the color stages.
129 */ 54 */
130 virtual bool supportsRGBCoverage(GrColor knownColor, uint32_t knownColorFlag s) const = 0; 55 virtual bool supportsRGBCoverage(GrColor knownColor, uint32_t knownColorFlag s) const = 0;
131 56
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
166 bool isEqual(const GrXPFactory& that) const { 57 bool isEqual(const GrXPFactory& that) const {
167 if (this->classID() != that.classID()) { 58 if (this->classID() != that.classID()) {
168 return false; 59 return false;
169 } 60 }
170 return this->onIsEqual(that); 61 return this->onIsEqual(that);
171 } 62 }
172 63
173 /** 64 /**
174 * Helper for down-casting to a GrXPFactory subclass 65 * Helper for down-casting to a GrXPFactory subclass
175 */ 66 */
(...skipping 29 matching lines...) Expand all
205 enum { 96 enum {
206 kIllegalXPFClassID = 0, 97 kIllegalXPFClassID = 0,
207 }; 98 };
208 static int32_t gCurrXPFClassID; 99 static int32_t gCurrXPFClassID;
209 100
210 typedef GrProgramElement INHERITED; 101 typedef GrProgramElement INHERITED;
211 }; 102 };
212 103
213 #endif 104 #endif
214 105
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