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

Side by Side Diff: gm/imagealphathreshold.cpp

Issue 1879643003: Switch AlphaThresholdFilter over to new onFilterImage interface (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix serialize-8888 config (deserialize crop rect) Created 4 years, 8 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/core/SkImageFilter.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 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 "SkAlphaThresholdFilter.h" 9 #include "SkAlphaThresholdFilter.h"
10 #include "SkRandom.h" 10 #include "SkRandom.h"
11 #include "SkSurface.h" 11 #include "SkSurface.h"
12 12
13 #define WIDTH 500 13 #define WIDTH 500
14 #define HEIGHT 500 14 #define HEIGHT 500
15 15
16 namespace { 16 namespace {
17 17
18 void draw_rects(SkCanvas* canvas) { 18 void draw_rects(SkCanvas* canvas) {
19 SkPaint rectPaint; 19 SkPaint rectPaint;
20 rectPaint.setColor(0xFF0000FF); 20 rectPaint.setColor(0xFF0000FF);
21 canvas->drawRect(SkRect::MakeXYWH(0, 0, WIDTH / 2, HEIGHT / 2), rectPaint); 21 canvas->drawRect(SkRect::MakeXYWH(0, 0, WIDTH / 2, HEIGHT / 2), rectPaint);
22 rectPaint.setColor(0xBFFF0000); 22 rectPaint.setColor(0xBFFF0000);
23 canvas->drawRect(SkRect::MakeXYWH(WIDTH / 2, 0, WIDTH / 2, HEIGHT / 2), rect Paint); 23 canvas->drawRect(SkRect::MakeXYWH(WIDTH / 2, 0, WIDTH / 2, HEIGHT / 2), rect Paint);
24 rectPaint.setColor(0x3F00FF00); 24 rectPaint.setColor(0x3F00FF00);
25 canvas->drawRect(SkRect::MakeXYWH(0, HEIGHT / 2, WIDTH / 2, HEIGHT / 2), rec tPaint); 25 canvas->drawRect(SkRect::MakeXYWH(0, HEIGHT / 2, WIDTH / 2, HEIGHT / 2), rec tPaint);
26 rectPaint.setColor(0x00000000); 26 rectPaint.setColor(0x00000000);
27 canvas->drawRect(SkRect::MakeXYWH(WIDTH / 2, HEIGHT / 2, WIDTH / 2, HEIGHT / 2), rectPaint); 27 canvas->drawRect(SkRect::MakeXYWH(WIDTH / 2, HEIGHT / 2, WIDTH / 2, HEIGHT / 2), rectPaint);
28 } 28 }
29 29
30 SkPaint create_filter_paint() { 30 SkPaint create_filter_paint(SkImageFilter::CropRect* cropRect = nullptr) {
31 SkIRect rects[2]; 31 SkIRect rects[2];
32 rects[0] = SkIRect::MakeXYWH(0, 150, WIDTH, HEIGHT - 300); 32 rects[0] = SkIRect::MakeXYWH(0, 150, WIDTH, HEIGHT - 300);
33 rects[1] = SkIRect::MakeXYWH(150, 0, WIDTH - 300, HEIGHT); 33 rects[1] = SkIRect::MakeXYWH(150, 0, WIDTH - 300, HEIGHT);
34 SkRegion region; 34 SkRegion region;
35 region.setRects(rects, 2); 35 region.setRects(rects, 2);
36 36
37 SkPaint paint; 37 SkPaint paint;
38 paint.setImageFilter(SkAlphaThresholdFilter::Make(region, 0.2f, 0.7f, nullpt r)); 38 paint.setImageFilter(SkAlphaThresholdFilter::Make(region, 0.2f, 0.7f, nullpt r, cropRect));
39 return paint; 39 return paint;
40 } 40 }
41 41
42 }; 42 };
43 43
44 namespace skiagm { 44 namespace skiagm {
45 45
46 class ImageAlphaThresholdGM : public GM { 46 class ImageAlphaThresholdGM : public GM {
47 public: 47 public:
48 ImageAlphaThresholdGM() { 48 ImageAlphaThresholdGM(bool useCropRect) : fUseCropRect(true) {
49 this->setBGColor(0xFFFFFFFF); 49 this->setBGColor(0xFFFFFFFF);
50 } 50 }
51 51
52 protected: 52 protected:
53 53
54 SkString onShortName() override { 54 SkString onShortName() override {
55 if (fUseCropRect) {
56 return SkString("imagealphathreshold_crop");
57 }
58
55 return SkString("imagealphathreshold"); 59 return SkString("imagealphathreshold");
56 } 60 }
57 61
58 SkISize onISize() override { 62 SkISize onISize() override {
59 return SkISize::Make(WIDTH, HEIGHT); 63 return SkISize::Make(WIDTH, HEIGHT);
60 } 64 }
61 65
62 void onDraw(SkCanvas* canvas) override { 66 void onDraw(SkCanvas* canvas) override {
63 SkMatrix matrix; 67 SkMatrix matrix;
64 matrix.reset(); 68 matrix.reset();
65 matrix.setTranslate(WIDTH * .1f, HEIGHT * .1f); 69 matrix.setTranslate(WIDTH * .1f, HEIGHT * .1f);
66 matrix.postScale(.8f, .8f); 70 matrix.postScale(.8f, .8f);
67 71
68 canvas->concat(matrix); 72 canvas->concat(matrix);
69 73
70 SkPaint paint = create_filter_paint(); 74 SkRect r = SkRect::MakeLTRB(100, 100, WIDTH - 100, HEIGHT - 100);
75 SkImageFilter::CropRect cropRect(r);
76
77 SkPaint paint = create_filter_paint(fUseCropRect ? &cropRect : nullptr);
71 canvas->saveLayer(nullptr, &paint); 78 canvas->saveLayer(nullptr, &paint);
72 draw_rects(canvas); 79 draw_rects(canvas);
73 80
74 canvas->restore(); 81 canvas->restore();
75 } 82 }
76 83
77 private: 84 private:
85 bool fUseCropRect;
86
78 typedef GM INHERITED; 87 typedef GM INHERITED;
79 }; 88 };
80 89
90
81 class ImageAlphaThresholdSurfaceGM : public GM { 91 class ImageAlphaThresholdSurfaceGM : public GM {
82 public: 92 public:
83 ImageAlphaThresholdSurfaceGM() { 93 ImageAlphaThresholdSurfaceGM() {
84 this->setBGColor(0xFFFFFFFF); 94 this->setBGColor(0xFFFFFFFF);
85 } 95 }
86 96
87 protected: 97 protected:
88 SkString onShortName() override { 98 SkString onShortName() override {
89 return SkString("imagealphathreshold_surface"); 99 return SkString("imagealphathreshold_surface");
90 } 100 }
(...skipping 15 matching lines...) Expand all
106 canvas->clipRect(SkRect::MakeLTRB(100, 100, WIDTH - 100, HEIGHT - 100)); 116 canvas->clipRect(SkRect::MakeLTRB(100, 100, WIDTH - 100, HEIGHT - 100));
107 canvas->drawImage(surface->makeImageSnapshot().get(), 0, 0, &paint); 117 canvas->drawImage(surface->makeImageSnapshot().get(), 0, 0, &paint);
108 } 118 }
109 119
110 private: 120 private:
111 typedef GM INHERITED; 121 typedef GM INHERITED;
112 }; 122 };
113 123
114 ////////////////////////////////////////////////////////////////////////////// 124 //////////////////////////////////////////////////////////////////////////////
115 125
116 DEF_GM(return new ImageAlphaThresholdGM();) 126 DEF_GM(return new ImageAlphaThresholdGM(true);)
127 DEF_GM(return new ImageAlphaThresholdGM(false);)
117 DEF_GM(return new ImageAlphaThresholdSurfaceGM();) 128 DEF_GM(return new ImageAlphaThresholdSurfaceGM();)
118 129
119 } 130 }
OLDNEW
« no previous file with comments | « no previous file | include/core/SkImageFilter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698