reed@google.com | 2ade086 | 2011-03-17 17:48:04 +0000 | [diff] [blame] | 1 | #include "Test.h" |
| 2 | #include "SkBitmap.h" |
| 3 | #include "SkCanvas.h" |
| 4 | |
| 5 | static bool check_for_all_zeros(const SkBitmap& bm) { |
| 6 | SkAutoLockPixels alp(bm); |
| 7 | |
| 8 | size_t count = bm.width() * bm.bytesPerPixel(); |
| 9 | for (int y = 0; y < bm.height(); y++) { |
| 10 | const uint8_t* ptr = reinterpret_cast<const uint8_t*>(bm.getAddr(0, y)); |
| 11 | for (size_t i = 0; i < count; i++) { |
| 12 | if (ptr[i]) { |
| 13 | return false; |
| 14 | } |
| 15 | } |
| 16 | } |
| 17 | return true; |
| 18 | } |
| 19 | |
| 20 | static const int gWidth = 256; |
| 21 | static const int gHeight = 256; |
| 22 | |
| 23 | static void create(SkBitmap* bm, SkBitmap::Config config, SkColor color) { |
| 24 | bm->setConfig(config, gWidth, gHeight); |
| 25 | bm->allocPixels(); |
| 26 | bm->eraseColor(color); |
| 27 | } |
| 28 | |
| 29 | static void TestDrawBitmapRect(skiatest::Reporter* reporter) { |
| 30 | SkBitmap src, dst; |
| 31 | |
| 32 | create(&src, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF); |
| 33 | create(&dst, SkBitmap::kARGB_8888_Config, 0); |
| 34 | |
| 35 | SkCanvas canvas(dst); |
| 36 | |
| 37 | SkIRect srcR = { gWidth, 0, gWidth + 16, 16 }; |
| 38 | SkRect dstR = { 0, 0, SkIntToScalar(16), SkIntToScalar(16) }; |
| 39 | |
| 40 | canvas.drawBitmapRect(src, &srcR, dstR, NULL); |
| 41 | |
| 42 | // ensure that we draw nothing if srcR does not intersect the bitmap |
| 43 | REPORTER_ASSERT(reporter, check_for_all_zeros(dst)); |
| 44 | } |
| 45 | |
| 46 | #include "TestClassDef.h" |
| 47 | DEFINE_TESTCLASS("DrawBitmapRect", TestDrawBitmapRectClass, TestDrawBitmapRect) |