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

Unified Diff: src/effects/SkOffsetImageFilter.cpp

Issue 24157005: Moving 4 SkImageFilter derived classes from blink to skia (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Added gm tests Created 7 years, 3 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
Index: src/effects/SkOffsetImageFilter.cpp
diff --git a/src/effects/SkOffsetImageFilter.cpp b/src/effects/SkOffsetImageFilter.cpp
index ad5e49d776256b8e0c54deb17ca73ed9681dd056..3b98160841bbef6840f2b837592811eb92ad343a 100644
--- a/src/effects/SkOffsetImageFilter.cpp
+++ b/src/effects/SkOffsetImageFilter.cpp
@@ -7,24 +7,51 @@
#include "SkOffsetImageFilter.h"
#include "SkBitmap.h"
-#include "SkMatrix.h"
+#include "SkCanvas.h"
+#include "SkDevice.h"
#include "SkFlattenableBuffers.h"
+#include "SkMatrix.h"
+#include "SkPaint.h"
bool SkOffsetImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& source,
const SkMatrix& matrix,
SkBitmap* result,
SkIPoint* loc) {
+ SkImageFilter* input = getInput(0);
SkBitmap src = source;
- if (getInput(0) && !getInput(0)->filterImage(proxy, source, matrix, &src, loc)) {
- return false;
- }
+ if (cropRect().isLargest()) {
Stephen White 2013/09/25 18:11:50 So is this stanza still needed?
Stephen White 2013/09/25 18:13:54 Er, ignore that. Not enough coffee...
+ if (input && !input->filterImage(proxy, source, matrix, &src, loc)) {
+ return false;
+ }
- SkVector vec;
- matrix.mapVectors(&vec, &fOffset, 1);
+ SkVector vec;
+ matrix.mapVectors(&vec, &fOffset, 1);
- loc->fX += SkScalarRoundToInt(vec.fX);
- loc->fY += SkScalarRoundToInt(vec.fY);
- *result = src;
+ loc->fX += SkScalarRoundToInt(vec.fX);
+ loc->fY += SkScalarRoundToInt(vec.fY);
+ *result = src;
+ } else {
+ SkIPoint srcOffset = SkIPoint::Make(0, 0);
+ if (input && !input->filterImage(proxy, source, matrix, &src, &srcOffset)) {
+ return false;
+ }
+
+ SkIRect bounds;
+ src.getBounds(&bounds);
+
+ if (!applyCropRect(&bounds, matrix)) {
+ return false;
+ }
+
+ SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds.height()));
+ SkCanvas canvas(device);
+ SkPaint paint;
+ paint.setXfermodeMode(SkXfermode::kSrc_Mode);
+ canvas.drawBitmap(src, fOffset.fX - bounds.left(), fOffset.fY - bounds.top(), &paint);
+ *result = device->accessBitmap(false);
+ loc->fX += bounds.left();
+ loc->fY += bounds.top();
+ }
return true;
}
@@ -43,8 +70,8 @@ void SkOffsetImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const {
buffer.writePoint(fOffset);
}
-SkOffsetImageFilter::SkOffsetImageFilter(SkScalar dx, SkScalar dy,
- SkImageFilter* input) : INHERITED(input) {
+SkOffsetImageFilter::SkOffsetImageFilter(SkScalar dx, SkScalar dy, SkImageFilter* input,
+ const SkIRect* cropRect) : INHERITED(input, cropRect) {
fOffset.set(dx, dy);
}

Powered by Google App Engine
This is Rietveld 408576698