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