Index: src/core/SkCanvas.cpp |
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp |
index 8426f090ec5949653ab516ffca3f7d33a317c338..3a9b4ed39dfed6bf52a4f6cfe6898dab72ac4cba 100644 |
--- a/src/core/SkCanvas.cpp |
+++ b/src/core/SkCanvas.cpp |
@@ -113,11 +113,13 @@ struct DeviceCM { |
SkRasterClip fClip; |
const SkMatrix* fMatrix; |
SkPaint* fPaint; // may be null (in the future) |
+ SkMatrix fStashedMatrix; // Original CTM; used by imageFilter at saveLayer time |
DeviceCM(SkBaseDevice* device, const SkPaint* paint, SkCanvas* canvas, |
- bool conservativeRasterClip) |
+ bool conservativeRasterClip, const SkMatrix& stashedMatrix) |
: fNext(NULL) |
, fClip(conservativeRasterClip) |
+ , fStashedMatrix(stashedMatrix) |
{ |
if (NULL != device) { |
device->ref(); |
@@ -438,7 +440,8 @@ SkBaseDevice* SkCanvas::init(SkBaseDevice* device, InitFlags flags) { |
fMCRec = (MCRec*)fMCStack.push_back(); |
new (fMCRec) MCRec(fConservativeRasterClip); |
- fMCRec->fLayer = SkNEW_ARGS(DeviceCM, (NULL, NULL, NULL, fConservativeRasterClip)); |
+ fMCRec->fLayer = SkNEW_ARGS(DeviceCM, (NULL, NULL, NULL, fConservativeRasterClip, |
+ fMCRec->fMatrix)); |
fMCRec->fTopLayer = fMCRec->fLayer; |
fSurfaceBase = NULL; |
@@ -899,6 +902,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)) { |
+ this->resetMatrix(); |
reed1
2015/03/26 15:54:03
these two calls for matrix changes are virtual, wh
Stephen White
2015/03/26 16:18:34
Hmm -- they don't seem to be virtual on SkCanvas?
|
+ this->scale(scale.width(), scale.height()); |
+ SkAutoTUnref<SkImageFilter> matrixFilter(SkImageFilter::CreateMatrixFilter(remainder, SkFilterQuality::kHigh_SkFilterQuality, imageFilter)); |
reed1
2015/03/26 15:54:03
kLow might be more honest, since by definition rem
Stephen White
2015/03/26 16:18:34
Done.
|
+ 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 |
@@ -907,7 +924,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; |
} |
@@ -952,7 +969,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)); |
+ DeviceCM* layer = SkNEW_ARGS(DeviceCM, (device, paint, this, fConservativeRasterClip, matrix)); |
device->unref(); |
layer->fNext = fMCRec->fTopLayer; |
@@ -1005,6 +1022,9 @@ void SkCanvas::internalRestore() { |
// reset this, since internalDrawDevice will have set it to true |
fDeviceCMDirty = true; |
} |
+ if (layer->fPaint && layer->fPaint->fImageFilter) { |
reed1
2015/03/26 15:54:03
the check seems a little fragile, since it somehow
Stephen White
2015/03/26 16:18:34
Done.
|
+ fMCRec->fMatrix = layer->fStashedMatrix; |
+ } |
SkDELETE(layer); |
} |
} |