Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Unified Diff: src/effects/SkRectShaderImageFilter.cpp

Issue 26009004: Implement crop rect support for SkRectShaderImageFilter (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Updated to new CropRect API Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/effects/SkRectShaderImageFilter.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
}
« no previous file with comments | « include/effects/SkRectShaderImageFilter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698