OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2016 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 "SkPaintImageFilter.h" |
| 9 #include "SkBitmap.h" |
| 10 #include "SkCanvas.h" |
| 11 #include "SkDevice.h" |
| 12 #include "SkReadBuffer.h" |
| 13 #include "SkWriteBuffer.h" |
| 14 |
| 15 SkImageFilter* SkPaintImageFilter::Create(const SkPaint& paint, const CropRect*
cropRect) { |
| 16 return new SkPaintImageFilter(paint, cropRect); |
| 17 } |
| 18 |
| 19 SkPaintImageFilter::SkPaintImageFilter(const SkPaint& paint, const CropRect* cro
pRect) |
| 20 : INHERITED(0, nullptr, cropRect) |
| 21 , fPaint(paint) { |
| 22 } |
| 23 |
| 24 SkFlattenable* SkPaintImageFilter::CreateProc(SkReadBuffer& buffer) { |
| 25 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 0); |
| 26 SkPaint paint; |
| 27 buffer.readPaint(&paint); |
| 28 return Create(paint, &common.cropRect()); |
| 29 } |
| 30 |
| 31 void SkPaintImageFilter::flatten(SkWriteBuffer& buffer) const { |
| 32 this->INHERITED::flatten(buffer); |
| 33 buffer.writePaint(fPaint); |
| 34 } |
| 35 |
| 36 bool SkPaintImageFilter::onFilterImage(Proxy* proxy, |
| 37 const SkBitmap& source, |
| 38 const Context& ctx, |
| 39 SkBitmap* result, |
| 40 SkIPoint* offset) const { |
| 41 SkIRect bounds; |
| 42 if (!this->applyCropRect(ctx, source, SkIPoint::Make(0, 0), &bounds)) { |
| 43 return false; |
| 44 } |
| 45 |
| 46 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), |
| 47 bounds.height())); |
| 48 if (nullptr == device.get()) { |
| 49 return false; |
| 50 } |
| 51 SkCanvas canvas(device.get()); |
| 52 |
| 53 SkMatrix matrix(ctx.ctm()); |
| 54 matrix.postTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.to
p())); |
| 55 SkRect rect = SkRect::MakeWH(SkIntToScalar(bounds.width()), SkIntToScalar(bo
unds.height())); |
| 56 SkMatrix inverse; |
| 57 if (matrix.invert(&inverse)) { |
| 58 inverse.mapRect(&rect); |
| 59 } |
| 60 canvas.setMatrix(matrix); |
| 61 canvas.drawRect(rect, fPaint); |
| 62 |
| 63 *result = device.get()->accessBitmap(false); |
| 64 offset->fX = bounds.fLeft; |
| 65 offset->fY = bounds.fTop; |
| 66 return true; |
| 67 } |
| 68 |
| 69 bool SkPaintImageFilter::canComputeFastBounds() const { |
| 70 // http:skbug.com/4627: "make computeFastBounds and onFilterBounds() CropRec
t-aware" |
| 71 // computeFastBounds() doesn't currently take the crop rect into account, |
| 72 // so we can't compute it. If a full crop rect is set, we should return true
here. |
| 73 return false; |
| 74 } |
| 75 |
| 76 #ifndef SK_IGNORE_TO_STRING |
| 77 void SkPaintImageFilter::toString(SkString* str) const { |
| 78 str->appendf("SkPaintImageFilter: ("); |
| 79 str->append(")"); |
| 80 } |
| 81 #endif |
OLD | NEW |