OLD | NEW |
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 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 public: | 47 public: |
48 virtual const GrXferProcessor* createXferProcessor() const = 0; | 48 virtual const GrXferProcessor* createXferProcessor() const = 0; |
49 | 49 |
50 /** | 50 /** |
51 * This function returns true if the GrXferProcessor generated from this fac
tory will be able to | 51 * This function returns true if the GrXferProcessor generated from this fac
tory will be able to |
52 * correctly blend when using RGB coverage. The knownColor and knownColorFla
gs represent the | 52 * correctly blend when using RGB coverage. The knownColor and knownColorFla
gs represent the |
53 * final computed color from the color stages. | 53 * final computed color from the color stages. |
54 */ | 54 */ |
55 virtual bool supportsRGBCoverage(GrColor knownColor, uint32_t knownColorFlag
s) const = 0; | 55 virtual bool supportsRGBCoverage(GrColor knownColor, uint32_t knownColorFlag
s) const = 0; |
56 | 56 |
| 57 bool isEqual(const GrXPFactory& that) const { |
| 58 if (this->classID() != that.classID()) { |
| 59 return false; |
| 60 } |
| 61 return this->onIsEqual(that); |
| 62 } |
| 63 |
| 64 /** |
| 65 * Helper for down-casting to a GrXPFactory subclass |
| 66 */ |
| 67 template <typename T> const T& cast() const { return *static_cast<const T*>(
this); } |
| 68 |
| 69 uint32_t classID() const { SkASSERT(kIllegalXPFClassID != fClassID); return
fClassID; } |
| 70 |
| 71 protected: |
| 72 GrXPFactory() : fClassID(kIllegalXPFClassID) {} |
| 73 |
| 74 template <typename XPF_SUBCLASS> void initClassID() { |
| 75 static uint32_t kClassID = GenClassID(); |
| 76 fClassID = kClassID; |
| 77 } |
| 78 |
| 79 uint32_t fClassID; |
| 80 |
57 private: | 81 private: |
| 82 virtual bool onIsEqual(const GrXPFactory&) const = 0; |
| 83 |
| 84 static uint32_t GenClassID() { |
| 85 // fCurrXPFactoryID has been initialized to kIllegalXPFactoryID. The |
| 86 // atomic inc returns the old value not the incremented value. So we add |
| 87 // 1 to the returned value. |
| 88 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(&gCurrXPFClassID)) + 1
; |
| 89 if (!id) { |
| 90 SkFAIL("This should never wrap as it should only be called once for
each GrXPFactory " |
| 91 "subclass."); |
| 92 } |
| 93 return id; |
| 94 } |
| 95 |
| 96 enum { |
| 97 kIllegalXPFClassID = 0, |
| 98 }; |
| 99 static int32_t gCurrXPFClassID; |
| 100 |
58 typedef GrProgramElement INHERITED; | 101 typedef GrProgramElement INHERITED; |
59 }; | 102 }; |
60 | 103 |
61 #endif | 104 #endif |
62 | 105 |
OLD | NEW |