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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 void SkRectShaderImageFilter::flatten(SkWriteBuffer& buffer) const { | 42 void SkRectShaderImageFilter::flatten(SkWriteBuffer& buffer) const { |
43 this->INHERITED::flatten(buffer); | 43 this->INHERITED::flatten(buffer); |
44 buffer.writeFlattenable(fShader); | 44 buffer.writeFlattenable(fShader); |
45 } | 45 } |
46 | 46 |
47 SkRectShaderImageFilter::~SkRectShaderImageFilter() { | 47 SkRectShaderImageFilter::~SkRectShaderImageFilter() { |
48 fShader->unref(); | 48 fShader->unref(); |
49 } | 49 } |
50 | 50 |
51 bool SkRectShaderImageFilter::onFilterImage(Proxy* proxy, | 51 bool SkRectShaderImageFilter::onFilterImage(Proxy* proxy, |
52 const SkBitmap& source, | 52 const SkImage* source, |
53 const Context& ctx, | 53 const Context& ctx, |
54 SkBitmap* result, | 54 SkAutoTUnref<const SkImage>& result, |
55 SkIPoint* offset) const { | 55 SkIPoint* offset) const { |
56 SkIRect bounds; | 56 SkIRect bounds; |
57 if (!this->applyCropRect(ctx, source, SkIPoint::Make(0, 0), &bounds)) { | 57 if (!this->applyCropRect(ctx, source, SkIPoint::Make(0, 0), &bounds)) { |
58 return false; | 58 return false; |
59 } | 59 } |
60 | 60 |
61 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), | 61 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), |
62 bounds.height())); | 62 bounds.height())); |
63 if (NULL == device.get()) { | 63 if (NULL == device.get()) { |
64 return false; | 64 return false; |
65 } | 65 } |
66 SkCanvas canvas(device.get()); | 66 SkCanvas canvas(device.get()); |
67 | 67 |
68 SkPaint paint; | 68 SkPaint paint; |
69 SkMatrix matrix(ctx.ctm()); | 69 SkMatrix matrix(ctx.ctm()); |
70 matrix.postTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.to
p())); | 70 matrix.postTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.to
p())); |
71 SkSafeUnref(paint.setShader(SkShader::CreateLocalMatrixShader(fShader, matri
x))); | 71 SkSafeUnref(paint.setShader(SkShader::CreateLocalMatrixShader(fShader, matri
x))); |
72 | 72 |
73 SkRect rect = SkRect::MakeWH(SkIntToScalar(bounds.width()), SkIntToScalar(bo
unds.height())); | 73 SkRect rect = SkRect::MakeWH(SkIntToScalar(bounds.width()), SkIntToScalar(bo
unds.height())); |
74 canvas.drawRect(rect, paint); | 74 canvas.drawRect(rect, paint); |
| 75 SkImage* image = device->newImageSnapshot(); |
| 76 if (NULL == image) { |
| 77 return false; |
| 78 } |
| 79 result.reset(image); |
75 | 80 |
76 *result = device.get()->accessBitmap(false); | |
77 offset->fX = bounds.fLeft; | 81 offset->fX = bounds.fLeft; |
78 offset->fY = bounds.fTop; | 82 offset->fY = bounds.fTop; |
79 return true; | 83 return true; |
80 } | 84 } |
81 | 85 |
82 #ifndef SK_IGNORE_TO_STRING | 86 #ifndef SK_IGNORE_TO_STRING |
83 void SkRectShaderImageFilter::toString(SkString* str) const { | 87 void SkRectShaderImageFilter::toString(SkString* str) const { |
84 str->appendf("SkRectShaderImageFilter: ("); | 88 str->appendf("SkRectShaderImageFilter: ("); |
85 str->append(")"); | 89 str->append(")"); |
86 } | 90 } |
87 #endif | 91 #endif |
OLD | NEW |