| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2008 The Android Open Source Project | 3 * Copyright 2008 The Android Open Source Project |
| 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 | 9 |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| (...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 739 } | 739 } |
| 740 | 740 |
| 741 return saveCount; | 741 return saveCount; |
| 742 } | 742 } |
| 743 | 743 |
| 744 int SkCanvas::save(SaveFlags flags) { | 744 int SkCanvas::save(SaveFlags flags) { |
| 745 // call shared impl | 745 // call shared impl |
| 746 return this->internalSave(flags); | 746 return this->internalSave(flags); |
| 747 } | 747 } |
| 748 | 748 |
| 749 #define C32MASK (1 << SkBitmap::kARGB_8888_Config) | |
| 750 #define C16MASK (1 << SkBitmap::kRGB_565_Config) | |
| 751 #define C8MASK (1 << SkBitmap::kA8_Config) | |
| 752 | |
| 753 static SkBitmap::Config resolve_config(SkCanvas* canvas, | |
| 754 const SkIRect& bounds, | |
| 755 SkCanvas::SaveFlags flags, | |
| 756 bool* isOpaque) { | |
| 757 *isOpaque = (flags & SkCanvas::kHasAlphaLayer_SaveFlag) == 0; | |
| 758 | |
| 759 #if 0 | |
| 760 // loop through and union all the configs we may draw into | |
| 761 uint32_t configMask = 0; | |
| 762 for (int i = canvas->countLayerDevices() - 1; i >= 0; --i) | |
| 763 { | |
| 764 SkBaseDevice* device = canvas->getLayerDevice(i); | |
| 765 if (device->intersects(bounds)) | |
| 766 configMask |= 1 << device->config(); | |
| 767 } | |
| 768 | |
| 769 // if the caller wants alpha or fullcolor, we can't return 565 | |
| 770 if (flags & (SkCanvas::kFullColorLayer_SaveFlag | | |
| 771 SkCanvas::kHasAlphaLayer_SaveFlag)) | |
| 772 configMask &= ~C16MASK; | |
| 773 | |
| 774 switch (configMask) { | |
| 775 case C8MASK: // if we only have A8, return that | |
| 776 return SkBitmap::kA8_Config; | |
| 777 | |
| 778 case C16MASK: // if we only have 565, return that | |
| 779 return SkBitmap::kRGB_565_Config; | |
| 780 | |
| 781 default: | |
| 782 return SkBitmap::kARGB_8888_Config; // default answer | |
| 783 } | |
| 784 #else | |
| 785 return SkBitmap::kARGB_8888_Config; // default answer | |
| 786 #endif | |
| 787 } | |
| 788 | |
| 789 static bool bounds_affects_clip(SkCanvas::SaveFlags flags) { | 749 static bool bounds_affects_clip(SkCanvas::SaveFlags flags) { |
| 790 return (flags & SkCanvas::kClipToLayer_SaveFlag) != 0; | 750 return (flags & SkCanvas::kClipToLayer_SaveFlag) != 0; |
| 791 } | 751 } |
| 792 | 752 |
| 793 bool SkCanvas::clipRectBounds(const SkRect* bounds, SaveFlags flags, | 753 bool SkCanvas::clipRectBounds(const SkRect* bounds, SaveFlags flags, |
| 794 SkIRect* intersection, const SkImageFilter* image
Filter) { | 754 SkIRect* intersection, const SkImageFilter* image
Filter) { |
| 795 SkIRect clipBounds; | 755 SkIRect clipBounds; |
| 796 SkRegion::Op op = SkRegion::kIntersect_Op; | 756 SkRegion::Op op = SkRegion::kIntersect_Op; |
| 797 if (!this->getClipDeviceBounds(&clipBounds)) { | 757 if (!this->getClipDeviceBounds(&clipBounds)) { |
| 798 return false; | 758 return false; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 } | 793 } |
| 834 return true; | 794 return true; |
| 835 } | 795 } |
| 836 | 796 |
| 837 int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, | 797 int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, |
| 838 SaveFlags flags) { | 798 SaveFlags flags) { |
| 839 return this->internalSaveLayer(bounds, paint, flags, false); | 799 return this->internalSaveLayer(bounds, paint, flags, false); |
| 840 } | 800 } |
| 841 | 801 |
| 842 static SkBaseDevice* createCompatibleDevice(SkCanvas* canvas, | 802 static SkBaseDevice* createCompatibleDevice(SkCanvas* canvas, |
| 843 SkBitmap::Config config, | 803 const SkImageInfo& info) { |
| 844 int width, int height, | |
| 845 bool isOpaque) { | |
| 846 SkBaseDevice* device = canvas->getDevice(); | 804 SkBaseDevice* device = canvas->getDevice(); |
| 847 if (device) { | 805 return device ? device->createCompatibleDevice(info) : NULL; |
| 848 return device->createCompatibleDevice(config, width, height, isOpaque); | |
| 849 } else { | |
| 850 return NULL; | |
| 851 } | |
| 852 } | 806 } |
| 853 | 807 |
| 854 int SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, | 808 int SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, |
| 855 SaveFlags flags, bool justForImageFilter) { | 809 SaveFlags flags, bool justForImageFilter) { |
| 856 // do this before we create the layer. We don't call the public save() since | 810 // do this before we create the layer. We don't call the public save() since |
| 857 // that would invoke a possibly overridden virtual | 811 // that would invoke a possibly overridden virtual |
| 858 int count = this->internalSave(flags); | 812 int count = this->internalSave(flags); |
| 859 | 813 |
| 860 fDeviceCMDirty = true; | 814 fDeviceCMDirty = true; |
| 861 | 815 |
| 862 SkIRect ir; | 816 SkIRect ir; |
| 863 if (!this->clipRectBounds(bounds, flags, &ir, paint ? paint->getImageFilter(
) : NULL)) { | 817 if (!this->clipRectBounds(bounds, flags, &ir, paint ? paint->getImageFilter(
) : NULL)) { |
| 864 return count; | 818 return count; |
| 865 } | 819 } |
| 866 | 820 |
| 867 // Kill the imagefilter if our device doesn't allow it | 821 // Kill the imagefilter if our device doesn't allow it |
| 868 SkLazyPaint lazyP; | 822 SkLazyPaint lazyP; |
| 869 if (paint && paint->getImageFilter()) { | 823 if (paint && paint->getImageFilter()) { |
| 870 if (!this->getTopDevice()->allowImageFilter(paint->getImageFilter())) { | 824 if (!this->getTopDevice()->allowImageFilter(paint->getImageFilter())) { |
| 871 if (justForImageFilter) { | 825 if (justForImageFilter) { |
| 872 // early exit if the layer was just for the imageFilter | 826 // early exit if the layer was just for the imageFilter |
| 873 return count; | 827 return count; |
| 874 } | 828 } |
| 875 SkPaint* p = lazyP.set(*paint); | 829 SkPaint* p = lazyP.set(*paint); |
| 876 p->setImageFilter(NULL); | 830 p->setImageFilter(NULL); |
| 877 paint = p; | 831 paint = p; |
| 878 } | 832 } |
| 879 } | 833 } |
| 880 | 834 |
| 881 bool isOpaque; | 835 bool isOpaque = !SkToBool(flags & kHasAlphaLayer_SaveFlag); |
| 882 SkBitmap::Config config = resolve_config(this, ir, flags, &isOpaque); | 836 SkImageInfo info = SkImageInfo::MakeN32(ir.width(), ir.height(), |
| 837 isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); |
| 883 | 838 |
| 884 SkBaseDevice* device; | 839 SkBaseDevice* device; |
| 885 if (paint && paint->getImageFilter()) { | 840 if (paint && paint->getImageFilter()) { |
| 886 device = createCompatibleDevice(this, config, ir.width(), ir.height(), | 841 device = createCompatibleDevice(this, info); |
| 887 isOpaque); | |
| 888 } else { | 842 } else { |
| 889 device = this->createLayerDevice(config, ir.width(), ir.height(), | 843 device = this->createLayerDevice(info); |
| 890 isOpaque); | |
| 891 } | 844 } |
| 892 if (NULL == device) { | 845 if (NULL == device) { |
| 893 SkDebugf("Unable to create device for layer."); | 846 SkDebugf("Unable to create device for layer."); |
| 894 return count; | 847 return count; |
| 895 } | 848 } |
| 896 | 849 |
| 897 device->setOrigin(ir.fLeft, ir.fTop); | 850 device->setOrigin(ir.fLeft, ir.fTop); |
| 898 DeviceCM* layer = SkNEW_ARGS(DeviceCM, (device, ir.fLeft, ir.fTop, paint, th
is)); | 851 DeviceCM* layer = SkNEW_ARGS(DeviceCM, (device, ir.fLeft, ir.fTop, paint, th
is)); |
| 899 device->unref(); | 852 device->unref(); |
| 900 | 853 |
| (...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1600 SkCanvas::ClipType SkCanvas::getClipType() const { | 1553 SkCanvas::ClipType SkCanvas::getClipType() const { |
| 1601 if (fMCRec->fRasterClip->isEmpty()) return kEmpty_ClipType; | 1554 if (fMCRec->fRasterClip->isEmpty()) return kEmpty_ClipType; |
| 1602 if (fMCRec->fRasterClip->isRect()) return kRect_ClipType; | 1555 if (fMCRec->fRasterClip->isRect()) return kRect_ClipType; |
| 1603 return kComplex_ClipType; | 1556 return kComplex_ClipType; |
| 1604 } | 1557 } |
| 1605 | 1558 |
| 1606 const SkRegion& SkCanvas::getTotalClip() const { | 1559 const SkRegion& SkCanvas::getTotalClip() const { |
| 1607 return fMCRec->fRasterClip->forceGetBW(); | 1560 return fMCRec->fRasterClip->forceGetBW(); |
| 1608 } | 1561 } |
| 1609 | 1562 |
| 1610 SkBaseDevice* SkCanvas::createLayerDevice(SkBitmap::Config config, | 1563 SkBaseDevice* SkCanvas::createLayerDevice(const SkImageInfo& info) { |
| 1611 int width, int height, | |
| 1612 bool isOpaque) { | |
| 1613 SkBaseDevice* device = this->getTopDevice(); | 1564 SkBaseDevice* device = this->getTopDevice(); |
| 1614 if (device) { | 1565 return device ? device->createCompatibleDeviceForSaveLayer(info) : NULL; |
| 1615 return device->createCompatibleDeviceForSaveLayer(config, width, height, | |
| 1616 isOpaque); | |
| 1617 } else { | |
| 1618 return NULL; | |
| 1619 } | |
| 1620 } | 1566 } |
| 1621 | 1567 |
| 1622 GrContext* SkCanvas::getGrContext() { | 1568 GrContext* SkCanvas::getGrContext() { |
| 1623 #if SK_SUPPORT_GPU | 1569 #if SK_SUPPORT_GPU |
| 1624 SkBaseDevice* device = this->getTopDevice(); | 1570 SkBaseDevice* device = this->getTopDevice(); |
| 1625 if (NULL != device) { | 1571 if (NULL != device) { |
| 1626 GrRenderTarget* renderTarget = device->accessRenderTarget(); | 1572 GrRenderTarget* renderTarget = device->accessRenderTarget(); |
| 1627 if (NULL != renderTarget) { | 1573 if (NULL != renderTarget) { |
| 1628 return renderTarget->getContext(); | 1574 return renderTarget->getContext(); |
| 1629 } | 1575 } |
| (...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2281 return *paint; | 2227 return *paint; |
| 2282 } | 2228 } |
| 2283 | 2229 |
| 2284 const SkRegion& SkCanvas::LayerIter::clip() const { return fImpl->getClip(); } | 2230 const SkRegion& SkCanvas::LayerIter::clip() const { return fImpl->getClip(); } |
| 2285 int SkCanvas::LayerIter::x() const { return fImpl->getX(); } | 2231 int SkCanvas::LayerIter::x() const { return fImpl->getX(); } |
| 2286 int SkCanvas::LayerIter::y() const { return fImpl->getY(); } | 2232 int SkCanvas::LayerIter::y() const { return fImpl->getY(); } |
| 2287 | 2233 |
| 2288 /////////////////////////////////////////////////////////////////////////////// | 2234 /////////////////////////////////////////////////////////////////////////////// |
| 2289 | 2235 |
| 2290 SkCanvas::ClipVisitor::~ClipVisitor() { } | 2236 SkCanvas::ClipVisitor::~ClipVisitor() { } |
| OLD | NEW |