Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: src/core/SkPictureFlat.h

Issue 138803005: Set write buffer flags only in SkWriteBuffer and SkFlatController constructors. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: INHERITED Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkFlattenableSerialization.cpp ('k') | src/core/SkPictureFlat.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 // 161 //
162 // 162 //
163 /////////////////////////////////////////////////////////////////////////////// 163 ///////////////////////////////////////////////////////////////////////////////
164 164
165 class SkFlatData; 165 class SkFlatData;
166 166
167 class SkFlatController : public SkRefCnt { 167 class SkFlatController : public SkRefCnt {
168 public: 168 public:
169 SK_DECLARE_INST_COUNT(SkFlatController) 169 SK_DECLARE_INST_COUNT(SkFlatController)
170 170
171 SkFlatController(); 171 SkFlatController(uint32_t writeBufferFlags = 0);
172 virtual ~SkFlatController(); 172 virtual ~SkFlatController();
173 /** 173 /**
174 * Return a new block of memory for the SkFlatDictionary to use. 174 * Return a new block of memory for the SkFlatDictionary to use.
175 * This memory is owned by the controller and has the same lifetime unless y ou 175 * This memory is owned by the controller and has the same lifetime unless y ou
176 * call unalloc(), in which case it may be freed early. 176 * call unalloc(), in which case it may be freed early.
177 */ 177 */
178 virtual void* allocThrow(size_t bytes) = 0; 178 virtual void* allocThrow(size_t bytes) = 0;
179 179
180 /** 180 /**
181 * Hint that this block, which was allocated with allocThrow, is no longer n eeded. 181 * Hint that this block, which was allocated with allocThrow, is no longer n eeded.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 */ 235 */
236 void setTypefacePlayback(SkTypefacePlayback*); 236 void setTypefacePlayback(SkTypefacePlayback*);
237 237
238 /** 238 /**
239 * Set an SkNamedFactorySet to be used to store Factorys and their 239 * Set an SkNamedFactorySet to be used to store Factorys and their
240 * corresponding names during flattening. Ref counted. Returns the same 240 * corresponding names during flattening. Ref counted. Returns the same
241 * set as a convenience. 241 * set as a convenience.
242 */ 242 */
243 SkNamedFactorySet* setNamedFactorySet(SkNamedFactorySet*); 243 SkNamedFactorySet* setNamedFactorySet(SkNamedFactorySet*);
244 244
245 /**
246 * Set the flags to be used during flattening.
247 */
248 void setWriteBufferFlags(uint32_t flags) { fWriteBufferFlags = flags; }
249
250 private: 245 private:
251 SkBitmapHeap* fBitmapHeap; 246 SkBitmapHeap* fBitmapHeap;
252 SkRefCntSet* fTypefaceSet; 247 SkRefCntSet* fTypefaceSet;
253 SkTypefacePlayback* fTypefacePlayback; 248 SkTypefacePlayback* fTypefacePlayback;
254 SkNamedFactorySet* fFactorySet; 249 SkNamedFactorySet* fFactorySet;
255 uint32_t fWriteBufferFlags; 250 const uint32_t fWriteBufferFlags;
256 251
257 typedef SkRefCnt INHERITED; 252 typedef SkRefCnt INHERITED;
258 }; 253 };
259 254
260 class SkFlatData { 255 class SkFlatData {
261 public: 256 public:
262 // Flatten obj into an SkFlatData with this index. controller owns the SkFl atData*. 257 // Flatten obj into an SkFlatData with this index. controller owns the SkFl atData*.
263 template <typename Traits, typename T> 258 template <typename Traits, typename T>
264 static SkFlatData* Create(SkFlatController* controller, const T& obj, int in dex) { 259 static SkFlatData* Create(SkFlatController* controller, const T& obj, int in dex) {
265 // A buffer of 256 bytes should fit most paints, regions, and matrices. 260 // A buffer of 256 bytes should fit most paints, regions, and matrices.
266 uint32_t storage[64]; 261 uint32_t storage[64];
267 SkWriteBuffer buffer(storage, sizeof(storage)); 262 SkWriteBuffer buffer(storage, sizeof(storage), controller->getWriteBuffe rFlags());
268 263
269 buffer.setBitmapHeap(controller->getBitmapHeap()); 264 buffer.setBitmapHeap(controller->getBitmapHeap());
270 buffer.setTypefaceRecorder(controller->getTypefaceSet()); 265 buffer.setTypefaceRecorder(controller->getTypefaceSet());
271 buffer.setNamedFactoryRecorder(controller->getNamedFactorySet()); 266 buffer.setNamedFactoryRecorder(controller->getNamedFactorySet());
272 buffer.setFlags(controller->getWriteBufferFlags());
273 267
274 Traits::flatten(buffer, obj); 268 Traits::flatten(buffer, obj);
275 size_t size = buffer.bytesWritten(); 269 size_t size = buffer.bytesWritten();
276 SkASSERT(SkIsAlign4(size)); 270 SkASSERT(SkIsAlign4(size));
277 271
278 // Allocate enough memory to hold SkFlatData struct and the flat data it self. 272 // Allocate enough memory to hold SkFlatData struct and the flat data it self.
279 size_t allocSize = sizeof(SkFlatData) + size; 273 size_t allocSize = sizeof(SkFlatData) + size;
280 SkFlatData* result = (SkFlatData*) controller->allocThrow(allocSize); 274 SkFlatData* result = (SkFlatData*) controller->allocThrow(allocSize);
281 275
282 // Put the serialized contents into the data section of the new allocati on. 276 // Put the serialized contents into the data section of the new allocati on.
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 // uint32_t flattenedData[] implicitly hangs off the end. 354 // uint32_t flattenedData[] implicitly hangs off the end.
361 355
362 template <typename T, typename Traits> friend class SkFlatDictionary; 356 template <typename T, typename Traits> friend class SkFlatDictionary;
363 }; 357 };
364 358
365 template <typename T, typename Traits> 359 template <typename T, typename Traits>
366 class SkFlatDictionary { 360 class SkFlatDictionary {
367 public: 361 public:
368 explicit SkFlatDictionary(SkFlatController* controller) 362 explicit SkFlatDictionary(SkFlatController* controller)
369 : fController(SkRef(controller)) 363 : fController(SkRef(controller))
364 , fScratch(controller->getWriteBufferFlags())
370 , fReady(false) { 365 , fReady(false) {
371 this->reset(); 366 this->reset();
372 } 367 }
373 368
374 /** 369 /**
375 * Clears the dictionary of all entries. However, it does NOT free the 370 * Clears the dictionary of all entries. However, it does NOT free the
376 * memory that was allocated for each entry (that's owned by controller). 371 * memory that was allocated for each entry (that's owned by controller).
377 */ 372 */
378 void reset() { 373 void reset() {
379 fIndexedData.rewind(); 374 fIndexedData.rewind();
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 void lazyInit() { 484 void lazyInit() {
490 if (fReady) { 485 if (fReady) {
491 return; 486 return;
492 } 487 }
493 488
494 // Without a bitmap heap, we'll flatten bitmaps into paints. That's nev er what you want. 489 // Without a bitmap heap, we'll flatten bitmaps into paints. That's nev er what you want.
495 SkASSERT(fController->getBitmapHeap() != NULL); 490 SkASSERT(fController->getBitmapHeap() != NULL);
496 fScratch.setBitmapHeap(fController->getBitmapHeap()); 491 fScratch.setBitmapHeap(fController->getBitmapHeap());
497 fScratch.setTypefaceRecorder(fController->getTypefaceSet()); 492 fScratch.setTypefaceRecorder(fController->getTypefaceSet());
498 fScratch.setNamedFactoryRecorder(fController->getNamedFactorySet()); 493 fScratch.setNamedFactoryRecorder(fController->getNamedFactorySet());
499 fScratch.setFlags(fController->getWriteBufferFlags());
500 fReady = true; 494 fReady = true;
501 } 495 }
502 496
503 // As findAndReturnFlat, but returns a mutable pointer for internal use. 497 // As findAndReturnFlat, but returns a mutable pointer for internal use.
504 SkFlatData* findAndReturnMutableFlat(const T& element) { 498 SkFlatData* findAndReturnMutableFlat(const T& element) {
505 // Only valid until the next call to resetScratch(). 499 // Only valid until the next call to resetScratch().
506 const SkFlatData& scratch = this->resetScratch(element, this->count()+1) ; 500 const SkFlatData& scratch = this->resetScratch(element, this->count()+1) ;
507 501
508 SkFlatData* candidate = fHash.find(scratch); 502 SkFlatData* candidate = fHash.find(scratch);
509 if (candidate != NULL) return candidate; 503 if (candidate != NULL) return candidate;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 } 601 }
608 602
609 private: 603 private:
610 SkChunkAlloc fHeap; 604 SkChunkAlloc fHeap;
611 SkAutoTUnref<SkRefCntSet> fTypefaceSet; 605 SkAutoTUnref<SkRefCntSet> fTypefaceSet;
612 void* fLastAllocated; 606 void* fLastAllocated;
613 mutable SkTypefacePlayback fTypefacePlayback; 607 mutable SkTypefacePlayback fTypefacePlayback;
614 }; 608 };
615 609
616 #endif 610 #endif
OLDNEW
« no previous file with comments | « src/core/SkFlattenableSerialization.cpp ('k') | src/core/SkPictureFlat.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698