Add a zoom filter to Skia. This will be used on ChromeOS to implement the screen magnifier.

Committed on behalf of zork@chromium.org

Review URL: http://codereview.appspot.com/6354065/


git-svn-id: http://skia.googlecode.com/svn/trunk@5056 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gm/imagemagnifier.cpp b/gm/imagemagnifier.cpp
new file mode 100644
index 0000000..f9aff28
--- /dev/null
+++ b/gm/imagemagnifier.cpp
@@ -0,0 +1,63 @@
+/*
+ * 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 "SkMagnifierImageFilter.h"
+
+#define WIDTH 500
+#define HEIGHT 500
+
+namespace skiagm {
+
+class ImageMagnifierGM : public GM {
+public:
+    ImageMagnifierGM() {
+        this->setBGColor(0xFF000000);
+    }
+
+protected:
+    virtual SkString onShortName() {
+        return SkString("imagemagnifier");
+    }
+
+    virtual SkISize onISize() {
+        return make_isize(WIDTH, HEIGHT);
+    }
+
+    virtual void onDraw(SkCanvas* canvas) {
+        SkPaint paint;
+        paint.setImageFilter(
+            new SkMagnifierImageFilter(
+                SkRect::MakeXYWH(SkIntToScalar(125), SkIntToScalar(125),
+                                 SkIntToScalar(WIDTH / 2),
+                                 SkIntToScalar(HEIGHT / 2)),
+                100))->unref();
+        canvas->saveLayer(NULL, &paint);
+        paint.setAntiAlias(true);
+        const char* str = "The quick brown fox jumped over the lazy dog.";
+        srand(1234);
+        for (int i = 0; i < 25; ++i) {
+            int x = rand() % WIDTH;
+            int y = rand() % HEIGHT;
+            paint.setColor(rand() % 0x1000000 | 0xFF000000);
+            paint.setTextSize(SkIntToScalar(rand() % 300));
+            canvas->drawText(str, strlen(str), SkIntToScalar(x),
+                             SkIntToScalar(y), paint);
+        }
+        canvas->restore();
+    }
+
+private:
+    typedef GM INHERITED;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+static GM* MyFactory(void*) { return new ImageMagnifierGM; }
+static GMRegistry reg(MyFactory);
+
+}