| 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 GrBackendEffectFactory_DEFINED | 8 #ifndef GrBackendEffectFactory_DEFINED |
| 9 #define GrBackendEffectFactory_DEFINED | 9 #define GrBackendEffectFactory_DEFINED |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 class GrEffectRef; | 26 class GrEffectRef; |
| 27 class GrGLEffect; | 27 class GrGLEffect; |
| 28 class GrGLCaps; | 28 class GrGLCaps; |
| 29 class GrDrawEffect; | 29 class GrDrawEffect; |
| 30 | 30 |
| 31 class GrBackendEffectFactory : public SkNoncopyable { | 31 class GrBackendEffectFactory : public SkNoncopyable { |
| 32 public: | 32 public: |
| 33 typedef uint32_t EffectKey; | 33 typedef uint32_t EffectKey; |
| 34 enum { | 34 enum { |
| 35 kNoEffectKey = 0, | 35 kNoEffectKey = 0, |
| 36 kEffectKeyBits = 15, | 36 kEffectKeyBits = 10, |
| 37 /** | 37 /** |
| 38 * Some aspects of the generated code may be determined by the particula
r textures that are | 38 * The framework automatically includes coord transforms and texture acc
esses in their |
| 39 * associated with the effect. These manipulations are performed by GrGL
ShaderBuilder beyond | 39 * effect's EffectKey, so effects don't need to account for them in GenK
ey(). |
| 40 * GrGLEffects' control. So there is a dedicated part of the key which i
s combined | |
| 41 * automatically with the bits produced by GrGLEffect::GenKey(). | |
| 42 */ | 40 */ |
| 43 kTextureKeyBits = 4, | 41 kTextureKeyBits = 4, |
| 44 kAttribKeyBits = 6 | 42 kTransformKeyBits = 6, |
| 43 kAttribKeyBits = 6, |
| 44 kClassIDBits = 6 |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 virtual EffectKey glEffectKey(const GrDrawEffect&, const GrGLCaps&) const =
0; | 47 virtual EffectKey glEffectKey(const GrDrawEffect&, const GrGLCaps&) const =
0; |
| 48 virtual GrGLEffect* createGLInstance(const GrDrawEffect&) const = 0; | 48 virtual GrGLEffect* createGLInstance(const GrDrawEffect&) const = 0; |
| 49 | 49 |
| 50 bool operator ==(const GrBackendEffectFactory& b) const { | 50 bool operator ==(const GrBackendEffectFactory& b) const { |
| 51 return fEffectClassID == b.fEffectClassID; | 51 return fEffectClassID == b.fEffectClassID; |
| 52 } | 52 } |
| 53 bool operator !=(const GrBackendEffectFactory& b) const { | 53 bool operator !=(const GrBackendEffectFactory& b) const { |
| 54 return !(*this == b); | 54 return !(*this == b); |
| 55 } | 55 } |
| 56 | 56 |
| 57 virtual const char* name() const = 0; | 57 virtual const char* name() const = 0; |
| 58 | 58 |
| 59 static EffectKey GetTransformKey(EffectKey key) { |
| 60 return key >> (kEffectKeyBits + kTextureKeyBits) & ((1U << kTransformKey
Bits) - 1); |
| 61 } |
| 62 |
| 59 protected: | 63 protected: |
| 60 enum { | 64 enum { |
| 61 kIllegalEffectClassID = 0, | 65 kIllegalEffectClassID = 0, |
| 62 }; | 66 }; |
| 63 | 67 |
| 64 GrBackendEffectFactory() { | 68 GrBackendEffectFactory() { |
| 65 fEffectClassID = kIllegalEffectClassID; | 69 fEffectClassID = kIllegalEffectClassID; |
| 66 } | 70 } |
| 67 virtual ~GrBackendEffectFactory() {} | 71 virtual ~GrBackendEffectFactory() {} |
| 68 | 72 |
| 69 static EffectKey GenID() { | 73 static EffectKey GenID() { |
| 70 SkDEBUGCODE(static const int32_t kClassIDBits = 8 * sizeof(EffectKey) - | 74 SkDEBUGCODE(static const int32_t kClassIDBits = 8 * sizeof(EffectKey) - |
| 71 kTextureKeyBits - kEffectKeyBits - kAttribKeyBits); | 75 kTextureKeyBits - kEffectKeyBits - kAttribKeyBits); |
| 72 // fCurrEffectClassID has been initialized to kIllegalEffectClassID. The | 76 // fCurrEffectClassID has been initialized to kIllegalEffectClassID. The |
| 73 // atomic inc returns the old value not the incremented value. So we add | 77 // atomic inc returns the old value not the incremented value. So we add |
| 74 // 1 to the returned value. | 78 // 1 to the returned value. |
| 75 int32_t id = sk_atomic_inc(&fCurrEffectClassID) + 1; | 79 int32_t id = sk_atomic_inc(&fCurrEffectClassID) + 1; |
| 76 SkASSERT(id < (1 << kClassIDBits)); | 80 SkASSERT(id < (1 << kClassIDBits)); |
| 77 return static_cast<EffectKey>(id); | 81 return static_cast<EffectKey>(id); |
| 78 } | 82 } |
| 79 | 83 |
| 80 EffectKey fEffectClassID; | 84 EffectKey fEffectClassID; |
| 81 | 85 |
| 82 private: | 86 private: |
| 83 static int32_t fCurrEffectClassID; | 87 static int32_t fCurrEffectClassID; |
| 84 }; | 88 }; |
| 85 | 89 |
| 86 #endif | 90 #endif |
| OLD | NEW |