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