Implement offset for GPU filter path. Although we can't yet use this in Blink for FEOffset, due to SVG semantics, we can use it to support crop rect (upcoming patch).
This patch adds the parameter to the filterImageGPU() signature, plumbs through the code on the GPU side, and implements support for it in SkXfermodeImageFilter for both raster and GPU.
Of the remaining filters with GPU implementations, Blur, Morphology, Bicubic and Displacement work fine; they're commutative wrt offset and can simply pass it up the chain. Blend is not, but will be removed shortly anyway (has been replaced with SkXfermodeImageFilter in Blink).
R=reed@google.com, bsalomon@google.com
Author: senorblanco@chromium.org
Review URL: https://chromiumcodereview.appspot.com/15995026
git-svn-id: http://skia.googlecode.com/svn/trunk@9977 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gm/xfermodeimagefilter.cpp b/gm/xfermodeimagefilter.cpp
index a6d395e..e602c70 100644
--- a/gm/xfermodeimagefilter.cpp
+++ b/gm/xfermodeimagefilter.cpp
@@ -7,6 +7,7 @@
#include "gm.h"
#include "SkArithmeticMode.h"
+#include "SkOffsetImageFilter.h"
#include "SkXfermodeImageFilter.h"
#include "SkBitmapSource.h"
@@ -68,7 +69,8 @@
return make_isize(WIDTH, HEIGHT);
}
- void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, const SkPaint& paint, SkScalar x, SkScalar y) {
+ void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, const SkPaint& paint,
+ SkScalar x, SkScalar y) {
canvas->save();
canvas->clipRect(SkRect::MakeXYWH(x, y,
SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height())));
@@ -125,7 +127,8 @@
SkAutoTUnref<SkImageFilter> background(SkNEW_ARGS(SkBitmapSource, (fCheckerboard)));
for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) {
SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(gModes[i].fMode));
- SkAutoTUnref<SkImageFilter> filter(SkNEW_ARGS(SkXfermodeImageFilter, (mode, background)));
+ SkAutoTUnref<SkImageFilter> filter(SkNEW_ARGS(
+ SkXfermodeImageFilter, (mode, background)));
paint.setImageFilter(filter);
drawClippedBitmap(canvas, fBitmap, paint, SkIntToScalar(x), SkIntToScalar(y));
x += fBitmap.width() + MARGIN;
@@ -148,6 +151,40 @@
filter.reset(SkNEW_ARGS(SkXfermodeImageFilter, (NULL, background)));
paint.setImageFilter(filter);
drawClippedBitmap(canvas, fBitmap, paint, SkIntToScalar(x), SkIntToScalar(y));
+ x += fBitmap.width() + MARGIN;
+ if (x + fBitmap.width() > WIDTH) {
+ x = 0;
+ y += fBitmap.height() + MARGIN;
+ }
+ // Test offsets on SrcMode (uses fixed-function blend)
+ SkAutoTUnref<SkImageFilter> foreground(SkNEW_ARGS(SkBitmapSource, (fBitmap)));
+ SkAutoTUnref<SkImageFilter> offsetForeground(SkNEW_ARGS(SkOffsetImageFilter,
+ (SkIntToScalar(4), SkIntToScalar(-4), foreground)));
+ SkAutoTUnref<SkImageFilter> offsetBackground(SkNEW_ARGS(SkOffsetImageFilter,
+ (SkIntToScalar(4), SkIntToScalar(4), background)));
+ mode.reset(SkXfermode::Create(SkXfermode::kSrcOver_Mode));
+ filter.reset(SkNEW_ARGS(SkXfermodeImageFilter,
+ (mode, offsetBackground, offsetForeground)));
+ paint.setImageFilter(filter);
+ canvas->save();
+ canvas->clipRect(SkRect::MakeXYWH(x, y,
+ SkIntToScalar(fBitmap.width() + 4), SkIntToScalar(fBitmap.height() + 4)));
+ canvas->drawPaint(paint);
+ canvas->restore();
+ x += fBitmap.width() + MARGIN;
+ if (x + fBitmap.width() > WIDTH) {
+ x = 0;
+ y += fBitmap.height() + MARGIN;
+ }
+ // Test offsets on Darken (uses shader blend)
+ mode.reset(SkXfermode::Create(SkXfermode::kDarken_Mode));
+ filter.reset(SkNEW_ARGS(SkXfermodeImageFilter, (mode, offsetBackground, offsetForeground)));
+ paint.setImageFilter(filter);
+ canvas->save();
+ canvas->clipRect(SkRect::MakeXYWH(x, y,
+ SkIntToScalar(fBitmap.width() + 4), SkIntToScalar(fBitmap.height() + 4)));
+ canvas->drawPaint(paint);
+ canvas->restore();
}
private:
typedef GM INHERITED;