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 885923002: Move DstCopy on gpu into the GrXferProcessor. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Back to bool 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"
13 #include "GrTypes.h" 14 #include "GrTypes.h"
14 #include "SkXfermode.h" 15 #include "SkXfermode.h"
15 16
16 class GrDrawTargetCaps; 17 class GrDrawTargetCaps;
17 class GrGLCaps; 18 class GrGLCaps;
18 class GrGLXferProcessor; 19 class GrGLXferProcessor;
19 class GrProcOptInfo; 20 class GrProcOptInfo;
20 21
21 /** 22 /**
22 * GrXferProcessor is responsible for implementing the xfer mode that blends the src color and dst 23 * GrXferProcessor is responsible for implementing the xfer mode that blends the src color and dst
23 * color. It does this by emitting fragment shader code and controlling the fixe d-function blend 24 * color. It does this by emitting fragment shader code and controlling the fixe d-function blend
24 * state. The inputs to its shader code are the final computed src color and fra ctional pixel 25 * state. The inputs to its shader code are the final computed src color and fra ctional pixel
25 * coverage. The GrXferProcessor's shader code writes the fragment shader output color that goes 26 * coverage. The GrXferProcessor's shader code writes the fragment shader output color that goes
26 * into the fixed-function blend. When dual-source blending is available, it may also write a 27 * into the fixed-function blend. When dual-source blending is available, it may also write a
27 * seconday fragment shader output color. When allowed by the backend API, the G rXferProcessor may 28 * seconday fragment shader output color. When allowed by the backend API, the G rXferProcessor may
28 * read the destination color. The GrXferProcessor is responsible for setting th e blend coefficients 29 * read the destination color. The GrXferProcessor is responsible for setting th e blend coefficients
29 * and blend constant color. 30 * and blend constant color.
30 * 31 *
31 * A GrXferProcessor is never installed directly into our draw state, but instea d is created from a 32 * A GrXferProcessor is never installed directly into our draw state, but instea d is created from a
32 * GrXPFactory once we have finalized the state of our draw. 33 * GrXPFactory once we have finalized the state of our draw.
33 */ 34 */
34 class GrXferProcessor : public GrProcessor { 35 class GrXferProcessor : public GrProcessor {
35 public: 36 public:
36 /** 37 /**
37 * Sets a unique key on the GrProcessorKeyBuilder that is directly associate d with this xfer 38 * Sets a unique key on the GrProcessorKeyBuilder calls onGetGLProcessorKey( ...) to get the
38 * processor's GL backend implementation. 39 * specific subclass's key.
39 */ 40 */
40 virtual void getGLProcessorKey(const GrGLCaps& caps, 41 void getGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBuilder* b) const ;
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? */
107 bool willReadDstColor() const { return fWillReadDstColor; } 106 bool willReadDstColor() const { return fWillReadDstColor; }
108 107
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
109 /** 124 /**
110 * Returns whether or not this xferProcossor will set a secondary output to be used with dual 125 * Returns whether or not this xferProcossor will set a secondary output to be used with dual
111 * source blending. 126 * source blending.
112 */ 127 */
113 virtual bool hasSecondaryOutput() const { return false; } 128 virtual bool hasSecondaryOutput() const { return false; }
114 129
115 /** Returns true if this and other processor conservatively draw identically . It can only return 130 /** Returns true if this and other processor conservatively draw identically . It can only return
116 true when the two processor are of the same subclass (i.e. they return t he same object from 131 true when the two processor are of the same subclass (i.e. they return t he same object from
117 from getFactory()). 132 from getFactory()).
118 133
119 A return value of true from isEqual() should not be used to test whether the processor would 134 A return value of true from isEqual() should not be used to test whether the processor would
120 generate the same shader code. To test for identical code generation use getGLProcessorKey*/ 135 generate the same shader code. To test for identical code generation use getGLProcessorKey*/
121 136
122 bool isEqual(const GrXferProcessor& that) const { 137 bool isEqual(const GrXferProcessor& that) const {
123 if (this->classID() != that.classID()) { 138 if (this->classID() != that.classID()) {
124 return false; 139 return false;
125 } 140 }
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 }
126 return this->onIsEqual(that); 150 return this->onIsEqual(that);
127 } 151 }
128 152
129 protected: 153 protected:
130 GrXferProcessor() : fWillReadDstColor(false) {} 154 GrXferProcessor();
131 155 GrXferProcessor(const GrDeviceCoordTexture* dstCopy, bool willReadDstColor);
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; }
138 156
139 private: 157 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
140 virtual bool onIsEqual(const GrXferProcessor&) const = 0; 165 virtual bool onIsEqual(const GrXferProcessor&) const = 0;
141 166
142 bool fWillReadDstColor; 167 bool fWillReadDstColor;
168 SkIPoint fDstCopyTextureOffset;
169 GrTextureAccess fDstCopy;
143 170
144 typedef GrFragmentProcessor INHERITED; 171 typedef GrFragmentProcessor INHERITED;
145 }; 172 };
146 173
147 GR_MAKE_BITFIELD_OPS(GrXferProcessor::OptFlags); 174 GR_MAKE_BITFIELD_OPS(GrXferProcessor::OptFlags);
148 175
176 ///////////////////////////////////////////////////////////////////////////////
177
149 /** 178 /**
150 * We install a GrXPFactory (XPF) early on in the pipeline before all the final draw information is 179 * We install a GrXPFactory (XPF) early on in the pipeline before all the final draw information is
151 * known (e.g. whether there is fractional pixel coverage, will coverage be 1 or 4 channel, is the 180 * known (e.g. whether there is fractional pixel coverage, will coverage be 1 or 4 channel, is the
152 * draw opaque, etc.). Once the state of the draw is finalized, we use the XPF a long with all the 181 * draw opaque, etc.). Once the state of the draw is finalized, we use the XPF a long with all the
153 * draw information to create a GrXferProcessor (XP) which can implement the des ired blending for 182 * draw information to create a GrXferProcessor (XP) which can implement the des ired blending for
154 * the draw. 183 * the draw.
155 * 184 *
156 * Before the XP is created, the XPF is able to answer queries about what functi onality the XPs it 185 * Before the XP is created, the XPF is able to answer queries about what functi onality the XPs it
157 * creates will have. For example, can it create an XP that supports RGB coverag e or will the XP 186 * creates will have. For example, can it create an XP that supports RGB coverag e or will the XP
158 * blend with the destination color. 187 * blend with the destination color.
159 */ 188 */
160 class GrXPFactory : public SkRefCnt { 189 class GrXPFactory : public SkRefCnt {
161 public: 190 public:
162 virtual GrXferProcessor* createXferProcessor(const GrProcOptInfo& colorPOI, 191 GrXferProcessor* createXferProcessor(const GrProcOptInfo& colorPOI,
163 const GrProcOptInfo& coveragePO I) const = 0; 192 const GrProcOptInfo& coveragePOI,
193 const GrDeviceCoordTexture* dstCopy,
194 const GrDrawTargetCaps& caps) const;
164 195
165 /** 196 /**
166 * This function returns true if the GrXferProcessor generated from this fac tory will be able to 197 * This function returns true if the GrXferProcessor generated from this fac tory will be able to
167 * correctly blend when using RGB coverage. The knownColor and knownColorFla gs represent the 198 * correctly blend when using RGB coverage. The knownColor and knownColorFla gs represent the
168 * final computed color from the color stages. 199 * final computed color from the color stages.
169 */ 200 */
170 virtual bool supportsRGBCoverage(GrColor knownColor, uint32_t knownColorFlag s) const = 0; 201 virtual bool supportsRGBCoverage(GrColor knownColor, uint32_t knownColorFlag s) const = 0;
171 202
172 /** 203 /**
173 * Depending on color blend mode requested it may or may not be possible to correctly blend with 204 * Depending on color blend mode requested it may or may not be possible to correctly blend with
(...skipping 21 matching lines...) Expand all
195 virtual void getInvariantOutput(const GrProcOptInfo& colorPOI, const GrProcO ptInfo& coveragePOI, 226 virtual void getInvariantOutput(const GrProcOptInfo& colorPOI, const GrProcO ptInfo& coveragePOI,
196 InvariantOutput*) const = 0; 227 InvariantOutput*) const = 0;
197 228
198 /** 229 /**
199 * Determines whether multiplying the computed per-pixel color by the pixel' s fractional 230 * Determines whether multiplying the computed per-pixel color by the pixel' s fractional
200 * coverage before the blend will give the correct final destination color. In general it 231 * coverage before the blend will give the correct final destination color. In general it
201 * will not as coverage is applied after blending. 232 * will not as coverage is applied after blending.
202 */ 233 */
203 virtual bool canTweakAlphaForCoverage() const = 0; 234 virtual bool canTweakAlphaForCoverage() const = 0;
204 235
205 /** 236 bool willNeedDstCopy(const GrDrawTargetCaps& caps) const;
206 * Returns true if the XP generated by this factory will read dst.
207 */
208 virtual bool willReadDst() const = 0;
209 237
210 bool isEqual(const GrXPFactory& that) const { 238 bool isEqual(const GrXPFactory& that) const {
211 if (this->classID() != that.classID()) { 239 if (this->classID() != that.classID()) {
212 return false; 240 return false;
213 } 241 }
214 return this->onIsEqual(that); 242 return this->onIsEqual(that);
215 } 243 }
216 244
217 /** 245 /**
218 * Helper for down-casting to a GrXPFactory subclass 246 * Helper for down-casting to a GrXPFactory subclass
219 */ 247 */
220 template <typename T> const T& cast() const { return *static_cast<const T*>( this); } 248 template <typename T> const T& cast() const { return *static_cast<const T*>( this); }
221 249
222 uint32_t classID() const { SkASSERT(kIllegalXPFClassID != fClassID); return fClassID; } 250 uint32_t classID() const { SkASSERT(kIllegalXPFClassID != fClassID); return fClassID; }
223 251
224 protected: 252 protected:
225 GrXPFactory() : fClassID(kIllegalXPFClassID) {} 253 GrXPFactory() : fClassID(kIllegalXPFClassID) {}
226 254
227 template <typename XPF_SUBCLASS> void initClassID() { 255 template <typename XPF_SUBCLASS> void initClassID() {
228 static uint32_t kClassID = GenClassID(); 256 static uint32_t kClassID = GenClassID();
229 fClassID = kClassID; 257 fClassID = kClassID;
230 } 258 }
231 259
232 uint32_t fClassID; 260 uint32_t fClassID;
233 261
234 private: 262 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
235 virtual bool onIsEqual(const GrXPFactory&) const = 0; 272 virtual bool onIsEqual(const GrXPFactory&) const = 0;
236 273
237 static uint32_t GenClassID() { 274 static uint32_t GenClassID() {
238 // fCurrXPFactoryID has been initialized to kIllegalXPFactoryID. The 275 // fCurrXPFactoryID has been initialized to kIllegalXPFactoryID. The
239 // atomic inc returns the old value not the incremented value. So we add 276 // atomic inc returns the old value not the incremented value. So we add
240 // 1 to the returned value. 277 // 1 to the returned value.
241 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(&gCurrXPFClassID)) + 1 ; 278 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(&gCurrXPFClassID)) + 1 ;
242 if (!id) { 279 if (!id) {
243 SkFAIL("This should never wrap as it should only be called once for each GrXPFactory " 280 SkFAIL("This should never wrap as it should only be called once for each GrXPFactory "
244 "subclass."); 281 "subclass.");
245 } 282 }
246 return id; 283 return id;
247 } 284 }
248 285
249 enum { 286 enum {
250 kIllegalXPFClassID = 0, 287 kIllegalXPFClassID = 0,
251 }; 288 };
252 static int32_t gCurrXPFClassID; 289 static int32_t gCurrXPFClassID;
253 290
254 typedef GrProgramElement INHERITED; 291 typedef GrProgramElement INHERITED;
255 }; 292 };
256 293
257 #endif 294 #endif
258 295
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