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 "sk_tool_utils.h" | 8 #include "sk_tool_utils.h" |
9 #include "SkImage.h" | 9 #include "SkImage.h" |
10 #include "SkImageSource.h" | 10 #include "SkImageSource.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 return SkString("offsetimagefilter"); | 27 return SkString("offsetimagefilter"); |
28 } | 28 } |
29 | 29 |
30 SkISize onISize() override { | 30 SkISize onISize() override { |
31 return SkISize::Make(WIDTH, HEIGHT); | 31 return SkISize::Make(WIDTH, HEIGHT); |
32 } | 32 } |
33 | 33 |
34 void onOnceBeforeDraw() override { | 34 void onOnceBeforeDraw() override { |
35 fBitmap = SkImage::MakeFromBitmap( | 35 fBitmap = SkImage::MakeFromBitmap( |
36 sk_tool_utils::create_string_bitmap(80, 80, 0xD000D000, 15, 65, 96,
"e")); | 36 sk_tool_utils::create_string_bitmap(80, 80, 0xD000D000, 15, 65, 96,
"e")); |
37 | 37 |
38 fCheckerboard = SkImage::MakeFromBitmap( | 38 fCheckerboard = SkImage::MakeFromBitmap( |
39 sk_tool_utils::create_checkerboard_bitmap(80, 80, | 39 sk_tool_utils::create_checkerboard_bitmap(80, 80, |
40 sk_tool_utils::color_to_56
5(0xFFA0A0A0), | 40 sk_tool_utils::color_to_56
5(0xFFA0A0A0), |
41 sk_tool_utils::color_to_56
5(0xFF404040), | 41 sk_tool_utils::color_to_56
5(0xFF404040), |
42 8)); | 42 8)); |
43 } | 43 } |
44 | 44 |
45 void onDraw(SkCanvas* canvas) override { | 45 void onDraw(SkCanvas* canvas) override { |
46 canvas->clear(SK_ColorBLACK); | 46 canvas->clear(SK_ColorBLACK); |
47 SkPaint paint; | 47 SkPaint paint; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 | 96 |
97 typedef skiagm::GM INHERITED; | 97 typedef skiagm::GM INHERITED; |
98 }; | 98 }; |
99 DEF_GM( return new OffsetImageFilterGM; ) | 99 DEF_GM( return new OffsetImageFilterGM; ) |
100 | 100 |
101 ////////////////////////////////////////////////////////////////////////////// | 101 ////////////////////////////////////////////////////////////////////////////// |
102 | 102 |
103 class SimpleOffsetImageFilterGM : public skiagm::GM { | 103 class SimpleOffsetImageFilterGM : public skiagm::GM { |
104 public: | 104 public: |
105 SimpleOffsetImageFilterGM() {} | 105 SimpleOffsetImageFilterGM() {} |
106 | 106 |
107 protected: | 107 protected: |
108 SkString onShortName() override { | 108 SkString onShortName() override { |
109 return SkString("simple-offsetimagefilter"); | 109 return SkString("simple-offsetimagefilter"); |
110 } | 110 } |
111 | 111 |
112 SkISize onISize() override { return SkISize::Make(640, 200); } | 112 SkISize onISize() override { return SkISize::Make(640, 200); } |
113 | 113 |
114 void doDraw(SkCanvas* canvas, const SkRect& r, SkImageFilter* imgf, | 114 void doDraw(SkCanvas* canvas, const SkRect& r, SkImageFilter* imgf, |
115 const SkRect* clipR = nullptr) { | 115 const SkRect* clipR = nullptr) { |
116 SkPaint p; | 116 SkPaint p; |
117 | 117 |
118 if (clipR) { | 118 if (clipR) { |
119 p.setColor(0xFF00FF00); | 119 p.setColor(0xFF00FF00); |
120 p.setStyle(SkPaint::kStroke_Style); | 120 p.setStyle(SkPaint::kStroke_Style); |
121 canvas->drawRect(clipR->makeInset(SK_ScalarHalf, SK_ScalarHalf), p); | 121 canvas->drawRect(clipR->makeInset(SK_ScalarHalf, SK_ScalarHalf), p); |
122 p.setStyle(SkPaint::kFill_Style); | 122 p.setStyle(SkPaint::kFill_Style); |
123 } | 123 } |
(...skipping 26 matching lines...) Expand all Loading... |
150 } | 150 } |
151 | 151 |
152 void onDraw(SkCanvas* canvas) override { | 152 void onDraw(SkCanvas* canvas) override { |
153 const SkRect r = SkRect::MakeWH(40, 40); | 153 const SkRect r = SkRect::MakeWH(40, 40); |
154 SkImageFilter::CropRect cr0(r); | 154 SkImageFilter::CropRect cr0(r); |
155 SkImageFilter::CropRect cr1(SkRect::MakeWH(20, 20)); | 155 SkImageFilter::CropRect cr1(SkRect::MakeWH(20, 20)); |
156 const SkRect r2 = SkRect::MakeXYWH(40, 0, 40, 40); | 156 const SkRect r2 = SkRect::MakeXYWH(40, 0, 40, 40); |
157 SkImageFilter::CropRect cr2(r2); | 157 SkImageFilter::CropRect cr2(r2); |
158 | 158 |
159 canvas->translate(40, 40); | 159 canvas->translate(40, 40); |
160 | 160 |
161 canvas->save(); | 161 canvas->save(); |
162 this->doDraw(canvas, r, nullptr); | 162 this->doDraw(canvas, r, nullptr); |
163 | 163 |
164 canvas->translate(100, 0); | 164 canvas->translate(100, 0); |
165 this->doDraw(canvas, r, SkOffsetImageFilter::Create(20, 20)); | 165 this->doDraw(canvas, r, SkOffsetImageFilter::Create(20, 20)); |
166 | 166 |
167 canvas->translate(100, 0); | 167 canvas->translate(100, 0); |
168 this->doDraw(canvas, r, SkOffsetImageFilter::Create(20, 20, nullptr, &cr
0)); | 168 this->doDraw(canvas, r, SkOffsetImageFilter::Create(20, 20, nullptr, &cr
0)); |
169 | 169 |
170 canvas->translate(100, 0); | 170 canvas->translate(100, 0); |
171 this->doDraw(canvas, r, SkOffsetImageFilter::Create(20, 20), &r); | 171 this->doDraw(canvas, r, SkOffsetImageFilter::Create(20, 20), &r); |
172 | 172 |
173 canvas->translate(100, 0); | 173 canvas->translate(100, 0); |
174 this->doDraw(canvas, r, SkOffsetImageFilter::Create(20, 20, nullptr, &cr
1)); | 174 this->doDraw(canvas, r, SkOffsetImageFilter::Create(20, 20, nullptr, &cr
1)); |
175 | 175 |
176 SkRect clipR = SkRect::MakeXYWH(40, 40, 40, 40); | 176 SkRect clipR = SkRect::MakeXYWH(40, 40, 40, 40); |
177 canvas->translate(100, 0); | 177 canvas->translate(100, 0); |
178 this->doDraw(canvas, r, SkOffsetImageFilter::Create(20, 20, nullptr, nul
lptr), &clipR); | 178 this->doDraw(canvas, r, SkOffsetImageFilter::Create(20, 20, nullptr, nul
lptr), &clipR); |
179 canvas->restore(); | 179 canvas->restore(); |
180 | 180 |
181 // 2nd row | 181 // 2nd row |
182 canvas->translate(0, 80); | 182 canvas->translate(0, 80); |
183 | 183 |
184 /* | 184 /* |
185 * combos of clip and crop rects that align with src and dst | 185 * combos of clip and crop rects that align with src and dst |
(...skipping 12 matching lines...) Expand all Loading... |
198 | 198 |
199 // crop==clip==dst | 199 // crop==clip==dst |
200 canvas->translate(100, 0); | 200 canvas->translate(100, 0); |
201 this->doDraw(canvas, r, SkOffsetImageFilter::Create(40, 0, nullptr, &cr2
), &r2); | 201 this->doDraw(canvas, r, SkOffsetImageFilter::Create(40, 0, nullptr, &cr2
), &r2); |
202 } | 202 } |
203 | 203 |
204 private: | 204 private: |
205 typedef skiagm::GM INHERITED; | 205 typedef skiagm::GM INHERITED; |
206 }; | 206 }; |
207 DEF_GM( return new SimpleOffsetImageFilterGM; ) | 207 DEF_GM( return new SimpleOffsetImageFilterGM; ) |
OLD | NEW |