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 "sk_tool_utils.h" | 9 #include "sk_tool_utils.h" |
10 #include "SkArithmeticMode.h" | 10 #include "SkArithmeticMode.h" |
11 #include "SkImage.h" | 11 #include "SkImage.h" |
12 #include "SkImageSource.h" | 12 #include "SkImageSource.h" |
13 #include "SkOffsetImageFilter.h" | 13 #include "SkOffsetImageFilter.h" |
14 #include "SkXfermodeImageFilter.h" | 14 #include "SkXfermodeImageFilter.h" |
15 | 15 |
16 #define WIDTH 600 | 16 #define WIDTH 600 |
17 #define HEIGHT 600 | 17 #define HEIGHT 700 |
18 #define MARGIN 12 | 18 #define MARGIN 12 |
19 | 19 |
20 namespace skiagm { | 20 namespace skiagm { |
21 | 21 |
22 class XfermodeImageFilterGM : public GM { | 22 class XfermodeImageFilterGM : public GM { |
23 public: | 23 public: |
24 XfermodeImageFilterGM(){ | 24 XfermodeImageFilterGM(){ |
25 this->setBGColor(0xFF000000); | 25 this->setBGColor(0xFF000000); |
26 } | 26 } |
27 | 27 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 filter.reset(SkXfermodeImageFilter::Create( | 162 filter.reset(SkXfermodeImageFilter::Create( |
163 mode, offsetBackground, offsetForeground, &r ect)); | 163 mode, offsetBackground, offsetForeground, &r ect)); |
164 paint.setImageFilter(filter); | 164 paint.setImageFilter(filter); |
165 DrawClippedPaint(canvas, clipRect, paint, x, y); | 165 DrawClippedPaint(canvas, clipRect, paint, x, y); |
166 x += fBitmap.width() + MARGIN; | 166 x += fBitmap.width() + MARGIN; |
167 if (x + fBitmap.width() > WIDTH) { | 167 if (x + fBitmap.width() > WIDTH) { |
168 x = 0; | 168 x = 0; |
169 y += fBitmap.height() + MARGIN; | 169 y += fBitmap.height() + MARGIN; |
170 } | 170 } |
171 } | 171 } |
172 // Test small bg, large fg with Screen (uses shader blend) | |
173 mode.reset(SkXfermode::Create(SkXfermode::kScreen_Mode)); | |
174 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(10, 10, 60, 60)); | |
robertphillips
2016/01/13 20:13:15
\n ?
Stephen White
2016/01/13 21:32:31
Done.
| |
175 SkAutoTUnref<SkImageFilter> cropped(SkOffsetImageFilter::Create(0, 0, fo reground, &cropRect)); | |
176 filter.reset(SkXfermodeImageFilter::Create(mode, cropped, background)); | |
177 paint.setImageFilter(filter); | |
178 DrawClippedPaint(canvas, clipRect, paint, x, y); | |
179 x += fBitmap.width() + MARGIN; | |
180 if (x + fBitmap.width() > WIDTH) { | |
181 x = 0; | |
182 y += fBitmap.height() + MARGIN; | |
183 } | |
184 // Test small fg, large bg with Screen (uses shader blend) | |
185 filter.reset(SkXfermodeImageFilter::Create(mode, background, cropped)); | |
186 paint.setImageFilter(filter); | |
187 DrawClippedPaint(canvas, clipRect, paint, x, y); | |
188 x += fBitmap.width() + MARGIN; | |
189 if (x + fBitmap.width() > WIDTH) { | |
190 x = 0; | |
191 y += fBitmap.height() + MARGIN; | |
192 } | |
172 } | 193 } |
173 | 194 |
174 private: | 195 private: |
175 static void DrawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, cons t SkPaint& paint, | 196 static void DrawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, cons t SkPaint& paint, |
176 int x, int y) { | 197 int x, int y) { |
177 canvas->save(); | 198 canvas->save(); |
178 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); | 199 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); |
179 canvas->clipRect(SkRect::MakeWH( | 200 canvas->clipRect(SkRect::MakeWH( |
180 SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height()))); | 201 SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height()))); |
181 canvas->drawBitmap(bitmap, 0, 0, &paint); | 202 canvas->drawBitmap(bitmap, 0, 0, &paint); |
(...skipping 13 matching lines...) Expand all Loading... | |
195 SkAutoTUnref<SkImage> fCheckerboard; | 216 SkAutoTUnref<SkImage> fCheckerboard; |
196 | 217 |
197 typedef GM INHERITED; | 218 typedef GM INHERITED; |
198 }; | 219 }; |
199 | 220 |
200 ////////////////////////////////////////////////////////////////////////////// | 221 ////////////////////////////////////////////////////////////////////////////// |
201 | 222 |
202 DEF_GM( return new XfermodeImageFilterGM; ); | 223 DEF_GM( return new XfermodeImageFilterGM; ); |
203 | 224 |
204 } | 225 } |
OLD | NEW |