| OLD | NEW |
| 1 | |
| 2 /* | 1 /* |
| 3 * Copyright 2010 Google Inc. | 2 * Copyright 2010 Google Inc. |
| 4 * | 3 * |
| 5 * 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 |
| 6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 7 */ | 6 */ |
| 8 | 7 |
| 9 | |
| 10 | |
| 11 #ifndef GrAllocator_DEFINED | 8 #ifndef GrAllocator_DEFINED |
| 12 #define GrAllocator_DEFINED | 9 #define GrAllocator_DEFINED |
| 13 | 10 |
| 14 #include "GrNoncopyable.h" | |
| 15 #include "GrConfig.h" | 11 #include "GrConfig.h" |
| 12 #include "GrTypes.h" |
| 16 #include "SkTArray.h" | 13 #include "SkTArray.h" |
| 14 #include "SkTypes.h" |
| 17 | 15 |
| 18 class GrAllocator : GrNoncopyable { | 16 class GrAllocator : public SkNoncopyable { |
| 19 public: | 17 public: |
| 20 ~GrAllocator() { | 18 ~GrAllocator() { |
| 21 reset(); | 19 reset(); |
| 22 } | 20 } |
| 23 | 21 |
| 24 /** | 22 /** |
| 25 * Create an allocator | 23 * Create an allocator |
| 26 * | 24 * |
| 27 * @param itemSize the size of each item to allocate | 25 * @param itemSize the size of each item to allocate |
| 28 * @param itemsPerBlock the number of items to allocate at once | 26 * @param itemsPerBlock the number of items to allocate at once |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 private: | 126 private: |
| 129 static const int NUM_INIT_BLOCK_PTRS = 8; | 127 static const int NUM_INIT_BLOCK_PTRS = 8; |
| 130 | 128 |
| 131 SkSTArray<NUM_INIT_BLOCK_PTRS, void*> fBlocks; | 129 SkSTArray<NUM_INIT_BLOCK_PTRS, void*> fBlocks; |
| 132 size_t fBlockSize; | 130 size_t fBlockSize; |
| 133 size_t fItemSize; | 131 size_t fItemSize; |
| 134 int fItemsPerBlock; | 132 int fItemsPerBlock; |
| 135 bool fOwnFirstBlock; | 133 bool fOwnFirstBlock; |
| 136 int fCount; | 134 int fCount; |
| 137 | 135 |
| 138 typedef GrNoncopyable INHERITED; | 136 typedef SkNoncopyable INHERITED; |
| 139 }; | 137 }; |
| 140 | 138 |
| 141 template <typename T> | 139 template <typename T> |
| 142 class GrTAllocator : GrNoncopyable { | 140 class GrTAllocator : public SkNoncopyable { |
| 143 | |
| 144 public: | 141 public: |
| 145 virtual ~GrTAllocator() { this->reset(); }; | 142 virtual ~GrTAllocator() { this->reset(); }; |
| 146 | 143 |
| 147 /** | 144 /** |
| 148 * Create an allocator | 145 * Create an allocator |
| 149 * | 146 * |
| 150 * @param itemsPerBlock the number of items to allocate at once | 147 * @param itemsPerBlock the number of items to allocate at once |
| 151 * @param initialBlock optional memory to use for the first block. | 148 * @param initialBlock optional memory to use for the first block. |
| 152 * Must be at least size(T)*itemsPerBlock sized. | 149 * Must be at least size(T)*itemsPerBlock sized. |
| 153 * Caller is responsible for freeing this memory. | 150 * Caller is responsible for freeing this memory. |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 return *(const T*)(fAllocator[i]); | 222 return *(const T*)(fAllocator[i]); |
| 226 } | 223 } |
| 227 | 224 |
| 228 protected: | 225 protected: |
| 229 GrTAllocator(int itemsPerBlock, void* initialBlock) | 226 GrTAllocator(int itemsPerBlock, void* initialBlock) |
| 230 : fAllocator(sizeof(T), itemsPerBlock, initialBlock) { | 227 : fAllocator(sizeof(T), itemsPerBlock, initialBlock) { |
| 231 } | 228 } |
| 232 | 229 |
| 233 private: | 230 private: |
| 234 GrAllocator fAllocator; | 231 GrAllocator fAllocator; |
| 235 typedef GrNoncopyable INHERITED; | 232 typedef SkNoncopyable INHERITED; |
| 236 }; | 233 }; |
| 237 | 234 |
| 238 template <int N, typename T> class GrSTAllocator : public GrTAllocator<T> { | 235 template <int N, typename T> class GrSTAllocator : public GrTAllocator<T> { |
| 239 private: | 236 private: |
| 240 typedef GrTAllocator<T> INHERITED; | 237 typedef GrTAllocator<T> INHERITED; |
| 241 | 238 |
| 242 public: | 239 public: |
| 243 GrSTAllocator() : INHERITED(N, fStorage.get()) { | 240 GrSTAllocator() : INHERITED(N, fStorage.get()) { |
| 244 } | 241 } |
| 245 | 242 |
| 246 private: | 243 private: |
| 247 SkAlignedSTStorage<N, T> fStorage; | 244 SkAlignedSTStorage<N, T> fStorage; |
| 248 }; | 245 }; |
| 249 | 246 |
| 250 #endif | 247 #endif |
| OLD | NEW |