Line data Source code
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 "SkSpecialImage.h"
11 : #include "SkString.h"
12 :
13 0 : sk_sp<SkImageFilter> SkLocalMatrixImageFilter::Make(const SkMatrix& localM,
14 : sk_sp<SkImageFilter> input) {
15 0 : if (!input) {
16 0 : return nullptr;
17 : }
18 0 : if (localM.getType() & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)) {
19 0 : return nullptr;
20 : }
21 0 : if (localM.isIdentity()) {
22 0 : return input;
23 : }
24 0 : return sk_sp<SkImageFilter>(new SkLocalMatrixImageFilter(localM, input));
25 : }
26 :
27 0 : SkLocalMatrixImageFilter::SkLocalMatrixImageFilter(const SkMatrix& localM,
28 0 : sk_sp<SkImageFilter> input)
29 : : INHERITED(&input, 1, nullptr)
30 0 : , fLocalM(localM) {
31 0 : }
32 :
33 0 : sk_sp<SkFlattenable> SkLocalMatrixImageFilter::CreateProc(SkReadBuffer& buffer) {
34 0 : SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
35 : SkMatrix lm;
36 0 : buffer.readMatrix(&lm);
37 0 : return SkLocalMatrixImageFilter::Make(lm, common.getInput(0));
38 : }
39 :
40 0 : void SkLocalMatrixImageFilter::flatten(SkWriteBuffer& buffer) const {
41 0 : this->INHERITED::flatten(buffer);
42 0 : buffer.writeMatrix(fLocalM);
43 0 : }
44 :
45 0 : sk_sp<SkSpecialImage> SkLocalMatrixImageFilter::onFilterImage(SkSpecialImage* source,
46 : const Context& ctx,
47 : SkIPoint* offset) const {
48 0 : Context localCtx(SkMatrix::Concat(ctx.ctm(), fLocalM), ctx.clipBounds(), ctx.cache(),
49 0 : ctx.outputProperties());
50 0 : return this->filterInput(0, source, localCtx, offset);
51 : }
52 :
53 0 : SkIRect SkLocalMatrixImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& matrix,
54 : MapDirection direction) const {
55 0 : return this->getInput(0)->filterBounds(src, SkMatrix::Concat(matrix, fLocalM), direction);
56 : }
57 :
58 : #ifndef SK_IGNORE_TO_STRING
59 0 : void SkLocalMatrixImageFilter::toString(SkString* str) const {
60 0 : str->append("SkLocalMatrixImageFilter: (");
61 0 : str->append(")");
62 0 : }
63 : #endif
|