senorblanco@chromium.org | fd0ec2c | 2014-03-25 17:35:10 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "gm.h" |
| 9 | #include "SkColor.h" |
senorblanco | 8c874ee | 2015-03-20 06:38:17 -0700 | [diff] [blame] | 10 | #include "SkImageFilter.h" |
senorblanco@chromium.org | fd0ec2c | 2014-03-25 17:35:10 +0000 | [diff] [blame] | 11 | |
halcanary | 2a24338 | 2015-09-09 08:16:41 -0700 | [diff] [blame^] | 12 | static void draw(SkCanvas* canvas, const SkRect& rect, const SkBitmap& bitmap, |
| 13 | const SkMatrix& matrix, SkFilterQuality filter) { |
senorblanco@chromium.org | fd0ec2c | 2014-03-25 17:35:10 +0000 | [diff] [blame] | 14 | SkAutoTUnref<SkImageFilter> imageFilter( |
senorblanco | 8c874ee | 2015-03-20 06:38:17 -0700 | [diff] [blame] | 15 | SkImageFilter::CreateMatrixFilter(matrix, filter)); |
senorblanco@chromium.org | fd0ec2c | 2014-03-25 17:35:10 +0000 | [diff] [blame] | 16 | SkPaint paint; |
| 17 | paint.setImageFilter(imageFilter.get()); |
| 18 | canvas->saveLayer(&rect, &paint); |
| 19 | canvas->drawBitmap(bitmap, 0, 0); |
| 20 | canvas->restore(); |
halcanary | 2a24338 | 2015-09-09 08:16:41 -0700 | [diff] [blame^] | 21 | } |
senorblanco@chromium.org | fd0ec2c | 2014-03-25 17:35:10 +0000 | [diff] [blame] | 22 | |
halcanary | 2a24338 | 2015-09-09 08:16:41 -0700 | [diff] [blame^] | 23 | static void make_checkerboard(SkBitmap* bitmap) { |
senorblanco@chromium.org | fd0ec2c | 2014-03-25 17:35:10 +0000 | [diff] [blame] | 24 | bitmap->allocN32Pixels(64, 64); |
| 25 | SkCanvas canvas(*bitmap); |
| 26 | SkPaint darkPaint; |
caryclark | 1259601 | 2015-07-29 05:27:47 -0700 | [diff] [blame] | 27 | darkPaint.setColor(sk_tool_utils::color_to_565(0xFF404040)); |
senorblanco@chromium.org | fd0ec2c | 2014-03-25 17:35:10 +0000 | [diff] [blame] | 28 | SkPaint lightPaint; |
caryclark | 1259601 | 2015-07-29 05:27:47 -0700 | [diff] [blame] | 29 | lightPaint.setColor(sk_tool_utils::color_to_565(0xFFA0A0A0)); |
senorblanco@chromium.org | fd0ec2c | 2014-03-25 17:35:10 +0000 | [diff] [blame] | 30 | for (int y = 0; y < 64; y += 32) { |
| 31 | for (int x = 0; x < 64; x += 32) { |
| 32 | canvas.save(); |
| 33 | canvas.translate(SkIntToScalar(x), SkIntToScalar(y)); |
| 34 | canvas.drawRect(SkRect::MakeXYWH(0, 0, 16, 16), darkPaint); |
| 35 | canvas.drawRect(SkRect::MakeXYWH(16, 0, 16, 16), lightPaint); |
| 36 | canvas.drawRect(SkRect::MakeXYWH(0, 16, 16, 16), lightPaint); |
| 37 | canvas.drawRect(SkRect::MakeXYWH(16, 16, 16, 16), darkPaint); |
| 38 | canvas.restore(); |
| 39 | } |
| 40 | } |
halcanary | 2a24338 | 2015-09-09 08:16:41 -0700 | [diff] [blame^] | 41 | } |
senorblanco@chromium.org | fd0ec2c | 2014-03-25 17:35:10 +0000 | [diff] [blame] | 42 | |
halcanary | 2a24338 | 2015-09-09 08:16:41 -0700 | [diff] [blame^] | 43 | DEF_SIMPLE_GM_BG(matriximagefilter, canvas, 420, 100, SK_ColorBLACK) { |
senorblanco@chromium.org | fd0ec2c | 2014-03-25 17:35:10 +0000 | [diff] [blame] | 44 | SkMatrix matrix; |
| 45 | SkScalar margin = SkIntToScalar(10); |
| 46 | matrix.setSkew(SkDoubleToScalar(0.5), SkDoubleToScalar(0.2)); |
senorblanco@chromium.org | fd0ec2c | 2014-03-25 17:35:10 +0000 | [diff] [blame] | 47 | SkBitmap checkerboard; |
| 48 | make_checkerboard(&checkerboard); |
senorblanco@chromium.org | fd0ec2c | 2014-03-25 17:35:10 +0000 | [diff] [blame] | 49 | |
| 50 | SkRect srcRect = SkRect::MakeWH(96, 96); |
| 51 | |
| 52 | canvas->translate(margin, margin); |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 53 | draw(canvas, srcRect, checkerboard, matrix, kNone_SkFilterQuality); |
senorblanco@chromium.org | fd0ec2c | 2014-03-25 17:35:10 +0000 | [diff] [blame] | 54 | |
| 55 | canvas->translate(srcRect.width() + margin, 0); |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 56 | draw(canvas, srcRect, checkerboard, matrix, kLow_SkFilterQuality); |
senorblanco@chromium.org | fd0ec2c | 2014-03-25 17:35:10 +0000 | [diff] [blame] | 57 | |
senorblanco@chromium.org | 6aeabb1 | 2014-03-25 21:12:18 +0000 | [diff] [blame] | 58 | #if 0 |
| 59 | // This may be causing Mac 10.6 to barf. |
senorblanco@chromium.org | fd0ec2c | 2014-03-25 17:35:10 +0000 | [diff] [blame] | 60 | canvas->translate(srcRect.width() + margin, 0); |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 61 | draw(canvas, srcRect, checkerboard, matrix, kMedium_SkFilterQuality); |
senorblanco@chromium.org | fd0ec2c | 2014-03-25 17:35:10 +0000 | [diff] [blame] | 62 | |
| 63 | canvas->translate(srcRect.width() + margin, 0); |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 64 | draw(canvas, srcRect, checkerboard, matrix, kHigh_SkFilterQuality); |
senorblanco@chromium.org | 6aeabb1 | 2014-03-25 21:12:18 +0000 | [diff] [blame] | 65 | #endif |
senorblanco@chromium.org | fd0ec2c | 2014-03-25 17:35:10 +0000 | [diff] [blame] | 66 | } |