Chromium Code Reviews| Index: src/core/SkLocalMatrixImageFilter.cpp |
| diff --git a/src/core/SkLocalMatrixImageFilter.cpp b/src/core/SkLocalMatrixImageFilter.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..eb2f84c89fbbd71687668d6b45ef12de885070a6 |
| --- /dev/null |
| +++ b/src/core/SkLocalMatrixImageFilter.cpp |
| @@ -0,0 +1,87 @@ |
| +/* |
| + * 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 "SkImageFilter.h" |
| +#include "SkReadBuffer.h" |
| +#include "SkString.h" |
| + |
| +/** |
| + * Wraps another imagefilter + matrix, such that using this filter will give the same result |
| + * as using the wrapped filter with the matrix applied to its context. |
| + */ |
| +class SkLocalMatrixImageFilter : public SkImageFilter { |
| +public: |
| + static SkImageFilter* Create(SkImageFilter* base, const SkMatrix& localM) { |
| + if (localM.getType() & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)) { |
| + return nullptr; |
| + } |
| + if (localM.isIdentity()) { |
|
robertphillips
2015/10/13 19:42:39
readd this ?
Stephen White
2015/10/13 20:12:40
Done.
|
| + // return SkRef(base); |
| + } |
| + return new SkLocalMatrixImageFilter(base, localM); |
| + } |
| + |
| + SK_TO_STRING_OVERRIDE() |
| + SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLocalMatrixImageFilter) |
| + |
| +protected: |
| + void flatten(SkWriteBuffer&) const override; |
| + bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, |
| + SkBitmap* result, SkIPoint* offset) const override; |
| + bool onFilterBounds(const SkIRect& src, const SkMatrix&, SkIRect* dst) const override; |
| + |
| +private: |
| + SkLocalMatrixImageFilter(SkImageFilter* base, const SkMatrix& localM) |
| + : INHERITED(1, &base), fLocalM(localM) |
| + {} |
| + |
| + SkMatrix fLocalM; |
| + |
| + typedef SkImageFilter INHERITED; |
| +}; |
| + |
|
robertphillips
2015/10/13 19:42:39
use SkMatrix::Concat ?
Stephen White
2015/10/13 20:12:40
Done.
|
| +static SkMatrix concat(const SkMatrix& a, const SkMatrix& b) { |
| + SkMatrix c; |
| + c.setConcat(a, b); |
| + return c; |
| +} |
| + |
| +SkFlattenable* SkLocalMatrixImageFilter::CreateProc(SkReadBuffer& buffer) { |
| + SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); |
| + SkMatrix lm; |
| + buffer.readMatrix(&lm); |
| + return SkLocalMatrixImageFilter::Create(common.getInput(0), lm); |
| +} |
| + |
| +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(concat(ctx.ctm(), fLocalM), ctx.clipBounds(), ctx.cache()); |
|
robertphillips
2015/10/13 19:42:39
this-> on the getInputs ?
Stephen White
2015/10/13 20:12:40
Done.
|
| + return getInput(0) && getInput(0)->filterImage(proxy, src, localCtx, result, offset); |
| +} |
| + |
| +bool SkLocalMatrixImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& matrix, |
| + SkIRect* dst) const { |
|
robertphillips
2015/10/13 19:42:39
this-> here too ?
Stephen White
2015/10/13 20:12:40
Done.
|
| + return getInput(0) && getInput(0)->onFilterBounds(src, concat(matrix, fLocalM), dst); |
| +} |
| + |
| +#ifndef SK_IGNORE_TO_STRING |
| +void SkLocalMatrixImageFilter::toString(SkString* str) const { |
| + str->append("SkLocalMatrixImageFilter: ("); |
| + str->append(")"); |
| +} |
| +#endif |
| + |
| +/////////////////////////////////////////////////////////////////////////////////////////////////// |
| + |
| +SkImageFilter* SkImageFilter::newWithLocalMatrix(const SkMatrix& localMatrix) const { |
| + return SkLocalMatrixImageFilter::Create(const_cast<SkImageFilter*>(this), localMatrix); |
| +} |