aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar sugoi@google.com <sugoi@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-04-18 14:13:10 +0000
committerGravatar sugoi@google.com <sugoi@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-04-18 14:13:10 +0000
commitf738cf0689bc3f823158e29d0ba9693d89f21c93 (patch)
tree47cd50417814101c67f2cb8c7534b37895ef7b81
parent423ac13f351b22308d3b1d039ab4859540be0b9d (diff)
Adding a bit of rebustness to SkRectShaderImageFilter
Since SkRectShaderImageFilter is an image filter, I added logic so that it can actually use the size of an input image as the rect if an empty rect is provided as an argument. I also added logic to prevent creating an empty device. Review URL: https://codereview.chromium.org/14093008 git-svn-id: http://skia.googlecode.com/svn/trunk@8739 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--src/effects/SkRectShaderImageFilter.cpp23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/effects/SkRectShaderImageFilter.cpp b/src/effects/SkRectShaderImageFilter.cpp
index f5466cc2cc..aee0e63bae 100644
--- a/src/effects/SkRectShaderImageFilter.cpp
+++ b/src/effects/SkRectShaderImageFilter.cpp
@@ -43,16 +43,25 @@ SkRectShaderImageFilter::~SkRectShaderImageFilter() {
}
bool SkRectShaderImageFilter::onFilterImage(Proxy* proxy,
- const SkBitmap& source,
- const SkMatrix& matrix,
- SkBitmap* result,
- SkIPoint* loc) {
- SkAutoTUnref<SkDevice> device(proxy->createDevice(SkScalarCeilToInt(fRect.width()),
- SkScalarCeilToInt(fRect.height())));
+ const SkBitmap& source,
+ const SkMatrix&,
+ SkBitmap* result,
+ SkIPoint*) {
+ SkRect rect(fRect);
+ if (rect.isEmpty()) {
+ rect = SkRect::MakeWH(source.width(), source.height());
+ }
+
+ if (rect.isEmpty()) {
+ return false;
+ }
+
+ SkAutoTUnref<SkDevice> device(proxy->createDevice(SkScalarCeilToInt(rect.width()),
+ SkScalarCeilToInt(rect.height())));
SkCanvas canvas(device.get());
SkPaint paint;
paint.setShader(fShader);
- canvas.drawRect(fRect, paint);
+ canvas.drawRect(rect, paint);
*result = device.get()->accessBitmap(false);
return true;
}