OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 SkRecord_DEFINED | 8 #ifndef SkRecord_DEFINED |
9 #define SkRecord_DEFINED | 9 #define SkRecord_DEFINED |
10 | 10 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 // We store the types of each of the pointers alongside the pointer. | 131 // We store the types of each of the pointers alongside the pointer. |
132 // The cost to append a T to this structure is 8 + sizeof(T) bytes. | 132 // The cost to append a T to this structure is 8 + sizeof(T) bytes. |
133 | 133 |
134 // A mutator that can be used with replace to destroy canvas commands. | 134 // A mutator that can be used with replace to destroy canvas commands. |
135 struct Destroyer { | 135 struct Destroyer { |
136 template <typename T> | 136 template <typename T> |
137 void operator()(T* record) { record->~T(); } | 137 void operator()(T* record) { record->~T(); } |
138 }; | 138 }; |
139 | 139 |
140 template <typename T> | 140 template <typename T> |
141 SK_WHEN(skstd::is_empty<T>::value, T*) allocCommand() { | 141 SK_WHEN(std::is_empty<T>::value, T*) allocCommand() { |
142 static T singleton = {}; | 142 static T singleton = {}; |
143 return &singleton; | 143 return &singleton; |
144 } | 144 } |
145 | 145 |
146 template <typename T> | 146 template <typename T> |
147 SK_WHEN(!skstd::is_empty<T>::value, T*) allocCommand() { return this->alloc<
T>(); } | 147 SK_WHEN(!std::is_empty<T>::value, T*) allocCommand() { return this->alloc<T>
(); } |
148 | 148 |
149 void grow(); | 149 void grow(); |
150 | 150 |
151 // A typed pointer to some bytes in fAlloc. visit() and mutate() allow poly
morphic dispatch. | 151 // A typed pointer to some bytes in fAlloc. visit() and mutate() allow poly
morphic dispatch. |
152 struct Record { | 152 struct Record { |
153 // On 32-bit machines we store type in 4 bytes, followed by a pointer.
Simple. | 153 // On 32-bit machines we store type in 4 bytes, followed by a pointer.
Simple. |
154 // On 64-bit machines we store a pointer with the type slotted into two
top (unused) bytes. | 154 // On 64-bit machines we store a pointer with the type slotted into two
top (unused) bytes. |
155 // FWIW, SkRecords::Type is tiny. It can easily fit in one byte. | 155 // FWIW, SkRecords::Type is tiny. It can easily fit in one byte. |
156 uint64_t fTypeAndPtr; | 156 uint64_t fTypeAndPtr; |
157 static const int kTypeShift = sizeof(void*) == 4 ? 32 : 48; | 157 static const int kTypeShift = sizeof(void*) == 4 ? 32 : 48; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 int fCount, fReserved; | 193 int fCount, fReserved; |
194 SkAutoSTMalloc<kInlineRecords, Record> fRecords; | 194 SkAutoSTMalloc<kInlineRecords, Record> fRecords; |
195 | 195 |
196 // fAlloc needs to be a data structure which can append variable length data
in contiguous | 196 // fAlloc needs to be a data structure which can append variable length data
in contiguous |
197 // chunks, returning a stable handle to that data for later retrieval. | 197 // chunks, returning a stable handle to that data for later retrieval. |
198 SkVarAlloc fAlloc; | 198 SkVarAlloc fAlloc; |
199 char fInlineAlloc[1 << kInlineAllocLgBytes]; | 199 char fInlineAlloc[1 << kInlineAllocLgBytes]; |
200 }; | 200 }; |
201 | 201 |
202 #endif//SkRecord_DEFINED | 202 #endif//SkRecord_DEFINED |
OLD | NEW |