OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2015 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #include "SkSwizzler.h" | |
9 #include "Test.h" | |
10 | |
11 static void check_fill(skiatest::Reporter* r, | |
12 SkColorType colorType, | |
13 uint32_t width, | |
14 uint32_t height, | |
15 uint32_t row, | |
scroggo
2015/04/08 17:21:27
nit: startRow?
msarett
2015/04/08 19:35:40
Done.
| |
16 size_t rowBytes, | |
17 size_t totalBytes, | |
18 uint32_t input, | |
scroggo
2015/04/08 17:21:27
Maybe rename this to colorOrIndex? (Same for SkSwi
msarett
2015/04/08 19:35:40
Done.
| |
19 SkPMColor* colorTable) { | |
20 | |
21 // Create fake image data where every bytes has a value of 0xFF | |
scroggo
2015/04/08 17:21:27
nit: byte*
msarett
2015/04/08 19:35:40
Done.
| |
22 SkAutoTDelete<uint8_t> imageData((uint8_t*) sk_malloc_throw(totalBytes)); | |
23 memset(imageData.get(), 0xFF, totalBytes); | |
24 | |
25 // Create fake image info (alpha type does not matter) | |
26 SkImageInfo imageInfo = SkImageInfo::Make(width, height, colorType, kUnknown _SkAlphaType); | |
27 | |
28 // Fill image with zeros starting at the indicated row | |
29 SkSwizzler::Fill(imageData.get(), imageInfo, rowBytes, row, input, colorTabl e); | |
30 | |
31 // Ensure that the filled pixels are zero | |
32 // The bots should catch any memory corruption | |
33 for (uint32_t y = row; y < height; y++) { | |
34 uint8_t* indexPtr = imageData.get() + y * rowBytes; | |
35 uint32_t* colorPtr = (uint32_t*) indexPtr; | |
36 for (uint32_t x = 0; x < width; x++) { | |
37 if (kIndex_8_SkColorType == colorType) { | |
38 REPORTER_ASSERT(r, 0 == indexPtr[x]); | |
39 } else { | |
40 REPORTER_ASSERT(r, 0 == colorPtr[x]); | |
41 } | |
42 } | |
43 } | |
44 } | |
45 | |
46 // Each of these tests provide valid, but sometimes strange, values of width, he ight, and rowBytes. | |
47 // We ensure that Fill() works properly and does not corrupt memory for all of t hese inputs. | |
48 DEF_TEST(SwizzlerFill, r) { | |
49 | |
50 // Fill using an index into a color table | |
51 SkPMColor colorTable[256]; | |
52 colorTable[0] = 0xFFFFFFFF; | |
scroggo
2015/04/08 17:21:27
Why did you choose these colors? It seems like sin
msarett
2015/04/08 19:35:40
The tests for "an index to a color" always use 1 a
| |
53 colorTable[1] = 0; | |
scroggo
2015/04/08 17:21:27
Do we ever use values outside of the first two ent
msarett
2015/04/08 19:35:40
I thought it made sense because this is the most l
scroggo
2015/04/08 20:37:37
In this case, my concern is more about clarity tha
msarett
2015/04/09 13:02:47
Makes sense, I'm in agreement.
| |
54 // Zero dimensional cases | |
55 check_fill(r, kN32_SkColorType, 0, 1, 0, 0, 0, 1, colorTable); | |
scroggo
2015/04/08 17:21:27
I'm having trouble following all these cases with
msarett
2015/04/08 19:35:40
I agree that this benefits from better organizatio
| |
56 check_fill(r, kN32_SkColorType, 0, 1, 0, 10, 0, 1, colorTable); | |
scroggo
2015/04/08 17:21:27
Do we ever have a case where the dst is not four b
msarett
2015/04/08 19:35:40
This is implicitly covered by odd numbers of row b
| |
57 // Cases with different row padding | |
58 check_fill(r, kN32_SkColorType, 10, 10, 0, 40, 400, 1, colorTable); | |
59 check_fill(r, kN32_SkColorType, 10, 10, 0, 41, 410, 1, colorTable); | |
60 check_fill(r, kN32_SkColorType, 10, 10, 0, 42, 420, 1, colorTable); | |
61 check_fill(r, kN32_SkColorType, 10, 10, 0, 43, 430, 1, colorTable); | |
62 check_fill(r, kN32_SkColorType, 10, 10, 0, 44, 440, 1, colorTable); | |
63 // Cases that neglect to pad the bottom row | |
64 check_fill(r, kN32_SkColorType, 10, 10, 0, 41, 409, 1, colorTable); | |
65 check_fill(r, kN32_SkColorType, 10, 10, 0, 42, 418, 1, colorTable); | |
66 check_fill(r, kN32_SkColorType, 10, 10, 0, 43, 427, 1, colorTable); | |
67 check_fill(r, kN32_SkColorType, 10, 10, 0, 44, 436, 1, colorTable); | |
68 // Cases where we do not fill all of the rows | |
69 check_fill(r, kN32_SkColorType, 10, 10, 1, 40, 400, 1, colorTable); | |
70 check_fill(r, kN32_SkColorType, 10, 10, 2, 41, 410, 1, colorTable); | |
71 check_fill(r, kN32_SkColorType, 10, 10, 4, 42, 420, 1, colorTable); | |
72 check_fill(r, kN32_SkColorType, 10, 10, 6, 43, 430, 1, colorTable); | |
73 check_fill(r, kN32_SkColorType, 10, 10, 7, 44, 440, 1, colorTable); | |
74 check_fill(r, kN32_SkColorType, 10, 10, 9, 41, 409, 1, colorTable); | |
75 | |
76 // Fill using an index | |
77 // Zero dimensional cases | |
78 check_fill(r, kIndex_8_SkColorType, 0, 1, 0, 0, 0, 0, NULL); | |
79 check_fill(r, kIndex_8_SkColorType, 0, 1, 0, 10, 0, 0, NULL); | |
80 // Cases with different row padding | |
81 check_fill(r, kIndex_8_SkColorType, 10, 10, 0, 10, 100, 0, NULL); | |
82 check_fill(r, kIndex_8_SkColorType, 10, 10, 0, 11, 110, 0, NULL); | |
83 check_fill(r, kIndex_8_SkColorType, 10, 10, 0, 12, 120, 0, NULL); | |
84 check_fill(r, kIndex_8_SkColorType, 10, 10, 0, 13, 130, 0, NULL); | |
85 check_fill(r, kIndex_8_SkColorType, 10, 10, 0, 14, 140, 0, NULL); | |
86 // Cases that neglect to pad the bottom row | |
87 check_fill(r, kIndex_8_SkColorType, 10, 10, 0, 11, 109, 0, NULL); | |
88 check_fill(r, kIndex_8_SkColorType, 10, 10, 0, 12, 118, 0, NULL); | |
89 check_fill(r, kIndex_8_SkColorType, 10, 10, 0, 13, 127, 0, NULL); | |
90 check_fill(r, kIndex_8_SkColorType, 10, 10, 0, 14, 136, 0, NULL); | |
91 // Cases where we do not fill all of the rows | |
92 check_fill(r, kIndex_8_SkColorType, 10, 10, 1, 10, 100, 0, NULL); | |
93 check_fill(r, kIndex_8_SkColorType, 10, 10, 2, 11, 110, 0, NULL); | |
94 check_fill(r, kIndex_8_SkColorType, 10, 10, 4, 12, 120, 0, NULL); | |
95 check_fill(r, kIndex_8_SkColorType, 10, 10, 6, 13, 130, 0, NULL); | |
96 check_fill(r, kIndex_8_SkColorType, 10, 10, 7, 14, 140, 0, NULL); | |
97 check_fill(r, kIndex_8_SkColorType, 10, 10, 9, 11, 109, 0, NULL); | |
98 | |
99 // Fill using a color | |
100 // Zero dimensional cases | |
101 check_fill(r, kN32_SkColorType, 0, 1, 0, 0, 0, 0, NULL); | |
102 check_fill(r, kN32_SkColorType, 0, 1, 0, 10, 0, 0, NULL); | |
103 // Cases with different row padding | |
104 check_fill(r, kN32_SkColorType, 10, 10, 0, 40, 400, 0, NULL); | |
105 check_fill(r, kN32_SkColorType, 10, 10, 0, 41, 410, 0, NULL); | |
106 check_fill(r, kN32_SkColorType, 10, 10, 0, 42, 420, 0, NULL); | |
107 check_fill(r, kN32_SkColorType, 10, 10, 0, 43, 430, 0, NULL); | |
108 check_fill(r, kN32_SkColorType, 10, 10, 0, 44, 440, 0, NULL); | |
109 // Cases that neglect to pad the bottom row | |
110 check_fill(r, kN32_SkColorType, 10, 10, 0, 41, 409, 0, NULL); | |
111 check_fill(r, kN32_SkColorType, 10, 10, 0, 42, 418, 0, NULL); | |
112 check_fill(r, kN32_SkColorType, 10, 10, 0, 43, 427, 0, NULL); | |
113 check_fill(r, kN32_SkColorType, 10, 10, 0, 44, 436, 0, NULL); | |
114 // Cases where we do not fill all of the rows | |
115 check_fill(r, kN32_SkColorType, 10, 10, 1, 40, 400, 0, NULL); | |
116 check_fill(r, kN32_SkColorType, 10, 10, 2, 41, 410, 0, NULL); | |
117 check_fill(r, kN32_SkColorType, 10, 10, 4, 42, 420, 0, NULL); | |
118 check_fill(r, kN32_SkColorType, 10, 10, 6, 43, 430, 0, NULL); | |
119 check_fill(r, kN32_SkColorType, 10, 10, 7, 44, 440, 0, NULL); | |
120 check_fill(r, kN32_SkColorType, 10, 10, 9, 41, 409, 0, NULL); | |
121 } | |
OLD | NEW |