diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkMatrixImageFilter.cpp | 71 | ||||
-rw-r--r-- | src/core/SkMatrixImageFilter.h | 20 |
2 files changed, 45 insertions, 46 deletions
diff --git a/src/core/SkMatrixImageFilter.cpp b/src/core/SkMatrixImageFilter.cpp index b8f510f91c..d66772c244 100644 --- a/src/core/SkMatrixImageFilter.cpp +++ b/src/core/SkMatrixImageFilter.cpp @@ -6,21 +6,20 @@ */ #include "SkMatrixImageFilter.h" -#include "SkBitmap.h" + #include "SkCanvas.h" -#include "SkDevice.h" -#include "SkColorPriv.h" #include "SkReadBuffer.h" +#include "SkSpecialImage.h" +#include "SkSpecialSurface.h" #include "SkWriteBuffer.h" -#include "SkMatrix.h" #include "SkRect.h" SkMatrixImageFilter::SkMatrixImageFilter(const SkMatrix& transform, SkFilterQuality filterQuality, SkImageFilter* input) - : INHERITED(1, &input), - fTransform(transform), - fFilterQuality(filterQuality) { + : INHERITED(1, &input) + , fTransform(transform) + , fFilterQuality(filterQuality) { } SkMatrixImageFilter* SkMatrixImageFilter::Create(const SkMatrix& transform, @@ -43,52 +42,56 @@ void SkMatrixImageFilter::flatten(SkWriteBuffer& buffer) const { buffer.writeInt(fFilterQuality); } -SkMatrixImageFilter::~SkMatrixImageFilter() { -} +sk_sp<SkSpecialImage> SkMatrixImageFilter::onFilterImage(SkSpecialImage* source, + const Context& ctx, + SkIPoint* offset) const { -bool SkMatrixImageFilter::onFilterImageDeprecated(Proxy* proxy, - const SkBitmap& source, - const Context& ctx, - SkBitmap* result, - SkIPoint* offset) const { - SkBitmap src = source; - SkIPoint srcOffset = SkIPoint::Make(0, 0); - if (!this->filterInputDeprecated(0, proxy, source, ctx, &src, &srcOffset)) { - return false; + SkIPoint inputOffset = SkIPoint::Make(0, 0); + sk_sp<SkSpecialImage> input(this->filterInput(0, source, ctx, &inputOffset)); + if (!input) { + return nullptr; } - SkRect dstRect; - SkIRect srcBounds, dstBounds; - src.getBounds(&srcBounds); - srcBounds.offset(srcOffset); - SkRect srcRect = SkRect::Make(srcBounds); SkMatrix matrix; if (!ctx.ctm().invert(&matrix)) { - return false; + return nullptr; } matrix.postConcat(fTransform); matrix.postConcat(ctx.ctm()); + + const SkIRect srcBounds = SkIRect::MakeXYWH(inputOffset.x(), inputOffset.y(), + input->width(), input->height()); + const SkRect srcRect = SkRect::Make(srcBounds); + + SkRect dstRect; matrix.mapRect(&dstRect, srcRect); + SkIRect dstBounds; dstRect.roundOut(&dstBounds); - SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(dstBounds.width(), dstBounds.height())); - if (nullptr == device.get()) { - return false; + const SkImageInfo info = SkImageInfo::MakeN32Premul(dstBounds.width(), dstBounds.height()); + + sk_sp<SkSpecialSurface> surf(input->makeSurface(info)); + if (!surf) { + return nullptr; } - SkCanvas canvas(device.get()); - canvas.translate(-SkIntToScalar(dstBounds.x()), -SkIntToScalar(dstBounds.y())); - canvas.concat(matrix); - SkPaint paint; + SkCanvas* canvas = surf->getCanvas(); + SkASSERT(canvas); + + canvas->clear(0x0); + canvas->translate(-SkIntToScalar(dstBounds.x()), -SkIntToScalar(dstBounds.y())); + canvas->concat(matrix); + + SkPaint paint; paint.setXfermodeMode(SkXfermode::kSrc_Mode); paint.setFilterQuality(fFilterQuality); - canvas.drawBitmap(src, srcRect.x(), srcRect.y(), &paint); - *result = device.get()->accessBitmap(false); + input->draw(canvas, srcRect.x(), srcRect.y(), &paint); + offset->fX = dstBounds.fLeft; offset->fY = dstBounds.fTop; - return true; + return surf->makeImageSnapshot(); } SkRect SkMatrixImageFilter::computeFastBounds(const SkRect& src) const { diff --git a/src/core/SkMatrixImageFilter.h b/src/core/SkMatrixImageFilter.h index 0631a8b8c4..d7745668c4 100644 --- a/src/core/SkMatrixImageFilter.h +++ b/src/core/SkMatrixImageFilter.h @@ -9,10 +9,7 @@ #define SkMatrixImageFilter_DEFINED #include "SkImageFilter.h" -#include "SkScalar.h" -#include "SkSize.h" -#include "SkPoint.h" -#include "SkPaint.h" +#include "SkMatrix.h" /*! \class SkMatrixImageFilter Matrix transformation image filter. This filter draws its source @@ -22,16 +19,15 @@ class SK_API SkMatrixImageFilter : public SkImageFilter { public: /** Construct a 2D transformation image filter. - * @param transform The matrix to apply when drawing the src bitmap - * @param filterLevel The quality of filtering to apply when scaling. - * @param input The input image filter. If nullptr, the src bitmap - * passed to filterImage() is used instead. + * @param transform The matrix to apply when drawing the src bitmap + * @param filterQuality The quality of filtering to apply when scaling. + * @param input The input image filter. If nullptr, the src bitmap + * passed to filterImage() is used instead. */ static SkMatrixImageFilter* Create(const SkMatrix& transform, - SkFilterQuality, + SkFilterQuality filterQuality, SkImageFilter* input = nullptr); - virtual ~SkMatrixImageFilter(); SkRect computeFastBounds(const SkRect&) const override; @@ -44,8 +40,8 @@ protected: SkImageFilter* input); void flatten(SkWriteBuffer&) const override; - bool onFilterImageDeprecated(Proxy*, const SkBitmap& src, const Context&, - SkBitmap* result, SkIPoint* loc) const override; + sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&, + SkIPoint* offset) const override; SkIRect onFilterNodeBounds(const SkIRect& src, const SkMatrix&, MapDirection) const override; private: |