OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2008 The Android Open Source Project | 2 * Copyright 2008 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkBitmapDevice.h" | 8 #include "SkBitmapDevice.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkCanvasPriv.h" | 10 #include "SkCanvasPriv.h" |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
620 fCachedLocalClipBoundsDirty = true; | 620 fCachedLocalClipBoundsDirty = true; |
621 fClipStack->reset(); | 621 fClipStack->reset(); |
622 fMCRec->reset(bounds); | 622 fMCRec->reset(bounds); |
623 | 623 |
624 // We're peering through a lot of structs here. Only at this scope do we | 624 // We're peering through a lot of structs here. Only at this scope do we |
625 // know that the device is an SkBitmapDevice (really an SkNoPixelsBitmapDevi ce). | 625 // know that the device is an SkBitmapDevice (really an SkNoPixelsBitmapDevi ce). |
626 static_cast<SkBitmapDevice*>(fMCRec->fLayer->fDevice)->setNewSize(bounds.siz e()); | 626 static_cast<SkBitmapDevice*>(fMCRec->fLayer->fDevice)->setNewSize(bounds.siz e()); |
627 } | 627 } |
628 | 628 |
629 SkBaseDevice* SkCanvas::init(SkBaseDevice* device, InitFlags flags) { | 629 SkBaseDevice* SkCanvas::init(SkBaseDevice* device, InitFlags flags) { |
630 fConservativeRasterClip = SkToBool(flags & kConservativeRasterClip_InitFlag) ; | 630 if (device && device->forceConservativeRasterClip()) { |
631 flags = InitFlags(flags | kConservativeRasterClip_InitFlag); | |
632 } | |
robertphillips
2015/11/20 19:45:47
Why don't we just do this inside the above else:
reed1
2015/11/20 20:46:34
doesn't seem smaller or clearer (to me) since it p
| |
633 // Since init() is only called once by our constructors, it is safe to perfo rm this | |
634 // const-cast. | |
635 *const_cast<bool*>(&fConservativeRasterClip) = SkToBool(flags & kConservativ eRasterClip_InitFlag); | |
636 | |
631 fCachedLocalClipBounds.setEmpty(); | 637 fCachedLocalClipBounds.setEmpty(); |
632 fCachedLocalClipBoundsDirty = true; | 638 fCachedLocalClipBoundsDirty = true; |
633 fAllowSoftClip = true; | 639 fAllowSoftClip = true; |
634 fAllowSimplifyClip = false; | 640 fAllowSimplifyClip = false; |
635 fDeviceCMDirty = true; | 641 fDeviceCMDirty = true; |
636 fSaveCount = 1; | 642 fSaveCount = 1; |
637 fMetaData = nullptr; | 643 fMetaData = nullptr; |
638 | 644 |
639 fClipStack.reset(new SkClipStack); | 645 fClipStack.reset(new SkClipStack); |
640 | 646 |
641 fMCRec = (MCRec*)fMCStack.push_back(); | 647 fMCRec = (MCRec*)fMCStack.push_back(); |
642 new (fMCRec) MCRec(fConservativeRasterClip); | 648 new (fMCRec) MCRec(fConservativeRasterClip); |
643 | 649 |
644 SkASSERT(sizeof(DeviceCM) <= sizeof(fDeviceCMStorage)); | 650 SkASSERT(sizeof(DeviceCM) <= sizeof(fDeviceCMStorage)); |
645 fMCRec->fLayer = (DeviceCM*)fDeviceCMStorage; | 651 fMCRec->fLayer = (DeviceCM*)fDeviceCMStorage; |
646 new (fDeviceCMStorage) DeviceCM(nullptr, nullptr, nullptr, fConservativeRast erClip, false); | 652 new (fDeviceCMStorage) DeviceCM(nullptr, nullptr, nullptr, fConservativeRast erClip, false); |
647 | 653 |
648 fMCRec->fTopLayer = fMCRec->fLayer; | 654 fMCRec->fTopLayer = fMCRec->fLayer; |
649 | 655 |
650 fSurfaceBase = nullptr; | 656 fSurfaceBase = nullptr; |
651 | 657 |
652 if (device) { | 658 if (device) { |
653 // The root device and the canvas should always have the same pixel geom etry | 659 // The root device and the canvas should always have the same pixel geom etry |
654 SkASSERT(fProps.pixelGeometry() == device->surfaceProps().pixelGeometry( )); | 660 SkASSERT(fProps.pixelGeometry() == device->surfaceProps().pixelGeometry( )); |
655 if (device->forceConservativeRasterClip()) { | |
656 fConservativeRasterClip = true; | |
657 } | |
658 device->onAttachToCanvas(this); | 661 device->onAttachToCanvas(this); |
659 fMCRec->fLayer->fDevice = SkRef(device); | 662 fMCRec->fLayer->fDevice = SkRef(device); |
660 fMCRec->fRasterClip.setRect(device->getGlobalBounds()); | 663 fMCRec->fRasterClip.setRect(device->getGlobalBounds()); |
661 } | 664 } |
662 return device; | 665 return device; |
663 } | 666 } |
664 | 667 |
665 SkCanvas::SkCanvas() | 668 SkCanvas::SkCanvas() |
666 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) | 669 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) |
667 , fProps(SkSurfaceProps::kLegacyFontHost_InitType) | 670 , fProps(SkSurfaceProps::kLegacyFontHost_InitType) |
671 , fConservativeRasterClip(false) | |
668 { | 672 { |
669 inc_canvas(); | 673 inc_canvas(); |
670 | 674 |
671 this->init(nullptr, kDefault_InitFlags); | 675 this->init(nullptr, kDefault_InitFlags); |
672 } | 676 } |
673 | 677 |
674 static SkBitmap make_nopixels(int width, int height) { | 678 static SkBitmap make_nopixels(int width, int height) { |
675 SkBitmap bitmap; | 679 SkBitmap bitmap; |
676 bitmap.setInfo(SkImageInfo::MakeUnknown(width, height)); | 680 bitmap.setInfo(SkImageInfo::MakeUnknown(width, height)); |
677 return bitmap; | 681 return bitmap; |
678 } | 682 } |
679 | 683 |
680 class SkNoPixelsBitmapDevice : public SkBitmapDevice { | 684 class SkNoPixelsBitmapDevice : public SkBitmapDevice { |
681 public: | 685 public: |
682 SkNoPixelsBitmapDevice(const SkIRect& bounds, const SkSurfaceProps& surfaceP rops) | 686 SkNoPixelsBitmapDevice(const SkIRect& bounds, const SkSurfaceProps& surfaceP rops) |
683 : INHERITED(make_nopixels(bounds.width(), bounds.height()), surfaceProps ) | 687 : INHERITED(make_nopixels(bounds.width(), bounds.height()), surfaceProps ) |
684 { | 688 { |
685 this->setOrigin(bounds.x(), bounds.y()); | 689 this->setOrigin(bounds.x(), bounds.y()); |
686 } | 690 } |
687 | 691 |
688 private: | 692 private: |
689 | 693 |
690 typedef SkBitmapDevice INHERITED; | 694 typedef SkBitmapDevice INHERITED; |
691 }; | 695 }; |
692 | 696 |
693 SkCanvas::SkCanvas(int width, int height, const SkSurfaceProps* props) | 697 SkCanvas::SkCanvas(int width, int height, const SkSurfaceProps* props) |
694 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) | 698 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) |
695 , fProps(SkSurfacePropsCopyOrDefault(props)) | 699 , fProps(SkSurfacePropsCopyOrDefault(props)) |
700 , fConservativeRasterClip(false) | |
696 { | 701 { |
697 inc_canvas(); | 702 inc_canvas(); |
698 | 703 |
699 this->init(new SkNoPixelsBitmapDevice(SkIRect::MakeWH(width, height), fProps ), | 704 this->init(new SkNoPixelsBitmapDevice(SkIRect::MakeWH(width, height), fProps ), |
700 kDefault_InitFlags)->unref(); | 705 kDefault_InitFlags)->unref(); |
701 } | 706 } |
702 | 707 |
703 SkCanvas::SkCanvas(const SkIRect& bounds, InitFlags flags) | 708 SkCanvas::SkCanvas(const SkIRect& bounds, InitFlags flags) |
704 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) | 709 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) |
705 , fProps(SkSurfaceProps::kLegacyFontHost_InitType) | 710 , fProps(SkSurfaceProps::kLegacyFontHost_InitType) |
711 , fConservativeRasterClip(false) | |
706 { | 712 { |
707 inc_canvas(); | 713 inc_canvas(); |
708 | 714 |
709 this->init(new SkNoPixelsBitmapDevice(bounds, fProps), flags)->unref(); | 715 this->init(new SkNoPixelsBitmapDevice(bounds, fProps), flags)->unref(); |
710 } | 716 } |
711 | 717 |
712 SkCanvas::SkCanvas(SkBaseDevice* device) | 718 SkCanvas::SkCanvas(SkBaseDevice* device) |
713 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) | 719 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) |
714 , fProps(device->surfaceProps()) | 720 , fProps(device->surfaceProps()) |
721 , fConservativeRasterClip(false) | |
715 { | 722 { |
716 inc_canvas(); | 723 inc_canvas(); |
717 | 724 |
718 this->init(device, kDefault_InitFlags); | 725 this->init(device, kDefault_InitFlags); |
719 } | 726 } |
720 | 727 |
721 SkCanvas::SkCanvas(SkBaseDevice* device, InitFlags flags) | 728 SkCanvas::SkCanvas(SkBaseDevice* device, InitFlags flags) |
722 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) | 729 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) |
723 , fProps(device->surfaceProps()) | 730 , fProps(device->surfaceProps()) |
731 , fConservativeRasterClip(false) | |
724 { | 732 { |
725 inc_canvas(); | 733 inc_canvas(); |
726 | 734 |
727 this->init(device, flags); | 735 this->init(device, flags); |
728 } | 736 } |
729 | 737 |
730 SkCanvas::SkCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props) | 738 SkCanvas::SkCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props) |
731 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) | 739 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) |
732 , fProps(props) | 740 , fProps(props) |
741 , fConservativeRasterClip(false) | |
733 { | 742 { |
734 inc_canvas(); | 743 inc_canvas(); |
735 | 744 |
736 SkAutoTUnref<SkBaseDevice> device(new SkBitmapDevice(bitmap, fProps)); | 745 SkAutoTUnref<SkBaseDevice> device(new SkBitmapDevice(bitmap, fProps)); |
737 this->init(device, kDefault_InitFlags); | 746 this->init(device, kDefault_InitFlags); |
738 } | 747 } |
739 | 748 |
740 SkCanvas::SkCanvas(const SkBitmap& bitmap) | 749 SkCanvas::SkCanvas(const SkBitmap& bitmap) |
741 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) | 750 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) |
742 , fProps(SkSurfaceProps::kLegacyFontHost_InitType) | 751 , fProps(SkSurfaceProps::kLegacyFontHost_InitType) |
752 , fConservativeRasterClip(false) | |
743 { | 753 { |
744 inc_canvas(); | 754 inc_canvas(); |
745 | 755 |
746 SkAutoTUnref<SkBaseDevice> device(new SkBitmapDevice(bitmap, fProps)); | 756 SkAutoTUnref<SkBaseDevice> device(new SkBitmapDevice(bitmap, fProps)); |
747 this->init(device, kDefault_InitFlags); | 757 this->init(device, kDefault_InitFlags); |
748 } | 758 } |
749 | 759 |
750 SkCanvas::~SkCanvas() { | 760 SkCanvas::~SkCanvas() { |
751 // free up the contents of our deque | 761 // free up the contents of our deque |
752 this->restoreToCount(1); // restore everything but the last | 762 this->restoreToCount(1); // restore everything but the last |
(...skipping 2168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2921 } | 2931 } |
2922 | 2932 |
2923 if (matrix) { | 2933 if (matrix) { |
2924 canvas->concat(*matrix); | 2934 canvas->concat(*matrix); |
2925 } | 2935 } |
2926 } | 2936 } |
2927 | 2937 |
2928 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { | 2938 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { |
2929 fCanvas->restoreToCount(fSaveCount); | 2939 fCanvas->restoreToCount(fSaveCount); |
2930 } | 2940 } |
OLD | NEW |