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 GrBackendEffectFactory_DEFINED | 8 #ifndef GrBackendEffectFactory_DEFINED |
| 9 #define GrBackendEffectFactory_DEFINED | 9 #define GrBackendEffectFactory_DEFINED |
| 10 | 10 |
| 11 #include "GrTypes.h" | 11 #include "GrTypes.h" |
| 12 #include "SkTemplates.h" | 12 #include "SkTemplates.h" |
| 13 #include "SkThread.h" | 13 #include "SkThread.h" |
| 14 #include "SkTypes.h" | 14 #include "SkTypes.h" |
| 15 #include "SkTArray.h" | |
| 15 | 16 |
| 16 /** Given a GrEffect of a particular type, creates the corresponding graphics-ba ckend-specific | 17 /** Given a GrEffect of a particular type, creates the corresponding graphics-ba ckend-specific |
| 17 effect object. Also tracks equivalence of shaders generated via a key. Each factory instance | 18 effect object. Also tracks equivalence of shaders generated via a key. Each factory instance |
| 18 is assigned a generation ID at construction. The ID of the return of GrEffec t::getFactory() | 19 is assigned a generation ID at construction. The ID of the return of GrEffec t::getFactory() |
| 19 is used as a type identifier. Thus a GrEffect subclass must return a singlet on from | 20 is used as a type identifier. Thus a GrEffect subclass must return a singlet on from |
| 20 getFactory(). GrEffect subclasses should use the derived class GrTBackendEff ectFactory that is | 21 getFactory(). GrEffect subclasses should use the derived class GrTBackendEff ectFactory that is |
| 21 templated on the GrEffect subclass as their factory object. It requires that the GrEffect | 22 templated on the GrEffect subclass as their factory object. It requires that the GrEffect |
| 22 subclass has a nested class (or typedef) GLEffect which is its GL implementa tion and a subclass | 23 subclass has a nested class (or typedef) GLEffect which is its GL implementa tion and a subclass |
| 23 of GrGLEffect. | 24 of GrGLEffect. |
| 24 */ | 25 */ |
| 25 | 26 |
| 26 class GrGLEffect; | 27 class GrGLEffect; |
| 27 class GrGLCaps; | 28 class GrGLCaps; |
| 28 class GrDrawEffect; | 29 class GrDrawEffect; |
| 29 | 30 |
|
robertphillips
2014/07/10 12:15:50
// The EffectKeyBuilder class helps assemble a key
bsalomon
2014/07/10 17:24:34
I didn't add the bit about ownership to the top do
| |
| 31 class EffectKeyBuilder { | |
| 32 public: | |
| 33 EffectKeyBuilder(SkTArray<unsigned char, true>* data) : fData(data), fCount( 0) { | |
| 34 SkASSERT(0 == fData->count() % sizeof(uint32_t)); | |
| 35 } | |
| 36 | |
| 37 void add32(uint32_t v) { | |
| 38 ++fCount; | |
| 39 fData->push_back_n(4, reinterpret_cast<uint8_t*>(&v)); | |
| 40 } | |
| 41 | |
| 42 size_t size() const { return sizeof(uint32_t) * fCount; } | |
| 43 private: | |
| 44 SkTArray<uint8_t, true>* fData; | |
|
robertphillips
2014/07/10 12:15:50
Couldn't we replace fCount with (fData->count()/4)
| |
| 45 int fCount; | |
|
bsalomon
2014/07/10 17:24:34
No, it is the count of uint32_ts added since this
robertphillips
2014/07/10 18:13:17
That probably needs a comment
| |
| 46 }; | |
| 47 | |
| 30 class GrBackendEffectFactory : SkNoncopyable { | 48 class GrBackendEffectFactory : SkNoncopyable { |
| 31 public: | 49 public: |
| 32 typedef uint32_t EffectKey; | 50 typedef uint32_t EffectKey; |
| 33 enum { | |
| 34 kNoEffectKey = 0, | |
| 35 kEffectKeyBits = 10, | |
| 36 /** | |
| 37 * The framework automatically includes coord transforms and texture acc esses in their | |
| 38 * effect's EffectKey, so effects don't need to account for them in GenK ey(). | |
| 39 */ | |
| 40 kTextureKeyBits = 4, | |
| 41 kTransformKeyBits = 6, | |
| 42 kAttribKeyBits = 6, | |
| 43 kClassIDBits = 6 | |
| 44 }; | |
| 45 | 51 |
|
robertphillips
2014/07/10 12:15:50
// Return true ... ?
bsalomon
2014/07/10 17:24:34
The subclass GrTBackendEffectFactory has a comment
| |
| 46 virtual EffectKey glEffectKey(const GrDrawEffect&, const GrGLCaps&) const = 0; | 52 virtual bool getGLEffectKey(const GrDrawEffect&, const GrGLCaps&, EffectKeyB uilder*) const = 0; |
| 47 virtual GrGLEffect* createGLInstance(const GrDrawEffect&) const = 0; | 53 virtual GrGLEffect* createGLInstance(const GrDrawEffect&) const = 0; |
| 48 | 54 |
| 49 bool operator ==(const GrBackendEffectFactory& b) const { | 55 bool operator ==(const GrBackendEffectFactory& b) const { |
| 50 return fEffectClassID == b.fEffectClassID; | 56 return fEffectClassID == b.fEffectClassID; |
| 51 } | 57 } |
| 52 bool operator !=(const GrBackendEffectFactory& b) const { | 58 bool operator !=(const GrBackendEffectFactory& b) const { |
| 53 return !(*this == b); | 59 return !(*this == b); |
| 54 } | 60 } |
| 55 | 61 |
| 56 virtual const char* name() const = 0; | 62 virtual const char* name() const = 0; |
|
robertphillips
2014/07/10 12:15:50
Remove this '\' ?
bsalomon
2014/07/10 17:24:34
Done.
| |
| 57 | 63 \ |
| 58 static EffectKey GetTransformKey(EffectKey key) { | |
| 59 return key >> (kEffectKeyBits + kTextureKeyBits) & ((1U << kTransformKey Bits) - 1); | |
| 60 } | |
| 61 | |
| 62 protected: | 64 protected: |
| 63 enum { | 65 enum { |
| 64 kIllegalEffectClassID = 0, | 66 kIllegalEffectClassID = 0, |
| 65 }; | 67 }; |
| 66 | 68 |
| 67 GrBackendEffectFactory() { | 69 GrBackendEffectFactory() { |
| 68 fEffectClassID = kIllegalEffectClassID; | 70 fEffectClassID = kIllegalEffectClassID; |
| 69 } | 71 } |
| 70 virtual ~GrBackendEffectFactory() {} | 72 virtual ~GrBackendEffectFactory() {} |
| 71 | 73 |
| 72 static EffectKey GenID() { | 74 static int32_t GenID() { |
| 73 SkDEBUGCODE(static const int32_t kClassIDBits = 8 * sizeof(EffectKey) - | |
| 74 kTextureKeyBits - kEffectKeyBits - kAttribKeyBits); | |
| 75 // fCurrEffectClassID has been initialized to kIllegalEffectClassID. The | 75 // fCurrEffectClassID has been initialized to kIllegalEffectClassID. The |
| 76 // atomic inc returns the old value not the incremented value. So we add | 76 // atomic inc returns the old value not the incremented value. So we add |
| 77 // 1 to the returned value. | 77 // 1 to the returned value. |
| 78 int32_t id = sk_atomic_inc(&fCurrEffectClassID) + 1; | 78 int32_t id = sk_atomic_inc(&fCurrEffectClassID) + 1; |
| 79 SkASSERT(id < (1 << kClassIDBits)); | 79 return id; |
| 80 return static_cast<EffectKey>(id); | |
| 81 } | 80 } |
| 82 | 81 |
| 83 EffectKey fEffectClassID; | 82 int32_t fEffectClassID; |
| 84 | 83 |
| 85 private: | 84 private: |
| 86 static int32_t fCurrEffectClassID; | 85 static int32_t fCurrEffectClassID; |
| 87 }; | 86 }; |
| 88 | 87 |
| 89 #endif | 88 #endif |
| OLD | NEW |