Index: src/core/SkCanvas.cpp |
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp |
index daf8425f57fb9b395de3f3984995a39e15669f0a..4bd0584c72ae56712c034f212960cf08f4e4c82c 100644 |
--- a/src/core/SkCanvas.cpp |
+++ b/src/core/SkCanvas.cpp |
@@ -191,12 +191,15 @@ struct DeviceCM { |
const SkMatrix* fMatrix; |
SkMatrix fMatrixStorage; |
const bool fDeviceIsBitmapDevice; |
+ SkMatrix fStashedMatrix; // Original CTM; used by imageFilter at saveLayer time |
DeviceCM(SkBaseDevice* device, const SkPaint* paint, SkCanvas* canvas, |
- bool conservativeRasterClip, bool deviceIsBitmapDevice) |
+ bool conservativeRasterClip, bool deviceIsBitmapDevice, |
+ const SkMatrix& stashedMatrix) |
: fNext(NULL) |
, fClip(conservativeRasterClip) |
, fDeviceIsBitmapDevice(deviceIsBitmapDevice) |
+ , fStashedMatrix(stashedMatrix) |
{ |
if (NULL != device) { |
device->ref(); |
@@ -611,7 +614,8 @@ SkBaseDevice* SkCanvas::init(SkBaseDevice* device, InitFlags flags) { |
SkASSERT(sizeof(DeviceCM) <= sizeof(fDeviceCMStorage)); |
fMCRec->fLayer = (DeviceCM*)fDeviceCMStorage; |
- new (fDeviceCMStorage) DeviceCM(NULL, NULL, NULL, fConservativeRasterClip, false); |
+ new (fDeviceCMStorage) DeviceCM(NULL, NULL, NULL, fConservativeRasterClip, false, |
+ fMCRec->fMatrix); |
fMCRec->fTopLayer = fMCRec->fLayer; |
@@ -1079,6 +1083,20 @@ void SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Sav |
#ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG |
flags |= kClipToLayer_SaveFlag; |
#endif |
+ SkLazyPaint lazyP; |
+ SkImageFilter* imageFilter = paint ? paint->getImageFilter() : NULL; |
+ SkMatrix matrix = fMCRec->fMatrix; |
+ SkMatrix remainder; |
+ SkSize scale; |
+ if (imageFilter && !matrix.isScaleTranslate() && matrix.decomposeScale(&scale, &remainder)) { |
+ SkMatrix scaleMatrix = SkMatrix::MakeScale(scale.width(), scale.height()); |
+ this->internalSetMatrix(scaleMatrix); |
+ SkAutoTUnref<SkImageFilter> matrixFilter(SkImageFilter::CreateMatrixFilter(remainder, SkFilterQuality::kLow_SkFilterQuality, imageFilter)); |
+ imageFilter = matrixFilter.get(); |
+ SkPaint* p = lazyP.set(*paint); |
+ p->setImageFilter(imageFilter); |
+ paint = p; |
+ } |
// do this before we create the layer. We don't call the public save() since |
// that would invoke a possibly overridden virtual |
@@ -1087,7 +1105,7 @@ void SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Sav |
fDeviceCMDirty = true; |
SkIRect ir; |
- if (!this->clipRectBounds(bounds, flags, &ir, paint ? paint->getImageFilter() : NULL)) { |
+ if (!this->clipRectBounds(bounds, flags, &ir, imageFilter)) { |
return; |
} |
@@ -1136,7 +1154,7 @@ void SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Sav |
device->setOrigin(ir.fLeft, ir.fTop); |
DeviceCM* layer = SkNEW_ARGS(DeviceCM, (device, paint, this, fConservativeRasterClip, |
- forceSpriteOnRestore)); |
+ forceSpriteOnRestore, fMCRec->fMatrix)); |
device->unref(); |
layer->fNext = fMCRec->fTopLayer; |
@@ -1188,6 +1206,9 @@ void SkCanvas::internalRestore() { |
layer->fPaint, layer->fDeviceIsBitmapDevice); |
// reset this, since internalDrawDevice will have set it to true |
fDeviceCMDirty = true; |
+ if (fMCRec) { |
+ fMCRec->fMatrix = layer->fStashedMatrix; |
+ } |
SkDELETE(layer); |
} else { |
// we're at the root |
@@ -1440,11 +1461,15 @@ void SkCanvas::concat(const SkMatrix& matrix) { |
this->didConcat(matrix); |
} |
-void SkCanvas::setMatrix(const SkMatrix& matrix) { |
- this->checkForDeferredSave(); |
+void SkCanvas::internalSetMatrix(const SkMatrix& matrix) { |
fDeviceCMDirty = true; |
fCachedLocalClipBoundsDirty = true; |
fMCRec->fMatrix = matrix; |
+} |
+ |
+void SkCanvas::setMatrix(const SkMatrix& matrix) { |
+ this->checkForDeferredSave(); |
+ this->internalSetMatrix(matrix); |
this->didSetMatrix(matrix); |
} |