1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkLocalMatrixImageFilter.h"
9 #include "SkReadBuffer.h"
10 #include "SkString.h"
11
Create(const SkMatrix & localM,SkImageFilter * input)12 SkImageFilter* SkLocalMatrixImageFilter::Create(const SkMatrix& localM, SkImageFilter* input) {
13 if (!input) {
14 return nullptr;
15 }
16 if (localM.getType() & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)) {
17 return nullptr;
18 }
19 if (localM.isIdentity()) {
20 return SkRef(input);
21 }
22 return new SkLocalMatrixImageFilter(localM, input);
23 }
24
SkLocalMatrixImageFilter(const SkMatrix & localM,SkImageFilter * input)25 SkLocalMatrixImageFilter::SkLocalMatrixImageFilter(const SkMatrix& localM, SkImageFilter* input)
26 : INHERITED(1, &input), fLocalM(localM)
27 {}
28
CreateProc(SkReadBuffer & buffer)29 SkFlattenable* SkLocalMatrixImageFilter::CreateProc(SkReadBuffer& buffer) {
30 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
31 SkMatrix lm;
32 buffer.readMatrix(&lm);
33 return SkLocalMatrixImageFilter::Create(lm, common.getInput(0));
34 }
35
flatten(SkWriteBuffer & buffer) const36 void SkLocalMatrixImageFilter::flatten(SkWriteBuffer& buffer) const {
37 this->INHERITED::flatten(buffer);
38 buffer.writeMatrix(fLocalM);
39 }
40
onFilterImageDeprecated(Proxy * proxy,const SkBitmap & src,const Context & ctx,SkBitmap * result,SkIPoint * offset) const41 bool SkLocalMatrixImageFilter::onFilterImageDeprecated(Proxy* proxy, const SkBitmap& src,
42 const Context& ctx,
43 SkBitmap* result, SkIPoint* offset) const {
44 Context localCtx(SkMatrix::Concat(ctx.ctm(), fLocalM), ctx.clipBounds(), ctx.cache());
45 return this->filterInputDeprecated(0, proxy, src, localCtx, result, offset);
46 }
47
onFilterBounds(const SkIRect & src,const SkMatrix & matrix,SkIRect * dst,MapDirection direction) const48 bool SkLocalMatrixImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& matrix,
49 SkIRect* dst, MapDirection direction) const {
50 return this->getInput(0)->filterBounds(src, SkMatrix::Concat(matrix, fLocalM), dst, direction);
51 }
52
53 #ifndef SK_IGNORE_TO_STRING
toString(SkString * str) const54 void SkLocalMatrixImageFilter::toString(SkString* str) const {
55 str->append("SkLocalMatrixImageFilter: (");
56 str->append(")");
57 }
58 #endif
59