aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkCanvas.cpp
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2015-05-13 13:34:57 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-05-13 13:34:57 -0700
commit4f12b8bd2cb43daeffa4d1c53120ae94c5ccf486 (patch)
treef7099c4479cd3c9d9acc36bf0756c2213f8c4f0a /src/core/SkCanvas.cpp
parent231c5fd590c898957d65cbfbc51040c7fe236af6 (diff)
Implement support for non-scale/translate CTM in image filters.
Implemented by extracting out the non-scale/translate components and applying that post-filter as an SkMatrixImageFilter. BUG=skia: Review URL: https://codereview.chromium.org/1120043002
Diffstat (limited to 'src/core/SkCanvas.cpp')
-rw-r--r--src/core/SkCanvas.cpp39
1 files changed, 33 insertions, 6 deletions
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index 34d6aaa0ab..f2ca15159e 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -115,12 +115,14 @@ struct DeviceCM {
SkPaint* fPaint; // may be null (in the future)
const SkMatrix* fMatrix;
SkMatrix fMatrixStorage;
+ SkMatrix fStashedMatrix; // Original CTM; used by imageFilter at saveLayer time
const bool fDeviceIsBitmapDevice;
DeviceCM(SkBaseDevice* device, const SkPaint* paint, SkCanvas* canvas,
- bool conservativeRasterClip, bool deviceIsBitmapDevice)
+ bool conservativeRasterClip, bool deviceIsBitmapDevice, const SkMatrix& stashed)
: fNext(NULL)
, fClip(conservativeRasterClip)
+ , fStashedMatrix(stashed)
, fDeviceIsBitmapDevice(deviceIsBitmapDevice)
{
if (NULL != device) {
@@ -528,7 +530,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;
@@ -991,6 +994,22 @@ 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 stashedMatrix = fMCRec->fMatrix;
+ SkMatrix remainder;
+ SkSize scale;
+ if (imageFilter &&
+ !stashedMatrix.isScaleTranslate() && stashedMatrix.decomposeScale(&scale, &remainder)) {
+ // We will restore the matrix (which we are overwriting here) in restore via fStashedMatrix
+ this->internalSetMatrix(SkMatrix::MakeScale(scale.width(), scale.height()));
+ 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
@@ -999,7 +1018,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;
}
@@ -1047,7 +1066,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, stashedMatrix));
device->unref();
layer->fNext = fMCRec->fTopLayer;
@@ -1105,6 +1124,10 @@ void SkCanvas::internalRestore() {
SkASSERT(layer == (void*)fDeviceCMStorage);
layer->~DeviceCM();
}
+ if (fMCRec) {
+ // restore what we smashed in internalSaveLayer
+ fMCRec->fMatrix = layer->fStashedMatrix;
+ }
}
}
@@ -1332,11 +1355,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);
}