OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2013 The Android Open Source Project |
| 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 "SkFloodImageFilter.h" |
| 9 #include "SkBitmap.h" |
| 10 #include "SkCanvas.h" |
| 11 #include "SkDevice.h" |
| 12 #include "SkFlattenableBuffers.h" |
| 13 #include "SkMatrix.h" |
| 14 #include "SkPaint.h" |
| 15 |
| 16 SkFloodImageFilter::SkFloodImageFilter(SkFlattenableReadBuffer& buffer) : INHERI
TED(buffer) { |
| 17 fColor = buffer.readColor(); |
| 18 } |
| 19 |
| 20 void SkFloodImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const { |
| 21 this->INHERITED::flatten(buffer); |
| 22 buffer.writeColor(fColor); |
| 23 } |
| 24 |
| 25 bool SkFloodImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& src, const
SkMatrix& ctm, |
| 26 SkBitmap* result, SkIPoint* offset) { |
| 27 if (!src.width() || !src.height()) { |
| 28 return false; |
| 29 } |
| 30 |
| 31 SkIRect bounds; |
| 32 src.getBounds(&bounds); |
| 33 if (!applyCropRect(&bounds, ctm)) { |
| 34 return false; |
| 35 } |
| 36 |
| 37 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds
.height())); |
| 38 SkCanvas canvas(device.get()); |
| 39 SkPaint paint; |
| 40 paint.setColor(fColor); |
| 41 canvas.drawRect(SkRect::MakeWH(SkIntToScalar(src.width()), |
| 42 SkIntToScalar(src.height())), paint); |
| 43 *result = device->accessBitmap(false); |
| 44 offset->fX += bounds.left(); |
| 45 offset->fY += bounds.top(); |
| 46 return true; |
| 47 } |
OLD | NEW |