OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
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 "SkRectShaderImageFilter.h" | 8 #include "SkRectShaderImageFilter.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 buffer.writeFlattenable(fShader); | 46 buffer.writeFlattenable(fShader); |
47 } | 47 } |
48 | 48 |
49 SkRectShaderImageFilter::~SkRectShaderImageFilter() { | 49 SkRectShaderImageFilter::~SkRectShaderImageFilter() { |
50 SkSafeUnref(fShader); | 50 SkSafeUnref(fShader); |
51 } | 51 } |
52 | 52 |
53 bool SkRectShaderImageFilter::onFilterImage(Proxy* proxy, | 53 bool SkRectShaderImageFilter::onFilterImage(Proxy* proxy, |
54 const SkBitmap& source, | 54 const SkBitmap& source, |
55 const SkMatrix& ctm, | 55 const Context& ctx, |
56 SkBitmap* result, | 56 SkBitmap* result, |
57 SkIPoint* offset) const { | 57 SkIPoint* offset) const { |
58 SkIRect bounds; | 58 SkIRect bounds; |
59 source.getBounds(&bounds); | 59 source.getBounds(&bounds); |
60 if (!this->applyCropRect(&bounds, ctm)) { | 60 if (!this->applyCropRect(&bounds, ctx.ctm())) { |
61 return false; | 61 return false; |
62 } | 62 } |
63 | 63 |
64 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), | 64 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), |
65 bounds.height())); | 65 bounds.height())); |
66 if (NULL == device.get()) { | 66 if (NULL == device.get()) { |
67 return false; | 67 return false; |
68 } | 68 } |
69 SkCanvas canvas(device.get()); | 69 SkCanvas canvas(device.get()); |
70 SkPaint paint; | 70 SkPaint paint; |
71 paint.setShader(fShader); | 71 paint.setShader(fShader); |
72 SkMatrix matrix(ctm); | 72 SkMatrix matrix(ctx.ctm()); |
73 matrix.postTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.to
p())); | 73 matrix.postTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.to
p())); |
74 fShader->setLocalMatrix(matrix); | 74 fShader->setLocalMatrix(matrix); |
75 SkRect rect = SkRect::MakeWH(SkIntToScalar(bounds.width()), SkIntToScalar(bo
unds.height())); | 75 SkRect rect = SkRect::MakeWH(SkIntToScalar(bounds.width()), SkIntToScalar(bo
unds.height())); |
76 canvas.drawRect(rect, paint); | 76 canvas.drawRect(rect, paint); |
77 *result = device.get()->accessBitmap(false); | 77 *result = device.get()->accessBitmap(false); |
78 offset->fX = bounds.fLeft; | 78 offset->fX = bounds.fLeft; |
79 offset->fY = bounds.fTop; | 79 offset->fY = bounds.fTop; |
80 return true; | 80 return true; |
81 } | 81 } |
OLD | NEW |