OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 GrBatch_DEFINED | 8 #ifndef GrBatch_DEFINED |
9 #define GrBatch_DEFINED | 9 #define GrBatch_DEFINED |
10 | 10 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 static uint32_t GenBatchClassID() { return GenID(&gCurrBatchClassID); } | 134 static uint32_t GenBatchClassID() { return GenID(&gCurrBatchClassID); } |
135 | 135 |
136 SkRect fBounds; | 136 SkRect fBounds; |
137 | 137 |
138 private: | 138 private: |
139 virtual bool onCombineIfPossible(GrBatch*, const GrCaps& caps) = 0; | 139 virtual bool onCombineIfPossible(GrBatch*, const GrCaps& caps) = 0; |
140 | 140 |
141 virtual void onPrepare(GrBatchFlushState*) = 0; | 141 virtual void onPrepare(GrBatchFlushState*) = 0; |
142 virtual void onDraw(GrBatchFlushState*) = 0; | 142 virtual void onDraw(GrBatchFlushState*) = 0; |
143 | 143 |
| 144 // Override this method if the batch subclass gets allocated in a nonstandar
d way. |
| 145 virtual void onDelete() const { delete this; } |
| 146 |
144 static uint32_t GenID(int32_t* idCounter) { | 147 static uint32_t GenID(int32_t* idCounter) { |
145 // The atomic inc returns the old value not the incremented value. So we
add | 148 // The atomic inc returns the old value not the incremented value. So we
add |
146 // 1 to the returned value. | 149 // 1 to the returned value. |
147 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(idCounter)) + 1; | 150 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(idCounter)) + 1; |
148 if (!id) { | 151 if (!id) { |
149 SkFAIL("This should never wrap as it should only be called once for
each GrBatch " | 152 SkFAIL("This should never wrap as it should only be called once for
each GrBatch " |
150 "subclass."); | 153 "subclass."); |
151 } | 154 } |
152 return id; | 155 return id; |
153 } | 156 } |
154 | 157 |
155 enum { | 158 enum { |
156 kIllegalBatchID = 0, | 159 kIllegalBatchID = 0, |
157 }; | 160 }; |
158 | 161 |
159 SkDEBUGCODE(bool fUsed;) | 162 SkDEBUGCODE(bool fUsed;) |
160 const uint32_t fClassID; | 163 const uint32_t fClassID; |
161 static uint32_t GenBatchID() { return GenID(&gCurrBatchUniqueID); } | 164 static uint32_t GenBatchID() { return GenID(&gCurrBatchUniqueID); } |
162 mutable uint32_t fUniqueID; | 165 mutable uint32_t fUniqueID; |
163 static int32_t gCurrBatchUniqueID; | 166 static int32_t gCurrBatchUniqueID; |
164 static int32_t gCurrBatchClassID; | 167 static int32_t gCurrBatchClassID; |
| 168 |
| 169 friend void GrTDeleteNonAtomicRef(const GrBatch*); // For onDelete. |
165 }; | 170 }; |
166 | 171 |
| 172 inline void GrTDeleteNonAtomicRef(const GrBatch* batch) { |
| 173 batch->onDelete(); |
| 174 } |
| 175 |
167 #endif | 176 #endif |
OLD | NEW |