Index: src/effects/SkRectShaderImageFilter.cpp |
diff --git a/src/effects/SkRectShaderImageFilter.cpp b/src/effects/SkRectShaderImageFilter.cpp |
index 2ee1d4a2ed6be4d712de95013d6c1a40d1a1f7a7..b1faebc813646c0a67eb4dca01f940d58445264b 100644 |
--- a/src/effects/SkRectShaderImageFilter.cpp |
+++ b/src/effects/SkRectShaderImageFilter.cpp |
@@ -14,13 +14,18 @@ |
SkRectShaderImageFilter* SkRectShaderImageFilter::Create(SkShader* s, const SkRect& rect) { |
SkASSERT(s); |
- return SkNEW_ARGS(SkRectShaderImageFilter, (s, rect)); |
+#ifdef SK_CROP_RECT_IS_INT |
+ SkIRect cropRect; |
+ rect.roundOut(&cropRect); |
+#else |
+ CropRect cropRect(rect); |
+#endif |
+ return SkNEW_ARGS(SkRectShaderImageFilter, (s, &cropRect)); |
} |
-SkRectShaderImageFilter::SkRectShaderImageFilter(SkShader* s, const SkRect& rect) |
- : INHERITED(NULL) |
- , fShader(s) |
- , fRect(rect) { |
+SkRectShaderImageFilter::SkRectShaderImageFilter(SkShader* s, const CropRect* cropRect) |
+ : INHERITED(NULL, cropRect) |
+ , fShader(s) { |
SkASSERT(s); |
s->ref(); |
} |
@@ -28,14 +33,12 @@ SkRectShaderImageFilter::SkRectShaderImageFilter(SkShader* s, const SkRect& rect |
SkRectShaderImageFilter::SkRectShaderImageFilter(SkFlattenableReadBuffer& buffer) |
: INHERITED(buffer) { |
fShader = buffer.readFlattenableT<SkShader>(); |
- buffer.readRect(&fRect); |
} |
void SkRectShaderImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const { |
this->INHERITED::flatten(buffer); |
buffer.writeFlattenable(fShader); |
- buffer.writeRect(fRect); |
} |
SkRectShaderImageFilter::~SkRectShaderImageFilter() { |
@@ -44,24 +47,27 @@ SkRectShaderImageFilter::~SkRectShaderImageFilter() { |
bool SkRectShaderImageFilter::onFilterImage(Proxy* proxy, |
const SkBitmap& source, |
- const SkMatrix&, |
+ const SkMatrix& ctm, |
SkBitmap* result, |
- SkIPoint*) { |
- SkRect rect(fRect); |
- if (rect.isEmpty()) { |
- rect = SkRect::MakeWH(SkIntToScalar(source.width()), SkIntToScalar(source.height())); |
- } |
- |
- if (rect.isEmpty()) { |
+ SkIPoint* offset) { |
+ SkIRect bounds; |
+ source.getBounds(&bounds); |
+ if (!this->applyCropRect(&bounds, ctm)) { |
return false; |
} |
- SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(SkScalarCeilToInt(rect.width()), |
- SkScalarCeilToInt(rect.height()))); |
+ SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), |
+ bounds.height())); |
SkCanvas canvas(device.get()); |
SkPaint paint; |
paint.setShader(fShader); |
+ SkMatrix matrix; |
+ matrix.setTranslate(-SkIntToScalar(bounds.fLeft), -SkIntToScalar(bounds.fTop)); |
+ fShader->setLocalMatrix(matrix); |
+ SkRect rect = SkRect::MakeWH(SkIntToScalar(bounds.width()), SkIntToScalar(bounds.height())); |
canvas.drawRect(rect, paint); |
*result = device.get()->accessBitmap(false); |
+ offset->fX += bounds.fLeft; |
+ offset->fY += bounds.fTop; |
return true; |
} |