OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "Test.h" | 8 #include "Test.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| 11 #include "SkData.h" |
| 12 #include "SkPaint.h" |
11 #include "SkShader.h" | 13 #include "SkShader.h" |
| 14 #include "SkSurface.h" |
12 #include "SkRandom.h" | 15 #include "SkRandom.h" |
13 #include "SkMatrixUtils.h" | 16 #include "SkMatrixUtils.h" |
14 | 17 |
| 18 #include "SkLazyPixelRef.h" |
| 19 #include "SkLruImageCache.h" |
| 20 |
| 21 // A BitmapFactory that always fails when asked to return pixels. |
| 22 static bool FailureDecoder(const void* data, size_t length, SkImage::Info* info, |
| 23 const SkBitmapFactory::Target* target) { |
| 24 if (info) { |
| 25 info->fWidth = info->fHeight = 100; |
| 26 info->fColorType = SkImage::kRGBA_8888_ColorType; |
| 27 info->fAlphaType = kPremul_SkAlphaType; |
| 28 } |
| 29 // this will deliberately return false if they are asking us to decode |
| 30 // into pixels. |
| 31 return NULL == target; |
| 32 } |
| 33 |
| 34 // crbug.com/295895 |
| 35 // Crashing in skia when a pixelref fails in lockPixels |
| 36 // |
| 37 static void test_faulty_pixelref(skiatest::Reporter* reporter) { |
| 38 // need a cache, but don't expect to use it, so the budget is not critical |
| 39 SkLruImageCache cache(10 * 1000); |
| 40 // construct a garbage data represent "bad" encoded data. |
| 41 SkAutoDataUnref data(SkData::NewFromMalloc(malloc(1000), 1000)); |
| 42 SkAutoTUnref<SkPixelRef> pr(new SkLazyPixelRef(data, FailureDecoder, &cache)
); |
| 43 |
| 44 SkBitmap bm; |
| 45 bm.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); |
| 46 bm.setPixelRef(pr); |
| 47 // now our bitmap has a pixelref, but we know it will fail to lock |
| 48 |
| 49 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(200, 200)); |
| 50 SkCanvas* canvas = surface->getCanvas(); |
| 51 |
| 52 const SkPaint::FilterLevel levels[] = { |
| 53 SkPaint::kNone_FilterLevel, |
| 54 SkPaint::kLow_FilterLevel, |
| 55 SkPaint::kMedium_FilterLevel, |
| 56 SkPaint::kHigh_FilterLevel, |
| 57 }; |
| 58 |
| 59 SkPaint paint; |
| 60 canvas->scale(2, 2); // need a scale, otherwise we may ignore filtering |
| 61 for (size_t i = 0; i < SK_ARRAY_COUNT(levels); ++i) { |
| 62 paint.setFilterLevel(levels[i]); |
| 63 canvas->drawBitmap(bm, 0, 0, &paint); |
| 64 } |
| 65 } |
| 66 |
| 67 /////////////////////////////////////////////////////////////////////////////// |
| 68 |
15 static void rand_matrix(SkMatrix* mat, SkRandom& rand, unsigned mask) { | 69 static void rand_matrix(SkMatrix* mat, SkRandom& rand, unsigned mask) { |
16 mat->setIdentity(); | 70 mat->setIdentity(); |
17 if (mask & SkMatrix::kTranslate_Mask) { | 71 if (mask & SkMatrix::kTranslate_Mask) { |
18 mat->postTranslate(rand.nextSScalar1(), rand.nextSScalar1()); | 72 mat->postTranslate(rand.nextSScalar1(), rand.nextSScalar1()); |
19 } | 73 } |
20 if (mask & SkMatrix::kScale_Mask) { | 74 if (mask & SkMatrix::kScale_Mask) { |
21 mat->postScale(rand.nextSScalar1(), rand.nextSScalar1()); | 75 mat->postScale(rand.nextSScalar1(), rand.nextSScalar1()); |
22 } | 76 } |
23 if (mask & SkMatrix::kAffine_Mask) { | 77 if (mask & SkMatrix::kAffine_Mask) { |
24 mat->postRotate(rand.nextSScalar1() * 360); | 78 mat->postRotate(rand.nextSScalar1() * 360); |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 | 315 |
262 canvas.drawBitmapRect(src, &srcR, dstR, NULL); | 316 canvas.drawBitmapRect(src, &srcR, dstR, NULL); |
263 | 317 |
264 // ensure that we draw nothing if srcR does not intersect the bitmap | 318 // ensure that we draw nothing if srcR does not intersect the bitmap |
265 REPORTER_ASSERT(reporter, check_for_all_zeros(dst)); | 319 REPORTER_ASSERT(reporter, check_for_all_zeros(dst)); |
266 | 320 |
267 test_nan_antihair(); | 321 test_nan_antihair(); |
268 test_giantrepeat_crbug118018(reporter); | 322 test_giantrepeat_crbug118018(reporter); |
269 | 323 |
270 test_treatAsSprite(reporter); | 324 test_treatAsSprite(reporter); |
| 325 |
| 326 if (false) { // will enable when fix lands |
| 327 test_faulty_pixelref(reporter); |
| 328 } |
271 } | 329 } |
272 | 330 |
273 #include "TestClassDef.h" | 331 #include "TestClassDef.h" |
274 DEFINE_TESTCLASS("DrawBitmapRect", TestDrawBitmapRectClass, TestDrawBitmapRect) | 332 DEFINE_TESTCLASS("DrawBitmapRect", TestDrawBitmapRectClass, TestDrawBitmapRect) |
OLD | NEW |