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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
11 #include "SkGradientShader.h" | 11 #include "SkGradientShader.h" |
12 #include "SkRect.h" | 12 #include "SkRect.h" |
13 #include "Test.h" | 13 #include "Test.h" |
14 | 14 |
15 // these are in the same order as the SkColorType enum | 15 // these are in the same order as the SkColorType enum |
16 static const char* gConfigName[] = { | 16 static const char* gColorTypeName[] = { |
17 "Unknown", "Alpha8", "565", "4444", "RGBA", "BGRA", "Index8" | 17 "None", "A8", "565", "4444", "RGBA", "BGRA", "Index8" |
18 }; | 18 }; |
19 | 19 |
20 /** Returns -1 on success, else the x coord of the first bad pixel, return its | 20 /** Returns -1 on success, else the x coord of the first bad pixel, return its |
21 value in bad | 21 value in bad |
22 */ | 22 */ |
23 typedef int (*Proc)(const void*, int width, uint32_t expected, uint32_t* bad); | 23 typedef int (*Proc)(const void*, int width, uint32_t expected, uint32_t* bad); |
24 | 24 |
25 static int proc_32(const void* ptr, int w, uint32_t expected, uint32_t* bad) { | 25 static int proc_32(const void* ptr, int w, uint32_t expected, uint32_t* bad) { |
26 const SkPMColor* addr = static_cast<const SkPMColor*>(ptr); | 26 const SkPMColor* addr = static_cast<const SkPMColor*>(ptr); |
27 for (int x = 0; x < w; x++) { | 27 for (int x = 0; x < w; x++) { |
(...skipping 27 matching lines...) Expand all Loading... |
55 return -1; | 55 return -1; |
56 } | 56 } |
57 | 57 |
58 static int proc_bad(const void*, int, uint32_t, uint32_t* bad) { | 58 static int proc_bad(const void*, int, uint32_t, uint32_t* bad) { |
59 *bad = 0; | 59 *bad = 0; |
60 return 0; | 60 return 0; |
61 } | 61 } |
62 | 62 |
63 static Proc find_proc(const SkBitmap& bm, SkPMColor expect32, uint16_t expect16, | 63 static Proc find_proc(const SkBitmap& bm, SkPMColor expect32, uint16_t expect16, |
64 uint8_t expect8, uint32_t* expect) { | 64 uint8_t expect8, uint32_t* expect) { |
65 switch (bm.config()) { | 65 switch (bm.colorType()) { |
66 case SkBitmap::kARGB_8888_Config: | 66 case kPMColor_SkColorType: |
67 *expect = expect32; | 67 *expect = expect32; |
68 return proc_32; | 68 return proc_32; |
69 case SkBitmap::kARGB_4444_Config: | 69 case kARGB_4444_SkColorType: |
70 case SkBitmap::kRGB_565_Config: | 70 case kRGB_565_SkColorType: |
71 *expect = expect16; | 71 *expect = expect16; |
72 return proc_16; | 72 return proc_16; |
73 case SkBitmap::kA8_Config: | 73 case kAlpha_8_SkColorType: |
74 *expect = expect8; | 74 *expect = expect8; |
75 return proc_8; | 75 return proc_8; |
76 default: | 76 default: |
77 *expect = 0; | 77 *expect = 0; |
78 return proc_bad; | 78 return proc_bad; |
79 } | 79 } |
80 } | 80 } |
81 | 81 |
82 static bool check_color(const SkBitmap& bm, SkPMColor expect32, | 82 static bool check_color(const SkBitmap& bm, SkPMColor expect32, |
83 uint16_t expect16, uint8_t expect8, | 83 uint16_t expect16, uint8_t expect8, |
84 skiatest::Reporter* reporter) { | 84 skiatest::Reporter* reporter) { |
85 uint32_t expect; | 85 uint32_t expect; |
86 Proc proc = find_proc(bm, expect32, expect16, expect8, &expect); | 86 Proc proc = find_proc(bm, expect32, expect16, expect8, &expect); |
87 for (int y = 0; y < bm.height(); y++) { | 87 for (int y = 0; y < bm.height(); y++) { |
88 uint32_t bad; | 88 uint32_t bad; |
89 int x = proc(bm.getAddr(0, y), bm.width(), expect, &bad); | 89 int x = proc(bm.getAddr(0, y), bm.width(), expect, &bad); |
90 if (x >= 0) { | 90 if (x >= 0) { |
91 ERRORF(reporter, "BlitRow config=%s [%d %d] expected %x got %x", | 91 ERRORF(reporter, "BlitRow colortype=%s [%d %d] expected %x got %x", |
92 gConfigName[bm.config()], x, y, expect, bad); | 92 gColorTypeName[bm.colorType()], x, y, expect, bad); |
93 return false; | 93 return false; |
94 } | 94 } |
95 } | 95 } |
96 return true; | 96 return true; |
97 } | 97 } |
98 | 98 |
99 // Make sure our blits always map src==0 to a noop, and src==FF to full opaque | 99 // Make sure our blits always map src==0 to a noop, and src==FF to full opaque |
100 static void test_00_FF(skiatest::Reporter* reporter) { | 100 static void test_00_FF(skiatest::Reporter* reporter) { |
101 static const int W = 256; | 101 static const int W = 256; |
102 | 102 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 | 242 |
243 if (!gOnce && false) { | 243 if (!gOnce && false) { |
244 save_bm(dstBM0, "drawBitmap.png"); | 244 save_bm(dstBM0, "drawBitmap.png"); |
245 save_bm(dstBM1, "drawMesh.png"); | 245 save_bm(dstBM1, "drawMesh.png"); |
246 gOnce = true; | 246 gOnce = true; |
247 } | 247 } |
248 | 248 |
249 if (memcmp(dstBM0.getPixels(), dstBM1.getPixels(), dstBM0.ge
tSize())) { | 249 if (memcmp(dstBM0.getPixels(), dstBM1.getPixels(), dstBM0.ge
tSize())) { |
250 ERRORF(reporter, "Diagonal colortype=%s bg=0x%x dither=%
d" | 250 ERRORF(reporter, "Diagonal colortype=%s bg=0x%x dither=%
d" |
251 " alpha=0x%x src=0x%x", | 251 " alpha=0x%x src=0x%x", |
252 gConfigName[gDstColorType[i]], bgColor, dither, | 252 gColorTypeName[gDstColorType[i]], bgColor, dither
, |
253 alpha, c); | 253 alpha, c); |
254 } | 254 } |
255 } | 255 } |
256 } | 256 } |
257 } | 257 } |
258 } | 258 } |
259 } | 259 } |
260 | 260 |
261 DEF_TEST(BlitRow, reporter) { | 261 DEF_TEST(BlitRow, reporter) { |
262 test_00_FF(reporter); | 262 test_00_FF(reporter); |
263 test_diagonal(reporter); | 263 test_diagonal(reporter); |
264 } | 264 } |
OLD | NEW |