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 "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkCanvasPriv.h" | 9 #include "SkCanvasPriv.h" |
10 #include "SkBitmapDevice.h" | 10 #include "SkBitmapDevice.h" |
(...skipping 974 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
985 this->internalSaveLayer(bounds, paint, flags, strategy); | 985 this->internalSaveLayer(bounds, paint, flags, strategy); |
986 return this->getSaveCount() - 1; | 986 return this->getSaveCount() - 1; |
987 } | 987 } |
988 | 988 |
989 void SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Sav
eFlags flags, | 989 void SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Sav
eFlags flags, |
990 SaveLayerStrategy strategy) { | 990 SaveLayerStrategy strategy) { |
991 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG | 991 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG |
992 flags |= kClipToLayer_SaveFlag; | 992 flags |= kClipToLayer_SaveFlag; |
993 #endif | 993 #endif |
994 | 994 |
| 995 SkImageFilter* imgf = paint ? paint->getImageFilter() : NULL; |
| 996 |
995 // do this before we create the layer. We don't call the public save() since | 997 // do this before we create the layer. We don't call the public save() since |
996 // that would invoke a possibly overridden virtual | 998 // that would invoke a possibly overridden virtual |
997 this->internalSave(); | 999 this->internalSave(); |
998 | 1000 |
999 fDeviceCMDirty = true; | 1001 fDeviceCMDirty = true; |
1000 | 1002 |
1001 SkIRect ir; | 1003 SkIRect ir; |
1002 if (!this->clipRectBounds(bounds, flags, &ir, paint ? paint->getImageFilter(
) : NULL)) { | 1004 if (!this->clipRectBounds(bounds, flags, &ir, imgf)) { |
1003 return; | 1005 return; |
1004 } | 1006 } |
1005 | 1007 |
1006 // FIXME: do willSaveLayer() overriders returning kNoLayer_SaveLayerStrategy
really care about | 1008 // FIXME: do willSaveLayer() overriders returning kNoLayer_SaveLayerStrategy
really care about |
1007 // the clipRectBounds() call above? | 1009 // the clipRectBounds() call above? |
1008 if (kNoLayer_SaveLayerStrategy == strategy) { | 1010 if (kNoLayer_SaveLayerStrategy == strategy) { |
1009 return; | 1011 return; |
1010 } | 1012 } |
1011 | 1013 |
1012 bool isOpaque = !SkToBool(flags & kHasAlphaLayer_SaveFlag); | 1014 bool isOpaque = !SkToBool(flags & kHasAlphaLayer_SaveFlag); |
1013 SkPixelGeometry geo = fProps.pixelGeometry(); | 1015 SkPixelGeometry geo = fProps.pixelGeometry(); |
1014 if (paint) { | 1016 if (paint) { |
1015 // TODO: perhaps add a query to filters so we might preserve opaqueness.
.. | 1017 // TODO: perhaps add a query to filters so we might preserve opaqueness.
.. |
1016 if (paint->getImageFilter() || paint->getColorFilter()) { | 1018 if (imgf || paint->getColorFilter()) { |
1017 isOpaque = false; | 1019 isOpaque = false; |
1018 geo = kUnknown_SkPixelGeometry; | 1020 geo = kUnknown_SkPixelGeometry; |
1019 } | 1021 } |
1020 } | 1022 } |
1021 SkImageInfo info = SkImageInfo::MakeN32(ir.width(), ir.height(), | 1023 SkImageInfo info = SkImageInfo::MakeN32(ir.width(), ir.height(), |
1022 isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); | 1024 isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); |
1023 | 1025 |
1024 SkBaseDevice* device = this->getTopDevice(); | 1026 SkBaseDevice* device = this->getTopDevice(); |
1025 if (NULL == device) { | 1027 if (NULL == device) { |
1026 SkDebugf("Unable to find device for layer."); | 1028 SkDebugf("Unable to find device for layer."); |
1027 return; | 1029 return; |
1028 } | 1030 } |
1029 | 1031 |
1030 bool forceSpriteOnRestore = false; | 1032 bool forceSpriteOnRestore = false; |
1031 { | 1033 { |
1032 const SkBaseDevice::TileUsage usage = SkBaseDevice::kNever_TileUsage; | 1034 SkBaseDevice::TileUsage usage = SkBaseDevice::kNever_TileUsage; |
| 1035 if (imgf && imgf->mayDrawWithMatrix()) { |
| 1036 usage = SkBaseDevice::kPossible_TileUsage; |
| 1037 } |
1033 const SkBaseDevice::CreateInfo createInfo = SkBaseDevice::CreateInfo(inf
o, usage, geo); | 1038 const SkBaseDevice::CreateInfo createInfo = SkBaseDevice::CreateInfo(inf
o, usage, geo); |
1034 SkBaseDevice* newDev = device->onCreateDevice(createInfo, paint); | 1039 SkBaseDevice* newDev = device->onCreateDevice(createInfo, paint); |
1035 if (NULL == newDev) { | 1040 if (NULL == newDev) { |
1036 // If onCreateDevice didn't succeed, try raster (e.g. PDF couldn't h
andle the paint) | 1041 // If onCreateDevice didn't succeed, try raster (e.g. PDF couldn't h
andle the paint) |
1037 newDev = SkBitmapDevice::Create(createInfo.fInfo); | 1042 newDev = SkBitmapDevice::Create(createInfo.fInfo); |
1038 if (NULL == newDev) { | 1043 if (NULL == newDev) { |
1039 SkErrorInternals::SetError(kInternalError_SkError, | 1044 SkErrorInternals::SetError(kInternalError_SkError, |
1040 "Unable to create device for layer.")
; | 1045 "Unable to create device for layer.")
; |
1041 return; | 1046 return; |
1042 } | 1047 } |
(...skipping 1644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2687 } | 2692 } |
2688 | 2693 |
2689 if (matrix) { | 2694 if (matrix) { |
2690 canvas->concat(*matrix); | 2695 canvas->concat(*matrix); |
2691 } | 2696 } |
2692 } | 2697 } |
2693 | 2698 |
2694 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { | 2699 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { |
2695 fCanvas->restoreToCount(fSaveCount); | 2700 fCanvas->restoreToCount(fSaveCount); |
2696 } | 2701 } |
OLD | NEW |