| 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 "Test.h" | 8 #include "Test.h" |
| 9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkRect.h" | 10 #include "SkRect.h" |
| 11 #include "SkRandom.h" | 11 #include "SkRandom.h" |
| 12 | 12 |
| 13 static int nextRand(SkMWCRandom& rand, int min, int max) { | 13 static int nextRand(SkRandom& rand, int min, int max) { |
| 14 return min + (int)rand.nextRangeU(0, max - min); | 14 return min + (int)rand.nextRangeU(0, max - min); |
| 15 } | 15 } |
| 16 | 16 |
| 17 static void rand_irect(SkIRect* rect, int W, int H, SkMWCRandom& rand) { | 17 static void rand_irect(SkIRect* rect, int W, int H, SkRandom& rand) { |
| 18 const int DX = W / 2; | 18 const int DX = W / 2; |
| 19 const int DY = H / 2; | 19 const int DY = H / 2; |
| 20 | 20 |
| 21 rect->fLeft = nextRand(rand, -DX, W + DX); | 21 rect->fLeft = nextRand(rand, -DX, W + DX); |
| 22 rect->fTop = nextRand(rand, -DY, H + DY); | 22 rect->fTop = nextRand(rand, -DY, H + DY); |
| 23 rect->fRight = nextRand(rand, -DX, W + DX); | 23 rect->fRight = nextRand(rand, -DX, W + DX); |
| 24 rect->fBottom = nextRand(rand, -DY, H + DY); | 24 rect->fBottom = nextRand(rand, -DY, H + DY); |
| 25 rect->sort(); | 25 rect->sort(); |
| 26 } | 26 } |
| 27 | 27 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 50 const int W = 43; | 50 const int W = 43; |
| 51 const int H = 13; | 51 const int H = 13; |
| 52 | 52 |
| 53 SkBitmap bm1, bm8; | 53 SkBitmap bm1, bm8; |
| 54 | 54 |
| 55 bm1.setConfig(SkBitmap::kA1_Config, W, H); | 55 bm1.setConfig(SkBitmap::kA1_Config, W, H); |
| 56 bm1.allocPixels(); | 56 bm1.allocPixels(); |
| 57 bm8.setConfig(SkBitmap::kA8_Config, W, H); | 57 bm8.setConfig(SkBitmap::kA8_Config, W, H); |
| 58 bm8.allocPixels(); | 58 bm8.allocPixels(); |
| 59 | 59 |
| 60 SkMWCRandom rand; | 60 SkRandom rand; |
| 61 for (int i = 0; i < 10000; ++i) { | 61 for (int i = 0; i < 10000; ++i) { |
| 62 SkIRect area; | 62 SkIRect area; |
| 63 rand_irect(&area, W, H, rand); | 63 rand_irect(&area, W, H, rand); |
| 64 | 64 |
| 65 bm1.eraseColor(0); | 65 bm1.eraseColor(0); |
| 66 bm8.eraseColor(0); | 66 bm8.eraseColor(0); |
| 67 | 67 |
| 68 bm1.eraseArea(area, SK_ColorWHITE); | 68 bm1.eraseArea(area, SK_ColorWHITE); |
| 69 bm8.eraseArea(area, SK_ColorWHITE); | 69 bm8.eraseArea(area, SK_ColorWHITE); |
| 70 test_equal_A1_A8(reporter, bm1, bm8); | 70 test_equal_A1_A8(reporter, bm1, bm8); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 | 104 |
| 105 SkColor c = bm.getColor(1, 1); | 105 SkColor c = bm.getColor(1, 1); |
| 106 REPORTER_ASSERT(reporter, c == gRec[i].fOutColor); | 106 REPORTER_ASSERT(reporter, c == gRec[i].fOutColor); |
| 107 } | 107 } |
| 108 | 108 |
| 109 test_eraserect_A1(reporter); | 109 test_eraserect_A1(reporter); |
| 110 } | 110 } |
| 111 | 111 |
| 112 #include "TestClassDef.h" | 112 #include "TestClassDef.h" |
| 113 DEFINE_TESTCLASS("GetColor", TestGetColorClass, TestGetColor) | 113 DEFINE_TESTCLASS("GetColor", TestGetColorClass, TestGetColor) |
| OLD | NEW |