Index: src/core/SkCanvas.cpp |
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp |
index 11dc739f4c4dc6aa0509f8ba404a56fa246817e4..8babd29ba444fb3ffa94e73492d8d61ff4f35f8b 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) |
robertphillips
2015/03/20 14:01:10
// The stashed matrix is used for ... ?
|
+ SkMatrix fStashedMatrix; |
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,7 @@ SkBaseDevice* SkCanvas::init(SkBaseDevice* device, InitFlags flags) { |
fMCRec = (MCRec*)fMCStack.push_back(); |
new (fMCRec) MCRec(fConservativeRasterClip); |
robertphillips
2015/03/20 14:01:09
overlength ?
Stephen White
2015/03/20 14:47:21
Done.
|
- 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 +901,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; |
robertphillips
2015/03/20 14:01:09
Can matrix be a "const&" rather than a copy ?
Stephen White
2015/03/20 14:47:21
No. fMCRec->fMatrix will be modified by resetMatri
|
+ SkMatrix matrix = fMCRec->fMatrix; |
+ SkMatrix remainder; |
+ SkSize scale; |
+ if (imageFilter && !matrix.isScaleTranslate() && matrix.decomposeScale(&scale, &remainder)) { |
+ this->resetMatrix(); |
+ this->scale(scale.width(), scale.height()); |
+ SkAutoTUnref<SkImageFilter> matrixFilter(SkImageFilter::CreateMatrixFilter(remainder, SkFilterQuality::kHigh_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 |
@@ -907,7 +923,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; |
} |
@@ -951,7 +967,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; |
@@ -1004,6 +1020,9 @@ void SkCanvas::internalRestore() { |
// reset this, since internalDrawDevice will have set it to true |
fDeviceCMDirty = true; |
} |
+ if (layer->fPaint && layer->fPaint->fImageFilter) { |
+ fMCRec->fMatrix = layer->fStashedMatrix; |
+ } |
SkDELETE(layer); |
} |
} |