aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/pictureimagefilter.cpp
diff options
context:
space:
mode:
authorGravatar senorblanco@chromium.org <senorblanco@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-12-12 23:28:52 +0000
committerGravatar senorblanco@chromium.org <senorblanco@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-12-12 23:28:52 +0000
commit533330065a28b51808e5bf564ae45e56f8d9956a (patch)
treea16998931b11cfe5c6bf385eec8fcb2958cf0d9f /gm/pictureimagefilter.cpp
parent6b8dbb668f1f069270d35a47cfe98decd059c625 (diff)
Implement an SkPicture image filter source. This is required for the external-SVG reference feature of feImage. It simply plays back an SkPicture to a given destination rect.
R=reed@google.com Review URL: https://codereview.chromium.org/114263002 git-svn-id: http://skia.googlecode.com/svn/trunk@12661 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gm/pictureimagefilter.cpp')
-rw-r--r--gm/pictureimagefilter.cpp82
1 files changed, 82 insertions, 0 deletions
diff --git a/gm/pictureimagefilter.cpp b/gm/pictureimagefilter.cpp
new file mode 100644
index 0000000000..781088ce0e
--- /dev/null
+++ b/gm/pictureimagefilter.cpp
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "gm.h"
+
+#include "SkPictureImageFilter.h"
+
+// This GM exercises the SkPictureImageFilter ImageFilter class.
+
+class PictureImageFilterGM : public skiagm::GM {
+public:
+ PictureImageFilterGM() {
+ }
+
+protected:
+ virtual SkString onShortName() SK_OVERRIDE {
+ return SkString("pictureimagefilter");
+ }
+
+ void makePicture() {
+ SkCanvas* canvas = fPicture.beginRecording(100, 100);
+ canvas->clear(0x00000000);
+ SkPaint paint;
+ paint.setAntiAlias(true);
+ paint.setColor(0xFFFFFFFF);
+ paint.setTextSize(SkIntToScalar(96));
+ const char* str = "e";
+ canvas->drawText(str, strlen(str), SkIntToScalar(20), SkIntToScalar(70), paint);
+ fPicture.endRecording();
+ }
+
+ virtual SkISize onISize() SK_OVERRIDE { return SkISize::Make(500, 150); }
+
+ virtual void onOnceBeforeDraw() SK_OVERRIDE {
+ this->makePicture();
+ }
+
+ static void fillRectFiltered(SkCanvas* canvas, const SkRect& clipRect, SkImageFilter* filter) {
+ SkPaint paint;
+ paint.setImageFilter(filter);
+ canvas->save();
+ canvas->clipRect(clipRect);
+ canvas->drawPaint(paint);
+ canvas->restore();
+ }
+
+ virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
+ canvas->clear(0x00000000);
+ {
+ SkRect srcRect = SkRect::MakeXYWH(20, 20, 30, 30);
+ SkRect emptyRect = SkRect::MakeXYWH(20, 20, 0, 0);
+ SkRect bounds = SkRect::MakeXYWH(0, 0, 100, 100);
+ SkAutoTUnref<SkImageFilter> pictureSource(new SkPictureImageFilter(&fPicture));
+ SkAutoTUnref<SkImageFilter> pictureSourceSrcRect(new SkPictureImageFilter(&fPicture, srcRect));
+ SkAutoTUnref<SkImageFilter> pictureSourceEmptyRect(new SkPictureImageFilter(&fPicture, emptyRect));
+
+ // Draw the picture unscaled.
+ fillRectFiltered(canvas, bounds, pictureSource);
+ canvas->translate(SkIntToScalar(100), 0);
+
+ // Draw an unscaled subset of the source picture.
+ fillRectFiltered(canvas, bounds, pictureSourceSrcRect);
+ canvas->translate(SkIntToScalar(100), 0);
+
+ // Draw the picture to an empty rect (should draw nothing).
+ fillRectFiltered(canvas, bounds, pictureSourceEmptyRect);
+ canvas->translate(SkIntToScalar(100), 0);
+ }
+ }
+
+private:
+ SkPicture fPicture;
+ typedef GM INHERITED;
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
+DEF_GM( return new PictureImageFilterGM; )