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 "SkDevice.h" |
12 #include "SkFlattenableBuffers.h" | 12 #include "SkFlattenableBuffers.h" |
13 #include "SkShader.h" | 13 #include "SkShader.h" |
14 | 14 |
15 SkRectShaderImageFilter* SkRectShaderImageFilter::Create(SkShader* s, const SkRe
ct& rect) { | 15 SkRectShaderImageFilter* SkRectShaderImageFilter::Create(SkShader* s, const SkRe
ct& rect) { |
16 SkASSERT(s); | 16 SkASSERT(s); |
17 #ifdef SK_CROP_RECT_IS_INT | 17 #ifdef SK_CROP_RECT_IS_INT |
18 SkIRect cropRect; | 18 SkIRect cropRect; |
19 rect.roundOut(&cropRect); | 19 if (rect.width() == 0 || rect.height() == 0) { |
| 20 cropRect = SkIRect::MakeLargest(); |
| 21 } else { |
| 22 rect.roundOut(&cropRect); |
| 23 } |
20 #else | 24 #else |
21 CropRect cropRect(rect); | 25 uint32_t flags = CropRect::kHasAll_CropEdge; |
| 26 if (rect.width() == 0 || rect.height() == 0) { |
| 27 flags = 0x0; |
| 28 } |
| 29 CropRect cropRect(rect, flags); |
22 #endif | 30 #endif |
23 return SkNEW_ARGS(SkRectShaderImageFilter, (s, &cropRect)); | 31 return SkNEW_ARGS(SkRectShaderImageFilter, (s, &cropRect)); |
24 } | 32 } |
25 | 33 |
26 SkRectShaderImageFilter::SkRectShaderImageFilter(SkShader* s, const CropRect* cr
opRect) | 34 SkRectShaderImageFilter::SkRectShaderImageFilter(SkShader* s, const CropRect* cr
opRect) |
27 : INHERITED(NULL, cropRect) | 35 : INHERITED(NULL, cropRect) |
28 , fShader(s) { | 36 , fShader(s) { |
29 SkASSERT(s); | 37 SkASSERT(s); |
30 s->ref(); | 38 s->ref(); |
31 } | 39 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 SkMatrix matrix; | 72 SkMatrix matrix; |
65 matrix.setTranslate(-SkIntToScalar(bounds.fLeft), -SkIntToScalar(bounds.fTop
)); | 73 matrix.setTranslate(-SkIntToScalar(bounds.fLeft), -SkIntToScalar(bounds.fTop
)); |
66 fShader->setLocalMatrix(matrix); | 74 fShader->setLocalMatrix(matrix); |
67 SkRect rect = SkRect::MakeWH(SkIntToScalar(bounds.width()), SkIntToScalar(bo
unds.height())); | 75 SkRect rect = SkRect::MakeWH(SkIntToScalar(bounds.width()), SkIntToScalar(bo
unds.height())); |
68 canvas.drawRect(rect, paint); | 76 canvas.drawRect(rect, paint); |
69 *result = device.get()->accessBitmap(false); | 77 *result = device.get()->accessBitmap(false); |
70 offset->fX += bounds.fLeft; | 78 offset->fX += bounds.fLeft; |
71 offset->fY += bounds.fTop; | 79 offset->fY += bounds.fTop; |
72 return true; | 80 return true; |
73 } | 81 } |
OLD | NEW |