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 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
11 #include "SkDevice.h" | 11 #include "SkDevice.h" |
12 #include "SkReadBuffer.h" | 12 #include "SkReadBuffer.h" |
13 #include "SkWriteBuffer.h" | 13 #include "SkWriteBuffer.h" |
14 #include "SkMatrix.h" | 14 #include "SkMatrix.h" |
15 #include "SkPaint.h" | 15 #include "SkPaint.h" |
16 #include "SkSpecialImage.h" | |
17 #include "SkSpecialSurface.h" | |
18 | |
19 SkSpecialImage* SkOffsetImageFilter::onFilterImage(SkSpecialImage* srcIn, | |
20 const Context& ctx, | |
21 SkIPoint* offset) const { | |
22 SkIPoint srcOffset = SkIPoint::Make(0, 0); | |
23 SkAutoTUnref<SkSpecialImage> src(this->filterInput(0, srcIn, ctx, &srcOffset )); | |
24 if (!src) { | |
25 return nullptr; | |
26 } | |
27 | |
28 SkVector vec; | |
29 ctx.ctm().mapVectors(&vec, &fOffset, 1); | |
30 | |
31 if (!this->cropRectIsSet()) { | |
32 offset->fX = srcOffset.fX + SkScalarRoundToInt(vec.fX); | |
33 offset->fY = srcOffset.fY + SkScalarRoundToInt(vec.fY); | |
34 return src.release(); | |
35 } else { | |
36 SkIRect bounds; | |
37 SkIRect srcBounds = SkIRect::MakeWH(srcIn->width(), srcIn->height()); | |
38 srcBounds.offset(srcOffset); | |
39 if (!this->applyCropRect(ctx, srcBounds, &bounds)) { | |
40 return false; | |
41 } | |
42 | |
43 SkImageInfo info = SkImageInfo::MakeN32(bounds.width(), bounds.height(), | |
44 kPremul_SkAlphaType); | |
45 // TODO: need to plumb MSAA sampleCount down to here! | |
Stephen White
2016/02/18 17:56:18
I don't think we should (except for the original p
robertphillips
2016/02/19 19:37:59
Done. I agree that all the draws performed by the
| |
46 SkAutoTUnref<SkSpecialSurface> surf(src->newSurface(info)); | |
47 if (!surf) { | |
48 return nullptr; | |
49 } | |
50 | |
51 SkCanvas* canvas = surf->getCanvas(); | |
52 | |
53 canvas->clear(0x0); | |
54 | |
55 SkPaint paint; | |
56 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | |
57 canvas->translate(SkIntToScalar(srcOffset.fX - bounds.fLeft), | |
58 SkIntToScalar(srcOffset.fY - bounds.fTop)); | |
59 | |
60 src->draw(canvas, vec.x(), vec.y(), &paint); | |
61 | |
62 offset->fX = bounds.fLeft; | |
63 offset->fY = bounds.fTop; | |
64 return surf->newImageSnapshot(); | |
65 } | |
66 } | |
16 | 67 |
17 bool SkOffsetImageFilter::onFilterImageDeprecated(Proxy* proxy, const SkBitmap& source, | 68 bool SkOffsetImageFilter::onFilterImageDeprecated(Proxy* proxy, const SkBitmap& source, |
Stephen White
2016/02/18 17:56:18
Can we not simply remove this function now? When d
robertphillips
2016/02/19 19:37:59
It can still be called when the offset image filte
Stephen White
2016/02/19 19:53:55
Could we also switch over the callsites (in SkCanv
robertphillips
2016/02/22 15:21:58
I think that should probably be its own patch. We
Stephen White
2016/02/22 15:42:38
OK, just to clarify: you're saying
1) Land the Sk
| |
18 const Context& ctx, | 69 const Context& ctx, |
19 SkBitmap* result, | 70 SkBitmap* result, |
20 SkIPoint* offset) const { | 71 SkIPoint* offset) const { |
21 SkBitmap src = source; | 72 SkAutoTUnref<SkSpecialImage> specialSrc(SkSpecialImage::internal_fromBM(prox y, source)); |
22 SkIPoint srcOffset = SkIPoint::Make(0, 0); | 73 if (!specialSrc) { |
23 if (!cropRectIsSet()) { | 74 return false; |
24 if (!this->filterInputDeprecated(0, proxy, source, ctx, &src, &srcOffset )) { | 75 } |
25 return false; | |
26 } | |
27 | 76 |
28 SkVector vec; | 77 SkAutoTUnref<SkSpecialImage> tmp(this->onFilterImage(specialSrc, ctx, offset )); |
29 ctx.ctm().mapVectors(&vec, &fOffset, 1); | 78 if (!tmp) { |
79 return false; | |
80 } | |
30 | 81 |
31 offset->fX = srcOffset.fX + SkScalarRoundToInt(vec.fX); | 82 return tmp->internal_getBM(result); |
32 offset->fY = srcOffset.fY + SkScalarRoundToInt(vec.fY); | |
33 *result = src; | |
34 } else { | |
35 if (!this->filterInputDeprecated(0, proxy, source, ctx, &src, &srcOffset )) { | |
36 return false; | |
37 } | |
38 | |
39 SkIRect bounds; | |
40 SkIRect srcBounds = src.bounds(); | |
41 srcBounds.offset(srcOffset); | |
42 if (!this->applyCropRect(ctx, srcBounds, &bounds)) { | |
43 return false; | |
44 } | |
45 | |
46 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bo unds.height())); | |
47 if (nullptr == device.get()) { | |
48 return false; | |
49 } | |
50 SkCanvas canvas(device); | |
51 SkPaint paint; | |
52 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | |
53 canvas.translate(SkIntToScalar(srcOffset.fX - bounds.fLeft), | |
54 SkIntToScalar(srcOffset.fY - bounds.fTop)); | |
55 SkVector vec; | |
56 ctx.ctm().mapVectors(&vec, &fOffset, 1); | |
57 canvas.drawBitmap(src, vec.x(), vec.y(), &paint); | |
58 *result = device->accessBitmap(false); | |
59 offset->fX = bounds.fLeft; | |
60 offset->fY = bounds.fTop; | |
61 } | |
62 return true; | |
63 } | 83 } |
64 | 84 |
65 void SkOffsetImageFilter::computeFastBounds(const SkRect& src, SkRect* dst) cons t { | 85 void SkOffsetImageFilter::computeFastBounds(const SkRect& src, SkRect* dst) cons t { |
66 if (getInput(0)) { | 86 if (getInput(0)) { |
67 getInput(0)->computeFastBounds(src, dst); | 87 getInput(0)->computeFastBounds(src, dst); |
68 } else { | 88 } else { |
69 *dst = src; | 89 *dst = src; |
70 } | 90 } |
71 dst->offset(fOffset.fX, fOffset.fY); | 91 dst->offset(fOffset.fX, fOffset.fY); |
72 } | 92 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 void SkOffsetImageFilter::toString(SkString* str) const { | 125 void SkOffsetImageFilter::toString(SkString* str) const { |
106 str->appendf("SkOffsetImageFilter: ("); | 126 str->appendf("SkOffsetImageFilter: ("); |
107 str->appendf("offset: (%f, %f) ", fOffset.fX, fOffset.fY); | 127 str->appendf("offset: (%f, %f) ", fOffset.fX, fOffset.fY); |
108 str->append("input: ("); | 128 str->append("input: ("); |
109 if (this->getInput(0)) { | 129 if (this->getInput(0)) { |
110 this->getInput(0)->toString(str); | 130 this->getInput(0)->toString(str); |
111 } | 131 } |
112 str->append("))"); | 132 str->append("))"); |
113 } | 133 } |
114 #endif | 134 #endif |
OLD | NEW |