aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/tileimagefilter.cpp
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-09-26 16:09:28 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-09-26 16:09:28 +0000
commit1a4fb70c8a04db2d92ec821555f91218a989031d (patch)
tree14ac67f5ef3d1784f0c03d941d7d5b505e344920 /gm/tileimagefilter.cpp
parent952944144758dd3f9a8a010ec1d99cb4bd035ae4 (diff)
Moving 4 SkImageFilter derived classes from blink to skia
There were 4 classes in blink that derived from SkImageFilter : - TileImageFilter -> SkTileImageFilter - OffsetImageFilter -> SkOffsetImageFilter (already existed) - FloodImageFilter -> SkFloodImageFilter - CompositeImageFilter -> SkCompositeImageFilter All functions were copied as is, without modification (except for warnings fixes), except for the offset filter, which was merged into the existing SkOffsetImageFilter class, as a special case when a crop rect is provided. Since the names won't clash with the names in blink, it should be easy to integrate them in blink later and fix issues, if needed. BUG= R=senorblanco@google.com, senorblanco@chromium.org, bsalomon@google.com, reed@google.com, mtklein@google.com Author: sugoi@chromium.org Review URL: https://chromiumcodereview.appspot.com/24157005 git-svn-id: http://skia.googlecode.com/svn/trunk@11475 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gm/tileimagefilter.cpp')
-rw-r--r--gm/tileimagefilter.cpp122
1 files changed, 122 insertions, 0 deletions
diff --git a/gm/tileimagefilter.cpp b/gm/tileimagefilter.cpp
new file mode 100644
index 0000000000..9a14344772
--- /dev/null
+++ b/gm/tileimagefilter.cpp
@@ -0,0 +1,122 @@
+/*
+ * 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 "SkTileImageFilter.h"
+#include "SkBitmapSource.h"
+
+#define WIDTH 400
+#define HEIGHT 100
+#define MARGIN 12
+
+namespace skiagm {
+
+class TileImageFilterGM : public GM {
+public:
+ TileImageFilterGM() : fInitialized(false) {
+ this->setBGColor(0xFF000000);
+ }
+
+protected:
+ virtual SkString onShortName() {
+ return SkString("tileimagefilter");
+ }
+
+ void make_bitmap() {
+ fBitmap.setConfig(SkBitmap::kARGB_8888_Config, 80, 80);
+ fBitmap.allocPixels();
+ SkBitmapDevice device(fBitmap);
+ SkCanvas canvas(&device);
+ canvas.clear(0x00000000);
+ SkPaint paint;
+ paint.setAntiAlias(true);
+ paint.setColor(0xD000D000);
+ paint.setTextSize(SkIntToScalar(96));
+ const char* str = "e";
+ canvas.drawText(str, strlen(str), SkIntToScalar(15), SkIntToScalar(65), paint);
+ }
+
+ void make_checkerboard() {
+ fCheckerboard.setConfig(SkBitmap::kARGB_8888_Config, 80, 80);
+ fCheckerboard.allocPixels();
+ SkBitmapDevice device(fCheckerboard);
+ SkCanvas canvas(&device);
+ canvas.clear(0x00000000);
+ SkPaint darkPaint;
+ darkPaint.setColor(0xFF404040);
+ SkPaint lightPaint;
+ lightPaint.setColor(0xFFA0A0A0);
+ for (int y = 0; y < 80; y += 16) {
+ for (int x = 0; x < 80; x += 16) {
+ canvas.save();
+ canvas.translate(SkIntToScalar(x), SkIntToScalar(y));
+ canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint);
+ canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint);
+ canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint);
+ canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint);
+ canvas.restore();
+ }
+ }
+ }
+
+ virtual SkISize onISize() {
+ return make_isize(WIDTH, HEIGHT);
+ }
+
+ 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())));
+ canvas->drawBitmap(bitmap, x, y, &paint);
+ canvas->restore();
+ }
+
+ virtual void onDraw(SkCanvas* canvas) {
+ if (!fInitialized) {
+ make_bitmap();
+ make_checkerboard();
+ fInitialized = true;
+ }
+ canvas->clear(0x00000000);
+ SkPaint paint;
+
+ int x = 0, y = 0;
+ for (size_t i = 0; i < 4; i++) {
+ SkBitmap* bitmap = (i & 0x01) ? &fCheckerboard : &fBitmap;
+ SkRect srcRect = SkRect::MakeXYWH(SkIntToScalar(bitmap->width()/4),
+ SkIntToScalar(bitmap->height()/4),
+ SkIntToScalar(bitmap->width()/(i+1)),
+ SkIntToScalar(bitmap->height()/(i+1)));
+ SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(i * 8),
+ SkIntToScalar(i * 4),
+ SkIntToScalar(bitmap->width() - i * 4),
+ SkIntToScalar(bitmap->height()) - i * 8);
+ SkAutoTUnref<SkImageFilter> tileInput(SkNEW_ARGS(SkBitmapSource, (*bitmap)));
+ SkAutoTUnref<SkImageFilter> filter(SkNEW_ARGS(
+ SkTileImageFilter, (srcRect, dstRect, tileInput)));
+ paint.setImageFilter(filter);
+ drawClippedBitmap(canvas, *bitmap, paint, SkIntToScalar(x), SkIntToScalar(y));
+ x += bitmap->width() + MARGIN;
+ if (x + bitmap->width() > WIDTH) {
+ x = 0;
+ y += bitmap->height() + MARGIN;
+ }
+ }
+ }
+private:
+ typedef GM INHERITED;
+ SkBitmap fBitmap, fCheckerboard;
+ bool fInitialized;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+static GM* MyFactory(void*) { return new TileImageFilterGM; }
+static GMRegistry reg(MyFactory);
+
+}