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 "SkOffsetImageFilter.h" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 { SkXfermode::kDifference_Mode, "Difference" }, | 123 { SkXfermode::kDifference_Mode, "Difference" }, |
124 { SkXfermode::kExclusion_Mode, "Exclusion" }, | 124 { SkXfermode::kExclusion_Mode, "Exclusion" }, |
125 { SkXfermode::kMultiply_Mode, "Multiply" }, | 125 { SkXfermode::kMultiply_Mode, "Multiply" }, |
126 { SkXfermode::kHue_Mode, "Hue" }, | 126 { SkXfermode::kHue_Mode, "Hue" }, |
127 { SkXfermode::kSaturation_Mode, "Saturation" }, | 127 { SkXfermode::kSaturation_Mode, "Saturation" }, |
128 { SkXfermode::kColor_Mode, "Color" }, | 128 { SkXfermode::kColor_Mode, "Color" }, |
129 { SkXfermode::kLuminosity_Mode, "Luminosity" }, | 129 { SkXfermode::kLuminosity_Mode, "Luminosity" }, |
130 }; | 130 }; |
131 | 131 |
132 int x = 0, y = 0; | 132 int x = 0, y = 0; |
133 SkAutoTUnref<SkImageFilter> background(SkNEW_ARGS(SkBitmapSource, (fChec
kerboard))); | 133 SkAutoTUnref<SkImageFilter> background(SkBitmapSource::Create(fCheckerbo
ard)); |
134 for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) { | 134 for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) { |
135 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(gModes[i].fMode)); | 135 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(gModes[i].fMode)); |
136 SkAutoTUnref<SkImageFilter> filter(SkNEW_ARGS( | 136 SkAutoTUnref<SkImageFilter> filter(SkXfermodeImageFilter::Create(mod
e, background)); |
137 SkXfermodeImageFilter, (mode, background))); | |
138 paint.setImageFilter(filter); | 137 paint.setImageFilter(filter); |
139 drawClippedBitmap(canvas, fBitmap, paint, x, y); | 138 drawClippedBitmap(canvas, fBitmap, paint, x, y); |
140 x += fBitmap.width() + MARGIN; | 139 x += fBitmap.width() + MARGIN; |
141 if (x + fBitmap.width() > WIDTH) { | 140 if (x + fBitmap.width() > WIDTH) { |
142 x = 0; | 141 x = 0; |
143 y += fBitmap.height() + MARGIN; | 142 y += fBitmap.height() + MARGIN; |
144 } | 143 } |
145 } | 144 } |
146 // Test arithmetic mode as image filter | 145 // Test arithmetic mode as image filter |
147 SkAutoTUnref<SkXfermode> mode(SkArithmeticMode::Create(0, SK_Scalar1, SK
_Scalar1, 0)); | 146 SkAutoTUnref<SkXfermode> mode(SkArithmeticMode::Create(0, SK_Scalar1, SK
_Scalar1, 0)); |
148 SkAutoTUnref<SkImageFilter> filter(SkNEW_ARGS(SkXfermodeImageFilter, (mo
de, background))); | 147 SkAutoTUnref<SkImageFilter> filter(SkXfermodeImageFilter::Create(mode, b
ackground)); |
149 paint.setImageFilter(filter); | 148 paint.setImageFilter(filter); |
150 drawClippedBitmap(canvas, fBitmap, paint, x, y); | 149 drawClippedBitmap(canvas, fBitmap, paint, x, y); |
151 x += fBitmap.width() + MARGIN; | 150 x += fBitmap.width() + MARGIN; |
152 if (x + fBitmap.width() > WIDTH) { | 151 if (x + fBitmap.width() > WIDTH) { |
153 x = 0; | 152 x = 0; |
154 y += fBitmap.height() + MARGIN; | 153 y += fBitmap.height() + MARGIN; |
155 } | 154 } |
156 // Test NULL mode | 155 // Test NULL mode |
157 filter.reset(SkNEW_ARGS(SkXfermodeImageFilter, (NULL, background))); | 156 filter.reset(SkXfermodeImageFilter::Create(NULL, background)); |
158 paint.setImageFilter(filter); | 157 paint.setImageFilter(filter); |
159 drawClippedBitmap(canvas, fBitmap, paint, x, y); | 158 drawClippedBitmap(canvas, fBitmap, paint, x, y); |
160 x += fBitmap.width() + MARGIN; | 159 x += fBitmap.width() + MARGIN; |
161 if (x + fBitmap.width() > WIDTH) { | 160 if (x + fBitmap.width() > WIDTH) { |
162 x = 0; | 161 x = 0; |
163 y += fBitmap.height() + MARGIN; | 162 y += fBitmap.height() + MARGIN; |
164 } | 163 } |
165 SkRect clipRect = SkRect::MakeWH(SkIntToScalar(fBitmap.width() + 4), | 164 SkRect clipRect = SkRect::MakeWH(SkIntToScalar(fBitmap.width() + 4), |
166 SkIntToScalar(fBitmap.height() + 4)); | 165 SkIntToScalar(fBitmap.height() + 4)); |
167 // Test offsets on SrcMode (uses fixed-function blend) | 166 // Test offsets on SrcMode (uses fixed-function blend) |
168 SkAutoTUnref<SkImageFilter> foreground(SkNEW_ARGS(SkBitmapSource, (fBitm
ap))); | 167 SkAutoTUnref<SkImageFilter> foreground(SkBitmapSource::Create(fBitmap)); |
169 SkAutoTUnref<SkImageFilter> offsetForeground(SkNEW_ARGS(SkOffsetImageFil
ter, | 168 SkAutoTUnref<SkImageFilter> offsetForeground(SkOffsetImageFilter::Create
( |
170 (SkIntToScalar(4), SkIntToScalar(-4), foreground))); | 169 SkIntToScalar(4), SkIntToScalar(-4), foreground)); |
171 SkAutoTUnref<SkImageFilter> offsetBackground(SkNEW_ARGS(SkOffsetImageFil
ter, | 170 SkAutoTUnref<SkImageFilter> offsetBackground(SkOffsetImageFilter::Create
( |
172 (SkIntToScalar(4), SkIntToScalar(4), background))); | 171 SkIntToScalar(4), SkIntToScalar(4), background)); |
173 mode.reset(SkXfermode::Create(SkXfermode::kSrcOver_Mode)); | 172 mode.reset(SkXfermode::Create(SkXfermode::kSrcOver_Mode)); |
174 filter.reset(SkNEW_ARGS(SkXfermodeImageFilter, | 173 filter.reset(SkXfermodeImageFilter::Create(mode, offsetBackground, offse
tForeground)); |
175 (mode, offsetBackground, offsetForeground))); | |
176 paint.setImageFilter(filter); | 174 paint.setImageFilter(filter); |
177 drawClippedPaint(canvas, clipRect, paint, x, y); | 175 drawClippedPaint(canvas, clipRect, paint, x, y); |
178 x += fBitmap.width() + MARGIN; | 176 x += fBitmap.width() + MARGIN; |
179 if (x + fBitmap.width() > WIDTH) { | 177 if (x + fBitmap.width() > WIDTH) { |
180 x = 0; | 178 x = 0; |
181 y += fBitmap.height() + MARGIN; | 179 y += fBitmap.height() + MARGIN; |
182 } | 180 } |
183 // Test offsets on Darken (uses shader blend) | 181 // Test offsets on Darken (uses shader blend) |
184 mode.reset(SkXfermode::Create(SkXfermode::kDarken_Mode)); | 182 mode.reset(SkXfermode::Create(SkXfermode::kDarken_Mode)); |
185 filter.reset(SkNEW_ARGS(SkXfermodeImageFilter, (mode, offsetBackground,
offsetForeground))); | 183 filter.reset(SkXfermodeImageFilter::Create(mode, offsetBackground, offse
tForeground)); |
186 paint.setImageFilter(filter); | 184 paint.setImageFilter(filter); |
187 drawClippedPaint(canvas, clipRect, paint, x, y); | 185 drawClippedPaint(canvas, clipRect, paint, x, y); |
188 x += fBitmap.width() + MARGIN; | 186 x += fBitmap.width() + MARGIN; |
189 if (x + fBitmap.width() > WIDTH) { | 187 if (x + fBitmap.width() > WIDTH) { |
190 x = 0; | 188 x = 0; |
191 y += fBitmap.height() + MARGIN; | 189 y += fBitmap.height() + MARGIN; |
192 } | 190 } |
193 // Test cropping | 191 // Test cropping |
194 static const size_t nbSamples = 3; | 192 static const size_t nbSamples = 3; |
195 SkXfermode::Mode sampledModes[nbSamples] = {SkXfermode::kOverlay_Mode, | 193 SkXfermode::Mode sampledModes[nbSamples] = {SkXfermode::kOverlay_Mode, |
196 SkXfermode::kSrcOver_Mode, | 194 SkXfermode::kSrcOver_Mode, |
197 SkXfermode::kPlus_Mode}; | 195 SkXfermode::kPlus_Mode}; |
198 int offsets[nbSamples][4] = {{ 10, 10, -16, -16}, | 196 int offsets[nbSamples][4] = {{ 10, 10, -16, -16}, |
199 { 10, 10, 10, 10}, | 197 { 10, 10, 10, 10}, |
200 {-10, -10, -6, -6}}; | 198 {-10, -10, -6, -6}}; |
201 for (size_t i = 0; i < nbSamples; ++i) { | 199 for (size_t i = 0; i < nbSamples; ++i) { |
202 SkIRect cropRect = SkIRect::MakeXYWH(offsets[i][0], | 200 SkIRect cropRect = SkIRect::MakeXYWH(offsets[i][0], |
203 offsets[i][1], | 201 offsets[i][1], |
204 fBitmap.width() + offsets[i][2
], | 202 fBitmap.width() + offsets[i][2
], |
205 fBitmap.height() + offsets[i][3
]); | 203 fBitmap.height() + offsets[i][3
]); |
206 SkImageFilter::CropRect rect(SkRect::Make(cropRect)); | 204 SkImageFilter::CropRect rect(SkRect::Make(cropRect)); |
207 mode.reset(SkXfermode::Create(sampledModes[i])); | 205 mode.reset(SkXfermode::Create(sampledModes[i])); |
208 filter.reset(SkNEW_ARGS(SkXfermodeImageFilter, | 206 filter.reset(SkXfermodeImageFilter::Create( |
209 (mode, offsetBackground, offsetForeground, &
rect))); | 207 mode, offsetBackground, offsetForeground, &r
ect)); |
210 paint.setImageFilter(filter); | 208 paint.setImageFilter(filter); |
211 drawClippedPaint(canvas, clipRect, paint, x, y); | 209 drawClippedPaint(canvas, clipRect, paint, x, y); |
212 x += fBitmap.width() + MARGIN; | 210 x += fBitmap.width() + MARGIN; |
213 if (x + fBitmap.width() > WIDTH) { | 211 if (x + fBitmap.width() > WIDTH) { |
214 x = 0; | 212 x = 0; |
215 y += fBitmap.height() + MARGIN; | 213 y += fBitmap.height() + MARGIN; |
216 } | 214 } |
217 } | 215 } |
218 } | 216 } |
219 private: | 217 private: |
220 SkBitmap fBitmap, fCheckerboard; | 218 SkBitmap fBitmap, fCheckerboard; |
221 typedef GM INHERITED; | 219 typedef GM INHERITED; |
222 }; | 220 }; |
223 | 221 |
224 ////////////////////////////////////////////////////////////////////////////// | 222 ////////////////////////////////////////////////////////////////////////////// |
225 | 223 |
226 DEF_GM( return new XfermodeImageFilterGM; ); | 224 DEF_GM( return new XfermodeImageFilterGM; ); |
227 | 225 |
228 } | 226 } |
OLD | NEW |