diff options
author | 2013-09-26 16:09:28 +0000 | |
---|---|---|
committer | 2013-09-26 16:09:28 +0000 | |
commit | 1a4fb70c8a04db2d92ec821555f91218a989031d (patch) | |
tree | 14ac67f5ef3d1784f0c03d941d7d5b505e344920 /src/effects/SkOffsetImageFilter.cpp | |
parent | 952944144758dd3f9a8a010ec1d99cb4bd035ae4 (diff) |
Moving 4 SkImageFilter derived classes from blink to skia
There were 4 classes in blink that derived from SkImageFilter :
- TileImageFilter -> SkTileImageFilter
- OffsetImageFilter -> SkOffsetImageFilter (already existed)
- FloodImageFilter -> SkFloodImageFilter
- CompositeImageFilter -> SkCompositeImageFilter
All functions were copied as is, without modification (except for warnings fixes), except for the offset filter, which was merged into the existing SkOffsetImageFilter class, as a special case when a crop rect is provided. Since the names won't clash with the names in blink, it should be easy to integrate them in blink later and fix issues, if needed.
BUG=
R=senorblanco@google.com, senorblanco@chromium.org, bsalomon@google.com, reed@google.com, mtklein@google.com
Author: sugoi@chromium.org
Review URL: https://chromiumcodereview.appspot.com/24157005
git-svn-id: http://skia.googlecode.com/svn/trunk@11475 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/effects/SkOffsetImageFilter.cpp')
-rw-r--r-- | src/effects/SkOffsetImageFilter.cpp | 49 |
1 files changed, 38 insertions, 11 deletions
diff --git a/src/effects/SkOffsetImageFilter.cpp b/src/effects/SkOffsetImageFilter.cpp index ad5e49d776..3b98160841 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()) { + 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); } |