Chromium Code Reviews| 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 GrEffect_DEFINED | 8 #ifndef GrEffect_DEFINED |
| 9 #define GrEffect_DEFINED | 9 #define GrEffect_DEFINED |
| 10 | 10 |
| 11 #include "GrColor.h" | 11 #include "GrColor.h" |
| 12 #include "GrEffectUnitTest.h" | 12 #include "GrEffectUnitTest.h" |
| 13 #include "GrTexture.h" | 13 #include "GrTexture.h" |
| 14 #include "GrTextureAccess.h" | 14 #include "GrTextureAccess.h" |
| 15 #include "GrTypesPriv.h" | 15 #include "GrTypesPriv.h" |
| 16 | 16 |
| 17 class GrBackendEffectFactory; | 17 class GrBackendEffectFactory; |
| 18 class GrContext; | 18 class GrContext; |
| 19 class GrCoordTransform; | |
| 19 class GrEffect; | 20 class GrEffect; |
| 20 class GrVertexEffect; | 21 class GrVertexEffect; |
| 21 class SkString; | 22 class SkString; |
| 22 | 23 |
| 23 /** | 24 /** |
| 24 * A Wrapper class for GrEffect. Its ref-count will track owners that may use ef fects to enqueue | 25 * A Wrapper class for GrEffect. Its ref-count will track owners that may use ef fects to enqueue |
| 25 * new draw operations separately from ownership within a deferred drawing queue . When the | 26 * new draw operations separately from ownership within a deferred drawing queue . When the |
| 26 * GrEffectRef ref count reaches zero the scratch GrResources owned by the effec t can be recycled | 27 * GrEffectRef ref count reaches zero the scratch GrResources owned by the effec t can be recycled |
| 27 * in service of later draws. However, the deferred draw queue may still own dir ect references to | 28 * in service of later draws. However, the deferred draw queue may still own dir ect references to |
| 28 * the underlying GrEffect. | 29 * the underlying GrEffect. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 privately inherit from SkRefCnt to help prevent accidental direct ref'ing/un ref'ing of effects. | 77 privately inherit from SkRefCnt to help prevent accidental direct ref'ing/un ref'ing of effects. |
| 77 | 78 |
| 78 Dynamically allocated GrEffects and their corresponding GrEffectRefs are man aged by a per-thread | 79 Dynamically allocated GrEffects and their corresponding GrEffectRefs are man aged by a per-thread |
| 79 memory pool. The ref count of an effect must reach 0 before the thread termi nates and the pool | 80 memory pool. The ref count of an effect must reach 0 before the thread termi nates and the pool |
| 80 is destroyed. To create a static effect use the macro GR_CREATE_STATIC_EFFEC T declared below. | 81 is destroyed. To create a static effect use the macro GR_CREATE_STATIC_EFFEC T declared below. |
| 81 */ | 82 */ |
| 82 class GrEffect : private SkRefCnt { | 83 class GrEffect : private SkRefCnt { |
| 83 public: | 84 public: |
| 84 SK_DECLARE_INST_COUNT(GrEffect) | 85 SK_DECLARE_INST_COUNT(GrEffect) |
| 85 | 86 |
| 86 /** | |
| 87 * The types of vertex coordinates available to an effect in the vertex shad er. Effects can | |
| 88 * require their own vertex attribute but these coordinates are made availab le by the framework | |
| 89 * in all programs. | |
| 90 */ | |
| 91 enum CoordsType { | |
| 92 kLocal_CoordsType, | |
| 93 kPosition_CoordsType, | |
| 94 }; | |
| 95 | |
| 96 virtual ~GrEffect(); | 87 virtual ~GrEffect(); |
| 97 | 88 |
| 98 /** | 89 /** |
| 99 * This function is used to perform optimizations. When called the color and validFlags params | 90 * This function is used to perform optimizations. When called the color and validFlags params |
| 100 * indicate whether the input components to this effect in the FS will have known values. | 91 * indicate whether the input components to this effect in the FS will have known values. |
| 101 * validFlags is a bitfield of GrColorComponentFlags. The function updates b oth params to | 92 * validFlags is a bitfield of GrColorComponentFlags. The function updates b oth params to |
| 102 * indicate known values of its output. A component of the color param only has meaning if the | 93 * indicate known values of its output. A component of the color param only has meaning if the |
| 103 * corresponding bit in validFlags is set. | 94 * corresponding bit in validFlags is set. |
| 104 */ | 95 */ |
| 105 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags ) const = 0; | 96 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags ) const = 0; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 131 effectA.getFactory().glEffectKey(effectA) == effectB.getFactory().gl EffectKey(effectB). | 122 effectA.getFactory().glEffectKey(effectA) == effectB.getFactory().gl EffectKey(effectB). |
| 132 */ | 123 */ |
| 133 bool isEqual(const GrEffectRef& other) const { | 124 bool isEqual(const GrEffectRef& other) const { |
| 134 return this->isEqual(*other.get()); | 125 return this->isEqual(*other.get()); |
| 135 } | 126 } |
| 136 | 127 |
| 137 /** Human-meaningful string to identify this effect; may be embedded | 128 /** Human-meaningful string to identify this effect; may be embedded |
| 138 in generated shader code. */ | 129 in generated shader code. */ |
| 139 const char* name() const; | 130 const char* name() const; |
| 140 | 131 |
| 132 int numTransforms() const { return fCoordTransforms.count(); } | |
| 133 | |
| 134 /** Returns the coordinate transformation at index. index must be valid acco rding to | |
| 135 numTransforms(). */ | |
| 136 const GrCoordTransform& coordTransform(int index) const { return *fCoordTran sforms[index]; } | |
| 137 | |
| 141 int numTextures() const { return fTextureAccesses.count(); } | 138 int numTextures() const { return fTextureAccesses.count(); } |
| 142 | 139 |
| 143 /** Returns the access pattern for the texture at index. index must be valid according to | 140 /** Returns the access pattern for the texture at index. index must be valid according to |
| 144 numTextures(). */ | 141 numTextures(). */ |
| 145 const GrTextureAccess& textureAccess(int index) const { return *fTextureAcce sses[index]; } | 142 const GrTextureAccess& textureAccess(int index) const { return *fTextureAcce sses[index]; } |
| 146 | 143 |
| 147 /** Shortcut for textureAccess(index).texture(); */ | 144 /** Shortcut for textureAccess(index).texture(); */ |
| 148 GrTexture* texture(int index) const { return this->textureAccess(index).getT exture(); } | 145 GrTexture* texture(int index) const { return this->textureAccess(index).getT exture(); } |
| 149 | 146 |
| 150 /** Will this effect read the destination pixel value? */ | 147 /** Will this effect read the destination pixel value? */ |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 void decDeferredRefCounts() const { | 195 void decDeferredRefCounts() const { |
| 199 int count = fTextureAccesses.count(); | 196 int count = fTextureAccesses.count(); |
| 200 for (int t = 0; t < count; ++t) { | 197 for (int t = 0; t < count; ++t) { |
| 201 fTextureAccesses[t]->getTexture()->decDeferredRefCount(); | 198 fTextureAccesses[t]->getTexture()->decDeferredRefCount(); |
| 202 } | 199 } |
| 203 this->unref(); | 200 this->unref(); |
| 204 } | 201 } |
| 205 | 202 |
| 206 protected: | 203 protected: |
| 207 /** | 204 /** |
| 205 * Subclasses call this from their constructor to register coordinate transf ormations. The | |
| 206 * effect subclass manages the lifetime of the transformations (this functio n only stores a | |
| 207 * pointer). The GrCoordTransform is typically a member field of the GrEffet subclass. When the | |
|
jvanverth1
2013/09/27 20:41:35
Typo: GrEffet
Chris Dalton
2013/09/27 23:33:45
Done.
| |
| 208 * matrix has perspective, the transformed coordinates will have 3 component s. Otherwise they'll | |
| 209 * have 2. This must only be called from the constructor because GrEffects a re immutable. | |
| 210 */ | |
| 211 void addCoordTransform(const GrCoordTransform* coordTransform); | |
| 212 | |
| 213 /** | |
| 208 * Subclasses call this from their constructor to register GrTextureAccesses . The effect | 214 * Subclasses call this from their constructor to register GrTextureAccesses . The effect |
| 209 * subclass manages the lifetime of the accesses (this function only stores a pointer). The | 215 * subclass manages the lifetime of the accesses (this function only stores a pointer). The |
| 210 * GrTextureAccess is typically a member field of the GrEffet subclass. This must only be | 216 * GrTextureAccess is typically a member field of the GrEffet subclass. This must only be |
| 211 * called from the constructor because GrEffects are immutable. | 217 * called from the constructor because GrEffects are immutable. |
| 212 */ | 218 */ |
| 213 void addTextureAccess(const GrTextureAccess* textureAccess); | 219 void addTextureAccess(const GrTextureAccess* textureAccess); |
| 214 | 220 |
| 215 GrEffect() | 221 GrEffect() |
| 216 : fWillReadDstColor(false) | 222 : fWillReadDstColor(false) |
| 217 , fWillReadFragmentPosition(false) | 223 , fWillReadFragmentPosition(false) |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 282 void setWillReadFragmentPosition() { fWillReadFragmentPosition = true; } | 288 void setWillReadFragmentPosition() { fWillReadFragmentPosition = true; } |
| 283 | 289 |
| 284 private: | 290 private: |
| 285 bool isEqual(const GrEffect& other) const { | 291 bool isEqual(const GrEffect& other) const { |
| 286 if (&this->getFactory() != &other.getFactory()) { | 292 if (&this->getFactory() != &other.getFactory()) { |
| 287 return false; | 293 return false; |
| 288 } | 294 } |
| 289 bool result = this->onIsEqual(other); | 295 bool result = this->onIsEqual(other); |
| 290 #ifdef SK_DEBUG | 296 #ifdef SK_DEBUG |
| 291 if (result) { | 297 if (result) { |
| 292 SkASSERT(this->numTextures() == other.numTextures()); | 298 this->assertEquality(other); |
| 293 for (int i = 0; i < this->numTextures(); ++i) { | |
| 294 SkASSERT(*fTextureAccesses[i] == *other.fTextureAccesses[i]); | |
| 295 } | |
| 296 } | 299 } |
| 297 #endif | 300 #endif |
| 298 return result; | 301 return result; |
| 299 } | 302 } |
| 300 | 303 |
| 304 SkDEBUGCODE(void assertEquality(const GrEffect& other) const;) | |
| 305 | |
| 301 /** Subclass implements this to support isEqual(). It will only be called if it is known that | 306 /** Subclass implements this to support isEqual(). It will only be called if it is known that |
| 302 the two effects are of the same subclass (i.e. they return the same obje ct from | 307 the two effects are of the same subclass (i.e. they return the same obje ct from |
| 303 getFactory()).*/ | 308 getFactory()).*/ |
| 304 virtual bool onIsEqual(const GrEffect& other) const = 0; | 309 virtual bool onIsEqual(const GrEffect& other) const = 0; |
| 305 | 310 |
| 306 void EffectRefDestroyed() { fEffectRef = NULL; } | 311 void EffectRefDestroyed() { fEffectRef = NULL; } |
| 307 | 312 |
| 308 friend class GrEffectRef; // to call EffectRefDestroyed() | 313 friend class GrEffectRef; // to call EffectRefDestroyed() |
| 309 friend class GrEffectStage; // to rewrap GrEffect in GrEffectRef when resto ring an effect-stage | 314 friend class GrEffectStage; // to rewrap GrEffect in GrEffectRef when resto ring an effect-stage |
| 310 // from deferred state, to call isEqual on nake d GrEffects, and | 315 // from deferred state, to call isEqual on nake d GrEffects, and |
| 311 // to inc/dec deferred ref counts. | 316 // to inc/dec deferred ref counts. |
| 312 friend class GrVertexEffect; // to set fHasVertexCode and build fVertexAttri bTypes. | 317 friend class GrVertexEffect; // to set fHasVertexCode and build fVertexAttri bTypes. |
| 313 | 318 |
| 319 SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms; | |
| 314 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses; | 320 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses; |
| 315 SkSTArray<kMaxVertexAttribs, GrSLType, true> fVertexAttribTypes; | 321 SkSTArray<kMaxVertexAttribs, GrSLType, true> fVertexAttribTypes; |
| 316 bool fWillReadDstColor; | 322 bool fWillReadDstColor; |
| 317 bool fWillReadFragmentPosition; | 323 bool fWillReadFragmentPosition; |
| 318 bool fHasVertexCode; | 324 bool fHasVertexCode; |
| 319 GrEffectRef* fEffectRef; | 325 GrEffectRef* fEffectRef; |
| 320 | 326 |
| 321 typedef SkRefCnt INHERITED; | 327 typedef SkRefCnt INHERITED; |
| 322 }; | 328 }; |
| 323 | 329 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 338 }; \ | 344 }; \ |
| 339 static SkAlignedSStorage<k_##NAME##_StorageSize> g_##NAME##_Storage; \ | 345 static SkAlignedSStorage<k_##NAME##_StorageSize> g_##NAME##_Storage; \ |
| 340 static void* NAME##_RefLocation = (char*)g_##NAME##_Storage.get() + k_##NAME##_E ffectRefOffset; \ | 346 static void* NAME##_RefLocation = (char*)g_##NAME##_Storage.get() + k_##NAME##_E ffectRefOffset; \ |
| 341 static GrEffect* NAME##_Effect SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), EF FECT_CLASS, ARGS);\ | 347 static GrEffect* NAME##_Effect SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), EF FECT_CLASS, ARGS);\ |
| 342 static SkAutoTDestroy<GrEffect> NAME##_ad(NAME##_Effect); \ | 348 static SkAutoTDestroy<GrEffect> NAME##_ad(NAME##_Effect); \ |
| 343 static GrEffectRef* NAME(GrEffect::CreateStaticEffectRef(NAME##_RefLocation, NAM E##_Effect)); \ | 349 static GrEffectRef* NAME(GrEffect::CreateStaticEffectRef(NAME##_RefLocation, NAM E##_Effect)); \ |
| 344 static SkAutoTDestroy<GrEffectRef> NAME##_Ref_ad(NAME) | 350 static SkAutoTDestroy<GrEffectRef> NAME##_Ref_ad(NAME) |
| 345 | 351 |
| 346 | 352 |
| 347 #endif | 353 #endif |
| OLD | NEW |