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

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

Issue 901663007: 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 {
120 SkASSERT(this->getDstCopyTexture());
121 return fDstCopyTextureOffset;
122 }
123
124 /** 109 /**
125 * 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
126 * source blending. 111 * source blending.
127 */ 112 */
128 virtual bool hasSecondaryOutput() const { return false; } 113 virtual bool hasSecondaryOutput() const { return false; }
129 114
130 /** 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
131 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
132 from getFactory()). 117 from getFactory()).
133 118
134 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
135 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*/
136 121
137 bool isEqual(const GrXferProcessor& that) const { 122 bool isEqual(const GrXferProcessor& that) const {
138 if (this->classID() != that.classID()) { 123 if (this->classID() != that.classID()) {
139 return false; 124 return false;
140 } 125 }
141 if (this->fWillReadDstColor != that.fWillReadDstColor) {
142 return false;
143 }
144 if (this->fDstCopy.getTexture() != that.fDstCopy.getTexture()) {
145 return false;
146 }
147 if (this->fDstCopyTextureOffset != that.fDstCopyTextureOffset) {
148 return false;
149 }
150 return this->onIsEqual(that); 126 return this->onIsEqual(that);
151 } 127 }
152 128
153 protected: 129 protected:
154 GrXferProcessor(); 130 GrXferProcessor() : fWillReadDstColor(false) {}
155 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; }
156 138
157 private: 139 private:
158 /**
159 * Sets a unique key on the GrProcessorKeyBuilder that is directly associate d with this xfer
160 * processor's GL backend implementation.
161 */
162 virtual void onGetGLProcessorKey(const GrGLCaps& caps,
163 GrProcessorKeyBuilder* b) const = 0;
164
165 virtual bool onIsEqual(const GrXferProcessor&) const = 0; 140 virtual bool onIsEqual(const GrXferProcessor&) const = 0;
166 141
167 bool fWillReadDstColor; 142 bool fWillReadDstColor;
168 SkIPoint fDstCopyTextureOffset;
169 GrTextureAccess fDstCopy;
170 143
171 typedef GrFragmentProcessor INHERITED; 144 typedef GrFragmentProcessor INHERITED;
172 }; 145 };
173 146
174 GR_MAKE_BITFIELD_OPS(GrXferProcessor::OptFlags); 147 GR_MAKE_BITFIELD_OPS(GrXferProcessor::OptFlags);
175 148
176 ///////////////////////////////////////////////////////////////////////////////
177
178 /** 149 /**
179 * 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
180 * 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
181 * 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
182 * 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
183 * the draw. 154 * the draw.
184 * 155 *
185 * 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
186 * 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
187 * blend with the destination color. 158 * blend with the destination color.
188 */ 159 */
189 class GrXPFactory : public SkRefCnt { 160 class GrXPFactory : public SkRefCnt {
190 public: 161 public:
191 GrXferProcessor* createXferProcessor(const GrProcOptInfo& colorPOI, 162 virtual GrXferProcessor* createXferProcessor(const GrProcOptInfo& colorPOI,
192 const GrProcOptInfo& coveragePOI, 163 const GrProcOptInfo& coveragePO I) const = 0;
193 const GrDeviceCoordTexture* dstCopy,
194 const GrDrawTargetCaps& caps) const;
195 164
196 /** 165 /**
197 * 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
198 * 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
199 * final computed color from the color stages. 168 * final computed color from the color stages.
200 */ 169 */
201 virtual bool supportsRGBCoverage(GrColor knownColor, uint32_t knownColorFlag s) const = 0; 170 virtual bool supportsRGBCoverage(GrColor knownColor, uint32_t knownColorFlag s) const = 0;
202 171
203 /** 172 /**
204 * 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
226 virtual void getInvariantOutput(const GrProcOptInfo& colorPOI, const GrProcO ptInfo& coveragePOI, 195 virtual void getInvariantOutput(const GrProcOptInfo& colorPOI, const GrProcO ptInfo& coveragePOI,
227 InvariantOutput*) const = 0; 196 InvariantOutput*) const = 0;
228 197
229 /** 198 /**
230 * 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
231 * 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
232 * will not as coverage is applied after blending. 201 * will not as coverage is applied after blending.
233 */ 202 */
234 virtual bool canTweakAlphaForCoverage() const = 0; 203 virtual bool canTweakAlphaForCoverage() const = 0;
235 204
236 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;
237 209
238 bool isEqual(const GrXPFactory& that) const { 210 bool isEqual(const GrXPFactory& that) const {
239 if (this->classID() != that.classID()) { 211 if (this->classID() != that.classID()) {
240 return false; 212 return false;
241 } 213 }
242 return this->onIsEqual(that); 214 return this->onIsEqual(that);
243 } 215 }
244 216
245 /** 217 /**
246 * Helper for down-casting to a GrXPFactory subclass 218 * Helper for down-casting to a GrXPFactory subclass
247 */ 219 */
248 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); }
249 221
250 uint32_t classID() const { SkASSERT(kIllegalXPFClassID != fClassID); return fClassID; } 222 uint32_t classID() const { SkASSERT(kIllegalXPFClassID != fClassID); return fClassID; }
251 223
252 protected: 224 protected:
253 GrXPFactory() : fClassID(kIllegalXPFClassID) {} 225 GrXPFactory() : fClassID(kIllegalXPFClassID) {}
254 226
255 template <typename XPF_SUBCLASS> void initClassID() { 227 template <typename XPF_SUBCLASS> void initClassID() {
256 static uint32_t kClassID = GenClassID(); 228 static uint32_t kClassID = GenClassID();
257 fClassID = kClassID; 229 fClassID = kClassID;
258 } 230 }
259 231
260 uint32_t fClassID; 232 uint32_t fClassID;
261 233
262 private: 234 private:
263 virtual GrXferProcessor* onCreateXferProcessor(const GrProcOptInfo& colorPOI ,
264 const GrProcOptInfo& coverage POI,
265 const GrDeviceCoordTexture* d stCopy) const = 0;
266 /**
267 * Returns true if the XP generated by this factory will explicitly read ds t in the fragment
268 * shader.
269 */
270 virtual bool willReadDstColor() const = 0;
271
272 virtual bool onIsEqual(const GrXPFactory&) const = 0; 235 virtual bool onIsEqual(const GrXPFactory&) const = 0;
273 236
274 static uint32_t GenClassID() { 237 static uint32_t GenClassID() {
275 // fCurrXPFactoryID has been initialized to kIllegalXPFactoryID. The 238 // fCurrXPFactoryID has been initialized to kIllegalXPFactoryID. The
276 // 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
277 // 1 to the returned value. 240 // 1 to the returned value.
278 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 ;
279 if (!id) { 242 if (!id) {
280 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 "
281 "subclass."); 244 "subclass.");
282 } 245 }
283 return id; 246 return id;
284 } 247 }
285 248
286 enum { 249 enum {
287 kIllegalXPFClassID = 0, 250 kIllegalXPFClassID = 0,
288 }; 251 };
289 static int32_t gCurrXPFClassID; 252 static int32_t gCurrXPFClassID;
290 253
291 typedef GrProgramElement INHERITED; 254 typedef GrProgramElement INHERITED;
292 }; 255 };
293 256
294 #endif 257 #endif
295 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