add filterImage() entry-point to SkDevice, to allow it to specialize on subclasses
of SkImageFilter. If that returns false, then the filter itself is invoked.
git-svn-id: http://skia.googlecode.com/svn/trunk@2977 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gm/testimagefilters.cpp b/gm/testimagefilters.cpp
index e484e1b..fc71d30 100644
--- a/gm/testimagefilters.cpp
+++ b/gm/testimagefilters.cpp
@@ -10,6 +10,8 @@
#include "SkColorFilter.h"
#include "SkColorPriv.h"
#include "SkShader.h"
+
+#include "SkBlurImageFilter.h"
#include "SkTestImageFilters.h"
#define FILTER_WIDTH SkIntToScalar(150)
@@ -24,13 +26,17 @@
return new SkColorFilterImageFilter(cf);
}
static SkImageFilter* make3() {
+ return new SkBlurImageFilter(8, 0);
+}
+
+static SkImageFilter* make4() {
SkImageFilter* outer = new SkOffsetImageFilter(SkIntToScalar(16), SkIntToScalar(16));
SkImageFilter* inner = new SkDownSampleImageFilter(SK_Scalar1 / 5);
SkAutoUnref aur0(outer);
SkAutoUnref aur1(inner);
return new SkComposeImageFilter(outer, inner);
}
-static SkImageFilter* make4() {
+static SkImageFilter* make5() {
SkImageFilter* first = new SkOffsetImageFilter(SkIntToScalar(16), SkIntToScalar(16));
SkImageFilter* second = new SkDownSampleImageFilter(SK_Scalar1 / 5);
SkAutoUnref aur0(first);
@@ -38,20 +44,37 @@
return new SkMergeImageFilter(first, second);
}
-static SkImageFilter* make5() {
+static SkImageFilter* make6() {
SkImageFilter* outer = new SkOffsetImageFilter(SkIntToScalar(16), SkIntToScalar(16));
SkImageFilter* inner = new SkDownSampleImageFilter(SK_Scalar1 / 5);
SkAutoUnref aur0(outer);
SkAutoUnref aur1(inner);
SkImageFilter* compose = new SkComposeImageFilter(outer, inner);
SkAutoUnref aur2(compose);
-
+
SkColorFilter* cf = SkColorFilter::CreateModeFilter(0x880000FF,
SkXfermode::kSrcIn_Mode);
SkAutoUnref aur3(cf);
SkImageFilter* blue = new SkColorFilterImageFilter(cf);
SkAutoUnref aur4(blue);
+
+ return new SkMergeImageFilter(compose, blue);
+}
+static SkImageFilter* make7() {
+ SkImageFilter* outer = new SkOffsetImageFilter(SkIntToScalar(16), SkIntToScalar(16));
+ SkImageFilter* inner = make3();
+ SkAutoUnref aur0(outer);
+ SkAutoUnref aur1(inner);
+ SkImageFilter* compose = new SkComposeImageFilter(outer, inner);
+ SkAutoUnref aur2(compose);
+
+ SkColorFilter* cf = SkColorFilter::CreateModeFilter(0x880000FF,
+ SkXfermode::kSrcIn_Mode);
+ SkAutoUnref aur3(cf);
+ SkImageFilter* blue = new SkColorFilterImageFilter(cf);
+ SkAutoUnref aur4(blue);
+
return new SkMergeImageFilter(compose, blue);
}
@@ -59,7 +82,7 @@
SkPaint p;
p.setAntiAlias(true);
SkRect r = SkRect::MakeWH(FILTER_WIDTH, FILTER_HEIGHT);
- r.inset(SK_Scalar1, SK_Scalar1);
+ r.inset(SK_Scalar1 * 12, SK_Scalar1 * 12);
p.setColor(SK_ColorRED);
canvas->drawOval(r, p);
}
@@ -74,11 +97,13 @@
return SkString("testimagefilters");
}
- virtual SkISize onISize() { return SkISize::Make(640, 480); }
+ virtual SkISize onISize() { return SkISize::Make(700, 460); }
virtual void onDraw(SkCanvas* canvas) {
+// this->drawSizeBounds(canvas, 0xFFCCCCCC);
+
static SkImageFilter* (*gFilterProc[])() = {
- make0, make1, make2, make3, make4, make5
+ make0, make1, make2, make3, make4, make5, make6, make7
};
const SkRect bounds = SkRect::MakeWH(FILTER_WIDTH, FILTER_HEIGHT);
@@ -86,20 +111,21 @@
const SkScalar dx = bounds.width() * 8 / 7;
const SkScalar dy = bounds.height() * 8 / 7;
- for (size_t i = 0; i < SK_ARRAY_COUNT(gFilterProc); ++i) {
- int ix = i % 3;
- int iy = i / 3;
+ canvas->translate(SkIntToScalar(8), SkIntToScalar(8));
- SkPaint paint;
- paint.setImageFilter(gFilterProc[i]())->unref();
+ for (size_t i = 0; i < SK_ARRAY_COUNT(gFilterProc); ++i) {
+ int ix = i % 4;
+ int iy = i / 4;
SkAutoCanvasRestore acr(canvas, true);
canvas->translate(ix * dx, iy * dy);
SkPaint p;
- p.setColor(0xFFCCCCCC);
+ p.setStyle(SkPaint::kStroke_Style);
canvas->drawRect(bounds, p);
+ SkPaint paint;
+ paint.setImageFilter(gFilterProc[i]())->unref();
canvas->saveLayer(&bounds, &paint);
draw0(canvas);
}