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 25 matching lines...) Expand all Loading... |
36 | 36 |
37 buffer.writeFlattenable(fShader); | 37 buffer.writeFlattenable(fShader); |
38 buffer.writeRect(fRect); | 38 buffer.writeRect(fRect); |
39 } | 39 } |
40 | 40 |
41 SkRectShaderImageFilter::~SkRectShaderImageFilter() { | 41 SkRectShaderImageFilter::~SkRectShaderImageFilter() { |
42 SkSafeUnref(fShader); | 42 SkSafeUnref(fShader); |
43 } | 43 } |
44 | 44 |
45 bool SkRectShaderImageFilter::onFilterImage(Proxy* proxy, | 45 bool SkRectShaderImageFilter::onFilterImage(Proxy* proxy, |
46 const SkBitmap& source, | 46 const SkBitmap& source, |
47 const SkMatrix& matrix, | 47 const SkMatrix&, |
48 SkBitmap* result, | 48 SkBitmap* result, |
49 SkIPoint* loc) { | 49 SkIPoint*) { |
50 SkAutoTUnref<SkDevice> device(proxy->createDevice(SkScalarCeilToInt(fRect.wi
dth()), | 50 SkRect rect(fRect); |
51 SkScalarCeilToInt(fRect.he
ight()))); | 51 if (rect.isEmpty()) { |
| 52 rect = SkRect::MakeWH(source.width(), source.height()); |
| 53 } |
| 54 |
| 55 if (rect.isEmpty()) { |
| 56 return false; |
| 57 } |
| 58 |
| 59 SkAutoTUnref<SkDevice> device(proxy->createDevice(SkScalarCeilToInt(rect.wid
th()), |
| 60 SkScalarCeilToInt(rect.hei
ght()))); |
52 SkCanvas canvas(device.get()); | 61 SkCanvas canvas(device.get()); |
53 SkPaint paint; | 62 SkPaint paint; |
54 paint.setShader(fShader); | 63 paint.setShader(fShader); |
55 canvas.drawRect(fRect, paint); | 64 canvas.drawRect(rect, paint); |
56 *result = device.get()->accessBitmap(false); | 65 *result = device.get()->accessBitmap(false); |
57 return true; | 66 return true; |
58 } | 67 } |
OLD | NEW |