OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 GrProcessor_DEFINED | 8 #ifndef GrProcessor_DEFINED |
9 #define GrProcessor_DEFINED | 9 #define GrProcessor_DEFINED |
10 | 10 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 class MyCustomEffect : public GrProcessor { | 168 class MyCustomEffect : public GrProcessor { |
169 ... | 169 ... |
170 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE
{ | 170 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE
{ |
171 return GrTBackendEffectFactory<MyCustomEffect>::getInstance(); | 171 return GrTBackendEffectFactory<MyCustomEffect>::getInstance(); |
172 } | 172 } |
173 ... | 173 ... |
174 }; | 174 }; |
175 */ | 175 */ |
176 virtual const GrBackendProcessorFactory& getFactory() const = 0; | 176 virtual const GrBackendProcessorFactory& getFactory() const = 0; |
177 | 177 |
178 /** Returns true if this and other effect conservatively draw identically. I
t can only return | |
179 true when the two effects are of the same subclass (i.e. they return the
same object from | |
180 from getFactory()). | |
181 | |
182 A return value of true from isEqual() should not be used to test whether
the effects would | |
183 generate the same shader code. To test for identical code generation use
the effects' keys | |
184 computed by the GrBackendEffectFactory. | |
185 */ | |
186 bool isEqual(const GrProcessor& other) const { | |
187 if (&this->getFactory() != &other.getFactory()) { | |
188 return false; | |
189 } | |
190 bool result = this->onIsEqual(other); | |
191 #ifdef SK_DEBUG | |
192 if (result) { | |
193 this->assertEquality(other); | |
194 } | |
195 #endif | |
196 return result; | |
197 } | |
198 | |
199 /** Human-meaningful string to identify this effect; may be embedded | 178 /** Human-meaningful string to identify this effect; may be embedded |
200 in generated shader code. */ | 179 in generated shader code. */ |
201 const char* name() const; | 180 const char* name() const; |
202 | 181 |
203 int numTextures() const { return fTextureAccesses.count(); } | 182 int numTextures() const { return fTextureAccesses.count(); } |
204 | 183 |
205 /** Returns the access pattern for the texture at index. index must be valid
according to | 184 /** Returns the access pattern for the texture at index. index must be valid
according to |
206 numTextures(). */ | 185 numTextures(). */ |
207 const GrTextureAccess& textureAccess(int index) const { return *fTextureAcce
sses[index]; } | 186 const GrTextureAccess& textureAccess(int index) const { return *fTextureAcce
sses[index]; } |
208 | 187 |
(...skipping 30 matching lines...) Expand all Loading... |
239 GrProcessor() | 218 GrProcessor() |
240 : fWillReadFragmentPosition(false) {} | 219 : fWillReadFragmentPosition(false) {} |
241 | 220 |
242 /** | 221 /** |
243 * If the effect will generate a backend-specific effect that will read the
fragment position | 222 * If the effect will generate a backend-specific effect that will read the
fragment position |
244 * in the FS then it must call this method from its constructor. Otherwise,
the request to | 223 * in the FS then it must call this method from its constructor. Otherwise,
the request to |
245 * access the fragment position will be denied. | 224 * access the fragment position will be denied. |
246 */ | 225 */ |
247 void setWillReadFragmentPosition() { fWillReadFragmentPosition = true; } | 226 void setWillReadFragmentPosition() { fWillReadFragmentPosition = true; } |
248 | 227 |
| 228 SkDEBUGCODE(void assertTexturesEqual(const GrProcessor& other) const;) |
| 229 |
249 private: | 230 private: |
250 SkDEBUGCODE(void assertEquality(const GrProcessor& other) const;) | |
251 | |
252 /** Subclass implements this to support isEqual(). It will only be called if
it is known that | |
253 the two effects are of the same subclass (i.e. they return the same obje
ct from | |
254 getFactory()).*/ | |
255 virtual bool onIsEqual(const GrProcessor& other) const = 0; | |
256 | 231 |
257 /** | 232 /** |
258 * Subclass implements this to support getConstantColorComponents(...). | 233 * Subclass implements this to support getConstantColorComponents(...). |
259 */ | 234 */ |
260 virtual void onComputeInvariantOutput(InvariantOutput* inout) const = 0; | 235 virtual void onComputeInvariantOutput(InvariantOutput* inout) const = 0; |
261 | 236 |
262 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses; | 237 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses; |
263 bool fWillReadFragmentPosition; | 238 bool fWillReadFragmentPosition; |
264 | 239 |
265 typedef GrProgramElement INHERITED; | 240 typedef GrProgramElement INHERITED; |
(...skipping 13 matching lines...) Expand all Loading... |
279 /** Returns the coordinate transformation at index. index must be valid acco
rding to | 254 /** Returns the coordinate transformation at index. index must be valid acco
rding to |
280 numTransforms(). */ | 255 numTransforms(). */ |
281 const GrCoordTransform& coordTransform(int index) const { return *fCoordTran
sforms[index]; } | 256 const GrCoordTransform& coordTransform(int index) const { return *fCoordTran
sforms[index]; } |
282 | 257 |
283 /** Will this effect read the destination pixel value? */ | 258 /** Will this effect read the destination pixel value? */ |
284 bool willReadDstColor() const { return fWillReadDstColor; } | 259 bool willReadDstColor() const { return fWillReadDstColor; } |
285 | 260 |
286 /** Will this effect read the source color value? */ | 261 /** Will this effect read the source color value? */ |
287 bool willUseInputColor() const { return fWillUseInputColor; } | 262 bool willUseInputColor() const { return fWillUseInputColor; } |
288 | 263 |
| 264 /** Returns true if this and other effect conservatively draw identically. I
t can only return |
| 265 true when the two effects are of the same subclass (i.e. they return the
same object from |
| 266 from getFactory()). |
| 267 |
| 268 A return value of true from isEqual() should not be used to test whether
the effects would |
| 269 generate the same shader code. To test for identical code generation use
the effects' keys |
| 270 computed by the GrBackendEffectFactory. */ |
| 271 bool isEqual(const GrFragmentProcessor& other) const { |
| 272 if (&this->getFactory() != &other.getFactory()) { |
| 273 return false; |
| 274 } |
| 275 bool result = this->onIsEqual(other); |
| 276 #ifdef SK_DEBUG |
| 277 if (result) { |
| 278 this->assertTexturesEqual(other); |
| 279 } |
| 280 #endif |
| 281 return result; |
| 282 } |
| 283 |
289 protected: | 284 protected: |
290 /** | 285 /** |
291 * Fragment Processor subclasses call this from their constructor to registe
r coordinate | 286 * Fragment Processor subclasses call this from their constructor to registe
r coordinate |
292 * transformations. The processor subclass manages the lifetime of the trans
formations (this | 287 * transformations. The processor subclass manages the lifetime of the trans
formations (this |
293 * function only stores a pointer). The GrCoordTransform is typically a memb
er field of the | 288 * function only stores a pointer). The GrCoordTransform is typically a memb
er field of the |
294 * GrProcessor subclass. When the matrix has perspective, the transformed co
ordinates will have | 289 * GrProcessor subclass. When the matrix has perspective, the transformed co
ordinates will have |
295 * 3 components. Otherwise they'll have 2. This must only be called from the
constructor because | 290 * 3 components. Otherwise they'll have 2. This must only be called from the
constructor because |
296 * GrProcessors are immutable. | 291 * GrProcessors are immutable. |
297 */ | 292 */ |
298 void addCoordTransform(const GrCoordTransform*); | 293 void addCoordTransform(const GrCoordTransform*); |
299 | 294 |
300 /** | 295 /** |
301 * If the effect subclass will read the destination pixel value then it must
call this function | 296 * If the effect subclass will read the destination pixel value then it must
call this function |
302 * from its constructor. Otherwise, when its generated backend-specific effe
ct class attempts | 297 * from its constructor. Otherwise, when its generated backend-specific effe
ct class attempts |
303 * to generate code that reads the destination pixel it will fail. | 298 * to generate code that reads the destination pixel it will fail. |
304 */ | 299 */ |
305 void setWillReadDstColor() { fWillReadDstColor = true; } | 300 void setWillReadDstColor() { fWillReadDstColor = true; } |
306 | 301 |
307 /** | 302 /** |
308 * If the effect will generate a result that does not depend on the input co
lor value then it | 303 * If the effect will generate a result that does not depend on the input co
lor value then it |
309 * must call this function from its constructor. Otherwise, when its generat
ed backend-specific | 304 * must call this function from its constructor. Otherwise, when its generat
ed backend-specific |
310 * code might fail during variable binding due to unused variables. | 305 * code might fail during variable binding due to unused variables. |
311 */ | 306 */ |
312 void setWillNotUseInputColor() { fWillUseInputColor = false; } | 307 void setWillNotUseInputColor() { fWillUseInputColor = false; } |
313 | 308 |
314 private: | 309 private: |
| 310 /** Subclass implements this to support isEqual(). It will only be called if
it is known that |
| 311 the two effects are of the same subclass (i.e. they return the same obje
ct from |
| 312 getFactory()).*/ |
| 313 virtual bool onIsEqual(const GrFragmentProcessor& other) const = 0; |
| 314 |
315 SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms; | 315 SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms; |
316 bool fWillReadDstColor; | 316 bool fWillReadDstColor; |
317 bool fWillUseInputColor; | 317 bool fWillUseInputColor; |
318 | 318 |
319 typedef GrProcessor INHERITED; | 319 typedef GrProcessor INHERITED; |
320 }; | 320 }; |
321 | 321 |
322 /** | 322 /** |
323 * This creates an effect outside of the effect memory pool. The effect's destru
ctor will be called | 323 * This creates an effect outside of the effect memory pool. The effect's destru
ctor will be called |
324 * at global destruction time. NAME will be the name of the created GrProcessor. | 324 * at global destruction time. NAME will be the name of the created GrProcessor. |
325 */ | 325 */ |
326 #define GR_CREATE_STATIC_FRAGMENT_PROCESSOR(NAME, EFFECT_CLASS, ARGS)
\ | 326 #define GR_CREATE_STATIC_FRAGMENT_PROCESSOR(NAME, EFFECT_CLASS, ARGS)
\ |
327 static SkAlignedSStorage<sizeof(EFFECT_CLASS)> g_##NAME##_Storage;
\ | 327 static SkAlignedSStorage<sizeof(EFFECT_CLASS)> g_##NAME##_Storage;
\ |
328 static GrFragmentProcessor*
\ | 328 static GrFragmentProcessor*
\ |
329 NAME SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), EFFECT_CLASS, ARGS);
\ | 329 NAME SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), EFFECT_CLASS, ARGS);
\ |
330 static SkAutoTDestroy<GrFragmentProcessor> NAME##_ad(NAME); | 330 static SkAutoTDestroy<GrFragmentProcessor> NAME##_ad(NAME); |
331 | 331 |
332 #endif | 332 #endif |
OLD | NEW |