Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1161)

Side by Side Diff: gm/morphology.cpp

Issue 1819393002: Switch SkMorphologyImageFilter over to new onFilterImage interface (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Update to ToT Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | include/effects/SkMorphologyImageFilter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 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 "SkMorphologyImageFilter.h" 9 #include "SkMorphologyImageFilter.h"
10 10
11 #define WIDTH 700 11 #define WIDTH 700
12 #define HEIGHT 560 12 #define HEIGHT 560
13 13
14 namespace skiagm { 14 namespace skiagm {
15 15
16 class MorphologyGM : public GM { 16 class MorphologyGM : public GM {
17 public: 17 public:
18 MorphologyGM() { 18 MorphologyGM() {
19 this->setBGColor(0xFF000000); 19 this->setBGColor(0xFF000000);
20 fOnce = false;
21 } 20 }
22 21
23 protected: 22 protected:
24 virtual SkString onShortName() { 23 SkString onShortName() override {
25 return SkString("morphology"); 24 return SkString("morphology");
26 } 25 }
27 26
28 void make_bitmap() { 27 void onOnceBeforeDraw() override {
29 fBitmap.allocN32Pixels(135, 135); 28 fBitmap.allocN32Pixels(135, 135);
30 SkCanvas canvas(fBitmap); 29 SkCanvas canvas(fBitmap);
31 canvas.clear(0x0); 30 canvas.clear(0x0);
32 SkPaint paint; 31 SkPaint paint;
33 paint.setAntiAlias(true); 32 paint.setAntiAlias(true);
34 sk_tool_utils::set_portable_typeface(&paint); 33 sk_tool_utils::set_portable_typeface(&paint);
35 const char* str1 = "ABC"; 34 const char* str1 = "ABC";
36 const char* str2 = "XYZ"; 35 const char* str2 = "XYZ";
37 paint.setColor(0xFFFFFFFF); 36 paint.setColor(0xFFFFFFFF);
38 paint.setTextSize(64); 37 paint.setTextSize(64);
39 canvas.drawText(str1, strlen(str1), 10, 55, paint); 38 canvas.drawText(str1, strlen(str1), 10, 55, paint);
40 canvas.drawText(str2, strlen(str2), 10, 110, paint); 39 canvas.drawText(str2, strlen(str2), 10, 110, paint);
41 } 40 }
42 41
43 virtual SkISize onISize() { 42 SkISize onISize() override {
44 return SkISize::Make(WIDTH, HEIGHT); 43 return SkISize::Make(WIDTH, HEIGHT);
45 } 44 }
46 45
47 void drawClippedBitmap(SkCanvas* canvas, const SkPaint& paint, int x, int y) { 46 void drawClippedBitmap(SkCanvas* canvas, const SkPaint& paint, int x, int y) {
48 canvas->save(); 47 canvas->save();
49 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); 48 canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
50 canvas->clipRect(SkRect::MakeWH( 49 canvas->clipRect(SkRect::MakeWH(
51 SkIntToScalar(fBitmap.width()), SkIntToScalar(fBitmap.height()))); 50 SkIntToScalar(fBitmap.width()), SkIntToScalar(fBitmap.height())));
52 canvas->drawBitmap(fBitmap, 0, 0, &paint); 51 canvas->drawBitmap(fBitmap, 0, 0, &paint);
53 canvas->restore(); 52 canvas->restore();
54 } 53 }
55 54
56 virtual void onDraw(SkCanvas* canvas) { 55 void onDraw(SkCanvas* canvas) override {
57 if (!fOnce) {
58 make_bitmap();
59 fOnce = true;
60 }
61 struct { 56 struct {
62 int fWidth, fHeight; 57 int fWidth, fHeight;
63 int fRadiusX, fRadiusY; 58 int fRadiusX, fRadiusY;
64 } samples[] = { 59 } samples[] = {
65 { 140, 140, 0, 0 }, 60 { 140, 140, 0, 0 },
66 { 140, 140, 0, 2 }, 61 { 140, 140, 0, 2 },
67 { 140, 140, 2, 0 }, 62 { 140, 140, 2, 0 },
68 { 140, 140, 2, 2 }, 63 { 140, 140, 2, 2 },
69 { 24, 24, 25, 25 }, 64 { 24, 24, 25, 25 },
70 }; 65 };
71 SkPaint paint; 66 SkPaint paint;
72 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(25, 20, 100, 80)); 67 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(25, 20, 100, 80));
73 68
74 for (unsigned j = 0; j < 4; ++j) { 69 for (unsigned j = 0; j < 4; ++j) {
75 for (unsigned i = 0; i < SK_ARRAY_COUNT(samples); ++i) { 70 for (unsigned i = 0; i < SK_ARRAY_COUNT(samples); ++i) {
76 const SkImageFilter::CropRect* cr = j & 0x02 ? &cropRect : nullp tr; 71 const SkImageFilter::CropRect* cr = j & 0x02 ? &cropRect : nullp tr;
77 if (j & 0x01) { 72 if (j & 0x01) {
78 paint.setImageFilter(SkErodeImageFilter::Create( 73 paint.setImageFilter(SkErodeImageFilter::Create(
79 samples[i].fRadiusX, 74 samples[i].fRadiusX,
80 samples[i].fRadiusY, 75 samples[i].fRadiusY,
81 nullptr, 76 nullptr,
82 cr))->unref(); 77 cr))->unref();
83 } else { 78 } else {
84 paint.setImageFilter(SkDilateImageFilter::Create( 79 paint.setImageFilter(SkDilateImageFilter::Create(
85 samples[i].fRadiusX, 80 samples[i].fRadiusX,
86 samples[i].fRadiusY, 81 samples[i].fRadiusY,
87 nullptr, 82 nullptr,
88 cr))->unref(); 83 cr))->unref();
89 } 84 }
90 drawClippedBitmap(canvas, paint, i * 140, j * 140); 85 this->drawClippedBitmap(canvas, paint, i * 140, j * 140);
91 } 86 }
92 } 87 }
93 } 88 }
94 89
95 private: 90 private:
91 SkBitmap fBitmap;
92
96 typedef GM INHERITED; 93 typedef GM INHERITED;
97 SkBitmap fBitmap;
98 bool fOnce;
99 }; 94 };
100 95
101 ////////////////////////////////////////////////////////////////////////////// 96 //////////////////////////////////////////////////////////////////////////////
102 97
103 static GM* MyFactory(void*) { return new MorphologyGM; } 98 DEF_GM(return new MorphologyGM;)
104 static GMRegistry reg(MyFactory);
105 99
106 } 100 }
OLDNEW
« no previous file with comments | « no previous file | include/effects/SkMorphologyImageFilter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698