Chromium Code Reviews| 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" | |
| 11 #include "SkDevice.h" | |
| 12 #include "SkFlattenableBuffers.h" | |
| 10 #include "SkMatrix.h" | 13 #include "SkMatrix.h" |
| 11 #include "SkFlattenableBuffers.h" | 14 #include "SkPaint.h" |
| 12 | 15 |
| 13 bool SkOffsetImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& source, | 16 bool SkOffsetImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& source, |
| 14 const SkMatrix& matrix, | 17 const SkMatrix& matrix, |
| 15 SkBitmap* result, | 18 SkBitmap* result, |
| 16 SkIPoint* loc) { | 19 SkIPoint* loc) { |
| 20 SkImageFilter* input = getInput(0); | |
| 17 SkBitmap src = source; | 21 SkBitmap src = source; |
| 18 if (getInput(0) && !getInput(0)->filterImage(proxy, source, matrix, &src, lo c)) { | 22 if (cropRect().isLargest()) { |
| 19 return false; | 23 if (input && !input->filterImage(proxy, source, matrix, &src, loc)) { |
| 24 return false; | |
| 25 } | |
| 26 | |
| 27 SkVector vec; | |
| 28 matrix.mapVectors(&vec, &fOffset, 1); | |
| 29 | |
| 30 loc->fX += SkScalarRoundToInt(vec.fX); | |
| 31 loc->fY += SkScalarRoundToInt(vec.fY); | |
| 32 *result = src; | |
| 33 } else { | |
| 34 SkIPoint srcOffset = SkIPoint::Make(0, 0); | |
|
sugoi1
2013/09/23 18:37:30
@senorblanco : Was there a reason here why we aren
Stephen White
2013/09/24 01:13:19
Since this path draws its input into a buffer, it'
sugoi1
2013/09/24 11:39:50
Thanks for the explanation, I wanted to make sure
| |
| 35 if (input && !input->filterImage(proxy, source, matrix, &src, &srcOffset )) { | |
| 36 return false; | |
| 37 } | |
| 38 | |
| 39 SkIRect bounds; | |
| 40 src.getBounds(&bounds); | |
| 41 | |
| 42 if (!applyCropRect(&bounds, matrix)) { | |
| 43 return false; | |
| 44 } | |
| 45 | |
| 46 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bo unds.height())); | |
| 47 SkCanvas canvas(device); | |
| 48 SkPaint paint; | |
| 49 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | |
| 50 canvas.drawBitmap(src, fOffset.fX - bounds.left(), fOffset.fY - bounds.t op(), &paint); | |
| 51 *result = device->accessBitmap(false); | |
| 52 loc->fX += bounds.left(); | |
| 53 loc->fY += bounds.top(); | |
| 20 } | 54 } |
| 21 | |
| 22 SkVector vec; | |
| 23 matrix.mapVectors(&vec, &fOffset, 1); | |
| 24 | |
| 25 loc->fX += SkScalarRoundToInt(vec.fX); | |
| 26 loc->fY += SkScalarRoundToInt(vec.fY); | |
| 27 *result = src; | |
| 28 return true; | 55 return true; |
| 29 } | 56 } |
| 30 | 57 |
| 31 bool SkOffsetImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& ctm , | 58 bool SkOffsetImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& ctm , |
| 32 SkIRect* dst) { | 59 SkIRect* dst) { |
| 33 SkVector vec; | 60 SkVector vec; |
| 34 ctm.mapVectors(&vec, &fOffset, 1); | 61 ctm.mapVectors(&vec, &fOffset, 1); |
| 35 | 62 |
| 36 *dst = src; | 63 *dst = src; |
| 37 dst->offset(SkScalarRoundToInt(vec.fX), SkScalarRoundToInt(vec.fY)); | 64 dst->offset(SkScalarRoundToInt(vec.fX), SkScalarRoundToInt(vec.fY)); |
| 38 return true; | 65 return true; |
| 39 } | 66 } |
| 40 | 67 |
| 41 void SkOffsetImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const { | 68 void SkOffsetImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const { |
| 42 this->INHERITED::flatten(buffer); | 69 this->INHERITED::flatten(buffer); |
| 43 buffer.writePoint(fOffset); | 70 buffer.writePoint(fOffset); |
| 44 } | 71 } |
| 45 | 72 |
| 46 SkOffsetImageFilter::SkOffsetImageFilter(SkScalar dx, SkScalar dy, | 73 SkOffsetImageFilter::SkOffsetImageFilter(SkScalar dx, SkScalar dy, SkImageFilter * input, |
| 47 SkImageFilter* input) : INHERITED(input ) { | 74 const SkIRect* cropRect) : INHERITED(in put, cropRect) { |
| 48 fOffset.set(dx, dy); | 75 fOffset.set(dx, dy); |
| 49 } | 76 } |
| 50 | 77 |
| 51 SkOffsetImageFilter::SkOffsetImageFilter(SkFlattenableReadBuffer& buffer) : INHE RITED(buffer) { | 78 SkOffsetImageFilter::SkOffsetImageFilter(SkFlattenableReadBuffer& buffer) : INHE RITED(buffer) { |
| 52 buffer.readPoint(&fOffset); | 79 buffer.readPoint(&fOffset); |
| 53 } | 80 } |
| OLD | NEW |