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 "SkArithmeticMode.h" | 9 #include "SkArithmeticMode.h" |
| 10 #include "SkOffsetImageFilter.h" |
10 #include "SkXfermodeImageFilter.h" | 11 #include "SkXfermodeImageFilter.h" |
11 #include "SkBitmapSource.h" | 12 #include "SkBitmapSource.h" |
12 | 13 |
13 #define WIDTH 600 | 14 #define WIDTH 600 |
14 #define HEIGHT 600 | 15 #define HEIGHT 600 |
15 #define MARGIN 12 | 16 #define MARGIN 12 |
16 | 17 |
17 namespace skiagm { | 18 namespace skiagm { |
18 | 19 |
19 class XfermodeImageFilterGM : public GM { | 20 class XfermodeImageFilterGM : public GM { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint); | 62 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint); |
62 canvas.restore(); | 63 canvas.restore(); |
63 } | 64 } |
64 } | 65 } |
65 } | 66 } |
66 | 67 |
67 virtual SkISize onISize() { | 68 virtual SkISize onISize() { |
68 return make_isize(WIDTH, HEIGHT); | 69 return make_isize(WIDTH, HEIGHT); |
69 } | 70 } |
70 | 71 |
71 void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, const SkPai
nt& paint, SkScalar x, SkScalar y) { | 72 void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, const SkPai
nt& paint, |
| 73 SkScalar x, SkScalar y) { |
72 canvas->save(); | 74 canvas->save(); |
73 canvas->clipRect(SkRect::MakeXYWH(x, y, | 75 canvas->clipRect(SkRect::MakeXYWH(x, y, |
74 SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height()))); | 76 SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height()))); |
75 canvas->drawBitmap(bitmap, x, y, &paint); | 77 canvas->drawBitmap(bitmap, x, y, &paint); |
76 canvas->restore(); | 78 canvas->restore(); |
77 } | 79 } |
78 | 80 |
79 virtual void onDraw(SkCanvas* canvas) { | 81 virtual void onDraw(SkCanvas* canvas) { |
80 if (!fInitialized) { | 82 if (!fInitialized) { |
81 make_bitmap(); | 83 make_bitmap(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 { SkXfermode::kHue_Mode, "Hue" }, | 120 { SkXfermode::kHue_Mode, "Hue" }, |
119 { SkXfermode::kSaturation_Mode, "Saturation" }, | 121 { SkXfermode::kSaturation_Mode, "Saturation" }, |
120 { SkXfermode::kColor_Mode, "Color" }, | 122 { SkXfermode::kColor_Mode, "Color" }, |
121 { SkXfermode::kLuminosity_Mode, "Luminosity" }, | 123 { SkXfermode::kLuminosity_Mode, "Luminosity" }, |
122 }; | 124 }; |
123 | 125 |
124 int x = 0, y = 0; | 126 int x = 0, y = 0; |
125 SkAutoTUnref<SkImageFilter> background(SkNEW_ARGS(SkBitmapSource, (fChec
kerboard))); | 127 SkAutoTUnref<SkImageFilter> background(SkNEW_ARGS(SkBitmapSource, (fChec
kerboard))); |
126 for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) { | 128 for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) { |
127 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(gModes[i].fMode)); | 129 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(gModes[i].fMode)); |
128 SkAutoTUnref<SkImageFilter> filter(SkNEW_ARGS(SkXfermodeImageFilter,
(mode, background))); | 130 SkAutoTUnref<SkImageFilter> filter(SkNEW_ARGS( |
| 131 SkXfermodeImageFilter, (mode, background))); |
129 paint.setImageFilter(filter); | 132 paint.setImageFilter(filter); |
130 drawClippedBitmap(canvas, fBitmap, paint, SkIntToScalar(x), SkIntToS
calar(y)); | 133 drawClippedBitmap(canvas, fBitmap, paint, SkIntToScalar(x), SkIntToS
calar(y)); |
131 x += fBitmap.width() + MARGIN; | 134 x += fBitmap.width() + MARGIN; |
132 if (x + fBitmap.width() > WIDTH) { | 135 if (x + fBitmap.width() > WIDTH) { |
133 x = 0; | 136 x = 0; |
134 y += fBitmap.height() + MARGIN; | 137 y += fBitmap.height() + MARGIN; |
135 } | 138 } |
136 } | 139 } |
137 // Test arithmetic mode as image filter | 140 // Test arithmetic mode as image filter |
138 SkAutoTUnref<SkXfermode> mode(SkArithmeticMode::Create(0, SK_Scalar1, SK
_Scalar1, 0)); | 141 SkAutoTUnref<SkXfermode> mode(SkArithmeticMode::Create(0, SK_Scalar1, SK
_Scalar1, 0)); |
139 SkAutoTUnref<SkImageFilter> filter(SkNEW_ARGS(SkXfermodeImageFilter, (mo
de, background))); | 142 SkAutoTUnref<SkImageFilter> filter(SkNEW_ARGS(SkXfermodeImageFilter, (mo
de, background))); |
140 paint.setImageFilter(filter); | 143 paint.setImageFilter(filter); |
141 drawClippedBitmap(canvas, fBitmap, paint, SkIntToScalar(x), SkIntToScala
r(y)); | 144 drawClippedBitmap(canvas, fBitmap, paint, SkIntToScalar(x), SkIntToScala
r(y)); |
142 x += fBitmap.width() + MARGIN; | 145 x += fBitmap.width() + MARGIN; |
143 if (x + fBitmap.width() > WIDTH) { | 146 if (x + fBitmap.width() > WIDTH) { |
144 x = 0; | 147 x = 0; |
145 y += fBitmap.height() + MARGIN; | 148 y += fBitmap.height() + MARGIN; |
146 } | 149 } |
147 // Test NULL mode | 150 // Test NULL mode |
148 filter.reset(SkNEW_ARGS(SkXfermodeImageFilter, (NULL, background))); | 151 filter.reset(SkNEW_ARGS(SkXfermodeImageFilter, (NULL, background))); |
149 paint.setImageFilter(filter); | 152 paint.setImageFilter(filter); |
150 drawClippedBitmap(canvas, fBitmap, paint, SkIntToScalar(x), SkIntToScala
r(y)); | 153 drawClippedBitmap(canvas, fBitmap, paint, SkIntToScalar(x), SkIntToScala
r(y)); |
| 154 x += fBitmap.width() + MARGIN; |
| 155 if (x + fBitmap.width() > WIDTH) { |
| 156 x = 0; |
| 157 y += fBitmap.height() + MARGIN; |
| 158 } |
| 159 // Test offsets on SrcMode (uses fixed-function blend) |
| 160 SkAutoTUnref<SkImageFilter> foreground(SkNEW_ARGS(SkBitmapSource, (fBitm
ap))); |
| 161 SkAutoTUnref<SkImageFilter> offsetForeground(SkNEW_ARGS(SkOffsetImageFil
ter, |
| 162 (SkIntToScalar(4), SkIntToScalar(-4), foreground))); |
| 163 SkAutoTUnref<SkImageFilter> offsetBackground(SkNEW_ARGS(SkOffsetImageFil
ter, |
| 164 (SkIntToScalar(4), SkIntToScalar(4), background))); |
| 165 mode.reset(SkXfermode::Create(SkXfermode::kSrcOver_Mode)); |
| 166 filter.reset(SkNEW_ARGS(SkXfermodeImageFilter, |
| 167 (mode, offsetBackground, offsetForeground))); |
| 168 paint.setImageFilter(filter); |
| 169 canvas->save(); |
| 170 canvas->clipRect(SkRect::MakeXYWH(x, y, |
| 171 SkIntToScalar(fBitmap.width() + 4), SkIntToScalar(fBitmap.height() +
4))); |
| 172 canvas->drawPaint(paint); |
| 173 canvas->restore(); |
| 174 x += fBitmap.width() + MARGIN; |
| 175 if (x + fBitmap.width() > WIDTH) { |
| 176 x = 0; |
| 177 y += fBitmap.height() + MARGIN; |
| 178 } |
| 179 // Test offsets on Darken (uses shader blend) |
| 180 mode.reset(SkXfermode::Create(SkXfermode::kDarken_Mode)); |
| 181 filter.reset(SkNEW_ARGS(SkXfermodeImageFilter, (mode, offsetBackground,
offsetForeground))); |
| 182 paint.setImageFilter(filter); |
| 183 canvas->save(); |
| 184 canvas->clipRect(SkRect::MakeXYWH(x, y, |
| 185 SkIntToScalar(fBitmap.width() + 4), SkIntToScalar(fBitmap.height() +
4))); |
| 186 canvas->drawPaint(paint); |
| 187 canvas->restore(); |
151 } | 188 } |
152 private: | 189 private: |
153 typedef GM INHERITED; | 190 typedef GM INHERITED; |
154 SkBitmap fBitmap, fCheckerboard; | 191 SkBitmap fBitmap, fCheckerboard; |
155 bool fInitialized; | 192 bool fInitialized; |
156 }; | 193 }; |
157 | 194 |
158 ////////////////////////////////////////////////////////////////////////////// | 195 ////////////////////////////////////////////////////////////////////////////// |
159 | 196 |
160 static GM* MyFactory(void*) { return new XfermodeImageFilterGM; } | 197 static GM* MyFactory(void*) { return new XfermodeImageFilterGM; } |
161 static GMRegistry reg(MyFactory); | 198 static GMRegistry reg(MyFactory); |
162 | 199 |
163 } | 200 } |
OLD | NEW |