aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm
diff options
context:
space:
mode:
authorGravatar senorblanco@chromium.org <senorblanco@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-08-20 14:53:21 +0000
committerGravatar senorblanco@chromium.org <senorblanco@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-08-20 14:53:21 +0000
commitf1369ce607adf55ffffe58fb93893bafb6ff6ebe (patch)
tree5d375585df0e0b1ff05b6f08f597bb578a58261f /gm
parent52805485581cff7e13134aa1465a2950f7bed007 (diff)
Implements a new class, SkSingleInputImageFilter, to handle DAG connectivity
for filters with a single image input. This provides functionality to store, flatten and unflatten a single SkImageFilter input, as well as to recursively evaluate it on the CPU or GPU. The following classes were re-parented to implement DAG connectivity: SkBlurImageFilter, SkDilateImageFilter, SkErodeImageFilter, SkColorFilterImageFilter. The constructors for each have been appended with a new parameter, representing the input filter (default NULL). This change also implements an arbitrary SkBitmap input source for filtering, SkBitmapSource. NOTE: This CL will require gyp file changes when rolling past this revision. Review URL: https://codereview.appspot.com/6462071/ git-svn-id: http://skia.googlecode.com/svn/trunk@5170 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gm')
-rw-r--r--gm/imagefiltersgraph.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/gm/imagefiltersgraph.cpp b/gm/imagefiltersgraph.cpp
new file mode 100644
index 0000000000..7c60546a11
--- /dev/null
+++ b/gm/imagefiltersgraph.cpp
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2012 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 "SkBitmapSource.h"
+#include "SkBlurImageFilter.h"
+#include "SkMorphologyImageFilter.h"
+
+#include "SkTestImageFilters.h"
+
+///////////////////////////////////////////////////////////////////////////////
+
+class ImageFiltersGraphGM : public skiagm::GM {
+public:
+ ImageFiltersGraphGM() : fInitialized(false) {}
+
+protected:
+
+ virtual SkString onShortName() {
+ return SkString("imagefiltersgraph");
+ }
+
+ void make_bitmap() {
+ fBitmap.setConfig(SkBitmap::kARGB_8888_Config, 100, 100);
+ fBitmap.allocPixels();
+ SkDevice device(fBitmap);
+ SkCanvas canvas(&device);
+ 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);
+ }
+
+ virtual SkISize onISize() { return SkISize::Make(500, 500); }
+
+ virtual void onDraw(SkCanvas* canvas) {
+ if (!fInitialized) {
+ this->make_bitmap();
+ fInitialized = true;
+ }
+ canvas->clear(0x00000000);
+
+ SkAutoTUnref<SkImageFilter> bitmapSource(new SkBitmapSource(fBitmap));
+
+ SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorRED,
+ SkXfermode::kSrcIn_Mode));
+ SkAutoTUnref<SkImageFilter> blur(new SkBlurImageFilter(4.0f, 4.0f, bitmapSource));
+ SkAutoTUnref<SkImageFilter> erode(new SkErodeImageFilter(4, 4, blur));
+ SkAutoTUnref<SkImageFilter> color(new SkColorFilterImageFilter(cf, erode));
+ SkAutoTUnref<SkImageFilter> merge(new SkMergeImageFilter(blur, color));
+
+ SkPaint paint;
+ paint.setImageFilter(merge);
+ canvas->drawPaint(paint);
+ }
+
+private:
+ typedef GM INHERITED;
+ SkBitmap fBitmap;
+ bool fInitialized;
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
+static skiagm::GM* MyFactory(void*) { return new ImageFiltersGraphGM; }
+static skiagm::GMRegistry reg(MyFactory);
+
+