diff options
author | senorblanco <senorblanco@google.com> | 2015-10-14 04:53:31 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-10-14 04:53:31 -0700 |
commit | 20311d4843f25e6a3d9416456b18780ad5d9c1fa (patch) | |
tree | 552690a8378128e568d8c013162329e26f9a673e /src/core/SkLocalMatrixImageFilter.cpp | |
parent | 2da1a854b0836001533aa29ade89d87f420cbbc3 (diff) |
Implement SkLocalMatrixImageFilter.
At draw time, this filter simply concatenates the given matrix to the
CTM, and recurses on its input. The matrix is thus applied to any
upstream filter parameters and crop rects.
BUG=skia:
Review URL: https://codereview.chromium.org/1392833005
Diffstat (limited to 'src/core/SkLocalMatrixImageFilter.cpp')
-rw-r--r-- | src/core/SkLocalMatrixImageFilter.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/core/SkLocalMatrixImageFilter.cpp b/src/core/SkLocalMatrixImageFilter.cpp new file mode 100644 index 0000000000..17ee1028a8 --- /dev/null +++ b/src/core/SkLocalMatrixImageFilter.cpp @@ -0,0 +1,57 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkLocalMatrixImageFilter.h" +#include "SkReadBuffer.h" +#include "SkString.h" + +SkImageFilter* SkLocalMatrixImageFilter::Create(const SkMatrix& localM, SkImageFilter* input) { + if (!input) { + return nullptr; + } + if (localM.getType() & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)) { + return nullptr; + } + if (localM.isIdentity()) { + return SkRef(input); + } + return new SkLocalMatrixImageFilter(localM, input); +} + +SkLocalMatrixImageFilter::SkLocalMatrixImageFilter(const SkMatrix& localM, SkImageFilter* input) + : INHERITED(1, &input), fLocalM(localM) +{} + +SkFlattenable* SkLocalMatrixImageFilter::CreateProc(SkReadBuffer& buffer) { + SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); + SkMatrix lm; + buffer.readMatrix(&lm); + return SkLocalMatrixImageFilter::Create(lm, common.getInput(0)); +} + +void SkLocalMatrixImageFilter::flatten(SkWriteBuffer& buffer) const { + this->INHERITED::flatten(buffer); + buffer.writeMatrix(fLocalM); +} + +bool SkLocalMatrixImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& src, const Context& ctx, + SkBitmap* result, SkIPoint* offset) const { + Context localCtx(SkMatrix::Concat(ctx.ctm(), fLocalM), ctx.clipBounds(), ctx.cache()); + return this->getInput(0)->filterImage(proxy, src, localCtx, result, offset); +} + +bool SkLocalMatrixImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& matrix, + SkIRect* dst) const { + return this->getInput(0)->filterBounds(src, SkMatrix::Concat(matrix, fLocalM), dst); +} + +#ifndef SK_IGNORE_TO_STRING +void SkLocalMatrixImageFilter::toString(SkString* str) const { + str->append("SkLocalMatrixImageFilter: ("); + str->append(")"); +} +#endif |