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

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

Issue 900883002: Revert of Move DstCopy on gpu into the GrXferProcessor. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 10 months 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 | « gyp/gpu.gypi ('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 "GrProcessor.h" 12 #include "GrProcessor.h"
13 #include "GrTexture.h"
14 #include "GrTypes.h" 13 #include "GrTypes.h"
15 #include "SkXfermode.h" 14 #include "SkXfermode.h"
16 15
17 class GrDrawTargetCaps; 16 class GrDrawTargetCaps;
18 class GrGLCaps; 17 class GrGLCaps;
19 class GrGLXferProcessor; 18 class GrGLXferProcessor;
20 class GrProcOptInfo; 19 class GrProcOptInfo;
21 20
22 /** 21 /**
23 * 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
24 * 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
25 * 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
26 * 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
27 * 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
28 * 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
29 * 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
30 * and blend constant color. 29 * and blend constant color.
31 * 30 *
32 * 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
33 * GrXPFactory once we have finalized the state of our draw. 32 * GrXPFactory once we have finalized the state of our draw.
34 */ 33 */
35 class GrXferProcessor : public GrProcessor { 34 class GrXferProcessor : public GrProcessor {
36 public: 35 public:
37 /** 36 /**
38 * Sets a unique key on the GrProcessorKeyBuilder calls onGetGLProcessorKey( ...) to get the 37 * Sets a unique key on the GrProcessorKeyBuilder that is directly associate d with this xfer
39 * specific subclass's key. 38 * processor's GL backend implementation.
40 */ 39 */
41 void getGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBuilder* b) const ; 40 virtual void getGLProcessorKey(const GrGLCaps& caps,
41 GrProcessorKeyBuilder* b) const = 0;
42 42
43 /** Returns a new instance of the appropriate *GL* implementation class 43 /** Returns a new instance of the appropriate *GL* implementation class
44 for the given GrXferProcessor; caller is responsible for deleting 44 for the given GrXferProcessor; caller is responsible for deleting
45 the object. */ 45 the object. */
46 virtual GrGLXferProcessor* createGLInstance() const = 0; 46 virtual GrGLXferProcessor* createGLInstance() const = 0;
47 47
48 /** 48 /**
49 * 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.
50 */ 50 */
51 enum OptFlags { 51 enum OptFlags {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 BlendInfo() : fWriteColor(true) {} 96 BlendInfo() : fWriteColor(true) {}
97 97
98 GrBlendCoeff fSrcBlend; 98 GrBlendCoeff fSrcBlend;
99 GrBlendCoeff fDstBlend; 99 GrBlendCoeff fDstBlend;
100 GrColor fBlendConstant; 100 GrColor fBlendConstant;
101 bool fWriteColor; 101 bool fWriteColor;
102 }; 102 };
103 103
104 virtual void getBlendInfo(BlendInfo* blendInfo) const = 0; 104 virtual void getBlendInfo(BlendInfo* blendInfo) const = 0;
105 105
106 /** Will this prceossor read the destination pixel value? */
106 bool willReadDstColor() const { return fWillReadDstColor; } 107 bool willReadDstColor() const { return fWillReadDstColor; }
107 108
108 /**
109 * Returns the texture to be used as the destination when reading the dst in the fragment
110 * shader. If the returned texture is NULL then the XP is either not reading the dst or we have
111 * extentions that support framebuffer fetching and thus don't need a copy o f the dst texture.
112 */
113 const GrTexture* getDstCopyTexture() const { return fDstCopy.getTexture(); }
114
115 /**
116 * Returns the offset into the DstCopyTexture to use when reading it in the shader. This value
117 * is only valid if getDstCopyTexture() != NULL.
118 */
119 const SkIPoint& dstCopyTextureOffset() const { return fDstCopyTextureOffset; }
120
121 /** 109 /**
122 * Returns whether or not this xferProcossor will set a secondary output to be used with dual 110 * Returns whether or not this xferProcossor will set a secondary output to be used with dual
123 * source blending. 111 * source blending.
124 */ 112 */
125 virtual bool hasSecondaryOutput() const { return false; } 113 virtual bool hasSecondaryOutput() const { return false; }
126 114
127 /** Returns true if this and other processor conservatively draw identically . It can only return 115 /** Returns true if this and other processor conservatively draw identically . It can only return
128 true when the two processor are of the same subclass (i.e. they return t he same object from 116 true when the two processor are of the same subclass (i.e. they return t he same object from
129 from getFactory()). 117 from getFactory()).
130 118
131 A return value of true from isEqual() should not be used to test whether the processor would 119 A return value of true from isEqual() should not be used to test whether the processor would
132 generate the same shader code. To test for identical code generation use getGLProcessorKey*/ 120 generate the same shader code. To test for identical code generation use getGLProcessorKey*/
133 121
134 bool isEqual(const GrXferProcessor& that) const { 122 bool isEqual(const GrXferProcessor& that) const {
135 if (this->classID() != that.classID()) { 123 if (this->classID() != that.classID()) {
136 return false; 124 return false;
137 } 125 }
138 if (this->fWillReadDstColor != that.fWillReadDstColor) {
139 return false;
140 }
141 if (this->fDstCopy.getTexture() != that.fDstCopy.getTexture()) {
142 return false;
143 }
144 if (this->fDstCopyTextureOffset != that.fDstCopyTextureOffset) {
145 return false;
146 }
147 return this->onIsEqual(that); 126 return this->onIsEqual(that);
148 } 127 }
149 128
150 protected: 129 protected:
151 GrXferProcessor(); 130 GrXferProcessor() : fWillReadDstColor(false) {}
152 GrXferProcessor(const GrDeviceCoordTexture* dstCopy, bool willReadDstColor); 131
132 /**
133 * If the prceossor subclass will read the destination pixel value then it m ust call this
134 * function from its constructor. Otherwise, when its generated backend-spec ific prceossor class
135 * attempts to generate code that reads the destination pixel it will fail.
136 */
137 void setWillReadDstColor() { fWillReadDstColor = true; }
153 138
154 private: 139 private:
155 /**
156 * Sets a unique key on the GrProcessorKeyBuilder that is directly associate d with this xfer
157 * processor's GL backend implementation.
158 */
159 virtual void onGetGLProcessorKey(const GrGLCaps& caps,
160 GrProcessorKeyBuilder* b) const = 0;
161
162 virtual bool onIsEqual(const GrXferProcessor&) const = 0; 140 virtual bool onIsEqual(const GrXferProcessor&) const = 0;
163 141
164 bool fWillReadDstColor; 142 bool fWillReadDstColor;
165 SkIPoint fDstCopyTextureOffset;
166 GrTextureAccess fDstCopy;
167 143
168 typedef GrFragmentProcessor INHERITED; 144 typedef GrFragmentProcessor INHERITED;
169 }; 145 };
170 146
171 GR_MAKE_BITFIELD_OPS(GrXferProcessor::OptFlags); 147 GR_MAKE_BITFIELD_OPS(GrXferProcessor::OptFlags);
172 148
173 ///////////////////////////////////////////////////////////////////////////////
174
175 /** 149 /**
176 * We install a GrXPFactory (XPF) early on in the pipeline before all the final draw information is 150 * We install a GrXPFactory (XPF) early on in the pipeline before all the final draw information is
177 * known (e.g. whether there is fractional pixel coverage, will coverage be 1 or 4 channel, is the 151 * known (e.g. whether there is fractional pixel coverage, will coverage be 1 or 4 channel, is the
178 * draw opaque, etc.). Once the state of the draw is finalized, we use the XPF a long with all the 152 * draw opaque, etc.). Once the state of the draw is finalized, we use the XPF a long with all the
179 * draw information to create a GrXferProcessor (XP) which can implement the des ired blending for 153 * draw information to create a GrXferProcessor (XP) which can implement the des ired blending for
180 * the draw. 154 * the draw.
181 * 155 *
182 * Before the XP is created, the XPF is able to answer queries about what functi onality the XPs it 156 * Before the XP is created, the XPF is able to answer queries about what functi onality the XPs it
183 * creates will have. For example, can it create an XP that supports RGB coverag e or will the XP 157 * creates will have. For example, can it create an XP that supports RGB coverag e or will the XP
184 * blend with the destination color. 158 * blend with the destination color.
185 */ 159 */
186 class GrXPFactory : public SkRefCnt { 160 class GrXPFactory : public SkRefCnt {
187 public: 161 public:
188 GrXferProcessor* createXferProcessor(const GrProcOptInfo& colorPOI, 162 virtual GrXferProcessor* createXferProcessor(const GrProcOptInfo& colorPOI,
189 const GrProcOptInfo& coveragePOI, 163 const GrProcOptInfo& coveragePO I) const = 0;
190 const GrDeviceCoordTexture* dstCopy,
191 const GrDrawTargetCaps& caps) const;
192 164
193 /** 165 /**
194 * This function returns true if the GrXferProcessor generated from this fac tory will be able to 166 * This function returns true if the GrXferProcessor generated from this fac tory will be able to
195 * correctly blend when using RGB coverage. The knownColor and knownColorFla gs represent the 167 * correctly blend when using RGB coverage. The knownColor and knownColorFla gs represent the
196 * final computed color from the color stages. 168 * final computed color from the color stages.
197 */ 169 */
198 virtual bool supportsRGBCoverage(GrColor knownColor, uint32_t knownColorFlag s) const = 0; 170 virtual bool supportsRGBCoverage(GrColor knownColor, uint32_t knownColorFlag s) const = 0;
199 171
200 /** 172 /**
201 * Depending on color blend mode requested it may or may not be possible to correctly blend with 173 * Depending on color blend mode requested it may or may not be possible to correctly blend with
(...skipping 21 matching lines...) Expand all
223 virtual void getInvariantOutput(const GrProcOptInfo& colorPOI, const GrProcO ptInfo& coveragePOI, 195 virtual void getInvariantOutput(const GrProcOptInfo& colorPOI, const GrProcO ptInfo& coveragePOI,
224 InvariantOutput*) const = 0; 196 InvariantOutput*) const = 0;
225 197
226 /** 198 /**
227 * Determines whether multiplying the computed per-pixel color by the pixel' s fractional 199 * Determines whether multiplying the computed per-pixel color by the pixel' s fractional
228 * coverage before the blend will give the correct final destination color. In general it 200 * coverage before the blend will give the correct final destination color. In general it
229 * will not as coverage is applied after blending. 201 * will not as coverage is applied after blending.
230 */ 202 */
231 virtual bool canTweakAlphaForCoverage() const = 0; 203 virtual bool canTweakAlphaForCoverage() const = 0;
232 204
233 bool willNeedDstCopy(const GrDrawTargetCaps& caps) const; 205 /**
206 * Returns true if the XP generated by this factory will read dst.
207 */
208 virtual bool willReadDst() const = 0;
234 209
235 bool isEqual(const GrXPFactory& that) const { 210 bool isEqual(const GrXPFactory& that) const {
236 if (this->classID() != that.classID()) { 211 if (this->classID() != that.classID()) {
237 return false; 212 return false;
238 } 213 }
239 return this->onIsEqual(that); 214 return this->onIsEqual(that);
240 } 215 }
241 216
242 /** 217 /**
243 * Helper for down-casting to a GrXPFactory subclass 218 * Helper for down-casting to a GrXPFactory subclass
244 */ 219 */
245 template <typename T> const T& cast() const { return *static_cast<const T*>( this); } 220 template <typename T> const T& cast() const { return *static_cast<const T*>( this); }
246 221
247 uint32_t classID() const { SkASSERT(kIllegalXPFClassID != fClassID); return fClassID; } 222 uint32_t classID() const { SkASSERT(kIllegalXPFClassID != fClassID); return fClassID; }
248 223
249 protected: 224 protected:
250 GrXPFactory() : fClassID(kIllegalXPFClassID) {} 225 GrXPFactory() : fClassID(kIllegalXPFClassID) {}
251 226
252 template <typename XPF_SUBCLASS> void initClassID() { 227 template <typename XPF_SUBCLASS> void initClassID() {
253 static uint32_t kClassID = GenClassID(); 228 static uint32_t kClassID = GenClassID();
254 fClassID = kClassID; 229 fClassID = kClassID;
255 } 230 }
256 231
257 uint32_t fClassID; 232 uint32_t fClassID;
258 233
259 private: 234 private:
260 virtual GrXferProcessor* onCreateXferProcessor(const GrProcOptInfo& colorPOI ,
261 const GrProcOptInfo& coverage POI,
262 const GrDeviceCoordTexture* d stCopy) const = 0;
263 /**
264 * Returns true if the XP generated by this factory will explicitly read ds t in the fragment
265 * shader.
266 */
267 virtual bool willReadDstColor() const = 0;
268
269 virtual bool onIsEqual(const GrXPFactory&) const = 0; 235 virtual bool onIsEqual(const GrXPFactory&) const = 0;
270 236
271 static uint32_t GenClassID() { 237 static uint32_t GenClassID() {
272 // fCurrXPFactoryID has been initialized to kIllegalXPFactoryID. The 238 // fCurrXPFactoryID has been initialized to kIllegalXPFactoryID. The
273 // atomic inc returns the old value not the incremented value. So we add 239 // atomic inc returns the old value not the incremented value. So we add
274 // 1 to the returned value. 240 // 1 to the returned value.
275 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(&gCurrXPFClassID)) + 1 ; 241 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(&gCurrXPFClassID)) + 1 ;
276 if (!id) { 242 if (!id) {
277 SkFAIL("This should never wrap as it should only be called once for each GrXPFactory " 243 SkFAIL("This should never wrap as it should only be called once for each GrXPFactory "
278 "subclass."); 244 "subclass.");
279 } 245 }
280 return id; 246 return id;
281 } 247 }
282 248
283 enum { 249 enum {
284 kIllegalXPFClassID = 0, 250 kIllegalXPFClassID = 0,
285 }; 251 };
286 static int32_t gCurrXPFClassID; 252 static int32_t gCurrXPFClassID;
287 253
288 typedef GrProgramElement INHERITED; 254 typedef GrProgramElement INHERITED;
289 }; 255 };
290 256
291 #endif 257 #endif
292 258
OLDNEW
« no previous file with comments | « gyp/gpu.gypi ('k') | include/gpu/effects/GrPorterDuffXferProcessor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698