| OLD | NEW |
| 1 #ifndef SkVarAlloc_DEFINED | 1 #ifndef SkVarAlloc_DEFINED |
| 2 #define SkVarAlloc_DEFINED | 2 #define SkVarAlloc_DEFINED |
| 3 | 3 |
| 4 #include "SkTypes.h" | 4 #include "SkTypes.h" |
| 5 | 5 |
| 6 class SkVarAlloc : SkNoncopyable { | 6 class SkVarAlloc : SkNoncopyable { |
| 7 public: | 7 public: |
| 8 SkVarAlloc(); | 8 // Smallest block we'll allocate is 2**N bytes. |
| 9 explicit SkVarAlloc(size_t minLgSize); |
| 9 ~SkVarAlloc(); | 10 ~SkVarAlloc(); |
| 10 | 11 |
| 11 // Returns contiguous bytes aligned at least for pointers. You may pass SK_
MALLOC_THROW, etc. | 12 // Returns contiguous bytes aligned at least for pointers. You may pass SK_
MALLOC_THROW, etc. |
| 12 char* alloc(size_t bytes, unsigned sk_malloc_flags) { | 13 char* alloc(size_t bytes, unsigned sk_malloc_flags) { |
| 13 bytes = SkAlignPtr(bytes); | 14 bytes = SkAlignPtr(bytes); |
| 14 | 15 |
| 15 if (bytes > fRemaining) { | 16 if (bytes > fRemaining) { |
| 16 this->makeSpace(bytes, sk_malloc_flags); | 17 this->makeSpace(bytes, sk_malloc_flags); |
| 17 } | 18 } |
| 18 SkASSERT(bytes <= fRemaining); | 19 SkASSERT(bytes <= fRemaining); |
| 19 | 20 |
| 20 char* ptr = fByte; | 21 char* ptr = fByte; |
| 21 fByte += bytes; | 22 fByte += bytes; |
| 22 fRemaining -= bytes; | 23 fRemaining -= bytes; |
| 23 return ptr; | 24 return ptr; |
| 24 } | 25 } |
| 25 | 26 |
| 26 // Returns our best estimate of the number of bytes we've allocated. | 27 // Returns our best estimate of the number of bytes we've allocated. |
| 27 // (We intentionally do not track this precisely to save space.) | 28 // (We intentionally do not track this precisely to save space.) |
| 28 size_t approxBytesAllocated() const; | 29 size_t approxBytesAllocated() const; |
| 29 | 30 |
| 30 private: | 31 private: |
| 31 void makeSpace(size_t bytes, unsigned flags); | 32 void makeSpace(size_t bytes, unsigned flags); |
| 32 | 33 |
| 33 char* fByte; | 34 char* fByte; |
| 34 unsigned fRemaining; | 35 unsigned fRemaining; |
| 35 unsigned fLgSize; // This is always in the range [4, 16], so it really only
needs 4 bits. | 36 unsigned fLgSize; |
| 36 | 37 |
| 37 struct Block; | 38 struct Block; |
| 38 Block* fBlock; | 39 Block* fBlock; |
| 39 }; | 40 }; |
| 40 SK_COMPILE_ASSERT(sizeof(SkVarAlloc) <= 24, SkVarAllocSize); | 41 SK_COMPILE_ASSERT(sizeof(SkVarAlloc) <= 24, SkVarAllocSize); |
| 41 | 42 |
| 42 #endif//SkVarAlloc_DEFINED | 43 #endif//SkVarAlloc_DEFINED |
| OLD | NEW |