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

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

Issue 166193006: staticMethod -> StaticMethod (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 | « no previous file | src/pipe/SkGPipeWrite.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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 template <typename Traits, typename T> 258 template <typename Traits, typename T>
259 static SkFlatData* Create(SkFlatController* controller, const T& obj, int in dex) { 259 static SkFlatData* Create(SkFlatController* controller, const T& obj, int in dex) {
260 // 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.
261 uint32_t storage[64]; 261 uint32_t storage[64];
262 SkWriteBuffer buffer(storage, sizeof(storage), controller->getWriteBuffe rFlags()); 262 SkWriteBuffer buffer(storage, sizeof(storage), controller->getWriteBuffe rFlags());
263 263
264 buffer.setBitmapHeap(controller->getBitmapHeap()); 264 buffer.setBitmapHeap(controller->getBitmapHeap());
265 buffer.setTypefaceRecorder(controller->getTypefaceSet()); 265 buffer.setTypefaceRecorder(controller->getTypefaceSet());
266 buffer.setNamedFactoryRecorder(controller->getNamedFactorySet()); 266 buffer.setNamedFactoryRecorder(controller->getNamedFactorySet());
267 267
268 Traits::flatten(buffer, obj); 268 Traits::Flatten(buffer, obj);
269 size_t size = buffer.bytesWritten(); 269 size_t size = buffer.bytesWritten();
270 SkASSERT(SkIsAlign4(size)); 270 SkASSERT(SkIsAlign4(size));
271 271
272 // 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.
273 size_t allocSize = sizeof(SkFlatData) + size; 273 size_t allocSize = sizeof(SkFlatData) + size;
274 SkFlatData* result = (SkFlatData*) controller->allocThrow(allocSize); 274 SkFlatData* result = (SkFlatData*) controller->allocThrow(allocSize);
275 275
276 // 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.
277 buffer.writeToMemory(result->data()); 277 buffer.writeToMemory(result->data());
278 // Stamp the index, size and checksum in the header. 278 // Stamp the index, size and checksum in the header.
279 result->stampHeader(index, SkToS32(size)); 279 result->stampHeader(index, SkToS32(size));
280 return result; 280 return result;
281 } 281 }
282 282
283 // Unflatten this into result, using bitmapHeap and facePlayback for bitmaps and fonts if given 283 // Unflatten this into result, using bitmapHeap and facePlayback for bitmaps and fonts if given
284 template <typename Traits, typename T> 284 template <typename Traits, typename T>
285 void unflatten(T* result, 285 void unflatten(T* result,
286 SkBitmapHeap* bitmapHeap = NULL, 286 SkBitmapHeap* bitmapHeap = NULL,
287 SkTypefacePlayback* facePlayback = NULL) const { 287 SkTypefacePlayback* facePlayback = NULL) const {
288 SkReadBuffer buffer(this->data(), fFlatSize); 288 SkReadBuffer buffer(this->data(), fFlatSize);
289 289
290 if (bitmapHeap) { 290 if (bitmapHeap) {
291 buffer.setBitmapStorage(bitmapHeap); 291 buffer.setBitmapStorage(bitmapHeap);
292 } 292 }
293 if (facePlayback) { 293 if (facePlayback) {
294 facePlayback->setupBuffer(buffer); 294 facePlayback->setupBuffer(buffer);
295 } 295 }
296 296
297 Traits::unflatten(buffer, result); 297 Traits::Unflatten(buffer, result);
298 SkASSERT(fFlatSize == (int32_t)buffer.offset()); 298 SkASSERT(fFlatSize == (int32_t)buffer.offset());
299 } 299 }
300 300
301 // Do these contain the same data? Ignores index() and topBot(). 301 // Do these contain the same data? Ignores index() and topBot().
302 bool operator==(const SkFlatData& that) const { 302 bool operator==(const SkFlatData& that) const {
303 if (this->checksum() != that.checksum() || this->flatSize() != that.flat Size()) { 303 if (this->checksum() != that.checksum() || this->flatSize() != that.flat Size()) {
304 return false; 304 return false;
305 } 305 }
306 return memcmp(this->data(), that.data(), this->flatSize()) == 0; 306 return memcmp(this->data(), that.data(), this->flatSize()) == 0;
307 } 307 }
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 return detached; 509 return detached;
510 } 510 }
511 511
512 // This reference is valid only until the next call to resetScratch() or det achScratch(). 512 // This reference is valid only until the next call to resetScratch() or det achScratch().
513 const SkFlatData& resetScratch(const T& element, int index) { 513 const SkFlatData& resetScratch(const T& element, int index) {
514 this->lazyInit(); 514 this->lazyInit();
515 515
516 // Layout of fScratch: [ SkFlatData header, 20 bytes ] [ data ..., 4-byt e aligned ] 516 // Layout of fScratch: [ SkFlatData header, 20 bytes ] [ data ..., 4-byt e aligned ]
517 fScratch.reset(); 517 fScratch.reset();
518 fScratch.reserve(sizeof(SkFlatData)); 518 fScratch.reserve(sizeof(SkFlatData));
519 Traits::flatten(fScratch, element); 519 Traits::Flatten(fScratch, element);
520 const size_t dataSize = fScratch.bytesWritten() - sizeof(SkFlatData); 520 const size_t dataSize = fScratch.bytesWritten() - sizeof(SkFlatData);
521 521
522 // Reinterpret data in fScratch as an SkFlatData. 522 // Reinterpret data in fScratch as an SkFlatData.
523 SkFlatData* scratch = (SkFlatData*)fScratch.getWriter32()->contiguousArr ay(); 523 SkFlatData* scratch = (SkFlatData*)fScratch.getWriter32()->contiguousArr ay();
524 SkASSERT(scratch != NULL); 524 SkASSERT(scratch != NULL);
525 scratch->stampHeader(index, dataSize); 525 scratch->stampHeader(index, dataSize);
526 return *scratch; 526 return *scratch;
527 } 527 }
528 528
529 // This result is owned by fController and lives as long as it does (unless unalloc'd). 529 // This result is owned by fController and lives as long as it does (unless unalloc'd).
(...skipping 25 matching lines...) Expand all
555 555
556 // For index -> SkFlatData. 0-based, while all indices in the API are 1-bas ed. Careful! 556 // For index -> SkFlatData. 0-based, while all indices in the API are 1-bas ed. Careful!
557 SkTDArray<const SkFlatData*> fIndexedData; 557 SkTDArray<const SkFlatData*> fIndexedData;
558 558
559 // For SkFlatData -> cached SkFlatData, which has index(). 559 // For SkFlatData -> cached SkFlatData, which has index().
560 SkTDynamicHash<SkFlatData, SkFlatData, 560 SkTDynamicHash<SkFlatData, SkFlatData,
561 SkFlatData::Identity, SkFlatData::Hash, SkFlatData::Equal> fH ash; 561 SkFlatData::Identity, SkFlatData::Hash, SkFlatData::Equal> fH ash;
562 }; 562 };
563 563
564 struct SkPaintTraits { 564 struct SkPaintTraits {
565 static void flatten(SkWriteBuffer& buffer, const SkPaint& paint) { 565 static void Flatten(SkWriteBuffer& buffer, const SkPaint& paint) {
566 paint.flatten(buffer); 566 paint.flatten(buffer);
567 } 567 }
568 static void unflatten(SkReadBuffer& buffer, SkPaint* paint) { 568 static void Unflatten(SkReadBuffer& buffer, SkPaint* paint) {
569 paint->unflatten(buffer); 569 paint->unflatten(buffer);
570 } 570 }
571 }; 571 };
572 typedef SkFlatDictionary<SkPaint, SkPaintTraits> SkPaintDictionary; 572 typedef SkFlatDictionary<SkPaint, SkPaintTraits> SkPaintDictionary;
573 573
574 class SkChunkFlatController : public SkFlatController { 574 class SkChunkFlatController : public SkFlatController {
575 public: 575 public:
576 SkChunkFlatController(size_t minSize) 576 SkChunkFlatController(size_t minSize)
577 : fHeap(minSize) 577 : fHeap(minSize)
578 , fTypefaceSet(SkNEW(SkRefCntSet)) 578 , fTypefaceSet(SkNEW(SkRefCntSet))
(...skipping 22 matching lines...) Expand all
601 } 601 }
602 602
603 private: 603 private:
604 SkChunkAlloc fHeap; 604 SkChunkAlloc fHeap;
605 SkAutoTUnref<SkRefCntSet> fTypefaceSet; 605 SkAutoTUnref<SkRefCntSet> fTypefaceSet;
606 void* fLastAllocated; 606 void* fLastAllocated;
607 mutable SkTypefacePlayback fTypefacePlayback; 607 mutable SkTypefacePlayback fTypefacePlayback;
608 }; 608 };
609 609
610 #endif 610 #endif
OLDNEW
« no previous file with comments | « no previous file | src/pipe/SkGPipeWrite.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698