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