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

Side by Side Diff: src/pipe/SkGPipeWrite.cpp

Issue 1316233002: Style Change: NULL->nullptr (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-27 (Thursday) 10:25:06 EDT Created 5 years, 3 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/pipe/SkGPipeRead.cpp ('k') | src/pipe/utils/SamplePipeControllers.h » ('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 8
9 #include "SkAnnotation.h" 9 #include "SkAnnotation.h"
10 #include "SkBitmapHeap.h" 10 #include "SkBitmapHeap.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 case kColorFilter_PaintFlat: return paint.getColorFilter(); 46 case kColorFilter_PaintFlat: return paint.getColorFilter();
47 case kDrawLooper_PaintFlat: return paint.getLooper(); 47 case kDrawLooper_PaintFlat: return paint.getLooper();
48 case kMaskFilter_PaintFlat: return paint.getMaskFilter(); 48 case kMaskFilter_PaintFlat: return paint.getMaskFilter();
49 case kPathEffect_PaintFlat: return paint.getPathEffect(); 49 case kPathEffect_PaintFlat: return paint.getPathEffect();
50 case kRasterizer_PaintFlat: return paint.getRasterizer(); 50 case kRasterizer_PaintFlat: return paint.getRasterizer();
51 case kShader_PaintFlat: return paint.getShader(); 51 case kShader_PaintFlat: return paint.getShader();
52 case kImageFilter_PaintFlat: return paint.getImageFilter(); 52 case kImageFilter_PaintFlat: return paint.getImageFilter();
53 case kXfermode_PaintFlat: return paint.getXfermode(); 53 case kXfermode_PaintFlat: return paint.getXfermode();
54 } 54 }
55 SkDEBUGFAIL("never gets here"); 55 SkDEBUGFAIL("never gets here");
56 return NULL; 56 return nullptr;
57 } 57 }
58 58
59 static size_t writeTypeface(SkWriter32* writer, SkTypeface* typeface) { 59 static size_t writeTypeface(SkWriter32* writer, SkTypeface* typeface) {
60 SkASSERT(typeface); 60 SkASSERT(typeface);
61 SkDynamicMemoryWStream stream; 61 SkDynamicMemoryWStream stream;
62 typeface->serialize(&stream); 62 typeface->serialize(&stream);
63 size_t size = stream.getOffset(); 63 size_t size = stream.getOffset();
64 if (writer) { 64 if (writer) {
65 writer->write32(SkToU32(size)); 65 writer->write32(SkToU32(size));
66 SkAutoDataUnref data(stream.copyToData()); 66 SkAutoDataUnref data(stream.copyToData());
67 writer->writePad(data->data(), size); 67 writer->writePad(data->data(), size);
68 } 68 }
69 return 4 + SkAlign4(size); 69 return 4 + SkAlign4(size);
70 } 70 }
71 71
72 /////////////////////////////////////////////////////////////////////////////// 72 ///////////////////////////////////////////////////////////////////////////////
73 73
74 class FlattenableHeap : public SkFlatController { 74 class FlattenableHeap : public SkFlatController {
75 public: 75 public:
76 FlattenableHeap(int numFlatsToKeep, SkNamedFactorySet* fset, bool isCrossPro cess) 76 FlattenableHeap(int numFlatsToKeep, SkNamedFactorySet* fset, bool isCrossPro cess)
77 : INHERITED(isCrossProcess ? SkWriteBuffer::kCrossProcess_Flag : 0) 77 : INHERITED(isCrossProcess ? SkWriteBuffer::kCrossProcess_Flag : 0)
78 , fNumFlatsToKeep(numFlatsToKeep) { 78 , fNumFlatsToKeep(numFlatsToKeep) {
79 SkASSERT((isCrossProcess && fset != NULL) || (!isCrossProcess && NULL == fset)); 79 SkASSERT((isCrossProcess && fset != nullptr) || (!isCrossProcess && null ptr == fset));
80 if (isCrossProcess) { 80 if (isCrossProcess) {
81 this->setNamedFactorySet(fset); 81 this->setNamedFactorySet(fset);
82 } 82 }
83 } 83 }
84 84
85 ~FlattenableHeap() { 85 ~FlattenableHeap() {
86 fPointers.freeAll(); 86 fPointers.freeAll();
87 } 87 }
88 88
89 void* allocThrow(size_t bytes) override; 89 void* allocThrow(size_t bytes) override;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 if (potential->index() == fFlatsThatMustBeKept[j]) { 143 if (potential->index() == fFlatsThatMustBeKept[j]) {
144 mustKeep = true; 144 mustKeep = true;
145 break; 145 break;
146 } 146 }
147 } 147 }
148 if (!mustKeep) { 148 if (!mustKeep) {
149 return potential; 149 return potential;
150 } 150 }
151 } 151 }
152 } 152 }
153 return NULL; 153 return nullptr;
154 } 154 }
155 155
156 /////////////////////////////////////////////////////////////////////////////// 156 ///////////////////////////////////////////////////////////////////////////////
157 157
158 struct SkFlattenableTraits { 158 struct SkFlattenableTraits {
159 static void Flatten(SkWriteBuffer& buffer, const SkFlattenable& flattenable) { 159 static void Flatten(SkWriteBuffer& buffer, const SkFlattenable& flattenable) {
160 buffer.writeFlattenable(&flattenable); 160 buffer.writeFlattenable(&flattenable);
161 } 161 }
162 // No need to define unflatten if we never call it. 162 // No need to define unflatten if we never call it.
163 }; 163 };
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 fBitmapShuttle->removeCanvas(); 222 fBitmapShuttle->removeCanvas();
223 } 223 }
224 fDone = true; 224 fDone = true;
225 } 225 }
226 226
227 void flushRecording(bool detachCurrentBlock); 227 void flushRecording(bool detachCurrentBlock);
228 size_t freeMemoryIfPossible(size_t bytesToFree); 228 size_t freeMemoryIfPossible(size_t bytesToFree);
229 229
230 size_t storageAllocatedForRecording() { 230 size_t storageAllocatedForRecording() {
231 size_t bytesAllocated = 0; 231 size_t bytesAllocated = 0;
232 if (NULL != fBitmapHeap) { 232 if (nullptr != fBitmapHeap) {
233 bytesAllocated += fBitmapHeap->bytesAllocated(); 233 bytesAllocated += fBitmapHeap->bytesAllocated();
234 } 234 }
235 if (NULL != fImageHeap) { 235 if (nullptr != fImageHeap) {
236 bytesAllocated += fImageHeap->bytesInCache(); 236 bytesAllocated += fImageHeap->bytesInCache();
237 } 237 }
238 return bytesAllocated; 238 return bytesAllocated;
239 } 239 }
240 240
241 /** 241 /**
242 * Flatten an SkBitmap to send to the reader, where it will be referenced 242 * Flatten an SkBitmap to send to the reader, where it will be referenced
243 * according to slot. 243 * according to slot.
244 */ 244 */
245 bool shuttleBitmap(const SkBitmap&, int32_t slot); 245 bool shuttleBitmap(const SkBitmap&, int32_t slot);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 private: 368 private:
369 SkGPipeCanvas* fCanvas; 369 SkGPipeCanvas* fCanvas;
370 }; 370 };
371 friend class AutoPipeNotify; 371 friend class AutoPipeNotify;
372 372
373 typedef SkCanvas INHERITED; 373 typedef SkCanvas INHERITED;
374 }; 374 };
375 375
376 void SkGPipeCanvas::flattenFactoryNames() { 376 void SkGPipeCanvas::flattenFactoryNames() {
377 const char* name; 377 const char* name;
378 while ((name = fFactorySet->getNextAddedFactoryName()) != NULL) { 378 while ((name = fFactorySet->getNextAddedFactoryName()) != nullptr) {
379 size_t len = strlen(name); 379 size_t len = strlen(name);
380 if (this->needOpBytes(SkWriter32::WriteStringSize(name, len))) { 380 if (this->needOpBytes(SkWriter32::WriteStringSize(name, len))) {
381 this->writeOp(kDef_Factory_DrawOp); 381 this->writeOp(kDef_Factory_DrawOp);
382 fWriter.writeString(name, len); 382 fWriter.writeString(name, len);
383 } 383 }
384 } 384 }
385 } 385 }
386 386
387 bool SkGPipeCanvas::shuttleBitmap(const SkBitmap& bm, int32_t slot) { 387 bool SkGPipeCanvas::shuttleBitmap(const SkBitmap& bm, int32_t slot) {
388 SkASSERT(shouldFlattenBitmaps(fFlags)); 388 SkASSERT(shouldFlattenBitmaps(fFlags));
389 SkWriteBuffer buffer; 389 SkWriteBuffer buffer;
390 buffer.setNamedFactoryRecorder(fFactorySet); 390 buffer.setNamedFactoryRecorder(fFactorySet);
391 buffer.writeBitmap(bm); 391 buffer.writeBitmap(bm);
392 this->flattenFactoryNames(); 392 this->flattenFactoryNames();
393 size_t size = buffer.bytesWritten(); 393 size_t size = buffer.bytesWritten();
394 if (this->needOpBytes(size)) { 394 if (this->needOpBytes(size)) {
395 this->writeOp(kDef_Bitmap_DrawOp, 0, slot); 395 this->writeOp(kDef_Bitmap_DrawOp, 0, slot);
396 void* dst = static_cast<void*>(fWriter.reserve(size)); 396 void* dst = static_cast<void*>(fWriter.reserve(size));
397 buffer.writeToMemory(dst); 397 buffer.writeToMemory(dst);
398 return true; 398 return true;
399 } 399 }
400 return false; 400 return false;
401 } 401 }
402 402
403 // return 0 for NULL (or unflattenable obj), or index-base-1 403 // return 0 for nullptr (or unflattenable obj), or index-base-1
404 // return ~(index-base-1) if an old flattenable was replaced 404 // return ~(index-base-1) if an old flattenable was replaced
405 int SkGPipeCanvas::flattenToIndex(SkFlattenable* obj, PaintFlats paintflat) { 405 int SkGPipeCanvas::flattenToIndex(SkFlattenable* obj, PaintFlats paintflat) {
406 SkASSERT(!fDone && fBitmapHeap != NULL); 406 SkASSERT(!fDone && fBitmapHeap != nullptr);
407 if (NULL == obj) { 407 if (nullptr == obj) {
408 return 0; 408 return 0;
409 } 409 }
410 410
411 fBitmapHeap->deferAddingOwners(); 411 fBitmapHeap->deferAddingOwners();
412 bool added, replaced; 412 bool added, replaced;
413 const SkFlatData* flat = fFlatDictionary.findAndReplace(*obj, fFlattenableHe ap.flatToReplace(), 413 const SkFlatData* flat = fFlatDictionary.findAndReplace(*obj, fFlattenableHe ap.flatToReplace(),
414 &added, &replaced); 414 &added, &replaced);
415 fBitmapHeap->endAddingOwnersDeferral(added); 415 fBitmapHeap->endAddingOwnersDeferral(added);
416 int index = flat->index(); 416 int index = flat->index();
417 if (added) { 417 if (added) {
(...skipping 17 matching lines...) Expand all
435 #define MIN_BLOCK_SIZE (16 * 1024) 435 #define MIN_BLOCK_SIZE (16 * 1024)
436 #define BITMAPS_TO_KEEP 5 436 #define BITMAPS_TO_KEEP 5
437 #define FLATTENABLES_TO_KEEP 10 437 #define FLATTENABLES_TO_KEEP 10
438 438
439 SkGPipeCanvas::SkGPipeCanvas(SkGPipeController* controller, 439 SkGPipeCanvas::SkGPipeCanvas(SkGPipeController* controller,
440 SkWriter32* writer, 440 SkWriter32* writer,
441 uint32_t flags, 441 uint32_t flags,
442 uint32_t width, 442 uint32_t width,
443 uint32_t height) 443 uint32_t height)
444 : SkCanvas(width, height) 444 : SkCanvas(width, height)
445 , fFactorySet(is_cross_process(flags) ? new SkNamedFactorySet : NULL) 445 , fFactorySet(is_cross_process(flags) ? new SkNamedFactorySet : nullptr)
446 , fWriter(*writer) 446 , fWriter(*writer)
447 , fFlags(flags) 447 , fFlags(flags)
448 , fFlattenableHeap(FLATTENABLES_TO_KEEP, fFactorySet, is_cross_process(flags )) 448 , fFlattenableHeap(FLATTENABLES_TO_KEEP, fFactorySet, is_cross_process(flags ))
449 , fFlatDictionary(&fFlattenableHeap) { 449 , fFlatDictionary(&fFlattenableHeap) {
450 fController = controller; 450 fController = controller;
451 fDone = false; 451 fDone = false;
452 fBlockSize = 0; // need first block from controller 452 fBlockSize = 0; // need first block from controller
453 fBytesNotified = 0; 453 fBytesNotified = 0;
454 sk_bzero(fCurrFlatIndex, sizeof(fCurrFlatIndex)); 454 sk_bzero(fCurrFlatIndex, sizeof(fCurrFlatIndex));
455 455
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 needed += 4; // size of DrawOp atom 494 needed += 4; // size of DrawOp atom
495 needed = SkAlign4(needed); 495 needed = SkAlign4(needed);
496 if (fWriter.bytesWritten() + needed > fBlockSize) { 496 if (fWriter.bytesWritten() + needed > fBlockSize) {
497 // Before we wipe out any data that has already been written, read it ou t. 497 // Before we wipe out any data that has already been written, read it ou t.
498 this->doNotify(); 498 this->doNotify();
499 499
500 // If we're going to allocate a new block, allocate enough to make it wo rthwhile. 500 // If we're going to allocate a new block, allocate enough to make it wo rthwhile.
501 needed = SkTMax<size_t>(MIN_BLOCK_SIZE, needed); 501 needed = SkTMax<size_t>(MIN_BLOCK_SIZE, needed);
502 502
503 void* block = fController->requestBlock(needed, &fBlockSize); 503 void* block = fController->requestBlock(needed, &fBlockSize);
504 if (NULL == block) { 504 if (nullptr == block) {
505 // Do not notify the readers, which would call this function again. 505 // Do not notify the readers, which would call this function again.
506 this->finish(false); 506 this->finish(false);
507 return false; 507 return false;
508 } 508 }
509 SkASSERT(SkIsAlign4(fBlockSize)); 509 SkASSERT(SkIsAlign4(fBlockSize));
510 fWriter.reset(block, fBlockSize); 510 fWriter.reset(block, fBlockSize);
511 fBytesNotified = 0; 511 fBytesNotified = 0;
512 } 512 }
513 return true; 513 return true;
514 } 514 }
515 515
516 uint32_t SkGPipeCanvas::getTypefaceID(SkTypeface* face) { 516 uint32_t SkGPipeCanvas::getTypefaceID(SkTypeface* face) {
517 uint32_t id = 0; // 0 means default/null typeface 517 uint32_t id = 0; // 0 means default/null typeface
518 if (face) { 518 if (face) {
519 id = fTypefaceSet.find(face); 519 id = fTypefaceSet.find(face);
520 if (0 == id) { 520 if (0 == id) {
521 id = fTypefaceSet.add(face); 521 id = fTypefaceSet.add(face);
522 size_t size = writeTypeface(NULL, face); 522 size_t size = writeTypeface(nullptr, face);
523 if (this->needOpBytes(size)) { 523 if (this->needOpBytes(size)) {
524 this->writeOp(kDef_Typeface_DrawOp); 524 this->writeOp(kDef_Typeface_DrawOp);
525 writeTypeface(&fWriter, face); 525 writeTypeface(&fWriter, face);
526 } 526 }
527 } 527 }
528 } 528 }
529 return id; 529 return id;
530 } 530 }
531 531
532 /////////////////////////////////////////////////////////////////////////////// 532 ///////////////////////////////////////////////////////////////////////////////
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 589
590 void SkGPipeCanvas::recordScale(const SkMatrix& m) { 590 void SkGPipeCanvas::recordScale(const SkMatrix& m) {
591 if (this->needOpBytes(2 * sizeof(SkScalar))) { 591 if (this->needOpBytes(2 * sizeof(SkScalar))) {
592 this->writeOp(kScale_DrawOp); 592 this->writeOp(kScale_DrawOp);
593 fWriter.writeScalar(m.getScaleX()); 593 fWriter.writeScalar(m.getScaleX());
594 fWriter.writeScalar(m.getScaleY()); 594 fWriter.writeScalar(m.getScaleY());
595 } 595 }
596 } 596 }
597 597
598 void SkGPipeCanvas::recordConcat(const SkMatrix& m) { 598 void SkGPipeCanvas::recordConcat(const SkMatrix& m) {
599 if (this->needOpBytes(m.writeToMemory(NULL))) { 599 if (this->needOpBytes(m.writeToMemory(nullptr))) {
600 this->writeOp(kConcat_DrawOp); 600 this->writeOp(kConcat_DrawOp);
601 fWriter.writeMatrix(m); 601 fWriter.writeMatrix(m);
602 } 602 }
603 } 603 }
604 604
605 void SkGPipeCanvas::didConcat(const SkMatrix& matrix) { 605 void SkGPipeCanvas::didConcat(const SkMatrix& matrix) {
606 if (!matrix.isIdentity()) { 606 if (!matrix.isIdentity()) {
607 NOTIFY_SETUP(this); 607 NOTIFY_SETUP(this);
608 switch (matrix.getType()) { 608 switch (matrix.getType()) {
609 case SkMatrix::kTranslate_Mask: 609 case SkMatrix::kTranslate_Mask:
610 this->recordTranslate(matrix); 610 this->recordTranslate(matrix);
611 break; 611 break;
612 case SkMatrix::kScale_Mask: 612 case SkMatrix::kScale_Mask:
613 this->recordScale(matrix); 613 this->recordScale(matrix);
614 break; 614 break;
615 default: 615 default:
616 this->recordConcat(matrix); 616 this->recordConcat(matrix);
617 break; 617 break;
618 } 618 }
619 } 619 }
620 620
621 this->INHERITED::didConcat(matrix); 621 this->INHERITED::didConcat(matrix);
622 } 622 }
623 623
624 void SkGPipeCanvas::didSetMatrix(const SkMatrix& matrix) { 624 void SkGPipeCanvas::didSetMatrix(const SkMatrix& matrix) {
625 NOTIFY_SETUP(this); 625 NOTIFY_SETUP(this);
626 if (this->needOpBytes(matrix.writeToMemory(NULL))) { 626 if (this->needOpBytes(matrix.writeToMemory(nullptr))) {
627 this->writeOp(kSetMatrix_DrawOp); 627 this->writeOp(kSetMatrix_DrawOp);
628 fWriter.writeMatrix(matrix); 628 fWriter.writeMatrix(matrix);
629 } 629 }
630 this->INHERITED::didSetMatrix(matrix); 630 this->INHERITED::didSetMatrix(matrix);
631 } 631 }
632 632
633 void SkGPipeCanvas::onClipRect(const SkRect& rect, SkRegion::Op rgnOp, 633 void SkGPipeCanvas::onClipRect(const SkRect& rect, SkRegion::Op rgnOp,
634 ClipEdgeStyle edgeStyle) { 634 ClipEdgeStyle edgeStyle) {
635 NOTIFY_SETUP(this); 635 NOTIFY_SETUP(this);
636 if (this->needOpBytes(sizeof(SkRect))) { 636 if (this->needOpBytes(sizeof(SkRect))) {
(...skipping 17 matching lines...) Expand all
654 } 654 }
655 this->writeOp(kClipRRect_DrawOp, flags, rgnOp); 655 this->writeOp(kClipRRect_DrawOp, flags, rgnOp);
656 fWriter.writeRRect(rrect); 656 fWriter.writeRRect(rrect);
657 } 657 }
658 this->INHERITED::onClipRRect(rrect, rgnOp, edgeStyle); 658 this->INHERITED::onClipRRect(rrect, rgnOp, edgeStyle);
659 } 659 }
660 660
661 void SkGPipeCanvas::onClipPath(const SkPath& path, SkRegion::Op rgnOp, 661 void SkGPipeCanvas::onClipPath(const SkPath& path, SkRegion::Op rgnOp,
662 ClipEdgeStyle edgeStyle) { 662 ClipEdgeStyle edgeStyle) {
663 NOTIFY_SETUP(this); 663 NOTIFY_SETUP(this);
664 if (this->needOpBytes(path.writeToMemory(NULL))) { 664 if (this->needOpBytes(path.writeToMemory(nullptr))) {
665 unsigned flags = 0; 665 unsigned flags = 0;
666 if (kSoft_ClipEdgeStyle == edgeStyle) { 666 if (kSoft_ClipEdgeStyle == edgeStyle) {
667 flags = kClip_HasAntiAlias_DrawOpFlag; 667 flags = kClip_HasAntiAlias_DrawOpFlag;
668 } 668 }
669 this->writeOp(kClipPath_DrawOp, flags, rgnOp); 669 this->writeOp(kClipPath_DrawOp, flags, rgnOp);
670 fWriter.writePath(path); 670 fWriter.writePath(path);
671 } 671 }
672 // we just pass on the bounds of the path 672 // we just pass on the bounds of the path
673 this->INHERITED::onClipRect(path.getBounds(), rgnOp, edgeStyle); 673 this->INHERITED::onClipRect(path.getBounds(), rgnOp, edgeStyle);
674 } 674 }
675 675
676 void SkGPipeCanvas::onClipRegion(const SkRegion& region, SkRegion::Op rgnOp) { 676 void SkGPipeCanvas::onClipRegion(const SkRegion& region, SkRegion::Op rgnOp) {
677 NOTIFY_SETUP(this); 677 NOTIFY_SETUP(this);
678 if (this->needOpBytes(region.writeToMemory(NULL))) { 678 if (this->needOpBytes(region.writeToMemory(nullptr))) {
679 this->writeOp(kClipRegion_DrawOp, 0, rgnOp); 679 this->writeOp(kClipRegion_DrawOp, 0, rgnOp);
680 fWriter.writeRegion(region); 680 fWriter.writeRegion(region);
681 } 681 }
682 this->INHERITED::onClipRegion(region, rgnOp); 682 this->INHERITED::onClipRegion(region, rgnOp);
683 } 683 }
684 684
685 /////////////////////////////////////////////////////////////////////////////// 685 ///////////////////////////////////////////////////////////////////////////////
686 686
687 void SkGPipeCanvas::onDrawPaint(const SkPaint& paint) { 687 void SkGPipeCanvas::onDrawPaint(const SkPaint& paint) {
688 NOTIFY_SETUP(this); 688 NOTIFY_SETUP(this);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 if (this->needOpBytes(kSizeOfFlatRRect * 2)) { 739 if (this->needOpBytes(kSizeOfFlatRRect * 2)) {
740 this->writeOp(kDrawDRRect_DrawOp); 740 this->writeOp(kDrawDRRect_DrawOp);
741 fWriter.writeRRect(outer); 741 fWriter.writeRRect(outer);
742 fWriter.writeRRect(inner); 742 fWriter.writeRRect(inner);
743 } 743 }
744 } 744 }
745 745
746 void SkGPipeCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) { 746 void SkGPipeCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) {
747 NOTIFY_SETUP(this); 747 NOTIFY_SETUP(this);
748 this->writePaint(paint); 748 this->writePaint(paint);
749 if (this->needOpBytes(path.writeToMemory(NULL))) { 749 if (this->needOpBytes(path.writeToMemory(nullptr))) {
750 this->writeOp(kDrawPath_DrawOp); 750 this->writeOp(kDrawPath_DrawOp);
751 fWriter.writePath(path); 751 fWriter.writePath(path);
752 } 752 }
753 } 753 }
754 754
755 bool SkGPipeCanvas::commonDrawBitmap(const SkBitmap& bm, DrawOps op, 755 bool SkGPipeCanvas::commonDrawBitmap(const SkBitmap& bm, DrawOps op,
756 unsigned flags, 756 unsigned flags,
757 size_t opBytesNeeded, 757 size_t opBytesNeeded,
758 const SkPaint* paint) { 758 const SkPaint* paint) {
759 if (fDone) { 759 if (fDone) {
760 return false; 760 return false;
761 } 761 }
762 762
763 if (paint != NULL) { 763 if (paint != nullptr) {
764 flags |= kDrawBitmap_HasPaint_DrawOpFlag; 764 flags |= kDrawBitmap_HasPaint_DrawOpFlag;
765 this->writePaint(*paint); 765 this->writePaint(*paint);
766 } 766 }
767 // This needs to run first so its calls to needOpBytes() and its writes 767 // This needs to run first so its calls to needOpBytes() and its writes
768 // don't interlace with the needOpBytes() and write below. 768 // don't interlace with the needOpBytes() and write below.
769 SkASSERT(fBitmapHeap != NULL); 769 SkASSERT(fBitmapHeap != nullptr);
770 int32_t bitmapIndex = fBitmapHeap->insert(bm); 770 int32_t bitmapIndex = fBitmapHeap->insert(bm);
771 if (SkBitmapHeap::INVALID_SLOT == bitmapIndex) { 771 if (SkBitmapHeap::INVALID_SLOT == bitmapIndex) {
772 return false; 772 return false;
773 } 773 }
774 774
775 if (this->needOpBytes(opBytesNeeded)) { 775 if (this->needOpBytes(opBytesNeeded)) {
776 this->writeOp(op, flags, bitmapIndex); 776 this->writeOp(op, flags, bitmapIndex);
777 return true; 777 return true;
778 } 778 }
779 return false; 779 return false;
780 } 780 }
781 781
782 void SkGPipeCanvas::onDrawBitmap(const SkBitmap& bm, SkScalar left, SkScalar top , 782 void SkGPipeCanvas::onDrawBitmap(const SkBitmap& bm, SkScalar left, SkScalar top ,
783 const SkPaint* paint) { 783 const SkPaint* paint) {
784 NOTIFY_SETUP(this); 784 NOTIFY_SETUP(this);
785 size_t opBytesNeeded = sizeof(SkScalar) * 2; 785 size_t opBytesNeeded = sizeof(SkScalar) * 2;
786 786
787 if (this->commonDrawBitmap(bm, kDrawBitmap_DrawOp, 0, opBytesNeeded, paint)) { 787 if (this->commonDrawBitmap(bm, kDrawBitmap_DrawOp, 0, opBytesNeeded, paint)) {
788 fWriter.writeScalar(left); 788 fWriter.writeScalar(left);
789 fWriter.writeScalar(top); 789 fWriter.writeScalar(top);
790 } 790 }
791 } 791 }
792 792
793 void SkGPipeCanvas::onDrawBitmapRect(const SkBitmap& bm, const SkRect* src, cons t SkRect& dst, 793 void SkGPipeCanvas::onDrawBitmapRect(const SkBitmap& bm, const SkRect* src, cons t SkRect& dst,
794 const SkPaint* paint, SrcRectConstraint con straint) { 794 const SkPaint* paint, SrcRectConstraint con straint) {
795 NOTIFY_SETUP(this); 795 NOTIFY_SETUP(this);
796 size_t opBytesNeeded = sizeof(SkRect); 796 size_t opBytesNeeded = sizeof(SkRect);
797 bool hasSrc = src != NULL; 797 bool hasSrc = src != nullptr;
798 unsigned flags; 798 unsigned flags;
799 if (hasSrc) { 799 if (hasSrc) {
800 flags = kDrawBitmap_HasSrcRect_DrawOpFlag; 800 flags = kDrawBitmap_HasSrcRect_DrawOpFlag;
801 opBytesNeeded += sizeof(int32_t) * 4; 801 opBytesNeeded += sizeof(int32_t) * 4;
802 } else { 802 } else {
803 flags = 0; 803 flags = 0;
804 } 804 }
805 if (kFast_SrcRectConstraint == constraint) { 805 if (kFast_SrcRectConstraint == constraint) {
806 flags |= kDrawBitmap_Bleed_DrawOpFlag; 806 flags |= kDrawBitmap_Bleed_DrawOpFlag;
807 } 807 }
(...skipping 29 matching lines...) Expand all
837 fWriter.write32(top); 837 fWriter.write32(top);
838 } 838 }
839 } 839 }
840 840
841 bool SkGPipeCanvas::commonDrawImage(const SkImage* image, DrawOps op, unsigned f lags, 841 bool SkGPipeCanvas::commonDrawImage(const SkImage* image, DrawOps op, unsigned f lags,
842 size_t opBytesNeeded, const SkPaint* paint) { 842 size_t opBytesNeeded, const SkPaint* paint) {
843 if (fDone) { 843 if (fDone) {
844 return false; 844 return false;
845 } 845 }
846 846
847 if (paint != NULL) { 847 if (paint != nullptr) {
848 flags |= kDrawBitmap_HasPaint_DrawOpFlag; 848 flags |= kDrawBitmap_HasPaint_DrawOpFlag;
849 this->writePaint(*paint); 849 this->writePaint(*paint);
850 } 850 }
851 // This needs to run first so its calls to needOpBytes() and its writes 851 // This needs to run first so its calls to needOpBytes() and its writes
852 // don't interlace with the needOpBytes() and write below. 852 // don't interlace with the needOpBytes() and write below.
853 int32_t slot = fImageHeap->insert(image); 853 int32_t slot = fImageHeap->insert(image);
854 SkASSERT(slot != 0); 854 SkASSERT(slot != 0);
855 if (this->needOpBytes(opBytesNeeded)) { 855 if (this->needOpBytes(opBytesNeeded)) {
856 this->writeOp(op, flags, slot); 856 this->writeOp(op, flags, slot);
857 return true; 857 return true;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 fWriter.writeScalar(y); 909 fWriter.writeScalar(y);
910 } 910 }
911 } 911 }
912 } 912 }
913 913
914 void SkGPipeCanvas::onDrawPosText(const void* text, size_t byteLength, const SkP oint pos[], 914 void SkGPipeCanvas::onDrawPosText(const void* text, size_t byteLength, const SkP oint pos[],
915 const SkPaint& paint) { 915 const SkPaint& paint) {
916 if (byteLength) { 916 if (byteLength) {
917 NOTIFY_SETUP(this); 917 NOTIFY_SETUP(this);
918 this->writePaint(paint); 918 this->writePaint(paint);
919 int count = paint.textToGlyphs(text, byteLength, NULL); 919 int count = paint.textToGlyphs(text, byteLength, nullptr);
920 if (this->needOpBytes(4 + SkAlign4(byteLength) + 4 + count * sizeof(SkPo int))) { 920 if (this->needOpBytes(4 + SkAlign4(byteLength) + 4 + count * sizeof(SkPo int))) {
921 this->writeOp(kDrawPosText_DrawOp); 921 this->writeOp(kDrawPosText_DrawOp);
922 fWriter.write32(SkToU32(byteLength)); 922 fWriter.write32(SkToU32(byteLength));
923 fWriter.writePad(text, byteLength); 923 fWriter.writePad(text, byteLength);
924 fWriter.write32(count); 924 fWriter.write32(count);
925 fWriter.write(pos, count * sizeof(SkPoint)); 925 fWriter.write(pos, count * sizeof(SkPoint));
926 } 926 }
927 } 927 }
928 } 928 }
929 929
930 void SkGPipeCanvas::onDrawPosTextH(const void* text, size_t byteLength, const Sk Scalar xpos[], 930 void SkGPipeCanvas::onDrawPosTextH(const void* text, size_t byteLength, const Sk Scalar xpos[],
931 SkScalar constY, const SkPaint& paint) { 931 SkScalar constY, const SkPaint& paint) {
932 if (byteLength) { 932 if (byteLength) {
933 NOTIFY_SETUP(this); 933 NOTIFY_SETUP(this);
934 this->writePaint(paint); 934 this->writePaint(paint);
935 int count = paint.textToGlyphs(text, byteLength, NULL); 935 int count = paint.textToGlyphs(text, byteLength, nullptr);
936 if (this->needOpBytes(4 + SkAlign4(byteLength) + 4 + count * sizeof(SkSc alar) + 4)) { 936 if (this->needOpBytes(4 + SkAlign4(byteLength) + 4 + count * sizeof(SkSc alar) + 4)) {
937 this->writeOp(kDrawPosTextH_DrawOp); 937 this->writeOp(kDrawPosTextH_DrawOp);
938 fWriter.write32(SkToU32(byteLength)); 938 fWriter.write32(SkToU32(byteLength));
939 fWriter.writePad(text, byteLength); 939 fWriter.writePad(text, byteLength);
940 fWriter.write32(count); 940 fWriter.write32(count);
941 fWriter.write(xpos, count * sizeof(SkScalar)); 941 fWriter.write(xpos, count * sizeof(SkScalar));
942 fWriter.writeScalar(constY); 942 fWriter.writeScalar(constY);
943 } 943 }
944 } 944 }
945 } 945 }
946 946
947 void SkGPipeCanvas::onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path, 947 void SkGPipeCanvas::onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
948 const SkMatrix* matrix, const SkPaint& pain t) { 948 const SkMatrix* matrix, const SkPaint& pain t) {
949 if (byteLength) { 949 if (byteLength) {
950 NOTIFY_SETUP(this); 950 NOTIFY_SETUP(this);
951 unsigned flags = 0; 951 unsigned flags = 0;
952 size_t size = 4 + SkAlign4(byteLength) + path.writeToMemory(NULL); 952 size_t size = 4 + SkAlign4(byteLength) + path.writeToMemory(nullptr);
953 if (matrix) { 953 if (matrix) {
954 flags |= kDrawTextOnPath_HasMatrix_DrawOpFlag; 954 flags |= kDrawTextOnPath_HasMatrix_DrawOpFlag;
955 size += matrix->writeToMemory(NULL); 955 size += matrix->writeToMemory(nullptr);
956 } 956 }
957 this->writePaint(paint); 957 this->writePaint(paint);
958 if (this->needOpBytes(size)) { 958 if (this->needOpBytes(size)) {
959 this->writeOp(kDrawTextOnPath_DrawOp, flags, 0); 959 this->writeOp(kDrawTextOnPath_DrawOp, flags, 0);
960 960
961 fWriter.write32(SkToU32(byteLength)); 961 fWriter.write32(SkToU32(byteLength));
962 fWriter.writePad(text, byteLength); 962 fWriter.writePad(text, byteLength);
963 963
964 fWriter.writePath(path); 964 fWriter.writePath(path);
965 if (matrix) { 965 if (matrix) {
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1207 } 1207 }
1208 } 1208 }
1209 1209
1210 void SkGPipeCanvas::resetImageHeap() { 1210 void SkGPipeCanvas::resetImageHeap() {
1211 if (fImageHeap) { 1211 if (fImageHeap) {
1212 fImageHeap->reset(); 1212 fImageHeap->reset();
1213 } 1213 }
1214 } 1214 }
1215 1215
1216 size_t SkGPipeCanvas::freeMemoryIfPossible(size_t bytesToFree) { 1216 size_t SkGPipeCanvas::freeMemoryIfPossible(size_t bytesToFree) {
1217 return (NULL == fBitmapHeap) ? 0 : fBitmapHeap->freeMemoryIfPossible(bytesTo Free); 1217 return (nullptr == fBitmapHeap) ? 0 : fBitmapHeap->freeMemoryIfPossible(byte sToFree);
1218 } 1218 }
1219 1219
1220 /////////////////////////////////////////////////////////////////////////////// 1220 ///////////////////////////////////////////////////////////////////////////////
1221 1221
1222 template <typename T> uint32_t castToU32(T value) { 1222 template <typename T> uint32_t castToU32(T value) {
1223 union { 1223 union {
1224 T fSrc; 1224 T fSrc;
1225 uint32_t fDst; 1225 uint32_t fDst;
1226 } data; 1226 } data;
1227 data.fSrc = value; 1227 data.fSrc = value;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1340 fWriter.write(storage, size); 1340 fWriter.write(storage, size);
1341 for (size_t i = 0; i < size/4; i++) { 1341 for (size_t i = 0; i < size/4; i++) {
1342 // SkDebugf("[%d] %08X\n", i, storage[i]); 1342 // SkDebugf("[%d] %08X\n", i, storage[i]);
1343 } 1343 }
1344 } 1344 }
1345 1345
1346 // 1346 //
1347 // Do these after we've written kPaintOp_DrawOp 1347 // Do these after we've written kPaintOp_DrawOp
1348 1348
1349 if (base.getAnnotation() != paint.getAnnotation()) { 1349 if (base.getAnnotation() != paint.getAnnotation()) {
1350 if (NULL == paint.getAnnotation()) { 1350 if (nullptr == paint.getAnnotation()) {
1351 if (this->needOpBytes()) { 1351 if (this->needOpBytes()) {
1352 this->writeOp(kSetAnnotation_DrawOp, 0, 0); 1352 this->writeOp(kSetAnnotation_DrawOp, 0, 0);
1353 } 1353 }
1354 } else { 1354 } else {
1355 SkWriteBuffer buffer; 1355 SkWriteBuffer buffer;
1356 paint.getAnnotation()->writeToBuffer(buffer); 1356 paint.getAnnotation()->writeToBuffer(buffer);
1357 const size_t size = buffer.bytesWritten(); 1357 const size_t size = buffer.bytesWritten();
1358 if (this->needOpBytes(size)) { 1358 if (this->needOpBytes(size)) {
1359 this->writeOp(kSetAnnotation_DrawOp, 0, SkToU32(size)); 1359 this->writeOp(kSetAnnotation_DrawOp, 0, SkToU32(size));
1360 buffer.writeToMemory(fWriter.reserve(size)); 1360 buffer.writeToMemory(fWriter.reserve(size));
(...skipping 20 matching lines...) Expand all
1381 fCanvas->resetImageHeap(); 1381 fCanvas->resetImageHeap();
1382 // Other caches are self-purging with a small MRU pool 1382 // Other caches are self-purging with a small MRU pool
1383 // We could purge them as well, but it is not clear whether 1383 // We could purge them as well, but it is not clear whether
1384 // that would be a win. 1384 // that would be a win.
1385 } 1385 }
1386 1386
1387 /////////////////////////////////////////////////////////////////////////////// 1387 ///////////////////////////////////////////////////////////////////////////////
1388 1388
1389 SkGPipeWriter::SkGPipeWriter() 1389 SkGPipeWriter::SkGPipeWriter()
1390 : fWriter(0) { 1390 : fWriter(0) {
1391 fCanvas = NULL; 1391 fCanvas = nullptr;
1392 } 1392 }
1393 1393
1394 SkGPipeWriter::~SkGPipeWriter() { 1394 SkGPipeWriter::~SkGPipeWriter() {
1395 this->endRecording(); 1395 this->endRecording();
1396 } 1396 }
1397 1397
1398 SkCanvas* SkGPipeWriter::startRecording(SkGPipeController* controller, uint32_t flags, 1398 SkCanvas* SkGPipeWriter::startRecording(SkGPipeController* controller, uint32_t flags,
1399 uint32_t width, uint32_t height) { 1399 uint32_t width, uint32_t height) {
1400 if (NULL == fCanvas) { 1400 if (nullptr == fCanvas) {
1401 fWriter.reset(NULL, 0); 1401 fWriter.reset(nullptr, 0);
1402 fCanvas = new SkGPipeCanvas(controller, &fWriter, flags, width, height); 1402 fCanvas = new SkGPipeCanvas(controller, &fWriter, flags, width, height);
1403 } 1403 }
1404 controller->setCanvas(fCanvas); 1404 controller->setCanvas(fCanvas);
1405 return fCanvas; 1405 return fCanvas;
1406 } 1406 }
1407 1407
1408 void SkGPipeWriter::endRecording() { 1408 void SkGPipeWriter::endRecording() {
1409 if (fCanvas) { 1409 if (fCanvas) {
1410 fCanvas->finish(true); 1410 fCanvas->finish(true);
1411 fCanvas->unref(); 1411 fCanvas->unref();
1412 fCanvas = NULL; 1412 fCanvas = nullptr;
1413 } 1413 }
1414 } 1414 }
1415 1415
1416 void SkGPipeWriter::flushRecording(bool detachCurrentBlock) { 1416 void SkGPipeWriter::flushRecording(bool detachCurrentBlock) {
1417 if (fCanvas) { 1417 if (fCanvas) {
1418 fCanvas->flushRecording(detachCurrentBlock); 1418 fCanvas->flushRecording(detachCurrentBlock);
1419 } 1419 }
1420 } 1420 }
1421 1421
1422 size_t SkGPipeWriter::freeMemoryIfPossible(size_t bytesToFree) { 1422 size_t SkGPipeWriter::freeMemoryIfPossible(size_t bytesToFree) {
1423 if (fCanvas) { 1423 if (fCanvas) {
1424 return fCanvas->freeMemoryIfPossible(bytesToFree); 1424 return fCanvas->freeMemoryIfPossible(bytesToFree);
1425 } 1425 }
1426 return 0; 1426 return 0;
1427 } 1427 }
1428 1428
1429 size_t SkGPipeWriter::storageAllocatedForRecording() const { 1429 size_t SkGPipeWriter::storageAllocatedForRecording() const {
1430 return NULL == fCanvas ? 0 : fCanvas->storageAllocatedForRecording(); 1430 return nullptr == fCanvas ? 0 : fCanvas->storageAllocatedForRecording();
1431 } 1431 }
1432 1432
1433 /////////////////////////////////////////////////////////////////////////////// 1433 ///////////////////////////////////////////////////////////////////////////////
1434 1434
1435 BitmapShuttle::BitmapShuttle(SkGPipeCanvas* canvas) { 1435 BitmapShuttle::BitmapShuttle(SkGPipeCanvas* canvas) {
1436 SkASSERT(canvas != NULL); 1436 SkASSERT(canvas != nullptr);
1437 fCanvas = canvas; 1437 fCanvas = canvas;
1438 fCanvas->ref(); 1438 fCanvas->ref();
1439 } 1439 }
1440 1440
1441 BitmapShuttle::~BitmapShuttle() { 1441 BitmapShuttle::~BitmapShuttle() {
1442 this->removeCanvas(); 1442 this->removeCanvas();
1443 } 1443 }
1444 1444
1445 bool BitmapShuttle::insert(const SkBitmap& bitmap, int32_t slot) { 1445 bool BitmapShuttle::insert(const SkBitmap& bitmap, int32_t slot) {
1446 SkASSERT(fCanvas != NULL); 1446 SkASSERT(fCanvas != nullptr);
1447 return fCanvas->shuttleBitmap(bitmap, slot); 1447 return fCanvas->shuttleBitmap(bitmap, slot);
1448 } 1448 }
1449 1449
1450 void BitmapShuttle::removeCanvas() { 1450 void BitmapShuttle::removeCanvas() {
1451 if (NULL == fCanvas) { 1451 if (nullptr == fCanvas) {
1452 return; 1452 return;
1453 } 1453 }
1454 fCanvas->unref(); 1454 fCanvas->unref();
1455 fCanvas = NULL; 1455 fCanvas = nullptr;
1456 } 1456 }
1457 1457
1458 //////////////////////////////////////////////////////////////////////////////// /////////////////// 1458 //////////////////////////////////////////////////////////////////////////////// ///////////////////
1459 1459
1460 SkImageHeap::SkImageHeap() : fBytesInCache (0) {} 1460 SkImageHeap::SkImageHeap() : fBytesInCache (0) {}
1461 1461
1462 SkImageHeap::~SkImageHeap() { 1462 SkImageHeap::~SkImageHeap() {
1463 fArray.unrefAll(); 1463 fArray.unrefAll();
1464 } 1464 }
1465 1465
(...skipping 20 matching lines...) Expand all
1486 int32_t slot = this->find(img); 1486 int32_t slot = this->find(img);
1487 if (slot) { 1487 if (slot) {
1488 return slot; 1488 return slot;
1489 } 1489 }
1490 // TODO: SkImage does not expose bytes per pixel, 4 is just a best guess. 1490 // TODO: SkImage does not expose bytes per pixel, 4 is just a best guess.
1491 fBytesInCache += img->width() * img->height() * 4; 1491 fBytesInCache += img->width() * img->height() * 4;
1492 *fArray.append() = SkRef(img); 1492 *fArray.append() = SkRef(img);
1493 return fArray.count(); // slot is always index+1 1493 return fArray.count(); // slot is always index+1
1494 } 1494 }
1495 1495
OLDNEW
« no previous file with comments | « src/pipe/SkGPipeRead.cpp ('k') | src/pipe/utils/SamplePipeControllers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698