OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "SkBlurImageFilter.h" | 9 #include "SkBlurImageFilter.h" |
10 #include "SkRandom.h" | 10 #include "SkRandom.h" |
11 | 11 |
12 #define WIDTH 640 | 12 #define WIDTH 640 |
13 #define HEIGHT 480 | 13 #define HEIGHT 480 |
14 | 14 |
15 namespace skiagm { | 15 namespace skiagm { |
16 | 16 |
17 class ImageBlurTiledGM : public GM { | 17 class ImageBlurTiledGM : public GM { |
18 public: | 18 public: |
19 ImageBlurTiledGM(SkScalar sigmaX, SkScalar sigmaY) | 19 ImageBlurTiledGM(SkScalar sigmaX, SkScalar sigmaY) |
20 : fSigmaX(sigmaX), fSigmaY(sigmaY) { | 20 : fSigmaX(sigmaX), fSigmaY(sigmaY) { |
21 } | 21 } |
22 | 22 |
23 protected: | 23 protected: |
24 virtual SkString onShortName() { | 24 SkString onShortName() override { |
25 return SkString("imageblurtiled"); | 25 return SkString("imageblurtiled"); |
26 } | 26 } |
27 | 27 |
28 virtual SkISize onISize() { | 28 SkISize onISize() override { |
29 return SkISize::Make(WIDTH, HEIGHT); | 29 return SkISize::Make(WIDTH, HEIGHT); |
30 } | 30 } |
31 | 31 |
32 virtual void onDraw(SkCanvas* canvas) { | 32 void onDraw(SkCanvas* canvas) override { |
33 SkPaint paint; | 33 SkPaint paint; |
34 SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(fSigmaX, fSig
maY)); | 34 paint.setImageFilter(SkBlurImageFilter::Make(fSigmaX, fSigmaY, nullptr))
; |
35 paint.setImageFilter(blur); | 35 const SkScalar tileSize = SkIntToScalar(128); |
36 const SkScalar tile_size = SkIntToScalar(128); | |
37 SkRect bounds; | 36 SkRect bounds; |
38 if (!canvas->getClipBounds(&bounds)) { | 37 if (!canvas->getClipBounds(&bounds)) { |
39 bounds.setEmpty(); | 38 bounds.setEmpty(); |
40 } | 39 } |
41 for (SkScalar y = bounds.top(); y < bounds.bottom(); y += tile_size) { | 40 for (SkScalar y = bounds.top(); y < bounds.bottom(); y += tileSize) { |
42 for (SkScalar x = bounds.left(); x < bounds.right(); x += tile_size)
{ | 41 for (SkScalar x = bounds.left(); x < bounds.right(); x += tileSize)
{ |
43 canvas->save(); | 42 canvas->save(); |
44 canvas->clipRect(SkRect::MakeXYWH(x, y, tile_size, tile_size)); | 43 canvas->clipRect(SkRect::MakeXYWH(x, y, tileSize, tileSize)); |
45 canvas->saveLayer(nullptr, &paint); | 44 canvas->saveLayer(nullptr, &paint); |
46 const char* str[] = { | 45 const char* str[] = { |
47 "The quick", | 46 "The quick", |
48 "brown fox", | 47 "brown fox", |
49 "jumped over", | 48 "jumped over", |
50 "the lazy dog.", | 49 "the lazy dog.", |
51 }; | 50 }; |
52 SkPaint textPaint; | 51 SkPaint textPaint; |
53 textPaint.setAntiAlias(true); | 52 textPaint.setAntiAlias(true); |
54 sk_tool_utils::set_portable_typeface(&textPaint); | 53 sk_tool_utils::set_portable_typeface(&textPaint); |
(...skipping 12 matching lines...) Expand all Loading... |
67 | 66 |
68 private: | 67 private: |
69 SkScalar fSigmaX; | 68 SkScalar fSigmaX; |
70 SkScalar fSigmaY; | 69 SkScalar fSigmaY; |
71 | 70 |
72 typedef GM INHERITED; | 71 typedef GM INHERITED; |
73 }; | 72 }; |
74 | 73 |
75 ////////////////////////////////////////////////////////////////////////////// | 74 ////////////////////////////////////////////////////////////////////////////// |
76 | 75 |
77 static GM* MyFactory1(void*) { return new ImageBlurTiledGM(3.0f, 3.0f); } | 76 DEF_GM(return new ImageBlurTiledGM(3.0f, 3.0f);) |
78 static GMRegistry reg1(MyFactory1); | |
79 | 77 |
80 } | 78 } |
OLD | NEW |