epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
reed@google.com | 2ade086 | 2011-03-17 17:48:04 +0000 | [diff] [blame] | 8 | #include "Test.h" |
| 9 | #include "SkBitmap.h" |
| 10 | #include "SkCanvas.h" |
reed@google.com | cef5bb4 | 2013-10-15 20:05:24 +0000 | [diff] [blame] | 11 | #include "SkData.h" |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 12 | #include "SkDiscardableMemoryPool.h" |
| 13 | #include "SkDiscardablePixelRef.h" |
reed@google.com | cef5bb4 | 2013-10-15 20:05:24 +0000 | [diff] [blame] | 14 | #include "SkPaint.h" |
reed@google.com | 99c114e | 2012-05-03 20:14:26 +0000 | [diff] [blame] | 15 | #include "SkShader.h" |
reed@google.com | cef5bb4 | 2013-10-15 20:05:24 +0000 | [diff] [blame] | 16 | #include "SkSurface.h" |
reed@google.com | ad51430 | 2013-01-02 20:19:45 +0000 | [diff] [blame] | 17 | #include "SkRandom.h" |
| 18 | #include "SkMatrixUtils.h" |
| 19 | |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 20 | namespace { |
reed@google.com | cef5bb4 | 2013-10-15 20:05:24 +0000 | [diff] [blame] | 21 | // A BitmapFactory that always fails when asked to return pixels. |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 22 | class FailureImageGenerator : public SkImageGenerator { |
| 23 | public: |
| 24 | FailureImageGenerator() { } |
| 25 | virtual ~FailureImageGenerator() { } |
| 26 | virtual bool getInfo(SkImageInfo* info) { |
| 27 | info->fWidth = 100; |
| 28 | info->fHeight = 100; |
| 29 | info->fColorType = kPMColor_SkColorType; |
reed@google.com | cef5bb4 | 2013-10-15 20:05:24 +0000 | [diff] [blame] | 30 | info->fAlphaType = kPremul_SkAlphaType; |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 31 | return true; |
reed@google.com | cef5bb4 | 2013-10-15 20:05:24 +0000 | [diff] [blame] | 32 | } |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 33 | virtual bool getPixels(const SkImageInfo& info, |
| 34 | void* pixels, |
| 35 | size_t rowBytes) SK_OVERRIDE { |
| 36 | // this will deliberately return false if they are asking us |
| 37 | // to decode into pixels. |
| 38 | return false; |
| 39 | } |
| 40 | }; |
| 41 | } // namespace |
reed@google.com | cef5bb4 | 2013-10-15 20:05:24 +0000 | [diff] [blame] | 42 | |
| 43 | // crbug.com/295895 |
| 44 | // Crashing in skia when a pixelref fails in lockPixels |
| 45 | // |
| 46 | static void test_faulty_pixelref(skiatest::Reporter* reporter) { |
| 47 | // need a cache, but don't expect to use it, so the budget is not critical |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 48 | SkAutoTUnref<SkDiscardableMemoryPool> pool(SkNEW_ARGS(SkDiscardableMemoryPool, |
| 49 | (10 * 1000, NULL))); |
reed@google.com | cef5bb4 | 2013-10-15 20:05:24 +0000 | [diff] [blame] | 50 | SkBitmap bm; |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 51 | bool installSuccess = SkDiscardablePixelRef::Install(SkNEW(FailureImageGenerator), &bm, pool); |
| 52 | REPORTER_ASSERT(reporter, installSuccess); |
reed@google.com | cef5bb4 | 2013-10-15 20:05:24 +0000 | [diff] [blame] | 53 | // now our bitmap has a pixelref, but we know it will fail to lock |
| 54 | |
| 55 | SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(200, 200)); |
| 56 | SkCanvas* canvas = surface->getCanvas(); |
| 57 | |
| 58 | const SkPaint::FilterLevel levels[] = { |
| 59 | SkPaint::kNone_FilterLevel, |
| 60 | SkPaint::kLow_FilterLevel, |
| 61 | SkPaint::kMedium_FilterLevel, |
| 62 | SkPaint::kHigh_FilterLevel, |
| 63 | }; |
| 64 | |
| 65 | SkPaint paint; |
| 66 | canvas->scale(2, 2); // need a scale, otherwise we may ignore filtering |
| 67 | for (size_t i = 0; i < SK_ARRAY_COUNT(levels); ++i) { |
| 68 | paint.setFilterLevel(levels[i]); |
| 69 | canvas->drawBitmap(bm, 0, 0, &paint); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | /////////////////////////////////////////////////////////////////////////////// |
| 74 | |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 75 | static void rand_matrix(SkMatrix* mat, SkRandom& rand, unsigned mask) { |
reed@google.com | ad51430 | 2013-01-02 20:19:45 +0000 | [diff] [blame] | 76 | mat->setIdentity(); |
| 77 | if (mask & SkMatrix::kTranslate_Mask) { |
| 78 | mat->postTranslate(rand.nextSScalar1(), rand.nextSScalar1()); |
| 79 | } |
| 80 | if (mask & SkMatrix::kScale_Mask) { |
| 81 | mat->postScale(rand.nextSScalar1(), rand.nextSScalar1()); |
| 82 | } |
| 83 | if (mask & SkMatrix::kAffine_Mask) { |
| 84 | mat->postRotate(rand.nextSScalar1() * 360); |
| 85 | } |
| 86 | if (mask & SkMatrix::kPerspective_Mask) { |
| 87 | mat->setPerspX(rand.nextSScalar1()); |
| 88 | mat->setPerspY(rand.nextSScalar1()); |
| 89 | } |
| 90 | } |
| 91 | |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 92 | static void rand_size(SkISize* size, SkRandom& rand) { |
reed@google.com | ae57358 | 2013-01-03 15:22:40 +0000 | [diff] [blame] | 93 | size->set(rand.nextU() & 0xFFFF, rand.nextU() & 0xFFFF); |
| 94 | } |
| 95 | |
| 96 | static bool treat_as_sprite(const SkMatrix& mat, const SkISize& size, |
| 97 | unsigned bits) { |
| 98 | return SkTreatAsSprite(mat, size.width(), size.height(), bits); |
reed@google.com | ad51430 | 2013-01-02 20:19:45 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | static void test_treatAsSprite(skiatest::Reporter* reporter) { |
| 102 | const unsigned bilerBits = kSkSubPixelBitsForBilerp; |
| 103 | |
| 104 | SkMatrix mat; |
reed@google.com | ae57358 | 2013-01-03 15:22:40 +0000 | [diff] [blame] | 105 | SkISize size; |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 106 | SkRandom rand; |
reed@google.com | ad51430 | 2013-01-02 20:19:45 +0000 | [diff] [blame] | 107 | |
| 108 | // assert: translate-only no-filter can always be treated as sprite |
| 109 | for (int i = 0; i < 1000; ++i) { |
| 110 | rand_matrix(&mat, rand, SkMatrix::kTranslate_Mask); |
| 111 | for (int j = 0; j < 1000; ++j) { |
reed@google.com | ae57358 | 2013-01-03 15:22:40 +0000 | [diff] [blame] | 112 | rand_size(&size, rand); |
| 113 | REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, 0)); |
reed@google.com | ad51430 | 2013-01-02 20:19:45 +0000 | [diff] [blame] | 114 | } |
| 115 | } |
skia.committer@gmail.com | 422188f | 2013-01-03 02:01:32 +0000 | [diff] [blame] | 116 | |
reed@google.com | ad51430 | 2013-01-02 20:19:45 +0000 | [diff] [blame] | 117 | // assert: rotate/perspect is never treated as sprite |
| 118 | for (int i = 0; i < 1000; ++i) { |
| 119 | rand_matrix(&mat, rand, SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask); |
| 120 | for (int j = 0; j < 1000; ++j) { |
reed@google.com | ae57358 | 2013-01-03 15:22:40 +0000 | [diff] [blame] | 121 | rand_size(&size, rand); |
| 122 | REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, 0)); |
| 123 | REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, bilerBits)); |
reed@google.com | ad51430 | 2013-01-02 20:19:45 +0000 | [diff] [blame] | 124 | } |
| 125 | } |
| 126 | |
reed@google.com | ae57358 | 2013-01-03 15:22:40 +0000 | [diff] [blame] | 127 | size.set(500, 600); |
reed@google.com | ad51430 | 2013-01-02 20:19:45 +0000 | [diff] [blame] | 128 | |
commit-bot@chromium.org | 4b413c8 | 2013-11-25 19:44:07 +0000 | [diff] [blame] | 129 | const SkScalar tooMuchSubpixel = 100.1f; |
reed@google.com | ad51430 | 2013-01-02 20:19:45 +0000 | [diff] [blame] | 130 | mat.setTranslate(tooMuchSubpixel, 0); |
reed@google.com | ae57358 | 2013-01-03 15:22:40 +0000 | [diff] [blame] | 131 | REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, bilerBits)); |
reed@google.com | ad51430 | 2013-01-02 20:19:45 +0000 | [diff] [blame] | 132 | mat.setTranslate(0, tooMuchSubpixel); |
reed@google.com | ae57358 | 2013-01-03 15:22:40 +0000 | [diff] [blame] | 133 | REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, bilerBits)); |
reed@google.com | ad51430 | 2013-01-02 20:19:45 +0000 | [diff] [blame] | 134 | |
commit-bot@chromium.org | 4b413c8 | 2013-11-25 19:44:07 +0000 | [diff] [blame] | 135 | const SkScalar tinySubPixel = 100.02f; |
reed@google.com | ad51430 | 2013-01-02 20:19:45 +0000 | [diff] [blame] | 136 | mat.setTranslate(tinySubPixel, 0); |
reed@google.com | ae57358 | 2013-01-03 15:22:40 +0000 | [diff] [blame] | 137 | REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, bilerBits)); |
reed@google.com | ad51430 | 2013-01-02 20:19:45 +0000 | [diff] [blame] | 138 | mat.setTranslate(0, tinySubPixel); |
reed@google.com | ae57358 | 2013-01-03 15:22:40 +0000 | [diff] [blame] | 139 | REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, bilerBits)); |
skia.committer@gmail.com | 422188f | 2013-01-03 02:01:32 +0000 | [diff] [blame] | 140 | |
reed@google.com | ad51430 | 2013-01-02 20:19:45 +0000 | [diff] [blame] | 141 | const SkScalar twoThirds = SK_Scalar1 * 2 / 3; |
reed@google.com | ae57358 | 2013-01-03 15:22:40 +0000 | [diff] [blame] | 142 | const SkScalar bigScale = SkScalarDiv(size.width() + twoThirds, size.width()); |
reed@google.com | ad51430 | 2013-01-02 20:19:45 +0000 | [diff] [blame] | 143 | mat.setScale(bigScale, bigScale); |
reed@google.com | ae57358 | 2013-01-03 15:22:40 +0000 | [diff] [blame] | 144 | REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, false)); |
| 145 | REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, bilerBits)); |
skia.committer@gmail.com | 422188f | 2013-01-03 02:01:32 +0000 | [diff] [blame] | 146 | |
reed@google.com | ad51430 | 2013-01-02 20:19:45 +0000 | [diff] [blame] | 147 | const SkScalar oneThird = SK_Scalar1 / 3; |
reed@google.com | ae57358 | 2013-01-03 15:22:40 +0000 | [diff] [blame] | 148 | const SkScalar smallScale = SkScalarDiv(size.width() + oneThird, size.width()); |
reed@google.com | ad51430 | 2013-01-02 20:19:45 +0000 | [diff] [blame] | 149 | mat.setScale(smallScale, smallScale); |
reed@google.com | ae57358 | 2013-01-03 15:22:40 +0000 | [diff] [blame] | 150 | REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, false)); |
| 151 | REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, bilerBits)); |
skia.committer@gmail.com | 422188f | 2013-01-03 02:01:32 +0000 | [diff] [blame] | 152 | |
reed@google.com | ad51430 | 2013-01-02 20:19:45 +0000 | [diff] [blame] | 153 | const SkScalar oneFortyth = SK_Scalar1 / 40; |
reed@google.com | ae57358 | 2013-01-03 15:22:40 +0000 | [diff] [blame] | 154 | const SkScalar tinyScale = SkScalarDiv(size.width() + oneFortyth, size.width()); |
reed@google.com | ad51430 | 2013-01-02 20:19:45 +0000 | [diff] [blame] | 155 | mat.setScale(tinyScale, tinyScale); |
reed@google.com | ae57358 | 2013-01-03 15:22:40 +0000 | [diff] [blame] | 156 | REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, false)); |
| 157 | REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, bilerBits)); |
reed@google.com | ad51430 | 2013-01-02 20:19:45 +0000 | [diff] [blame] | 158 | } |
reed@google.com | 99c114e | 2012-05-03 20:14:26 +0000 | [diff] [blame] | 159 | |
| 160 | static void assert_ifDrawnTo(skiatest::Reporter* reporter, |
| 161 | const SkBitmap& bm, bool shouldBeDrawn) { |
| 162 | for (int y = 0; y < bm.height(); ++y) { |
| 163 | for (int x = 0; x < bm.width(); ++x) { |
| 164 | if (shouldBeDrawn) { |
commit-bot@chromium.org | c2050e3 | 2013-07-15 13:10:31 +0000 | [diff] [blame] | 165 | if (SK_ColorTRANSPARENT == *bm.getAddr32(x, y)) { |
reed@google.com | 99c114e | 2012-05-03 20:14:26 +0000 | [diff] [blame] | 166 | REPORTER_ASSERT(reporter, false); |
| 167 | return; |
| 168 | } |
| 169 | } else { |
| 170 | // should not be drawn |
commit-bot@chromium.org | c2050e3 | 2013-07-15 13:10:31 +0000 | [diff] [blame] | 171 | if (SK_ColorTRANSPARENT != *bm.getAddr32(x, y)) { |
reed@google.com | 99c114e | 2012-05-03 20:14:26 +0000 | [diff] [blame] | 172 | REPORTER_ASSERT(reporter, false); |
| 173 | return; |
| 174 | } |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | static void test_wacky_bitmapshader(skiatest::Reporter* reporter, |
| 181 | int width, int height, bool shouldBeDrawn) { |
| 182 | SkBitmap dev; |
| 183 | dev.setConfig(SkBitmap::kARGB_8888_Config, 0x56F, 0x4f6); |
| 184 | dev.allocPixels(); |
junov@google.com | dbfac8a | 2012-12-06 21:47:40 +0000 | [diff] [blame] | 185 | dev.eraseColor(SK_ColorTRANSPARENT); // necessary, so we know if we draw to it |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 186 | |
reed@google.com | 99c114e | 2012-05-03 20:14:26 +0000 | [diff] [blame] | 187 | SkMatrix matrix; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 188 | |
reed@google.com | 99c114e | 2012-05-03 20:14:26 +0000 | [diff] [blame] | 189 | SkCanvas c(dev); |
commit-bot@chromium.org | 4b413c8 | 2013-11-25 19:44:07 +0000 | [diff] [blame] | 190 | matrix.setAll(-119.34097f, |
| 191 | -43.436558f, |
| 192 | 93489.945f, |
| 193 | 43.436558f, |
| 194 | -119.34097f, |
| 195 | 123.98426f, |
robertphillips@google.com | 4debcac | 2012-05-14 16:33:36 +0000 | [diff] [blame] | 196 | 0, 0, SK_Scalar1); |
reed@google.com | 99c114e | 2012-05-03 20:14:26 +0000 | [diff] [blame] | 197 | c.concat(matrix); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 198 | |
reed@google.com | 99c114e | 2012-05-03 20:14:26 +0000 | [diff] [blame] | 199 | SkBitmap bm; |
| 200 | bm.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
| 201 | bm.allocPixels(); |
| 202 | bm.eraseColor(SK_ColorRED); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 203 | |
reed@google.com | 99c114e | 2012-05-03 20:14:26 +0000 | [diff] [blame] | 204 | SkShader* s = SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode, |
| 205 | SkShader::kRepeat_TileMode); |
commit-bot@chromium.org | 4b413c8 | 2013-11-25 19:44:07 +0000 | [diff] [blame] | 206 | matrix.setAll(0.0078740157f, |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 207 | 0, |
robertphillips@google.com | 4debcac | 2012-05-14 16:33:36 +0000 | [diff] [blame] | 208 | SkIntToScalar(249), |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 209 | 0, |
commit-bot@chromium.org | 4b413c8 | 2013-11-25 19:44:07 +0000 | [diff] [blame] | 210 | 0.0078740157f, |
robertphillips@google.com | 4debcac | 2012-05-14 16:33:36 +0000 | [diff] [blame] | 211 | SkIntToScalar(239), |
| 212 | 0, 0, SK_Scalar1); |
reed@google.com | 99c114e | 2012-05-03 20:14:26 +0000 | [diff] [blame] | 213 | s->setLocalMatrix(matrix); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 214 | |
reed@google.com | 99c114e | 2012-05-03 20:14:26 +0000 | [diff] [blame] | 215 | SkPaint paint; |
| 216 | paint.setShader(s)->unref(); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 217 | |
reed@google.com | 99c114e | 2012-05-03 20:14:26 +0000 | [diff] [blame] | 218 | SkRect r = SkRect::MakeXYWH(681, 239, 695, 253); |
| 219 | c.drawRect(r, paint); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 220 | |
reed@google.com | 99c114e | 2012-05-03 20:14:26 +0000 | [diff] [blame] | 221 | assert_ifDrawnTo(reporter, dev, shouldBeDrawn); |
| 222 | } |
| 223 | |
| 224 | /* |
| 225 | * Original bug was asserting that the matrix-proc had generated a (Y) value |
| 226 | * that was out of range. This led (in the release build) to the sampler-proc |
| 227 | * reading memory out-of-bounds of the original bitmap. |
| 228 | * |
| 229 | * We were numerically overflowing our 16bit coordinates that we communicate |
| 230 | * between these two procs. The fixes was in two parts: |
| 231 | * |
| 232 | * 1. Just don't draw bitmaps larger than 64K-1 in width or height, since we |
| 233 | * can't represent those coordinates in our transport format (yet). |
| 234 | * 2. Perform an unsigned shift during the calculation, so we don't get |
| 235 | * sign-extension bleed when packing the two values (X,Y) into our 32bit |
| 236 | * slot. |
| 237 | * |
| 238 | * This tests exercises the original setup, plus 3 more to ensure that we can, |
| 239 | * in fact, handle bitmaps at 64K-1 (assuming we don't exceed the total |
| 240 | * memory allocation limit). |
| 241 | */ |
| 242 | static void test_giantrepeat_crbug118018(skiatest::Reporter* reporter) { |
reed@google.com | 0da0627 | 2012-05-03 20:26:06 +0000 | [diff] [blame] | 243 | #ifdef SK_SCALAR_IS_FLOAT |
reed@google.com | 99c114e | 2012-05-03 20:14:26 +0000 | [diff] [blame] | 244 | static const struct { |
| 245 | int fWidth; |
| 246 | int fHeight; |
| 247 | bool fExpectedToDraw; |
| 248 | } gTests[] = { |
| 249 | { 0x1b294, 0x7f, false }, // crbug 118018 (width exceeds 64K) |
| 250 | { 0xFFFF, 0x7f, true }, // should draw, test max width |
| 251 | { 0x7f, 0xFFFF, true }, // should draw, test max height |
| 252 | { 0xFFFF, 0xFFFF, false }, // allocation fails (too much RAM) |
| 253 | }; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 254 | |
reed@google.com | 99c114e | 2012-05-03 20:14:26 +0000 | [diff] [blame] | 255 | for (size_t i = 0; i < SK_ARRAY_COUNT(gTests); ++i) { |
| 256 | test_wacky_bitmapshader(reporter, |
| 257 | gTests[i].fWidth, gTests[i].fHeight, |
| 258 | gTests[i].fExpectedToDraw); |
| 259 | } |
reed@google.com | 0da0627 | 2012-05-03 20:26:06 +0000 | [diff] [blame] | 260 | #endif |
reed@google.com | 99c114e | 2012-05-03 20:14:26 +0000 | [diff] [blame] | 261 | } |
reed@google.com | 0da0627 | 2012-05-03 20:26:06 +0000 | [diff] [blame] | 262 | |
reed@google.com | 99c114e | 2012-05-03 20:14:26 +0000 | [diff] [blame] | 263 | /////////////////////////////////////////////////////////////////////////////// |
reed@google.com | 2ade086 | 2011-03-17 17:48:04 +0000 | [diff] [blame] | 264 | |
sugoi@google.com | 54f0d1b | 2013-02-27 19:17:41 +0000 | [diff] [blame] | 265 | static void test_nan_antihair() { |
reed@google.com | 6de0bfc | 2012-03-30 17:43:33 +0000 | [diff] [blame] | 266 | SkBitmap bm; |
| 267 | bm.setConfig(SkBitmap::kARGB_8888_Config, 20, 20); |
| 268 | bm.allocPixels(); |
| 269 | |
| 270 | SkCanvas canvas(bm); |
| 271 | |
| 272 | SkPath path; |
| 273 | path.moveTo(0, 0); |
| 274 | path.lineTo(10, SK_ScalarNaN); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 275 | |
reed@google.com | 6de0bfc | 2012-03-30 17:43:33 +0000 | [diff] [blame] | 276 | SkPaint paint; |
| 277 | paint.setAntiAlias(true); |
| 278 | paint.setStyle(SkPaint::kStroke_Style); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 279 | |
reed@google.com | 6de0bfc | 2012-03-30 17:43:33 +0000 | [diff] [blame] | 280 | // before our fix to SkScan_Antihair.cpp to check for integral NaN (0x800...) |
| 281 | // this would trigger an assert/crash. |
| 282 | // |
| 283 | // see rev. 3558 |
| 284 | canvas.drawPath(path, paint); |
| 285 | } |
| 286 | |
reed@google.com | 2ade086 | 2011-03-17 17:48:04 +0000 | [diff] [blame] | 287 | static bool check_for_all_zeros(const SkBitmap& bm) { |
| 288 | SkAutoLockPixels alp(bm); |
| 289 | |
| 290 | size_t count = bm.width() * bm.bytesPerPixel(); |
| 291 | for (int y = 0; y < bm.height(); y++) { |
| 292 | const uint8_t* ptr = reinterpret_cast<const uint8_t*>(bm.getAddr(0, y)); |
| 293 | for (size_t i = 0; i < count; i++) { |
| 294 | if (ptr[i]) { |
| 295 | return false; |
| 296 | } |
| 297 | } |
| 298 | } |
| 299 | return true; |
| 300 | } |
| 301 | |
| 302 | static const int gWidth = 256; |
| 303 | static const int gHeight = 256; |
| 304 | |
| 305 | static void create(SkBitmap* bm, SkBitmap::Config config, SkColor color) { |
| 306 | bm->setConfig(config, gWidth, gHeight); |
| 307 | bm->allocPixels(); |
| 308 | bm->eraseColor(color); |
| 309 | } |
| 310 | |
| 311 | static void TestDrawBitmapRect(skiatest::Reporter* reporter) { |
| 312 | SkBitmap src, dst; |
| 313 | |
| 314 | create(&src, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF); |
| 315 | create(&dst, SkBitmap::kARGB_8888_Config, 0); |
| 316 | |
| 317 | SkCanvas canvas(dst); |
| 318 | |
| 319 | SkIRect srcR = { gWidth, 0, gWidth + 16, 16 }; |
| 320 | SkRect dstR = { 0, 0, SkIntToScalar(16), SkIntToScalar(16) }; |
| 321 | |
| 322 | canvas.drawBitmapRect(src, &srcR, dstR, NULL); |
| 323 | |
| 324 | // ensure that we draw nothing if srcR does not intersect the bitmap |
| 325 | REPORTER_ASSERT(reporter, check_for_all_zeros(dst)); |
reed@google.com | 6de0bfc | 2012-03-30 17:43:33 +0000 | [diff] [blame] | 326 | |
sugoi@google.com | 54f0d1b | 2013-02-27 19:17:41 +0000 | [diff] [blame] | 327 | test_nan_antihair(); |
reed@google.com | 99c114e | 2012-05-03 20:14:26 +0000 | [diff] [blame] | 328 | test_giantrepeat_crbug118018(reporter); |
reed@google.com | ad51430 | 2013-01-02 20:19:45 +0000 | [diff] [blame] | 329 | |
| 330 | test_treatAsSprite(reporter); |
reed@google.com | 23d0ab7 | 2013-10-15 20:14:00 +0000 | [diff] [blame] | 331 | test_faulty_pixelref(reporter); |
reed@google.com | 2ade086 | 2011-03-17 17:48:04 +0000 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | #include "TestClassDef.h" |
| 335 | DEFINE_TESTCLASS("DrawBitmapRect", TestDrawBitmapRectClass, TestDrawBitmapRect) |