| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "gm.h" | 8 #include "gm.h" |
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkBlurImageFilter.h" | 10 #include "SkBlurImageFilter.h" |
| 11 #include "SkRSXform.h" | 11 #include "SkRSXform.h" |
| 12 #include "SkSurface.h" | 12 #include "SkSurface.h" |
| 13 | 13 |
| 14 static void make_bm(SkBitmap* bm) { | 14 static void make_bm(SkBitmap* bm) { |
| 15 bm->allocN32Pixels(100, 100); | 15 bm->allocN32Pixels(100, 100); |
| 16 bm->eraseColor(SK_ColorBLUE); | 16 bm->eraseColor(SK_ColorBLUE); |
| 17 | 17 |
| 18 SkCanvas canvas(*bm); | 18 SkCanvas canvas(*bm); |
| 19 SkPaint paint; | 19 SkPaint paint; |
| 20 paint.setAntiAlias(true); | 20 paint.setAntiAlias(true); |
| 21 paint.setColor(SK_ColorRED); | 21 paint.setColor(SK_ColorRED); |
| 22 canvas.drawCircle(50, 50, 50, paint); | 22 canvas.drawCircle(50, 50, 50, paint); |
| 23 } | 23 } |
| 24 | 24 |
| 25 static void draw_1_bitmap(SkCanvas* canvas, const SkBitmap& bm, bool doClip, | 25 static void draw_1_bitmap(SkCanvas* canvas, const SkBitmap& bm, bool doClip, |
| 26 int dx, int dy, SkImageFilter* filter = nullptr) { | 26 int dx, int dy, sk_sp<SkImageFilter> filter) { |
| 27 SkAutoCanvasRestore acr(canvas, true); | 27 SkAutoCanvasRestore acr(canvas, true); |
| 28 SkPaint paint; | 28 SkPaint paint; |
| 29 | 29 |
| 30 SkRect clipR = SkRect::MakeXYWH(SkIntToScalar(dx), | 30 SkRect clipR = SkRect::MakeXYWH(SkIntToScalar(dx), |
| 31 SkIntToScalar(dy), | 31 SkIntToScalar(dy), |
| 32 SkIntToScalar(bm.width()), | 32 SkIntToScalar(bm.width()), |
| 33 SkIntToScalar(bm.height())); | 33 SkIntToScalar(bm.height())); |
| 34 | 34 |
| 35 paint.setImageFilter(filter); | 35 paint.setImageFilter(std::move(filter)); |
| 36 clipR.inset(5, 5); | 36 clipR.inset(5, 5); |
| 37 | 37 |
| 38 canvas->translate(SkIntToScalar(bm.width() + 20), 0); | 38 canvas->translate(SkIntToScalar(bm.width() + 20), 0); |
| 39 | 39 |
| 40 if (doClip) { | 40 if (doClip) { |
| 41 canvas->save(); | 41 canvas->save(); |
| 42 canvas->clipRect(clipR); | 42 canvas->clipRect(clipR); |
| 43 } | 43 } |
| 44 canvas->drawBitmap(bm, SkIntToScalar(dx), SkIntToScalar(dy), &paint); | 44 canvas->drawBitmap(bm, SkIntToScalar(dx), SkIntToScalar(dy), &paint); |
| 45 if (doClip) { | 45 if (doClip) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 65 } | 65 } |
| 66 | 66 |
| 67 void onDraw(SkCanvas* canvas) override { | 67 void onDraw(SkCanvas* canvas) override { |
| 68 SkBitmap bm; | 68 SkBitmap bm; |
| 69 make_bm(&bm); | 69 make_bm(&bm); |
| 70 | 70 |
| 71 int dx = 10; | 71 int dx = 10; |
| 72 int dy = 10; | 72 int dy = 10; |
| 73 | 73 |
| 74 SkScalar sigma = 8; | 74 SkScalar sigma = 8; |
| 75 SkAutoTUnref<SkImageFilter> filter(SkBlurImageFilter::Create(sigma, sigm
a)); | 75 sk_sp<SkImageFilter> filter(SkBlurImageFilter::Make(sigma, sigma, nullpt
r)); |
| 76 | 76 |
| 77 draw_1_bitmap(canvas, bm, false, dx, dy); | 77 draw_1_bitmap(canvas, bm, false, dx, dy, nullptr); |
| 78 dy += bm.height() + 20; | 78 dy += bm.height() + 20; |
| 79 draw_1_bitmap(canvas, bm, false, dx, dy, filter); | 79 draw_1_bitmap(canvas, bm, false, dx, dy, filter); |
| 80 dy += bm.height() + 20; | 80 dy += bm.height() + 20; |
| 81 draw_1_bitmap(canvas, bm, true, dx, dy); | 81 draw_1_bitmap(canvas, bm, true, dx, dy, nullptr); |
| 82 dy += bm.height() + 20; | 82 dy += bm.height() + 20; |
| 83 draw_1_bitmap(canvas, bm, true, dx, dy, filter); | 83 draw_1_bitmap(canvas, bm, true, dx, dy, filter); |
| 84 } | 84 } |
| 85 | 85 |
| 86 private: | 86 private: |
| 87 typedef GM INHERITED; | 87 typedef GM INHERITED; |
| 88 }; | 88 }; |
| 89 DEF_GM( return new SpriteBitmapGM; ) | 89 DEF_GM( return new SpriteBitmapGM; ) |
| OLD | NEW |