OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 #ifndef SkPictureFlat_DEFINED | 7 #ifndef SkPictureFlat_DEFINED |
8 #define SkPictureFlat_DEFINED | 8 #define SkPictureFlat_DEFINED |
9 | 9 |
10 | 10 |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 SkRefCntSet* getTypefaceSet() { return fTypefaceSet; } | 223 SkRefCntSet* getTypefaceSet() { return fTypefaceSet; } |
224 | 224 |
225 /** | 225 /** |
226 * Used during unflattening of the SkFlatData objects in the | 226 * Used during unflattening of the SkFlatData objects in the |
227 * SkFlatDictionary. Needs to be set by the protected setTypefacePlayback | 227 * SkFlatDictionary. Needs to be set by the protected setTypefacePlayback |
228 * and needs to be reset to the SkRefCntSet passed to setTypefaceSet. | 228 * and needs to be reset to the SkRefCntSet passed to setTypefaceSet. |
229 */ | 229 */ |
230 SkTypefacePlayback* getTypefacePlayback() { return fTypefacePlayback; } | 230 SkTypefacePlayback* getTypefacePlayback() { return fTypefacePlayback; } |
231 | 231 |
232 /** | 232 /** |
233 * Optional factory recorder used during creation of SkFlatData objects. Set | |
234 * using the protected method setNamedFactorySet. | |
235 */ | |
236 SkNamedFactorySet* getNamedFactorySet() { return fFactorySet; } | |
237 | |
238 /** | |
239 * Flags to use during creation of SkFlatData objects. Defaults to zero. | 233 * Flags to use during creation of SkFlatData objects. Defaults to zero. |
240 */ | 234 */ |
241 uint32_t getWriteBufferFlags() { return fWriteBufferFlags; } | 235 uint32_t getWriteBufferFlags() { return fWriteBufferFlags; } |
242 | 236 |
243 protected: | 237 protected: |
244 /** | 238 /** |
245 * Set an SkBitmapHeap to be used to store/read SkBitmaps. Ref counted. | 239 * Set an SkBitmapHeap to be used to store/read SkBitmaps. Ref counted. |
246 */ | 240 */ |
247 void setBitmapHeap(SkBitmapHeap*); | 241 void setBitmapHeap(SkBitmapHeap*); |
248 | 242 |
249 /** | 243 /** |
250 * Set an SkRefCntSet to be used to store SkTypefaces during flattening. Ref | 244 * Set an SkRefCntSet to be used to store SkTypefaces during flattening. Ref |
251 * counted. | 245 * counted. |
252 */ | 246 */ |
253 void setTypefaceSet(SkRefCntSet*); | 247 void setTypefaceSet(SkRefCntSet*); |
254 | 248 |
255 /** | 249 /** |
256 * Set an SkTypefacePlayback to be used to find references to SkTypefaces | 250 * Set an SkTypefacePlayback to be used to find references to SkTypefaces |
257 * during unflattening. Should be reset to the set provided to | 251 * during unflattening. Should be reset to the set provided to |
258 * setTypefaceSet. | 252 * setTypefaceSet. |
259 */ | 253 */ |
260 void setTypefacePlayback(SkTypefacePlayback*); | 254 void setTypefacePlayback(SkTypefacePlayback*); |
261 | 255 |
262 /** | |
263 * Set an SkNamedFactorySet to be used to store Factorys and their | |
264 * corresponding names during flattening. Ref counted. Returns the same | |
265 * set as a convenience. | |
266 */ | |
267 SkNamedFactorySet* setNamedFactorySet(SkNamedFactorySet*); | |
268 | |
269 private: | 256 private: |
270 SkBitmapHeap* fBitmapHeap; | 257 SkBitmapHeap* fBitmapHeap; |
271 SkRefCntSet* fTypefaceSet; | 258 SkRefCntSet* fTypefaceSet; |
272 SkTypefacePlayback* fTypefacePlayback; | 259 SkTypefacePlayback* fTypefacePlayback; |
273 SkNamedFactorySet* fFactorySet; | |
274 const uint32_t fWriteBufferFlags; | 260 const uint32_t fWriteBufferFlags; |
275 | 261 |
276 typedef SkRefCnt INHERITED; | 262 typedef SkRefCnt INHERITED; |
277 }; | 263 }; |
278 | 264 |
279 class SkFlatData { | 265 class SkFlatData { |
280 public: | 266 public: |
281 // Flatten obj into an SkFlatData with this index. controller owns the SkFl atData*. | 267 // Flatten obj into an SkFlatData with this index. controller owns the SkFl atData*. |
282 template <typename Traits, typename T> | 268 template <typename Traits, typename T> |
283 static SkFlatData* Create(SkFlatController* controller, const T& obj, int in dex) { | 269 static SkFlatData* Create(SkFlatController* controller, const T& obj, int in dex) { |
284 // A buffer of 256 bytes should fit most paints, regions, and matrices. | 270 // A buffer of 256 bytes should fit most paints, regions, and matrices. |
285 uint32_t storage[64]; | 271 uint32_t storage[64]; |
286 SkWriteBuffer buffer(storage, sizeof(storage), controller->getWriteBuffe rFlags()); | 272 SkWriteBuffer buffer(storage, sizeof(storage), controller->getWriteBuffe rFlags()); |
287 | 273 |
288 buffer.setBitmapHeap(controller->getBitmapHeap()); | 274 buffer.setBitmapHeap(controller->getBitmapHeap()); |
289 buffer.setTypefaceRecorder(controller->getTypefaceSet()); | 275 buffer.setTypefaceRecorder(controller->getTypefaceSet()); |
290 buffer.setNamedFactoryRecorder(controller->getNamedFactorySet()); | |
mtklein
2016/04/19 14:06:39
Walk me through how it's unused again? It looks l
msarett
2016/04/19 14:13:29
It's never set on the SkFlatController - so this c
mtklein
2016/04/19 14:18:36
Ah, brilliant!
| |
291 | 276 |
292 Traits::Flatten(buffer, obj); | 277 Traits::Flatten(buffer, obj); |
293 size_t size = buffer.bytesWritten(); | 278 size_t size = buffer.bytesWritten(); |
294 SkASSERT(SkIsAlign4(size)); | 279 SkASSERT(SkIsAlign4(size)); |
295 | 280 |
296 // Allocate enough memory to hold SkFlatData struct and the flat data it self. | 281 // Allocate enough memory to hold SkFlatData struct and the flat data it self. |
297 size_t allocSize = sizeof(SkFlatData) + size; | 282 size_t allocSize = sizeof(SkFlatData) + size; |
298 SkFlatData* result = (SkFlatData*) controller->allocThrow(allocSize); | 283 SkFlatData* result = (SkFlatData*) controller->allocThrow(allocSize); |
299 | 284 |
300 // Put the serialized contents into the data section of the new allocati on. | 285 // Put the serialized contents into the data section of the new allocati on. |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
491 // be fully set up by the time we get it in the constructor. | 476 // be fully set up by the time we get it in the constructor. |
492 void lazyInit() { | 477 void lazyInit() { |
493 if (fReady) { | 478 if (fReady) { |
494 return; | 479 return; |
495 } | 480 } |
496 | 481 |
497 // Without a bitmap heap, we'll flatten bitmaps into paints. That's nev er what you want. | 482 // Without a bitmap heap, we'll flatten bitmaps into paints. That's nev er what you want. |
498 SkASSERT(fController->getBitmapHeap() != nullptr); | 483 SkASSERT(fController->getBitmapHeap() != nullptr); |
499 fScratch.setBitmapHeap(fController->getBitmapHeap()); | 484 fScratch.setBitmapHeap(fController->getBitmapHeap()); |
500 fScratch.setTypefaceRecorder(fController->getTypefaceSet()); | 485 fScratch.setTypefaceRecorder(fController->getTypefaceSet()); |
501 fScratch.setNamedFactoryRecorder(fController->getNamedFactorySet()); | |
502 fReady = true; | 486 fReady = true; |
503 } | 487 } |
504 | 488 |
505 // As findAndReturnFlat, but returns a mutable pointer for internal use. | 489 // As findAndReturnFlat, but returns a mutable pointer for internal use. |
506 SkFlatData* findAndReturnMutableFlat(const T& element) { | 490 SkFlatData* findAndReturnMutableFlat(const T& element) { |
507 // Only valid until the next call to resetScratch(). | 491 // Only valid until the next call to resetScratch(). |
508 const SkFlatData& scratch = this->resetScratch(element, this->count()+1) ; | 492 const SkFlatData& scratch = this->resetScratch(element, this->count()+1) ; |
509 | 493 |
510 SkFlatData* candidate = fHash.find(scratch); | 494 SkFlatData* candidate = fHash.find(scratch); |
511 if (candidate != nullptr) { | 495 if (candidate != nullptr) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
564 bool fReady; | 548 bool fReady; |
565 | 549 |
566 // For index -> SkFlatData. 0-based, while all indices in the API are 1-bas ed. Careful! | 550 // For index -> SkFlatData. 0-based, while all indices in the API are 1-bas ed. Careful! |
567 SkTDArray<const SkFlatData*> fIndexedData; | 551 SkTDArray<const SkFlatData*> fIndexedData; |
568 | 552 |
569 // For SkFlatData -> cached SkFlatData, which has index(). | 553 // For SkFlatData -> cached SkFlatData, which has index(). |
570 SkTDynamicHash<SkFlatData, SkFlatData, SkFlatData::HashTraits> fHash; | 554 SkTDynamicHash<SkFlatData, SkFlatData, SkFlatData::HashTraits> fHash; |
571 }; | 555 }; |
572 | 556 |
573 #endif | 557 #endif |
OLD | NEW |