OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #ifndef SkPictureFlat_DEFINED | 8 #ifndef SkPictureFlat_DEFINED |
9 #define SkPictureFlat_DEFINED | 9 #define SkPictureFlat_DEFINED |
10 | 10 |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 // A buffer of 256 bytes should fit most paints, regions, and matrices. | 265 // A buffer of 256 bytes should fit most paints, regions, and matrices. |
266 uint32_t storage[64]; | 266 uint32_t storage[64]; |
267 SkOrderedWriteBuffer buffer(storage, sizeof(storage)); | 267 SkOrderedWriteBuffer buffer(storage, sizeof(storage)); |
268 | 268 |
269 buffer.setBitmapHeap(controller->getBitmapHeap()); | 269 buffer.setBitmapHeap(controller->getBitmapHeap()); |
270 buffer.setTypefaceRecorder(controller->getTypefaceSet()); | 270 buffer.setTypefaceRecorder(controller->getTypefaceSet()); |
271 buffer.setNamedFactoryRecorder(controller->getNamedFactorySet()); | 271 buffer.setNamedFactoryRecorder(controller->getNamedFactorySet()); |
272 buffer.setFlags(controller->getWriteBufferFlags()); | 272 buffer.setFlags(controller->getWriteBufferFlags()); |
273 | 273 |
274 Traits::flatten(buffer, obj); | 274 Traits::flatten(buffer, obj); |
275 uint32_t size = buffer.size(); | 275 size_t size = buffer.size(); |
276 SkASSERT(SkIsAlign4(size)); | 276 SkASSERT(SkIsAlign4(size)); |
277 | 277 |
278 // Allocate enough memory to hold SkFlatData struct and the flat data it
self. | 278 // Allocate enough memory to hold SkFlatData struct and the flat data it
self. |
279 size_t allocSize = sizeof(SkFlatData) + size; | 279 size_t allocSize = sizeof(SkFlatData) + size; |
280 SkFlatData* result = (SkFlatData*) controller->allocThrow(allocSize); | 280 SkFlatData* result = (SkFlatData*) controller->allocThrow(allocSize); |
281 | 281 |
282 // Put the serialized contents into the data section of the new allocati
on. | 282 // Put the serialized contents into the data section of the new allocati
on. |
283 buffer.writeToMemory(result->data()); | 283 buffer.writeToMemory(result->data()); |
284 // Stamp the index, size and checksum in the header. | 284 // Stamp the index, size and checksum in the header. |
285 result->stampHeader(index, size); | 285 result->stampHeader(index, SkToS32(size)); |
286 return result; | 286 return result; |
287 } | 287 } |
288 | 288 |
289 // Unflatten this into result, using bitmapHeap and facePlayback for bitmaps
and fonts if given | 289 // Unflatten this into result, using bitmapHeap and facePlayback for bitmaps
and fonts if given |
290 template <typename Traits, typename T> | 290 template <typename Traits, typename T> |
291 void unflatten(T* result, | 291 void unflatten(T* result, |
292 SkBitmapHeap* bitmapHeap = NULL, | 292 SkBitmapHeap* bitmapHeap = NULL, |
293 SkTypefacePlayback* facePlayback = NULL) const { | 293 SkTypefacePlayback* facePlayback = NULL) const { |
294 SkOrderedReadBuffer buffer(this->data(), fFlatSize); | 294 SkOrderedReadBuffer buffer(this->data(), fFlatSize); |
295 | 295 |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 } | 607 } |
608 | 608 |
609 private: | 609 private: |
610 SkChunkAlloc fHeap; | 610 SkChunkAlloc fHeap; |
611 SkAutoTUnref<SkRefCntSet> fTypefaceSet; | 611 SkAutoTUnref<SkRefCntSet> fTypefaceSet; |
612 void* fLastAllocated; | 612 void* fLastAllocated; |
613 mutable SkTypefacePlayback fTypefacePlayback; | 613 mutable SkTypefacePlayback fTypefacePlayback; |
614 }; | 614 }; |
615 | 615 |
616 #endif | 616 #endif |
OLD | NEW |