OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkData.h" | 10 #include "SkData.h" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 return; | 171 return; |
172 } | 172 } |
173 } | 173 } |
174 } | 174 } |
175 } | 175 } |
176 } | 176 } |
177 | 177 |
178 static void test_wacky_bitmapshader(skiatest::Reporter* reporter, | 178 static void test_wacky_bitmapshader(skiatest::Reporter* reporter, |
179 int width, int height, bool shouldBeDrawn) { | 179 int width, int height, bool shouldBeDrawn) { |
180 SkBitmap dev; | 180 SkBitmap dev; |
181 dev.setConfig(SkBitmap::kARGB_8888_Config, 0x56F, 0x4f6); | 181 dev.allocN32Pixels(0x56F, 0x4f6); |
182 dev.allocPixels(); | |
183 dev.eraseColor(SK_ColorTRANSPARENT); // necessary, so we know if we draw to
it | 182 dev.eraseColor(SK_ColorTRANSPARENT); // necessary, so we know if we draw to
it |
184 | 183 |
185 SkMatrix matrix; | 184 SkMatrix matrix; |
186 | 185 |
187 SkCanvas c(dev); | 186 SkCanvas c(dev); |
188 matrix.setAll(-119.34097f, | 187 matrix.setAll(-119.34097f, |
189 -43.436558f, | 188 -43.436558f, |
190 93489.945f, | 189 93489.945f, |
191 43.436558f, | 190 43.436558f, |
192 -119.34097f, | 191 -119.34097f, |
193 123.98426f, | 192 123.98426f, |
194 0, 0, SK_Scalar1); | 193 0, 0, SK_Scalar1); |
195 c.concat(matrix); | 194 c.concat(matrix); |
196 | 195 |
197 SkBitmap bm; | 196 SkBitmap bm; |
198 bm.setConfig(SkBitmap::kARGB_8888_Config, width, height); | 197 bm.allocN32Pixels(width, height); |
199 bm.allocPixels(); | |
200 bm.eraseColor(SK_ColorRED); | 198 bm.eraseColor(SK_ColorRED); |
201 | 199 |
202 SkShader* s = SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode, | 200 SkShader* s = SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode, |
203 SkShader::kRepeat_TileMode); | 201 SkShader::kRepeat_TileMode); |
204 matrix.setAll(0.0078740157f, | 202 matrix.setAll(0.0078740157f, |
205 0, | 203 0, |
206 SkIntToScalar(249), | 204 SkIntToScalar(249), |
207 0, | 205 0, |
208 0.0078740157f, | 206 0.0078740157f, |
209 SkIntToScalar(239), | 207 SkIntToScalar(239), |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 test_wacky_bitmapshader(reporter, | 251 test_wacky_bitmapshader(reporter, |
254 gTests[i].fWidth, gTests[i].fHeight, | 252 gTests[i].fWidth, gTests[i].fHeight, |
255 gTests[i].fExpectedToDraw); | 253 gTests[i].fExpectedToDraw); |
256 } | 254 } |
257 } | 255 } |
258 | 256 |
259 /////////////////////////////////////////////////////////////////////////////// | 257 /////////////////////////////////////////////////////////////////////////////// |
260 | 258 |
261 static void test_nan_antihair() { | 259 static void test_nan_antihair() { |
262 SkBitmap bm; | 260 SkBitmap bm; |
263 bm.setConfig(SkBitmap::kARGB_8888_Config, 20, 20); | 261 bm.allocN32Pixels(20, 20); |
264 bm.allocPixels(); | |
265 | 262 |
266 SkCanvas canvas(bm); | 263 SkCanvas canvas(bm); |
267 | 264 |
268 SkPath path; | 265 SkPath path; |
269 path.moveTo(0, 0); | 266 path.moveTo(0, 0); |
270 path.lineTo(10, SK_ScalarNaN); | 267 path.lineTo(10, SK_ScalarNaN); |
271 | 268 |
272 SkPaint paint; | 269 SkPaint paint; |
273 paint.setAntiAlias(true); | 270 paint.setAntiAlias(true); |
274 paint.setStyle(SkPaint::kStroke_Style); | 271 paint.setStyle(SkPaint::kStroke_Style); |
(...skipping 16 matching lines...) Expand all Loading... |
291 return false; | 288 return false; |
292 } | 289 } |
293 } | 290 } |
294 } | 291 } |
295 return true; | 292 return true; |
296 } | 293 } |
297 | 294 |
298 static const int gWidth = 256; | 295 static const int gWidth = 256; |
299 static const int gHeight = 256; | 296 static const int gHeight = 256; |
300 | 297 |
301 static void create(SkBitmap* bm, SkBitmap::Config config, SkColor color) { | 298 static void create(SkBitmap* bm, SkColor color) { |
302 bm->setConfig(config, gWidth, gHeight); | 299 bm->allocN32Pixels(gWidth, gHeight); |
303 bm->allocPixels(); | |
304 bm->eraseColor(color); | 300 bm->eraseColor(color); |
305 } | 301 } |
306 | 302 |
307 DEF_TEST(DrawBitmapRect, reporter) { | 303 DEF_TEST(DrawBitmapRect, reporter) { |
308 SkBitmap src, dst; | 304 SkBitmap src, dst; |
309 | 305 |
310 create(&src, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF); | 306 create(&src, 0xFFFFFFFF); |
311 create(&dst, SkBitmap::kARGB_8888_Config, 0); | 307 create(&dst, 0); |
312 | 308 |
313 SkCanvas canvas(dst); | 309 SkCanvas canvas(dst); |
314 | 310 |
315 SkIRect srcR = { gWidth, 0, gWidth + 16, 16 }; | 311 SkIRect srcR = { gWidth, 0, gWidth + 16, 16 }; |
316 SkRect dstR = { 0, 0, SkIntToScalar(16), SkIntToScalar(16) }; | 312 SkRect dstR = { 0, 0, SkIntToScalar(16), SkIntToScalar(16) }; |
317 | 313 |
318 canvas.drawBitmapRect(src, &srcR, dstR, NULL); | 314 canvas.drawBitmapRect(src, &srcR, dstR, NULL); |
319 | 315 |
320 // ensure that we draw nothing if srcR does not intersect the bitmap | 316 // ensure that we draw nothing if srcR does not intersect the bitmap |
321 REPORTER_ASSERT(reporter, check_for_all_zeros(dst)); | 317 REPORTER_ASSERT(reporter, check_for_all_zeros(dst)); |
322 | 318 |
323 test_nan_antihair(); | 319 test_nan_antihair(); |
324 test_giantrepeat_crbug118018(reporter); | 320 test_giantrepeat_crbug118018(reporter); |
325 | 321 |
326 test_treatAsSprite(reporter); | 322 test_treatAsSprite(reporter); |
327 test_faulty_pixelref(reporter); | 323 test_faulty_pixelref(reporter); |
328 } | 324 } |
OLD | NEW |