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 |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
11 #include "SkDevice.h" | |
12 #include "SkReadBuffer.h" | |
13 #include "SkWriteBuffer.h" | |
14 #include "SkMatrix.h" | 11 #include "SkMatrix.h" |
15 #include "SkPaint.h" | 12 #include "SkPaint.h" |
| 13 #include "SkReadBuffer.h" |
| 14 #include "SkSpecialImage.h" |
| 15 #include "SkSpecialSurface.h" |
| 16 #include "SkWriteBuffer.h" |
16 | 17 |
17 bool SkOffsetImageFilter::onFilterImageDeprecated(Proxy* proxy, const SkBitmap&
source, | 18 SkSpecialImage* SkOffsetImageFilter::onFilterImage(SkSpecialImage* source, |
18 const Context& ctx, | 19 const Context& ctx, |
19 SkBitmap* result, | 20 SkIPoint* offset) const { |
20 SkIPoint* offset) const { | |
21 SkBitmap src = source; | |
22 SkIPoint srcOffset = SkIPoint::Make(0, 0); | 21 SkIPoint srcOffset = SkIPoint::Make(0, 0); |
23 if (!cropRectIsSet()) { | 22 SkAutoTUnref<SkSpecialImage> input(this->filterInput(0, source, ctx, &srcOff
set)); |
24 if (!this->filterInputDeprecated(0, proxy, source, ctx, &src, &srcOffset
)) { | 23 if (!input) { |
25 return false; | 24 return nullptr; |
| 25 } |
| 26 |
| 27 SkVector vec; |
| 28 ctx.ctm().mapVectors(&vec, &fOffset, 1); |
| 29 |
| 30 if (!this->cropRectIsSet()) { |
| 31 offset->fX = srcOffset.fX + SkScalarRoundToInt(vec.fX); |
| 32 offset->fY = srcOffset.fY + SkScalarRoundToInt(vec.fY); |
| 33 return input.release(); |
| 34 } else { |
| 35 SkIRect bounds; |
| 36 SkIRect srcBounds = SkIRect::MakeWH(input->width(), input->height()); |
| 37 srcBounds.offset(srcOffset); |
| 38 if (!this->applyCropRect(ctx, srcBounds, &bounds)) { |
| 39 return nullptr; |
26 } | 40 } |
27 | 41 |
28 SkVector vec; | 42 SkImageInfo info = SkImageInfo::MakeN32(bounds.width(), bounds.height(), |
29 ctx.ctm().mapVectors(&vec, &fOffset, 1); | 43 kPremul_SkAlphaType); |
30 | 44 SkAutoTUnref<SkSpecialSurface> surf(source->newSurface(info)); |
31 offset->fX = srcOffset.fX + SkScalarRoundToInt(vec.fX); | 45 if (!surf) { |
32 offset->fY = srcOffset.fY + SkScalarRoundToInt(vec.fY); | 46 return nullptr; |
33 *result = src; | |
34 } else { | |
35 if (!this->filterInputDeprecated(0, proxy, source, ctx, &src, &srcOffset
)) { | |
36 return false; | |
37 } | 47 } |
38 | 48 |
39 SkIRect bounds; | 49 SkCanvas* canvas = surf->getCanvas(); |
40 SkIRect srcBounds = src.bounds(); | 50 SkASSERT(canvas); |
41 srcBounds.offset(srcOffset); | |
42 if (!this->applyCropRect(ctx, srcBounds, &bounds)) { | |
43 return false; | |
44 } | |
45 | 51 |
46 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bo
unds.height())); | 52 // TODO: it seems like this clear shouldn't be necessary (see skbug.com/
5075) |
47 if (nullptr == device.get()) { | 53 canvas->clear(0x0); |
48 return false; | 54 |
49 } | |
50 SkCanvas canvas(device); | |
51 SkPaint paint; | 55 SkPaint paint; |
52 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 56 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
53 canvas.translate(SkIntToScalar(srcOffset.fX - bounds.fLeft), | 57 canvas->translate(SkIntToScalar(srcOffset.fX - bounds.fLeft), |
54 SkIntToScalar(srcOffset.fY - bounds.fTop)); | 58 SkIntToScalar(srcOffset.fY - bounds.fTop)); |
55 SkVector vec; | 59 |
56 ctx.ctm().mapVectors(&vec, &fOffset, 1); | 60 input->draw(canvas, vec.x(), vec.y(), &paint); |
57 canvas.drawBitmap(src, vec.x(), vec.y(), &paint); | 61 |
58 *result = device->accessBitmap(false); | |
59 offset->fX = bounds.fLeft; | 62 offset->fX = bounds.fLeft; |
60 offset->fY = bounds.fTop; | 63 offset->fY = bounds.fTop; |
| 64 return surf->newImageSnapshot(); |
61 } | 65 } |
62 return true; | |
63 } | 66 } |
64 | 67 |
65 void SkOffsetImageFilter::computeFastBounds(const SkRect& src, SkRect* dst) cons
t { | 68 void SkOffsetImageFilter::computeFastBounds(const SkRect& src, SkRect* dst) cons
t { |
66 if (getInput(0)) { | 69 if (getInput(0)) { |
67 getInput(0)->computeFastBounds(src, dst); | 70 getInput(0)->computeFastBounds(src, dst); |
68 } else { | 71 } else { |
69 *dst = src; | 72 *dst = src; |
70 } | 73 } |
71 dst->offset(fOffset.fX, fOffset.fY); | 74 dst->offset(fOffset.fX, fOffset.fY); |
72 } | 75 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 void SkOffsetImageFilter::toString(SkString* str) const { | 108 void SkOffsetImageFilter::toString(SkString* str) const { |
106 str->appendf("SkOffsetImageFilter: ("); | 109 str->appendf("SkOffsetImageFilter: ("); |
107 str->appendf("offset: (%f, %f) ", fOffset.fX, fOffset.fY); | 110 str->appendf("offset: (%f, %f) ", fOffset.fX, fOffset.fY); |
108 str->append("input: ("); | 111 str->append("input: ("); |
109 if (this->getInput(0)) { | 112 if (this->getInput(0)) { |
110 this->getInput(0)->toString(str); | 113 this->getInput(0)->toString(str); |
111 } | 114 } |
112 str->append("))"); | 115 str->append("))"); |
113 } | 116 } |
114 #endif | 117 #endif |
OLD | NEW |