| OLD | NEW |
| 1 /* | |
| 2 * Copyright 2015 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #ifndef SkVarAlloc_DEFINED | 1 #ifndef SkVarAlloc_DEFINED |
| 9 #define SkVarAlloc_DEFINED | 2 #define SkVarAlloc_DEFINED |
| 10 | 3 |
| 11 #include "SkTypes.h" | 4 #include "SkTypes.h" |
| 12 | 5 |
| 13 class SkVarAlloc : SkNoncopyable { | 6 class SkVarAlloc : SkNoncopyable { |
| 14 public: | 7 public: |
| 15 // Smallest block we'll allocate is 2**N bytes. | 8 // Smallest block we'll allocate is 2**N bytes. |
| 16 explicit SkVarAlloc(size_t minLgSize); | 9 explicit SkVarAlloc(size_t minLgSize); |
| 17 // Same as above, but first uses up to len bytes from storage. | |
| 18 SkVarAlloc(size_t minLgSize, char* storage, size_t len); | |
| 19 | |
| 20 ~SkVarAlloc(); | 10 ~SkVarAlloc(); |
| 21 | 11 |
| 22 // 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. |
| 23 char* alloc(size_t bytes, unsigned sk_malloc_flags) { | 13 char* alloc(size_t bytes, unsigned sk_malloc_flags) { |
| 24 bytes = SkAlignPtr(bytes); | 14 bytes = SkAlignPtr(bytes); |
| 25 | 15 |
| 26 if (bytes > fRemaining) { | 16 if (bytes > fRemaining) { |
| 27 this->makeSpace(bytes, sk_malloc_flags); | 17 this->makeSpace(bytes, sk_malloc_flags); |
| 28 } | 18 } |
| 29 SkASSERT(bytes <= fRemaining); | 19 SkASSERT(bytes <= fRemaining); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 44 char* fByte; | 34 char* fByte; |
| 45 unsigned fRemaining; | 35 unsigned fRemaining; |
| 46 unsigned fLgSize; | 36 unsigned fLgSize; |
| 47 | 37 |
| 48 struct Block; | 38 struct Block; |
| 49 Block* fBlock; | 39 Block* fBlock; |
| 50 }; | 40 }; |
| 51 SK_COMPILE_ASSERT(sizeof(SkVarAlloc) <= 24, SkVarAllocSize); | 41 SK_COMPILE_ASSERT(sizeof(SkVarAlloc) <= 24, SkVarAllocSize); |
| 52 | 42 |
| 53 #endif//SkVarAlloc_DEFINED | 43 #endif//SkVarAlloc_DEFINED |
| OLD | NEW |