From: reed Date: Thu, 14 May 2015 19:25:22 +0000 (-0700) Subject: Revert of Implement support for non-scale/translate CTM in image filters. (patchset... X-Git-Tag: accepted/tizen/5.0/unified/20181102.025319~2384 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=86a17e7716c8db858e219a46b9db3817bb770bee;p=platform%2Fupstream%2FlibSkiaSharp.git Revert of Implement support for non-scale/translate CTM in image filters. (patchset #4 id:60001 of https://codereview.chromium.org/1140943004/) Reason for revert: matriximagefilter needs to antialias its draw, so we get smooth diagonals... Original issue's description: > Implement support for non-scale/translate CTM in image filters. > > Clone with tweaks of https://codereview.chromium.org/986623003/ > > pre-cl to guard chrome here: https://codereview.chromium.org/1133403003/ > > BUG=skia:3288 > > Committed: https://skia.googlesource.com/skia/+/35786b176c159d2e7a816e9da9b051ef3129d5cb TBR=robertphillips@google.com,senorblanco@google.com,senorblanco@chromium.org,reed@chromium.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=skia:3288 Review URL: https://codereview.chromium.org/1139173002 --- diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h index ac01fad..e7dac5e 100644 --- a/include/core/SkCanvas.h +++ b/include/core/SkCanvas.h @@ -1261,7 +1261,7 @@ private: enum { kMCRecSize = 128, // most recent measurement kMCRecCount = 8, // common depth for save/restores - kDeviceCMSize = 176, // most recent measurement + kDeviceCMSize = 136, // most recent measurement }; intptr_t fMCRecStorage[kMCRecSize * kMCRecCount / sizeof(intptr_t)]; intptr_t fDeviceCMStorage[kDeviceCMSize / sizeof(intptr_t)]; @@ -1285,7 +1285,6 @@ private: void doSave(); void checkForDeferredSave(); - void internalSetMatrix(const SkMatrix& matrix); friend class SkDrawIter; // needs setupDrawForLayerDevice() friend class AutoDrawLooper; diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index 2d45e34..34d6aaa 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -115,14 +115,12 @@ 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, const SkMatrix& stashed) + bool conservativeRasterClip, bool deviceIsBitmapDevice) : fNext(NULL) , fClip(conservativeRasterClip) - , fStashedMatrix(stashed) , fDeviceIsBitmapDevice(deviceIsBitmapDevice) { if (NULL != device) { @@ -530,8 +528,7 @@ SkBaseDevice* SkCanvas::init(SkBaseDevice* device, InitFlags flags) { SkASSERT(sizeof(DeviceCM) <= sizeof(fDeviceCMStorage)); fMCRec->fLayer = (DeviceCM*)fDeviceCMStorage; - new (fDeviceCMStorage) DeviceCM(NULL, NULL, NULL, fConservativeRasterClip, false, - fMCRec->fMatrix); + new (fDeviceCMStorage) DeviceCM(NULL, NULL, NULL, fConservativeRasterClip, false); fMCRec->fTopLayer = fMCRec->fLayer; @@ -994,40 +991,6 @@ 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; -#ifndef SK_SUPPORT_LEGACY_IMAGEFILTER_CTM - SkMatrix remainder; - SkSize scale; - /* - * ImageFilters (so far) do not correctly handle matrices (CTM) that contain rotation/skew/etc. - * but they do handle scaling. To accommodate this, we do the following: - * - * 1. Stash off the current CTM - * 2. Decompose the CTM into SCALE and REMAINDER - * 3. Wack the CTM to be just SCALE, and wrap the imagefilter with a MatrixImageFilter that - * contains the REMAINDER - * 4. Proceed as usual, allowing the client to draw into the layer (now with a scale-only CTM) - * 5. During restore, we process the MatrixImageFilter, which applies REMAINDER to the output - * of the original imagefilter, and draw that (via drawSprite) - * 6. Unwack the CTM to its original state (i.e. stashedMatrix) - * - * Perhaps in the future we could augment #5 to apply REMAINDER as part of the draw (no longer - * a sprite operation) to avoid the extra buffer/overhead of MatrixImageFilter. - */ - 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 matrixFilter(SkImageFilter::CreateMatrixFilter( - remainder, SkFilterQuality::kLow_SkFilterQuality, imageFilter)); - imageFilter = matrixFilter.get(); - SkPaint* p = lazyP.set(*paint); - p->setImageFilter(imageFilter); - paint = p; - } -#endif // do this before we create the layer. We don't call the public save() since // that would invoke a possibly overridden virtual @@ -1036,7 +999,7 @@ void SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Sav fDeviceCMDirty = true; SkIRect ir; - if (!this->clipRectBounds(bounds, flags, &ir, imageFilter)) { + if (!this->clipRectBounds(bounds, flags, &ir, paint ? paint->getImageFilter() : NULL)) { return; } @@ -1084,7 +1047,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, stashedMatrix)); + forceSpriteOnRestore)); device->unref(); layer->fNext = fMCRec->fTopLayer; @@ -1134,8 +1097,6 @@ void SkCanvas::internalRestore() { const SkIPoint& origin = layer->fDevice->getOrigin(); this->internalDrawDevice(layer->fDevice, origin.x(), origin.y(), layer->fPaint, layer->fDeviceIsBitmapDevice); - // restore what we smashed in internalSaveLayer - fMCRec->fMatrix = layer->fStashedMatrix; // reset this, since internalDrawDevice will have set it to true fDeviceCMDirty = true; SkDELETE(layer); @@ -1143,7 +1104,6 @@ void SkCanvas::internalRestore() { // we're at the root SkASSERT(layer == (void*)fDeviceCMStorage); layer->~DeviceCM(); - // no need to update fMCRec, 'cause we're killing the canvas } } } @@ -1372,15 +1332,11 @@ void SkCanvas::concat(const SkMatrix& matrix) { this->didConcat(matrix); } -void SkCanvas::internalSetMatrix(const SkMatrix& matrix) { +void SkCanvas::setMatrix(const SkMatrix& matrix) { + this->checkForDeferredSave(); fDeviceCMDirty = true; fCachedLocalClipBoundsDirty = true; fMCRec->fMatrix = matrix; -} - -void SkCanvas::setMatrix(const SkMatrix& matrix) { - this->checkForDeferredSave(); - this->internalSetMatrix(matrix); this->didSetMatrix(matrix); }