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 |
1 #ifndef SkVarAlloc_DEFINED | 8 #ifndef SkVarAlloc_DEFINED |
2 #define SkVarAlloc_DEFINED | 9 #define SkVarAlloc_DEFINED |
3 | 10 |
4 #include "SkTypes.h" | 11 #include "SkTypes.h" |
5 | 12 |
6 class SkVarAlloc : SkNoncopyable { | 13 class SkVarAlloc : SkNoncopyable { |
7 public: | 14 public: |
8 // Smallest block we'll allocate is 2**N bytes. | 15 // Smallest block we'll allocate is 2**N bytes. |
9 explicit SkVarAlloc(size_t minLgSize); | 16 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 |
10 ~SkVarAlloc(); | 20 ~SkVarAlloc(); |
11 | 21 |
12 // Returns contiguous bytes aligned at least for pointers. You may pass SK_
MALLOC_THROW, etc. | 22 // Returns contiguous bytes aligned at least for pointers. You may pass SK_
MALLOC_THROW, etc. |
13 char* alloc(size_t bytes, unsigned sk_malloc_flags) { | 23 char* alloc(size_t bytes, unsigned sk_malloc_flags) { |
14 bytes = SkAlignPtr(bytes); | 24 bytes = SkAlignPtr(bytes); |
15 | 25 |
16 if (bytes > fRemaining) { | 26 if (bytes > fRemaining) { |
17 this->makeSpace(bytes, sk_malloc_flags); | 27 this->makeSpace(bytes, sk_malloc_flags); |
18 } | 28 } |
19 SkASSERT(bytes <= fRemaining); | 29 SkASSERT(bytes <= fRemaining); |
(...skipping 14 matching lines...) Expand all Loading... |
34 char* fByte; | 44 char* fByte; |
35 unsigned fRemaining; | 45 unsigned fRemaining; |
36 unsigned fLgSize; | 46 unsigned fLgSize; |
37 | 47 |
38 struct Block; | 48 struct Block; |
39 Block* fBlock; | 49 Block* fBlock; |
40 }; | 50 }; |
41 SK_COMPILE_ASSERT(sizeof(SkVarAlloc) <= 24, SkVarAllocSize); | 51 SK_COMPILE_ASSERT(sizeof(SkVarAlloc) <= 24, SkVarAllocSize); |
42 | 52 |
43 #endif//SkVarAlloc_DEFINED | 53 #endif//SkVarAlloc_DEFINED |
OLD | NEW |