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