OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2013 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 "SkTileImageFilter.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 #include "SkShader.h" |
| 16 |
| 17 bool SkTileImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& src, const S
kMatrix& ctm, |
| 18 SkBitmap* dst, SkIPoint* offset) { |
| 19 SkBitmap source = src; |
| 20 SkImageFilter* input = getInput(0); |
| 21 SkIPoint localOffset = SkIPoint::Make(0, 0); |
| 22 if (input && !input->filterImage(proxy, src, ctm, &source, &localOffset)) { |
| 23 return false; |
| 24 } |
| 25 |
| 26 int w = SkScalarTruncToInt(fDstRect.width()); |
| 27 int h = SkScalarTruncToInt(fDstRect.height()); |
| 28 if (!fSrcRect.width() || !fSrcRect.height() || !w || !h) { |
| 29 return false; |
| 30 } |
| 31 |
| 32 SkIRect srcRect; |
| 33 fSrcRect.roundOut(&srcRect); |
| 34 SkBitmap subset; |
| 35 if (!source.extractSubset(&subset, srcRect)) { |
| 36 return false; |
| 37 } |
| 38 |
| 39 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(w, h)); |
| 40 SkIRect bounds; |
| 41 source.getBounds(&bounds); |
| 42 SkCanvas canvas(device); |
| 43 SkPaint paint; |
| 44 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
| 45 |
| 46 SkAutoTUnref<SkShader> shader(SkShader::CreateBitmapShader(subset, |
| 47 SkShader::kRepeat_TileMode, SkShader::kRepeat_
TileMode)); |
| 48 paint.setShader(shader); |
| 49 SkRect dstRect = fDstRect; |
| 50 dstRect.offset(SkIntToScalar(localOffset.fX), SkIntToScalar(localOffset.fY))
; |
| 51 canvas.drawRect(dstRect, paint); |
| 52 *dst = device->accessBitmap(false); |
| 53 return true; |
| 54 } |
| 55 |
| 56 SkTileImageFilter::SkTileImageFilter(SkFlattenableReadBuffer& buffer) : INHERITE
D(buffer) { |
| 57 buffer.readRect(&fSrcRect); |
| 58 buffer.readRect(&fDstRect); |
| 59 } |
| 60 |
| 61 void SkTileImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const { |
| 62 this->INHERITED::flatten(buffer); |
| 63 buffer.writeRect(fSrcRect); |
| 64 buffer.writeRect(fDstRect); |
| 65 } |
| 66 |
OLD | NEW |