OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The Android Open Source Project | 2 * Copyright 2012 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkOffsetImageFilter.h" | 8 #include "SkOffsetImageFilter.h" |
9 | 9 |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
11 #include "SkMatrix.h" | 11 #include "SkMatrix.h" |
12 #include "SkPaint.h" | 12 #include "SkPaint.h" |
13 #include "SkReadBuffer.h" | 13 #include "SkReadBuffer.h" |
14 #include "SkSpecialImage.h" | 14 #include "SkSpecialImage.h" |
15 #include "SkSpecialSurface.h" | 15 #include "SkSpecialSurface.h" |
16 #include "SkWriteBuffer.h" | 16 #include "SkWriteBuffer.h" |
17 | 17 |
18 SkSpecialImage* SkOffsetImageFilter::onFilterImage(SkSpecialImage* source, | 18 sk_sp<SkSpecialImage> SkOffsetImageFilter::onFilterImage(SkSpecialImage* source, |
19 const Context& ctx, | 19 const Context& ctx, |
20 SkIPoint* offset) const { | 20 SkIPoint* offset) const
{ |
21 SkIPoint srcOffset = SkIPoint::Make(0, 0); | 21 SkIPoint srcOffset = SkIPoint::Make(0, 0); |
22 SkAutoTUnref<SkSpecialImage> input(this->filterInput(0, source, ctx, &srcOff
set)); | 22 sk_sp<SkSpecialImage> input(this->filterInput(0, source, ctx, &srcOffset)); |
23 if (!input) { | 23 if (!input) { |
24 return nullptr; | 24 return nullptr; |
25 } | 25 } |
26 | 26 |
27 SkVector vec; | 27 SkVector vec; |
28 ctx.ctm().mapVectors(&vec, &fOffset, 1); | 28 ctx.ctm().mapVectors(&vec, &fOffset, 1); |
29 | 29 |
30 if (!this->cropRectIsSet()) { | 30 if (!this->cropRectIsSet()) { |
31 offset->fX = srcOffset.fX + SkScalarRoundToInt(vec.fX); | 31 offset->fX = srcOffset.fX + SkScalarRoundToInt(vec.fX); |
32 offset->fY = srcOffset.fY + SkScalarRoundToInt(vec.fY); | 32 offset->fY = srcOffset.fY + SkScalarRoundToInt(vec.fY); |
33 return input.release(); | 33 return input; |
34 } else { | 34 } else { |
35 SkIRect bounds; | 35 SkIRect bounds; |
36 SkIRect srcBounds = SkIRect::MakeWH(input->width(), input->height()); | 36 SkIRect srcBounds = SkIRect::MakeWH(input->width(), input->height()); |
37 srcBounds.offset(srcOffset); | 37 srcBounds.offset(srcOffset); |
38 if (!this->applyCropRect(ctx, srcBounds, &bounds)) { | 38 if (!this->applyCropRect(ctx, srcBounds, &bounds)) { |
39 return nullptr; | 39 return nullptr; |
40 } | 40 } |
41 | 41 |
42 SkImageInfo info = SkImageInfo::MakeN32(bounds.width(), bounds.height(), | 42 SkImageInfo info = SkImageInfo::MakeN32(bounds.width(), bounds.height(), |
43 kPremul_SkAlphaType); | 43 kPremul_SkAlphaType); |
(...skipping 10 matching lines...) Expand all Loading... |
54 | 54 |
55 SkPaint paint; | 55 SkPaint paint; |
56 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 56 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
57 canvas->translate(SkIntToScalar(srcOffset.fX - bounds.fLeft), | 57 canvas->translate(SkIntToScalar(srcOffset.fX - bounds.fLeft), |
58 SkIntToScalar(srcOffset.fY - bounds.fTop)); | 58 SkIntToScalar(srcOffset.fY - bounds.fTop)); |
59 | 59 |
60 input->draw(canvas, vec.x(), vec.y(), &paint); | 60 input->draw(canvas, vec.x(), vec.y(), &paint); |
61 | 61 |
62 offset->fX = bounds.fLeft; | 62 offset->fX = bounds.fLeft; |
63 offset->fY = bounds.fTop; | 63 offset->fY = bounds.fTop; |
64 return surf->makeImageSnapshot().release(); | 64 return surf->makeImageSnapshot(); |
65 } | 65 } |
66 } | 66 } |
67 | 67 |
68 SkRect SkOffsetImageFilter::computeFastBounds(const SkRect& src) const { | 68 SkRect SkOffsetImageFilter::computeFastBounds(const SkRect& src) const { |
69 SkRect bounds = this->getInput(0) ? this->getInput(0)->computeFastBounds(src
) : src; | 69 SkRect bounds = this->getInput(0) ? this->getInput(0)->computeFastBounds(src
) : src; |
70 bounds.offset(fOffset.fX, fOffset.fY); | 70 bounds.offset(fOffset.fX, fOffset.fY); |
71 return bounds; | 71 return bounds; |
72 } | 72 } |
73 | 73 |
74 SkIRect SkOffsetImageFilter::onFilterNodeBounds(const SkIRect& src, const SkMatr
ix& ctm, | 74 SkIRect SkOffsetImageFilter::onFilterNodeBounds(const SkIRect& src, const SkMatr
ix& ctm, |
(...skipping 29 matching lines...) Expand all Loading... |
104 void SkOffsetImageFilter::toString(SkString* str) const { | 104 void SkOffsetImageFilter::toString(SkString* str) const { |
105 str->appendf("SkOffsetImageFilter: ("); | 105 str->appendf("SkOffsetImageFilter: ("); |
106 str->appendf("offset: (%f, %f) ", fOffset.fX, fOffset.fY); | 106 str->appendf("offset: (%f, %f) ", fOffset.fX, fOffset.fY); |
107 str->append("input: ("); | 107 str->append("input: ("); |
108 if (this->getInput(0)) { | 108 if (this->getInput(0)) { |
109 this->getInput(0)->toString(str); | 109 this->getInput(0)->toString(str); |
110 } | 110 } |
111 str->append("))"); | 111 str->append("))"); |
112 } | 112 } |
113 #endif | 113 #endif |
OLD | NEW |