| 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 | 8 |
| 9 #include "SkAnnotation.h" | 9 #include "SkAnnotation.h" |
| 10 #include "SkBitmapDevice.h" | 10 #include "SkBitmapDevice.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "SkPathEffect.h" | 22 #include "SkPathEffect.h" |
| 23 #include "SkPictureFlat.h" | 23 #include "SkPictureFlat.h" |
| 24 #include "SkRasterizer.h" | 24 #include "SkRasterizer.h" |
| 25 #include "SkRRect.h" | 25 #include "SkRRect.h" |
| 26 #include "SkShader.h" | 26 #include "SkShader.h" |
| 27 #include "SkStream.h" | 27 #include "SkStream.h" |
| 28 #include "SkTSearch.h" | 28 #include "SkTSearch.h" |
| 29 #include "SkTypeface.h" | 29 #include "SkTypeface.h" |
| 30 #include "SkWriter32.h" | 30 #include "SkWriter32.h" |
| 31 | 31 |
| 32 #if SK_DEBUG |
| 33 // When debugging, allocate snuggly. |
| 34 static const size_t kMinBlockSize = 0; |
| 35 #else |
| 36 // For peformance, make large allocations. |
| 37 static const size_t kMinBlockSize = 16 * 1024; |
| 38 #endif |
| 39 |
| 32 enum { | 40 enum { |
| 33 kSizeOfFlatRRect = sizeof(SkRect) + 4 * sizeof(SkVector) | 41 kSizeOfFlatRRect = sizeof(SkRect) + 4 * sizeof(SkVector) |
| 34 }; | 42 }; |
| 35 | 43 |
| 36 static bool isCrossProcess(uint32_t flags) { | 44 static bool isCrossProcess(uint32_t flags) { |
| 37 return SkToBool(flags & SkGPipeWriter::kCrossProcess_Flag); | 45 return SkToBool(flags & SkGPipeWriter::kCrossProcess_Flag); |
| 38 } | 46 } |
| 39 | 47 |
| 40 static SkFlattenable* get_paintflat(const SkPaint& paint, unsigned paintFlat) { | 48 static SkFlattenable* get_paintflat(const SkPaint& paint, unsigned paintFlat) { |
| 41 SkASSERT(paintFlat < kCount_PaintFlats); | 49 SkASSERT(paintFlat < kCount_PaintFlats); |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 int flattenToIndex(SkFlattenable* obj, PaintFlats); | 351 int flattenToIndex(SkFlattenable* obj, PaintFlats); |
| 344 | 352 |
| 345 // Common code used by drawBitmap*. Behaves differently depending on the | 353 // Common code used by drawBitmap*. Behaves differently depending on the |
| 346 // type of SkBitmapHeap being used, which is determined by the flags used. | 354 // type of SkBitmapHeap being used, which is determined by the flags used. |
| 347 bool commonDrawBitmap(const SkBitmap& bm, DrawOps op, unsigned flags, | 355 bool commonDrawBitmap(const SkBitmap& bm, DrawOps op, unsigned flags, |
| 348 size_t opBytesNeeded, const SkPaint* paint); | 356 size_t opBytesNeeded, const SkPaint* paint); |
| 349 | 357 |
| 350 SkPaint fPaint; | 358 SkPaint fPaint; |
| 351 void writePaint(const SkPaint&); | 359 void writePaint(const SkPaint&); |
| 352 | 360 |
| 353 class AutoPipeNotify { | |
| 354 public: | |
| 355 AutoPipeNotify(SkGPipeCanvas* canvas) : fCanvas(canvas) {} | |
| 356 ~AutoPipeNotify() { fCanvas->doNotify(); } | |
| 357 private: | |
| 358 SkGPipeCanvas* fCanvas; | |
| 359 }; | |
| 360 friend class AutoPipeNotify; | |
| 361 | |
| 362 typedef SkCanvas INHERITED; | 361 typedef SkCanvas INHERITED; |
| 363 }; | 362 }; |
| 364 | 363 |
| 365 void SkGPipeCanvas::flattenFactoryNames() { | 364 void SkGPipeCanvas::flattenFactoryNames() { |
| 366 const char* name; | 365 const char* name; |
| 367 while ((name = fFactorySet->getNextAddedFactoryName()) != NULL) { | 366 while ((name = fFactorySet->getNextAddedFactoryName()) != NULL) { |
| 368 size_t len = strlen(name); | 367 size_t len = strlen(name); |
| 369 if (this->needOpBytes(len)) { | 368 if (this->needOpBytes(SkWriter32::WriteStringSize(name, len))) { |
| 370 this->writeOp(kDef_Factory_DrawOp); | 369 this->writeOp(kDef_Factory_DrawOp); |
| 371 fWriter.writeString(name, len); | 370 fWriter.writeString(name, len); |
| 372 } | 371 } |
| 373 } | 372 } |
| 374 } | 373 } |
| 375 | 374 |
| 376 bool SkGPipeCanvas::shuttleBitmap(const SkBitmap& bm, int32_t slot) { | 375 bool SkGPipeCanvas::shuttleBitmap(const SkBitmap& bm, int32_t slot) { |
| 377 SkASSERT(shouldFlattenBitmaps(fFlags)); | 376 SkASSERT(shouldFlattenBitmaps(fFlags)); |
| 378 SkWriteBuffer buffer; | 377 SkWriteBuffer buffer; |
| 379 buffer.setNamedFactoryRecorder(fFactorySet); | 378 buffer.setNamedFactoryRecorder(fFactorySet); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 } | 413 } |
| 415 } | 414 } |
| 416 if (replaced) { | 415 if (replaced) { |
| 417 index = ~index; | 416 index = ~index; |
| 418 } | 417 } |
| 419 return index; | 418 return index; |
| 420 } | 419 } |
| 421 | 420 |
| 422 /////////////////////////////////////////////////////////////////////////////// | 421 /////////////////////////////////////////////////////////////////////////////// |
| 423 | 422 |
| 424 #define MIN_BLOCK_SIZE (16 * 1024) | |
| 425 #define BITMAPS_TO_KEEP 5 | 423 #define BITMAPS_TO_KEEP 5 |
| 426 #define FLATTENABLES_TO_KEEP 10 | 424 #define FLATTENABLES_TO_KEEP 10 |
| 427 | 425 |
| 428 SkGPipeCanvas::SkGPipeCanvas(SkGPipeController* controller, | 426 SkGPipeCanvas::SkGPipeCanvas(SkGPipeController* controller, |
| 429 SkWriter32* writer, uint32_t flags, | 427 SkWriter32* writer, uint32_t flags, |
| 430 uint32_t width, uint32_t height) | 428 uint32_t width, uint32_t height) |
| 431 : SkCanvas(width, height) | 429 : SkCanvas(width, height) |
| 432 , fFactorySet(isCrossProcess(flags) ? SkNEW(SkNamedFactorySet) : NULL) | 430 , fFactorySet(isCrossProcess(flags) ? SkNEW(SkNamedFactorySet) : NULL) |
| 433 , fWriter(*writer) | 431 , fWriter(*writer) |
| 434 , fFlags(flags) | 432 , fFlags(flags) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 452 fBitmapHeap = SkNEW_ARGS(SkBitmapHeap, (fBitmapShuttle.get(), BITMAPS_TO
_KEEP)); | 450 fBitmapHeap = SkNEW_ARGS(SkBitmapHeap, (fBitmapShuttle.get(), BITMAPS_TO
_KEEP)); |
| 453 } else { | 451 } else { |
| 454 fBitmapHeap = SkNEW_ARGS(SkBitmapHeap, | 452 fBitmapHeap = SkNEW_ARGS(SkBitmapHeap, |
| 455 (BITMAPS_TO_KEEP, controller->numberOfReaders()
)); | 453 (BITMAPS_TO_KEEP, controller->numberOfReaders()
)); |
| 456 if (this->needOpBytes(sizeof(void*))) { | 454 if (this->needOpBytes(sizeof(void*))) { |
| 457 this->writeOp(kShareBitmapHeap_DrawOp); | 455 this->writeOp(kShareBitmapHeap_DrawOp); |
| 458 fWriter.writePtr(static_cast<void*>(fBitmapHeap)); | 456 fWriter.writePtr(static_cast<void*>(fBitmapHeap)); |
| 459 } | 457 } |
| 460 } | 458 } |
| 461 fFlattenableHeap.setBitmapStorage(fBitmapHeap); | 459 fFlattenableHeap.setBitmapStorage(fBitmapHeap); |
| 462 this->doNotify(); | |
| 463 } | 460 } |
| 464 | 461 |
| 465 SkGPipeCanvas::~SkGPipeCanvas() { | 462 SkGPipeCanvas::~SkGPipeCanvas() { |
| 466 this->finish(true); | 463 this->finish(true); |
| 467 SkSafeUnref(fFactorySet); | 464 SkSafeUnref(fFactorySet); |
| 468 SkSafeUnref(fBitmapHeap); | 465 SkSafeUnref(fBitmapHeap); |
| 469 } | 466 } |
| 470 | 467 |
| 471 bool SkGPipeCanvas::needOpBytes(size_t needed) { | 468 bool SkGPipeCanvas::needOpBytes(size_t needed) { |
| 472 if (fDone) { | 469 if (fDone) { |
| 473 return false; | 470 return false; |
| 474 } | 471 } |
| 475 | 472 |
| 476 needed += 4; // size of DrawOp atom | 473 needed += 4; // size of DrawOp atom |
| 474 needed = SkTMax(kMinBlockSize, needed); |
| 475 needed = SkAlign4(needed); |
| 477 if (fWriter.bytesWritten() + needed > fBlockSize) { | 476 if (fWriter.bytesWritten() + needed > fBlockSize) { |
| 478 // Before we wipe out any data that has already been written, read it | 477 // We're making a new block. First push out the current block. |
| 479 // out. | |
| 480 this->doNotify(); | 478 this->doNotify(); |
| 481 size_t blockSize = SkTMax<size_t>(MIN_BLOCK_SIZE, needed); | 479 |
| 482 void* block = fController->requestBlock(blockSize, &fBlockSize); | 480 void* block = fController->requestBlock(needed, &fBlockSize); |
| 483 if (NULL == block) { | 481 if (NULL == block) { |
| 484 // Do not notify the readers, which would call this function again. | 482 // Do not notify the readers, which would call this function again. |
| 485 this->finish(false); | 483 this->finish(false); |
| 486 return false; | 484 return false; |
| 487 } | 485 } |
| 488 SkASSERT(SkIsAlign4(fBlockSize)); | 486 SkASSERT(SkIsAlign4(fBlockSize)); |
| 489 fWriter.reset(block, fBlockSize); | 487 fWriter.reset(block, fBlockSize); |
| 490 fBytesNotified = 0; | 488 fBytesNotified = 0; |
| 491 } | 489 } |
| 492 return true; | 490 return true; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 503 this->writeOp(kDef_Typeface_DrawOp); | 501 this->writeOp(kDef_Typeface_DrawOp); |
| 504 writeTypeface(&fWriter, face); | 502 writeTypeface(&fWriter, face); |
| 505 } | 503 } |
| 506 } | 504 } |
| 507 } | 505 } |
| 508 return id; | 506 return id; |
| 509 } | 507 } |
| 510 | 508 |
| 511 /////////////////////////////////////////////////////////////////////////////// | 509 /////////////////////////////////////////////////////////////////////////////// |
| 512 | 510 |
| 513 #define NOTIFY_SETUP(canvas) \ | |
| 514 AutoPipeNotify apn(canvas) | |
| 515 | |
| 516 void SkGPipeCanvas::willSave(SaveFlags flags) { | 511 void SkGPipeCanvas::willSave(SaveFlags flags) { |
| 517 NOTIFY_SETUP(this); | |
| 518 if (this->needOpBytes()) { | 512 if (this->needOpBytes()) { |
| 519 this->writeOp(kSave_DrawOp, 0, flags); | 513 this->writeOp(kSave_DrawOp, 0, flags); |
| 520 } | 514 } |
| 521 | 515 |
| 522 this->INHERITED::willSave(flags); | 516 this->INHERITED::willSave(flags); |
| 523 } | 517 } |
| 524 | 518 |
| 525 SkCanvas::SaveLayerStrategy SkGPipeCanvas::willSaveLayer(const SkRect* bounds, c
onst SkPaint* paint, | 519 SkCanvas::SaveLayerStrategy SkGPipeCanvas::willSaveLayer(const SkRect* bounds, c
onst SkPaint* paint, |
| 526 SaveFlags saveFlags) { | 520 SaveFlags saveFlags) { |
| 527 NOTIFY_SETUP(this); | |
| 528 size_t size = 0; | 521 size_t size = 0; |
| 529 unsigned opFlags = 0; | 522 unsigned opFlags = 0; |
| 530 | 523 |
| 531 if (bounds) { | 524 if (bounds) { |
| 532 opFlags |= kSaveLayer_HasBounds_DrawOpFlag; | 525 opFlags |= kSaveLayer_HasBounds_DrawOpFlag; |
| 533 size += sizeof(SkRect); | 526 size += sizeof(SkRect); |
| 534 } | 527 } |
| 535 if (paint) { | 528 if (paint) { |
| 536 opFlags |= kSaveLayer_HasPaint_DrawOpFlag; | 529 opFlags |= kSaveLayer_HasPaint_DrawOpFlag; |
| 537 this->writePaint(*paint); | 530 this->writePaint(*paint); |
| 538 } | 531 } |
| 539 | 532 |
| 540 if (this->needOpBytes(size)) { | 533 if (this->needOpBytes(size)) { |
| 541 this->writeOp(kSaveLayer_DrawOp, opFlags, saveFlags); | 534 this->writeOp(kSaveLayer_DrawOp, opFlags, saveFlags); |
| 542 if (bounds) { | 535 if (bounds) { |
| 543 fWriter.writeRect(*bounds); | 536 fWriter.writeRect(*bounds); |
| 544 } | 537 } |
| 545 } | 538 } |
| 546 | 539 |
| 547 if (kNoSaveLayer == fFirstSaveLayerStackLevel){ | 540 if (kNoSaveLayer == fFirstSaveLayerStackLevel){ |
| 548 fFirstSaveLayerStackLevel = this->getSaveCount(); | 541 fFirstSaveLayerStackLevel = this->getSaveCount(); |
| 549 } | 542 } |
| 550 | 543 |
| 551 this->INHERITED::willSaveLayer(bounds, paint, saveFlags); | 544 this->INHERITED::willSaveLayer(bounds, paint, saveFlags); |
| 552 // we don't create a layer | 545 // we don't create a layer |
| 553 return kNoLayer_SaveLayerStrategy; | 546 return kNoLayer_SaveLayerStrategy; |
| 554 } | 547 } |
| 555 | 548 |
| 556 void SkGPipeCanvas::willRestore() { | 549 void SkGPipeCanvas::willRestore() { |
| 557 NOTIFY_SETUP(this); | |
| 558 if (this->needOpBytes()) { | 550 if (this->needOpBytes()) { |
| 559 this->writeOp(kRestore_DrawOp); | 551 this->writeOp(kRestore_DrawOp); |
| 560 } | 552 } |
| 561 | 553 |
| 562 if (this->getSaveCount() - 1 == fFirstSaveLayerStackLevel){ | 554 if (this->getSaveCount() - 1 == fFirstSaveLayerStackLevel){ |
| 563 fFirstSaveLayerStackLevel = kNoSaveLayer; | 555 fFirstSaveLayerStackLevel = kNoSaveLayer; |
| 564 } | 556 } |
| 565 | 557 |
| 566 this->INHERITED::willRestore(); | 558 this->INHERITED::willRestore(); |
| 567 } | 559 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 588 | 580 |
| 589 void SkGPipeCanvas::recordConcat(const SkMatrix& m) { | 581 void SkGPipeCanvas::recordConcat(const SkMatrix& m) { |
| 590 if (this->needOpBytes(m.writeToMemory(NULL))) { | 582 if (this->needOpBytes(m.writeToMemory(NULL))) { |
| 591 this->writeOp(kConcat_DrawOp); | 583 this->writeOp(kConcat_DrawOp); |
| 592 fWriter.writeMatrix(m); | 584 fWriter.writeMatrix(m); |
| 593 } | 585 } |
| 594 } | 586 } |
| 595 | 587 |
| 596 void SkGPipeCanvas::didConcat(const SkMatrix& matrix) { | 588 void SkGPipeCanvas::didConcat(const SkMatrix& matrix) { |
| 597 if (!matrix.isIdentity()) { | 589 if (!matrix.isIdentity()) { |
| 598 NOTIFY_SETUP(this); | |
| 599 switch (matrix.getType()) { | 590 switch (matrix.getType()) { |
| 600 case SkMatrix::kTranslate_Mask: | 591 case SkMatrix::kTranslate_Mask: |
| 601 this->recordTranslate(matrix); | 592 this->recordTranslate(matrix); |
| 602 break; | 593 break; |
| 603 case SkMatrix::kScale_Mask: | 594 case SkMatrix::kScale_Mask: |
| 604 this->recordScale(matrix); | 595 this->recordScale(matrix); |
| 605 break; | 596 break; |
| 606 default: | 597 default: |
| 607 this->recordConcat(matrix); | 598 this->recordConcat(matrix); |
| 608 break; | 599 break; |
| 609 } | 600 } |
| 610 } | 601 } |
| 611 | 602 |
| 612 this->INHERITED::didConcat(matrix); | 603 this->INHERITED::didConcat(matrix); |
| 613 } | 604 } |
| 614 | 605 |
| 615 void SkGPipeCanvas::didSetMatrix(const SkMatrix& matrix) { | 606 void SkGPipeCanvas::didSetMatrix(const SkMatrix& matrix) { |
| 616 NOTIFY_SETUP(this); | |
| 617 if (this->needOpBytes(matrix.writeToMemory(NULL))) { | 607 if (this->needOpBytes(matrix.writeToMemory(NULL))) { |
| 618 this->writeOp(kSetMatrix_DrawOp); | 608 this->writeOp(kSetMatrix_DrawOp); |
| 619 fWriter.writeMatrix(matrix); | 609 fWriter.writeMatrix(matrix); |
| 620 } | 610 } |
| 621 this->INHERITED::didSetMatrix(matrix); | 611 this->INHERITED::didSetMatrix(matrix); |
| 622 } | 612 } |
| 623 | 613 |
| 624 void SkGPipeCanvas::onClipRect(const SkRect& rect, SkRegion::Op rgnOp, | 614 void SkGPipeCanvas::onClipRect(const SkRect& rect, SkRegion::Op rgnOp, |
| 625 ClipEdgeStyle edgeStyle) { | 615 ClipEdgeStyle edgeStyle) { |
| 626 NOTIFY_SETUP(this); | |
| 627 if (this->needOpBytes(sizeof(SkRect))) { | 616 if (this->needOpBytes(sizeof(SkRect))) { |
| 628 unsigned flags = 0; | 617 unsigned flags = 0; |
| 629 if (kSoft_ClipEdgeStyle == edgeStyle) { | 618 if (kSoft_ClipEdgeStyle == edgeStyle) { |
| 630 flags = kClip_HasAntiAlias_DrawOpFlag; | 619 flags = kClip_HasAntiAlias_DrawOpFlag; |
| 631 } | 620 } |
| 632 this->writeOp(kClipRect_DrawOp, flags, rgnOp); | 621 this->writeOp(kClipRect_DrawOp, flags, rgnOp); |
| 633 fWriter.writeRect(rect); | 622 fWriter.writeRect(rect); |
| 634 } | 623 } |
| 635 this->INHERITED::onClipRect(rect, rgnOp, edgeStyle); | 624 this->INHERITED::onClipRect(rect, rgnOp, edgeStyle); |
| 636 } | 625 } |
| 637 | 626 |
| 638 void SkGPipeCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op rgnOp, | 627 void SkGPipeCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op rgnOp, |
| 639 ClipEdgeStyle edgeStyle) { | 628 ClipEdgeStyle edgeStyle) { |
| 640 NOTIFY_SETUP(this); | |
| 641 if (this->needOpBytes(kSizeOfFlatRRect)) { | 629 if (this->needOpBytes(kSizeOfFlatRRect)) { |
| 642 unsigned flags = 0; | 630 unsigned flags = 0; |
| 643 if (kSoft_ClipEdgeStyle == edgeStyle) { | 631 if (kSoft_ClipEdgeStyle == edgeStyle) { |
| 644 flags = kClip_HasAntiAlias_DrawOpFlag; | 632 flags = kClip_HasAntiAlias_DrawOpFlag; |
| 645 } | 633 } |
| 646 this->writeOp(kClipRRect_DrawOp, flags, rgnOp); | 634 this->writeOp(kClipRRect_DrawOp, flags, rgnOp); |
| 647 fWriter.writeRRect(rrect); | 635 fWriter.writeRRect(rrect); |
| 648 } | 636 } |
| 649 this->INHERITED::onClipRRect(rrect, rgnOp, edgeStyle); | 637 this->INHERITED::onClipRRect(rrect, rgnOp, edgeStyle); |
| 650 } | 638 } |
| 651 | 639 |
| 652 void SkGPipeCanvas::onClipPath(const SkPath& path, SkRegion::Op rgnOp, | 640 void SkGPipeCanvas::onClipPath(const SkPath& path, SkRegion::Op rgnOp, |
| 653 ClipEdgeStyle edgeStyle) { | 641 ClipEdgeStyle edgeStyle) { |
| 654 NOTIFY_SETUP(this); | |
| 655 if (this->needOpBytes(path.writeToMemory(NULL))) { | 642 if (this->needOpBytes(path.writeToMemory(NULL))) { |
| 656 unsigned flags = 0; | 643 unsigned flags = 0; |
| 657 if (kSoft_ClipEdgeStyle == edgeStyle) { | 644 if (kSoft_ClipEdgeStyle == edgeStyle) { |
| 658 flags = kClip_HasAntiAlias_DrawOpFlag; | 645 flags = kClip_HasAntiAlias_DrawOpFlag; |
| 659 } | 646 } |
| 660 this->writeOp(kClipPath_DrawOp, flags, rgnOp); | 647 this->writeOp(kClipPath_DrawOp, flags, rgnOp); |
| 661 fWriter.writePath(path); | 648 fWriter.writePath(path); |
| 662 } | 649 } |
| 663 // we just pass on the bounds of the path | 650 // we just pass on the bounds of the path |
| 664 this->INHERITED::onClipRect(path.getBounds(), rgnOp, edgeStyle); | 651 this->INHERITED::onClipRect(path.getBounds(), rgnOp, edgeStyle); |
| 665 } | 652 } |
| 666 | 653 |
| 667 void SkGPipeCanvas::onClipRegion(const SkRegion& region, SkRegion::Op rgnOp) { | 654 void SkGPipeCanvas::onClipRegion(const SkRegion& region, SkRegion::Op rgnOp) { |
| 668 NOTIFY_SETUP(this); | |
| 669 if (this->needOpBytes(region.writeToMemory(NULL))) { | 655 if (this->needOpBytes(region.writeToMemory(NULL))) { |
| 670 this->writeOp(kClipRegion_DrawOp, 0, rgnOp); | 656 this->writeOp(kClipRegion_DrawOp, 0, rgnOp); |
| 671 fWriter.writeRegion(region); | 657 fWriter.writeRegion(region); |
| 672 } | 658 } |
| 673 this->INHERITED::onClipRegion(region, rgnOp); | 659 this->INHERITED::onClipRegion(region, rgnOp); |
| 674 } | 660 } |
| 675 | 661 |
| 676 /////////////////////////////////////////////////////////////////////////////// | 662 /////////////////////////////////////////////////////////////////////////////// |
| 677 | 663 |
| 678 void SkGPipeCanvas::clear(SkColor color) { | 664 void SkGPipeCanvas::clear(SkColor color) { |
| 679 NOTIFY_SETUP(this); | |
| 680 unsigned flags = 0; | 665 unsigned flags = 0; |
| 681 if (color) { | 666 if (color) { |
| 682 flags |= kClear_HasColor_DrawOpFlag; | 667 flags |= kClear_HasColor_DrawOpFlag; |
| 683 } | 668 } |
| 684 if (this->needOpBytes(sizeof(SkColor))) { | 669 if (this->needOpBytes(sizeof(SkColor))) { |
| 685 this->writeOp(kDrawClear_DrawOp, flags, 0); | 670 this->writeOp(kDrawClear_DrawOp, flags, 0); |
| 686 if (color) { | 671 if (color) { |
| 687 fWriter.write32(color); | 672 fWriter.write32(color); |
| 688 } | 673 } |
| 689 } | 674 } |
| 690 } | 675 } |
| 691 | 676 |
| 692 void SkGPipeCanvas::drawPaint(const SkPaint& paint) { | 677 void SkGPipeCanvas::drawPaint(const SkPaint& paint) { |
| 693 NOTIFY_SETUP(this); | |
| 694 this->writePaint(paint); | 678 this->writePaint(paint); |
| 695 if (this->needOpBytes()) { | 679 if (this->needOpBytes()) { |
| 696 this->writeOp(kDrawPaint_DrawOp); | 680 this->writeOp(kDrawPaint_DrawOp); |
| 697 } | 681 } |
| 698 } | 682 } |
| 699 | 683 |
| 700 void SkGPipeCanvas::drawPoints(PointMode mode, size_t count, | 684 void SkGPipeCanvas::drawPoints(PointMode mode, size_t count, |
| 701 const SkPoint pts[], const SkPaint& paint) { | 685 const SkPoint pts[], const SkPaint& paint) { |
| 702 if (count) { | 686 if (count) { |
| 703 NOTIFY_SETUP(this); | |
| 704 this->writePaint(paint); | 687 this->writePaint(paint); |
| 705 if (this->needOpBytes(4 + count * sizeof(SkPoint))) { | 688 if (this->needOpBytes(4 + count * sizeof(SkPoint))) { |
| 706 this->writeOp(kDrawPoints_DrawOp, mode, 0); | 689 this->writeOp(kDrawPoints_DrawOp, mode, 0); |
| 707 fWriter.write32(SkToU32(count)); | 690 fWriter.write32(SkToU32(count)); |
| 708 fWriter.write(pts, count * sizeof(SkPoint)); | 691 fWriter.write(pts, count * sizeof(SkPoint)); |
| 709 } | 692 } |
| 710 } | 693 } |
| 711 } | 694 } |
| 712 | 695 |
| 713 void SkGPipeCanvas::drawOval(const SkRect& rect, const SkPaint& paint) { | 696 void SkGPipeCanvas::drawOval(const SkRect& rect, const SkPaint& paint) { |
| 714 NOTIFY_SETUP(this); | |
| 715 this->writePaint(paint); | 697 this->writePaint(paint); |
| 716 if (this->needOpBytes(sizeof(SkRect))) { | 698 if (this->needOpBytes(sizeof(SkRect))) { |
| 717 this->writeOp(kDrawOval_DrawOp); | 699 this->writeOp(kDrawOval_DrawOp); |
| 718 fWriter.writeRect(rect); | 700 fWriter.writeRect(rect); |
| 719 } | 701 } |
| 720 } | 702 } |
| 721 | 703 |
| 722 void SkGPipeCanvas::drawRect(const SkRect& rect, const SkPaint& paint) { | 704 void SkGPipeCanvas::drawRect(const SkRect& rect, const SkPaint& paint) { |
| 723 NOTIFY_SETUP(this); | |
| 724 this->writePaint(paint); | 705 this->writePaint(paint); |
| 725 if (this->needOpBytes(sizeof(SkRect))) { | 706 if (this->needOpBytes(sizeof(SkRect))) { |
| 726 this->writeOp(kDrawRect_DrawOp); | 707 this->writeOp(kDrawRect_DrawOp); |
| 727 fWriter.writeRect(rect); | 708 fWriter.writeRect(rect); |
| 728 } | 709 } |
| 729 } | 710 } |
| 730 | 711 |
| 731 void SkGPipeCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) { | 712 void SkGPipeCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) { |
| 732 NOTIFY_SETUP(this); | |
| 733 this->writePaint(paint); | 713 this->writePaint(paint); |
| 734 if (this->needOpBytes(kSizeOfFlatRRect)) { | 714 if (this->needOpBytes(kSizeOfFlatRRect)) { |
| 735 this->writeOp(kDrawRRect_DrawOp); | 715 this->writeOp(kDrawRRect_DrawOp); |
| 736 fWriter.writeRRect(rrect); | 716 fWriter.writeRRect(rrect); |
| 737 } | 717 } |
| 738 } | 718 } |
| 739 | 719 |
| 740 void SkGPipeCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, | 720 void SkGPipeCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, |
| 741 const SkPaint& paint) { | 721 const SkPaint& paint) { |
| 742 NOTIFY_SETUP(this); | |
| 743 this->writePaint(paint); | 722 this->writePaint(paint); |
| 744 if (this->needOpBytes(kSizeOfFlatRRect * 2)) { | 723 if (this->needOpBytes(kSizeOfFlatRRect * 2)) { |
| 745 this->writeOp(kDrawDRRect_DrawOp); | 724 this->writeOp(kDrawDRRect_DrawOp); |
| 746 fWriter.writeRRect(outer); | 725 fWriter.writeRRect(outer); |
| 747 fWriter.writeRRect(inner); | 726 fWriter.writeRRect(inner); |
| 748 } | 727 } |
| 749 } | 728 } |
| 750 | 729 |
| 751 void SkGPipeCanvas::drawPath(const SkPath& path, const SkPaint& paint) { | 730 void SkGPipeCanvas::drawPath(const SkPath& path, const SkPaint& paint) { |
| 752 NOTIFY_SETUP(this); | |
| 753 this->writePaint(paint); | 731 this->writePaint(paint); |
| 754 if (this->needOpBytes(path.writeToMemory(NULL))) { | 732 if (this->needOpBytes(path.writeToMemory(NULL))) { |
| 755 this->writeOp(kDrawPath_DrawOp); | 733 this->writeOp(kDrawPath_DrawOp); |
| 756 fWriter.writePath(path); | 734 fWriter.writePath(path); |
| 757 } | 735 } |
| 758 } | 736 } |
| 759 | 737 |
| 760 bool SkGPipeCanvas::commonDrawBitmap(const SkBitmap& bm, DrawOps op, | 738 bool SkGPipeCanvas::commonDrawBitmap(const SkBitmap& bm, DrawOps op, |
| 761 unsigned flags, | 739 unsigned flags, |
| 762 size_t opBytesNeeded, | 740 size_t opBytesNeeded, |
| 763 const SkPaint* paint) { | 741 const SkPaint* paint) { |
| 742 if (fDone) { |
| 743 return false; |
| 744 } |
| 745 |
| 764 if (paint != NULL) { | 746 if (paint != NULL) { |
| 765 flags |= kDrawBitmap_HasPaint_DrawOpFlag; | 747 flags |= kDrawBitmap_HasPaint_DrawOpFlag; |
| 766 this->writePaint(*paint); | 748 this->writePaint(*paint); |
| 767 } | 749 } |
| 750 |
| 751 // This needs to run first so its calls to needOpBytes() and writes |
| 752 // don't interlace with the needOpBytes() and writes below. |
| 753 SkASSERT(fBitmapHeap != NULL); |
| 754 int32_t bitmapIndex = fBitmapHeap->insert(bm); |
| 755 if (SkBitmapHeap::INVALID_SLOT == bitmapIndex) { |
| 756 return false; |
| 757 } |
| 758 |
| 768 if (this->needOpBytes(opBytesNeeded)) { | 759 if (this->needOpBytes(opBytesNeeded)) { |
| 769 SkASSERT(fBitmapHeap != NULL); | |
| 770 int32_t bitmapIndex = fBitmapHeap->insert(bm); | |
| 771 if (SkBitmapHeap::INVALID_SLOT == bitmapIndex) { | |
| 772 return false; | |
| 773 } | |
| 774 this->writeOp(op, flags, bitmapIndex); | 760 this->writeOp(op, flags, bitmapIndex); |
| 775 return true; | 761 return true; |
| 776 } | 762 } |
| 777 return false; | 763 return false; |
| 778 } | 764 } |
| 779 | 765 |
| 780 void SkGPipeCanvas::drawBitmap(const SkBitmap& bm, SkScalar left, SkScalar top, | 766 void SkGPipeCanvas::drawBitmap(const SkBitmap& bm, SkScalar left, SkScalar top, |
| 781 const SkPaint* paint) { | 767 const SkPaint* paint) { |
| 782 NOTIFY_SETUP(this); | |
| 783 size_t opBytesNeeded = sizeof(SkScalar) * 2; | 768 size_t opBytesNeeded = sizeof(SkScalar) * 2; |
| 784 | 769 |
| 785 if (this->commonDrawBitmap(bm, kDrawBitmap_DrawOp, 0, opBytesNeeded, paint))
{ | 770 if (this->commonDrawBitmap(bm, kDrawBitmap_DrawOp, 0, opBytesNeeded, paint))
{ |
| 786 fWriter.writeScalar(left); | 771 fWriter.writeScalar(left); |
| 787 fWriter.writeScalar(top); | 772 fWriter.writeScalar(top); |
| 788 } | 773 } |
| 789 } | 774 } |
| 790 | 775 |
| 791 void SkGPipeCanvas::drawBitmapRectToRect(const SkBitmap& bm, const SkRect* src, | 776 void SkGPipeCanvas::drawBitmapRectToRect(const SkBitmap& bm, const SkRect* src, |
| 792 const SkRect& dst, const SkPaint* paint
, | 777 const SkRect& dst, const SkPaint* paint
, |
| 793 DrawBitmapRectFlags dbmrFlags) { | 778 DrawBitmapRectFlags dbmrFlags) { |
| 794 NOTIFY_SETUP(this); | |
| 795 size_t opBytesNeeded = sizeof(SkRect); | 779 size_t opBytesNeeded = sizeof(SkRect); |
| 796 bool hasSrc = src != NULL; | 780 bool hasSrc = src != NULL; |
| 797 unsigned flags; | 781 unsigned flags; |
| 798 if (hasSrc) { | 782 if (hasSrc) { |
| 799 flags = kDrawBitmap_HasSrcRect_DrawOpFlag; | 783 flags = kDrawBitmap_HasSrcRect_DrawOpFlag; |
| 800 opBytesNeeded += sizeof(int32_t) * 4; | 784 opBytesNeeded += sizeof(int32_t) * 4; |
| 801 } else { | 785 } else { |
| 802 flags = 0; | 786 flags = 0; |
| 803 } | 787 } |
| 804 if (dbmrFlags & kBleed_DrawBitmapRectFlag) { | 788 if (dbmrFlags & kBleed_DrawBitmapRectFlag) { |
| 805 flags |= kDrawBitmap_Bleed_DrawOpFlag; | 789 flags |= kDrawBitmap_Bleed_DrawOpFlag; |
| 806 } | 790 } |
| 807 | 791 |
| 808 if (this->commonDrawBitmap(bm, kDrawBitmapRectToRect_DrawOp, flags, opBytesN
eeded, paint)) { | 792 if (this->commonDrawBitmap(bm, kDrawBitmapRectToRect_DrawOp, flags, opBytesN
eeded, paint)) { |
| 809 if (hasSrc) { | 793 if (hasSrc) { |
| 810 fWriter.writeRect(*src); | 794 fWriter.writeRect(*src); |
| 811 } | 795 } |
| 812 fWriter.writeRect(dst); | 796 fWriter.writeRect(dst); |
| 813 } | 797 } |
| 814 } | 798 } |
| 815 | 799 |
| 816 void SkGPipeCanvas::drawBitmapMatrix(const SkBitmap& bm, const SkMatrix& matrix, | 800 void SkGPipeCanvas::drawBitmapMatrix(const SkBitmap& bm, const SkMatrix& matrix, |
| 817 const SkPaint* paint) { | 801 const SkPaint* paint) { |
| 818 NOTIFY_SETUP(this); | |
| 819 size_t opBytesNeeded = matrix.writeToMemory(NULL); | 802 size_t opBytesNeeded = matrix.writeToMemory(NULL); |
| 820 | 803 |
| 821 if (this->commonDrawBitmap(bm, kDrawBitmapMatrix_DrawOp, 0, opBytesNeeded, p
aint)) { | 804 if (this->commonDrawBitmap(bm, kDrawBitmapMatrix_DrawOp, 0, opBytesNeeded, p
aint)) { |
| 822 fWriter.writeMatrix(matrix); | 805 fWriter.writeMatrix(matrix); |
| 823 } | 806 } |
| 824 } | 807 } |
| 825 | 808 |
| 826 void SkGPipeCanvas::drawBitmapNine(const SkBitmap& bm, const SkIRect& center, | 809 void SkGPipeCanvas::drawBitmapNine(const SkBitmap& bm, const SkIRect& center, |
| 827 const SkRect& dst, const SkPaint* paint) { | 810 const SkRect& dst, const SkPaint* paint) { |
| 828 NOTIFY_SETUP(this); | |
| 829 size_t opBytesNeeded = sizeof(int32_t) * 4 + sizeof(SkRect); | 811 size_t opBytesNeeded = sizeof(int32_t) * 4 + sizeof(SkRect); |
| 830 | 812 |
| 831 if (this->commonDrawBitmap(bm, kDrawBitmapNine_DrawOp, 0, opBytesNeeded, pai
nt)) { | 813 if (this->commonDrawBitmap(bm, kDrawBitmapNine_DrawOp, 0, opBytesNeeded, pai
nt)) { |
| 832 fWriter.write32(center.fLeft); | 814 fWriter.write32(center.fLeft); |
| 833 fWriter.write32(center.fTop); | 815 fWriter.write32(center.fTop); |
| 834 fWriter.write32(center.fRight); | 816 fWriter.write32(center.fRight); |
| 835 fWriter.write32(center.fBottom); | 817 fWriter.write32(center.fBottom); |
| 836 fWriter.writeRect(dst); | 818 fWriter.writeRect(dst); |
| 837 } | 819 } |
| 838 } | 820 } |
| 839 | 821 |
| 840 void SkGPipeCanvas::drawSprite(const SkBitmap& bm, int left, int top, | 822 void SkGPipeCanvas::drawSprite(const SkBitmap& bm, int left, int top, |
| 841 const SkPaint* paint) { | 823 const SkPaint* paint) { |
| 842 NOTIFY_SETUP(this); | |
| 843 size_t opBytesNeeded = sizeof(int32_t) * 2; | 824 size_t opBytesNeeded = sizeof(int32_t) * 2; |
| 844 | 825 |
| 845 if (this->commonDrawBitmap(bm, kDrawSprite_DrawOp, 0, opBytesNeeded, paint))
{ | 826 if (this->commonDrawBitmap(bm, kDrawSprite_DrawOp, 0, opBytesNeeded, paint))
{ |
| 846 fWriter.write32(left); | 827 fWriter.write32(left); |
| 847 fWriter.write32(top); | 828 fWriter.write32(top); |
| 848 } | 829 } |
| 849 } | 830 } |
| 850 | 831 |
| 851 void SkGPipeCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x,
SkScalar y, | 832 void SkGPipeCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x,
SkScalar y, |
| 852 const SkPaint& paint) { | 833 const SkPaint& paint) { |
| 853 if (byteLength) { | 834 if (byteLength) { |
| 854 NOTIFY_SETUP(this); | |
| 855 this->writePaint(paint); | 835 this->writePaint(paint); |
| 856 if (this->needOpBytes(4 + SkAlign4(byteLength) + 2 * sizeof(SkScalar)))
{ | 836 if (this->needOpBytes(4 + SkAlign4(byteLength) + 2 * sizeof(SkScalar)))
{ |
| 857 this->writeOp(kDrawText_DrawOp); | 837 this->writeOp(kDrawText_DrawOp); |
| 858 fWriter.write32(SkToU32(byteLength)); | 838 fWriter.write32(SkToU32(byteLength)); |
| 859 fWriter.writePad(text, byteLength); | 839 fWriter.writePad(text, byteLength); |
| 860 fWriter.writeScalar(x); | 840 fWriter.writeScalar(x); |
| 861 fWriter.writeScalar(y); | 841 fWriter.writeScalar(y); |
| 862 } | 842 } |
| 863 } | 843 } |
| 864 } | 844 } |
| 865 | 845 |
| 866 void SkGPipeCanvas::onDrawPosText(const void* text, size_t byteLength, const SkP
oint pos[], | 846 void SkGPipeCanvas::onDrawPosText(const void* text, size_t byteLength, const SkP
oint pos[], |
| 867 const SkPaint& paint) { | 847 const SkPaint& paint) { |
| 868 if (byteLength) { | 848 if (byteLength) { |
| 869 NOTIFY_SETUP(this); | |
| 870 this->writePaint(paint); | 849 this->writePaint(paint); |
| 871 int count = paint.textToGlyphs(text, byteLength, NULL); | 850 int count = paint.textToGlyphs(text, byteLength, NULL); |
| 872 if (this->needOpBytes(4 + SkAlign4(byteLength) + 4 + count * sizeof(SkPo
int))) { | 851 if (this->needOpBytes(4 + SkAlign4(byteLength) + 4 + count * sizeof(SkPo
int))) { |
| 873 this->writeOp(kDrawPosText_DrawOp); | 852 this->writeOp(kDrawPosText_DrawOp); |
| 874 fWriter.write32(SkToU32(byteLength)); | 853 fWriter.write32(SkToU32(byteLength)); |
| 875 fWriter.writePad(text, byteLength); | 854 fWriter.writePad(text, byteLength); |
| 876 fWriter.write32(count); | 855 fWriter.write32(count); |
| 877 fWriter.write(pos, count * sizeof(SkPoint)); | 856 fWriter.write(pos, count * sizeof(SkPoint)); |
| 878 } | 857 } |
| 879 } | 858 } |
| 880 } | 859 } |
| 881 | 860 |
| 882 void SkGPipeCanvas::onDrawPosTextH(const void* text, size_t byteLength, const Sk
Scalar xpos[], | 861 void SkGPipeCanvas::onDrawPosTextH(const void* text, size_t byteLength, const Sk
Scalar xpos[], |
| 883 SkScalar constY, const SkPaint& paint) { | 862 SkScalar constY, const SkPaint& paint) { |
| 884 if (byteLength) { | 863 if (byteLength) { |
| 885 NOTIFY_SETUP(this); | |
| 886 this->writePaint(paint); | 864 this->writePaint(paint); |
| 887 int count = paint.textToGlyphs(text, byteLength, NULL); | 865 int count = paint.textToGlyphs(text, byteLength, NULL); |
| 888 if (this->needOpBytes(4 + SkAlign4(byteLength) + 4 + count * sizeof(SkSc
alar) + 4)) { | 866 if (this->needOpBytes(4 + SkAlign4(byteLength) + 4 + count * sizeof(SkSc
alar) + 4)) { |
| 889 this->writeOp(kDrawPosTextH_DrawOp); | 867 this->writeOp(kDrawPosTextH_DrawOp); |
| 890 fWriter.write32(SkToU32(byteLength)); | 868 fWriter.write32(SkToU32(byteLength)); |
| 891 fWriter.writePad(text, byteLength); | 869 fWriter.writePad(text, byteLength); |
| 892 fWriter.write32(count); | 870 fWriter.write32(count); |
| 893 fWriter.write(xpos, count * sizeof(SkScalar)); | 871 fWriter.write(xpos, count * sizeof(SkScalar)); |
| 894 fWriter.writeScalar(constY); | 872 fWriter.writeScalar(constY); |
| 895 } | 873 } |
| 896 } | 874 } |
| 897 } | 875 } |
| 898 | 876 |
| 899 void SkGPipeCanvas::onDrawTextOnPath(const void* text, size_t byteLength, const
SkPath& path, | 877 void SkGPipeCanvas::onDrawTextOnPath(const void* text, size_t byteLength, const
SkPath& path, |
| 900 const SkMatrix* matrix, const SkPaint& pain
t) { | 878 const SkMatrix* matrix, const SkPaint& pain
t) { |
| 901 if (byteLength) { | 879 if (byteLength) { |
| 902 NOTIFY_SETUP(this); | |
| 903 unsigned flags = 0; | 880 unsigned flags = 0; |
| 904 size_t size = 4 + SkAlign4(byteLength) + path.writeToMemory(NULL); | 881 size_t size = 4 + SkAlign4(byteLength) + path.writeToMemory(NULL); |
| 905 if (matrix) { | 882 if (matrix) { |
| 906 flags |= kDrawTextOnPath_HasMatrix_DrawOpFlag; | 883 flags |= kDrawTextOnPath_HasMatrix_DrawOpFlag; |
| 907 size += matrix->writeToMemory(NULL); | 884 size += matrix->writeToMemory(NULL); |
| 908 } | 885 } |
| 909 this->writePaint(paint); | 886 this->writePaint(paint); |
| 910 if (this->needOpBytes(size)) { | 887 if (this->needOpBytes(size)) { |
| 911 this->writeOp(kDrawTextOnPath_DrawOp, flags, 0); | 888 this->writeOp(kDrawTextOnPath_DrawOp, flags, 0); |
| 912 | 889 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 928 | 905 |
| 929 void SkGPipeCanvas::drawVertices(VertexMode vmode, int vertexCount, | 906 void SkGPipeCanvas::drawVertices(VertexMode vmode, int vertexCount, |
| 930 const SkPoint vertices[], const SkPoint texs[], | 907 const SkPoint vertices[], const SkPoint texs[], |
| 931 const SkColor colors[], SkXfermode* xfer, | 908 const SkColor colors[], SkXfermode* xfer, |
| 932 const uint16_t indices[], int indexCount, | 909 const uint16_t indices[], int indexCount, |
| 933 const SkPaint& paint) { | 910 const SkPaint& paint) { |
| 934 if (0 == vertexCount) { | 911 if (0 == vertexCount) { |
| 935 return; | 912 return; |
| 936 } | 913 } |
| 937 | 914 |
| 938 NOTIFY_SETUP(this); | |
| 939 size_t size = 4 + vertexCount * sizeof(SkPoint); | |
| 940 this->writePaint(paint); | 915 this->writePaint(paint); |
| 941 unsigned flags = 0; | 916 |
| 917 unsigned flags = 0; // flags pack with the op, so don't need extra space th
emselves |
| 918 |
| 919 size_t size = 0; |
| 920 size += 4; // vmode |
| 921 size += 4; // vertexCount |
| 922 size += vertexCount * sizeof(SkPoint); // vertices |
| 942 if (texs) { | 923 if (texs) { |
| 943 flags |= kDrawVertices_HasTexs_DrawOpFlag; | 924 flags |= kDrawVertices_HasTexs_DrawOpFlag; |
| 944 size += vertexCount * sizeof(SkPoint); | 925 size += vertexCount * sizeof(SkPoint); |
| 945 } | 926 } |
| 946 if (colors) { | 927 if (colors) { |
| 947 flags |= kDrawVertices_HasColors_DrawOpFlag; | 928 flags |= kDrawVertices_HasColors_DrawOpFlag; |
| 948 size += vertexCount * sizeof(SkColor); | 929 size += vertexCount * sizeof(SkColor); |
| 949 } | 930 } |
| 931 if (xfer && !SkXfermode::IsMode(xfer, SkXfermode::kModulate_Mode)) { |
| 932 flags |= kDrawVertices_HasXfermode_DrawOpFlag; |
| 933 size += sizeof(int32_t); // SkXfermode::Mode |
| 934 } |
| 950 if (indices && indexCount > 0) { | 935 if (indices && indexCount > 0) { |
| 951 flags |= kDrawVertices_HasIndices_DrawOpFlag; | 936 flags |= kDrawVertices_HasIndices_DrawOpFlag; |
| 952 size += 4 + SkAlign4(indexCount * sizeof(uint16_t)); | 937 size += 4; // indexCount |
| 953 } | 938 size += SkAlign4(indexCount * sizeof(uint16_t)); // indices |
| 954 if (xfer && !SkXfermode::IsMode(xfer, SkXfermode::kModulate_Mode)) { | |
| 955 flags |= kDrawVertices_HasXfermode_DrawOpFlag; | |
| 956 size += sizeof(int32_t); // mode enum | |
| 957 } | 939 } |
| 958 | 940 |
| 959 if (this->needOpBytes(size)) { | 941 if (this->needOpBytes(size)) { |
| 960 this->writeOp(kDrawVertices_DrawOp, flags, 0); | 942 this->writeOp(kDrawVertices_DrawOp, flags, 0); |
| 961 fWriter.write32(vmode); | 943 fWriter.write32(vmode); |
| 962 fWriter.write32(vertexCount); | 944 fWriter.write32(vertexCount); |
| 963 fWriter.write(vertices, vertexCount * sizeof(SkPoint)); | 945 fWriter.write(vertices, vertexCount * sizeof(SkPoint)); |
| 964 if (texs) { | 946 if (flags & kDrawVertices_HasTexs_DrawOpFlag) { |
| 965 fWriter.write(texs, vertexCount * sizeof(SkPoint)); | 947 fWriter.write(texs, vertexCount * sizeof(SkPoint)); |
| 966 } | 948 } |
| 967 if (colors) { | 949 if (flags & kDrawVertices_HasColors_DrawOpFlag) { |
| 968 fWriter.write(colors, vertexCount * sizeof(SkColor)); | 950 fWriter.write(colors, vertexCount * sizeof(SkColor)); |
| 969 } | 951 } |
| 970 if (flags & kDrawVertices_HasXfermode_DrawOpFlag) { | 952 if (flags & kDrawVertices_HasXfermode_DrawOpFlag) { |
| 971 SkXfermode::Mode mode = SkXfermode::kModulate_Mode; | 953 SkXfermode::Mode mode = SkXfermode::kModulate_Mode; |
| 972 (void)xfer->asMode(&mode); | 954 SkAssertResult(xfer->asMode(&mode)); |
| 973 fWriter.write32(mode); | 955 fWriter.write32(mode); |
| 974 } | 956 } |
| 975 if (indices && indexCount > 0) { | 957 if (flags & kDrawVertices_HasIndices_DrawOpFlag) { |
| 976 fWriter.write32(indexCount); | 958 fWriter.write32(indexCount); |
| 977 fWriter.writePad(indices, indexCount * sizeof(uint16_t)); | 959 fWriter.writePad(indices, indexCount * sizeof(uint16_t)); |
| 978 } | 960 } |
| 979 } | 961 } |
| 980 } | 962 } |
| 981 | 963 |
| 982 void SkGPipeCanvas::drawData(const void* ptr, size_t size) { | 964 void SkGPipeCanvas::drawData(const void* ptr, size_t size) { |
| 983 if (size && ptr) { | 965 if (size && ptr) { |
| 984 NOTIFY_SETUP(this); | |
| 985 unsigned data = 0; | 966 unsigned data = 0; |
| 986 if (size < (1 << DRAWOPS_DATA_BITS)) { | 967 if (size < (1 << DRAWOPS_DATA_BITS)) { |
| 987 data = (unsigned)size; | 968 data = (unsigned)size; |
| 988 } | 969 } |
| 989 if (this->needOpBytes(4 + SkAlign4(size))) { | 970 if (this->needOpBytes(4 + SkAlign4(size))) { |
| 990 this->writeOp(kDrawData_DrawOp, 0, data); | 971 this->writeOp(kDrawData_DrawOp, 0, data); |
| 991 if (0 == data) { | 972 if (0 == data) { |
| 992 fWriter.write32(SkToU32(size)); | 973 fWriter.write32(SkToU32(size)); |
| 993 } | 974 } |
| 994 fWriter.writePad(ptr, size); | 975 fWriter.writePad(ptr, size); |
| 995 } | 976 } |
| 996 } | 977 } |
| 997 } | 978 } |
| 998 | 979 |
| 999 void SkGPipeCanvas::beginCommentGroup(const char* description) { | 980 void SkGPipeCanvas::beginCommentGroup(const char* description) { |
| 1000 // ignore for now | 981 // ignore for now |
| 1001 } | 982 } |
| 1002 | 983 |
| 1003 void SkGPipeCanvas::addComment(const char* kywd, const char* value) { | 984 void SkGPipeCanvas::addComment(const char* kywd, const char* value) { |
| 1004 // ignore for now | 985 // ignore for now |
| 1005 } | 986 } |
| 1006 | 987 |
| 1007 void SkGPipeCanvas::endCommentGroup() { | 988 void SkGPipeCanvas::endCommentGroup() { |
| 1008 // ignore for now | 989 // ignore for now |
| 1009 } | 990 } |
| 1010 | 991 |
| 1011 void SkGPipeCanvas::flushRecording(bool detachCurrentBlock) { | 992 void SkGPipeCanvas::flushRecording(bool detachCurrentBlock) { |
| 1012 doNotify(); | 993 this->doNotify(); |
| 1013 if (detachCurrentBlock) { | 994 if (detachCurrentBlock) { |
| 1014 // force a new block to be requested for the next recorded command | 995 // force a new block to be requested for the next recorded command |
| 1015 fBlockSize = 0; | 996 fBlockSize = 0; |
| 1016 } | 997 } |
| 1017 } | 998 } |
| 1018 | 999 |
| 1019 size_t SkGPipeCanvas::freeMemoryIfPossible(size_t bytesToFree) { | 1000 size_t SkGPipeCanvas::freeMemoryIfPossible(size_t bytesToFree) { |
| 1020 return (NULL == fBitmapHeap) ? 0 : fBitmapHeap->freeMemoryIfPossible(bytesTo
Free); | 1001 return (NULL == fBitmapHeap) ? 0 : fBitmapHeap->freeMemoryIfPossible(bytesTo
Free); |
| 1021 } | 1002 } |
| 1022 | 1003 |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1242 return fCanvas->shuttleBitmap(bitmap, slot); | 1223 return fCanvas->shuttleBitmap(bitmap, slot); |
| 1243 } | 1224 } |
| 1244 | 1225 |
| 1245 void BitmapShuttle::removeCanvas() { | 1226 void BitmapShuttle::removeCanvas() { |
| 1246 if (NULL == fCanvas) { | 1227 if (NULL == fCanvas) { |
| 1247 return; | 1228 return; |
| 1248 } | 1229 } |
| 1249 fCanvas->unref(); | 1230 fCanvas->unref(); |
| 1250 fCanvas = NULL; | 1231 fCanvas = NULL; |
| 1251 } | 1232 } |
| 1233 |
| OLD | NEW |