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 // These are the values that we will look for to indicate that the fill was succ essful | |
12 static const uint8_t fillIndex = 0x1; | |
scroggo
2015/04/09 14:53:48
nit: Typically we name our constants:
kFillIndex
msarett
2015/04/09 16:26:32
Done.
| |
13 static const uint32_t fillColor = 0x22334455; | |
14 | |
15 static void check_fill(skiatest::Reporter* r, | |
16 const SkImageInfo& imageInfo, | |
17 uint32_t startRow, | |
18 size_t rowBytes, | |
19 uint32_t offset, | |
20 uint32_t colorOrIndex, | |
21 SkPMColor* colorTable) { | |
22 | |
23 // Calculate the total size of the image in bytes. Use the smallest possibl e size. | |
scroggo
2015/04/09 14:53:48
nit: Might be nice to explain the offset. (We're s
msarett
2015/04/09 16:26:32
Yes that would be helpful.
| |
24 size_t totalBytes = imageInfo.getSafeSize(rowBytes) + offset; | |
scroggo
2015/04/09 14:53:48
nit: could be const.
msarett
2015/04/09 16:26:32
Done.
| |
25 | |
26 // Create fake image data where every byte has a value of 0 | |
27 SkAutoTDelete<uint8_t> storage((uint8_t*) sk_malloc_throw(totalBytes)); | |
28 memset(storage.get(), 0, totalBytes); | |
29 uint8_t* imageData = storage.get() + offset; | |
30 | |
31 // Fill image with the fill value starting at the indicated row | |
32 SkSwizzler::Fill(imageData, imageInfo, rowBytes, startRow, colorOrIndex, col orTable); | |
33 | |
34 // Ensure that the pixels are filled properly | |
35 // The bots should catch any memory corruption | |
36 uint8_t* indexPtr = imageData + startRow * rowBytes; | |
37 uint32_t* colorPtr = (uint32_t*) indexPtr; | |
38 for (int32_t y = startRow; y < imageInfo.height(); y++) { | |
39 for (int32_t x = 0; x < imageInfo.width(); x++) { | |
40 if (kIndex_8_SkColorType == imageInfo.colorType()) { | |
41 REPORTER_ASSERT(r, fillIndex == indexPtr[x]); | |
42 } else { | |
43 REPORTER_ASSERT(r, fillColor == colorPtr[x]); | |
44 } | |
45 } | |
46 indexPtr += rowBytes; | |
47 colorPtr = (uint32_t*) indexPtr; | |
48 } | |
49 } | |
50 | |
51 // Test Fill() with different combinations of dimensions, alignment, and padding | |
52 DEF_TEST(SwizzlerFill, r) { | |
53 // Set up a color table | |
54 SkPMColor colorTable[fillIndex + 1]; | |
55 colorTable[fillIndex] = fillColor; | |
56 | |
57 // Test on an invalid width and representative widths | |
58 const uint32_t widths[] = { 0, 10, 50 }; | |
59 | |
60 // In order to call Fill(), there must be at least one row to fill | |
61 // Test on the smallest possible height and representative heights | |
62 const uint32_t heights[] = { 1, 5, 10 }; | |
63 | |
64 // Test on interesting possibilities for row padding | |
65 const uint32_t paddings[] = { 0, 1, 2, 3, 4 }; | |
66 | |
67 // Iterate over test dimensions | |
68 for (uint32_t width : widths) { | |
69 for (uint32_t height : heights) { | |
70 | |
71 // Create image info objects | |
72 const SkImageInfo colorInfo = SkImageInfo::MakeN32(width, height, | |
73 kUnknown_SkAlphaType); | |
74 const SkImageInfo indexInfo = colorInfo.makeColorType(kIndex_8_SkCol orType); | |
75 | |
76 for (uint32_t padding : paddings) { | |
77 | |
78 // Calculate row bytes | |
79 size_t colorRowBytes = SkColorTypeBytesPerPixel(kN32_SkColorType ) * width + | |
80 padding; | |
81 size_t indexRowBytes = width + padding; | |
82 | |
83 // If there is padding, we can invent an offset to change the me mory alignment | |
84 for (uint32_t offset = 0; offset <= padding; offset++) { | |
85 | |
86 // Test all possible start rows | |
87 for (uint32_t startRow = 0; startRow < height; startRow++) { | |
88 | |
89 // Fill with an index that we use to look up a color | |
90 check_fill(r, colorInfo, startRow, colorRowBytes, offset , fillIndex, | |
91 colorTable); | |
92 | |
93 // Fill with a color | |
94 check_fill(r, colorInfo, startRow, colorRowBytes, offset , fillColor, | |
95 NULL); | |
96 | |
97 // Fill with an index | |
98 check_fill(r, indexInfo, startRow, indexRowBytes, offset , fillIndex, | |
99 NULL); | |
100 } | |
101 } | |
102 } | |
103 } | |
104 } | |
105 } | |
OLD | NEW |